rework and simplify evolve ability

This commit is contained in:
theelk801 2023-05-23 17:07:24 -04:00
parent 4b2c21ef9e
commit 85aaaec468

View file

@ -1,17 +1,15 @@
package mage.abilities.keyword; package mage.abilities.keyword;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/** /**
* FAQ 2013/01/11 * FAQ 2013/01/11
@ -64,48 +62,31 @@ import mage.target.targetpointer.FixedTarget;
* *
* @author LevelX2 * @author LevelX2
*/ */
public class EvolveAbility extends TriggeredAbilityImpl { public class EvolveAbility extends EntersBattlefieldAllTriggeredAbility {
public EvolveAbility() { public EvolveAbility() {
super(Zone.BATTLEFIELD, new EvolveEffect()); super(Zone.BATTLEFIELD, new EvolveEffect(), StaticFilters.FILTER_CONTROLLED_CREATURE, false);
} }
public EvolveAbility(EvolveAbility ability) { public EvolveAbility(EvolveAbility ability) {
super(ability); super(ability);
} }
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getTargetId().equals(this.getSourceId())) {
Permanent triggeringCreature = ((EntersTheBattlefieldEvent) event).getTarget();
if (triggeringCreature != null
&& triggeringCreature.isCreature(game)
&& triggeringCreature.isControlledBy(this.controllerId)) {
Permanent sourceCreature = game.getPermanent(sourceId);
if (sourceCreature != null && isPowerOrThoughnessGreater(sourceCreature, triggeringCreature)) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getTargetId(), game));
return true;
}
}
}
return false;
}
@Override @Override
public boolean checkInterveningIfClause(Game game) { public boolean checkInterveningIfClause(Game game) {
return true; Permanent sourcePermanent = getSourcePermanentOrLKI(game);
} Permanent permanentEntering = (Permanent) this
.getEffects()
public static boolean isPowerOrThoughnessGreater(Permanent sourceCreature, Permanent newCreature) { .stream()
if (newCreature.getPower().getValue() > sourceCreature.getPower().getValue()) { .map(effect -> effect.getValue("permanentEnteringBattlefield"))
return true; .findFirst()
} .orElse(null);
return newCreature.getToughness().getValue() > sourceCreature.getToughness().getValue(); return sourcePermanent != null
&& permanentEntering != null
&& sourcePermanent.isCreature(game)
&& permanentEntering.isCreature(game)
&& (permanentEntering.getPower().getValue() > sourcePermanent.getPower().getValue()
|| permanentEntering.getToughness().getValue() > sourcePermanent.getToughness().getValue());
} }
@Override @Override
@ -136,15 +117,15 @@ class EvolveEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent triggeringCreature = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (triggeringCreature != null) { if (permanent == null) {
Permanent sourceCreature = game.getPermanent(source.getSourceId()); return false;
if (sourceCreature != null && EvolveAbility.isPowerOrThoughnessGreater(sourceCreature, triggeringCreature)) {
sourceCreature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EVOLVED_CREATURE, sourceCreature.getId(), source, source.getControllerId()));
}
return true;
} }
permanent.addCounters(CounterType.P1P1.createInstance(), source, game);
game.fireEvent(GameEvent.getEvent(
GameEvent.EventType.EVOLVED_CREATURE,
permanent.getId(), source, source.getControllerId()
));
return false; return false;
} }
} }