Search in sources :

Example 21 with GameEvent

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

the class AnowonTheRuinThiefWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
        damageMap.clear();
        return;
    }
    if (event.getType() != GameEvent.EventType.DAMAGED_PLAYER || !((DamagedPlayerEvent) event).isCombatDamage()) {
        return;
    }
    Permanent creature = game.getPermanent(event.getSourceId());
    if (creature == null || !creature.hasSubtype(SubType.ROGUE, game)) {
        return;
    }
    damageMap.computeIfAbsent(event.getTargetId(), x -> new HashMap<>()).compute(creature.getControllerId(), (uuid, i) -> i == null ? event.getAmount() : event.getAmount() + i);
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) StaticFilters(mage.filter.StaticFilters) java.util(java.util) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect) mage.constants(mage.constants) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 22 with GameEvent

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

the class MindlinkMechApplier method watch.

@Override
public void watch(GameEvent event, Game game) {
    Permanent vehicle;
    Permanent crewer;
    switch(event.getType()) {
        case VEHICLE_CREWED:
            vehicle = game.getPermanent(event.getTargetId());
            crewer = null;
            break;
        case CREWED_VEHICLE:
            vehicle = game.getPermanent(event.getSourceId());
            crewer = game.getPermanent(event.getTargetId());
            break;
        default:
            return;
    }
    if (vehicle == null) {
        return;
    }
    if (crewer == null) {
        crewCount.compute(new MageObjectReference(vehicle, game), (m, i) -> i == null ? 1 : Integer.sum(i, 1));
        return;
    }
    crewMap.computeIfAbsent(new MageObjectReference(vehicle, game), x -> new HashSet<>()).add(new MageObjectReference(crewer, game));
}
Also used : java.util(java.util) CopyApplier(mage.util.functions.CopyApplier) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) CrewAbility(mage.abilities.keyword.CrewAbility) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference)

Example 23 with GameEvent

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

the class PilgrimOfVirtueEffect 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);
        // one time use
        this.used = true;
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        return true;
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 24 with GameEvent

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

the class PhyrexianHydraEffect method replaceEvent.

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

Example 25 with GameEvent

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

the class PilgrimOfJusticeEffect 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);
        // one time use
        this.used = true;
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        return true;
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

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