forked from External/mage
Distinguish "blocks or becomes blocked" triggered abilities from "blocks or becomes blocked by a creature". Fixes #9347
This commit is contained in:
parent
8e67386628
commit
c8c663b976
56 changed files with 431 additions and 753 deletions
|
|
@ -1,91 +0,0 @@
|
|||
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
* @author North, Loki
|
||||
*/
|
||||
public class BlocksOrBecomesBlockedSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
protected FilterPermanent filter;
|
||||
protected String rule;
|
||||
protected boolean setTargetPointer;
|
||||
|
||||
public BlocksOrBecomesBlockedSourceTriggeredAbility(Effect effect, boolean optional) {
|
||||
this(effect, optional, true);
|
||||
}
|
||||
|
||||
public BlocksOrBecomesBlockedSourceTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) {
|
||||
this(effect, StaticFilters.FILTER_PERMANENT_CREATURE, optional, null, setTargetPointer);
|
||||
}
|
||||
|
||||
public BlocksOrBecomesBlockedSourceTriggeredAbility(Effect effect, FilterPermanent filter, boolean optional) {
|
||||
this(effect, filter, optional, null, true);
|
||||
}
|
||||
|
||||
public BlocksOrBecomesBlockedSourceTriggeredAbility(Effect effect, FilterPermanent filter, boolean optional, String rule) {
|
||||
this(effect, filter, optional, rule, true);
|
||||
}
|
||||
|
||||
public BlocksOrBecomesBlockedSourceTriggeredAbility(Effect effect, FilterPermanent filter, boolean optional, String rule, boolean setTargetPointer) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.filter = filter;
|
||||
this.rule = rule;
|
||||
this.setTargetPointer = setTargetPointer;
|
||||
setTriggerPhrase("Whenever {this} blocks or becomes blocked" + (setTargetPointer ? " by a " + filter.getMessage() : "") + ", ");
|
||||
}
|
||||
|
||||
public BlocksOrBecomesBlockedSourceTriggeredAbility(final BlocksOrBecomesBlockedSourceTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.filter = ability.filter;
|
||||
this.rule = ability.rule;
|
||||
this.setTargetPointer = ability.setTargetPointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.BLOCKER_DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getSourceId().equals(this.getSourceId())) {
|
||||
Permanent blocked = game.getPermanent(event.getTargetId());
|
||||
if (filter.match(blocked, game)) {
|
||||
if (setTargetPointer) {
|
||||
this.getEffects().setTargetPointer(new FixedTarget(blocked, game));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (event.getTargetId().equals(this.getSourceId())) {
|
||||
Permanent blocker = game.getPermanent(event.getSourceId());
|
||||
if (filter.match(blocker, game)) {
|
||||
if (setTargetPointer) {
|
||||
this.getEffects().setTargetPointer(new FixedTarget(blocker, game));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return rule != null ? rule : super.getRule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlocksOrBecomesBlockedSourceTriggeredAbility copy() {
|
||||
return new BlocksOrBecomesBlockedSourceTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author awjackson
|
||||
*/
|
||||
public class BlocksOrBlockedByCreatureSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public BlocksOrBlockedByCreatureSourceTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
|
||||
public BlocksOrBlockedByCreatureSourceTriggeredAbility(Effect effect, FilterPermanent filter) {
|
||||
this(effect, filter, false);
|
||||
}
|
||||
|
||||
public BlocksOrBlockedByCreatureSourceTriggeredAbility(Effect effect, boolean optional) {
|
||||
this(effect, StaticFilters.FILTER_PERMANENT_CREATURE, optional);
|
||||
}
|
||||
|
||||
public BlocksOrBlockedByCreatureSourceTriggeredAbility(Effect effect, FilterPermanent filter, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.filter = filter;
|
||||
setTriggerPhrase("Whenever {this} blocks or becomes blocked by " + CardUtil.addArticle(filter.getMessage()) + ", ");
|
||||
}
|
||||
|
||||
public BlocksOrBlockedByCreatureSourceTriggeredAbility(final BlocksOrBlockedByCreatureSourceTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.filter = ability.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.BLOCKER_DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Permanent otherCreature = null;
|
||||
if (this.getSourceId().equals(event.getSourceId())) {
|
||||
otherCreature = game.getPermanent(event.getTargetId());
|
||||
} else if (this.getSourceId().equals(event.getTargetId())) {
|
||||
otherCreature = game.getPermanent(event.getSourceId());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!filter.match(otherCreature, getControllerId(), this, game)) {
|
||||
return false;
|
||||
}
|
||||
getEffects().setTargetPointer(new FixedTarget(otherCreature, game));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlocksOrBlockedByCreatureSourceTriggeredAbility copy() {
|
||||
return new BlocksOrBlockedByCreatureSourceTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* @author awjackson
|
||||
*/
|
||||
public class BlocksOrBlockedSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public BlocksOrBlockedSourceTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
public BlocksOrBlockedSourceTriggeredAbility(Effect effect, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
setTriggerPhrase("Whenever {this} blocks or becomes blocked, ");
|
||||
}
|
||||
|
||||
public BlocksOrBlockedSourceTriggeredAbility(final BlocksOrBlockedSourceTriggeredAbility 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) {
|
||||
return event.getTargetId().equals(getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlocksOrBlockedSourceTriggeredAbility copy() {
|
||||
return new BlocksOrBlockedSourceTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue