This commit is contained in:
jeff@delmarus.com 2021-08-28 15:40:46 -05:00
parent b6acaed99d
commit 5a87664a55
2 changed files with 17 additions and 34 deletions

View file

@ -1,7 +1,5 @@
package mage.cards.d;
import java.util.Objects;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
@ -20,9 +18,7 @@ import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.game.stack.StackObject;
import mage.players.Player;
/**
@ -71,38 +67,15 @@ public final class DivineIntervention extends CardImpl {
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.COUNTER_REMOVED;
return event.getType() == GameEvent.EventType.COUNTERS_REMOVED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getData().equals(CounterType.INTERVENTION.getName()) && event.getTargetId().equals(this.getSourceId())) {
boolean onlyYouOnStack = true;
boolean onlyOpponentOnStack = true;
UUID you = getControllerId();
boolean firstOnStack = false;
for (StackObject stackObject : game.getStack()) {
if (stackObject.getControllerId() != null && !firstOnStack) {
if (!Objects.equals(you, stackObject.getControllerId())) {
onlyYouOnStack = false;
} else if (Objects.equals(you, stackObject.getControllerId())) {
onlyOpponentOnStack = false;
}
firstOnStack = true;
}
}
if (onlyYouOnStack && !onlyOpponentOnStack) {
return true;
} else if (!onlyYouOnStack && onlyOpponentOnStack) {
return false;
}
}
return false;
return (event.getData().equals(CounterType.INTERVENTION.getName())
&& event.getTargetId().equals(this.getSourceId())
&& event.getPlayerId() != null
&& event.getPlayerId() == this.getControllerId()); // the controller of this removed the counter
}
@Override
@ -131,8 +104,10 @@ public final class DivineIntervention extends CardImpl {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
if (game.getState().getZone(sourcePermanent.getId()) == Zone.BATTLEFIELD && sourcePermanent.getCounters(game).getCount(CounterType.INTERVENTION) == 0) {
if (controller != null
&& sourcePermanent != null) {
if (game.getState().getZone(sourcePermanent.getId()) == Zone.BATTLEFIELD
&& sourcePermanent.getCounters(game).getCount(CounterType.INTERVENTION) == 0) {
game.setDraw(controller.getId());
}
return true;

View file

@ -747,11 +747,19 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
break;
}
GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTER_REMOVED, objectId, source, getControllerOrOwner());
if (source != null
&& source.getControllerId() != null) {
event.setPlayerId(source.getControllerId()); // player who controls the source ability that removed the counter
}
event.setData(name);
game.fireEvent(event);
finalAmount++;
}
GameEvent event = GameEvent.getEvent(GameEvent.EventType.COUNTERS_REMOVED, objectId, source, getControllerOrOwner());
if (source != null
&& source.getControllerId() != null) {
event.setPlayerId(source.getControllerId()); // player who controls the source ability that removed the counter
}
event.setData(name);
event.setAmount(finalAmount);
game.fireEvent(event);