Search in sources :

Example 6 with Plane

use of mage.game.command.Plane in project mage by magefree.

the class DrawCardsActivePlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Plane cPlane = game.getState().getCurrentPlane();
    if (cPlane == null) {
        return false;
    }
    if (!cPlane.getPlaneType().equals(Planes.PLANE_ACADEMY_AT_TOLARIA_WEST)) {
        return false;
    }
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player != null) {
        player.drawCards(amount.calculate(game, source, this), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Plane(mage.game.command.Plane)

Example 7 with Plane

use of mage.game.command.Plane in project mage by magefree.

the class FeedingGroundsEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (abilityToModify instanceof SpellAbility) {
        Plane cPlane = game.getState().getCurrentPlane();
        if (cPlane == null) {
            return false;
        }
        if (!cPlane.getPlaneType().equals(Planes.PLANE_FEEDING_GROUNDS)) {
            return false;
        }
        Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
        if (spell != null) {
            return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
        } else {
            // used at least for flashback ability because Flashback ability doesn't use stack
            Card sourceCard = game.getCard(abilityToModify.getSourceId());
            return filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
        }
    }
    return false;
}
Also used : Plane(mage.game.command.Plane) SpellAbility(mage.abilities.SpellAbility) Spell(mage.game.stack.Spell) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 8 with Plane

use of mage.game.command.Plane in project mage by magefree.

the class RollPlanarDieEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && mageObject != null) {
        PlanarDieRollResult planarRoll = controller.rollPlanarDie(outcome, source, game);
        if (planarRoll == PlanarDieRollResult.CHAOS_ROLL && chaosEffects != null && chaosTargets != null) {
            for (int i = 0; i < chaosTargets.size(); i++) {
                Target target = chaosTargets.get(i);
                if (target != null) {
                    target.clearChosen();
                }
            }
            for (int i = 0; i < chaosEffects.size(); i++) {
                Effect effect = chaosEffects.get(i);
                Target target = null;
                if (chaosTargets.size() > i) {
                    target = chaosTargets.get(i);
                }
                boolean done = false;
                while (controller.canRespond() && effect != null && !done) {
                    if (target != null && !target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game)) {
                        controller.chooseTarget(Outcome.Benefit, target, source, game);
                        source.addTarget(target);
                    }
                    if (target != null) {
                        effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
                    }
                    try {
                        effect.apply(game, source);
                    } catch (UnsupportedOperationException exception) {
                    }
                    if (effect instanceof ContinuousEffect) {
                        game.addEffect((ContinuousEffect) effect, source);
                    }
                    done = true;
                }
            }
        } else if (planarRoll == PlanarDieRollResult.PLANAR_ROLL) {
            // Steps: 1) Remove the last plane and set its effects to discarded
            for (CommandObject cobject : game.getState().getCommand()) {
                if (cobject instanceof Plane) {
                    if (cobject.getAbilities() != null) {
                        for (Ability ability : cobject.getAbilities()) {
                            for (Effect effect : ability.getEffects()) {
                                if (effect instanceof ContinuousEffect) {
                                    ((ContinuousEffect) effect).discard();
                                }
                            }
                        }
                    }
                    game.getState().removeTriggersOfSourceId(cobject.getId());
                    game.getState().getCommand().remove(cobject);
                    break;
                }
            }
            // 2) Choose a new random plane we haven't been to, or reset if we've been everywhere
            List<String> planesVisited = game.getState().getSeenPlanes();
            if (game.getState().getSeenPlanes() != null) {
                if (planesVisited.size() == Planes.values().length) {
                    game.getState().resetSeenPlanes();
                }
            }
            boolean foundNextPlane = false;
            while (!foundNextPlane) {
                Plane plane = Plane.createRandomPlane();
                try {
                    if (plane != null && !planesVisited.contains(plane.getName())) {
                        foundNextPlane = true;
                        plane.setControllerId(controller.getId());
                        game.addPlane(plane, null, controller.getId());
                    }
                } catch (Exception ex) {
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Ability(mage.abilities.Ability) Player(mage.players.Player) PlanarDieRollResult(mage.constants.PlanarDieRollResult) Plane(mage.game.command.Plane) MageObject(mage.MageObject) CommandObject(mage.game.command.CommandObject) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Effect(mage.abilities.effects.Effect) List(java.util.List) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 9 with Plane

use of mage.game.command.Plane in project mage by magefree.

the class UndercityReachesTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Plane cPlane = game.getState().getCurrentPlane();
    if (cPlane == null) {
        return false;
    }
    if (!cPlane.getPlaneType().equals(Planes.PLANE_UNDERCITY_REACHES)) {
        return false;
    }
    if (((DamagedPlayerEvent) event).isCombatDamage()) {
        Permanent creature = game.getPermanent(event.getSourceId());
        if (creature != null) {
            Effect effect = new DrawCardTargetEffect(StaticValue.get(1), true, false);
            effect.setTargetPointer(new FixedTarget(creature.getControllerId()));
            effect.apply(game, this);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) Plane(mage.game.command.Plane) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) RollPlanarDieEffect(mage.abilities.effects.common.RollPlanarDieEffect) MaximumHandSizeControllerEffect(mage.abilities.effects.common.continuous.MaximumHandSizeControllerEffect) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) PlanarDieRollCostIncreasingEffect(mage.abilities.effects.common.cost.PlanarDieRollCostIncreasingEffect) Effect(mage.abilities.effects.Effect) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 10 with Plane

use of mage.game.command.Plane in project mage by magefree.

the class AbilityImpl method isInUseableZone.

/**
 * @param game
 * @param source
 * @return
 */
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
    if (!this.hasSourceObjectAbility(game, source, event)) {
        return false;
    }
    if (zone == Zone.COMMAND) {
        if (this.getSourceId() == null) {
            // commander effects
            return true;
        }
        MageObject object = game.getObject(this.getSourceId());
        // emblem/planes are always actual
        if (object instanceof Emblem || object instanceof Dungeon || object instanceof Plane) {
            return true;
        }
    }
    UUID parameterSourceId;
    // so will use the sourceId of the object itself that came as a parameter if it is not null
    if (this instanceof MageSingleton && source != null) {
        parameterSourceId = source.getId();
    } else {
        parameterSourceId = getSourceId();
    }
    // check against shortLKI for effects that move multiple object at the same time (e.g. destroy all)
    if (game.getShortLivingLKI(getSourceId(), getZone())) {
        return true;
    }
    // check against current state
    Zone test = game.getState().getZone(parameterSourceId);
    return zone.match(test);
}
Also used : Plane(mage.game.command.Plane) Emblem(mage.game.command.Emblem) Dungeon(mage.game.command.Dungeon) MageObject(mage.MageObject) UUID(java.util.UUID)

Aggregations

Plane (mage.game.command.Plane)17 Effect (mage.abilities.effects.Effect)6 Player (mage.players.Player)6 Card (mage.cards.Card)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 UUID (java.util.UUID)3 MageObject (mage.MageObject)3 Ability (mage.abilities.Ability)3 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 RollPlanarDieEffect (mage.abilities.effects.common.RollPlanarDieEffect)3 PlanarDieRollCostIncreasingEffect (mage.abilities.effects.common.cost.PlanarDieRollCostIncreasingEffect)3 FilterCard (mage.filter.FilterCard)3 Permanent (mage.game.permanent.Permanent)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 SpellAbility (mage.abilities.SpellAbility)2 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 InfoEffect (mage.abilities.effects.common.InfoEffect)2 CardInfo (mage.cards.repository.CardInfo)2 CommandObject (mage.game.command.CommandObject)2