From 0b5a388dbb5078074323999f16ee2f923458e10b Mon Sep 17 00:00:00 2001 From: Timur Nurmagambetov Date: Sun, 1 Jan 2017 18:41:02 +0600 Subject: [PATCH 1/2] Fixed Asylum Visitor and Spined Sliver bugs --- Mage.Sets/src/mage/cards/a/AsylumVisitor.java | 48 ++++++++++---- Mage.Sets/src/mage/cards/s/SpinedSliver.java | 63 +++++++++++++++---- 2 files changed, 87 insertions(+), 24 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AsylumVisitor.java b/Mage.Sets/src/mage/cards/a/AsylumVisitor.java index 7ef03890f3..f7363c8984 100644 --- a/Mage.Sets/src/mage/cards/a/AsylumVisitor.java +++ b/Mage.Sets/src/mage/cards/a/AsylumVisitor.java @@ -29,12 +29,15 @@ package mage.cards.a; import java.util.UUID; import mage.MageInt; +import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.MadnessAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; +import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; @@ -72,12 +75,12 @@ public class AsylumVisitor extends CardImpl { } class AsylumVisitorTriggeredAbility extends TriggeredAbilityImpl { - + public AsylumVisitorTriggeredAbility() { - super(Zone.BATTLEFIELD, null); + super(Zone.BATTLEFIELD, new AsylumVisitorEffect()); } - public AsylumVisitorTriggeredAbility(final AsylumVisitorTriggeredAbility ability) { + public AsylumVisitorTriggeredAbility(final AsylumVisitorTriggeredAbility ability) { super(ability); } @@ -93,21 +96,44 @@ class AsylumVisitorTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { - - Player you = game.getPlayer(this.getControllerId()); Player upkeepPlayer = game.getPlayer(event.getPlayerId()); - - if (you != null && upkeepPlayer != null && upkeepPlayer.getHand().isEmpty()) { - you.drawCards(1, game); - you.loseLife(1, game, false); + if (upkeepPlayer != null && upkeepPlayer.getHand().isEmpty()) { return true; } - return false; } @Override public String getRule() { - return "At the beginning of each player's upkeep, if that player has no cards in hand, you draw a card and you lose 1 life."; + return "At the beginning of each player's upkeep, if that player has no cards in hand, you draw a card and you lose 1 life"; + } +} + +class AsylumVisitorEffect extends OneShotEffect { + + public AsylumVisitorEffect() { + super(Outcome.DrawCard); + this.staticText = "you draw a card and you lose 1 life"; + } + + public AsylumVisitorEffect(final AsylumVisitorEffect effect) { + super(effect); + } + + @Override + public AsylumVisitorEffect copy() { + return new AsylumVisitorEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player you = game.getPlayer(source.getControllerId()); + Player upkeepPlayer = game.getPlayer(game.getActivePlayerId()); + if (you != null && upkeepPlayer != null && upkeepPlayer.getHand().isEmpty()) { + you.drawCards(1, game); + you.loseLife(1, game, false); + return true; + } + return false; } } \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/s/SpinedSliver.java b/Mage.Sets/src/mage/cards/s/SpinedSliver.java index fe77e12403..414ef9adbd 100644 --- a/Mage.Sets/src/mage/cards/s/SpinedSliver.java +++ b/Mage.Sets/src/mage/cards/s/SpinedSliver.java @@ -30,19 +30,19 @@ package mage.cards.s; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.common.BecomesBlockedByCreatureTriggeredAbility; -import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.dynamicvalue.common.BlockedCreatureCount; +import mage.abilities.common.BecomesBlockedAllTriggeredAbility; +import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; -import mage.abilities.effects.common.continuous.BoostSourceEffect; -import mage.abilities.effects.common.continuous.GainAbilityAllEffect; +import mage.abilities.effects.common.continuous.BoostTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.SubtypePredicate; +import mage.game.Game; +import mage.game.combat.CombatGroup; +import mage.target.targetpointer.TargetPointer; /** * @@ -64,14 +64,10 @@ public class SpinedSliver extends CardImpl { this.toughness = new MageInt(2); // Whenever a Sliver becomes blocked, that Sliver gets +1/+1 until end of turn for each creature blocking it. - BlockedCreatureCount value = new BlockedCreatureCount(); - Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn, true); + BlockersCount value = new BlockersCount(); + Effect effect = new BoostTargetEffect(value, value, Duration.EndOfTurn, true); effect.setText("it gets +1/+1 until end of turn for each creature blocking it"); - Ability ability = new BecomesBlockedByCreatureTriggeredAbility(effect, false); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, - new GainAbilityAllEffect(ability, - Duration.WhileOnBattlefield, filter, - "Whenever a Sliver becomes blocked, that Sliver gets +1/+1 until end of turn for each creature blocking it."))); + this.addAbility(new BecomesBlockedAllTriggeredAbility(effect, false, filter, true)); } public SpinedSliver(final SpinedSliver card) { @@ -83,3 +79,44 @@ public class SpinedSliver extends CardImpl { return new SpinedSliver(this); } } + +class BlockersCount implements DynamicValue { + + private String message; + + public BlockersCount() { + this.message = "each creature blocking it"; + } + + public BlockersCount(final BlockersCount blockersCount) { + super(); + this.message = blockersCount.message; + } + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + TargetPointer attacker = effect.getTargetPointer(); + UUID attackerId = attacker.getFirst(game, sourceAbility); + for (CombatGroup combatGroup : game.getCombat().getGroups()) { + if (combatGroup.getAttackers().contains(attackerId)) { + return combatGroup.getBlockers().size(); + } + } + return 0; + } + + @Override + public BlockersCount copy() { + return new BlockersCount(this); + } + + @Override + public String getMessage() { + return message; + } + + @Override + public String toString() { + return "X"; + } +} From 93428aa54e2825eb541e1f497b4037d6ddf2edea Mon Sep 17 00:00:00 2001 From: Timur Nurmagambetov Date: Sun, 1 Jan 2017 20:39:44 +0600 Subject: [PATCH 2/2] mend --- Mage.Sets/src/mage/cards/a/AsylumVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage.Sets/src/mage/cards/a/AsylumVisitor.java b/Mage.Sets/src/mage/cards/a/AsylumVisitor.java index f7363c8984..16b938057d 100644 --- a/Mage.Sets/src/mage/cards/a/AsylumVisitor.java +++ b/Mage.Sets/src/mage/cards/a/AsylumVisitor.java @@ -105,7 +105,7 @@ class AsylumVisitorTriggeredAbility extends TriggeredAbilityImpl { @Override public String getRule() { - return "At the beginning of each player's upkeep, if that player has no cards in hand, you draw a card and you lose 1 life"; + return "At the beginning of each player's upkeep, if that player has no cards in hand, you draw a card and you lose 1 life."; } }