Fixed that creatures or enchantments with triggered abilities that should trigger only once as they or the enhcanted creature blocks (also multiple creatures e.g. Guardian of the Gateless) really only trigger once. They triggered wrongly per blocked creature before.

This commit is contained in:
LevelX2 2014-03-21 14:47:17 +01:00
parent ccd91f0657
commit 63b8890287
15 changed files with 244 additions and 60 deletions

View file

@ -28,7 +28,7 @@
package mage.sets.alarareborn;
import java.util.UUID;
import mage.abilities.common.BlocksAttachedTriggeredAbility;
import mage.abilities.common.BlocksCreatureAttachedTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.common.SkipNextUntapTargetEffect;
@ -63,7 +63,7 @@ public class ShieldOfTheRighteous extends CardImpl<ShieldOfTheRighteous> {
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(VigilanceAbility.getInstance(), AttachmentType.EQUIPMENT)));
// Whenever equipped creature blocks a creature, that creature doesn't untap during its controller's next untap step.
this.addAbility(new BlocksAttachedTriggeredAbility(new SkipNextUntapTargetEffect("that creature"), "equipped", false, false, true));
this.addAbility(new BlocksCreatureAttachedTriggeredAbility(new SkipNextUntapTargetEffect("that creature"), "equipped", false, false, true));
// Equip {2}
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2), new TargetControlledCreaturePermanent()));

View file

