Search in sources :

Example 46 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class EntersBattlefieldEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (optional) {
        Player controller = game.getPlayer(source.getControllerId());
        MageObject object = game.getPermanentEntering(source.getSourceId());
        if (object == null) {
            object = game.getObject(source.getSourceId());
        }
        if (controller == null || object == null) {
            return false;
        }
        if (!controller.chooseUse(outcome, "Use effect of " + object.getLogName() + '?', source, game)) {
            return false;
        }
    }
    Spell entersBySpell = game.getStack().getSpell(event.getSourceId());
    if (entersBySpell == null) {
        StackObject stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
        if (stackObject instanceof Spell) {
            entersBySpell = (Spell) stackObject;
        }
    }
    for (Effect effect : baseEffects) {
        if (effect instanceof ContinuousEffect) {
            game.addEffect((ContinuousEffect) effect, source);
        } else {
            if (entersBySpell != null) {
                effect.setValue(SOURCE_CAST_SPELL_ABILITY, entersBySpell.getSpellAbility());
            }
            effect.setValue("appliedEffects", event.getAppliedEffects());
            effect.apply(game, source);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell)

Example 47 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class PlaneswalkerRedirectionEffect method getSourceControllerId.

private UUID getSourceControllerId(UUID sourceId, Game game) {
    StackObject source = game.getStack().getStackObject(sourceId);
    if (source != null) {
        return source.getControllerId();
    }
    Permanent permanent = game.getBattlefield().getPermanent(sourceId);
    if (permanent != null) {
        return permanent.getControllerId();
    }
    // for effects like Deflecting Palm (could be wrong if card was played multiple times by different players)
    return game.getContinuousEffects().getControllerOfSourceId(sourceId);
}
Also used : Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) StackObject(mage.game.stack.StackObject)

Example 48 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class GainAbilitySpellsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    for (Card card : game.getExile().getAllCards(game)) {
        if (card.isOwnedBy(source.getControllerId()) && filter.match(card, game)) {
            game.getState().addOtherAbility(card, ability);
        }
    }
    for (Card card : player.getLibrary().getCards(game)) {
        if (filter.match(card, game)) {
            game.getState().addOtherAbility(card, ability);
        }
    }
    for (Card card : player.getHand().getCards(game)) {
        if (filter.match(card, game)) {
            game.getState().addOtherAbility(card, ability);
        }
    }
    for (Card card : player.getGraveyard().getCards(game)) {
        if (filter.match(card, game)) {
            game.getState().addOtherAbility(card, ability);
        }
    }
    // workaround to gain cost reduction abilities to commanders before cast (make it playable)
    game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY).stream().filter(card -> filter.match(card, game)).forEach(card -> {
        game.getState().addOtherAbility(card, ability);
    });
    for (StackObject stackObject : game.getStack()) {
        if (!stackObject.isControlledBy(source.getControllerId())) {
            continue;
        }
        Card card = game.getCard(stackObject.getSourceId());
        if (card == null || !filter.match(stackObject, game)) {
            continue;
        }
        game.getState().addOtherAbility(card, ability);
    }
    return true;
}
Also used : Game(mage.game.Game) MageSingleton(mage.abilities.MageSingleton) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card) mage.constants(mage.constants) FilterObject(mage.filter.FilterObject) Player(mage.players.Player) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card)

Example 49 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class StormEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(getSourceId())) {
        StackObject spell = game.getStack().getStackObject(getSourceId());
        if (spell instanceof Spell) {
            for (Effect effect : this.getEffects()) {
                effect.setValue("StormSpell", spell);
                effect.setValue("StormSpellRef", new MageObjectReference(spell.getId(), game));
            }
            return true;
        }
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 50 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class GameState method getValue.

public String getValue(boolean useHidden, Game game) {
    StringBuilder sb = threadLocalBuilder.get();
    sb.append(turn.getValue(turnNum));
    sb.append(activePlayerId).append(priorityPlayerId).append(playerByOrderId);
    for (Player player : players.values()) {
        sb.append("player").append(player.isPassed()).append(player.getLife()).append("hand");
        if (useHidden) {
            sb.append(player.getHand().getValue(game));
        } else {
            sb.append(player.getHand().size());
        }
        sb.append("library").append(player.getLibrary().size());
        sb.append("graveyard");
        sb.append(player.getGraveyard().getValue(game));
    }
    sb.append("permanents");
    List<String> perms = new ArrayList<>();
    for (Permanent permanent : battlefield.getAllPermanents()) {
        perms.add(permanent.getValue(this));
    }
    Collections.sort(perms);
    sb.append(perms);
    sb.append("spells");
    for (StackObject spell : stack) {
        sb.append(spell.getControllerId()).append(spell.getName());
        sb.append(spell.getStackAbility().toString());
        for (UUID modeId : spell.getStackAbility().getModes().getSelectedModes()) {
            Mode mode = spell.getStackAbility().getModes().get(modeId);
            if (!mode.getTargets().isEmpty()) {
                sb.append("targets");
                for (Target target : mode.getTargets()) {
                    sb.append(target.getTargets());
                }
            }
        }
    }
    for (ExileZone zone : exile.getExileZones()) {
        sb.append("exile").append(zone.getName()).append(zone.getValue(game));
    }
    sb.append("combat");
    for (CombatGroup group : combat.getGroups()) {
        sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers());
    }
    return sb.toString();
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ThreadLocalStringBuilder(mage.util.ThreadLocalStringBuilder) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) CombatGroup(mage.game.combat.CombatGroup)

Aggregations

StackObject (mage.game.stack.StackObject)130 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)57 Spell (mage.game.stack.Spell)41 MageObject (mage.MageObject)37 UUID (java.util.UUID)36 Card (mage.cards.Card)29 Target (mage.target.Target)17 TargetPermanent (mage.target.TargetPermanent)15 FilterCard (mage.filter.FilterCard)14 Ability (mage.abilities.Ability)13 FilterPermanent (mage.filter.FilterPermanent)13 StackAbility (mage.game.stack.StackAbility)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)11 HashSet (java.util.HashSet)10 Effect (mage.abilities.effects.Effect)9 Game (mage.game.Game)9 MageObjectReference (mage.MageObjectReference)8 Cost (mage.abilities.costs.Cost)8