mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
* The Ur-Dragon - Reworked triggered ability.
This commit is contained in:
parent
3bd716fb12
commit
e71c54593e
1 changed files with 12 additions and 85 deletions
|
@ -1,16 +1,12 @@
|
|||
|
||||
package mage.cards.t;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
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.cost.SpellsCostReductionControllerEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
|
@ -22,8 +18,6 @@ import mage.filter.predicate.mageobject.SubtypePredicate;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
|
@ -60,7 +54,7 @@ public final class TheUrDragon extends CardImpl {
|
|||
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
|
||||
this.addAbility(new TheUrDragonTriggeredAbility(), new DragonsAttackedWatcher());
|
||||
this.addAbility(new TheUrDragonTriggeredAbility());
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
public TheUrDragonTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new TheUrDragonEffect(), false);
|
||||
super(Zone.BATTLEFIELD, null, false);
|
||||
}
|
||||
|
||||
public TheUrDragonTriggeredAbility(final TheUrDragonTriggeredAbility ability) {
|
||||
|
@ -131,58 +89,27 @@ class TheUrDragonTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
int attackingDragons = 0;
|
||||
for (UUID attacker : game.getCombat().getAttackers()) {
|
||||
Permanent creature = game.getPermanent(attacker);
|
||||
if (creature != null
|
||||
&& creature.getControllerId() != null
|
||||
&& creature.getControllerId().equals(this.getControllerId())
|
||||
&& 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever one or more Dragons you control attack, " + super.getRule();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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.";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue