[AFC] Implemented Clay Golem

This commit is contained in:
Evan Kranzler 2021-07-19 16:35:39 -04:00
parent aa3254f09f
commit 66cebe64b0
3 changed files with 177 additions and 36 deletions

View file

@ -0,0 +1,140 @@
package mage.cards.c;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesMonstrousSourceTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.hint.common.MonstrousHint;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class ClayGolem extends CardImpl {
public ClayGolem(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{4}");
this.subtype.add(SubType.GOLEM);
this.power = new MageInt(4);
this.toughness = new MageInt(4);
// {6}, Roll a d8: Monstrosity X, where X is the result.
Ability ability = new SimpleActivatedAbility(new ClayGolemEffect(), new GenericManaCost(6));
ability.addCost(new ClayGolemCost());
this.addAbility(ability.addHint(MonstrousHint.instance));
// Berserk When Clay Golem becomes monstrous, destroy target permanent.
ability = new BecomesMonstrousSourceTriggeredAbility(new DestroyTargetEffect());
ability.addTarget(new TargetPermanent());
this.addAbility(ability.withFlavorWord("Berserk"));
}
private ClayGolem(final ClayGolem card) {
super(card);
}
@Override
public ClayGolem copy() {
return new ClayGolem(this);
}
}
class ClayGolemCost extends CostImpl {
private int lastRoll = 0;
ClayGolemCost() {
super();
text = "roll a d8";
}
private ClayGolemCost(final ClayGolemCost cost) {
super(cost);
this.lastRoll = cost.lastRoll;
}
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return true;
}
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player player = game.getPlayer(controllerId);
if (player == null) {
return paid;
}
lastRoll = player.rollDice(source, game, 8);
paid = true;
return paid;
}
@Override
public ClayGolemCost copy() {
return new ClayGolemCost(this);
}
public int getLastRoll() {
return lastRoll;
}
}
class ClayGolemEffect extends OneShotEffect {
ClayGolemEffect() {
super(Outcome.Benefit);
staticText = "monstrosity X, where X is the result";
}
private ClayGolemEffect(final ClayGolemEffect effect) {
super(effect);
}
@Override
public ClayGolemEffect copy() {
return new ClayGolemEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent == null || permanent.isMonstrous()) {
return false;
}
int monstrosityValue = source
.getCosts()
.stream()
.filter(ClayGolemCost.class::isInstance)
.map(ClayGolemCost.class::cast)
.mapToInt(ClayGolemCost::getLastRoll)
.findFirst()
.orElse(0);
permanent.addCounters(
CounterType.P1P1.createInstance(monstrosityValue),
source.getControllerId(), source, game
);
permanent.setMonstrous(true);
game.fireEvent(GameEvent.getEvent(
GameEvent.EventType.BECOMES_MONSTROUS, source.getSourceId(),
source, source.getControllerId(), monstrosityValue
));
return true;
}
}

View file

