Distinguish "blocks or becomes blocked" triggered abilities from "blocks or becomes blocked by a creature". Fixes #9347

This commit is contained in:
Alex W. Jackson 2022-09-25 02:53:07 -04:00
parent 8e67386628
commit c8c663b976
56 changed files with 431 additions and 753 deletions

View file

@ -0,0 +1,48 @@
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.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
* @author awjackson
*/
public class BlocksOrBlockedAttachedTriggeredAbility extends TriggeredAbilityImpl {
public BlocksOrBlockedAttachedTriggeredAbility(Effect effect) {
this(effect, false);
}
public BlocksOrBlockedAttachedTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, effect, optional);
setTriggerPhrase("Whenever enchanted creature blocks or becomes blocked, ");
}
public BlocksOrBlockedAttachedTriggeredAbility(final BlocksOrBlockedAttachedTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CREATURE_BLOCKS
|| event.getType() == GameEvent.EventType.CREATURE_BLOCKED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent creature = game.getPermanent(event.getTargetId());
if (creature == null || !creature.getAttachments().contains(getSourceId())) {
return false;
}
getEffects().setTargetPointer(new FixedTarget(creature, game));
return true;
}
@Override
public BlocksOrBlockedAttachedTriggeredAbility copy() {
return new BlocksOrBlockedAttachedTriggeredAbility(this);
}
}