Improved rule text generation for effects using DynamicValue.

This commit is contained in:
North 2011-06-05 15:37:06 +03:00
parent 1ed3f1f4f8
commit ca82485772
22 changed files with 143 additions and 164 deletions

View file

@ -33,11 +33,11 @@ import java.util.UUID;
import mage.Constants; import mage.Constants;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Rarity; import mage.Constants.Rarity;
import mage.Constants.Zone; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.dynamicvalue.common.CreaturesOnBattlefieldCount;
import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.PreventAllCombatDamageEffect; import mage.abilities.effects.common.PreventAllCombatDamageEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterPermanent;
/** /**
* *
@ -45,13 +45,17 @@ import mage.cards.CardImpl;
*/ */
public class BlunttheAssault extends CardImpl<BlunttheAssault> { public class BlunttheAssault extends CardImpl<BlunttheAssault> {
private static final FilterPermanent filter = new FilterPermanent("creature on the battlefield");
static {
filter.getCardType().add(Constants.CardType.CREATURE);
}
public BlunttheAssault (UUID ownerId) { public BlunttheAssault (UUID ownerId) {
super(ownerId, 113, "Blunt the Assault", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{3}{G}"); super(ownerId, 113, "Blunt the Assault", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{3}{G}");
this.expansionSetCode = "SOM"; this.expansionSetCode = "SOM";
this.color.setGreen(true); this.color.setGreen(true);
GainLifeEffect effect = new GainLifeEffect(new CreaturesOnBattlefieldCount()); this.getSpellAbility().addEffect(new GainLifeEffect(new PermanentsOnBattlefieldCount(filter)));
effect.setStaticText("You gain 1 life for each creature on the battlefield");
this.getSpellAbility().addEffect(effect);
this.getSpellAbility().addEffect(new PreventAllCombatDamageEffect(Constants.Duration.EndOfTurn)); this.getSpellAbility().addEffect(new PreventAllCombatDamageEffect(Constants.Duration.EndOfTurn));
} }

View file

@ -37,15 +37,22 @@ import mage.MageInt;
import mage.abilities.common.AttacksEachTurnStaticAbility; import mage.abilities.common.AttacksEachTurnStaticAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.continious.SetPowerToughnessSourceEffect; import mage.abilities.effects.common.continious.SetPowerToughnessSourceEffect;
import mage.abilities.dynamicvalue.common.ControlledArtifactsOnBattlefieldCount; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.keyword.IndestructibleAbility; import mage.abilities.keyword.IndestructibleAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterPermanent;
/** /**
* *
* @author Loki * @author Loki
*/ */
public class DarksteelJuggernaut extends CardImpl<DarksteelJuggernaut> { public class DarksteelJuggernaut extends CardImpl<DarksteelJuggernaut> {
private static final FilterPermanent filter = new FilterPermanent("artifacts you control");
static {
filter.getCardType().add(Constants.CardType.ARTIFACT);
filter.setTargetController(Constants.TargetController.YOU);
}
public DarksteelJuggernaut (UUID ownerId) { public DarksteelJuggernaut (UUID ownerId) {
super(ownerId, 150, "Darksteel Juggernaut", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{5}"); super(ownerId, 150, "Darksteel Juggernaut", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{5}");
@ -53,7 +60,9 @@ public class DarksteelJuggernaut extends CardImpl<DarksteelJuggernaut> {
this.subtype.add("Juggernaut"); this.subtype.add("Juggernaut");
this.power = new MageInt(0); this.power = new MageInt(0);
this.toughness = new MageInt(0); this.toughness = new MageInt(0);
SetPowerToughnessSourceEffect effect = new SetPowerToughnessSourceEffect(new ControlledArtifactsOnBattlefieldCount(), new ControlledArtifactsOnBattlefieldCount(), Constants.Duration.EndOfGame);
PermanentsOnBattlefieldCount value = new PermanentsOnBattlefieldCount(filter);
SetPowerToughnessSourceEffect effect = new SetPowerToughnessSourceEffect(value, value, Constants.Duration.EndOfGame);
effect.setStaticText("Darksteel Juggernaut's power and toughness are each equal to the number of artifacts you control"); effect.setStaticText("Darksteel Juggernaut's power and toughness are each equal to the number of artifacts you control");
this.addAbility(new SimpleStaticAbility(Constants.Zone.ALL, effect)); this.addAbility(new SimpleStaticAbility(Constants.Zone.ALL, effect));
this.addAbility(IndestructibleAbility.getInstance()); this.addAbility(IndestructibleAbility.getInstance());

View file

@ -42,7 +42,7 @@ import mage.filter.common.FilterLandPermanent;
*/ */
public class LandbindRitual extends CardImpl<LandbindRitual> { public class LandbindRitual extends CardImpl<LandbindRitual> {
private static final FilterLandPermanent filter = new FilterLandPermanent("Plains"); private static final FilterLandPermanent filter = new FilterLandPermanent("Plains you control");
static { static {
filter.getSubtype().add("Plains"); filter.getSubtype().add("Plains");
@ -55,7 +55,7 @@ public class LandbindRitual extends CardImpl<LandbindRitual> {
this.color.setWhite(true); this.color.setWhite(true);
this.getSpellAbility().addEffect(new GainLifeEffect(new PermanentsOnBattlefieldCount(filter))); this.getSpellAbility().addEffect(new GainLifeEffect(new PermanentsOnBattlefieldCount(filter, 2)));
} }
public LandbindRitual(final LandbindRitual card) { public LandbindRitual(final LandbindRitual card) {

View file

@ -43,7 +43,7 @@ import mage.target.TargetPlayer;
*/ */
public class MindSludge extends CardImpl<MindSludge> { public class MindSludge extends CardImpl<MindSludge> {
private static final FilterLandPermanent filter = new FilterLandPermanent("Swamp"); private static final FilterLandPermanent filter = new FilterLandPermanent("Swamp you control");
static { static {
filter.getSubtype().add("Swamp"); filter.getSubtype().add("Swamp");

View file

@ -8,4 +8,5 @@ import java.io.Serializable;
public interface DynamicValue extends Serializable { public interface DynamicValue extends Serializable {
int calculate(Game game, Ability sourceAbility); int calculate(Game game, Ability sourceAbility);
DynamicValue clone(); DynamicValue clone();
String getMessage();
} }

View file

@ -1,27 +0,0 @@
package mage.abilities.dynamicvalue.common;
import mage.Constants;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.filter.Filter;
import mage.filter.FilterPermanent;
import mage.game.Game;
class ArtifactsOnBattlefieldCount implements DynamicValue {
private static final FilterPermanent filter = new FilterPermanent();
static {
filter.getCardType().add(Constants.CardType.ARTIFACT);
filter.setScopeCardType(Filter.ComparisonScope.Any);
}
@Override
public int calculate(Game game, Ability sourceAbility) {
return game.getBattlefield().countAll(filter);
}
@Override
public DynamicValue clone() {
return new ArtifactsOnBattlefieldCount();
}
}

View file

@ -19,4 +19,9 @@ public class CardsInControlledPlayerHandCount implements DynamicValue {
public DynamicValue clone() { public DynamicValue clone() {
return new CardsInControlledPlayerHandCount(); return new CardsInControlledPlayerHandCount();
} }
@Override
public String getMessage() {
return "";
}
} }

View file

@ -1,32 +0,0 @@
package mage.abilities.dynamicvalue.common;
import mage.Constants;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.filter.Filter;
import mage.filter.FilterPermanent;
import mage.game.Game;
public class ControlledArtifactsOnBattlefieldCount implements DynamicValue {
private static final FilterPermanent filter = new FilterPermanent();
static {
filter.getCardType().add(Constants.CardType.ARTIFACT);
filter.setScopeCardType(Filter.ComparisonScope.Any);
}
@Override
public int calculate(Game game, Ability sourceAbility) {
return game.getBattlefield().countAll(filter, sourceAbility.getControllerId());
}
@Override
public DynamicValue clone() {
return new ControlledArtifactsOnBattlefieldCount();
}
@Override
public String toString() {
return "X";
}
}

View file

@ -35,4 +35,9 @@ public class CountersCount implements DynamicValue {
public String toString() { public String toString() {
return "X"; return "X";
} }
@Override
public String getMessage() {
return "";
}
} }

View file

@ -1,27 +0,0 @@
package mage.abilities.dynamicvalue.common;
import mage.Constants;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.filter.Filter;
import mage.filter.FilterPermanent;
import mage.game.Game;
public class CreaturesOnBattlefieldCount implements DynamicValue {
private static final FilterPermanent filter = new FilterPermanent();
static {
filter.getCardType().add(Constants.CardType.CREATURE);
filter.setScopeCardType(Filter.ComparisonScope.Any);
}
@Override
public int calculate(Game game, Ability sourceAbility) {
return game.getBattlefield().countAll(filter);
}
@Override
public DynamicValue clone() {
return new CreaturesOnBattlefieldCount();
}
}

View file

@ -19,4 +19,9 @@ public class ManacostVariableValue implements DynamicValue {
public String toString() { public String toString() {
return "X"; return "X";
} }
@Override
public String getMessage() {
return "";
}
} }

View file

@ -12,13 +12,19 @@ import mage.game.Game;
public class PermanentsOnBattlefieldCount implements DynamicValue { public class PermanentsOnBattlefieldCount implements DynamicValue {
private FilterPermanent filter; private FilterPermanent filter;
private Integer amount;
public PermanentsOnBattlefieldCount() { public PermanentsOnBattlefieldCount() {
filter = new FilterPermanent(); filter = new FilterPermanent();
} }
public PermanentsOnBattlefieldCount(FilterPermanent filter) { public PermanentsOnBattlefieldCount(FilterPermanent filter) {
this(filter, 1);
}
public PermanentsOnBattlefieldCount(FilterPermanent filter, Integer amount) {
this.filter = filter; this.filter = filter;
this.amount = amount;
} }
public PermanentsOnBattlefieldCount(final PermanentsOnBattlefieldCount dynamicValue) { public PermanentsOnBattlefieldCount(final PermanentsOnBattlefieldCount dynamicValue) {
@ -37,6 +43,11 @@ public class PermanentsOnBattlefieldCount implements DynamicValue {
@Override @Override
public String toString() { public String toString() {
return "X"; return amount.toString();
}
@Override
public String getMessage() {
return " for each " + filter.getMessage();
} }
} }

View file

@ -30,4 +30,9 @@ public class StaticValue implements DynamicValue {
public String toString() { public String toString() {
return Integer.toString(value); return Integer.toString(value);
} }
@Override
public String getMessage() {
return "";
}
} }

View file

@ -90,6 +90,7 @@ public class CreateTokenEffect extends OneShotEffect<CreateTokenEffect> {
sb.append("put ").append(amount); sb.append("put ").append(amount);
} }
sb.append(" ").append(token.getDescription()).append(" onto the battlefield"); sb.append(" ").append(token.getDescription()).append(" onto the battlefield");
sb.append(amount.getMessage());
return sb.toString(); return sb.toString();
} }

View file

@ -103,6 +103,7 @@ public class DamageTargetEffect extends OneShotEffect<DamageTargetEffect> {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{source} deals ").append(amount).append(" damage to target "); sb.append("{source} deals ").append(amount).append(" damage to target ");
sb.append(source.getTargets().get(0).getTargetName()); sb.append(source.getTargets().get(0).getTargetName());
sb.append(amount.getMessage());
if (!preventable) if (!preventable)
sb.append(". The damage can't be prevented"); sb.append(". The damage can't be prevented");
return sb.toString(); return sb.toString();

View file

@ -1,31 +1,30 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.common; package mage.abilities.effects.common;
import mage.Constants.Outcome; import mage.Constants.Outcome;
@ -42,45 +41,49 @@ import mage.players.Player;
*/ */
public class DiscardTargetEffect extends OneShotEffect<DiscardTargetEffect> { public class DiscardTargetEffect extends OneShotEffect<DiscardTargetEffect> {
protected DynamicValue amount; protected DynamicValue amount;
public DiscardTargetEffect(DynamicValue amount) { public DiscardTargetEffect(DynamicValue amount) {
super(Outcome.Discard); super(Outcome.Discard);
this.amount = amount; this.amount = amount;
} }
public DiscardTargetEffect(int amount) { public DiscardTargetEffect(int amount) {
this(new StaticValue(amount)); this(new StaticValue(amount));
} }
public DiscardTargetEffect(final DiscardTargetEffect effect) {
super(effect);
this.amount = effect.amount.clone();
}
@Override public DiscardTargetEffect(final DiscardTargetEffect effect) {
public DiscardTargetEffect copy() { super(effect);
return new DiscardTargetEffect(this); this.amount = effect.amount.clone();
} }
@Override @Override
public boolean apply(Game game, Ability source) { public DiscardTargetEffect copy() {
Player player = game.getPlayer(source.getFirstTarget()); return new DiscardTargetEffect(this);
if (player != null) { }
player.discard(amount.calculate(game, source), source, game);
return true;
}
return false;
}
@Override @Override
public String getText(Ability source) { public boolean apply(Game game, Ability source) {
int staticAmount = 0; Player player = game.getPlayer(source.getFirstTarget());
try{ if (player != null) {
staticAmount = Integer.parseInt(amount.toString()); player.discard(amount.calculate(game, source), source, game);
} catch (Exception e) { return true;
} }
return "Target player discards " + amount.toString() + " card" + (staticAmount == 1 ? "" : "s"); return false;
} }
@Override
public String getText(Ability source) {
StringBuilder sb = new StringBuilder("Target player discards ");
sb.append(amount).append(" card");
try {
if (Integer.parseInt(amount.toString()) > 1) {
sb.append("s");
}
} catch (Exception e) {
sb.append("s");
}
sb.append(amount.getMessage());
return sb.toString();
}
} }

View file

@ -77,10 +77,14 @@ public class DrawCardTargetEffect extends OneShotEffect<DrawCardTargetEffect> {
public String getText(Ability source) { public String getText(Ability source) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Target player draws ").append(amount).append(" card"); sb.append("Target player draws ").append(amount).append(" card");
if (amount instanceof StaticValue && amount.calculate(null, null) == 1) { try {
} else { if (Integer.parseInt(amount.toString()) > 1) {
sb.append("s");
}
} catch (Exception e) {
sb.append("s"); sb.append("s");
} }
sb.append(amount.getMessage());
return sb.toString(); return sb.toString();
} }

View file

@ -74,7 +74,7 @@ public class GainLifeEffect extends OneShotEffect<GainLifeEffect> {
@Override @Override
public String getDynamicText(Ability source) { public String getDynamicText(Ability source) {
return "you gain " + life.toString() + " life"; return "you gain " + life.toString() + " life" + life.getMessage();
} }
} }

View file

@ -93,9 +93,10 @@ public class BoostEquippedEffect extends ContinuousEffectImpl<BoostEquippedEffec
@Override @Override
public String getDynamicText(Ability source) { public String getDynamicText(Ability source) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Equipped creatures gets ").append(power.toString()).append("/").append(toughness.toString()); sb.append("Equipped creatures gets ").append(power).append("/").append(toughness);
if (duration != Duration.WhileOnBattlefield) if (duration != Duration.WhileOnBattlefield)
sb.append(" ").append(duration.toString()); sb.append(" ").append(duration.toString());
sb.append(power.getMessage());
return sb.toString(); return sb.toString();
} }

View file

@ -81,7 +81,12 @@ public class BoostSourceEffect extends ContinuousEffectImpl<BoostSourceEffect> {
@Override @Override
public String getDynamicText(Ability source) { public String getDynamicText(Ability source) {
return "{this} gets " + power.toString() + "/" + toughness.toString() + " " + duration.toString(); StringBuilder sb = new StringBuilder();
sb.append("{this} gets ").append(power).append("/").append(toughness);
if (duration != Duration.WhileOnBattlefield)
sb.append(" ").append(duration.toString());
sb.append(power.getMessage());
return sb.toString();
} }
} }

View file

@ -82,9 +82,11 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
@Override @Override
public String getText(Ability source) { public String getText(Ability source) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("target ").append(source.getTargets().get(0).getTargetName()).append(" gets "); sb.append("Target ").append(source.getTargets().get(0).getTargetName()).append(" gets ");
sb.append(power.toString()).append("/").append(toughness.toString()); sb.append(power).append("/").append(toughness);
sb.append(" ").append(duration.toString()); if (duration != Duration.WhileOnBattlefield)
sb.append(" ").append(duration.toString());
sb.append(power.getMessage());
return sb.toString(); return sb.toString();
} }
} }

View file

@ -84,7 +84,10 @@ public class SetPowerToughnessSourceEffect extends ContinuousEffectImpl<SetPower
public String getDynamicText(Ability source) { public String getDynamicText(Ability source) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("{this} ").append(" becomes "); sb.append("{this} ").append(" becomes ");
sb.append(power).append("/").append(toughness).append(" ").append(duration.toString()); sb.append(power).append("/").append(toughness);
if (duration != Duration.WhileOnBattlefield)
sb.append(" ").append(duration.toString());
sb.append(power.getMessage());
return sb.toString(); return sb.toString();
} }