(#4015) fixed enrage triggers triggering multiple times in combat,

didn't fix triggers which use amount of damage dealt (Boros Reckoner)
This commit is contained in:
Evan Kranzler 2017-09-22 18:18:30 -04:00
parent f4cc8311e8
commit 59b38b76ec
11 changed files with 59 additions and 33 deletions

View file

@ -51,20 +51,20 @@ import mage.target.common.TargetCreatureOrPlayer;
public class BorosReckoner extends CardImpl { public class BorosReckoner extends CardImpl {
public BorosReckoner(UUID ownerId, CardSetInfo setInfo) { public BorosReckoner(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{R/W}{R/W}{R/W}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{R/W}{R/W}{R/W}");
this.subtype.add(SubType.MINOTAUR, SubType.WIZARD); this.subtype.add(SubType.MINOTAUR, SubType.WIZARD);
this.power = new MageInt(3); this.power = new MageInt(3);
this.toughness = new MageInt(3); this.toughness = new MageInt(3);
// Whenever Boros Reckoner is dealt damage, it deals that much damage to target creature or player. // Whenever Boros Reckoner is dealt damage, it deals that much damage to target creature or player.
Ability ability = new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new BorosReckonerDealDamageEffect(), false); Ability ability = new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new BorosReckonerDealDamageEffect(), false, false, true);
ability.addTarget(new TargetCreatureOrPlayer()); ability.addTarget(new TargetCreatureOrPlayer());
this.addAbility(ability); this.addAbility(ability);
// {R/W}: Boros Reckoner gains first strike until end of turn. // {R/W}: Boros Reckoner gains first strike until end of turn.
this.addAbility(new SimpleActivatedAbility( this.addAbility(new SimpleActivatedAbility(
Zone.BATTLEFIELD, new GainAbilitySourceEffect(FirstStrikeAbility.getInstance(),Duration.EndOfTurn), new ManaCostsImpl("{R/W}"))); Zone.BATTLEFIELD, new GainAbilitySourceEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn), new ManaCostsImpl("{R/W}")));
} }
public BorosReckoner(final BorosReckoner card) { public BorosReckoner(final BorosReckoner card) {

View file

@ -52,13 +52,13 @@ import mage.players.Player;
public class BroodhatchNantuko extends CardImpl { public class BroodhatchNantuko extends CardImpl {
public BroodhatchNantuko(UUID ownerId, CardSetInfo setInfo) { public BroodhatchNantuko(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{G}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{G}");
this.subtype.add(SubType.INSECT, SubType.DRUID); this.subtype.add(SubType.INSECT, SubType.DRUID);
this.power = new MageInt(1); this.power = new MageInt(1);
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// Whenever Broodhatch Nantuko is dealt damage, you may create that many 1/1 green Insect creature tokens. // Whenever Broodhatch Nantuko is dealt damage, you may create that many 1/1 green Insect creature tokens.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new BroodhatchNantukoDealDamageEffect(), true)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new BroodhatchNantukoDealDamageEffect(), true, false, true));
// Morph {2}{G} // Morph {2}{G}
this.addAbility(new MorphAbility(this, new ManaCostsImpl("{2}{G}"))); this.addAbility(new MorphAbility(this, new ManaCostsImpl("{2}{G}")));
} }
@ -100,4 +100,4 @@ class BroodhatchNantukoDealDamageEffect extends OneShotEffect {
} }
return false; return false;
} }
} }

View file

