Search in sources :

Example 1 with PlayLandAsCommanderAbility

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

the class PlayerImpl method activateAbility.

@Override
public boolean activateAbility(ActivatedAbility ability, Game game) {
    if (ability == null) {
        return false;
    }
    boolean result;
    if (ability instanceof PassAbility) {
        pass(game);
        return true;
    }
    Card card = game.getCard(ability.getSourceId());
    if (ability instanceof PlayLandAsCommanderAbility) {
        // LAND as commander: play land with cost, but without stack
        ActivationStatus activationStatus = ability.canActivate(this.playerId, game);
        if (!activationStatus.canActivate() || !this.canPlayLand()) {
            return false;
        }
        if (card == null) {
            return false;
        }
        // as copy, tries to applie cost effects and pays
        Ability activatingAbility = ability.copy();
        if (activatingAbility.activate(game, false)) {
            result = playLand(card, game, false);
        } else {
            result = false;
        }
    } else if (ability instanceof PlayLandAbility) {
        // LAND as normal card: without cost and stack
        result = playLand(card, game, false);
    } else {
        // ABILITY
        ActivationStatus activationStatus = ability.canActivate(this.playerId, game);
        if (!activationStatus.canActivate()) {
            return false;
        }
        switch(ability.getAbilityType()) {
            case SPECIAL_ACTION:
                result = specialAction((SpecialAction) ability.copy(), game);
                break;
            case SPECIAL_MANA_PAYMENT:
                result = specialManaPayment((SpecialAction) ability.copy(), game);
                break;
            case MANA:
                result = playManaAbility((ActivatedManaAbilityImpl) ability.copy(), game);
                break;
            case SPELL:
                result = cast((SpellAbility) ability, game, false, activationStatus.getApprovingObject());
                break;
            default:
                result = playAbility(ability.copy(), game);
                break;
        }
    }
    // if player has taken an action then reset all player passed flags
    justActivatedType = null;
    if (result) {
        if (isHuman() && (ability.getAbilityType() == AbilityType.SPELL || ability.getAbilityType() == AbilityType.ACTIVATED)) {
            if (ability.isUsesStack()) {
                // if the ability does not use the stack (e.g. Suspend) auto pass would go to next phase unintended
                setJustActivatedType(ability.getAbilityType());
            }
        }
        game.getPlayers().resetPassed();
    }
    return result;
}
Also used : AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) StackAbility(mage.game.stack.StackAbility) WhileSearchingPlayFromLibraryAbility(mage.abilities.common.WhileSearchingPlayFromLibraryAbility) AtTheEndOfTurnStepPostDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility) PassAbility(mage.abilities.common.PassAbility) PlayLandAsCommanderAbility(mage.abilities.common.PlayLandAsCommanderAbility) PassAbility(mage.abilities.common.PassAbility) PlayLandAsCommanderAbility(mage.abilities.common.PlayLandAsCommanderAbility) ActivationStatus(mage.abilities.ActivatedAbility.ActivationStatus) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard)

Aggregations

ActivationStatus (mage.abilities.ActivatedAbility.ActivationStatus)1 PassAbility (mage.abilities.common.PassAbility)1 PlayLandAsCommanderAbility (mage.abilities.common.PlayLandAsCommanderAbility)1 WhileSearchingPlayFromLibraryAbility (mage.abilities.common.WhileSearchingPlayFromLibraryAbility)1 AtTheEndOfTurnStepPostDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility)1 AlternateManaPaymentAbility (mage.abilities.costs.mana.AlternateManaPaymentAbility)1 FilterCard (mage.filter.FilterCard)1 PermanentCard (mage.game.permanent.PermanentCard)1 StackAbility (mage.game.stack.StackAbility)1 TargetCard (mage.target.TargetCard)1