From 6458a9591210d74ba1fecce7e445ecb7c381582a Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 3 Feb 2016 00:25:17 +0100 Subject: [PATCH] * Stinkdrinker Bandit - Fixed triggered ability only triggering for controlled creatures now. --- .../sets/morningtide/StinkdrinkerBandit.java | 78 ++++++++++++------- .../main/java/mage/game/combat/Combat.java | 21 +++-- .../main/java/mage/game/events/GameEvent.java | 1 + 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/Mage.Sets/src/mage/sets/morningtide/StinkdrinkerBandit.java b/Mage.Sets/src/mage/sets/morningtide/StinkdrinkerBandit.java index 82fecdc17ad..26ebd772d6a 100644 --- a/Mage.Sets/src/mage/sets/morningtide/StinkdrinkerBandit.java +++ b/Mage.Sets/src/mage/sets/morningtide/StinkdrinkerBandit.java @@ -29,22 +29,20 @@ package mage.sets.morningtide; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.continuous.BoostTargetEffect; +import mage.abilities.keyword.ProwlAbility; import mage.cards.CardImpl; import mage.constants.CardType; -import mage.constants.Rarity; -import mage.abilities.effects.Effect; -import mage.abilities.common.SimpleTriggeredAbility; -import mage.abilities.effects.common.continuous.BoostControlledEffect; -import mage.abilities.keyword.ProwlAbility; import mage.constants.Duration; +import mage.constants.Rarity; import mage.constants.Zone; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.Predicates; -import mage.filter.predicate.mageobject.SubtypePredicate; -import mage.filter.predicate.permanent.AttackingPredicate; -import mage.filter.predicate.permanent.BlockedPredicate; +import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.permanent.Permanent; +import mage.target.targetpointer.FixedTarget; /** * @@ -52,30 +50,20 @@ import mage.game.events.GameEvent; */ public class StinkdrinkerBandit extends CardImpl { - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Attacking and unblocked Rogues"); - - static { - filter.add(new SubtypePredicate("Rogue")); - filter.add(new AttackingPredicate()); - filter.add(Predicates.not(new BlockedPredicate())); - } - public StinkdrinkerBandit(UUID ownerId) { super(ownerId, 80, "Stinkdrinker Bandit", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{3}{B}"); this.expansionSetCode = "MOR"; this.subtype.add("Goblin"); this.subtype.add("Rogue"); - + this.power = new MageInt(2); this.toughness = new MageInt(1); - + // Prowl {1}, {B} (You may cast this for its prowl cost if you dealt combat damage to a player this turn with a Goblin or Rogue.) this.addAbility(new ProwlAbility(this, "{1}{B}")); - + // Whenever a Rogue you control attacks and isn't blocked, it gets +2/+1 until end of turn. - Effect effect = new BoostControlledEffect(2,1,Duration.EndOfTurn, filter); - Ability ability = new SimpleTriggeredAbility(Zone.BATTLEFIELD, GameEvent.EventType.DECLARED_BLOCKERS, effect, "Whenever a Rogue you control attacks and isn't blocked,"); - this.addAbility(ability); + this.addAbility(new StinkdrinkerBanditTriggeredAbility()); } public StinkdrinkerBandit(final StinkdrinkerBandit card) { @@ -86,4 +74,42 @@ public class StinkdrinkerBandit extends CardImpl { public StinkdrinkerBandit copy() { return new StinkdrinkerBandit(this); } -} \ No newline at end of file +} + +class StinkdrinkerBanditTriggeredAbility extends TriggeredAbilityImpl { + + public StinkdrinkerBanditTriggeredAbility() { + super(Zone.BATTLEFIELD, new BoostTargetEffect(2, 1, Duration.EndOfTurn)); + } + + public StinkdrinkerBanditTriggeredAbility(final StinkdrinkerBanditTriggeredAbility ability) { + super(ability); + } + + @Override + public StinkdrinkerBanditTriggeredAbility copy() { + return new StinkdrinkerBanditTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType().equals(EventType.UNBLOCKED_ATTACKER); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + Permanent attackingCreature = game.getPermanent(event.getTargetId()); + if (attackingCreature != null && attackingCreature.hasSubtype("Rogue")) { + for (Effect effect : getEffects()) { + effect.setTargetPointer(new FixedTarget(event.getTargetId())); + } + return true; + } + return false; + } + + @Override + public String getRule() { + return "Whenever a Rogue you control attacks and isn't blocked, it gets +2/+1 until end of turn."; + } +} diff --git a/Mage/src/main/java/mage/game/combat/Combat.java b/Mage/src/main/java/mage/game/combat/Combat.java index f096a50f757..36c055fd186 100644 --- a/Mage/src/main/java/mage/game/combat/Combat.java +++ b/Mage/src/main/java/mage/game/combat/Combat.java @@ -50,6 +50,7 @@ import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterPlaneswalkerPermanent; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.players.Player; import mage.players.PlayerList; @@ -415,6 +416,12 @@ public class Combat implements Serializable, Copyable { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, attackerId, attackerId))) { game.getCombat().selectBlockers(null, game); } + for (UUID attackingCreatureID : game.getCombat().getAttackers()) { + Permanent permanent = game.getPermanent(attackingCreatureID); + if (permanent != null && permanent.getBlocking() == 0) { + game.fireEvent(GameEvent.getEvent(EventType.UNBLOCKED_ATTACKER, attackingCreatureID, attackerId)); + } + } } /** @@ -822,8 +829,8 @@ public class Combat implements Serializable, Copyable { // the creature is blocking a forcing attacker, so the block is ok blockIsValid = true; break CombatGroups; - } else { - // check if the blocker blocks a attacker that must be blocked at least by one and is the only blocker, this block is also valid + } else // check if the blocker blocks a attacker that must be blocked at least by one and is the only blocker, this block is also valid + { if (combatGroup.getBlockers().size() == 1) { if (mustBeBlockedByAtLeastOne.containsKey(forcingAttackerId)) { if (mustBeBlockedByAtLeastOne.get(forcingAttackerId).contains(creatureForcedToBlock.getId())) { @@ -910,7 +917,7 @@ public class Combat implements Serializable, Copyable { * @return */ public boolean checkBlockRestrictionsAfter(Player player, Player controller, Game game) { - // Restrictions applied to blocking creatures + // Restrictions applied to blocking creatures for (UUID blockingCreatureId : this.getBlockers()) { Permanent blockingCreature = game.getPermanent(blockingCreatureId); if (blockingCreature != null) { @@ -998,12 +1005,10 @@ public class Combat implements Serializable, Copyable { if (defendingPlayer != null) { if (defendingPlayer.getMaxAttackedBy() == Integer.MAX_VALUE) { maxAttackers = Integer.MAX_VALUE; + } else if (maxAttackers == Integer.MIN_VALUE) { + maxAttackers = defendingPlayer.getMaxAttackedBy(); } else { - if (maxAttackers == Integer.MIN_VALUE) { - maxAttackers = defendingPlayer.getMaxAttackedBy(); - } else { - maxAttackers += defendingPlayer.getMaxAttackedBy(); - } + maxAttackers += defendingPlayer.getMaxAttackedBy(); } } } diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index 46cce3480e9..2bc2a1ff308 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -185,6 +185,7 @@ public class GameEvent implements Serializable { DECLARED_BLOCKERS, DECLARE_BLOCKER, BLOCKER_DECLARED, CREATURE_BLOCKED, + UNBLOCKED_ATTACKER, SEARCH_LIBRARY, LIBRARY_SEARCHED, SHUFFLE_LIBRARY, LIBRARY_SHUFFLED, ENCHANT_PLAYER, ENCHANTED_PLAYER,