mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 22:42:03 -08:00
* Fixed target hadnling of PreventDamageBySourceEffect (fixes #952).
This commit is contained in:
parent
1f44e1a592
commit
6403fff12b
4 changed files with 168 additions and 7 deletions
|
|
@ -32,6 +32,7 @@ import java.util.UUID;
|
|||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
|
||||
/**
|
||||
* A object reference that takes zone changes into account.
|
||||
|
|
@ -61,7 +62,7 @@ public class MageObjectReference implements Comparable<MageObjectReference> {
|
|||
this.zoneChangeCounter = zoneChangeCounter;
|
||||
}
|
||||
|
||||
public MageObjectReference(UUID sourceId, Game game) {
|
||||
public MageObjectReference(UUID sourceId, Game game) {
|
||||
this.sourceId = sourceId;
|
||||
MageObject mageObject = game.getObject(sourceId);
|
||||
if (mageObject != null) {
|
||||
|
|
@ -110,6 +111,9 @@ public class MageObjectReference implements Comparable<MageObjectReference> {
|
|||
|
||||
public boolean refersTo(MageObject mageObject, Game game) {
|
||||
if (mageObject != null) {
|
||||
if (mageObject instanceof Spell) {
|
||||
return ((Spell)mageObject).getSourceId().equals(sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
}
|
||||
return mageObject.getId().equals(sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ public class PreventDamageBySourceEffect extends PreventionEffectImpl {
|
|||
public PreventDamageBySourceEffect(final PreventDamageBySourceEffect effect) {
|
||||
super(effect);
|
||||
this.target = effect.target.copy();
|
||||
this.mageObjectReference = effect.mageObjectReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -77,16 +78,16 @@ public class PreventDamageBySourceEffect extends PreventionEffectImpl {
|
|||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
|
||||
setTargetPointer(new FixedTarget(target.getFirstTarget()));
|
||||
mageObjectReference = new MageObjectReference(target.getFirstTarget(), game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (super.applies(event, source, game)) {
|
||||
Card card = game.getCard(((FixedTarget)getTargetPointer()).getTarget());
|
||||
if(card != null) {
|
||||
return card.getId().equals(event.getSourceId());
|
||||
}
|
||||
MageObject mageObject = game.getObject(event.getSourceId());
|
||||
if (mageObject != null && mageObjectReference.refersTo(mageObject, game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue