Search in sources :

Example 1 with TapTargetCost

use of mage.abilities.costs.common.TapTargetCost in project mage by magefree.

the class VodalianWarMachineWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
        if (event.getSourceId() != null) {
            Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
            if (sourcePermanent != null) {
                StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
                if (stackAbility != null) {
                    Ability ability = stackAbility.getStackAbility();
                    if (ability != null) {
                        for (Cost cost : ability.getCosts()) {
                            if (cost instanceof TapTargetCost && cost.isPaid()) {
                                TapTargetCost tapCost = (TapTargetCost) cost;
                                if (tapCost.getTarget().isChosen()) {
                                    MageObjectReference mor = new MageObjectReference(sourcePermanent.getId(), sourcePermanent.getZoneChangeCounter(game), game);
                                    Set<MageObjectReference> toAdd;
                                    if (tappedMerfolkIds.get(mor) == null) {
                                        toAdd = new HashSet<>();
                                    } else {
                                        toAdd = tappedMerfolkIds.get(mor);
                                    }
                                    for (UUID targetId : tapCost.getTarget().getTargets()) {
                                        toAdd.add(new MageObjectReference(targetId, game));
                                    }
                                    tappedMerfolkIds.put(mor, toAdd);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) StackAbility(mage.game.stack.StackAbility) DefenderAbility(mage.abilities.keyword.DefenderAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TapTargetCost(mage.abilities.costs.common.TapTargetCost) TapTargetCost(mage.abilities.costs.common.TapTargetCost) Cost(mage.abilities.costs.Cost) StackAbility(mage.game.stack.StackAbility) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)1 Ability (mage.abilities.Ability)1 DiesSourceTriggeredAbility (mage.abilities.common.DiesSourceTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 Cost (mage.abilities.costs.Cost)1 TapTargetCost (mage.abilities.costs.common.TapTargetCost)1 DefenderAbility (mage.abilities.keyword.DefenderAbility)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 Permanent (mage.game.permanent.Permanent)1 StackAbility (mage.game.stack.StackAbility)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1