Search in sources :

Example 56 with SimpleStaticAbility

use of mage.abilities.common.SimpleStaticAbility in project mage by magefree.

the class TestPlayer method priority.

@Override
public boolean priority(Game game) {
    // later remove actions (ai commands related)
    if (actionsToRemoveLater.size() > 0) {
        List<PlayerAction> removed = new ArrayList<>();
        actionsToRemoveLater.forEach((action, step) -> {
            if (game.getStep().getType() != step) {
                action.onActionRemovedLater(game, this);
                actions.remove(action);
                removed.add(action);
            }
        });
        removed.forEach(actionsToRemoveLater::remove);
    }
    // fake test ability for triggers and events
    Ability source = new SimpleStaticAbility(Zone.OUTSIDE, new InfoEffect("adding testing cards"));
    source.setControllerId(this.getId());
    int numberOfActions = actions.size();
    List<PlayerAction> tempActions = new ArrayList<>();
    tempActions.addAll(actions);
    for (PlayerAction action : tempActions) {
        if (action.getTurnNum() == game.getTurnNum() && action.getStep() == game.getStep().getType()) {
            if (action.getAction().startsWith(ACTIVATE_ABILITY)) {
                String command = action.getAction();
                command = command.substring(command.indexOf(ACTIVATE_ABILITY) + ACTIVATE_ABILITY.length());
                groupsForTargetHandling = null;
                String[] groups = command.split("\\$");
                if (groups.length > 2 && !checkExecuteCondition(groups, game)) {
                    break;
                }
                // must process all duplicated abilities (aliases need objects to search)
                for (ActivatedAbility ability : computerPlayer.getPlayable(game, true, Zone.ALL, false)) {
                    // add wrong action log?
                    if (hasAbilityTargetNameOrAlias(game, ability, groups[0])) {
                        int bookmark = game.bookmarkState();
                        ActivatedAbility newAbility = ability.copy();
                        if (groups.length > 1 && !groups[1].equals("target=" + NO_TARGET)) {
                            groupsForTargetHandling = groups;
                        }
                        if (computerPlayer.activateAbility(newAbility, game)) {
                            actions.remove(action);
                            groupsForTargetHandling = null;
                            // Reset enless loop check because of no action
                            foundNoAction = 0;
                            return true;
                        } else {
                            computerPlayer.restoreState(bookmark, ability.getRule(), game);
                            // skip failed command
                            if (!choices.isEmpty() && choices.get(0).equals(SKIP_FAILED_COMMAND)) {
                                actions.remove(action);
                                choices.remove(0);
                                return true;
                            }
                        }
                        groupsForTargetHandling = null;
                    }
                }
            // TODO: fix wrong commands (on non existing card), it's HUGE (350+ failed tests with wrong commands)
            // Assert.fail("Can't find ability to activate command: " + command);
            } else if (action.getAction().startsWith(ACTIVATE_MANA)) {
                String command = action.getAction();
                command = command.substring(command.indexOf(ACTIVATE_MANA) + ACTIVATE_MANA.length());
                String[] groups = command.split("\\$");
                List<MageObject> manaObjects = computerPlayer.getAvailableManaProducers(game);
                for (MageObject mageObject : manaObjects) {
                    if (mageObject instanceof Permanent) {
                        for (Ability manaAbility : ((Permanent) mageObject).getAbilities(game).getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, getId(), game)) {
                            if (hasAbilityTargetNameOrAlias(game, manaAbility, groups[0])) {
                                Ability newManaAbility = manaAbility.copy();
                                computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
                                actions.remove(action);
                                return true;
                            }
                        }
                    } else if (mageObject instanceof Card) {
                        for (Ability manaAbility : ((Card) mageObject).getAbilities(game).getAvailableActivatedManaAbilities(game.getState().getZone(mageObject.getId()), getId(), game)) {
                            if (hasAbilityTargetNameOrAlias(game, manaAbility, groups[0])) {
                                Ability newManaAbility = manaAbility.copy();
                                computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
                                actions.remove(action);
                                return true;
                            }
                        }
                    } else {
                        for (Ability manaAbility : mageObject.getAbilities().getAvailableActivatedManaAbilities(game.getState().getZone(mageObject.getId()), getId(), game)) {
                            if (hasAbilityTargetNameOrAlias(game, manaAbility, groups[0])) {
                                Ability newManaAbility = manaAbility.copy();
                                computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
                                actions.remove(action);
                                return true;
                            }
                        }
                    }
                }
                List<Permanent> manaPermsWithCost = computerPlayer.getAvailableManaProducersWithCost(game);
                for (Permanent perm : manaPermsWithCost) {
                    for (ActivatedManaAbilityImpl manaAbility : perm.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, getId(), game)) {
                        if (hasAbilityTargetNameOrAlias(game, manaAbility, groups[0]) && manaAbility.canActivate(computerPlayer.getId(), game).canActivate()) {
                            Ability newManaAbility = manaAbility.copy();
                            computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
                            actions.remove(action);
                            return true;
                        }
                    }
                }
            } else if (action.getAction().startsWith("addCounters:")) {
                String command = action.getAction();
                command = command.substring(command.indexOf("addCounters:") + 12);
                String[] groups = command.split("\\$");
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
                    if (hasObjectTargetNameOrAlias(permanent, groups[0])) {
                        CounterType counterType = CounterType.findByName(groups[1]);
                        Assert.assertNotNull("Invalid counter type " + groups[1], counterType);
                        Counter counter = counterType.createInstance(Integer.parseInt(groups[2]));
                        permanent.addCounters(counter, source.getControllerId(), source, game);
                        actions.remove(action);
                        return true;
                    }
                }
            } else if (action.getAction().startsWith("waitStackResolved")) {
                boolean skipOneStackObjectOnly = action.getAction().equals("waitStackResolved:1");
                if (game.getStack().isEmpty()) {
                    // all done, can use next command
                    actions.remove(action);
                    continue;
                } else {
                    // need to wait (don't remove command, except one skip only)
                    tryToPlayPriority(game);
                    if (skipOneStackObjectOnly) {
                        actions.remove(action);
                    }
                    return true;
                }
            } else if (action.getAction().startsWith("playerAction:")) {
                String command = action.getAction();
                command = command.substring(command.indexOf("playerAction:") + 13);
                groupsForTargetHandling = null;
                String[] groups = command.split("\\$");
                if (groups.length > 0) {
                    if (groups[0].equals("Rollback")) {
                        if (groups.length > 2 && groups[1].startsWith("turns=") && groups[2].startsWith("rollbackBlock=")) {
                            int turns = Integer.parseInt(groups[1].substring(6));
                            int rollbackBlockNumber = Integer.parseInt(groups[2].substring(14));
                            game.rollbackTurns(turns);
                            actions.remove(action);
                            addActionsAfterRollback(game, rollbackBlockNumber);
                            return true;
                        } else {
                            Assert.fail("Rollback command misses parameter: " + command);
                        }
                    }
                    if (groups[0].equals("Concede")) {
                        game.concede(getId());
                        ((GameImpl) game).checkConcede();
                        actions.remove(action);
                        return true;
                    }
                }
            } else if (action.getAction().startsWith(AI_PREFIX)) {
                String command = action.getAction();
                command = command.substring(command.indexOf(AI_PREFIX) + AI_PREFIX.length());
                // play priority
                if (command.equals(AI_COMMAND_PLAY_PRIORITY)) {
                    // disable on action's remove
                    AIRealGameSimulation = true;
                    computerPlayer.priority(game);
                    actions.remove(action);
                    return true;
                }
                // play step
                if (command.equals(AI_COMMAND_PLAY_STEP)) {
                    // disable on action's remove
                    AIRealGameSimulation = true;
                    actionsToRemoveLater.put(action, game.getStep().getType());
                    computerPlayer.priority(game);
                    return true;
                }
                Assert.fail("Unknown ai command: " + command);
            } else if (action.getAction().startsWith(RUN_PREFIX)) {
                String command = action.getAction();
                command = command.substring(command.indexOf(RUN_PREFIX) + RUN_PREFIX.length());
                // custom code execute
                if (command.equals(RUN_COMMAND_CODE)) {
                    action.getCodePayload().run(action.getActionName(), computerPlayer, game);
                    actions.remove(action);
                    return true;
                }
                Assert.fail("Unknown run command: " + command);
            } else if (action.getAction().startsWith(CHECK_PREFIX)) {
                String command = action.getAction();
                command = command.substring(command.indexOf(CHECK_PREFIX) + CHECK_PREFIX.length());
                String[] params = command.split(CHECK_PARAM_DELIMETER);
                boolean wasProccessed = false;
                if (params.length > 0) {
                    // check PT: card name, P, T
                    if (params[0].equals(CHECK_COMMAND_PT) && params.length == 4) {
                        assertPT(action, game, computerPlayer, params[1], Integer.parseInt(params[2]), Integer.parseInt(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check damage: card name, damage
                    if (params[0].equals(CHECK_COMMAND_DAMAGE) && params.length == 3) {
                        assertDamage(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check life: life
                    if (params[0].equals(CHECK_COMMAND_LIFE) && params.length == 2) {
                        assertLife(action, game, computerPlayer, Integer.parseInt(params[1]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check player in game: target player, must be in game
                    if (params[0].equals(CHECK_COMMAND_PLAYER_IN_GAME) && params.length == 3) {
                        assertPlayerInGame(action, game, game.getPlayer(UUID.fromString(params[1])), Boolean.parseBoolean(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check ability: card name, ability class, must have
                    if (params[0].equals(CHECK_COMMAND_ABILITY) && params.length == 4) {
                        assertAbility(action, game, computerPlayer, params[1], params[2], Boolean.parseBoolean(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check playable ability: ability text, must have
                    if (params[0].equals(CHECK_COMMAND_PLAYABLE_ABILITY) && params.length == 3) {
                        assertPlayableAbility(action, game, computerPlayer, params[1], Boolean.parseBoolean(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check battlefield count: target player, card name, count
                    if (params[0].equals(CHECK_COMMAND_PERMANENT_COUNT) && params.length == 4) {
                        assertPermanentCount(action, game, game.getPlayer(UUID.fromString(params[1])), params[2], Integer.parseInt(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check permanent tapped count: target player, card name, tapped status, count
                    if (params[0].equals(CHECK_COMMAND_PERMANENT_TAPPED) && params.length == 5) {
                        assertPermanentTapped(action, game, game.getPlayer(UUID.fromString(params[1])), params[2], Boolean.parseBoolean(params[3]), Integer.parseInt(params[4]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check permanent counters: card name, counter type, count
                    if (params[0].equals(CHECK_COMMAND_PERMANENT_COUNTERS) && params.length == 4) {
                        assertPermanentCounters(action, game, computerPlayer, params[1], CounterType.findByName(params[2]), Integer.parseInt(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check card counters: card name, counter type, count
                    if (params[0].equals(CHECK_COMMAND_CARD_COUNTERS) && params.length == 4) {
                        assertCardCounters(action, game, computerPlayer, params[1], CounterType.findByName(params[2]), Integer.parseInt(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check exile count: card name, count
                    if (params[0].equals(CHECK_COMMAND_EXILE_COUNT) && params.length == 3) {
                        assertExileCount(action, game, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check graveyard count: card name, count
                    if (params[0].equals(CHECK_COMMAND_GRAVEYARD_COUNT) && params.length == 3) {
                        assertGraveyardCount(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check library count: card name, count
                    if (params[0].equals(CHECK_COMMAND_LIBRARY_COUNT) && params.length == 3) {
                        assertLibraryCount(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check hand count: count
                    if (params[0].equals(CHECK_COMMAND_HAND_COUNT) && params.length == 2) {
                        assertHandCount(action, game, computerPlayer, Integer.parseInt(params[1]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check hand card count: card name, count
                    if (params[0].equals(CHECK_COMMAND_HAND_CARD_COUNT) && params.length == 3) {
                        assertHandCardCount(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check command card count: card name, count
                    if (params[0].equals(CHECK_COMMAND_COMMAND_CARD_COUNT) && params.length == 3) {
                        assertCommandCardCount(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check color: card name, colors, must have
                    if (params[0].equals(CHECK_COMMAND_COLOR) && params.length == 4) {
                        assertColor(action, game, computerPlayer, params[1], params[2], Boolean.parseBoolean(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check type: card name, type, must have
                    if (params[0].equals(CHECK_COMMAND_TYPE) && params.length == 4) {
                        assertType(action, game, computerPlayer, params[1], CardType.fromString(params[2]), Boolean.parseBoolean(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check subtype: card name, subtype, must have
                    if (params[0].equals(CHECK_COMMAND_SUBTYPE) && params.length == 4) {
                        assertSubType(action, game, computerPlayer, params[1], SubType.fromString(params[2]), Boolean.parseBoolean(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check mana pool: colors, amount
                    if (params[0].equals(CHECK_COMMAND_MANA_POOL) && params.length == 3) {
                        assertManaPool(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check alias at zone: alias name, zone, must have (only for TestPlayer)
                    if (params[0].equals(CHECK_COMMAND_ALIAS_ZONE) && params.length == 4) {
                        assertAliasZone(action, game, this, params[1], Zone.valueOf(params[2]), Boolean.parseBoolean(params[3]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check stack size: need size
                    if (params[0].equals(CHECK_COMMAND_STACK_SIZE) && params.length == 2) {
                        assertStackSize(action, game, Integer.parseInt(params[1]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // check stack object: stack ability name, amount
                    if (params[0].equals(CHECK_COMMAND_STACK_OBJECT) && params.length == 3) {
                        assertStackObject(action, game, params[1], Integer.parseInt(params[2]));
                        actions.remove(action);
                        wasProccessed = true;
                    }
                }
                if (wasProccessed) {
                    return true;
                } else {
                    Assert.fail("Unknown check command or params: " + command);
                }
            } else if (action.getAction().startsWith(SHOW_PREFIX)) {
                String command = action.getAction();
                command = command.substring(command.indexOf(SHOW_PREFIX) + SHOW_PREFIX.length());
                String[] params = command.split(CHECK_PARAM_DELIMETER);
                boolean wasProccessed = false;
                if (params.length > 0) {
                    // show library
                    if (params[0].equals(SHOW_COMMAND_LIBRARY) && params.length == 1) {
                        printStart(action.getActionName());
                        // do not sort
                        printCards(computerPlayer.getLibrary().getCards(game), false);
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show hand
                    if (params[0].equals(SHOW_COMMAND_HAND) && params.length == 1) {
                        printStart(action.getActionName());
                        printCards(computerPlayer.getHand().getCards(game));
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show command
                    if (params[0].equals(SHOW_COMMAND_COMMAND) && params.length == 1) {
                        printStart(action.getActionName());
                        CardsImpl cards = new CardsImpl(game.getCommandersIds(computerPlayer, CommanderCardType.ANY, false));
                        printCards(cards.getCards(game));
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show battlefield
                    if (params[0].equals(SHOW_COMMAND_BATTLEFIELD) && params.length == 1) {
                        printStart(action.getActionName());
                        printPermanents(game, game.getBattlefield().getAllActivePermanents(computerPlayer.getId()));
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show graveyard
                    if (params[0].equals(SHOW_COMMAND_GRAVEYEARD) && params.length == 1) {
                        printStart(action.getActionName());
                        printCards(computerPlayer.getGraveyard().getCards(game));
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show exile
                    if (params[0].equals(SHOW_COMMAND_EXILE) && params.length == 1) {
                        printStart(action.getActionName());
                        printCards(game.getExile().getAllCards(game).stream().filter(card -> card.isOwnedBy(computerPlayer.getId())).collect(Collectors.toList()), true);
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show available abilities
                    if (params[0].equals(SHOW_COMMAND_AVAILABLE_ABILITIES) && params.length == 1) {
                        printStart(action.getActionName());
                        printAbilities(game, computerPlayer.getPlayable(game, true));
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show available mana
                    if (params[0].equals(SHOW_COMMAND_AVAILABLE_MANA) && params.length == 1) {
                        printStart(action.getActionName());
                        printMana(game, computerPlayer.getManaAvailable(game));
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show aliases
                    if (params[0].equals(SHOW_COMMAND_ALIASES) && params.length == 1) {
                        printStart(action.getActionName());
                        printAliases(game, this);
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                    // show stack
                    if (params[0].equals(SHOW_COMMAND_STACK) && params.length == 1) {
                        printStart(action.getActionName());
                        printStack(game);
                        printEnd();
                        actions.remove(action);
                        wasProccessed = true;
                    }
                }
                if (wasProccessed) {
                    return true;
                } else {
                    Assert.fail("Unknown show command or params: " + command);
                }
            }
            // you don't need to use stack command all the time, so some cast commands can be skiped to next check
            if (game.getStack().isEmpty()) {
                this.chooseStrictModeFailed("cast/activate", game, "Can't find available command - " + action.getAction() + " (use checkPlayableAbility for \"non available\" checks)", true);
            }
        }
    // turn/step
    }
    tryToPlayPriority(game);
    // check to prevent endless loops
    if (numberOfActions == actions.size()) {
        foundNoAction++;
        if (foundNoAction > maxCallsWithoutAction) {
            throw new AssertionError("Too much priority calls to " + getName() + " without taking any action than allowed (" + maxCallsWithoutAction + ") on turn " + game.getTurnNum());
        }
    } else {
        foundNoAction = 0;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) InfoEffect(mage.abilities.effects.common.InfoEffect) Card(mage.cards.Card) GameImpl(mage.game.GameImpl) Counter(mage.counters.Counter) CardsImpl(mage.cards.CardsImpl)

Example 57 with SimpleStaticAbility

use of mage.abilities.common.SimpleStaticAbility in project mage by magefree.

the class LevelerCardBuilder method build.

/**
 * Main method constructing ability.
 *
 * @return
 */
public List<Ability> build() {
    List<Ability> constructed = new ArrayList<>();
    Condition condition = new SourceHasCounterCondition(CounterType.LEVEL, level1, level2);
    for (Ability ability : abilities) {
        ContinuousEffect effect = new GainAbilitySourceEffect(ability);
        ConditionalContinuousEffect abEffect = new ConditionalContinuousEffect(effect, condition, "");
        Ability staticAbility = new SimpleStaticAbility(Zone.BATTLEFIELD, abEffect);
        staticAbility.setRuleVisible(false);
        constructed.add(staticAbility);
    }
    ContinuousEffect effect = new SetPowerToughnessSourceEffect(power, toughness, Duration.WhileOnBattlefield, SubLayer.SetPT_7b);
    ConditionalContinuousEffect ptEffect = new ConditionalContinuousEffect(effect, condition, rule);
    constructed.add(new SimpleStaticAbility(Zone.BATTLEFIELD, ptEffect));
    return constructed;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) SourceHasCounterCondition(mage.abilities.condition.common.SourceHasCounterCondition) Condition(mage.abilities.condition.Condition) SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ArrayList(java.util.ArrayList) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SourceHasCounterCondition(mage.abilities.condition.common.SourceHasCounterCondition) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect)

Example 58 with SimpleStaticAbility

use of mage.abilities.common.SimpleStaticAbility in project mage by magefree.

the class MomirGame method init.

@Override
protected void init(UUID choosingPlayerId) {
    Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Vanguard effects"));
    for (UUID playerId : state.getPlayerList(startingPlayerId)) {
        Player player = getPlayer(playerId);
        if (player != null) {
            CardInfo cardInfo = CardRepository.instance.findCard("Momir Vig, Simic Visionary");
            addEmblem(new MomirEmblem(), cardInfo.getCard(), playerId);
        }
    }
    getState().addAbility(ability, null);
    super.init(choosingPlayerId);
    state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) CardInfo(mage.cards.repository.CardInfo) TurnMod(mage.game.turn.TurnMod) UUID(java.util.UUID) MomirEmblem(mage.game.command.emblems.MomirEmblem) InfoEffect(mage.abilities.effects.common.InfoEffect)

Example 59 with SimpleStaticAbility

use of mage.abilities.common.SimpleStaticAbility in project mage by magefree.

the class OathbreakerFreeForAll method initCommanderEffects.

@Override
public void initCommanderEffects(Card commander, Player player, Ability commanderAbility) {
    // all commander effects must be independent from sourceId or controllerId (it's limitation of current commander effects)
    boolean isSignatureSpell = this.playerSignatureSpells.getOrDefault(player.getId(), new HashSet<>()).contains(commander.getId());
    // basic commmander restrict (oathbreaker may ask to move, signature force to move)
    commanderAbility.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary, isSignatureSpell, getCommanderTypeName(commander)));
    commanderAbility.addEffect(new CommanderCostModification(commander));
    // signature spell restrict (spell can be casted on player's commander on battlefield)
    if (isSignatureSpell) {
        OathbreakerOnBattlefieldCondition condition = new OathbreakerOnBattlefieldCondition(this, player.getId(), commander.getId(), this.playerOathbreakers.getOrDefault(player.getId(), new HashSet<>()));
        commanderAbility.addEffect(new SignatureSpellCastOnlyWithOathbreakerEffect(condition, commander.getId()));
        // hint must be added to card, not global ability
        Ability ability = new SimpleStaticAbility(new InfoEffect("Signature spell hint"));
        ability.addHint(new ConditionHint(condition, "Oathbreaker on battlefield (" + condition.getCompatibleNames() + ")"));
        ability.setRuleVisible(false);
        commander.addAbility(ability);
    }
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) OathbreakerOnBattlefieldCondition(mage.abilities.condition.common.OathbreakerOnBattlefieldCondition) CommanderReplacementEffect(mage.abilities.effects.common.continuous.CommanderReplacementEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) SignatureSpellCastOnlyWithOathbreakerEffect(mage.abilities.common.SignatureSpellCastOnlyWithOathbreakerEffect) ConditionHint(mage.abilities.hint.ConditionHint) CommanderCostModification(mage.abilities.effects.common.cost.CommanderCostModification) InfoEffect(mage.abilities.effects.common.InfoEffect)

Example 60 with SimpleStaticAbility

use of mage.abilities.common.SimpleStaticAbility in project mage by magefree.

the class ArterialAlchemyEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
        switch(layer) {
            case TypeChangingEffects_4:
                permanent.addSubType(game, SubType.EQUIPMENT);
                break;
            case AbilityAddingRemovingEffects_6:
                permanent.addAbility(new SimpleStaticAbility(new BoostEquippedEffect(2, 0)), source.getSourceId(), game);
                permanent.addAbility(new EquipAbility(2), source.getSourceId(), game);
                break;
        }
    }
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) BoostEquippedEffect(mage.abilities.effects.common.continuous.BoostEquippedEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EquipAbility(mage.abilities.keyword.EquipAbility)

Aggregations

SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)61 Test (org.junit.Test)27 Ability (mage.abilities.Ability)21 Player (mage.players.Player)14 Permanent (mage.game.permanent.Permanent)11 InfoEffect (mage.abilities.effects.common.InfoEffect)10 BoostAllEffect (mage.abilities.effects.common.continuous.BoostAllEffect)10 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)9 Card (mage.cards.Card)9 FixedTarget (mage.target.targetpointer.FixedTarget)9 UUID (java.util.UUID)8 LeavesBattlefieldTriggeredAbility (mage.abilities.common.LeavesBattlefieldTriggeredAbility)6 ContinuousEffect (mage.abilities.effects.ContinuousEffect)6 GainLifeEffect (mage.abilities.effects.common.GainLifeEffect)6 FilterCard (mage.filter.FilterCard)5 MageObject (mage.MageObject)4 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)4 PreventAllDamageToAllEffect (mage.abilities.effects.common.PreventAllDamageToAllEffect)4 BoostSourceEffect (mage.abilities.effects.common.continuous.BoostSourceEffect)4 AbilitiesCostReductionControllerEffect (mage.abilities.effects.common.cost.AbilitiesCostReductionControllerEffect)4