@ -33,7 +33,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BlocksTriggeredAbility;
import mage.abilities.common.BlocksCreatureTriggeredAbility;
import mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ReturnToHandTargetEffect;
@ -61,7 +61,7 @@ public class KaijinOfTheVanishingTouch extends CardImpl<KaijinOfTheVanishingTouc
this.addAbility(DefenderAbility.getInstance());
// Whenever Kaijin of the Vanishing Touch blocks a creature, return that creature to its owner's hand at end of combat. (Return it only if it's on the battlefield.)
Ability ability = new BlocksTriggeredAbility(new KaijinOfTheVanishingTouchEffect(), false, true);
Ability ability = new BlocksCreatureTriggeredAbility(new KaijinOfTheVanishingTouchEffect(), false, true);
this.addAbility(ability);
}

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.common.BlocksTriggeredAbility;
import mage.abilities.common.BlocksCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.keyword.VigilanceAbility;
@ -69,7 +69,7 @@ public class BrimazKingOfOreskos extends CardImpl<BrimazKingOfOreskos> {
this.addAbility(new AttacksTriggeredAbility(new CreateTokenEffect(new CatSoldierCreatureToken(), 1, false, true), false));
// Whenever Brimaz blocks a creature, put a 1/1 white Cat Soldier creature token with vigilance onto the battlefield blocking that creature.
this.addAbility(new BlocksTriggeredAbility(new BrimazKingOfOreskosEffect(), false, true));
this.addAbility(new BlocksCreatureTriggeredAbility(new BrimazKingOfOreskosEffect(), false, true));
}
public BrimazKingOfOreskos(final BrimazKingOfOreskos card) {

View file

@ -30,7 +30,7 @@ package mage.sets.conflux;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BlocksTriggeredAbility;
import mage.abilities.common.BlocksCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.VigilanceAbility;
import mage.abilities.keyword.TrampleAbility;
@ -65,7 +65,7 @@ public class Meglonoth extends CardImpl<Meglonoth> {
this.addAbility(TrampleAbility.getInstance());
// Whenever Meglonoth blocks a creature, Meglonoth deals damage to that creature's controller equal to Meglonoth's power.
this.addAbility(new BlocksTriggeredAbility(new MeglonothEffect(), false, true));
this.addAbility(new BlocksCreatureTriggeredAbility(new MeglonothEffect(), false, true));
}

View file

@ -61,7 +61,7 @@ public class FavorOfTheWoods extends CardImpl<FavorOfTheWoods> {
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
// Whenever enchanted creature blocks, you gain 3 life.
this.addAbility(new BlocksAttachedTriggeredAbility(new GainLifeEffect(3), "equipped", false));
this.addAbility(new BlocksAttachedTriggeredAbility(new GainLifeEffect(3), "enchanted", false));
}
public FavorOfTheWoods(final FavorOfTheWoods card) {

View file

@ -31,7 +31,7 @@ import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.common.BlocksTriggeredAbility;
import mage.abilities.common.BlocksCreatureTriggeredAbility;
import mage.abilities.effects.common.SkipNextUntapTargetEffect;
import mage.abilities.keyword.DefenderAbility;
import mage.cards.CardImpl;
@ -51,7 +51,7 @@ public class WallOfFrost extends CardImpl<WallOfFrost> {
this.addAbility(DefenderAbility.getInstance());
// Whenever Wall of Frost blocks a creature, that creature doesn't untap during its controller's next untap step.
this.addAbility(new BlocksTriggeredAbility(new SkipNextUntapTargetEffect("that creature"), false, true));
this.addAbility(new BlocksCreatureTriggeredAbility(new SkipNextUntapTargetEffect("that creature"), false, true));
}
public WallOfFrost(final WallOfFrost card) {

View file

@ -51,8 +51,10 @@ public class GoldenglowMoth extends CardImpl<GoldenglowMoth> {
this.color.setWhite(true);
this.power = new MageInt(0);
this.toughness = new MageInt(1);
// Flying
this.addAbility(FlyingAbility.getInstance());
// Whenever Goldenglow Moth blocks, you may gain 4 life.
this.addAbility(new BlocksTriggeredAbility(new GainLifeEffect(4), true));
}

View file

@ -51,7 +51,9 @@ public class PrideGuardian extends CardImpl<PrideGuardian> {
this.color.setWhite(true);
this.power = new MageInt(0);
this.toughness = new MageInt(3);
this.addAbility(DefenderAbility.getInstance());
// Whenever Pride Guardian blocks, you gain 3 life.
this.addAbility(new BlocksTriggeredAbility(new GainLifeEffect(3), false));
}

View file

@ -50,6 +50,8 @@ public class PsychicMembrane extends CardImpl<PsychicMembrane> {
this.power = new MageInt(0);
this.toughness = new MageInt(3);
this.addAbility(DefenderAbility.getInstance());
// Whenever Psychic Membrane blocks, you may draw a card.
this.addAbility(new BlocksTriggeredAbility(new DrawCardControllerEffect(1), true));
}

View file

@ -52,8 +52,10 @@ public class EliteJavelineer extends CardImpl<EliteJavelineer> {
this.color.setWhite(true);
this.power = new MageInt(2);
this.toughness = new MageInt(2);
// Whenever Elite Javelineer blocks, it deals 1 damage to target attacking creature.
Ability ability = new BlocksTriggeredAbility(new DamageTargetEffect(1), false);
ability.addTarget(new TargetCreaturePermanent(new FilterAttackingCreature()));
ability.addTarget(new TargetCreaturePermanent(new FilterAttackingCreature(), true));
this.addAbility(ability);
}

View file

@ -34,7 +34,7 @@ import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BlocksTriggeredAbility;
import mage.abilities.common.BlocksCreatureTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
import mage.constants.Outcome;
@ -57,7 +57,8 @@ public class LoyalSentry extends CardImpl<LoyalSentry> {
this.power = new MageInt(1);
this.toughness = new MageInt(1);
this.addAbility(new BlocksTriggeredAbility(new LoyalSentryEffect(), false, true));
// When Loyal Sentry blocks a creature, destroy that creature and Loyal Sentry.
this.addAbility(new BlocksCreatureTriggeredAbility(new LoyalSentryEffect(), false, true));
}
public LoyalSentry (final LoyalSentry card) {
@ -82,11 +83,11 @@ class LoyalSentryEffect extends OneShotEffect<LoyalSentryEffect> {
@Override
public boolean apply(Game game, Ability source) {
Permanent p = game.getPermanent(source.getFirstTarget());
Permanent s = game.getPermanent(source.getSourceId());
Permanent p = game.getPermanent(source.getFirstTarget());
if (p != null) {
p.destroy(source.getSourceId(), game, false);
}
Permanent s = game.getPermanent(source.getSourceId());
if (s != null) {
s.destroy(source.getSourceId(), game, false);
}
@ -98,4 +99,4 @@ class LoyalSentryEffect extends OneShotEffect<LoyalSentryEffect> {
return new LoyalSentryEffect(this);
}
}
}

View file

@ -1,6 +1,29 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
@ -10,37 +33,21 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author garnold
*/
public class BlocksAttachedTriggeredAbility extends TriggeredAbilityImpl<BlocksAttachedTriggeredAbility>{
private boolean setFixedTargetPointer;
private String attachedDescription;
private boolean setFixedTargetPointerToBlocked;
public BlocksAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional) {
this(effect, attachedDescription, optional, false);
}
public BlocksAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
}
public BlocksAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer, boolean setFixedTargetPointerToBlocked) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
this.setFixedTargetPointerToBlocked = setFixedTargetPointerToBlocked;
}
public BlocksAttachedTriggeredAbility(final BlocksAttachedTriggeredAbility ability) {
super(ability);
this.setFixedTargetPointer = ability.setFixedTargetPointer;
this.attachedDescription = ability.attachedDescription;
}
@ -51,19 +58,9 @@ public class BlocksAttachedTriggeredAbility extends TriggeredAbilityImpl<BlocksA
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) {
Permanent p = game.getPermanent(event.getSourceId());
if (p != null && p.getAttachments().contains(this.getSourceId())) {
if (setFixedTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
}
if (setFixedTargetPointerToBlocked) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
if (event.getType() == GameEvent.EventType.DECLARED_BLOCKERS) {
Permanent attachment = game.getPermanent(this.getSourceId());
if (attachment != null && attachment.getAttachedTo() != null && game.getCombat().getBlockers().contains(attachment.getAttachedTo())) {
return true;
}
}

View file

@ -0,0 +1,102 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* 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.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public class BlocksCreatureAttachedTriggeredAbility extends TriggeredAbilityImpl<BlocksCreatureAttachedTriggeredAbility>{
private boolean setFixedTargetPointer;
private String attachedDescription;
private boolean setFixedTargetPointerToBlocked;
public BlocksCreatureAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional) {
this(effect, attachedDescription, optional, false);
}
public BlocksCreatureAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
}
public BlocksCreatureAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer, boolean setFixedTargetPointerToBlocked) {
super(Zone.BATTLEFIELD, effect, optional);
this.setFixedTargetPointer = setFixedTargetPointer;
this.attachedDescription = attachedDescription;
this.setFixedTargetPointerToBlocked = setFixedTargetPointerToBlocked;
}
public BlocksCreatureAttachedTriggeredAbility(final BlocksCreatureAttachedTriggeredAbility ability) {
super(ability);
this.setFixedTargetPointer = ability.setFixedTargetPointer;
this.attachedDescription = ability.attachedDescription;
}
@Override
public BlocksCreatureAttachedTriggeredAbility copy() {
return new BlocksCreatureAttachedTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) {
Permanent p = game.getPermanent(event.getSourceId());
if (p != null && p.getAttachments().contains(this.getSourceId())) {
if (setFixedTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
}
if (setFixedTargetPointerToBlocked) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever " + attachedDescription + " creature blocks a creature, " + super.getRule();
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* 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.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public class BlocksCreatureTriggeredAbility extends TriggeredAbilityImpl<BlocksCreatureTriggeredAbility> {
private boolean setTargetPointer;
public BlocksCreatureTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public BlocksCreatureTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
}
public BlocksCreatureTriggeredAbility(final BlocksCreatureTriggeredAbility ability) {
super(ability);
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.BLOCKER_DECLARED && event.getSourceId().equals(this.getSourceId())) {
if (setTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} blocks a creature, " + super.getRule();
}
@Override
public BlocksCreatureTriggeredAbility copy() {
return new BlocksCreatureTriggeredAbility(this);
}
}

View file

@ -33,7 +33,6 @@ import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -41,7 +40,7 @@ import mage.target.targetpointer.FixedTarget;
*/
public class BlocksTriggeredAbility extends TriggeredAbilityImpl<BlocksTriggeredAbility> {
private boolean fixedTargetPointer;
// private boolean fixedTargetPointer;
public BlocksTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
@ -49,22 +48,17 @@ public class BlocksTriggeredAbility extends TriggeredAbilityImpl<BlocksTriggered
public BlocksTriggeredAbility(Effect effect, boolean optional, boolean fixedTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.fixedTargetPointer = fixedTargetPointer;
// this.fixedTargetPointer = fixedTargetPointer;
}
public BlocksTriggeredAbility(final BlocksTriggeredAbility ability) {
super(ability);
this.fixedTargetPointer = ability.fixedTargetPointer;
// this.fixedTargetPointer = ability.fixedTargetPointer;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.BLOCKER_DECLARED && event.getSourceId().equals(this.getSourceId())) {
if (fixedTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
}
if (event.getType() == EventType.DECLARED_BLOCKERS && game.getCombat().getBlockers().contains(this.getSourceId())) {
return true;
}
return false;
@ -72,7 +66,7 @@ public class BlocksTriggeredAbility extends TriggeredAbilityImpl<BlocksTriggered
@Override
public String getRule() {
return "Whenever {this} blocks" + (fixedTargetPointer ? " a creature" : "") + ", " + super.getRule();
return "Whenever {this} blocks, " + super.getRule();
}
@Override