Implemented Oathsworn Knight

This commit is contained in:
Evan Kranzler 2019-09-14 18:30:51 -04:00
parent 4e974b0d3c
commit 3491b36ae8
4 changed files with 70 additions and 13 deletions

View file

@ -0,0 +1,50 @@
package mage.cards.o;
import mage.MageInt;
import mage.abilities.common.AttacksEachCombatStaticAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.PreventDamageAndRemoveCountersEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.counters.CounterType;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class OathswornKnight extends CardImpl {
public OathswornKnight(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{B}{B}");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.KNIGHT);
this.power = new MageInt(0);
this.toughness = new MageInt(0);
// Oathsworn Knight enters the battlefield with four +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(
CounterType.P1P1.createInstance(4)
), "with four +1/+1 counters on it"));
// Oathsworn Knight attacks each combat if able.
this.addAbility(new AttacksEachCombatStaticAbility());
// If damage would be dealt to Oathsworn Knight while it has a +1/+1 counter on it, prevent that damage and remove a +1/+1 counter from it.
this.addAbility(new SimpleStaticAbility(new PreventDamageAndRemoveCountersEffect(false)));
}
private OathswornKnight(final OathswornKnight card) {
super(card);
}
@Override
public OathswornKnight copy() {
return new OathswornKnight(this);
}
}

View file

@ -31,7 +31,7 @@ public final class UginsConjurant extends CardImpl {
// Ugins Conjurant enters the battlefield with X +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new EntersBattlefieldWithXCountersEffect(CounterType.P1P1.createInstance())));
// If damage would be dealt to Ugins Conjurant while it has a +1/+1 counter on it, prevent that damage and remove that many +1/+1 counters from Ugins Conjurant.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageAndRemoveCountersEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageAndRemoveCountersEffect(true)));
}
private UginsConjurant(final UginsConjurant card) {

View file

@ -124,6 +124,7 @@ public final class ThroneOfEldraine extends ExpansionSet {
cards.add(new SetCardInfo("Mystical Dispute", 58, Rarity.UNCOMMON, mage.cards.m.MysticalDispute.class));
cards.add(new SetCardInfo("Oakhame Adversary", 167, Rarity.UNCOMMON, mage.cards.o.OakhameAdversary.class));
cards.add(new SetCardInfo("Oakhame Ranger", 212, Rarity.UNCOMMON, mage.cards.o.OakhameRanger.class));
cards.add(new SetCardInfo("Oathsworn Knight", 98, Rarity.RARE, mage.cards.o.OathswornKnight.class));
cards.add(new SetCardInfo("Ogre Errant", 132, Rarity.COMMON, mage.cards.o.OgreErrant.class));
cards.add(new SetCardInfo("Oko's Accomplices", 310, Rarity.COMMON, mage.cards.o.OkosAccomplices.class));
cards.add(new SetCardInfo("Oko's Hospitality", 312, Rarity.RARE, mage.cards.o.OkosHospitality.class));

View file

@ -13,18 +13,21 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
*
* @author antoni-g
*/
public class PreventDamageAndRemoveCountersEffect extends PreventionEffectImpl {
private final boolean thatMany;
public PreventDamageAndRemoveCountersEffect() {
public PreventDamageAndRemoveCountersEffect(boolean thatMany) {
super(Duration.WhileOnBattlefield, Integer.MAX_VALUE, false, false);
staticText = "If damage would be dealt to {this}, prevent that damage and remove that many +1/+1 counters from it";
this.thatMany = thatMany;
staticText = "If damage would be dealt to {this} while it has a +1/+1 counter on it, " +
"prevent that damage and remove " + (thatMany ? "that many +1/+1 counters" : "a +1/+1 counter") + " from it";
}
public PreventDamageAndRemoveCountersEffect(final PreventDamageAndRemoveCountersEffect effect) {
private PreventDamageAndRemoveCountersEffect(final PreventDamageAndRemoveCountersEffect effect) {
super(effect);
this.thatMany = effect.thatMany;
}
@Override
@ -42,19 +45,22 @@ public class PreventDamageAndRemoveCountersEffect extends PreventionEffectImpl {
int damage = event.getAmount();
preventDamageAction(event, source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.removeCounters(CounterType.P1P1.createInstance(damage), game); //MTG ruling (this) loses counters even if the damage isn't prevented
if (permanent == null) {
return false;
}
if (!thatMany) {
damage = 1;
}
permanent.removeCounters(CounterType.P1P1.createInstance(damage), game); //MTG ruling (this) loses counters even if the damage isn't prevented
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
Permanent permanent = game.getPermanent(event.getTargetId());
return super.applies(event, source, game)
&& permanent != null
&& event.getTargetId().equals(source.getSourceId())
&& permanent.getCounters(game).containsKey(CounterType.P1P1);
}
}