Search in sources :

Example 6 with GameEvent

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

the class BeamsplitterMageApplier method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!isControlledBy(event.getPlayerId())) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    if (spell.getSpellAbilities().stream().map(AbilityImpl::getModes).flatMap(m -> m.getSelectedModes().stream().map(m::get)).filter(Objects::nonNull).map(Mode::getTargets).flatMap(Collection::stream).filter(t -> !t.isNotTarget()).map(Target::getTargets).flatMap(Collection::stream).anyMatch(uuid -> !getSourceId().equals(uuid) && uuid != null)) {
        return false;
    }
    this.getEffects().setValue("spellCast", spell);
    return true;
}
Also used : Target(mage.target.Target) java.util(java.util) Zone(mage.constants.Zone) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) SubType(mage.constants.SubType) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) Player(mage.players.Player) StackObjectCopyApplier(mage.util.functions.StackObjectCopyApplier) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) Spell(mage.game.stack.Spell)

Example 7 with GameEvent

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

the class FrontierWarmongerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Set<UUID> opponents = game.getOpponents(this.getControllerId());
    Predicate<UUID> predicate = uuid -> opponents.contains(game.getCombat().getDefendingPlayerId(uuid, game));
    if (game.getCombat().getAttackers().stream().noneMatch(predicate)) {
        return false;
    }
    List<Permanent> permanents = game.getCombat().getAttackers().stream().filter(predicate).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
    this.getEffects().setTargetPointer(new FixedTargets(permanents, game));
    return true;
}
Also used : Zone(mage.constants.Zone) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) List(java.util.List) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FixedTargets(mage.target.targetpointer.FixedTargets) MenaceAbility(mage.abilities.keyword.MenaceAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) UUID(java.util.UUID)

Example 8 with GameEvent

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

the class HeartOfLightEffect 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();
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 9 with GameEvent

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

the class HazeFrogEffect 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();
        Permanent permanent = game.getPermanent(event.getSourceId());
        StringBuilder message = new StringBuilder();
        if (permanent != null) {
            message.append(" from ").append(permanent.getName());
        }
        message.insert(0, "Damage").append(" has been prevented: ").append(damage);
        event.setAmount(0);
        game.informPlayers(message.toString());
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 10 with GameEvent

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

the class KotoseTheSilentSpiderWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.CLEANUP_STEP_POST) {
        morMap.entrySet().removeIf(e -> !e.getKey().zoneCounterIsCurrent(game));
        morMap.values().stream().flatMap(Collection::stream).map(set -> set.removeIf(mor -> !mor.zoneCounterIsCurrent(game)));
        morMap.values().removeIf(Set::isEmpty);
        return;
    }
    if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
        return;
    }
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null) {
        return;
    }
    morMap.getOrDefault(event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()).removeIf(set -> set.stream().anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId()) && mor.getZoneChangeCounter() + 1 == spell.getZoneChangeCounter(game)));
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Spell(mage.game.stack.Spell) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) Ability(mage.abilities.Ability) Spell(mage.game.stack.Spell)

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