Instill Energy: fix the haste-like effect

This commit is contained in:
Luna Skyrise 2015-05-11 19:13:17 -03:00
parent a49d082823
commit 0b712fc3e7

View file

@ -30,22 +30,19 @@ package mage.sets.fifthedition;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.ActivateIfConditionActivatedAbility;
import mage.abilities.common.LimitedTimesPerTurnActivatedAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.common.SimpleTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.MyTurnCondition;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.UntapEnchantedEffect;
import mage.abilities.effects.common.UntapSourceEffect;
import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl;
import mage.constants.AsThoughEffectType;
import mage.constants.AttachmentType;
import mage.constants.CardType;
import mage.constants.Duration;
@ -53,6 +50,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
import mage.util.CardUtil;
@ -75,7 +73,8 @@ public class InstillEnergy extends CardImpl {
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
// Enchanted creature can attack as though it had haste.
Ability haste = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(HasteAbility.getInstance(), AttachmentType.AURA, Duration.Custom, "Enchanted creature can attack as though it had haste."));
Ability asThough = new SimpleStaticAbility(Zone.BATTLEFIELD, new CanAttackAsThoughItHadHasteEnchantedEffect(Duration.WhileOnBattlefield));
Ability haste = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(asThough, AttachmentType.AURA, Duration.WhileOnBattlefield, "Enchanted creature can attack as though it had haste."));
this.addAbility(haste);
// {0}: Untap enchanted creature. Activate this ability only during your turn and only once each turn.
Ability gainedAbility = new LimitedTimesIfConditionActivatedAbility(Zone.BATTLEFIELD, new UntapEnchantedEffect(), new GenericManaCost(0), MyTurnCondition.getInstance(), 1);
@ -92,8 +91,35 @@ public class InstillEnergy extends CardImpl {
}
}
class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivatedAbility {
class CanAttackAsThoughItHadHasteEnchantedEffect extends AsThoughEffectImpl {
public CanAttackAsThoughItHadHasteEnchantedEffect(Duration duration) {
super(AsThoughEffectType.ATTACK, duration, Outcome.Benefit);
staticText = "Enchanted creature can attack as though it had haste";
}
public CanAttackAsThoughItHadHasteEnchantedEffect(final CanAttackAsThoughItHadHasteEnchantedEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public CanAttackAsThoughItHadHasteEnchantedEffect copy() {
return new CanAttackAsThoughItHadHasteEnchantedEffect(this);
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
Permanent enchantment = game.getPermanent(source.getSourceId());
return enchantment != null && enchantment.getAttachedTo() != null && enchantment.getAttachedTo() == objectId;
}
}
class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivatedAbility {
class ActivationInfo {
public int turnNum;
@ -106,7 +132,7 @@ class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivat
}
private int maxActivationsPerTurn;
public LimitedTimesIfConditionActivatedAbility(Zone zone, Effect effect, Cost cost, Condition condition) {
this(zone, effect, cost, condition, 1);
}
@ -137,13 +163,11 @@ class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivat
ActivationInfo activationInfo = getActivationInfo(game);
if (activationInfo == null) {
activationInfo = new ActivationInfo(game.getTurnNum(), 1);
} else if (activationInfo.turnNum != game.getTurnNum()) {
activationInfo.turnNum = game.getTurnNum();
activationInfo.activationCounter = 1;
} else {
if (activationInfo.turnNum != game.getTurnNum()) {
activationInfo.turnNum = game.getTurnNum();
activationInfo.activationCounter = 1;
} else {
activationInfo.activationCounter++;
}
activationInfo.activationCounter++;
}
setActivationInfo(activationInfo, game);
return true;
@ -160,8 +184,8 @@ class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivat
@Override
public String getRule() {
StringBuilder sb = new StringBuilder(super.getRule());
sb.replace(sb.length()-1, sb.length() -1, " and "); //suppress super()'s final period
switch(maxActivationsPerTurn) {
sb.replace(sb.length() - 1, sb.length() - 1, " and "); //suppress super()'s final period
switch (maxActivationsPerTurn) {
case 1:
sb.append("only once");
break;
@ -179,7 +203,7 @@ class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivat
public LimitedTimesIfConditionActivatedAbility copy() {
return new LimitedTimesIfConditionActivatedAbility(this);
}
private ActivationInfo getActivationInfo(Game game) {
Integer turnNum = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game));
Integer activationCount = (Integer) game.getState().getValue(CardUtil.getCardZoneString("activationsCount", sourceId, game));
@ -188,7 +212,7 @@ class LimitedTimesIfConditionActivatedAbility extends ActivateIfConditionActivat
}
return new ActivationInfo(turnNum, activationCount);
}
private void setActivationInfo(ActivationInfo activationInfo, Game game) {
game.getState().setValue(CardUtil.getCardZoneString("activationsTurn", sourceId, game), activationInfo.turnNum);
game.getState().setValue(CardUtil.getCardZoneString("activationsCount", sourceId, game), activationInfo.activationCounter);