Search in sources :

Example 1 with KorSoldierToken

use of mage.game.permanent.token.KorSoldierToken in project mage by magefree.

the class NahiriTheLithomancerSecondAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Token token = new KorSoldierToken();
        if (token.putOntoBattlefield(1, game, source, source.getControllerId())) {
            for (UUID tokenId : token.getLastAddedTokenIds()) {
                Permanent tokenPermanent = game.getPermanent(tokenId);
                if (tokenPermanent != null) {
                    // TODO: Make sure the Equipment can legally enchant the token, preferably on targetting.
                    Target target = new TargetControlledPermanent(0, 1, filter, true);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Attach an Equipment you control to the created " + tokenPermanent.getIdName() + '?', source, game)) {
                        if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
                            Permanent equipmentPermanent = game.getPermanent(target.getFirstTarget());
                            if (equipmentPermanent != null) {
                                Permanent attachedTo = game.getPermanent(equipmentPermanent.getAttachedTo());
                                if (attachedTo != null) {
                                    attachedTo.removeAttachment(equipmentPermanent.getId(), source, game);
                                }
                                tokenPermanent.addAttachment(equipmentPermanent.getId(), source, game);
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) KorSoldierToken(mage.game.permanent.token.KorSoldierToken) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) KorSoldierToken(mage.game.permanent.token.KorSoldierToken) NahiriTheLithomancerEquipmentToken(mage.game.permanent.token.NahiriTheLithomancerEquipmentToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 Permanent (mage.game.permanent.Permanent)1 KorSoldierToken (mage.game.permanent.token.KorSoldierToken)1 NahiriTheLithomancerEquipmentToken (mage.game.permanent.token.NahiriTheLithomancerEquipmentToken)1 Token (mage.game.permanent.token.Token)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)1