mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
* Arashin War Beast - Fixed triggerd ability.
This commit is contained in:
parent
bcb1331c0f
commit
a588b601b6
2 changed files with 105 additions and 20 deletions
|
@ -29,11 +29,20 @@ package mage.sets.fatereforged;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.keyword.ManifestEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.BlockingPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamagedCreatureEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -49,7 +58,7 @@ public class ArashinWarBeast extends CardImpl {
|
|||
this.toughness = new MageInt(6);
|
||||
|
||||
// Whenever Arashin War Beast deals combat damage to one or more blockers, manifest the top card of your library.
|
||||
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new ManifestEffect(1), true));
|
||||
this.addAbility(new ArashinWarBeastTriggeredAbility(new ManifestEffect(1), true));
|
||||
|
||||
}
|
||||
|
||||
|
@ -62,3 +71,55 @@ public class ArashinWarBeast extends CardImpl {
|
|||
return new ArashinWarBeast(this);
|
||||
}
|
||||
}
|
||||
|
||||
class ArashinWarBeastTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("one or more blockers");
|
||||
|
||||
static {
|
||||
filter.add(new BlockingPredicate());
|
||||
}
|
||||
|
||||
boolean usedForCombatDamageStep;
|
||||
|
||||
public ArashinWarBeastTriggeredAbility(Effect effect, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.usedForCombatDamageStep = false;
|
||||
}
|
||||
|
||||
public ArashinWarBeastTriggeredAbility(final ArashinWarBeastTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.usedForCombatDamageStep = ability.usedForCombatDamageStep;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArashinWarBeastTriggeredAbility copy() {
|
||||
return new ArashinWarBeastTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == EventType.DAMAGED_CREATURE &&
|
||||
event.getSourceId().equals(this.sourceId) &&
|
||||
((DamagedCreatureEvent) event).isCombatDamage() &&
|
||||
!usedForCombatDamageStep) {
|
||||
Permanent creature = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
||||
if (creature == null || !filter.match(creature, getSourceId(), getControllerId(), game)) {
|
||||
return false;
|
||||
}
|
||||
// trigger only once per combat damage step
|
||||
usedForCombatDamageStep = true;
|
||||
return true;
|
||||
|
||||
}
|
||||
if (event.getType() == EventType.COMBAT_DAMAGE_STEP_POST) {
|
||||
usedForCombatDamageStep = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever {this} deals combat damage to one or more blockers, " + super.getRule();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,17 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.constants.Zone;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamagedCreatureEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
|
@ -44,45 +45,68 @@ import mage.target.targetpointer.FixedTarget;
|
|||
public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private boolean combatOnly;
|
||||
private boolean setTargetPointer;
|
||||
private final boolean setTargetPointer;
|
||||
private FilterCreaturePermanent filter;
|
||||
|
||||
public DealsDamageToACreatureTriggeredAbility(Effect effect, boolean combatOnly, boolean optional, boolean setTargetPointer) {
|
||||
this(effect, combatOnly, optional, setTargetPointer, null);
|
||||
}
|
||||
|
||||
public DealsDamageToACreatureTriggeredAbility(Effect effect, boolean combatOnly, boolean optional, boolean setTargetPointer, FilterCreaturePermanent filter) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.setTargetPointer = setTargetPointer;
|
||||
}
|
||||
|
||||
public DealsDamageToACreatureTriggeredAbility(final DealsDamageToACreatureTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.setTargetPointer = ability.setTargetPointer;
|
||||
this.combatOnly = ability.combatOnly;
|
||||
super(ability);
|
||||
this.setTargetPointer = ability.setTargetPointer;
|
||||
this.combatOnly = ability.combatOnly;
|
||||
this.filter = ability.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DealsDamageToACreatureTriggeredAbility copy() {
|
||||
return new DealsDamageToACreatureTriggeredAbility(this);
|
||||
return new DealsDamageToACreatureTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == EventType.DAMAGED_CREATURE) {
|
||||
if (event.getSourceId().equals(this.sourceId)
|
||||
if (event.getType() == EventType.DAMAGED_CREATURE) {
|
||||
if (event.getSourceId().equals(this.sourceId)
|
||||
&& (!combatOnly || ((DamagedCreatureEvent) event).isCombatDamage())) {
|
||||
if (setTargetPointer) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
|
||||
effect.setValue("damage", event.getAmount());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (filter != null) {
|
||||
Permanent creature = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
||||
if (creature == null || !filter.match(creature, getSourceId(), getControllerId(), game)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
if (setTargetPointer) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
|
||||
effect.setValue("damage", event.getAmount());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return new StringBuilder("Whenever {this} deals ").append(combatOnly ? "combat ":"").append("damage to a creature, ").append(super.getRule()).toString();
|
||||
StringBuilder sb = new StringBuilder("Whenever {this} deals ");
|
||||
if (combatOnly) {
|
||||
sb.append("combat ");
|
||||
}
|
||||
sb.append("damage to ");
|
||||
if (filter == null) {
|
||||
sb.append("a creature, ");
|
||||
} else {
|
||||
sb.append(filter.getMessage());
|
||||
}
|
||||
sb.append(super.getRule());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue