* The Ur-Dragon - Reworked triggered ability.

This commit is contained in:
LevelX2 2018-06-24 01:22:54 +02:00
parent 3bd716fb12
commit e71c54593e

View file

@ -1,16 +1,12 @@
package mage.cards.t; package mage.cards.t;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect; import mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect;
import mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect; import mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect;
import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.FlyingAbility;
@ -22,8 +18,6 @@ import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.watchers.Watcher;
/** /**
* @author TheElk801 * @author TheElk801
@ -60,7 +54,7 @@ public final class TheUrDragon extends CardImpl {
this.addAbility(FlyingAbility.getInstance()); this.addAbility(FlyingAbility.getInstance());
// Whenever one or more Dragons you control attack, draw that many cards, then you may put a permanent card from your hand onto the battlefield // Whenever one or more Dragons you control attack, draw that many cards, then you may put a permanent card from your hand onto the battlefield
this.addAbility(new TheUrDragonTriggeredAbility(), new DragonsAttackedWatcher()); this.addAbility(new TheUrDragonTriggeredAbility());
} }
public TheUrDragon(final TheUrDragon card) { public TheUrDragon(final TheUrDragon card) {
@ -73,46 +67,10 @@ public final class TheUrDragon extends CardImpl {
} }
} }
class DragonsAttackedWatcher extends Watcher {
public final Set<MageObjectReference> attackedThisTurnCreatures = new HashSet<>();
public DragonsAttackedWatcher() {
super(DragonsAttackedWatcher.class.getSimpleName(), WatcherScope.GAME);
}
public DragonsAttackedWatcher(final DragonsAttackedWatcher watcher) {
super(watcher);
this.attackedThisTurnCreatures.addAll(watcher.attackedThisTurnCreatures);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.BEGIN_COMBAT_STEP_PRE) {
this.attackedThisTurnCreatures.clear();
}
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
if (game.getPermanent(event.getSourceId()).hasSubtype(SubType.DRAGON, game)) {
this.attackedThisTurnCreatures.add(new MageObjectReference(event.getSourceId(), game));
}
}
}
public Set<MageObjectReference> getAttackedThisTurnCreatures() {
return this.attackedThisTurnCreatures;
}
@Override
public DragonsAttackedWatcher copy() {
return new DragonsAttackedWatcher(this);
}
}
class TheUrDragonTriggeredAbility extends TriggeredAbilityImpl { class TheUrDragonTriggeredAbility extends TriggeredAbilityImpl {
public TheUrDragonTriggeredAbility() { public TheUrDragonTriggeredAbility() {
super(Zone.BATTLEFIELD, new TheUrDragonEffect(), false); super(Zone.BATTLEFIELD, null, false);
} }
public TheUrDragonTriggeredAbility(final TheUrDragonTriggeredAbility ability) { public TheUrDragonTriggeredAbility(final TheUrDragonTriggeredAbility ability) {
@ -131,58 +89,27 @@ class TheUrDragonTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
int attackingDragons = 0;
for (UUID attacker : game.getCombat().getAttackers()) { for (UUID attacker : game.getCombat().getAttackers()) {
Permanent creature = game.getPermanent(attacker); Permanent creature = game.getPermanent(attacker);
if (creature != null if (creature != null
&& creature.getControllerId() != null && creature.getControllerId() != null
&& creature.getControllerId().equals(this.getControllerId()) && creature.getControllerId().equals(this.getControllerId())
&& creature.hasSubtype(SubType.DRAGON, game)) { && creature.hasSubtype(SubType.DRAGON, game)) {
return true; attackingDragons++;
} }
} }
if (attackingDragons > 0) {
this.getEffects().clear();
addEffect(new DrawCardSourceControllerEffect(attackingDragons));
addEffect(new PutCardFromHandOntoBattlefieldEffect());
return true;
}
return false; return false;
} }
@Override @Override
public String getRule() { public String getRule() {
return "Whenever one or more Dragons you control attack, " + super.getRule(); return "Whenever one or more Dragons you control attack, draw that many cards, then you may put a permanent card from your hand onto the battlefield.";
}
}
class TheUrDragonEffect extends OneShotEffect {
public TheUrDragonEffect() {
super(Outcome.Benefit);
this.staticText = "draw that many cards, then you may put a permanent card from your hand onto the battlefield";
}
public TheUrDragonEffect(final TheUrDragonEffect effect) {
super(effect);
}
@Override
public TheUrDragonEffect copy() {
return new TheUrDragonEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
DragonsAttackedWatcher watcher = (DragonsAttackedWatcher) game.getState().getWatchers().get(DragonsAttackedWatcher.class.getSimpleName());
if (watcher != null) {
int attackingDragons = 0;
for (MageObjectReference attacker : watcher.getAttackedThisTurnCreatures()) {
if (attacker.getPermanentOrLKIBattlefield(game).getControllerId().equals(controller.getId())) {
attackingDragons++;
}
}
if (attackingDragons > 0) {
controller.drawCards(attackingDragons, game);
}
return new PutCardFromHandOntoBattlefieldEffect().apply(game, source);
}
}
return false;
} }
} }