Search in sources :

Example 21 with StackAbility

use of mage.game.stack.StackAbility 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 22 with StackAbility

use of mage.game.stack.StackAbility 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 23 with StackAbility

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

the class KurkeshOnakkeAncientTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getPlayerId().equals(getControllerId())) {
        return false;
    }
    Card source = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (source == null || !source.isArtifact(game)) {
        return false;
    }
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
    if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
        return false;
    }
    this.getEffects().setValue("stackAbility", stackAbility);
    return true;
}
Also used : ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) StackAbility(mage.game.stack.StackAbility) Card(mage.cards.Card)

Example 24 with StackAbility

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

the class RadiantPerformerEffect method prepareCopiesWithTargets.

@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
    List<MageObjectReferencePredicate> predicates = new ArrayList<>();
    Ability ability = stackObject instanceof Spell ? ((Spell) stackObject).getSpellAbility() : (StackAbility) stackObject;
    UUID targeted = ability == null ? null : ability.getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    return predicates;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) Ability(mage.abilities.Ability) Target(mage.target.Target) java.util(java.util) CopySpellForEachItCouldTargetEffect(mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect) TargetStackObject(mage.target.TargetStackObject) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) CastFromHandSourcePermanentCondition(mage.abilities.condition.common.CastFromHandSourcePermanentCondition) SubType(mage.constants.SubType) Mode(mage.abilities.Mode) Player(mage.players.Player) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) FilterStackObject(mage.filter.FilterStackObject) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CastFromHandWatcher(mage.watchers.common.CastFromHandWatcher) Ability(mage.abilities.Ability) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 25 with StackAbility

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

the class RepeatedReverberationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (stackAbility == null) {
        return false;
    }
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(stackAbility.getStackAbility().getSourceId());
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    stackAbility.createCopyOnStack(game, source, source.getControllerId(), true, 2);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) StackAbility(mage.game.stack.StackAbility)

Aggregations

StackAbility (mage.game.stack.StackAbility)42 Permanent (mage.game.permanent.Permanent)15 StackObject (mage.game.stack.StackObject)12 Player (mage.players.Player)11 Target (mage.target.Target)9 MageObject (mage.MageObject)8 Ability (mage.abilities.Ability)7 Spell (mage.game.stack.Spell)7 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)6 GameEvent (mage.game.events.GameEvent)6 Game (mage.game.Game)5 UUID (java.util.UUID)4 MageObjectReference (mage.MageObjectReference)4 PassAbility (mage.abilities.common.PassAbility)4 Mode (mage.abilities.Mode)3 Card (mage.cards.Card)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 ActivatedAbility (mage.abilities.ActivatedAbility)2 LoyaltyAbility (mage.abilities.LoyaltyAbility)2 SpellAbility (mage.abilities.SpellAbility)2