@ -49,14 +49,14 @@ public class CoalhaulerSwine extends CardImpl {
public CoalhaulerSwine(UUID ownerId, CardSetInfo setInfo) { public CoalhaulerSwine(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{R}{R}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{R}{R}");
this.subtype.add(SubType.BOAR); this.subtype.add(SubType.BOAR);
this.subtype.add(SubType.BEAST); this.subtype.add(SubType.BEAST);
this.power = new MageInt(4); this.power = new MageInt(4);
this.toughness = new MageInt(4); this.toughness = new MageInt(4);
// Whenever Coalhauler Swine is dealt damage, it deals that much damage to each player. // Whenever Coalhauler Swine is dealt damage, it deals that much damage to each player.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new CoalhaulerSwineEffect(), false)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new CoalhaulerSwineEffect(), false, false, true));
} }
public CoalhaulerSwine(final CoalhaulerSwine card) { public CoalhaulerSwine(final CoalhaulerSwine card) {
@ -88,7 +88,7 @@ public class CoalhaulerSwine extends CardImpl {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
for (UUID playerId : game.getPlayers().keySet()) { for (UUID playerId : game.getPlayers().keySet()) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if(player != null) { if (player != null) {
player.damage((Integer) this.getValue("damage"), source.getSourceId(), game, false, true); player.damage((Integer) this.getValue("damage"), source.getSourceId(), game, false, true);
} }
} }

View file

@ -54,7 +54,7 @@ import mage.players.Player;
public class FiredrinkerSatyr extends CardImpl { public class FiredrinkerSatyr extends CardImpl {
public FiredrinkerSatyr(UUID ownerId, CardSetInfo setInfo) { public FiredrinkerSatyr(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{R}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{R}");
this.subtype.add(SubType.SATYR); this.subtype.add(SubType.SATYR);
this.subtype.add(SubType.SHAMAN); this.subtype.add(SubType.SHAMAN);
@ -62,9 +62,9 @@ public class FiredrinkerSatyr extends CardImpl {
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// Whenever Firedrinker Satyr is dealt damage, it deals that much damage to you. // Whenever Firedrinker Satyr is dealt damage, it deals that much damage to you.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new FiredrinkerSatyrDealDamageEffect(), false)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new FiredrinkerSatyrDealDamageEffect(), false, false, true));
// {1}{R}: Firedrinker Satyr gets +1/+0 until end of turn and deals 1 damage to you. // {1}{R}: Firedrinker Satyr gets +1/+0 until end of turn and deals 1 damage to you.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(1,0, Duration.EndOfTurn), new ManaCostsImpl("{1}{R}")); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(1, 0, Duration.EndOfTurn), new ManaCostsImpl("{1}{R}"));
Effect effect = new DamageControllerEffect(1); Effect effect = new DamageControllerEffect(1);
effect.setText("and deals 1 damage to you"); effect.setText("and deals 1 damage to you");
ability.addEffect(effect); ability.addEffect(effect);

View file

@ -60,7 +60,7 @@ public class HornetNest extends CardImpl {
// Defender // Defender
this.addAbility(DefenderAbility.getInstance()); this.addAbility(DefenderAbility.getInstance());
// Whenever Hornet Nest is dealt damage, create that many 1/1 green Insect creature tokens with flying and deathtouch. // Whenever Hornet Nest is dealt damage, create that many 1/1 green Insect creature tokens with flying and deathtouch.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new HornetNestDealDamageEffect(), false)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new HornetNestDealDamageEffect(), false, false, true));
} }
public HornetNest(final HornetNest card) { public HornetNest(final HornetNest card) {

View file

@ -49,7 +49,7 @@ import mage.players.Player;
public class IllusoryAmbusher extends CardImpl { public class IllusoryAmbusher extends CardImpl {
public IllusoryAmbusher(UUID ownerId, CardSetInfo setInfo) { public IllusoryAmbusher(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{4}{U}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{U}");
this.subtype.add(SubType.CAT); this.subtype.add(SubType.CAT);
this.subtype.add(SubType.ILLUSION); this.subtype.add(SubType.ILLUSION);
this.power = new MageInt(4); this.power = new MageInt(4);
@ -57,9 +57,9 @@ public class IllusoryAmbusher extends CardImpl {
// Flash // Flash
this.addAbility(FlashAbility.getInstance()); this.addAbility(FlashAbility.getInstance());
// Whenever Illusory Ambusher is dealt damage, draw that many cards. // Whenever Illusory Ambusher is dealt damage, draw that many cards.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new IllusoryAmbusherDealtDamageEffect(), false)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new IllusoryAmbusherDealtDamageEffect(), false, false, true));
} }
public IllusoryAmbusher(final IllusoryAmbusher card) { public IllusoryAmbusher(final IllusoryAmbusher card) {
@ -100,4 +100,4 @@ class IllusoryAmbusherDealtDamageEffect extends OneShotEffect {
} }
return false; return false;
} }
} }

View file

@ -49,14 +49,14 @@ import mage.players.Player;
public class JackalPup extends CardImpl { public class JackalPup extends CardImpl {
public JackalPup(UUID ownerId, CardSetInfo setInfo) { public JackalPup(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{R}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{R}");
this.subtype.add(SubType.JACKAL); this.subtype.add(SubType.JACKAL);
this.power = new MageInt(2); this.power = new MageInt(2);
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// Whenever Jackal Pup is dealt damage, it deals that much damage to you. // Whenever Jackal Pup is dealt damage, it deals that much damage to you.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new JackalPupEffect(), false)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new JackalPupEffect(), false, false, true));
} }

View file

@ -49,13 +49,13 @@ import mage.target.common.TargetOpponent;
public class MoggManiac extends CardImpl { public class MoggManiac extends CardImpl {
public MoggManiac(UUID ownerId, CardSetInfo setInfo) { public MoggManiac(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{R}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}");
this.subtype.add(SubType.GOBLIN); this.subtype.add(SubType.GOBLIN);
this.power = new MageInt(1); this.power = new MageInt(1);
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// Whenever Mogg Maniac is dealt damage, it deals that much damage to target opponent. // Whenever Mogg Maniac is dealt damage, it deals that much damage to target opponent.
Ability ability = new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new MoggManiacDealDamageEffect(), false); Ability ability = new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new MoggManiacDealDamageEffect(), false, false, true);
ability.addTarget(new TargetOpponent()); ability.addTarget(new TargetOpponent());
this.addAbility(ability); this.addAbility(ability);
} }

View file

@ -46,18 +46,18 @@ import mage.players.Player;
/** /**
* *
* @author LoneFox * @author LoneFox
*
*/ */
public class SaberAnts extends CardImpl { public class SaberAnts extends CardImpl {
public SaberAnts(UUID ownerId, CardSetInfo setInfo) { public SaberAnts(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{G}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}");
this.subtype.add(SubType.INSECT); this.subtype.add(SubType.INSECT);
this.power = new MageInt(2); this.power = new MageInt(2);
this.toughness = new MageInt(3); this.toughness = new MageInt(3);
// Whenever Saber Ants is dealt damage, you may create that many 1/1 green Insect creature tokens. // Whenever Saber Ants is dealt damage, you may create that many 1/1 green Insect creature tokens.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new SaberAntsEffect(), true)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new SaberAntsEffect(), true, false, true));
} }
public SaberAnts(final SaberAnts card) { public SaberAnts(final SaberAnts card) {

View file

@ -48,7 +48,7 @@ import mage.players.Player;
public class ShinkaGatekeeper extends CardImpl { public class ShinkaGatekeeper extends CardImpl {
public ShinkaGatekeeper(UUID ownerId, CardSetInfo setInfo) { public ShinkaGatekeeper(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{R}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{R}");
this.subtype.add(SubType.OGRE); this.subtype.add(SubType.OGRE);
this.subtype.add(SubType.WARRIOR); this.subtype.add(SubType.WARRIOR);
@ -56,7 +56,7 @@ public class ShinkaGatekeeper extends CardImpl {
this.toughness = new MageInt(2); this.toughness = new MageInt(2);
// Whenever Shinka Gatekeeper is dealt damage, it deals that much damage to you. // Whenever Shinka Gatekeeper is dealt damage, it deals that much damage to you.
this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new ShinkaGatekeeperDealDamageEffect(), false)); this.addAbility(new DealtDamageToSourceTriggeredAbility(Zone.BATTLEFIELD, new ShinkaGatekeeperDealDamageEffect(), false, false, true));
} }
public ShinkaGatekeeper(final ShinkaGatekeeper card) { public ShinkaGatekeeper(final ShinkaGatekeeper card) {
@ -69,7 +69,6 @@ public class ShinkaGatekeeper extends CardImpl {
} }
} }
class ShinkaGatekeeperDealDamageEffect extends OneShotEffect { class ShinkaGatekeeperDealDamageEffect extends OneShotEffect {
public ShinkaGatekeeperDealDamageEffect() { public ShinkaGatekeeperDealDamageEffect() {

View file

@ -31,6 +31,7 @@ import mage.constants.Zone;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.game.Game; import mage.game.Game;
import mage.game.events.DamagedCreatureEvent;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
/** /**
@ -39,20 +40,30 @@ import mage.game.events.GameEvent;
*/ */
public class DealtDamageToSourceTriggeredAbility extends TriggeredAbilityImpl { public class DealtDamageToSourceTriggeredAbility extends TriggeredAbilityImpl {
private boolean enrage; private final boolean enrage;
private final boolean useValue;
private boolean usedForCombatDamageStep;
public DealtDamageToSourceTriggeredAbility(Zone zone, Effect effect, boolean optional) { public DealtDamageToSourceTriggeredAbility(Zone zone, Effect effect, boolean optional) {
this(zone, effect, optional, false); this(zone, effect, optional, false);
} }
public DealtDamageToSourceTriggeredAbility(Zone zone, Effect effect, boolean optional, boolean enrage) { public DealtDamageToSourceTriggeredAbility(Zone zone, Effect effect, boolean optional, boolean enrage) {
this(zone, effect, optional, enrage, false);
}
public DealtDamageToSourceTriggeredAbility(Zone zone, Effect effect, boolean optional, boolean enrage, boolean useValue) {
super(zone, effect, optional); super(zone, effect, optional);
this.enrage = enrage; this.enrage = enrage;
this.useValue = useValue;
this.usedForCombatDamageStep = false;
} }
public DealtDamageToSourceTriggeredAbility(final DealtDamageToSourceTriggeredAbility ability) { public DealtDamageToSourceTriggeredAbility(final DealtDamageToSourceTriggeredAbility ability) {
super(ability); super(ability);
this.enrage = ability.enrage; this.enrage = ability.enrage;
this.useValue = ability.useValue;
this.usedForCombatDamageStep = ability.usedForCombatDamageStep;
} }
@Override @Override
@ -62,16 +73,32 @@ public class DealtDamageToSourceTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkEventType(GameEvent event, Game game) { public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DAMAGED_CREATURE; return event.getType() == GameEvent.EventType.DAMAGED_CREATURE || event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST;
} }
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(getSourceId())) { if (event.getType() == GameEvent.EventType.DAMAGED_CREATURE && event.getTargetId().equals(getSourceId())) {
for (Effect effect : this.getEffects()) { if (useValue) {
effect.setValue("damage", event.getAmount()); // TODO: this ability should only trigger once for multiple creatures dealing combat damage.
// If the damaged creature uses the amount (e.g. Boros Reckoner), this will still trigger separately instead of all at once
for (Effect effect : this.getEffects()) {
effect.setValue("damage", event.getAmount());
}
return true;
} else {
if (((DamagedCreatureEvent) event).isCombatDamage()) {
if (!usedForCombatDamageStep) {
usedForCombatDamageStep = true;
return true;
}
} else {
return true;
}
} }
return true; }
if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
usedForCombatDamageStep = false;
} }
return false; return false;
} }