use of mage.game.events.ZoneChangeEvent in project mage by magefree.
the class NimDeathmantleEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
Permanent permanent = zEvent.getTarget();
if (permanent != null && permanent.isOwnedBy(this.controllerId) && zEvent.isDiesEvent() && !(permanent instanceof PermanentToken) && permanent.isCreature(game)) {
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId(), permanent.getZoneChangeCounter(game) + 1));
return true;
}
return false;
}
use of mage.game.events.ZoneChangeEvent in project mage by magefree.
the class RayamiFirstOfTheFallenReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || permanent == null) {
return false;
}
controller.moveCards(permanent, Zone.EXILED, source, game);
Card card = game.getCard(permanent.getId());
card.addCounters(CounterType.BLOOD.createInstance(), source.getControllerId(), source, game);
return true;
}
use of mage.game.events.ZoneChangeEvent in project mage by magefree.
the class VoltaicVisionaryWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.ZONE_CHANGE || ((ZoneChangeEvent) event).getToZone() != Zone.EXILED) {
return;
}
Card card = game.getCard(event.getTargetId());
UUID exileId = game.getExile().getExileZones().stream().filter(exileZone -> exileZone.contains(card)).map(ExileZone::getId).findFirst().orElse(null);
if (exileId == null) {
return;
}
map.computeIfAbsent(exileId, x -> new HashSet<>()).add(new MageObjectReference(card, game));
}
use of mage.game.events.ZoneChangeEvent in project mage by magefree.
the class DiesAttachedTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!((ZoneChangeEvent) event).isDiesEvent()) {
return false;
}
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
boolean triggered = false;
if (zEvent.getTarget() != null && zEvent.getTarget().getAttachments() != null && zEvent.getTarget().getAttachments().contains(this.getSourceId())) {
triggered = true;
} else {
// If the attachment and attachedTo went to graveyard at the same time, the trigger applies.
// If the attachment is removed beforehand, the trigger fails.
// IE: A player cast Planar Clensing. The attachment is Disenchanted in reponse
// and successfully removed from the attachedTo. The trigger fails.
Permanent attachment = getSourcePermanentOrLKI(game);
Card attachmentCard = game.getCard(getSourceId());
if (attachment != null && zEvent.getTargetId() != null && attachment.getAttachedTo() != null && zEvent.getTargetId().equals(attachment.getAttachedTo())) {
Permanent attachedTo = game.getPermanentOrLKIBattlefield(attachment.getAttachedTo());
if (attachedTo != null && // Demonic Vigor
game.getState().getZone(attachedTo.getId()) == (Zone.GRAVEYARD) && attachmentCard != null && attachment.getAttachedToZoneChangeCounter() == attachedTo.getZoneChangeCounter(game) && attachment.getZoneChangeCounter(game) == attachmentCard.getZoneChangeCounter(game)) {
triggered = true;
}
}
}
if (!triggered) {
return false;
}
if (zEvent.getTarget() == null) {
return true;
}
getEffects().setValue("attachedTo", zEvent.getTarget());
// zone change info from battlefield
getEffects().setValue("zcc", zEvent.getTarget().getZoneChangeCounter(game) + 1);
if (setTargetPointer == SetTargetPointer.ATTACHED_TO_CONTROLLER) {
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
if (attachment != null && attachment.getAttachedTo() != null) {
Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
if (attachedTo != null) {
getEffects().setTargetPointer(new FixedTarget(attachedTo.getControllerId()));
}
}
}
// set targetpointer to the creature that died
if (setTargetPointer == SetTargetPointer.CARD || setTargetPointer == SetTargetPointer.PERMANENT) {
Permanent attachment = game.getPermanentOrLKIBattlefield(getSourceId());
if (attachment != null && attachment.getAttachedTo() != null) {
Permanent attachedTo = (Permanent) game.getLastKnownInformation(attachment.getAttachedTo(), Zone.BATTLEFIELD, attachment.getAttachedToZoneChangeCounter());
if (attachedTo != null) {
getEffects().setTargetPointer(new FixedTarget(attachedTo.getId()));
}
}
}
return true;
}
use of mage.game.events.ZoneChangeEvent in project mage by magefree.
the class GodEternalEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getTargetId().equals(this.getSourceId())) {
this.getEffects().clear();
this.addEffect(new GodEternalEffect(new MageObjectReference(zEvent.getTarget(), game)));
return true;
}
return false;
}
Aggregations