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