From fc1a1523c50147f3f825f768fd465a0021e8c4d1 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 13 Jul 2016 17:04:52 +0200 Subject: [PATCH] * Gideon, Champion of Justice - Fixed that the P/T did not change if loyality counters were added after using the 0 ability. --- .../gatecrash/GideonChampionOfJustice.java | 3 +- .../test/cards/planeswalker/GideonTest.java | 18 +++-- .../dynamicvalue/LockedInDynamicValue.java | 77 +++++++++++++++++++ .../BecomesCreatureSourceEffect.java | 4 +- 4 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/dynamicvalue/LockedInDynamicValue.java diff --git a/Mage.Sets/src/mage/sets/gatecrash/GideonChampionOfJustice.java b/Mage.Sets/src/mage/sets/gatecrash/GideonChampionOfJustice.java index 75875b97e91..ca21e65092f 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/GideonChampionOfJustice.java +++ b/Mage.Sets/src/mage/sets/gatecrash/GideonChampionOfJustice.java @@ -32,6 +32,7 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; import mage.abilities.common.PlanswalkerEntersWithLoyalityCountersAbility; +import mage.abilities.dynamicvalue.LockedInDynamicValue; import mage.abilities.dynamicvalue.common.CountersCount; import mage.abilities.dynamicvalue.common.PermanentsTargetOpponentControlsCount; import mage.abilities.effects.OneShotEffect; @@ -71,7 +72,7 @@ public class GideonChampionOfJustice extends CardImpl { this.addAbility(ability1); // 0: Until end of turn, Gideon becomes an indestructible Human Soldier creature with power and toughness each equal to the number of loyalty counters on him. He's still a planeswalker. Prevent all damage that would be dealt to him this turn. - CountersCount loyaltyCount = new CountersCount(CounterType.LOYALTY); + LockedInDynamicValue loyaltyCount = new LockedInDynamicValue(new CountersCount(CounterType.LOYALTY)); LoyaltyAbility ability2 = new LoyaltyAbility(new BecomesCreatureSourceEffect( new GideonChampionOfJusticeToken(), "planeswalker", Duration.EndOfTurn, false, false, loyaltyCount, loyaltyCount), 0); ability2.addEffect(new PreventAllDamageToSourceEffect(Duration.EndOfTurn)); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/planeswalker/GideonTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/planeswalker/GideonTest.java index 78d4d81a443..ef3fe0da492 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/planeswalker/GideonTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/planeswalker/GideonTest.java @@ -82,7 +82,7 @@ public class GideonTest extends CardTestPlayerBase { */ @Test public void testGideonChampionOfJusticeSecondAbility() { - + addCard(Zone.BATTLEFIELD, playerA, "Plains", 4); /* Gideon, Champion of Justice {2}{W}{W} - 4 Loyalty +1: Put a loyalty counter on Gideon, Champion of Justice for each creature target opponent controls. @@ -94,16 +94,24 @@ public class GideonTest extends CardTestPlayerBase { -15: Exile all other permanents. */ - addCard(Zone.BATTLEFIELD, playerA, "Gideon, Champion of Justice", 1); + addCard(Zone.HAND, playerA, "Gideon, Champion of Justice", 1); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 2); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gideon, Champion of Justice"); activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+0: Until end of turn"); - setStopAt(1, PhaseStep.BEGIN_COMBAT); + + activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: Put a loyalty counter on", playerB); + + activateAbility(5, PhaseStep.PRECOMBAT_MAIN, playerA, "+0: Until end of turn"); + + setStopAt(5, PhaseStep.BEGIN_COMBAT); execute(); assertGraveyardCount(playerA, "Gideon, Champion of Justice", 0); assertPermanentCount(playerA, "Gideon, Champion of Justice", 1); - assertPowerToughness(playerA, "Gideon, Champion of Justice", 4, 4); - assertCounterCount(playerA, "Gideon, Champion of Justice", CounterType.LOYALTY, 4); + assertCounterCount(playerA, "Gideon, Champion of Justice", CounterType.LOYALTY, 7); + assertPowerToughness(playerA, "Gideon, Champion of Justice", 7, 7); } diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/LockedInDynamicValue.java b/Mage/src/main/java/mage/abilities/dynamicvalue/LockedInDynamicValue.java new file mode 100644 index 00000000000..81e2a9a1b51 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/LockedInDynamicValue.java @@ -0,0 +1,77 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.abilities.dynamicvalue; + +import mage.abilities.Ability; +import mage.abilities.effects.Effect; +import mage.game.Game; + +/** + * The first calculated value is used as long as the class instance is in use + * + * IMPORTANT: If used the ability / effect that uses a locked in dynamic value + * has to really copy the dnamic value in its copy method (not reference) + * + * @author LevelX2 + */ +public class LockedInDynamicValue implements DynamicValue { + + private boolean valueChecked = false; + private int lockedInValue; + private final DynamicValue basicDynamicValue; + + public LockedInDynamicValue(DynamicValue dynamicValue) { + this.basicDynamicValue = dynamicValue; + } + + public LockedInDynamicValue(LockedInDynamicValue dynamicValue, final boolean copy) { + this.basicDynamicValue = dynamicValue.basicDynamicValue; + this.lockedInValue = dynamicValue.lockedInValue; + this.valueChecked = dynamicValue.valueChecked; + } + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + if (!valueChecked) { + lockedInValue = basicDynamicValue.calculate(game, sourceAbility, effect); + valueChecked = true; + } + return lockedInValue; + } + + @Override + public LockedInDynamicValue copy() { + return new LockedInDynamicValue(this, true); + } + + @Override + public String getMessage() { + return basicDynamicValue.getMessage(); + } + +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureSourceEffect.java index 507fa018039..2a04f2e1a11 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureSourceEffect.java @@ -77,8 +77,8 @@ public class BecomesCreatureSourceEffect extends ContinuousEffectImpl implements this.token = effect.token.copy(); this.type = effect.type; this.losePreviousTypes = effect.losePreviousTypes; - this.power = effect.power; - this.toughness = effect.toughness; + this.power = effect.power.copy(); + this.toughness = effect.toughness.copy(); } @Override