foul-magics/Mage/src/main/java/mage/abilities/common/AttacksAndIsNotBlockedTriggeredAbility.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

56 lines
1.8 KiB
Java

package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
public class AttacksAndIsNotBlockedTriggeredAbility extends TriggeredAbilityImpl {
private final boolean setTargetPointer;
public AttacksAndIsNotBlockedTriggeredAbility(Effect effect) {
this(effect, false, false);
}
public AttacksAndIsNotBlockedTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public AttacksAndIsNotBlockedTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
setTriggerPhrase("Whenever {this} attacks and isn't blocked, ");
}
protected AttacksAndIsNotBlockedTriggeredAbility(final AttacksAndIsNotBlockedTriggeredAbility ability) {
super(ability);
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public AttacksAndIsNotBlockedTriggeredAbility copy() {
return new AttacksAndIsNotBlockedTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.UNBLOCKED_ATTACKER;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getTargetId().equals(getSourceId())) {
return false;
}
if (setTargetPointer) {
this.getEffects().setTargetPointer(new FixedTarget(
game.getCombat().getDefendingPlayerId(getSourceId(), game), game
));
}
return true;
}
}