mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 13:32:06 -08:00
Fixing multiple triggers during combat (#8017)
* Fixing multiple triggers during combat * Damage to Source Logic * Removing unused references
This commit is contained in:
parent
ff43670a2a
commit
86e5c5cb50
2 changed files with 64 additions and 36 deletions
|
|
@ -1,12 +1,15 @@
|
|||
|
||||
package mage.abilities.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.AbilityWord;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamagedEvent;
|
||||
import mage.game.events.DamagedPermanentBatchEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
/**
|
||||
|
|
@ -15,7 +18,6 @@ import mage.game.events.GameEvent;
|
|||
public class DealtDamageToSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private final boolean useValue;
|
||||
private boolean usedForCombatDamageStep;
|
||||
|
||||
public DealtDamageToSourceTriggeredAbility(Effect effect, boolean optional) {
|
||||
this(effect, optional, false);
|
||||
|
|
@ -28,7 +30,6 @@ public class DealtDamageToSourceTriggeredAbility extends TriggeredAbilityImpl {
|
|||
public DealtDamageToSourceTriggeredAbility(Effect effect, boolean optional, boolean enrage, boolean useValue) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.useValue = useValue;
|
||||
this.usedForCombatDamageStep = false;
|
||||
if (enrage) {
|
||||
this.setAbilityWord(AbilityWord.ENRAGE);
|
||||
}
|
||||
|
|
@ -37,7 +38,6 @@ public class DealtDamageToSourceTriggeredAbility extends TriggeredAbilityImpl {
|
|||
public DealtDamageToSourceTriggeredAbility(final DealtDamageToSourceTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.useValue = ability.useValue;
|
||||
this.usedForCombatDamageStep = ability.usedForCombatDamageStep;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -47,30 +47,34 @@ public class DealtDamageToSourceTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.DAMAGED_PERMANENT || event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST;
|
||||
return event.getType() == GameEvent.EventType.DAMAGED_PERMANENT_BATCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DAMAGED_PERMANENT && event.getTargetId().equals(getSourceId())) {
|
||||
if (useValue) {
|
||||
// TODO: this ability should only trigger once for multiple creatures dealing combat damage.
|
||||
// If the damaged creature uses the amount (e.g. Boros Reckoner), this will still trigger separately instead of all at once
|
||||
getEffects().setValue("damage", event.getAmount());
|
||||
return true;
|
||||
} else {
|
||||
if (((DamagedEvent) event).isCombatDamage()) {
|
||||
if (!usedForCombatDamageStep) {
|
||||
usedForCombatDamageStep = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event == null || game == null || this.getSourceId() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int damage = 0;
|
||||
DamagedPermanentBatchEvent dEvent = (DamagedPermanentBatchEvent) event;
|
||||
for (DamagedEvent damagedEvent : dEvent.getEvents()) {
|
||||
UUID targetID = damagedEvent.getTargetId();
|
||||
if (targetID == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (targetID == this.getSourceId()) {
|
||||
damage += damagedEvent.getAmount();
|
||||
}
|
||||
}
|
||||
if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
|
||||
usedForCombatDamageStep = false;
|
||||
|
||||
if (damage > 0) {
|
||||
if (this.useValue) {
|
||||
this.getEffects().setValue("damage", damage);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue