Search in sources :

Example 26 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class CemeteryProtectorTriggeredAbility method checkInterveningIfClause.

@Override
public boolean checkInterveningIfClause(Game game) {
    Effect effect = getEffects().get(0);
    UUID targetId = (UUID) effect.getValue("targetId");
    GameEvent.EventType eventType = (GameEvent.EventType) effect.getValue("eventType");
    UUID exileId = (UUID) effect.getValue("exileId");
    if (targetId != null && eventType != null && exileId != null) {
        if (eventType == GameEvent.EventType.LAND_PLAYED) {
            Permanent permanent = game.getPermanent(targetId);
            return permanent != null && checkCardTypes(permanent.getCardType(game), exileId, game);
        } else if (eventType == GameEvent.EventType.SPELL_CAST) {
            Spell spell = game.getSpellOrLKIStack(targetId);
            return spell != null && checkCardTypes(spell.getCardType(game), exileId, game);
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 27 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class CemeteryProtectorTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getPlayerId().equals(controllerId)) {
        Effect effect = getEffects().get(0);
        effect.setValue("targetId", event.getTargetId());
        effect.setValue("eventType", event.getType());
        // sourceObjectZoneChangeCounter is not updated until after checkTrigger is called.  Get ZCC from GameState instead.
        effect.setValue("exileId", CardUtil.getExileZoneId(game, sourceId, game.getState().getZoneChangeCounter(sourceId)));
        return true;
    }
    return false;
}
Also used : OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect)

Example 28 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class CommandoRaidEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
    Player opponent = game.getPlayer(event.getPlayerId());
    if (!damageEvent.isCombatDamage() || !event.getSourceId().equals(this.getSourceId()) || opponent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
    filter.add(new ControllerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCreaturePermanent(filter));
    for (Effect effect : this.getAllEffects()) {
        effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
        effect.setValue("damage", event.getAmount());
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 29 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class FalseOrdersUnblockEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
    if (controller == null || permanent == null) {
        return false;
    }
    // Remove target creature from combat
    Effect effect = new RemoveFromCombatTargetEffect();
    effect.apply(game, source);
    // Make blocked creatures unblocked
    BlockedByOnlyOneCreatureThisCombatWatcher watcher = game.getState().getWatcher(BlockedByOnlyOneCreatureThisCombatWatcher.class);
    if (watcher != null) {
        Set<CombatGroup> combatGroups = watcher.getBlockedOnlyByCreature(permanent.getId());
        if (combatGroups != null) {
            for (CombatGroup combatGroup : combatGroups) {
                if (combatGroup != null) {
                    combatGroup.setBlocked(false, game);
                }
            }
        }
    }
    if (!permanent.isCreature(game) || !controller.chooseUse(Outcome.Benefit, "Have " + permanent.getLogName() + " block an attacking creature?", source, game)) {
        return false;
    }
    // Choose new creature to block
    // according to the following mail response from MTG Rules Management about False Orders:
    // "if Player A attacks Players B and C, Player B's creatures cannot block creatures attacking Player C"
    // therefore we need to single out creatures attacking the target blocker's controller (disappointing, I know)
    List<Permanent> list = new ArrayList<>();
    for (CombatGroup combatGroup : game.getCombat().getGroups()) {
        if (combatGroup.getDefendingPlayerId().equals(permanent.getControllerId())) {
            for (UUID attackingCreatureId : combatGroup.getAttackers()) {
                Permanent targetsControllerAttacker = game.getPermanent(attackingCreatureId);
                list.add(targetsControllerAttacker);
            }
        }
    }
    Player targetsController = game.getPlayer(permanent.getControllerId());
    if (targetsController == null) {
        return false;
    }
    FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
    filter.add(new PermanentInListPredicate(list));
    TargetAttackingCreature target = new TargetAttackingCreature(1, 1, filter, true);
    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
        while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
            controller.chooseTarget(outcome, target, source, game);
        }
    } else {
        return true;
    }
    Permanent chosenPermanent = game.getPermanent(target.getFirstTarget());
    if (chosenPermanent == null || !chosenPermanent.isCreature(game)) {
        return false;
    }
    CombatGroup chosenGroup = game.getCombat().findGroup(chosenPermanent.getId());
    if (chosenGroup != null) {
        // Relevant ruling for Balduvian Warlord:
        // 7/15/2006 	If an attacking creature has an ability that triggers “When this creature becomes blocked,”
        // it triggers when a creature blocks it due to the Warlord's ability only if it was unblocked at that point.
        boolean notYetBlocked = chosenGroup.getBlockers().isEmpty();
        chosenGroup.addBlockerToGroup(permanent.getId(), controller.getId(), game);
        // 702.21h
        game.getCombat().addBlockingGroup(permanent.getId(), chosenPermanent.getId(), controller.getId(), game);
        if (notYetBlocked) {
            game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, chosenPermanent.getId(), source, null));
            Set<MageObjectReference> morSet = new HashSet<>();
            morSet.add(new MageObjectReference(chosenPermanent, game));
            for (UUID bandedId : chosenPermanent.getBandedCards()) {
                CombatGroup bandedGroup = game.getCombat().findGroup(bandedId);
                if (bandedGroup != null && chosenGroup.getBlockers().size() == 1) {
                    morSet.add(new MageObjectReference(bandedId, game));
                    game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, bandedId, source, null));
                }
            }
            String key = UUID.randomUUID().toString();
            game.getState().setValue("becameBlocked_" + key, morSet);
            game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BATCH_BLOCK_NONCOMBAT, source.getSourceId(), source, source.getControllerId(), key, 0));
        }
        game.fireEvent(new BlockerDeclaredEvent(chosenPermanent.getId(), permanent.getId(), permanent.getControllerId()));
    }
    // a new blockingGroup is formed, so it's necessary to find it again
    CombatGroup blockGroup = findBlockingGroup(permanent, game);
    if (blockGroup != null) {
        blockGroup.pickAttackerOrder(permanent.getControllerId(), game);
    }
    return true;
}
Also used : Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterAttackingCreature(mage.filter.common.FilterAttackingCreature) RemoveFromCombatTargetEffect(mage.abilities.effects.common.RemoveFromCombatTargetEffect) TargetAttackingCreature(mage.target.common.TargetAttackingCreature) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) RemoveFromCombatTargetEffect(mage.abilities.effects.common.RemoveFromCombatTargetEffect) BlockedByOnlyOneCreatureThisCombatWatcher(mage.watchers.common.BlockedByOnlyOneCreatureThisCombatWatcher) BlockerDeclaredEvent(mage.game.events.BlockerDeclaredEvent) CombatGroup(mage.game.combat.CombatGroup) MageObjectReference(mage.MageObjectReference)

