From 568044261c53e982d85d9bca3699a21ad5214ba5 Mon Sep 17 00:00:00 2001 From: JOAC69 Date: Fri, 23 Sep 2016 20:39:58 -0500 Subject: [PATCH] Refactor - remove duplicate TargetPlayerCardsInHand classes and made CardsInTargetHandCount shared --- .../avacynrestored/TibaltTheFiendBlooded.java | 30 +------------ .../mage/sets/dragonsmaze/ToilTrouble.java | 42 +++---------------- .../mage/sets/mastersedition/StormSeeker.java | 38 ++--------------- .../sets/seventhedition/SuddenImpact.java | 38 ++--------------- .../sets/shardsofalara/ViciousShadows.java | 35 +--------------- .../common/CardsInTargetHandCount.java | 36 ++++++++++++++++ 6 files changed, 53 insertions(+), 166 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/dynamicvalue/common/CardsInTargetHandCount.java diff --git a/Mage.Sets/src/mage/sets/avacynrestored/TibaltTheFiendBlooded.java b/Mage.Sets/src/mage/sets/avacynrestored/TibaltTheFiendBlooded.java index f287c8ae69..32783ba762 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/TibaltTheFiendBlooded.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/TibaltTheFiendBlooded.java @@ -32,7 +32,7 @@ import java.util.UUID; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; import mage.abilities.common.PlanswalkerEntersWithLoyalityCountersAbility; -import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.CardsInTargetHandCount; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.Effect; @@ -190,31 +190,3 @@ class TibaltTheFiendBloodedControlEffect extends ContinuousEffectImpl { } } -class CardsInTargetHandCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - if (sourceAbility != null) { - Player player = game.getPlayer(sourceAbility.getFirstTarget()); - if (player != null) { - return player.getHand().size(); - } - } - return 0; - } - - @Override - public DynamicValue copy() { - return new CardsInTargetHandCount(); - } - - @Override - public String getMessage() { - return "cards in that player's hand"; - } - - @Override - public String toString() { - return ""; - } -} diff --git a/Mage.Sets/src/mage/sets/dragonsmaze/ToilTrouble.java b/Mage.Sets/src/mage/sets/dragonsmaze/ToilTrouble.java index e4791770d9..17d3b6c7e6 100644 --- a/Mage.Sets/src/mage/sets/dragonsmaze/ToilTrouble.java +++ b/Mage.Sets/src/mage/sets/dragonsmaze/ToilTrouble.java @@ -28,20 +28,18 @@ package mage.sets.dragonsmaze; -import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Rarity; -import mage.abilities.Ability; -import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.CardsInTargetHandCount; import mage.abilities.effects.Effect; import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DrawCardTargetEffect; import mage.abilities.effects.common.LoseLifeTargetEffect; import mage.cards.SplitCard; -import mage.game.Game; -import mage.players.Player; +import mage.constants.CardType; +import mage.constants.Rarity; import mage.target.TargetPlayer; +import java.util.UUID; + /** * * @author LevelX2 @@ -62,7 +60,7 @@ public class ToilTrouble extends SplitCard { // Trouble // Trouble deals damage to target player equal to the number of cards in that player's hand. - Effect effect = new DamageTargetEffect(new TargetPlayerCardsInHandCount()); + Effect effect = new DamageTargetEffect(new CardsInTargetHandCount()); effect.setText("Trouble deals damage to target player equal to the number of cards in that player's hand"); getRightHalfCard().getSpellAbility().addEffect(effect); getRightHalfCard().getSpellAbility().addTarget(new TargetPlayer()); @@ -78,31 +76,3 @@ public class ToilTrouble extends SplitCard { return new ToilTrouble(this); } } - -class TargetPlayerCardsInHandCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - Player targetPlayer = game.getPlayer(sourceAbility.getFirstTarget()); - if (targetPlayer != null) { - return targetPlayer.getHand().size(); - } - - return 0; - } - - @Override - public DynamicValue copy() { - return new TargetPlayerCardsInHandCount(); - } - - @Override - public String toString() { - return "1"; - } - - @Override - public String getMessage() { - return "target player's cards in hand"; - } -} diff --git a/Mage.Sets/src/mage/sets/mastersedition/StormSeeker.java b/Mage.Sets/src/mage/sets/mastersedition/StormSeeker.java index 0ee4b22b08..5ec51dfd06 100644 --- a/Mage.Sets/src/mage/sets/mastersedition/StormSeeker.java +++ b/Mage.Sets/src/mage/sets/mastersedition/StormSeeker.java @@ -27,18 +27,16 @@ */ package mage.sets.mastersedition; -import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.CardsInTargetHandCount; import mage.abilities.effects.Effect; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.game.Game; -import mage.players.Player; import mage.target.TargetPlayer; +import java.util.UUID; + /** * * @author hanasu @@ -50,7 +48,7 @@ public class StormSeeker extends CardImpl { this.expansionSetCode = "MED"; // Storm Seeker deals damage to target player equal to the number of cards in that player's hand. - Effect effect = new DamageTargetEffect(new TargetPlayerCardsInHandCount()); + Effect effect = new DamageTargetEffect(new CardsInTargetHandCount()); effect.setText("{this} deals damage to target player equal to the number of cards in that player's hand."); this.getSpellAbility().addEffect(effect); this.getSpellAbility().addTarget(new TargetPlayer()); @@ -65,31 +63,3 @@ public class StormSeeker extends CardImpl { return new StormSeeker(this); } } - -class TargetPlayerCardsInHandCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - Player targetPlayer = game.getPlayer(sourceAbility.getFirstTarget()); - if (targetPlayer != null) { - return targetPlayer.getHand().size(); - } - - return 0; - } - - @Override - public DynamicValue copy() { - return new TargetPlayerCardsInHandCount(); - } - - @Override - public String toString() { - return "1"; - } - - @Override - public String getMessage() { - return "target player's cards in hand"; - } -} diff --git a/Mage.Sets/src/mage/sets/seventhedition/SuddenImpact.java b/Mage.Sets/src/mage/sets/seventhedition/SuddenImpact.java index 82dae72cb0..e6ccf44a85 100644 --- a/Mage.Sets/src/mage/sets/seventhedition/SuddenImpact.java +++ b/Mage.Sets/src/mage/sets/seventhedition/SuddenImpact.java @@ -27,18 +27,16 @@ */ package mage.sets.seventhedition; -import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.CardsInTargetHandCount; import mage.abilities.effects.Effect; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.game.Game; -import mage.players.Player; import mage.target.TargetPlayer; +import java.util.UUID; + /** * * @author emerald000 @@ -51,7 +49,7 @@ public class SuddenImpact extends CardImpl { // Sudden Impact deals damage to target player equal to the number of cards in that player's hand. - Effect effect = new DamageTargetEffect(new TargetPlayerCardsInHandCount()); + Effect effect = new DamageTargetEffect(new CardsInTargetHandCount()); effect.setText("{this} deals damage to target player equal to the number of cards in that player's hand."); this.getSpellAbility().addEffect(effect); this.getSpellAbility().addTarget(new TargetPlayer()); @@ -66,31 +64,3 @@ public class SuddenImpact extends CardImpl { return new SuddenImpact(this); } } - -class TargetPlayerCardsInHandCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - Player targetPlayer = game.getPlayer(sourceAbility.getFirstTarget()); - if (targetPlayer != null) { - return targetPlayer.getHand().size(); - } - - return 0; - } - - @Override - public DynamicValue copy() { - return new TargetPlayerCardsInHandCount(); - } - - @Override - public String toString() { - return "1"; - } - - @Override - public String getMessage() { - return "target player's cards in hand"; - } -} diff --git a/Mage.Sets/src/mage/sets/shardsofalara/ViciousShadows.java b/Mage.Sets/src/mage/sets/shardsofalara/ViciousShadows.java index 12c139740d..84f0c4a440 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/ViciousShadows.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/ViciousShadows.java @@ -29,14 +29,11 @@ package mage.sets.shardsofalara; import mage.abilities.Ability; import mage.abilities.common.DiesCreatureTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.common.CardsInTargetHandCount; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.game.Game; -import mage.players.Player; import mage.target.TargetPlayer; import java.util.UUID; @@ -53,7 +50,7 @@ public class ViciousShadows extends CardImpl { // Whenever a creature dies, you may have Vicious Shadows deal damage to target player equal to the number of cards in that player's hand. - Ability ability = new DiesCreatureTriggeredAbility(new DamageTargetEffect(new TargetPlayerCardsInHandCount()), true); + Ability ability = new DiesCreatureTriggeredAbility(new DamageTargetEffect(new CardsInTargetHandCount()), true); ability.addTarget(new TargetPlayer()); this.addAbility(ability); } @@ -67,31 +64,3 @@ public class ViciousShadows extends CardImpl { return new ViciousShadows(this); } } - -class TargetPlayerCardsInHandCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - Player targetPlayer = game.getPlayer(sourceAbility.getFirstTarget()); - if (targetPlayer != null) { - return targetPlayer.getHand().size(); - } - - return 0; - } - - @Override - public DynamicValue copy() { - return new TargetPlayerCardsInHandCount(); - } - - @Override - public String toString() { - return "1"; - } - - @Override - public String getMessage() { - return "target player's cards in hand"; - } -} diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/CardsInTargetHandCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CardsInTargetHandCount.java new file mode 100644 index 0000000000..dd7ac467d9 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CardsInTargetHandCount.java @@ -0,0 +1,36 @@ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.players.Player; + +public class CardsInTargetHandCount implements DynamicValue { + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + if (sourceAbility != null) { + Player player = game.getPlayer(sourceAbility.getFirstTarget()); + if (player != null) { + return player.getHand().size(); + } + } + return 0; + } + + @Override + public DynamicValue copy() { + return new CardsInTargetHandCount(); + } + + @Override + public String getMessage() { + return "cards in that player's hand"; + } + + @Override + public String toString() { + return ""; + } +}