foul-magics/Mage/src/main/java/mage/abilities/effects/common/PermanentsEnterBattlefieldTappedEffect.java
Susucre f75b1c9f0a
Code cleanup: protect all copy constructors (#10750)
* apply regex to change public copy constructors to protected
* cleanup code using now protected constructors
* fix manaBuilder weird casting of Mana into ConditionalMana
2023-08-04 19:34:58 -04:00

69 lines
2.1 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
* @author Eirkei
*/
public class PermanentsEnterBattlefieldTappedEffect extends ReplacementEffectImpl {
protected final FilterPermanent filter;
public PermanentsEnterBattlefieldTappedEffect(FilterPermanent filter) {
this(filter, Duration.WhileOnBattlefield);
}
public PermanentsEnterBattlefieldTappedEffect(FilterPermanent filter, Duration duration) {
super(duration, Outcome.Tap, false);
this.filter = filter;
}
protected PermanentsEnterBattlefieldTappedEffect(final PermanentsEnterBattlefieldTappedEffect effect) {
super(effect);
this.filter = effect.filter;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent target = ((EntersTheBattlefieldEvent) event).getTarget();
if (target != null) {
target.tap(source, game);
}
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget();
return filter.match(permanent, source.getControllerId(), source, game);
}
@Override
public PermanentsEnterBattlefieldTappedEffect copy() {
return new PermanentsEnterBattlefieldTappedEffect(this);
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return filter.getMessage()
+ " enter the battlefield tapped"
+ (duration == Duration.EndOfTurn ? " this turn" : "");
}
}