Search in sources :

Example 51 with ZoneChangeEvent

use of mage.game.events.ZoneChangeEvent in project mage by magefree.

the class CardsPutIntoGraveyardWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.ZONE_CHANGE || ((ZoneChangeEvent) event).getToZone() != Zone.GRAVEYARD) {
        return;
    }
    UUID playerId = event.getPlayerId();
    if (playerId == null || game.getCard(event.getTargetId()) == null) {
        return;
    }
    amountOfCardsThisTurn.compute(playerId, (k, amount) -> amount == null ? 1 : Integer.sum(amount, 1));
    if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
        cardsPutIntoGraveyardFromBattlefield.add(new MageObjectReference(((ZoneChangeEvent) event).getTarget(), game, 1));
    } else {
        cardsPutIntoGraveyardFromEverywhereElse.add(new MageObjectReference(((ZoneChangeEvent) event).getTarget(), game, 1));
    }
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObjectReference(mage.MageObjectReference)

Example 52 with ZoneChangeEvent

use of mage.game.events.ZoneChangeEvent in project mage by magefree.

the class CreaturesDiedWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
        ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
        if (zEvent.isDiesEvent() && zEvent.getTarget() != null && zEvent.getTarget().isCreature(game)) {
            int amount = getAmountOfCreaturesDiedThisTurnByController(zEvent.getTarget().getControllerId());
            amountOfCreaturesThatDiedByController.put(zEvent.getTarget().getControllerId(), amount + 1);
            amount = getAmountOfCreaturesDiedThisTurnByOwner(zEvent.getTarget().getOwnerId());
            amountOfCreaturesThatDiedByOwner.put(zEvent.getTarget().getOwnerId(), amount + 1);
        }
    }
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent)

Example 53 with ZoneChangeEvent

use of mage.game.events.ZoneChangeEvent in project mage by magefree.

the class EnigmaSphinxEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent != null && zEvent.isDiesEvent() && permanent.getId().equals(this.getSourceId()) && // graveyard from the battlefield, so Enigma Sphinx's middle ability won't trigger.
    permanent.isOwnedBy(permanent.getControllerId())) {
        return true;
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent)

Example 54 with ZoneChangeEvent

use of mage.game.events.ZoneChangeEvent in project mage by magefree.

the class FalkenrathNobleTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (!zEvent.isDiesEvent()) {
        return false;
    }
    Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
    if (permanent == null) {
        return false;
    }
    if (permanent.getId().equals(this.getSourceId())) {
        return true;
    }
    return permanent.isCreature(game);
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent)

Example 55 with ZoneChangeEvent

use of mage.game.events.ZoneChangeEvent in project mage by magefree.

the class FlayingTendrilsReplacementEffect 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 controller.moveCards(permanent, Zone.EXILED, source, game);
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Aggregations

ZoneChangeEvent (mage.game.events.ZoneChangeEvent)94 Permanent (mage.game.permanent.Permanent)56 Player (mage.players.Player)27 FixedTarget (mage.target.targetpointer.FixedTarget)23 Card (mage.cards.Card)20 UUID (java.util.UUID)14 MageObject (mage.MageObject)11 MageObjectReference (mage.MageObjectReference)10 Effect (mage.abilities.effects.Effect)9 FilterCard (mage.filter.FilterCard)8 PermanentToken (mage.game.permanent.PermanentToken)8 FilterPermanent (mage.filter.FilterPermanent)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)7 Ability (mage.abilities.Ability)6 OneShotEffect (mage.abilities.effects.OneShotEffect)6 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)6 Spell (mage.game.stack.Spell)6 Zone (mage.constants.Zone)5 TargetPermanent (mage.target.TargetPermanent)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5