From 5d0c7862c60425d1c48cad3d12a4ee550d09129a Mon Sep 17 00:00:00 2001 From: North Date: Fri, 25 May 2012 21:28:58 +0300 Subject: [PATCH] Fixed BecomesBlocked triggered abilities --- .../mage/sets/innistrad/AshmouthHound.java | 4 +- .../mage/sets/magic2010/InfernoElemental.java | 4 +- .../scarsofmirrodin/EngulfingSlagwurm.java | 7 +- ...omesBlockedByCreatureTriggeredAbility.java | 71 +++++++++++++++++ .../BecomesBlockedTriggeredAbility.java | 7 +- ...omesBlockedByCreatureTriggeredAbility.java | 79 +++++++++++++++++++ ...locksOrBecomesBlockedTriggeredAbility.java | 44 +++++++---- Mage/src/mage/game/combat/CombatGroup.java | 6 +- Mage/src/mage/game/events/GameEvent.java | 29 +++---- 9 files changed, 208 insertions(+), 43 deletions(-) create mode 100644 Mage/src/mage/abilities/common/BecomesBlockedByCreatureTriggeredAbility.java create mode 100644 Mage/src/mage/abilities/common/BlocksOrBecomesBlockedByCreatureTriggeredAbility.java diff --git a/Mage.Sets/src/mage/sets/innistrad/AshmouthHound.java b/Mage.Sets/src/mage/sets/innistrad/AshmouthHound.java index 605f619ea0e..9a5b2c695f3 100644 --- a/Mage.Sets/src/mage/sets/innistrad/AshmouthHound.java +++ b/Mage.Sets/src/mage/sets/innistrad/AshmouthHound.java @@ -31,7 +31,7 @@ import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.MageInt; -import mage.abilities.common.BlocksOrBecomesBlockedTriggeredAbility; +import mage.abilities.common.BlocksOrBecomesBlockedByCreatureTriggeredAbility; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; @@ -52,7 +52,7 @@ public class AshmouthHound extends CardImpl { this.toughness = new MageInt(1); // Whenever Ashmouth Hound blocks or becomes blocked by a creature, Ashmouth Hound deals 1 damage to that creature. - this.addAbility(new BlocksOrBecomesBlockedTriggeredAbility(new DamageTargetEffect(1, true, "that creature"), false)); + this.addAbility(new BlocksOrBecomesBlockedByCreatureTriggeredAbility(new DamageTargetEffect(1, true, "that creature"), false)); } public AshmouthHound(final AshmouthHound card) { diff --git a/Mage.Sets/src/mage/sets/magic2010/InfernoElemental.java b/Mage.Sets/src/mage/sets/magic2010/InfernoElemental.java index c298888fda0..fcb6a7e0624 100644 --- a/Mage.Sets/src/mage/sets/magic2010/InfernoElemental.java +++ b/Mage.Sets/src/mage/sets/magic2010/InfernoElemental.java @@ -31,7 +31,7 @@ import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.MageInt; -import mage.abilities.common.BlocksOrBecomesBlockedTriggeredAbility; +import mage.abilities.common.BlocksOrBecomesBlockedByCreatureTriggeredAbility; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; @@ -51,7 +51,7 @@ public class InfernoElemental extends CardImpl { this.toughness = new MageInt(4); // Whenever Inferno Elemental blocks or becomes blocked by a creature, Inferno Elemental deals 3 damage to that creature. - this.addAbility(new BlocksOrBecomesBlockedTriggeredAbility(new DamageTargetEffect(3, true, "that creature"), false)); + this.addAbility(new BlocksOrBecomesBlockedByCreatureTriggeredAbility(new DamageTargetEffect(3, true, "that creature"), false)); } public InfernoElemental(final InfernoElemental card) { diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/EngulfingSlagwurm.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/EngulfingSlagwurm.java index fd1a4a5e595..e264c2ed1aa 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/EngulfingSlagwurm.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/EngulfingSlagwurm.java @@ -36,10 +36,9 @@ import mage.Constants.Rarity; import mage.MageInt; import mage.MageObject; import mage.abilities.Ability; -import mage.abilities.common.BlocksOrBecomesBlockedTriggeredAbility; +import mage.abilities.common.BlocksOrBecomesBlockedByCreatureTriggeredAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DestroyTargetEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.game.Game; import mage.players.Player; @@ -57,7 +56,9 @@ public class EngulfingSlagwurm extends CardImpl { this.color.setGreen(true); this.power = new MageInt(7); this.toughness = new MageInt(7); - Ability ability = new BlocksOrBecomesBlockedTriggeredAbility(new DestroyTargetEffect(), false); + + // Whenever Engulfing Slagwurm blocks or becomes blocked by a creature, destroy that creature. You gain life equal to that creature's toughness. + Ability ability = new BlocksOrBecomesBlockedByCreatureTriggeredAbility(new DestroyTargetEffect(), false); ability.addEffect(new EngulfingSlagwurmEffect()); this.addAbility(ability); } diff --git a/Mage/src/mage/abilities/common/BecomesBlockedByCreatureTriggeredAbility.java b/Mage/src/mage/abilities/common/BecomesBlockedByCreatureTriggeredAbility.java new file mode 100644 index 00000000000..613594b9766 --- /dev/null +++ b/Mage/src/mage/abilities/common/BecomesBlockedByCreatureTriggeredAbility.java @@ -0,0 +1,71 @@ +/* + * 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.target.targetpointer.FixedTarget; + +/** + * + * @author North + */ +public class BecomesBlockedByCreatureTriggeredAbility extends TriggeredAbilityImpl { + + public BecomesBlockedByCreatureTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + public BecomesBlockedByCreatureTriggeredAbility(final BecomesBlockedByCreatureTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED && event.getTargetId().equals(this.getSourceId())) { + for (Effect effect : this.getEffects()) { + effect.setTargetPointer(new FixedTarget(event.getSourceId())); + } + return true; + } + return false; + } + + @Override + public String getRule() { + return "Whenever {this} becomes blocked by a creature, " + super.getRule(); + } + + @Override + public BecomesBlockedByCreatureTriggeredAbility copy() { + return new BecomesBlockedByCreatureTriggeredAbility(this); + } +} diff --git a/Mage/src/mage/abilities/common/BecomesBlockedTriggeredAbility.java b/Mage/src/mage/abilities/common/BecomesBlockedTriggeredAbility.java index 0bacbc92832..ef2c9426e12 100644 --- a/Mage/src/mage/abilities/common/BecomesBlockedTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/BecomesBlockedTriggeredAbility.java @@ -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.common.TargetCreaturePermanent; /** * @@ -43,7 +42,6 @@ public class BecomesBlockedTriggeredAbility extends TriggeredAbilityImpl { + + public BlocksOrBecomesBlockedByCreatureTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + public BlocksOrBecomesBlockedByCreatureTriggeredAbility(final BlocksOrBecomesBlockedByCreatureTriggeredAbility ability) { + super(ability); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) { + if (event.getSourceId().equals(this.getSourceId())) { + for (Effect effect : this.getEffects()) { + effect.setTargetPointer(new FixedTarget(event.getTargetId())); + } + return true; + } + if (event.getTargetId().equals(this.getSourceId())) { + for (Effect effect : this.getEffects()) { + effect.setTargetPointer(new FixedTarget(event.getSourceId())); + } + return true; + } + } + return false; + } + + @Override + public String getRule() { + return "Whenever {this} blocks or becomes blocked by a creature, " + super.getRule(); + } + + @Override + public BlocksOrBecomesBlockedByCreatureTriggeredAbility copy() { + return new BlocksOrBecomesBlockedByCreatureTriggeredAbility(this); + } +} diff --git a/Mage/src/mage/abilities/common/BlocksOrBecomesBlockedTriggeredAbility.java b/Mage/src/mage/abilities/common/BlocksOrBecomesBlockedTriggeredAbility.java index 7c104d0226d..9f2d9f8c2e6 100644 --- a/Mage/src/mage/abilities/common/BlocksOrBecomesBlockedTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/BlocksOrBecomesBlockedTriggeredAbility.java @@ -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,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; /** * @@ -28,19 +50,9 @@ public class BlocksOrBecomesBlockedTriggeredAbility extends TriggeredAbilityImpl @Override public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == EventType.BLOCKER_DECLARED) { - if (event.getSourceId().equals(this.getSourceId())) { - for (Effect effect : this.getEffects()) { - effect.setTargetPointer(new FixedTarget(event.getTargetId())); - } - return true; - } - if (event.getTargetId().equals(this.getSourceId())) { - for (Effect effect : this.getEffects()) { - effect.setTargetPointer(new FixedTarget(event.getSourceId())); - } - return true; - } + if ((event.getType() == EventType.BLOCKER_DECLARED || event.getType() == EventType.CREATURE_BLOCKED) + && event.getSourceId().equals(this.getSourceId())) { + return true; } return false; } diff --git a/Mage/src/mage/game/combat/CombatGroup.java b/Mage/src/mage/game/combat/CombatGroup.java index 9fa6453e800..4b3f3adc8bf 100644 --- a/Mage/src/mage/game/combat/CombatGroup.java +++ b/Mage/src/mage/game/combat/CombatGroup.java @@ -364,7 +364,6 @@ public class CombatGroup implements Serializable, Copyable { lethalDamage = attacker.getToughness().getValue() - attacker.getDamage(); if (lethalDamage >= damage) { assigned.put(attackerId, damage); - damage = 0; break; } int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + attacker.getName(), game); @@ -518,6 +517,11 @@ public class CombatGroup implements Serializable, Copyable { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BLOCKER_DECLARED, attackerId, blockerId, players.get(blockerId))); } } + if(!blockers.isEmpty()) { + for (UUID attackerId: attackers) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, attackerId, null)); + } + } } @Override diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index ed585ee165d..a6342bc2cd3 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -88,7 +88,7 @@ public class GameEvent { PLAY_LAND, LAND_PLAYED, CAST_SPELL, SPELL_CAST, ACTIVATE_ABILITY, ACTIVATED_ABILITY, - MANA_ADDED, MANA_PAYED, + MANA_ADDED, MANA_PAYED, LOSES, LOST, WINS, TARGET, TARGETED, COUNTER, COUNTERED, @@ -96,9 +96,10 @@ public class GameEvent { DECLARE_ATTACKER, ATTACKER_DECLARED, DECLARING_BLOCKERS, DECLARED_BLOCKERS, DECLARE_BLOCKER, BLOCKER_DECLARED, + CREATURE_BLOCKED, SEARCH_LIBRARY, LIBRARY_SEARCHED, - SHUFFLE_LIBRARY, LIBRARY_SHUFFLED, - ENCHANT_PLAYER, ENCHANTED_PLAYER, + SHUFFLE_LIBRARY, LIBRARY_SHUFFLED, + ENCHANT_PLAYER, ENCHANTED_PLAYER, //permanent events ENTERS_THE_BATTLEFIELD, @@ -121,8 +122,8 @@ public class GameEvent { COUNTER_REMOVED, LOSE_CONTROL, LOST_CONTROL, GAIN_CONTROL, GAINED_CONTROL, - CREATE_TOKEN, - REGENERATE, REGENERATED, + CREATE_TOKEN, + REGENERATE, REGENERATED, //combat events COMBAT_DAMAGE_APPLIED, @@ -157,9 +158,9 @@ public class GameEvent { public static GameEvent getEvent(EventType type, UUID targetId, UUID playerId, String data, int amount) { GameEvent event = getEvent(type, targetId,playerId); - event.setAmount(amount); - event.setData(data); - return event; + event.setAmount(amount); + event.setData(data); + return event; } public EventType getType() { @@ -198,11 +199,11 @@ public class GameEvent { this.data = data; } - public Zone getZone() { - return zone; - } + public Zone getZone() { + return zone; + } - public void setZone(Zone zone) { - this.zone = zone; - } + public void setZone(Zone zone) { + this.zone = zone; + } }