Search in sources :

Example 46 with GameEvent

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

the class MageDrawAction method doAction.

/**
 * Draw and set action score.
 *
 * @param source
 * @param game     Game context.
 * @return
 */
@Override
public int doAction(Ability source, Game game) {
    int numDrawn = 0;
    int score = 0;
    GameEvent event = new DrawCardsEvent(this.player.getId(), source, this.originalDrawEvent, this.amount);
    if (amount < 2 || !game.replaceEvent(event)) {
        amount = event.getAmount();
        for (int i = 0; i < amount; i++) {
            int value = drawCard(source, this.originalDrawEvent, game);
            if (value == NEGATIVE_VALUE) {
                continue;
            }
            numDrawn++;
            score += value;
        }
        if (!player.isTopCardRevealed() && numDrawn > 0) {
            game.fireInformEvent(player.getLogName() + " draws " + CardUtil.numberToText(numDrawn, "a") + " card" + (numDrawn > 1 ? "s" : ""));
        }
        setScore(player, score);
    }
    return numDrawn;
}
Also used : DrawCardsEvent(mage.game.events.DrawCardsEvent) GameEvent(mage.game.events.GameEvent)

Example 47 with GameEvent

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

the class MageDrawAction method drawCard.

/**
 * Draw a card if possible (there is no replacement effect that prevent us
 * from drawing). Fire event about card drawn.
 *
 * @param source
 * @param originalDrawEvent original draw event for replacement effects, can be null for normal calls
 * @param game
 * @return
 */
protected int drawCard(Ability source, GameEvent originalDrawEvent, Game game) {
    GameEvent event = new DrawCardEvent(this.player.getId(), source, originalDrawEvent);
    if (!game.replaceEvent(event)) {
        Card card = player.getLibrary().removeFromTop(game);
        if (card != null) {
            drawnCards.add(card);
            // if you want to use event.getSourceId() here then thinks x10 times
            card.moveToZone(Zone.HAND, source, game, false);
            if (player.isTopCardRevealed()) {
                game.fireInformEvent(player.getLogName() + " draws a revealed card  (" + card.getLogName() + ')');
            }
            game.fireEvent(new DrewCardEvent(card.getId(), player.getId(), source, originalDrawEvent));
            return ArtificialScoringSystem.inst.getCardScore(card);
        }
    }
    return NEGATIVE_VALUE;
}
Also used : GameEvent(mage.game.events.GameEvent) DrawCardEvent(mage.game.events.DrawCardEvent) DrewCardEvent(mage.game.events.DrewCardEvent) Card(mage.cards.Card)

Example 48 with GameEvent

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

the class CombatDamageStep method priority.

@Override
public void priority(Game game, UUID activePlayerId, boolean resuming) {
    game.fireEvent(new GameEvent(GameEvent.EventType.COMBAT_DAMAGE_STEP_PRIORITY, null, null, activePlayerId));
    super.priority(game, activePlayerId, resuming);
}
Also used : GameEvent(mage.game.events.GameEvent)

Example 49 with GameEvent

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

the class ManaPaidSourceWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    switch(event.getType()) {
        case ZONE_CHANGE:
            if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
                manaMap.remove(event.getTargetId());
            }
            return;
        case MANA_PAID:
            ManaPaidEvent manaEvent = (ManaPaidEvent) event;
            manaMap.computeIfAbsent(manaEvent.getTargetId(), x -> new ManaPaidTracker()).increment(manaEvent.getSourceObject(), manaEvent.getManaType(), game);
            manaMap.computeIfAbsent(manaEvent.getSourcePaidId(), x -> new ManaPaidTracker()).increment(manaEvent.getSourceObject(), manaEvent.getManaType(), game);
    }
}
Also used : Zone(mage.constants.Zone) HashMap(java.util.HashMap) UUID(java.util.UUID) SubType(mage.constants.SubType) ManaPaidEvent(mage.game.events.ManaPaidEvent) Serializable(java.io.Serializable) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) ManaType(mage.constants.ManaType) Map(java.util.Map) WatcherScope(mage.constants.WatcherScope) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) ObjectColor(mage.ObjectColor) Copyable(mage.util.Copyable) ManaPaidEvent(mage.game.events.ManaPaidEvent)

Example 50 with GameEvent

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

the class ProwlWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != EventType.DAMAGED_PLAYER) {
        return;
    }
    DamagedPlayerEvent dEvent = (DamagedPlayerEvent) event;
    if (!dEvent.isCombatDamage()) {
        return;
    }
    Permanent creature = game.getPermanent(dEvent.getSourceId());
    if (creature == null || allSubtypes.contains(creature.getControllerId())) {
        return;
    }
    if (creature.isAllCreatureTypes(game)) {
        allSubtypes.add(creature.getControllerId());
        return;
    }
    damagingSubtypes.computeIfAbsent(creature.getControllerId(), m -> new LinkedHashSet<>()).addAll(creature.getSubtype(game));
}
Also used : Game(mage.game.Game) Watcher(mage.watchers.Watcher) java.util(java.util) GameEvent(mage.game.events.GameEvent) SubTypeSet(mage.constants.SubTypeSet) Permanent(mage.game.permanent.Permanent) WatcherScope(mage.constants.WatcherScope) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) EventType(mage.game.events.GameEvent.EventType) Card(mage.cards.Card) SubType(mage.constants.SubType) Permanent(mage.game.permanent.Permanent) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

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