Search in sources :

Example 71 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class ValiantRescuerWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.ACTIVATED_ABILITY || game.getState().getStack().isEmpty()) {
        return;
    }
    StackObject item = game.getState().getStack().getFirst();
    if (item instanceof StackAbility && item.getStackAbility() instanceof CyclingAbility) {
        playerMap.computeIfAbsent(event.getPlayerId(), u -> new HashMap<>());
        playerMap.get(event.getPlayerId()).compute(event.getSourceId(), CardUtil::setOrIncrementValue);
    }
}
Also used : CyclingAbility(mage.abilities.keyword.CyclingAbility) StackObject(mage.game.stack.StackObject) StackAbility(mage.game.stack.StackAbility) CardUtil(mage.util.CardUtil)

Example 72 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class ValiantRescuerWatcher method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ValiantRescuerWatcher watcher = game.getState().getWatcher(ValiantRescuerWatcher.class);
    if (watcher == null || !watcher.checkSpell(event.getPlayerId(), event.getSourceId()) || game.getState().getStack().isEmpty() || !event.getPlayerId().equals(this.getControllerId()) || event.getSourceId().equals(this.getSourceId())) {
        return false;
    }
    StackObject item = game.getState().getStack().getFirst();
    return item instanceof StackAbility && item.getStackAbility() instanceof CyclingAbility;
}
Also used : CyclingAbility(mage.abilities.keyword.CyclingAbility) StackObject(mage.game.stack.StackObject) StackAbility(mage.game.stack.StackAbility)

Example 73 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class BecomesTargetControlledPermanentTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
    if (sourceObject == null) {
        return false;
    }
    Player targetter = game.getPlayer(event.getPlayerId());
    if (targetter == null || !targetter.hasOpponent(this.controllerId, game)) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
    if (permanent == null || !permanent.isControlledBy(this.getControllerId())) {
        return false;
    }
    // If a spell or ability an opponent controls targets a single permanent you control more than once,
    // Battle Mammoth’s triggered ability will trigger only once.
    // However, if a spell or ability an opponent controls targets multiple permanents you control,
    // Battle Mammoth’s triggered ability will trigger once for each of those permanents.
    // targetMap - key - targetId, value - Set of stackObject Ids
    Map<UUID, Set<UUID>> targetMap = (Map<UUID, Set<UUID>>) game.getState().getValue("targetMap" + this.id);
    if (targetMap == null) {
        targetMap = new HashMap<>();
    }
    Set<UUID> sourceObjects = targetMap.get(event.getTargetId());
    if (sourceObjects == null) {
        sourceObjects = new HashSet<>();
    }
    if (!sourceObjects.add(sourceObject.getId())) {
        return false;
    }
    targetMap.put(event.getTargetId(), sourceObjects);
    game.getState().setValue("targetMap" + this.id, targetMap);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject)

Example 74 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class VariableCostImpl method announceXValue.

@Override
public int announceXValue(Ability source, Game game) {
    int xValue = 0;
    Player controller = game.getPlayer(source.getControllerId());
    StackObject stackObject = game.getStack().getStackObject(source.getId());
    if (controller != null && (source instanceof ManaAbility || stackObject != null)) {
        xValue = controller.announceXCost(getMinValue(source, game), getMaxValue(source, game), "Announce the number of " + actionText, game, source, this);
    }
    return xValue;
}
Also used : Player(mage.players.Player) ManaAbility(mage.abilities.mana.ManaAbility) StackObject(mage.game.stack.StackObject)

Example 75 with StackObject

use of mage.game.stack.StackObject in project mage by magefree.

the class GravestormEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        StackObject spell = game.getStack().getStackObject(this.getSourceId());
        if (spell instanceof Spell) {
            for (Effect effect : this.getEffects()) {
                effect.setValue("GravestormSpell", spell);
                effect.setValue("GravestormSpellRef", new MageObjectReference(spell.getId(), game));
            }
            return true;
        }
    }
    return false;
}
Also used : StackObject(mage.game.stack.StackObject) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Aggregations

StackObject (mage.game.stack.StackObject)130 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)57 Spell (mage.game.stack.Spell)41 MageObject (mage.MageObject)37 UUID (java.util.UUID)36 Card (mage.cards.Card)29 Target (mage.target.Target)17 TargetPermanent (mage.target.TargetPermanent)15 FilterCard (mage.filter.FilterCard)14 Ability (mage.abilities.Ability)13 FilterPermanent (mage.filter.FilterPermanent)13 StackAbility (mage.game.stack.StackAbility)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)11 HashSet (java.util.HashSet)10 Effect (mage.abilities.effects.Effect)9 Game (mage.game.Game)9 MageObjectReference (mage.MageObjectReference)8 Cost (mage.abilities.costs.Cost)8