rewrite fix for Ring of Evos Isle more generic

This commit is contained in:
Loki 2012-07-30 22:34:47 +12:00
parent d07ee80580
commit 9d4714507a
2 changed files with 36 additions and 45 deletions

View file

@ -42,6 +42,7 @@ import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.decorator.ConditionalTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continious.GainAbilityAttachedEffect;
import mage.abilities.effects.common.continious.GainAbilitySourceEffect;
import mage.abilities.effects.common.counter.AddPlusOneCountersAttachedEffect;
import mage.abilities.keyword.EquipAbility;
@ -70,7 +71,7 @@ public class RingOfEvosIsle extends CardImpl<RingOfEvosIsle> {
this.subtype.add("Equipment");
// {2}: Equipped creature gains hexproof until end of turn.
this.addAbility(new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new RingOfEvosIsleEffect(), new GenericManaCost(2)));
this.addAbility(new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new GainAbilityAttachedEffect(HexproofAbility.getInstance(), Constants.AttachmentType.EQUIPMENT, Constants.Duration.EndOfTurn), new GenericManaCost(2)));
// At the beginning of your upkeep, put a +1/+1 counter on equipped creature if it's blue.
TriggeredAbility triggeredAbility = new BeginningOfUpkeepTriggeredAbility(Constants.Zone.BATTLEFIELD, new AddPlusOneCountersAttachedEffect(1), Constants.TargetController.YOU, false);
@ -90,34 +91,3 @@ public class RingOfEvosIsle extends CardImpl<RingOfEvosIsle> {
return new RingOfEvosIsle(this);
}
}
class RingOfEvosIsleEffect extends OneShotEffect<RingOfEvosIsleEffect> {
RingOfEvosIsleEffect() {
super(Constants.Outcome.BoostCreature);
staticText = "Equipped creature gains hexproof until end of turn";
}
RingOfEvosIsleEffect(final RingOfEvosIsleEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null) {
Permanent equipped = game.getPermanent(equipment.getAttachedTo());
if (equipped != null) {
Effect effect = new GainAbilitySourceEffect(HexproofAbility.getInstance(), Constants.Duration.EndOfTurn);
equipped.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, effect), game);
return true;
}
}
return false;
}
@Override
public RingOfEvosIsleEffect copy() {
return new RingOfEvosIsleEffect(this);
}
}

View file

@ -37,21 +37,25 @@ import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GainAbilityAttachedEffect extends ContinuousEffectImpl<GainAbilityAttachedEffect> {
protected Ability ability;
protected AttachmentType attachmentType;
protected boolean fixedTarget = false;
public GainAbilityAttachedEffect(Ability ability, AttachmentType attachmentType, Duration duration) {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.ability = ability;
this.attachmentType = attachmentType;
this.duration = duration;
if (duration == Duration.EndOfTurn) {
fixedTarget = true;
}
setText();
}
@ -66,6 +70,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl<GainAbilityA
super(effect);
this.ability = effect.ability.copy();
this.attachmentType = effect.attachmentType;
this.fixedTarget = effect.fixedTarget;
}
@Override
@ -74,31 +79,47 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl<GainAbilityA
}
@Override
public boolean apply(Game game, Ability source) {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
Permanent creature = game.getPermanent(equipment.getAttachedTo());
if (creature != null) {
creature.addAbility(ability, game);
public void init(Ability source, Game game) {
super.init(source, game);
if (fixedTarget) {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
this.setTargetPointer(new FixedTarget(equipment.getAttachedTo()));
}
}
}
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = null;
if (fixedTarget) {
creature = game.getPermanent(targetPointer.getFirst(game, source));
} else {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
creature = game.getPermanent(equipment.getAttachedTo());
}
}
if (creature != null) {
creature.addAbility(ability, game);
}
return true;
}
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA) {
sb.append("Enchanted");
sb.append("Enchanted");
} else if (attachmentType == AttachmentType.EQUIPMENT) {
sb.append("Equipped");
}
sb.append(" creature ");
if (duration == Duration.WhileOnBattlefield) {
sb.append("has ");
sb.append("has ");
} else {
sb.append("gains ");
sb.append("gains ");
}
sb.append(ability.getRule());
sb.append(ability.getRule());
staticText = sb.toString();
}