From 810434932bd972ce3599f72e51c3b754be1168a8 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 10 Jul 2014 08:52:21 +0200 Subject: [PATCH] * Planeswalker - Changed handling of LoyayltyAbilities to a times used based handling. --- .../costs/common/PayLoyaltyCost.java | 6 +++--- .../costs/common/PayVariableLoyaltyCost.java | 2 +- Mage/src/mage/game/permanent/Permanent.java | 5 +++-- .../mage/game/permanent/PermanentImpl.java | 19 ++++++++++++------- Mage/src/mage/players/Player.java | 2 ++ Mage/src/mage/players/PlayerImpl.java | 14 ++++++++++++++ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Mage/src/mage/abilities/costs/common/PayLoyaltyCost.java b/Mage/src/mage/abilities/costs/common/PayLoyaltyCost.java index 5bfeff317d..f2c8b3daf6 100644 --- a/Mage/src/mage/abilities/costs/common/PayLoyaltyCost.java +++ b/Mage/src/mage/abilities/costs/common/PayLoyaltyCost.java @@ -60,19 +60,19 @@ public class PayLoyaltyCost extends CostImpl { @Override public boolean canPay(UUID sourceId, UUID controllerId, Game game) { Permanent planeswalker = game.getPermanent(sourceId); - return planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && !planeswalker.isLoyaltyUsed(); + return planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game); } @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { Permanent planeswalker = game.getPermanent(sourceId); - if (planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && !planeswalker.isLoyaltyUsed()) { + if (planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) { if (amount > 0) { planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount)); } else if (amount < 0) { planeswalker.getCounters().removeCounter(CounterType.LOYALTY, Math.abs(amount)); } - planeswalker.setLoyaltyUsed(true); + planeswalker.addLoyaltyUsed(); this.paid = true; } return paid; diff --git a/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java b/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java index bedeffa6b6..f15617a674 100644 --- a/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java +++ b/Mage/src/mage/abilities/costs/common/PayVariableLoyaltyCost.java @@ -59,7 +59,7 @@ public class PayVariableLoyaltyCost extends VariableCostImpl { @Override public boolean canPay(UUID sourceId, UUID controllerId, Game game) { Permanent planeswalker = game.getPermanent(sourceId); - return planeswalker!= null && !planeswalker.isLoyaltyUsed(); + return planeswalker!= null && planeswalker.canLoyaltyBeUsed(game); } @Override diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 75bf94ea68..38f234c723 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -116,8 +116,9 @@ public interface Permanent extends Card, Controllable { void removeAllAbilities(UUID sourceId, Game game); - void setLoyaltyUsed(boolean used); - boolean isLoyaltyUsed(); + void addLoyaltyUsed(); + boolean canLoyaltyBeUsed(Game game); + public void resetControl(); boolean changeControllerId(UUID controllerId, Game game); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index 53b7b6e9a7..193bc352b7 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -92,7 +92,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { protected int minBlockedBy = 1; // maximal number of creatures the creature can be blocked by 0 = no restriction protected int maxBlockedBy = 0; - protected boolean loyaltyUsed; protected boolean deathtouched; protected List attachments = new ArrayList<>(); protected Map> connectedCards = new HashMap<>(); @@ -100,6 +99,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { protected UUID attachedTo; protected UUID pairedCard; protected List markedDamage; + protected int timesLoyaltyUsed = 0; private static final List emptyList = Collections.unmodifiableList(new ArrayList()); @@ -128,7 +128,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { this.attacking = permanent.attacking; this.blocking = permanent.blocking; this.maxBlocks = permanent.maxBlocks; - this.loyaltyUsed = permanent.loyaltyUsed; this.deathtouched = permanent.deathtouched; this.attachments.addAll(permanent.attachments); for (Map.Entry> entry: permanent.connectedCards.entrySet()) { @@ -149,6 +148,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { this.transformed = permanent.transformed; this.monstrous = permanent.monstrous; this.pairedCard = permanent.pairedCard; + this.timesLoyaltyUsed = permanent.timesLoyaltyUsed; } @Override @@ -276,7 +276,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { @Override public void endOfTurn(Game game) { this.damage = 0; - this.loyaltyUsed = false; + this.timesLoyaltyUsed = 0; this.turnsOnBattlefield++; this.deathtouched = false; dealtDamageByThisTurn = null; @@ -286,15 +286,20 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { } @Override - public void setLoyaltyUsed(boolean used) { - this.loyaltyUsed = used; + public void addLoyaltyUsed() { + this.timesLoyaltyUsed++; } @Override - public boolean isLoyaltyUsed() { - return this.loyaltyUsed; + public boolean canLoyaltyBeUsed(Game game) { + Player controller = game.getPlayer(controllerId); + if (controller != null) { + return controller.getLoyaltyUsePerTurn() > timesLoyaltyUsed; + } + return false; } + @Override public boolean isTapped() { return tapped; diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 75903526a0..2df689ddfe 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -119,6 +119,8 @@ public interface Player extends MageItem, Copyable { int getLandsPlayed(); int getLandsPerTurn(); void setLandsPerTurn(int landsPerTurn); + int getLoyaltyUsePerTurn(); + void setLoyaltyUsePerTurn(int loyaltyUsePerTurn); int getMaxHandSize(); void setMaxHandSize(int maxHandSize); int getMaxAttackedBy(); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 55a0202ec7..dfdfb02b55 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -142,6 +142,7 @@ public abstract class PlayerImpl implements Player, Serializable { protected Counters counters; protected int landsPlayed; protected int landsPerTurn = 1; + protected int loyaltyUsePerTurn = 1; protected int maxHandSize = 7; protected int maxAttackedBy = Integer.MAX_VALUE; protected ManaPool manaPool; @@ -230,6 +231,7 @@ public abstract class PlayerImpl implements Player, Serializable { this.landsPlayed = player.landsPlayed; this.landsPerTurn = player.landsPerTurn; + this.loyaltyUsePerTurn = player.loyaltyUsePerTurn; this.maxHandSize = player.maxHandSize; this.maxAttackedBy = player.maxAttackedBy; this.manaPool = player.manaPool.copy(); @@ -287,6 +289,7 @@ public abstract class PlayerImpl implements Player, Serializable { this.landsPlayed = player.getLandsPlayed(); this.landsPerTurn = player.getLandsPerTurn(); + this.loyaltyUsePerTurn = player.getLoyaltyUsePerTurn(); this.maxHandSize = player.getMaxHandSize(); this.maxAttackedBy = player.getMaxAttackedBy(); this.manaPool = player.getManaPool().copy(); @@ -377,6 +380,7 @@ public abstract class PlayerImpl implements Player, Serializable { public void reset() { this.abilities.clear(); this.landsPerTurn = 1; + this.loyaltyUsePerTurn = 1; this.maxHandSize = 7; this.maxAttackedBy = Integer.MAX_VALUE; this.canGainLife = true; @@ -1457,6 +1461,16 @@ public abstract class PlayerImpl implements Player, Serializable { this.landsPerTurn = landsPerTurn; } + @Override + public int getLoyaltyUsePerTurn() { + return this.loyaltyUsePerTurn; + } + + @Override + public void setLoyaltyUsePerTurn(int loyaltyUsePerTurn) { + this.loyaltyUsePerTurn = loyaltyUsePerTurn; + } + @Override public int getMaxHandSize() { return maxHandSize;