mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Fix various 'deals damage to a creature' abilities triggering on damage to planeswalkers
This commit is contained in:
parent
7ca7e10d80
commit
79234b4059
4 changed files with 41 additions and 47 deletions
|
@ -16,7 +16,7 @@ import mage.target.targetpointer.FixedTarget;
|
||||||
*/
|
*/
|
||||||
public class DealsDamageToACreatureAllTriggeredAbility extends TriggeredAbilityImpl {
|
public class DealsDamageToACreatureAllTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
private final boolean combatDamageOnly;
|
private final boolean combatOnly;
|
||||||
private final FilterPermanent filterPermanent;
|
private final FilterPermanent filterPermanent;
|
||||||
private final SetTargetPointer setTargetPointer;
|
private final SetTargetPointer setTargetPointer;
|
||||||
|
|
||||||
|
@ -32,19 +32,19 @@ public class DealsDamageToACreatureAllTriggeredAbility extends TriggeredAbilityI
|
||||||
* - PLAYER = player controlling the damage source.<br>
|
* - PLAYER = player controlling the damage source.<br>
|
||||||
* - PERMANENT = source permanent.<br>
|
* - PERMANENT = source permanent.<br>
|
||||||
* - PERMANENT_TARGET = damaged creature.
|
* - PERMANENT_TARGET = damaged creature.
|
||||||
* @param combatDamageOnly The flag to determine if only combat damage has
|
* @param combatOnly The flag to determine if only combat damage has
|
||||||
* to trigger
|
* to trigger
|
||||||
*/
|
*/
|
||||||
public DealsDamageToACreatureAllTriggeredAbility(Effect effect, boolean optional, FilterPermanent filterPermanent, SetTargetPointer setTargetPointer, boolean combatDamageOnly) {
|
public DealsDamageToACreatureAllTriggeredAbility(Effect effect, boolean optional, FilterPermanent filterPermanent, SetTargetPointer setTargetPointer, boolean combatOnly) {
|
||||||
super(Zone.BATTLEFIELD, effect, optional);
|
super(Zone.BATTLEFIELD, effect, optional);
|
||||||
this.combatDamageOnly = combatDamageOnly;
|
this.combatOnly = combatOnly;
|
||||||
this.setTargetPointer = setTargetPointer;
|
this.setTargetPointer = setTargetPointer;
|
||||||
this.filterPermanent = filterPermanent;
|
this.filterPermanent = filterPermanent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DealsDamageToACreatureAllTriggeredAbility(final DealsDamageToACreatureAllTriggeredAbility ability) {
|
public DealsDamageToACreatureAllTriggeredAbility(final DealsDamageToACreatureAllTriggeredAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
this.combatDamageOnly = ability.combatDamageOnly;
|
this.combatOnly = ability.combatOnly;
|
||||||
this.filterPermanent = ability.filterPermanent;
|
this.filterPermanent = ability.filterPermanent;
|
||||||
this.setTargetPointer = ability.setTargetPointer;
|
this.setTargetPointer = ability.setTargetPointer;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class DealsDamageToACreatureAllTriggeredAbility extends TriggeredAbilityI
|
||||||
if (permanent == null || !permanent.isCreature(game)) {
|
if (permanent == null || !permanent.isCreature(game)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (combatDamageOnly && !((DamagedEvent) event).isCombatDamage()) {
|
if (combatOnly && !((DamagedEvent) event).isCombatDamage()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
|
permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
|
||||||
|
@ -94,6 +94,6 @@ public class DealsDamageToACreatureAllTriggeredAbility extends TriggeredAbilityI
|
||||||
@Override
|
@Override
|
||||||
public String getTriggerPhrase() {
|
public String getTriggerPhrase() {
|
||||||
return "Whenever " + filterPermanent.getMessage() + " deals "
|
return "Whenever " + filterPermanent.getMessage() + " deals "
|
||||||
+ (combatDamageOnly ? "combat " : "") + "damage to a creature, ";
|
+ (combatOnly ? "combat " : "") + "damage to a creature, ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,15 @@ public class DealsDamageToACreatureAttachedTriggeredAbility extends TriggeredAbi
|
||||||
|
|
||||||
public DealsDamageToACreatureAttachedTriggeredAbility(Effect effect, boolean combatOnly, String attachedDescription, boolean optional, boolean setTargetPointer) {
|
public DealsDamageToACreatureAttachedTriggeredAbility(Effect effect, boolean combatOnly, String attachedDescription, boolean optional, boolean setTargetPointer) {
|
||||||
super(Zone.BATTLEFIELD, effect, optional);
|
super(Zone.BATTLEFIELD, effect, optional);
|
||||||
|
this.combatOnly = combatOnly;
|
||||||
this.setTargetPointer = setTargetPointer;
|
this.setTargetPointer = setTargetPointer;
|
||||||
this.attachedDescription = attachedDescription;
|
this.attachedDescription = attachedDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DealsDamageToACreatureAttachedTriggeredAbility(final DealsDamageToACreatureAttachedTriggeredAbility ability) {
|
public DealsDamageToACreatureAttachedTriggeredAbility(final DealsDamageToACreatureAttachedTriggeredAbility ability) {
|
||||||
super(ability);
|
super(ability);
|
||||||
this.setTargetPointer = ability.setTargetPointer;
|
|
||||||
this.combatOnly = ability.combatOnly;
|
this.combatOnly = ability.combatOnly;
|
||||||
|
this.setTargetPointer = ability.setTargetPointer;
|
||||||
this.attachedDescription = ability.attachedDescription;
|
this.attachedDescription = ability.attachedDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,29 +46,29 @@ public class DealsDamageToACreatureAttachedTriggeredAbility extends TriggeredAbi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
if (!combatOnly || ((DamagedEvent) event).isCombatDamage()) {
|
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||||
Permanent attachment = game.getPermanent(this.getSourceId());
|
if (permanent == null || !permanent.isCreature(game)) {
|
||||||
if (attachment != null
|
return false;
|
||||||
&& attachment.isAttachedTo(event.getSourceId())) {
|
|
||||||
if (setTargetPointer) {
|
|
||||||
for (Effect effect : this.getEffects()) {
|
|
||||||
effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
|
|
||||||
effect.setValue("damage", event.getAmount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
if (combatOnly && !((DamagedEvent) event).isCombatDamage()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Permanent attachment = game.getPermanent(this.getSourceId());
|
||||||
|
if (attachment == null || !attachment.isAttachedTo(event.getSourceId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (setTargetPointer) {
|
||||||
|
for (Effect effect : this.getEffects()) {
|
||||||
|
effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
|
||||||
|
effect.setValue("damage", event.getAmount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTriggerPhrase() {
|
public String getTriggerPhrase() {
|
||||||
return new StringBuilder("Whenever ").append(attachedDescription)
|
return "Whenever " + attachedDescription + " deals "
|
||||||
.append(" deals ")
|
+ (combatOnly ? "combat " : "") + "damage to a creature, ";
|
||||||
.append(combatOnly ? "combat " : "")
|
|
||||||
.append("damage to a creature, ").toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package mage.abilities.common;
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
|
import mage.filter.StaticFilters;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
import mage.filter.common.FilterCreaturePermanent;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.DamagedEvent;
|
import mage.game.events.DamagedEvent;
|
||||||
|
@ -16,12 +17,12 @@ import mage.target.targetpointer.FixedTarget;
|
||||||
*/
|
*/
|
||||||
public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl {
|
public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
private boolean combatOnly;
|
protected boolean combatOnly;
|
||||||
private final boolean setTargetPointer;
|
private final boolean setTargetPointer;
|
||||||
private FilterCreaturePermanent filter;
|
private FilterCreaturePermanent filter;
|
||||||
|
|
||||||
public DealsDamageToACreatureTriggeredAbility(Effect effect, boolean combatOnly, boolean optional, boolean setTargetPointer) {
|
public DealsDamageToACreatureTriggeredAbility(Effect effect, boolean combatOnly, boolean optional, boolean setTargetPointer) {
|
||||||
this(effect, combatOnly, optional, setTargetPointer, null);
|
this(effect, combatOnly, optional, setTargetPointer, StaticFilters.FILTER_PERMANENT_A_CREATURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DealsDamageToACreatureTriggeredAbility(Effect effect, boolean combatOnly, boolean optional, boolean setTargetPointer, FilterCreaturePermanent filter) {
|
public DealsDamageToACreatureTriggeredAbility(Effect effect, boolean combatOnly, boolean optional, boolean setTargetPointer, FilterCreaturePermanent filter) {
|
||||||
|
@ -52,12 +53,12 @@ public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
if (event.getSourceId().equals(this.sourceId)
|
if (event.getSourceId().equals(this.sourceId)
|
||||||
&& (!combatOnly || ((DamagedEvent) event).isCombatDamage())) {
|
&& (!combatOnly || ((DamagedEvent) event).isCombatDamage())) {
|
||||||
if (filter != null) {
|
|
||||||
Permanent creature = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
Permanent creature = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
||||||
if (!filter.match(creature, getControllerId(), this, game)) {
|
if (!filter.match(creature, getControllerId(), this, game)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setTargetPointer) {
|
if (setTargetPointer) {
|
||||||
this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId(), game));
|
this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId(), game));
|
||||||
this.getEffects().setValue("damage", event.getAmount());
|
this.getEffects().setValue("damage", event.getAmount());
|
||||||
|
@ -69,18 +70,6 @@ public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTriggerPhrase() {
|
public String getTriggerPhrase() {
|
||||||
StringBuilder sb = new StringBuilder("Whenever {this} deals ");
|
return "Whenever {this} deals " + (combatOnly ? "combat " : "") + "damage to " + filter.getMessage() + ", ";
|
||||||
if (combatOnly) {
|
|
||||||
sb.append("combat ");
|
|
||||||
}
|
|
||||||
sb.append("damage to ");
|
|
||||||
if (filter == null) {
|
|
||||||
sb.append("a creature, ");
|
|
||||||
} else {
|
|
||||||
sb.append(filter.getMessage());
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,4 +46,8 @@ public class DealsDamageToOneOrMoreCreaturesTriggeredAbility extends DealsDamage
|
||||||
return new DealsDamageToOneOrMoreCreaturesTriggeredAbility(this);
|
return new DealsDamageToOneOrMoreCreaturesTriggeredAbility(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTriggerPhrase() {
|
||||||
|
return "Whenever {this} deals " + (combatOnly ? "combat " : "") + "damage to one or more creatures, ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue