Search in sources :

Example 61 with GameEvent

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

the class Mulligan method executeMulliganPhase.

public void executeMulliganPhase(Game game, int startingHandSize) {
    /*
         * 103.4. Each player draws a number of cards equal to their starting hand size,
         * which is normally seven. (Some effects can modify a player’s starting hand size.)
         * A player who is dissatisfied with their initial hand may take a mulligan. First
         * the starting player declares whether they will take a mulligan. Then each other
         * player in turn order does the same. Once each player has made a declaration, all
         * players who decided to take mulligans do so at the same time. To take a mulligan,
         * a player shuffles their hand back into their library, then draws a new hand of one
         * fewer cards than they had before. If a player kept their hand of cards, those cards
         * become the player’s opening hand, and that player may not take any further mulligans.
         * This process is then repeated until no player takes a mulligan. (Note that if a
         * player’s hand size reaches zero cards, that player must keep that hand.)
         */
    List<UUID> keepPlayers = new ArrayList<>();
    List<UUID> mulliganPlayers = new ArrayList<>();
    do {
        mulliganPlayers.clear();
        for (UUID playerId : game.getState().getPlayerList(game.getStartingPlayerId())) {
            if (!keepPlayers.contains(playerId)) {
                Player player = game.getPlayer(playerId);
                boolean keep = true;
                while (true) {
                    if (!canTakeMulligan(game, player)) {
                        break;
                    }
                    GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId);
                    if (!game.replaceEvent(event)) {
                        game.fireEvent(event);
                        game.getState().setChoosingPlayerId(playerId);
                        if (player.chooseMulligan(game)) {
                            keep = false;
                        }
                        break;
                    }
                }
                if (keep) {
                    game.endMulligan(player.getId());
                    keepPlayers.add(playerId);
                    game.fireInformEvent(player.getLogName() + " keeps hand");
                } else {
                    mulliganPlayers.add(playerId);
                    game.fireInformEvent(player.getLogName() + " decides to take mulligan");
                }
            }
        }
        for (UUID mulliganPlayerId : mulliganPlayers) {
            mulligan(game, mulliganPlayerId);
        }
        game.saveState(false);
    } while (!mulliganPlayers.isEmpty());
}
Also used : Player(mage.players.Player) GameEvent(mage.game.events.GameEvent)

Example 62 with GameEvent

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

the class TestOfFaithPreventDamageTargetEffect 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 prevented = 0;
        if (event.getAmount() >= this.amount) {
            int damage = amount;
            event.setAmount(event.getAmount() - amount);
            this.used = true;
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
            prevented = damage;
        } else {
            int damage = event.getAmount();
            event.setAmount(0);
            amount -= damage;
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
            prevented = damage;
        }
        // add counters now
        if (prevented > 0) {
            Permanent targetPermanent = game.getPermanent(source.getTargets().getFirstTarget());
            if (targetPermanent != null) {
                targetPermanent.addCounters(CounterType.P1P1.createInstance(prevented), source.getControllerId(), source, game);
                game.informPlayers("Test of Faith: Prevented " + prevented + " damage ");
                game.informPlayers("Test of Faith: Adding " + prevented + " +1/+1 counters to " + targetPermanent.getName());
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 63 with GameEvent

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

the class WoodlandChampionTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeGroupEvent zEvent = (ZoneChangeGroupEvent) event;
    if (zEvent != null && Zone.BATTLEFIELD == zEvent.getToZone() && zEvent.getTokens() != null) {
        int tokenCount = zEvent.getTokens().stream().mapToInt(card -> card.isControlledBy(this.getControllerId()) ? 1 : 0).sum();
        if (tokenCount > 0) {
            this.getEffects().clear();
            this.addEffect(new AddCountersSourceEffect(CounterType.P1P1.createInstance(tokenCount)));
            return true;
        }
    }
    return false;
}
Also used : Zone(mage.constants.Zone) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent) CounterType(mage.counters.CounterType) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent)

Example 64 with GameEvent

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

the class AbilityImpl method resolve.

@Override
public boolean resolve(Game game) {
    boolean result = true;
    // 20100716 - 117.12
    if (checkIfClause(game)) {
        // Ability has started resolving. Fire event.
        // Used for abilities counting the number of resolutions like Ashling the Pilgrim.
        game.fireEvent(new GameEvent(GameEvent.EventType.RESOLVING_ABILITY, this.getOriginalId(), this, this.getControllerId()));
        if (this instanceof TriggeredAbility) {
            for (UUID modeId : this.getModes().getSelectedModes()) {
                this.getModes().setActiveMode(modeId);
                result = resolveMode(game);
            }
        } else {
            result = resolveMode(game);
        }
    }
    return result;
}
Also used : GameEvent(mage.game.events.GameEvent) UUID(java.util.UUID)

Example 65 with GameEvent

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

the class AdaptEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Verify source object did not change zone and is on the battlefield
    MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
    if (sourceObject == null) {
        if (game.getState().getZone(source.getSourceId()).equals(Zone.BATTLEFIELD) && source.getSourceObjectZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(source.getSourceId())) {
            sourceObject = game.getPermanent(source.getSourceId());
        }
    }
    Permanent permanent = ((Permanent) sourceObject);
    if (permanent == null) {
        return false;
    }
    GameEvent event = new GameEvent(GameEvent.EventType.ADAPT, source.getSourceId(), source, source.getControllerId(), adaptNumber, false);
    if (game.replaceEvent(event)) {
        return false;
    }
    if (permanent.getCounters(game).getCount(CounterType.P1P1) == 0 || event.getFlag()) {
        permanent.addCounters(CounterType.P1P1.createInstance(event.getAmount()), source.getControllerId(), source, game);
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) GameEvent(mage.game.events.GameEvent)

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