From a5063ef9ee7d86e1a912cc9ade75436d48575d4b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 21 Jan 2014 17:18:44 +0100 Subject: [PATCH] Minor changes to the framework. --- .../common/SourcePermanentToughnessValue.java | 81 +++++++++++++++++++ .../common/TargetPermanenToughnessValue.java | 81 +++++++++++++++++++ .../common/DiscardEachPlayerEffect.java | 1 - ...dOfTargetPlayerLibraryIntoGraveEffect.java | 13 ++- 4 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 Mage/src/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java create mode 100644 Mage/src/mage/abilities/dynamicvalue/common/TargetPermanenToughnessValue.java diff --git a/Mage/src/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java b/Mage/src/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java new file mode 100644 index 0000000000..288d737265 --- /dev/null +++ b/Mage/src/mage/abilities/dynamicvalue/common/SourcePermanentToughnessValue.java @@ -0,0 +1,81 @@ +/* + * 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.common; + +import java.io.ObjectStreamException; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author LevelX2 + */ + +public class SourcePermanentToughnessValue implements DynamicValue { + + private static final SourcePermanentToughnessValue fINSTANCE = new SourcePermanentToughnessValue(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static SourcePermanentToughnessValue getInstance() { + return fINSTANCE; + } + + @Override + public int calculate(Game game, Ability sourceAbility) { + Permanent sourcePermanent = game.getPermanent(sourceAbility.getSourceId()); + if (sourcePermanent == null) { + sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD); + } + if (sourcePermanent != null) { + return sourcePermanent.getToughness().getValue(); + } + return 0; + } + + @Override + public SourcePermanentToughnessValue copy() { + return new SourcePermanentToughnessValue(); + } + + @Override + public String toString() { + return "X"; + } + + @Override + public String getMessage() { + return "{source}'s toughness"; + } +} diff --git a/Mage/src/mage/abilities/dynamicvalue/common/TargetPermanenToughnessValue.java b/Mage/src/mage/abilities/dynamicvalue/common/TargetPermanenToughnessValue.java new file mode 100644 index 0000000000..6b38f11552 --- /dev/null +++ b/Mage/src/mage/abilities/dynamicvalue/common/TargetPermanenToughnessValue.java @@ -0,0 +1,81 @@ +/* + * 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.common; + +import java.io.ObjectStreamException; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author LevelX2 + */ + +public class TargetPermanenToughnessValue implements DynamicValue { + + private static final TargetPermanenToughnessValue fINSTANCE = new TargetPermanenToughnessValue(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static TargetPermanenToughnessValue getInstance() { + return fINSTANCE; + } + + @Override + public int calculate(Game game, Ability sourceAbility) { + Permanent sourcePermanent = game.getPermanent(sourceAbility.getFirstTarget()); + if (sourcePermanent == null) { + sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getFirstTarget(), Zone.BATTLEFIELD); + } + if (sourcePermanent != null) { + return sourcePermanent.getToughness().getValue(); + } + return 0; + } + + @Override + public TargetPermanenToughnessValue copy() { + return new TargetPermanenToughnessValue(); + } + + @Override + public String toString() { + return "X"; + } + + @Override + public String getMessage() { + return "target creature's toughness"; + } +} diff --git a/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java b/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java index f575070e48..41267f11c9 100644 --- a/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java +++ b/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java @@ -109,7 +109,6 @@ public class DiscardEachPlayerEffect extends OneShotEffect 1 ? "s" : "").toString()); } } } diff --git a/Mage/src/mage/abilities/effects/common/PutTopCardOfTargetPlayerLibraryIntoGraveEffect.java b/Mage/src/mage/abilities/effects/common/PutTopCardOfTargetPlayerLibraryIntoGraveEffect.java index 0ce9fd3a22..4260537f69 100644 --- a/Mage/src/mage/abilities/effects/common/PutTopCardOfTargetPlayerLibraryIntoGraveEffect.java +++ b/Mage/src/mage/abilities/effects/common/PutTopCardOfTargetPlayerLibraryIntoGraveEffect.java @@ -30,6 +30,8 @@ package mage.abilities.effects.common; import mage.constants.Outcome; import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.constants.Zone; @@ -44,9 +46,12 @@ import mage.util.CardUtil; public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffect { - private int numberCards; + private DynamicValue numberCards; public PutTopCardOfTargetPlayerLibraryIntoGraveEffect(int numberCards) { + this(new StaticValue(numberCards)); + } + public PutTopCardOfTargetPlayerLibraryIntoGraveEffect(DynamicValue numberCards) { super(Outcome.Discard); this.numberCards = numberCards; this.staticText = setText(); @@ -66,7 +71,7 @@ public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffec public boolean apply(Game game, Ability source) { Player player = game.getPlayer(targetPointer.getFirst(game, source)); if (player != null) { - int cardsCount = Math.min(numberCards, player.getLibrary().size()); + int cardsCount = Math.min(numberCards.calculate(game, source), player.getLibrary().size()); for (int i = 0; i < cardsCount; i++) { Card card = player.getLibrary().removeFromTop(game); if (card != null) { @@ -80,10 +85,10 @@ public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffec private String setText() { StringBuilder sb = new StringBuilder("Target player puts the top "); - if (numberCards == 1) { + if (numberCards.toString().equals("1")) { sb.append(" card"); } else { - sb.append(CardUtil.numberToText(numberCards)); + sb.append(CardUtil.numberToText(numberCards.toString())); sb.append(" cards"); } sb.append(" of his or her library into his or her graveyard");