mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
* Fixed that CantCounterSourceEffect only prevents the SpellAbility from beeing countered and not e.g. triggered abilities from that source (fixes #625).
This commit is contained in:
parent
1cdf2ab4b0
commit
109e18fdd5
2 changed files with 18 additions and 5 deletions
|
@ -36,6 +36,7 @@ import mage.constants.Outcome;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.GameEvent.EventType;
|
import mage.game.events.GameEvent.EventType;
|
||||||
|
import mage.game.stack.Spell;
|
||||||
import mage.game.stack.StackObject;
|
import mage.game.stack.StackObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,9 +77,9 @@ public class CantCounterSourceEffect extends ContinuousRuleModifiyingEffectImpl
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
if (event.getType() == EventType.COUNTER) {
|
if (event.getType() == EventType.COUNTER) {
|
||||||
StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
|
Spell spell = game.getStack().getSpell(event.getTargetId());
|
||||||
if (stackObject != null) {
|
if (spell != null) {
|
||||||
if (stackObject.getSourceId().equals(source.getSourceId())) {
|
if (spell.getSourceId().equals(source.getSourceId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,16 +82,28 @@ public class SpellStack extends ArrayDeque<StackObject> {
|
||||||
StackObject stackObject = getStackObject(objectId);
|
StackObject stackObject = getStackObject(objectId);
|
||||||
MageObject sourceObject = game.getObject(sourceId);
|
MageObject sourceObject = game.getObject(sourceId);
|
||||||
if (stackObject != null && sourceObject != null) {
|
if (stackObject != null && sourceObject != null) {
|
||||||
|
MageObject targetSourceObject = game.getObject(stackObject.getSourceId());
|
||||||
|
String counteredObjectName, targetSourceName;
|
||||||
|
if (targetSourceObject == null) {
|
||||||
|
targetSourceName = "[Object not found]";
|
||||||
|
} else {
|
||||||
|
targetSourceName = game.getObject(stackObject.getSourceId()).getName();
|
||||||
|
}
|
||||||
|
if (stackObject instanceof Spell) {
|
||||||
|
counteredObjectName = targetSourceName;
|
||||||
|
} else {
|
||||||
|
counteredObjectName = "Ability (" + stackObject.getStackAbility().getRule(targetSourceName) + ") of " + targetSourceName;
|
||||||
|
}
|
||||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER, objectId, sourceId, stackObject.getControllerId()))) {
|
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER, objectId, sourceId, stackObject.getControllerId()))) {
|
||||||
if ( stackObject instanceof Spell ) {
|
if ( stackObject instanceof Spell ) {
|
||||||
game.rememberLKI(objectId, Zone.STACK, (Spell)stackObject);
|
game.rememberLKI(objectId, Zone.STACK, (Spell)stackObject);
|
||||||
}
|
}
|
||||||
this.remove(stackObject);
|
this.remove(stackObject);
|
||||||
stackObject.counter(sourceId, game); // tries to move to graveyard
|
stackObject.counter(sourceId, game); // tries to move to graveyard
|
||||||
game.informPlayers(new StringBuilder(stackObject.getName()).append(" is countered by ").append(sourceObject.getLogName()).toString());
|
game.informPlayers(counteredObjectName + " is countered by " + sourceObject.getLogName());
|
||||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERED, objectId, sourceId, stackObject.getControllerId()));
|
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERED, objectId, sourceId, stackObject.getControllerId()));
|
||||||
} else {
|
} else {
|
||||||
game.informPlayers(new StringBuilder(stackObject.getName()).append(" could not be countered by ").append(sourceObject.getLogName()).toString());
|
game.informPlayers(counteredObjectName + " could not be countered by " + sourceObject.getLogName());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue