BoostEnchantedEffect enhanced with DynamicValue

This commit is contained in:
North 2011-07-01 00:05:28 +03:00
parent b9c9532724
commit e1a05a7e4b
4 changed files with 53 additions and 80 deletions

View file

@ -31,35 +31,41 @@ package mage.sets.magic2011;
import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Layer;
import mage.Constants.Outcome;
import mage.Constants.Rarity;
import mage.Constants.SubLayer;
import mage.Constants.TargetController;
import mage.Constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.common.continious.BoostSourceEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterLandPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author BetaSteward_at_googlemail.com
* @author BetaSteward_at_googlemail.com, North
*/
public class EarthServant extends CardImpl<EarthServant> {
private static final FilterLandPermanent filter = new FilterLandPermanent("Mountain you control");
static {
filter.getSubtype().add("Mountain");
filter.setTargetController(TargetController.YOU);
}
public EarthServant(UUID ownerId) {
super(ownerId, 134, "Earth Servant", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{5}{R}");
this.expansionSetCode = "M11";
this.subtype.add("Elemental");
this.color.setRed(true);
this.power = new MageInt(4);
this.toughness = new MageInt(4);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new EarthServantEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostSourceEffect(new PermanentsOnBattlefieldCount(filter, 0),
new PermanentsOnBattlefieldCount(filter, 1),
Duration.WhileOnBattlefield)));
}
public EarthServant(final EarthServant card) {
@ -72,58 +78,3 @@ public class EarthServant extends CardImpl<EarthServant> {
}
}
class EarthServantEffect extends ContinuousEffectImpl<EarthServantEffect> {
private static final FilterLandPermanent filter = new FilterLandPermanent("Mountain");
static {
filter.getSubtype().add("Mountain");
}
public EarthServantEffect() {
super(Duration.WhileOnBattlefield, Outcome.BoostCreature);
}
public EarthServantEffect(final EarthServantEffect effect) {
super(effect);
}
@Override
public EarthServantEffect copy() {
return new EarthServantEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent creature = game.getPermanent(source.getSourceId());
if (creature != null) {
switch (layer) {
case PTChangingEffects_7:
if (sublayer == SubLayer.ModifyPT_7c) {
int amount = game.getBattlefield().countAll(filter, source.getControllerId());
creature.addToughness(amount);
}
break;
}
return true;
}
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == layer.PTChangingEffects_7;
}
@Override
public String getText(Ability source) {
return "Earth Servant gets +0/+1 for each Mountain you control";
}
}

View file

@ -33,7 +33,6 @@ import mage.Constants.Duration;
import mage.Constants.Outcome;
import mage.Constants.Rarity;
import mage.Constants.Zone;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continious.BoostEnchantedEffect;
@ -58,8 +57,7 @@ public class DefensiveStance extends CardImpl<DefensiveStance> {
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
this.addAbility(new EnchantAbility(auraTarget.getTargetName()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(-1, 1, Duration.WhileOnBattlefield)));
}

View file

@ -33,20 +33,30 @@ 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;
/**
*
* @author BetaSteward_at_googlemail.com
* @author BetaSteward_at_googlemail.com, North
*/
public class BoostEnchantedEffect extends ContinuousEffectImpl<BoostEnchantedEffect> {
private int power;
private int toughness;
private DynamicValue power;
private DynamicValue toughness;
public BoostEnchantedEffect(int power, int toughness, Duration duration) {
public BoostEnchantedEffect(int power, int toughness) {
this(power, toughness, Duration.WhileOnBattlefield);
}
public BoostEnchantedEffect(int power, int toughness, Duration duration) {
this(new StaticValue(power), new StaticValue(toughness), duration);
}
public BoostEnchantedEffect(DynamicValue power, DynamicValue toughness, Duration duration) {
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
this.power = power;
this.toughness = toughness;
@ -54,8 +64,8 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl<BoostEnchantedEff
public BoostEnchantedEffect(final BoostEnchantedEffect effect) {
super(effect);
this.power = effect.power;
this.toughness = effect.toughness;
this.power = effect.power.clone();
this.toughness = effect.toughness.clone();
}
@Override
@ -69,8 +79,8 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl<BoostEnchantedEff
if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
if (creature != null) {
creature.addPower(power);
creature.addToughness(toughness);
creature.addPower(power.calculate(game, source));
creature.addToughness(toughness.calculate(game, source));
}
}
return true;
@ -78,10 +88,27 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl<BoostEnchantedEff
@Override
public String getText(Ability source) {
StringBuilder sb = new StringBuilder();
sb.append("Enchanted creature gets ").append(String.format("%1$+d/%2$+d", power, toughness));
StringBuilder sb = new StringBuilder();
sb.append("Enchanted creature gets ");
String p = power.toString();
if(!p.startsWith("-"))
sb.append("+");
sb.append(p).append("/");
String t = toughness.toString();
if(!t.startsWith("-")){
if(p.startsWith("-"))
sb.append("-");
else
sb.append("+");
}
sb.append(t);
if (duration != Duration.WhileOnBattlefield)
sb.append(" ").append(duration.toString());
String message = power.getMessage();
if (message.length() > 0) {
sb.append(" for each ");
}
sb.append(message);
return sb.toString();
}

View file

@ -28,11 +28,8 @@
package mage.abilities.keyword;
import mage.Constants.Outcome;
import mage.Constants.Zone;
import mage.abilities.StaticAbility;
import mage.abilities.effects.common.AttachEffect;
import mage.target.TargetPermanent;
/**
*