Search in sources :

Example 51 with GameEvent

use of mage.game.events.GameEvent in project mage by magefree.

the class FlameskullWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
        return;
    }
    MageObjectReference mor = event.getAdditionalReference().getApprovingMageObjectReference();
    Spell spell = game.getSpell(event.getTargetId());
    if (mor == null || spell == null) {
        return;
    }
    morMap.computeIfAbsent(mor, x -> new HashSet<>()).add(new MageObjectReference(spell.getMainCard(), game, -1));
}
Also used : java.util(java.util) mage.cards(mage.cards) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Player(mage.players.Player) CantBlockAbility(mage.abilities.common.CantBlockAbility) Game(mage.game.Game) Watcher(mage.watchers.Watcher) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) GameEvent(mage.game.events.GameEvent) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) Ability(mage.abilities.Ability) MageObjectReference(mage.MageObjectReference) Spell(mage.game.stack.Spell)

Example 52 with GameEvent

use of mage.game.events.GameEvent in project mage by magefree.

the class NineLivesStateTriggeredAbility method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        int damage = event.getAmount();
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            Permanent nineLives = source.getSourcePermanentIfItStillExists(game);
            if (nineLives != null) {
                nineLives.addCounters(CounterType.INCARNATION.createInstance(1), source.getControllerId(), source, game);
            }
        }
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 53 with GameEvent

use of mage.game.events.GameEvent in project mage by magefree.

the class VoltaicVisionaryWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.ZONE_CHANGE || ((ZoneChangeEvent) event).getToZone() != Zone.EXILED) {
        return;
    }
    Card card = game.getCard(event.getTargetId());
    UUID exileId = game.getExile().getExileZones().stream().filter(exileZone -> exileZone.contains(card)).map(ExileZone::getId).findFirst().orElse(null);
    if (exileId == null) {
        return;
    }
    map.computeIfAbsent(exileId, x -> new HashSet<>()).add(new MageObjectReference(card, game));
}
Also used : java.util(java.util) Zone(mage.constants.Zone) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) SubType(mage.constants.SubType) TransformSourceEffect(mage.abilities.effects.common.TransformSourceEffect) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ExileZone(mage.game.ExileZone) GameEvent(mage.game.events.GameEvent) ExileTopXMayPlayUntilEndOfTurnEffect(mage.abilities.effects.common.ExileTopXMayPlayUntilEndOfTurnEffect) TransformAbility(mage.abilities.keyword.TransformAbility) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) CardImpl(mage.cards.CardImpl) ActivateAsSorceryActivatedAbility(mage.abilities.common.ActivateAsSorceryActivatedAbility) CardType(mage.constants.CardType) WatcherScope(mage.constants.WatcherScope) Card(mage.cards.Card) DamageControllerEffect(mage.abilities.effects.common.DamageControllerEffect) Ability(mage.abilities.Ability) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ExileZone(mage.game.ExileZone) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 54 with GameEvent

use of mage.game.events.GameEvent in project mage by magefree.

the class CascadeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card sourceCard = game.getCard(source.getSourceId());
    if (sourceCard == null) {
        return false;
    }
    // exile cards from the top of your library until you exile a nonland card whose converted mana cost is less than this spell's converted mana cost
    Cards cardsToExile = new CardsImpl();
    int sourceCost = sourceCard.getManaValue();
    Card cardToCast = null;
    for (Card card : controller.getLibrary().getCards(game)) {
        cardsToExile.add(card);
        // the card move is sequential, not all at once.
        controller.moveCards(card, Zone.EXILED, source, game);
        // Laelia, the Blade Reforged
        game.getState().processAction(game);
        if (!card.isLand(game) && card.getManaValue() < sourceCost) {
            cardToCast = card;
            break;
        }
    }
    // set back empty draw state if that caused an empty draw
    controller.getLibrary().reset();
    // additional replacement effect: As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped
    GameEvent event = GameEvent.getEvent(GameEvent.EventType.CASCADE_LAND, source.getSourceId(), source, source.getControllerId(), 0);
    game.replaceEvent(event);
    if (event.getAmount() > 0) {
        TargetCardInExile target = new TargetCardInExile(0, event.getAmount(), StaticFilters.FILTER_CARD_LAND, null, true);
        target.withChooseHint("land to put onto battlefield tapped");
        controller.choose(Outcome.PutCardInPlay, cardsToExile, target, game);
        controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
    }
    // You may cast that spell without paying its mana cost if its converted mana cost is less than this spell's converted mana cost.
    List<Card> partsToCast = new ArrayList<>();
    if (cardToCast != null) {
        if (cardToCast instanceof SplitCard) {
            partsToCast.add(((SplitCard) cardToCast).getLeftHalfCard());
            partsToCast.add(((SplitCard) cardToCast).getRightHalfCard());
            partsToCast.add(cardToCast);
        } else if (cardToCast instanceof AdventureCard) {
            partsToCast.add(((AdventureCard) cardToCast).getSpellCard());
            partsToCast.add(cardToCast);
        } else if (cardToCast instanceof ModalDoubleFacesCard) {
            partsToCast.add(((ModalDoubleFacesCard) cardToCast).getLeftHalfCard());
            partsToCast.add(((ModalDoubleFacesCard) cardToCast).getRightHalfCard());
        } else {
            partsToCast.add(cardToCast);
        }
        // remove too big cmc
        partsToCast.removeIf(card -> card.getManaValue() >= sourceCost);
        // remove non spells
        partsToCast.removeIf(card -> card.getSpellAbility() == null);
    }
    String partsInfo = partsToCast.stream().map(MageObject::getIdName).collect(Collectors.joining(" or "));
    if (cardToCast != null && partsToCast.size() > 0 && controller.chooseUse(outcome, "Cast spell without paying its mana cost (" + partsInfo + ")?", source, game)) {
        try {
            // enable free cast for all compatible parts
            partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE));
            controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        } finally {
            partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null));
        }
    }
    // Then put all cards exiled this way that weren't cast on the bottom of your library in a random order.
    cardsToExile.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    return controller.putCardsOnBottomOfLibrary(cardsToExile, game, source, false);
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInExile(mage.target.common.TargetCardInExile) ArrayList(java.util.ArrayList) GameEvent(mage.game.events.GameEvent)

