Search in sources :

Example 1 with RemoveAllCountersSourceEffect

use of mage.abilities.effects.common.RemoveAllCountersSourceEffect in project mage by magefree.

the class RogueSkycaptainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && permanent != null) {
        new AddCountersSourceEffect(CounterType.WAGE.createInstance(), true).apply(game, source);
        Cost cost = ManaUtil.createManaCost(2 * permanent.getCounters(game).getCount(CounterType.WAGE), false);
        if (!cost.pay(source, game, source, controller.getId(), false)) {
            new RemoveAllCountersSourceEffect(CounterType.WAGE).apply(game, source);
            Player opponent;
            Set<UUID> opponents = game.getOpponents(controller.getId());
            if (opponents.size() == 1) {
                opponent = game.getPlayer(opponents.iterator().next());
            } else {
                Target target = new TargetOpponent(true);
                target.setNotTarget(true);
                target.choose(Outcome.GainControl, source.getControllerId(), source.getSourceId(), game);
                opponent = game.getPlayer(target.getFirstTarget());
            }
            if (opponent != null) {
                permanent.changeControllerId(opponent.getId(), game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) RemoveAllCountersSourceEffect(mage.abilities.effects.common.RemoveAllCountersSourceEffect) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost)

Aggregations

UUID (java.util.UUID)1 Cost (mage.abilities.costs.Cost)1 RemoveAllCountersSourceEffect (mage.abilities.effects.common.RemoveAllCountersSourceEffect)1 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetOpponent (mage.target.common.TargetOpponent)1