From d06b3a924be98657d867683239fdaf7dbb4a7156 Mon Sep 17 00:00:00 2001 From: Loki Date: Sun, 16 Jan 2011 18:53:59 +0200 Subject: [PATCH] Dymamic Values, Sigil of Distinction as example, tooltip is generated badly --- .../shardsofalara/SigilofDistinction.java | 99 +++++++++++++++++++ .../src/mage/sets/zendikar/KorSkyfisher.java | 73 ++++++++++++++ .../abilities/dynamicvalue/DynamicValue.java | 11 +++ .../dynamicvalue/common/CountersCount.java | 38 +++++++ .../dynamicvalue/common/StaticValue.java | 33 +++++++ .../effects/common/BoostEquippedEffect.java | 30 ++++-- 6 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java create mode 100644 Mage.Sets/src/mage/sets/zendikar/KorSkyfisher.java create mode 100644 Mage/src/mage/abilities/dynamicvalue/DynamicValue.java create mode 100644 Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java create mode 100644 Mage/src/mage/abilities/dynamicvalue/common/StaticValue.java diff --git a/Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java b/Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java new file mode 100644 index 00000000000..13a30f1c592 --- /dev/null +++ b/Mage.Sets/src/mage/sets/shardsofalara/SigilofDistinction.java @@ -0,0 +1,99 @@ +/* + * 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.sets.shardsofalara; + +import java.util.UUID; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.CountersCount; +import mage.abilities.common.EntersBattlefieldAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.common.RemoveCountersSourceCost; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.BoostEquippedEffect; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author Loki + */ +public class SigilofDistinction extends CardImpl { + + public SigilofDistinction (UUID ownerId) { + super(ownerId, 219, "Sigil of Distinction", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{X}"); + this.expansionSetCode = "ALA"; + this.subtype.add("Equipment"); + this.addAbility(new EntersBattlefieldAbility(new SigilofDistinctionEffect(), "Sigil of Distinction enters the battlefield with X charge counters on it")); + this.addAbility(new EquipAbility(Constants.Outcome.AddAbility, new RemoveCountersSourceCost(CounterType.CHARGE.createInstance()))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(new CountersCount(CounterType.CHARGE), new CountersCount(CounterType.CHARGE)))); + } + + public SigilofDistinction (final SigilofDistinction card) { + super(card); + } + + @Override + public SigilofDistinction copy() { + return new SigilofDistinction(this); + } +} + +class SigilofDistinctionEffect extends OneShotEffect { + public SigilofDistinctionEffect() { + super(Constants.Outcome.Benefit); + } + + public SigilofDistinctionEffect(final SigilofDistinctionEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + int amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); + Permanent p = game.getPermanent(source.getSourceId()); + if (p != null) { + p.addCounters(CounterType.CHARGE.createInstance(amount)); + return true; + } + return true; + } + + @Override + public SigilofDistinctionEffect copy() { + return new SigilofDistinctionEffect(this); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/zendikar/KorSkyfisher.java b/Mage.Sets/src/mage/sets/zendikar/KorSkyfisher.java new file mode 100644 index 00000000000..e1dee8afa12 --- /dev/null +++ b/Mage.Sets/src/mage/sets/zendikar/KorSkyfisher.java @@ -0,0 +1,73 @@ +/* + * 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.sets.zendikar; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Rarity; +import mage.Constants.Zone; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.effects.common.ReturnToHandTargetEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.cards.CardImpl; +import mage.target.common.TargetControlledPermanent; + +/** + * + * @author Loki + */ +public class KorSkyfisher extends CardImpl { + + public KorSkyfisher (UUID ownerId) { + super(ownerId, 23, "Kor Skyfisher", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{1}{W}"); + this.expansionSetCode = "ZEN"; + this.subtype.add("Kor"); + this.subtype.add("Soldier"); + this.color.setWhite(true); + this.power = new MageInt(2); + this.toughness = new MageInt(3); + this.addAbility(FlyingAbility.getInstance()); + Ability ability = new EntersBattlefieldTriggeredAbility(new ReturnToHandTargetEffect(), false); + ability.addTarget(new TargetControlledPermanent()); + this.addAbility(ability); + } + + public KorSkyfisher (final KorSkyfisher card) { + super(card); + } + + @Override + public KorSkyfisher copy() { + return new KorSkyfisher(this); + } + +} diff --git a/Mage/src/mage/abilities/dynamicvalue/DynamicValue.java b/Mage/src/mage/abilities/dynamicvalue/DynamicValue.java new file mode 100644 index 00000000000..a97e85b30f8 --- /dev/null +++ b/Mage/src/mage/abilities/dynamicvalue/DynamicValue.java @@ -0,0 +1,11 @@ +package mage.abilities.dynamicvalue; + +import mage.abilities.Ability; +import mage.game.Game; + +import java.io.Serializable; + +public interface DynamicValue extends Serializable { + int calculate(Game game, Ability sourceAbility); + DynamicValue clone(); +} diff --git a/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java b/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java new file mode 100644 index 00000000000..efa22f71fbd --- /dev/null +++ b/Mage/src/mage/abilities/dynamicvalue/common/CountersCount.java @@ -0,0 +1,38 @@ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.permanent.Permanent; + +public class CountersCount implements DynamicValue { + private CounterType counter; + + public CountersCount(CounterType counter) { + this.counter = counter; + } + + public CountersCount(final CountersCount countersCount) { + this.counter = countersCount.counter; + } + + @Override + public int calculate(Game game, Ability sourceAbility) { + Permanent p = game.getPermanent(sourceAbility.getSourceId()); + if (p != null) { + return p.getCounters().getCount(counter.getName()); + } + return 0; + } + + @Override + public DynamicValue clone() { + return new CountersCount(this); + } + + @Override + public String toString() { + return "X"; + } +} diff --git a/Mage/src/mage/abilities/dynamicvalue/common/StaticValue.java b/Mage/src/mage/abilities/dynamicvalue/common/StaticValue.java new file mode 100644 index 00000000000..2ae770b0186 --- /dev/null +++ b/Mage/src/mage/abilities/dynamicvalue/common/StaticValue.java @@ -0,0 +1,33 @@ +package mage.abilities.dynamicvalue.common; + + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.game.Game; + +public class StaticValue implements DynamicValue { + private int value = 0; + + public StaticValue(int value) { + this.value = value; + } + + public StaticValue(final StaticValue staticValue) { + this.value = staticValue.value; + } + + @Override + public int calculate(Game game, Ability sourceAbility) { + return value; + } + + @Override + public DynamicValue clone() { + return new StaticValue(this); + } + + @Override + public String toString() { + return String.format("%1$+d", value); + } +} diff --git a/Mage/src/mage/abilities/effects/common/BoostEquippedEffect.java b/Mage/src/mage/abilities/effects/common/BoostEquippedEffect.java index cb89da0661f..6e1bdf7695f 100644 --- a/Mage/src/mage/abilities/effects/common/BoostEquippedEffect.java +++ b/Mage/src/mage/abilities/effects/common/BoostEquippedEffect.java @@ -33,6 +33,8 @@ import mage.Constants.Layer; import mage.Constants.Outcome; import mage.Constants.SubLayer; import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.ContinuousEffectImpl; import mage.game.Game; import mage.game.permanent.Permanent; @@ -43,23 +45,31 @@ import mage.game.permanent.Permanent; */ public class BoostEquippedEffect extends ContinuousEffectImpl { - private int power; - private int toughness; + private DynamicValue power; + private DynamicValue toughness; public BoostEquippedEffect(int power, int toughness) { this(power, toughness, Duration.WhileOnBattlefield); } public BoostEquippedEffect(int power, int toughness, Duration duration) { - super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); - this.power = power; - this.toughness = toughness; + this(new StaticValue(power), new StaticValue(toughness), duration); } + public BoostEquippedEffect(DynamicValue powerDynamicValue, DynamicValue toughnessDynamicValue) { + this(powerDynamicValue, toughnessDynamicValue, Duration.WhileOnBattlefield); + } + + public BoostEquippedEffect(DynamicValue powerDynamicValue, DynamicValue toughnessDynamicValue, Duration duration) { + super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); + this.power = powerDynamicValue; + this.toughness = toughnessDynamicValue; + } + public BoostEquippedEffect(final BoostEquippedEffect effect) { super(effect); - this.power = effect.power; - this.toughness = effect.toughness; + this.power = effect.power.clone(); + this.toughness = effect.toughness.clone(); } @Override @@ -73,8 +83,8 @@ public class BoostEquippedEffect extends ContinuousEffectImpl