Example 55 with GameEvent

use of mage.game.events.GameEvent in project mage by magefree.

the class CrewCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    if (handleAltCost(ability, game, source, controllerId, noMana, costToPay)) {
        paid = true;
        return true;
    }
    Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true) {

        @Override
        public String getMessage() {
            // shows selected power
            int selectedPower = this.targets.entrySet().stream().map(entry -> (game.getPermanent(entry.getKey()))).filter(Objects::nonNull).mapToInt(p -> (getCrewPower(p, game))).sum();
            String extraInfo = "(selected power " + selectedPower + " of " + value + ")";
            if (selectedPower >= value) {
                extraInfo = HintUtils.prepareText(extraInfo, Color.GREEN);
            }
            return super.getMessage() + " " + extraInfo;
        }
    };
    // can cancel
    if (target.choose(Outcome.Tap, controllerId, source.getSourceId(), game)) {
        int sumPower = 0;
        for (UUID targetId : target.getTargets()) {
            GameEvent event = new GameEvent(GameEvent.EventType.CREW_VEHICLE, targetId, source, controllerId);
            if (!game.replaceEvent(event)) {
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null && permanent.tap(source, game)) {
                    sumPower += getCrewPower(permanent, game);
                }
            }
        }
        paid = sumPower >= value;
        if (paid) {
            for (UUID targetId : target.getTargets()) {
                game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREWED_VEHICLE, targetId, source, controllerId));
            }
        }
    } else {
        return false;
    }
    return paid;
}
Also used : Target(mage.target.Target) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) CrewAbilityIcon(mage.abilities.icon.abilities.CrewAbilityIcon) Zone(mage.constants.Zone) TappedPredicate(mage.filter.predicate.permanent.TappedPredicate) AddCardTypeSourceEffect(mage.abilities.effects.common.continuous.AddCardTypeSourceEffect) Player(mage.players.Player) CrewIncreasedPowerAbility(mage.abilities.common.CrewIncreasedPowerAbility) Cost(mage.abilities.costs.Cost) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CrewWithToughnessAbility(mage.abilities.common.CrewWithToughnessAbility) CostImpl(mage.abilities.costs.CostImpl) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) java.awt(java.awt) Objects(java.util.Objects) Duration(mage.constants.Duration) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) InfoEffect(mage.abilities.effects.common.InfoEffect) Permanent(mage.game.permanent.Permanent) HintUtils(mage.abilities.hint.HintUtils) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Ability(mage.abilities.Ability) Target(mage.target.Target) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Objects(java.util.Objects) GameEvent(mage.game.events.GameEvent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

GameEvent (mage.game.events.GameEvent)82 Permanent (mage.game.permanent.Permanent)28 Player (mage.players.Player)24 PreventDamageEvent (mage.game.events.PreventDamageEvent)23 PreventedDamageEvent (mage.game.events.PreventedDamageEvent)23 Game (mage.game.Game)22 Ability (mage.abilities.Ability)15 MageInt (mage.MageInt)13 CardImpl (mage.cards.CardImpl)13 CardSetInfo (mage.cards.CardSetInfo)13 java.util (java.util)12 OneShotEffect (mage.abilities.effects.OneShotEffect)12 Watcher (mage.watchers.Watcher)12 MageObjectReference (mage.MageObjectReference)11 Card (mage.cards.Card)11 UUID (java.util.UUID)10 TriggeredAbilityImpl (mage.abilities.TriggeredAbilityImpl)10 mage.constants (mage.constants)10 MageObject (mage.MageObject)9 Spell (mage.game.stack.Spell)9