Example 30 with Effect

use of mage.abilities.effects.Effect in project mage by magefree.

the class FatalLoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player chosenOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller != null && chosenOpponent != null) {
        if (chosenOpponent.chooseUse(Outcome.Neutral, "If you choose Yes, the controller draws three cards. If no, the controller gets to destroy up to two target creatures that you control and you get to draw up to 3 cards. Those creatures can't be regenerated.", source, game)) {
            controller.drawCards(3, source, game);
        } else {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("chosen opponent's creature");
            filter.add(new ControllerIdPredicate(chosenOpponent.getId()));
            TargetCreaturePermanent target = new TargetCreaturePermanent(0, 2, filter, false);
            if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.DestroyPermanent, target, source.getSourceId(), game)) {
                for (UUID targetId : target.getTargets()) {
                    Effect destroyCreature = new DestroyTargetEffect(true);
                    destroyCreature.setTargetPointer(new FixedTarget(targetId, game));
                    destroyCreature.apply(game, source);
                }
                Effect opponentDrawsCards = new DrawCardTargetEffect(StaticValue.get(3), false, true);
                opponentDrawsCards.setTargetPointer(new FixedTarget(chosenOpponent.getId()));
                opponentDrawsCards.apply(game, source);
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID)

Aggregations

Effect (mage.abilities.effects.Effect)328 OneShotEffect (mage.abilities.effects.OneShotEffect)254 FixedTarget (mage.target.targetpointer.FixedTarget)224 Permanent (mage.game.permanent.Permanent)180 Player (mage.players.Player)167 UUID (java.util.UUID)75 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)60 Card (mage.cards.Card)57 MageObject (mage.MageObject)41 ContinuousEffect (mage.abilities.effects.ContinuousEffect)40 TargetPermanent (mage.target.TargetPermanent)39 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)38 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 FilterPermanent (mage.filter.FilterPermanent)29 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)28 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)27 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)25 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)24 AttachEffect (mage.abilities.effects.common.AttachEffect)23 Target (mage.target.Target)22