mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Quercitron
|
||||
*/
|
||||
public class DestroyAllAttachedEquipmentEffect extends OneShotEffect {
|
||||
|
||||
public DestroyAllAttachedEquipmentEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "Destroy all Equipment attached to that creature";
|
||||
}
|
||||
|
||||
public DestroyAllAttachedEquipmentEffect(final DestroyAllAttachedEquipmentEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DestroyAllAttachedEquipmentEffect copy() {
|
||||
return new DestroyAllAttachedEquipmentEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (targetPermanent != null) {
|
||||
List<UUID> attachments = new ArrayList<>(targetPermanent.getAttachments());
|
||||
for (UUID attachmentId : attachments) {
|
||||
Permanent attachment = game.getPermanent(attachmentId);
|
||||
if (attachment != null && attachment.hasSubtype(SubType.EQUIPMENT, game)) {
|
||||
attachment.destroy(source, game, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.filter.FilterPermanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author awjackson
|
||||
*/
|
||||
public class DestroyAllAttachedToTargetEffect extends OneShotEffect {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public DestroyAllAttachedToTargetEffect(FilterPermanent filter, String description) {
|
||||
super(Outcome.DestroyPermanent);
|
||||
this.filter = filter;
|
||||
this.staticText = "destroy all " + filter.getMessage() + " attached to " + description;
|
||||
}
|
||||
|
||||
public DestroyAllAttachedToTargetEffect(final DestroyAllAttachedToTargetEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DestroyAllAttachedToTargetEffect copy() {
|
||||
return new DestroyAllAttachedToTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
|
||||
if (targetPermanent != null) {
|
||||
List<UUID> attachments = new ArrayList<>(targetPermanent.getAttachments());
|
||||
for (UUID attachmentId : attachments) {
|
||||
Permanent attachment = game.getPermanent(attachmentId);
|
||||
if (filter.match(attachment, source.getControllerId(), source, game)) {
|
||||
attachment.destroy(source, game, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.BlocksOrBlockedSourceTriggeredAbility;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
|
|
@ -10,26 +9,27 @@ import mage.abilities.effects.common.continuous.BoostSourceEffect;
|
|||
import mage.constants.Duration;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
public class BushidoAbility extends TriggeredAbilityImpl {
|
||||
/**
|
||||
* @author awjackson
|
||||
*/
|
||||
public class BushidoAbility extends BlocksOrBlockedSourceTriggeredAbility {
|
||||
|
||||
private DynamicValue value;
|
||||
private String rulesText = null;
|
||||
private final DynamicValue value;
|
||||
private final String rule;
|
||||
|
||||
public BushidoAbility(int value) {
|
||||
this(StaticValue.get(value));
|
||||
rulesText = "Bushido " + value + getReminder(Integer.toString(value));
|
||||
}
|
||||
|
||||
public BushidoAbility(DynamicValue value) {
|
||||
super(Zone.BATTLEFIELD, new BoostSourceEffect(value, value, Duration.EndOfTurn, true), false);
|
||||
if (!(value instanceof StaticValue)) {
|
||||
rulesText = "{this} has bushido X, where X is " + value.getMessage() + getReminder(value.toString());
|
||||
}
|
||||
super(new BoostSourceEffect(value, value, Duration.EndOfTurn, true));
|
||||
this.value = value;
|
||||
rule = (
|
||||
value instanceof StaticValue ?
|
||||
"Bushido " + value.toString() :
|
||||
"{this} has bushido X, where X is " + value.getMessage()
|
||||
) + getReminder(value.toString());
|
||||
}
|
||||
|
||||
static String getReminder(String xValue) {
|
||||
|
|
@ -39,28 +39,7 @@ public class BushidoAbility extends TriggeredAbilityImpl {
|
|||
public BushidoAbility(final BushidoAbility ability) {
|
||||
super(ability);
|
||||
this.value = ability.value;
|
||||
this.rulesText = ability.rulesText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.DECLARE_BLOCKERS_STEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Permanent source = game.getPermanent(getSourceId());
|
||||
if (source != null) {
|
||||
if (source.isBlocked(game)) {
|
||||
return true;
|
||||
}
|
||||
for (CombatGroup group : game.getCombat().getGroups()) {
|
||||
if (group.getBlockers().contains(getSourceId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
this.rule = ability.rule;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -74,6 +53,6 @@ public class BushidoAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return rulesText;
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -952,12 +952,11 @@ public final class StaticFilters {
|
|||
FILTER_BLOCKING_CREATURES.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterPermanent FILTER_PERMANENT_AURA = new FilterPermanent();
|
||||
public static final FilterPermanent FILTER_PERMANENT_AURAS = new FilterEnchantmentPermanent("Auras");
|
||||
|
||||
static {
|
||||
FILTER_PERMANENT_AURA.add(CardType.ENCHANTMENT.getPredicate());
|
||||
FILTER_PERMANENT_AURA.add(SubType.AURA.getPredicate());
|
||||
FILTER_PERMANENT_AURA.setLockedFilter(true);
|
||||
FILTER_PERMANENT_AURAS.add(SubType.AURA.getPredicate());
|
||||
FILTER_PERMANENT_AURAS.setLockedFilter(true);
|
||||
}
|
||||
|
||||
public static final FilterPermanent FILTER_PERMANENT_EQUIPMENT = new FilterEquipmentPermanent();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue