Search in sources :

Example 31 with CombatGroup

use of mage.game.combat.CombatGroup in project mage by magefree.

the class SorrowsPathSwitchBlockersEffect method reassignBlocker.

private void reassignBlocker(Permanent blocker, Set<Permanent> attackers, Game game) {
    for (Permanent attacker : attackers) {
        CombatGroup group = game.getCombat().findGroup(attacker.getId());
        if (group != null) {
            group.addBlockerToGroup(blocker.getId(), blocker.getControllerId(), game);
            game.getCombat().addBlockingGroup(blocker.getId(), attacker.getId(), blocker.getControllerId(), game);
            // TODO: find an alternate event solution for multi-blockers (as per issue #4285), this will work fine for single blocker creatures though
            game.fireEvent(new BlockerDeclaredEvent(attacker.getId(), blocker.getId(), blocker.getControllerId()));
            group.pickBlockerOrder(attacker.getControllerId(), game);
        }
    }
    // a new blockingGroup is formed, so it's necessary to find it again
    CombatGroup blockGroup = findBlockingGroup(blocker, game);
    if (blockGroup != null) {
        blockGroup.pickAttackerOrder(blocker.getControllerId(), game);
    }
}
Also used : Permanent(mage.game.permanent.Permanent) FilterOpponentsCreaturePermanent(mage.filter.common.FilterOpponentsCreaturePermanent) BlockerDeclaredEvent(mage.game.events.BlockerDeclaredEvent) CombatGroup(mage.game.combat.CombatGroup)

Example 32 with CombatGroup

use of mage.game.combat.CombatGroup in project mage by magefree.

the class TheWretchedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent theWretched = source.getSourcePermanentIfItStillExists(game);
    if (theWretched == null || theWretched.isRemovedFromCombat() || !theWretched.isAttacking() || !source.isControlledBy(theWretched.getControllerId())) {
        return false;
    }
    // Check if control of source has changed since ability triggered????? (does it work is it neccessary???)
    for (CombatGroup combatGroup : game.getCombat().getGroups()) {
        if (!combatGroup.getAttackers().contains(source.getSourceId())) {
            continue;
        }
        for (UUID creatureId : combatGroup.getBlockers()) {
            Permanent blocker = game.getPermanent(creatureId);
            if (blocker == null || blocker.getBlocking() <= 0) {
                continue;
            }
            ContinuousEffect effect = new GainControlTargetEffect(Duration.WhileControlled, source.getControllerId());
            effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) CombatGroup(mage.game.combat.CombatGroup)

Example 33 with CombatGroup

use of mage.game.combat.CombatGroup in project mage by magefree.

the class TrialEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && creature != null) {
        Set<Card> toHand = new HashSet<>();
        for (CombatGroup combatGroup : game.getCombat().getGroups()) {
            if (combatGroup.getBlockers().contains(creature.getId())) {
                for (UUID attackerId : combatGroup.getAttackers()) {
                    Permanent attacker = game.getPermanent(attackerId);
                    if (attacker != null) {
                        toHand.add(attacker);
                    }
                }
            } else if (combatGroup.getAttackers().contains(creature.getId())) {
                for (UUID blockerId : combatGroup.getBlockers()) {
                    Permanent blocker = game.getPermanent(blockerId);
                    if (blocker != null) {
                        toHand.add(blocker);
                    }
                }
            }
        }
        controller.moveCards(toHand, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 34 with CombatGroup

use of mage.game.combat.CombatGroup in project mage by magefree.

the class BecomeBlockedTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Set<MageObjectReference> morSet = new HashSet<>();
    for (UUID targetId : targetPointer.getTargets(game, source)) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent == null) {
            continue;
        }
        CombatGroup combatGroup = game.getCombat().findGroup(permanent.getId());
        if (combatGroup == null) {
            continue;
        }
        boolean alreadyBlocked = combatGroup.getBlocked();
        combatGroup.setBlocked(true, game);
        if (alreadyBlocked) {
            continue;
        }
        game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, permanent.getId(), source, null));
        morSet.add(new MageObjectReference(permanent, game));
    }
    String key = UUID.randomUUID().toString();
    game.getState().setValue("becameBlocked_" + key, morSet);
    game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BATCH_BLOCK_NONCOMBAT, source.getSourceId(), source, source.getControllerId(), key, 0));
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) CombatGroup(mage.game.combat.CombatGroup) HashSet(java.util.HashSet)

Example 35 with CombatGroup

use of mage.game.combat.CombatGroup in project mage by magefree.

the class CombatSimulator method load.

public static CombatSimulator load(Game game) {
    CombatSimulator simCombat = new CombatSimulator();
    for (CombatGroup group : game.getCombat().getGroups()) {
        simCombat.groups.add(new CombatGroupSimulator(group.getDefenderId(), group.getAttackers(), group.getBlockers(), game));
    }
    for (UUID defenderId : game.getCombat().getDefenders()) {
        simCombat.defenders.add(defenderId);
        Player player = game.getPlayer(defenderId);
        if (player != null) {
            simCombat.playersLife.put(defenderId, player.getLife());
        } else {
            Permanent permanent = game.getPermanent(defenderId);
            simCombat.planeswalkerLoyalty.put(defenderId, permanent.getCounters(game).getCount(CounterType.LOYALTY));
        }
    }
    return simCombat;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) CombatGroup(mage.game.combat.CombatGroup)

Aggregations

CombatGroup (mage.game.combat.CombatGroup)44 Permanent (mage.game.permanent.Permanent)39 UUID (java.util.UUID)25 Player (mage.players.Player)23 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)9 FixedTarget (mage.target.targetpointer.FixedTarget)9 TargetPermanent (mage.target.TargetPermanent)8 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)8 HashSet (java.util.HashSet)7 OneShotEffect (mage.abilities.effects.OneShotEffect)6 Game (mage.game.Game)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Combat (mage.game.combat.Combat)5 BlockerDeclaredEvent (mage.game.events.BlockerDeclaredEvent)5 Target (mage.target.Target)5 MageObjectReference (mage.MageObjectReference)4 Ability (mage.abilities.Ability)4 PermanentInListPredicate (mage.filter.predicate.permanent.PermanentInListPredicate)4 BlockedByOnlyOneCreatureThisCombatWatcher (mage.watchers.common.BlockedByOnlyOneCreatureThisCombatWatcher)4