Search in sources :

Example 11 with StackAbility

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

the class ComputerPlayer6 method resolve.

protected void resolve(SimulationNode2 node, int depth, Game game) {
    StackObject stackObject = game.getStack().getFirst();
    if (stackObject instanceof StackAbility) {
        // AI hint for search effects (calc all possible cards for best score)
        SearchEffect effect = getSearchEffect((StackAbility) stackObject);
        if (effect != null && stackObject.getControllerId().equals(playerId)) {
            Target target = effect.getTarget();
            if (!target.doneChosing()) {
                for (UUID targetId : target.possibleTargets(stackObject.getSourceId(), stackObject.getControllerId(), game)) {
                    Game sim = game.copy();
                    StackAbility newAbility = (StackAbility) stackObject.copy();
                    SearchEffect newEffect = getSearchEffect(newAbility);
                    newEffect.getTarget().addTarget(targetId, newAbility, sim);
                    sim.getStack().push(newAbility);
                    SimulationNode2 newNode = new SimulationNode2(node, sim, depth, stackObject.getControllerId());
                    node.children.add(newNode);
                    newNode.getTargets().add(targetId);
                    logger.trace("Sim search -- node#: " + SimulationNode2.getCount() + " for player: " + sim.getPlayer(stackObject.getControllerId()).getName());
                }
                return;
            }
        }
    }
    stackObject.resolve(game);
    if (stackObject instanceof StackAbility) {
        game.getStack().remove(stackObject, game);
    }
    game.applyEffects();
    game.getPlayers().resetPassed();
    game.getPlayerList().setCurrent(game.getActivePlayerId());
}
Also used : SearchEffect(mage.abilities.effects.SearchEffect) Target(mage.target.Target) Game(mage.game.Game) StackObject(mage.game.stack.StackObject) StackAbility(mage.game.stack.StackAbility)

Example 12 with StackAbility

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

the class LithoformEngineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (stackAbility != null) {
        Player controller = game.getPlayer(source.getControllerId());
        Permanent sourcePermanent = game.getPermanent(source.getSourceId());
        if (controller != null && sourcePermanent != null) {
            stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) StackAbility(mage.game.stack.StackAbility)

Example 13 with StackAbility

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

the class StrionicResonatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (stackAbility == null) {
        return false;
    }
    stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
    return true;
}
Also used : StackAbility(mage.game.stack.StackAbility)

Example 14 with StackAbility

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

the class AbilityImpl method getMessageText.

protected String getMessageText(Game game) {
    StringBuilder sb = threadLocalBuilder.get();
    MageObject object = game.getObject(this.sourceId);
    if (object != null) {
        if (object instanceof StackAbility) {
            Card card = game.getCard(((StackAbility) object).getSourceId());
            if (card != null) {
                sb.append(GameLog.getColoredObjectIdName(card));
            } else {
                sb.append(GameLog.getColoredObjectIdName(object));
            }
        } else if (object instanceof Spell) {
            Spell spell = (Spell) object;
            String castText = spell.getSpellCastText(game);
            sb.append((castText.startsWith("Cast ") ? castText.substring(5) : castText));
            if (spell.getFromZone() == Zone.GRAVEYARD) {
                sb.append(" from graveyard");
            }
            sb.append(getOptionalTextSuffix(game, spell));
        } else {
            sb.append(GameLog.getColoredObjectIdName(object));
        }
    } else {
        sb.append("unknown");
    }
    if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) {
        if (((Spell) object).getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
            Spell spell = (Spell) object;
            int i = 0;
            for (SpellAbility spellAbility : spell.getSpellAbilities()) {
                i++;
                String half;
                if (i == 1) {
                    half = " left";
                } else {
                    half = " right";
                }
                if (!spellAbility.getTargets().isEmpty()) {
                    sb.append(half).append(" half targeting ");
                    for (Target target : spellAbility.getTargets()) {
                        sb.append(target.getTargetedName(game));
                    }
                }
            }
        } else {
            Spell spell = (Spell) object;
            int i = 0;
            for (SpellAbility spellAbility : spell.getSpellAbilities()) {
                i++;
                if (i > 1) {
                    sb.append(" splicing ");
                    if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) {
                        sb.append(spellAbility.name.substring(5));
                    } else {
                        sb.append(spellAbility.name);
                    }
                }
                sb.append(getTargetDescriptionForLog(spellAbility.getTargets(), game));
            }
        }
    } else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) {
        Modes spellModes = ((Spell) object).getSpellAbility().getModes();
        for (UUID selectedModeId : spellModes.getSelectedModes()) {
            Mode selectedMode = spellModes.get(selectedModeId);
            int item = 0;
            for (Mode mode : spellModes.values()) {
                item++;
                if (mode.getId().equals(selectedMode.getId())) {
                    sb.append(" (mode ").append(item).append(')');
                    sb.append(getTargetDescriptionForLog(selectedMode.getTargets(), game));
                    break;
                }
            }
        }
    } else {
        sb.append(getTargetDescriptionForLog(getTargets(), game));
    }
    return sb.toString();
}
Also used : Target(mage.target.Target) ThreadLocalStringBuilder(mage.util.ThreadLocalStringBuilder) MageObject(mage.MageObject) UUID(java.util.UUID) StackAbility(mage.game.stack.StackAbility) Spell(mage.game.stack.Spell) Hint(mage.abilities.hint.Hint) SplitCard(mage.cards.SplitCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 15 with StackAbility

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

the class IllusionistsBracersTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent equipment = game.getPermanent(this.getSourceId());
    if (equipment == null || !equipment.isAttachedTo(event.getSourceId())) {
        return false;
    }
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
    if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
        return false;
    }
    this.getEffects().setValue("stackAbility", stackAbility);
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StackAbility(mage.game.stack.StackAbility)

Aggregations

StackAbility (mage.game.stack.StackAbility)42 Permanent (mage.game.permanent.Permanent)15 StackObject (mage.game.stack.StackObject)12 Player (mage.players.Player)11 Target (mage.target.Target)9 MageObject (mage.MageObject)8 Ability (mage.abilities.Ability)7 Spell (mage.game.stack.Spell)7 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)6 GameEvent (mage.game.events.GameEvent)6 Game (mage.game.Game)5 UUID (java.util.UUID)4 MageObjectReference (mage.MageObjectReference)4 PassAbility (mage.abilities.common.PassAbility)4 Mode (mage.abilities.Mode)3 Card (mage.cards.Card)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 LoyaltyAbility (mage.abilities.LoyaltyAbility)2 SpellAbility (mage.abilities.SpellAbility)2