Refactor - remove duplicate TargetPlayerCardsInHand classes and made CardsInTargetHandCount shared

This commit is contained in:
JOAC69 2016-09-23 20:39:58 -05:00
parent 4cd4dbfcd2
commit 568044261c
6 changed files with 53 additions and 166 deletions

View file

@ -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 "";
}
}

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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 "";
}
}