Changed MonstosityAbility to support X value.

This commit is contained in:
LevelX2 2013-09-18 16:24:31 +02:00
parent 1304069de3
commit 4129838e36
3 changed files with 53 additions and 17 deletions

View file

@ -40,12 +40,15 @@ import mage.game.events.GameEvent.EventType;
*/
public class BecomesMonstrousSourceTriggeredAbility extends TriggeredAbilityImpl<BecomesMonstrousSourceTriggeredAbility> {
private int monstrosityValue;
public BecomesMonstrousSourceTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public BecomesMonstrousSourceTriggeredAbility(final BecomesMonstrousSourceTriggeredAbility ability) {
super(ability);
this.monstrosityValue = ability.monstrosityValue;
}
@Override
@ -56,11 +59,16 @@ public class BecomesMonstrousSourceTriggeredAbility extends TriggeredAbilityImpl
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType().equals(EventType.BECOMES_MONSTROUS) && event.getSourceId().equals(this.getSourceId())) {
this.monstrosityValue = event.getAmount();
return true;
}
return false;
}
public int getMonstrosityValue() {
return monstrosityValue;
}
@Override
public String getRule() {
return "When {this} becomes monstrous, " + super.getRule();

View file

@ -73,7 +73,6 @@ public class CreateDelayedTriggeredAbilityEffect extends OneShotEffect<CreateDel
if (this.copyTargets) {
delayedAbility.getTargets().addAll(source.getTargets());
for(Effect effect : delayedAbility.getEffects()) {
effect.setTargetPointer(targetPointer);
effect.getTargetPointer().init(game, source);
}
}

View file

@ -30,10 +30,7 @@ package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.condition.InvertCondition;
import mage.abilities.condition.common.MonstrousCondition;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.constants.Outcome;
@ -44,8 +41,29 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
/**
* Monstrosity
*
* 701.28. Monstrosity
*
* 701.28a Monstrosity N means If this permanent isnt monstrous, put N +1/+1 counters on it
* and it becomes monstrous. Monstrous is a condition of that permanent that can be
* referred to by other abilities.
*
* 701.28b If a permanents ability instructs a player to monstrosity X, other abilities of
* that permanent may also refer to X. The value of X in those abilities is equal to
* the value of X as that permanent became monstrous.
*
* * Once a creature becomes monstrous, it cant become monstrous again. If the creature
* is already monstrous when the monstrosity ability resolves, nothing happens.
*
* * Monstrous isnt an ability that a creature has. Its just something true about that
* creature. If the creature stops being a creature or loses its abilities, it will
* continue to be monstrous.
*
* * An ability that triggers when a creature becomes monstrous wont trigger if that creature
* isnt on the battlefield when its monstrosity ability resolves.
*
* @author LevelX2
*/
@ -54,15 +72,13 @@ public class MonstrosityAbility extends ActivatedAbilityImpl<MonstrosityAbility>
private int monstrosityValue;
/**
*
* @param manaString
* @param monstrosityValue use Integer.MAX_VALUE for monstrosity X.
*/
public MonstrosityAbility(String manaString, int monstrosityValue) {
super(Zone.BATTLEFIELD, new ConditionalOneShotEffect(
new AddCountersSourceEffect(CounterType.P1P1.createInstance(monstrosityValue)),
new InvertCondition(MonstrousCondition.getInstance()),
""), new ManaCostsImpl(manaString));
this.addEffect(new ConditionalOneShotEffect(
new BecomeMonstrousSourceEffect(),
new InvertCondition(MonstrousCondition.getInstance()),""));
super(Zone.BATTLEFIELD, new BecomeMonstrousSourceEffect(),new ManaCostsImpl(manaString));
this.monstrosityValue = monstrosityValue;
}
@ -78,13 +94,20 @@ public class MonstrosityAbility extends ActivatedAbilityImpl<MonstrosityAbility>
@Override
public String getRule() {
return new StringBuilder(manaCosts.getText()).append(": Monstrosity ").append(monstrosityValue)
.append(". <i>(If this creature isn't monstrous, put ").append(CardUtil.numberToText(monstrosityValue))
return new StringBuilder(manaCosts.getText()).append(": Monstrosity ")
.append(monstrosityValue == Integer.MAX_VALUE ? "X":monstrosityValue)
.append(". <i>(If this creature isn't monstrous, put ")
.append(monstrosityValue == Integer.MAX_VALUE ? "X":CardUtil.numberToText(monstrosityValue))
.append(" +1/+1 counters on it and it becomes monstrous.)</i>").toString();
}
}
public int getMonstrosityValue() {
return monstrosityValue;
}
}
class BecomeMonstrousSourceEffect extends OneShotEffect<BecomeMonstrousSourceEffect> {
public BecomeMonstrousSourceEffect() {
@ -104,9 +127,15 @@ class BecomeMonstrousSourceEffect extends OneShotEffect<BecomeMonstrousSourceEff
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (permanent != null && !permanent.isMonstrous() && source instanceof MonstrosityAbility) {
int monstrosityValue = ((MonstrosityAbility) source).getMonstrosityValue();
// handle monstrosity = X
if (monstrosityValue == Integer.MAX_VALUE) {
monstrosityValue = source.getManaCostsToPay().getX();
}
new AddCountersSourceEffect(CounterType.P1P1.createInstance(monstrosityValue)).apply(game, source);
permanent.setMonstrous(true);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_MONSTROUS, source.getSourceId(), source.getSourceId(), source.getControllerId()));
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_MONSTROUS, source.getSourceId(), source.getSourceId(), source.getControllerId(), monstrosityValue));
return true;
}
return false;