forked from External/mage
Combat.getAttackers and Combat.getBlockers now return a Set instead of a List, so that two-headed blockers aren't included twice
This commit is contained in:
parent
efaccf8564
commit
a6c5209a2a
20 changed files with 192 additions and 354 deletions
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.AttachmentType;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* "When enchanted/equipped creature attacks " triggered ability
|
||||
|
|
@ -20,7 +20,7 @@ import java.util.Locale;
|
|||
public class AttacksAttachedTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private final AttachmentType attachmentType;
|
||||
private final boolean setTargetPointer;
|
||||
private final SetTargetPointer setTargetPointer;
|
||||
|
||||
public AttacksAttachedTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
|
|
@ -31,20 +31,20 @@ public class AttacksAttachedTriggeredAbility extends TriggeredAbilityImpl {
|
|||
}
|
||||
|
||||
public AttacksAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType, boolean optional) {
|
||||
this(effect, attachmentType, optional, false);
|
||||
this(effect, attachmentType, optional, SetTargetPointer.NONE);
|
||||
}
|
||||
|
||||
public AttacksAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType, boolean optional, boolean setTargetPointer) {
|
||||
public AttacksAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType, boolean optional, SetTargetPointer setTargetPointer) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.attachmentType = attachmentType;
|
||||
this.setTargetPointer = setTargetPointer;
|
||||
setTriggerPhrase("Whenever " + attachmentType.verb().toLowerCase(Locale.ENGLISH) + " creature attacks, ");
|
||||
setTriggerPhrase("Whenever " + attachmentType.verb().toLowerCase() + " creature attacks, ");
|
||||
}
|
||||
|
||||
public AttacksAttachedTriggeredAbility(final AttacksAttachedTriggeredAbility abiltity) {
|
||||
super(abiltity);
|
||||
this.attachmentType = abiltity.attachmentType;
|
||||
this.setTargetPointer = abiltity.setTargetPointer;
|
||||
protected AttacksAttachedTriggeredAbility(final AttacksAttachedTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.attachmentType = ability.attachmentType;
|
||||
this.setTargetPointer = ability.setTargetPointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -59,20 +59,19 @@ public class AttacksAttachedTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Permanent equipment = game.getPermanent(this.sourceId);
|
||||
if (equipment != null && equipment.getAttachedTo() != null
|
||||
&& event.getSourceId().equals(equipment.getAttachedTo())) {
|
||||
getEffects().setValue("sourceId", event.getSourceId());
|
||||
// TODO: Passing a permanent object like this can cause bugs. May need refactoring to use UUID instead.
|
||||
// See https://github.com/magefree/mage/issues/8377
|
||||
// 11-08-2021: Added a new constructor to set target pointer. Should probably be using this instead.
|
||||
Permanent attachedPermanent = game.getPermanent(event.getSourceId());
|
||||
getEffects().setValue("attachedPermanent", attachedPermanent);
|
||||
if (setTargetPointer && attachedPermanent != null) {
|
||||
getEffects().setTargetPointer(new FixedTarget(attachedPermanent, game));
|
||||
}
|
||||
return true;
|
||||
Permanent attachment = getSourcePermanentOrLKI(game);
|
||||
UUID attackerId = event.getSourceId();
|
||||
if (attachment == null || !attackerId.equals(attachment.getAttachedTo())) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
switch (setTargetPointer) {
|
||||
case PERMANENT:
|
||||
getEffects().setTargetPointer(new FixedTarget(attackerId, game));
|
||||
break;
|
||||
case PLAYER:
|
||||
getEffects().setTargetPointer(new FixedTarget(game.getCombat().getDefendingPlayerId(attackerId, game)));
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue