Search in sources :

Example 11 with CombatGroup

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

the class GoblinVandalTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent sourcePermanent = game.getPermanent(getSourceId());
    if (sourcePermanent.isAttacking()) {
        for (CombatGroup combatGroup : game.getCombat().getGroups()) {
            if (combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(getSourceId())) {
                UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(getSourceId(), game);
                FilterPermanent filter = new FilterArtifactPermanent();
                filter.add(new ControllerIdPredicate(defendingPlayerId));
                Target target = new TargetPermanent(filter);
                this.addTarget(target);
                return true;
            }
        }
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup)

Example 12 with CombatGroup

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

the class VortexElementalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Combat combat = game.getState().getCombat();
        Set<UUID> creaturesToReturn = new HashSet<>();
        Set<UUID> playersToShuffle = new HashSet<>();
        creaturesToReturn.add(source.getSourceId());
        if (combat != null) {
            for (CombatGroup combatGroup : combat.getGroups()) {
                if (combatGroup.getAttackers().contains(source.getSourceId())) {
                    creaturesToReturn.addAll(combatGroup.getBlockers());
                } else if (combatGroup.getBlockers().contains(source.getSourceId())) {
                    creaturesToReturn.addAll(combatGroup.getAttackers());
                }
            }
        }
        for (UUID creatureId : creaturesToReturn) {
            Permanent creature = game.getPermanent(creatureId);
            if (creature != null) {
                playersToShuffle.add(creature.getControllerId());
            }
        }
        Cards toLib = new CardsImpl(creaturesToReturn);
        controller.putCardsOnTopOfLibrary(toLib, game, source, false);
        for (UUID playerId : playersToShuffle) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.shuffleLibrary(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Combat(mage.game.combat.Combat) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet)

Example 13 with CombatGroup

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

the class FeintEffect 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) {
        for (CombatGroup combatGroup : game.getCombat().getGroups()) {
            if (combatGroup.getAttackers().contains(creature.getId())) {
                for (UUID blockerId : combatGroup.getBlockers()) {
                    Permanent blocker = game.getPermanent(blockerId);
                    if (blocker != null) {
                        blocker.tap(source, game);
                        PreventionEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn, true);
                        effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
                        game.addEffect(effect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup) PreventionEffect(mage.abilities.effects.PreventionEffect)

Example 14 with CombatGroup

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

the class IbHalfheartGoblinTacticianEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent blockedCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (blockedCreature == null) {
        // it can't be sacrificed, nothing happens
        return true;
    }
    Set<UUID> blockingCreatures = new HashSet<>();
    for (CombatGroup combatGroup : game.getCombat().getGroups()) {
        if (combatGroup.getAttackers().contains(blockedCreature.getId())) {
            blockingCreatures.addAll(combatGroup.getBlockers());
        }
    }
    if (blockedCreature.sacrifice(source, game)) {
        for (UUID blockerId : blockingCreatures) {
            Permanent blockingCreature = game.getPermanent(blockerId);
            if (blockingCreature != null) {
                blockingCreature.damage(4, blockedCreature.getId(), source, game, false, true);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup) HashSet(java.util.HashSet)

Example 15 with CombatGroup

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

the class RandomPlayer method selectBlockers.

@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
    int numGroups = game.getCombat().getGroups().size();
    if (numGroups == 0) {
        return;
    }
    List<Permanent> blockers = getAvailableBlockers(game);
    for (Permanent blocker : blockers) {
        int check = RandomUtil.nextInt(numGroups + 1);
        if (check < numGroups) {
            CombatGroup group = game.getCombat().getGroups().get(check);
            if (!group.getAttackers().isEmpty()) {
                this.declareBlocker(this.getId(), blocker.getId(), group.getAttackers().get(0), game);
            }
        }
    }
    actionCount++;
}
Also used : 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