Implemented Quartzwood Crasher

This commit is contained in:
Evan Kranzler 2020-04-15 08:32:17 -04:00
parent fd02d66227
commit 1874a8404a
3 changed files with 201 additions and 0 deletions

View file

@ -0,0 +1,169 @@
package mage.cards.q;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.BeastXToken;
import mage.target.targetpointer.FixedTarget;
import mage.watchers.Watcher;
import java.util.*;
/**
* @author TheElk801
*/
public final class QuartzwoodCrasher extends CardImpl {
public QuartzwoodCrasher(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{R}{R}{G}");
this.subtype.add(SubType.DINOSAUR);
this.subtype.add(SubType.BEAST);
this.power = new MageInt(6);
this.toughness = new MageInt(6);
// Trample
this.addAbility(TrampleAbility.getInstance());
// Whenever one or more creatures you control with trample deal combat damage to a player, create an X/X green Dinosaur Beast creature token with trample, where X is the amount of damage those creatures dealt to that player.
this.addAbility(new QuartzwoodCrasherTriggeredAbility(), new QuartzwoodCrasherWatcher());
}
private QuartzwoodCrasher(final QuartzwoodCrasher card) {
super(card);
}
@Override
public QuartzwoodCrasher copy() {
return new QuartzwoodCrasher(this);
}
}
class QuartzwoodCrasherTriggeredAbility extends TriggeredAbilityImpl {
private final Set<UUID> damagedPlayerIds = new HashSet();
QuartzwoodCrasherTriggeredAbility() {
super(Zone.BATTLEFIELD, new QuartzwoodCrasherEffect(), false);
}
private QuartzwoodCrasherTriggeredAbility(final QuartzwoodCrasherTriggeredAbility ability) {
super(ability);
}
@Override
public QuartzwoodCrasherTriggeredAbility copy() {
return new QuartzwoodCrasherTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DAMAGED_PLAYER
|| event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
damagedPlayerIds.clear();
return false;
}
if (event.getType() != GameEvent.EventType.DAMAGED_PLAYER
&& !((DamagedPlayerEvent) event).isCombatDamage()) {
return false;
}
Permanent creature = game.getPermanent(event.getSourceId());
if (creature != null && creature.isControlledBy(controllerId)
&& creature.getAbilities(game).containsKey(TrampleAbility.getInstance().getId())
&& !damagedPlayerIds.contains(event.getTargetId())) {
damagedPlayerIds.add(event.getTargetId());
this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId(), game));
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever one or more creatures you control with trample deal combat damage to a player, " +
"create an X/X green Dinosaur Beast creature token with trample, " +
"where X is the amount of damage those creatures dealt to that player.";
}
}
class QuartzwoodCrasherEffect extends OneShotEffect {
QuartzwoodCrasherEffect() {
super(Outcome.Benefit);
}
private QuartzwoodCrasherEffect(final QuartzwoodCrasherEffect effect) {
super(effect);
}
@Override
public QuartzwoodCrasherEffect copy() {
return new QuartzwoodCrasherEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
QuartzwoodCrasherWatcher watcher = game.getState().getWatcher(QuartzwoodCrasherWatcher.class);
return watcher != null && new BeastXToken(
watcher.getDamage(targetPointer.getFirst(game, source), source.getControllerId())
).putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
}
}
class QuartzwoodCrasherWatcher extends Watcher {
private final Map<UUID, Map<UUID, Integer>> damageMap = new HashMap();
QuartzwoodCrasherWatcher() {
super(WatcherScope.GAME);
}
private QuartzwoodCrasherWatcher(final QuartzwoodCrasherWatcher watcher) {
super(watcher);
this.damageMap.putAll(watcher.damageMap);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
damageMap.clear();
}
if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER
|| ((DamagedPlayerEvent) event).isCombatDamage()) {
return;
}
Permanent creature = game.getPermanent(event.getSourceId());
if (creature == null || !creature.getAbilities(game).containsKey(TrampleAbility.getInstance().getId())) {
return;
}
damageMap
.computeIfAbsent(event.getTargetId(), x -> new HashMap())
.compute(creature.getControllerId(), (uuid, i) -> i == null ? event.getAmount() : i + event.getAmount());
}
public int getDamage(UUID damagedPlayerId, UUID controllerId) {
if (!damageMap.containsKey(damagedPlayerId)) {
return 0;
}
return damageMap.get(damagedPlayerId).getOrDefault(controllerId, 0);
}
@Override
public QuartzwoodCrasherWatcher copy() {
return new QuartzwoodCrasherWatcher(this);
}
}

View file

@ -250,6 +250,7 @@ public final class IkoriaLairOfBehemoths extends ExpansionSet {
cards.add(new SetCardInfo("Primal Empathy", 200, Rarity.UNCOMMON, mage.cards.p.PrimalEmpathy.class));
cards.add(new SetCardInfo("Proud Wildbonder", 229, Rarity.UNCOMMON, mage.cards.p.ProudWildbonder.class));
cards.add(new SetCardInfo("Pyroceratops", 130, Rarity.COMMON, mage.cards.p.Pyroceratops.class));
cards.add(new SetCardInfo("Quartzwood Crasher", 201, Rarity.RARE, mage.cards.q.QuartzwoodCrasher.class));
cards.add(new SetCardInfo("Raking Claws", 131, Rarity.COMMON, mage.cards.r.RakingClaws.class));
cards.add(new SetCardInfo("Ram Through", 170, Rarity.COMMON, mage.cards.r.RamThrough.class));
cards.add(new SetCardInfo("Raugrin Crystal", 238, Rarity.UNCOMMON, mage.cards.r.RaugrinCrystal.class));

View file

@ -0,0 +1,31 @@
package mage.game.permanent.token;
import mage.MageInt;
import mage.abilities.keyword.TrampleAbility;
import mage.constants.CardType;
import mage.constants.SubType;
/**
* @author TheElk801
*/
public final class BeastXToken extends TokenImpl {
public BeastXToken(int xValue) {
super("Beast", "X/X green Beast creature token");
cardType.add(CardType.CREATURE);
color.setGreen(true);
subtype.add(SubType.BEAST);
power = new MageInt(xValue);
toughness = new MageInt(xValue);
addAbility(TrampleAbility.getInstance());
}
private BeastXToken(final BeastXToken token) {
super(token);
}
@Override
public BeastXToken copy() {
return new BeastXToken(this);
}
}