@ -56,6 +56,7 @@ public final class ForgottenRealmsCommander extends ExpansionSet {
cards.add(new SetCardInfo("Chittering Witch", 95, Rarity.RARE, mage.cards.c.ChitteringWitch.class)); cards.add(new SetCardInfo("Chittering Witch", 95, Rarity.RARE, mage.cards.c.ChitteringWitch.class));
cards.add(new SetCardInfo("Choked Estuary", 228, Rarity.RARE, mage.cards.c.ChokedEstuary.class)); cards.add(new SetCardInfo("Choked Estuary", 228, Rarity.RARE, mage.cards.c.ChokedEstuary.class));
cards.add(new SetCardInfo("Cinder Glade", 229, Rarity.RARE, mage.cards.c.CinderGlade.class)); cards.add(new SetCardInfo("Cinder Glade", 229, Rarity.RARE, mage.cards.c.CinderGlade.class));
cards.add(new SetCardInfo("Clay Golem", 58, Rarity.UNCOMMON, mage.cards.c.ClayGolem.class));
cards.add(new SetCardInfo("Cloudblazer", 182, Rarity.UNCOMMON, mage.cards.c.Cloudblazer.class)); cards.add(new SetCardInfo("Cloudblazer", 182, Rarity.UNCOMMON, mage.cards.c.Cloudblazer.class));
cards.add(new SetCardInfo("Cold-Eyed Selkie", 183, Rarity.RARE, mage.cards.c.ColdEyedSelkie.class)); cards.add(new SetCardInfo("Cold-Eyed Selkie", 183, Rarity.RARE, mage.cards.c.ColdEyedSelkie.class));
cards.add(new SetCardInfo("Colossal Majesty", 154, Rarity.UNCOMMON, mage.cards.c.ColossalMajesty.class)); cards.add(new SetCardInfo("Colossal Majesty", 154, Rarity.UNCOMMON, mage.cards.c.ColossalMajesty.class));

View file

@ -1,12 +1,9 @@
package mage.abilities.keyword; package mage.abilities.keyword;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl; import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.hint.common.MonstrousHint; import mage.abilities.hint.common.MonstrousHint;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
@ -19,24 +16,24 @@ import mage.util.CardUtil;
/** /**
* Monstrosity * Monstrosity
* * <p>
* 701.28. Monstrosity * 701.28. Monstrosity
* * <p>
* 701.28a Monstrosity N means If this permanent isn't monstrous, put N +1/+1 counters on it * 701.28a Monstrosity N means If this permanent isn't monstrous, put N +1/+1 counters on it
* and it becomes monstrous. Monstrous is a condition of that permanent that can be * and it becomes monstrous. Monstrous is a condition of that permanent that can be
* referred to by other abilities. * referred to by other abilities.
* * <p>
* 701.28b If a permanent's ability instructs a player to monstrosity X, other abilities of * 701.28b If a permanent's ability instructs a player to monstrosity X, other abilities of
* that permanent may also refer to X. The value of X in those abilities is equal to * that permanent may also refer to X. The value of X in those abilities is equal to
* the value of X as that permanent became monstrous. * the value of X as that permanent became monstrous.
* * <p>
* * Once a creature becomes monstrous, it can't become monstrous again. If the creature * * Once a creature becomes monstrous, it can't become monstrous again. If the creature
* is already monstrous when the monstrosity ability resolves, nothing happens. * is already monstrous when the monstrosity ability resolves, nothing happens.
* * <p>
* * Monstrous isn't an ability that a creature has. It's just something true about that * * Monstrous isn't an ability that a creature has. It's just something true about that
* creature. If the creature stops being a creature or loses its abilities, it will * creature. If the creature stops being a creature or loses its abilities, it will
* continue to be monstrous. * continue to be monstrous.
* * <p>
* * An ability that triggers when a creature becomes monstrous won't trigger if that creature * * An ability that triggers when a creature becomes monstrous won't trigger if that creature
* isn't on the battlefield when its monstrosity ability resolves. * isn't on the battlefield when its monstrosity ability resolves.
* *
@ -45,15 +42,14 @@ import mage.util.CardUtil;
public class MonstrosityAbility extends ActivatedAbilityImpl { public class MonstrosityAbility extends ActivatedAbilityImpl {
private int monstrosityValue; private final int monstrosityValue;
/** /**
*
* @param manaString * @param manaString
* @param monstrosityValue use Integer.MAX_VALUE for monstrosity X. * @param monstrosityValue use Integer.MAX_VALUE for monstrosity X.
*/ */
public MonstrosityAbility(String manaString, int monstrosityValue) { public MonstrosityAbility(String manaString, int monstrosityValue) {
super(Zone.BATTLEFIELD, new BecomeMonstrousSourceEffect(monstrosityValue),new ManaCostsImpl(manaString)); super(Zone.BATTLEFIELD, new BecomeMonstrousSourceEffect(monstrosityValue), new ManaCostsImpl<>(manaString));
this.monstrosityValue = monstrosityValue; this.monstrosityValue = monstrosityValue;
this.addHint(MonstrousHint.instance); this.addHint(MonstrousHint.instance);
@ -72,7 +68,6 @@ public class MonstrosityAbility extends ActivatedAbilityImpl {
public int getMonstrosityValue() { public int getMonstrosityValue() {
return monstrosityValue; return monstrosityValue;
} }
} }
@ -94,28 +89,33 @@ class BecomeMonstrousSourceEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null && !permanent.isMonstrous() && source instanceof MonstrosityAbility) { if (permanent == null || permanent.isMonstrous()) {
return false;
}
int monstrosityValue = ((MonstrosityAbility) source).getMonstrosityValue(); int monstrosityValue = ((MonstrosityAbility) source).getMonstrosityValue();
// handle monstrosity = X // handle monstrosity = X
if (monstrosityValue == Integer.MAX_VALUE) { if (monstrosityValue == Integer.MAX_VALUE) {
monstrosityValue = source.getManaCostsToPay().getX(); monstrosityValue = source.getManaCostsToPay().getX();
} }
new AddCountersSourceEffect(CounterType.P1P1.createInstance(monstrosityValue)).apply(game, source); permanent.addCounters(
CounterType.P1P1.createInstance(monstrosityValue),
source.getControllerId(), source, game
);
permanent.setMonstrous(true); permanent.setMonstrous(true);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_MONSTROUS, source.getSourceId(), source, source.getControllerId(), monstrosityValue)); game.fireEvent(GameEvent.getEvent(
GameEvent.EventType.BECOMES_MONSTROUS, source.getSourceId(),
source, source.getControllerId(), monstrosityValue
));
return true; return true;
} }
return false;
}
private String setText(int monstrosityValue) { private String setText(int monstrosityValue) {
StringBuilder sb = new StringBuilder("Monstrosity "); StringBuilder sb = new StringBuilder("Monstrosity ");
sb.append(monstrosityValue == Integer.MAX_VALUE ? "X":monstrosityValue) sb.append(monstrosityValue == Integer.MAX_VALUE ? "X" : monstrosityValue)
.append(". <i>(If this creature isn't monstrous, put ") .append(". <i>(If this creature isn't monstrous, put ")
.append(monstrosityValue == Integer.MAX_VALUE ? "X":CardUtil.numberToText(monstrosityValue)) .append(monstrosityValue == Integer.MAX_VALUE ? "X" : CardUtil.numberToText(monstrosityValue))
.append(" +1/+1 counters on it and it becomes monstrous.)</i>").toString(); .append(" +1/+1 counters on it and it becomes monstrous.)</i>").toString();
return sb.toString(); return sb.toString();
} }
} }