mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
Dymamic Values, Sigil of Distinction as example, tooltip is generated badly
This commit is contained in:
parent
cba120cb24
commit
d06b3a924b
6 changed files with 274 additions and 10 deletions
|
@ -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<SigilofDistinction> {
|
||||
|
||||
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<SigilofDistinctionEffect> {
|
||||
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);
|
||||
}
|
||||
}
|
73
Mage.Sets/src/mage/sets/zendikar/KorSkyfisher.java
Normal file
73
Mage.Sets/src/mage/sets/zendikar/KorSkyfisher.java
Normal file
|
@ -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<KorSkyfisher> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
11
Mage/src/mage/abilities/dynamicvalue/DynamicValue.java
Normal file
11
Mage/src/mage/abilities/dynamicvalue/DynamicValue.java
Normal file
|
@ -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();
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
33
Mage/src/mage/abilities/dynamicvalue/common/StaticValue.java
Normal file
33
Mage/src/mage/abilities/dynamicvalue/common/StaticValue.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<BoostEquippedEffect> {
|
||||
|
||||
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<BoostEquippedEffec
|
|||
if (equipment != null && equipment.getAttachedTo() != null) {
|
||||
Permanent creature = game.getPermanent(equipment.getAttachedTo());
|
||||
if (creature != null) {
|
||||
creature.addPower(power);
|
||||
creature.addToughness(toughness);
|
||||
creature.addPower(power.calculate(game, source));
|
||||
creature.addToughness(toughness.calculate(game, source));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -83,7 +93,7 @@ public class BoostEquippedEffect extends ContinuousEffectImpl<BoostEquippedEffec
|
|||
@Override
|
||||
public String getText(Ability source) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Equipped creatures gets ").append(String.format("%1$+d/%2$+d", power, toughness));
|
||||
sb.append("Equipped creatures gets ").append(power.toString()).append("/").append(toughness.toString());
|
||||
if (duration != Duration.WhileOnBattlefield)
|
||||
sb.append(" ").append(duration.toString());
|
||||
return sb.toString();
|
||||
|
|
Loading…
Reference in a new issue