Search in sources :

Example 76 with ZoneChangeEvent

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

the class ScrapTrawlerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
        Permanent permanent = ((ZoneChangeEvent) event).getTarget();
        if (permanent != null && permanent.isControlledBy(this.getControllerId()) && permanent.isArtifact(game)) {
            FilterCard filter = new FilterArtifactCard("artifact card in your graveyard with mana value less than " + permanent.getManaCost().manaValue());
            filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaCost().manaValue()));
            TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
            getTargets().clear();
            addTarget(target);
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) FilterArtifactCard(mage.filter.common.FilterArtifactCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard)

Example 77 with ZoneChangeEvent

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

the class TianaShipsCaretakerEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getTarget() == null) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(zEvent.getTarget().getId());
    if (permanent != null && zEvent.isDiesEvent() && (permanent.isArtifact(game) && permanent.hasSubtype(SubType.EQUIPMENT, game) || permanent.isEnchantment(game) && permanent.hasSubtype(SubType.AURA, game)) && permanent.isControlledBy(this.controllerId)) {
        this.getEffects().setTargetPointer(new FixedTarget(zEvent.getTargetId()));
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent)

Example 78 with ZoneChangeEvent

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

the class VileRedeemerNonTokenCreaturesDiedWatcher 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) && !(zEvent.getTarget() instanceof PermanentToken)) {
            int count = getAmountOfNontokenCreatureDiedThisTurn(zEvent.getTargetId());
            amountOfCreaturesThatDied.put(zEvent.getTarget().getControllerId(), ++count);
        }
    }
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) PermanentToken(mage.game.permanent.PermanentToken)

Example 79 with ZoneChangeEvent

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

the class WarBargeDelayedTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getTargetId().equals(this.getSourceId())) {
        ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
        if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
            Effect effect = this.getEffects().get(0);
            effect.setTargetPointer(new FixedTarget(this.getFirstTarget()));
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) Effect(mage.abilities.effects.Effect) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect)

Example 80 with ZoneChangeEvent

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

the class AttackingCreaturePutIntoGraveyardTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    switch(event.getType()) {
        case ATTACKER_DECLARED:
            Permanent permanent = game.getPermanent(event.getSourceId());
            if (permanent != null && !filterPermanent.match(permanent, game)) {
                return false;
            }
            List<UUID> attackersList = new ArrayList<>();
            List<UUID> attackersListCopy = (List<UUID>) game.getState().getValue(this.getSourceId() + "Attackers");
            if (attackersListCopy == null) {
                attackersListCopy = attackersList;
            }
            // add the filtered creature to the list
            attackersListCopy.add(event.getSourceId());
            game.getState().setValue(this.getSourceId() + "Attackers", attackersListCopy);
            return false;
        case END_COMBAT_STEP_POST:
            game.getState().setValue(this.getSourceId() + "Attackers", null);
            return false;
        case ZONE_CHANGE:
            ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
            if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) {
                if (onlyToControllerGraveyard && !this.isControlledBy(game.getOwnerId(zEvent.getTargetId()))) {
                    return false;
                }
                if (itDies && !zEvent.isDiesEvent()) {
                    return false;
                }
                List<UUID> attackers = (List<UUID>) game.getState().getValue(this.getSourceId() + "Attackers");
                return attackers != null && attackers.contains(zEvent.getTargetId());
            }
        case REMOVED_FROM_COMBAT:
            // a card removed from combat is no longer an attacker or blocker so remove it from the list
            List<UUID> attackersListRFC = (List<UUID>) game.getState().getValue(this.getSourceId() + "Attackers");
            if (attackersListRFC != null && attackersListRFC.contains(event.getTargetId())) {
                attackersListRFC.remove(event.getTargetId());
                game.getState().setValue(this.getSourceId() + "Attackers", attackersListRFC);
            }
        default:
            return false;
    }
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

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