Search in sources :

Example 21 with CombatGroup

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

the class GameState method getValue.

public String getValue(boolean useHidden, Game game) {
    StringBuilder sb = threadLocalBuilder.get();
    sb.append(turn.getValue(turnNum));
    sb.append(activePlayerId).append(priorityPlayerId).append(playerByOrderId);
    for (Player player : players.values()) {
        sb.append("player").append(player.isPassed()).append(player.getLife()).append("hand");
        if (useHidden) {
            sb.append(player.getHand().getValue(game));
        } else {
            sb.append(player.getHand().size());
        }
        sb.append("library").append(player.getLibrary().size());
        sb.append("graveyard");
        sb.append(player.getGraveyard().getValue(game));
    }
    sb.append("permanents");
    List<String> perms = new ArrayList<>();
    for (Permanent permanent : battlefield.getAllPermanents()) {
        perms.add(permanent.getValue(this));
    }
    Collections.sort(perms);
    sb.append(perms);
    sb.append("spells");
    for (StackObject spell : stack) {
        sb.append(spell.getControllerId()).append(spell.getName());
        sb.append(spell.getStackAbility().toString());
        for (UUID modeId : spell.getStackAbility().getModes().getSelectedModes()) {
            Mode mode = spell.getStackAbility().getModes().get(modeId);
            if (!mode.getTargets().isEmpty()) {
                sb.append("targets");
                for (Target target : mode.getTargets()) {
                    sb.append(target.getTargets());
                }
            }
        }
    }
    for (ExileZone zone : exile.getExileZones()) {
        sb.append("exile").append(zone.getName()).append(zone.getValue(game));
    }
    sb.append("combat");
    for (CombatGroup group : combat.getGroups()) {
        sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers());
    }
    return sb.toString();
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ThreadLocalStringBuilder(mage.util.ThreadLocalStringBuilder) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) CombatGroup(mage.game.combat.CombatGroup)

Example 22 with CombatGroup

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

the class GameState method getValue.

public String getValue(boolean useHidden) {
    StringBuilder sb = threadLocalBuilder.get();
    sb.append(turn.getValue(turnNum));
    sb.append(activePlayerId).append(priorityPlayerId).append(playerByOrderId);
    for (Player player : players.values()) {
        sb.append("player").append(player.getLife()).append("hand");
        if (useHidden) {
            sb.append(player.getHand());
        } else {
            sb.append(player.getHand().size());
        }
        sb.append("library").append(player.getLibrary().size()).append("graveyard").append(player.getGraveyard());
    }
    sb.append("permanents");
    for (Permanent permanent : battlefield.getAllPermanents()) {
        sb.append(permanent.getValue(this));
    }
    sb.append("spells");
    for (StackObject spell : stack) {
        sb.append(spell.getControllerId()).append(spell.getName());
    }
    for (ExileZone zone : exile.getExileZones()) {
        sb.append("exile").append(zone.getName()).append(zone);
    }
    sb.append("combat");
    for (CombatGroup group : combat.getGroups()) {
        sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers());
    }
    return sb.toString();
}
Also used : Player(mage.players.Player) ThreadLocalStringBuilder(mage.util.ThreadLocalStringBuilder) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) CombatGroup(mage.game.combat.CombatGroup)

Example 23 with CombatGroup

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

the class PlayerImpl method declareBlocker.

@Override
public void declareBlocker(UUID defenderId, UUID blockerId, UUID attackerId, Game game, boolean allowUndo) {
    if (isHuman() && allowUndo) {
        setStoredBookmark(game.bookmarkState());
    }
    Permanent blocker = game.getPermanent(blockerId);
    CombatGroup group = game.getCombat().findGroup(attackerId);
    if (blocker != null && group != null && group.canBlock(blocker, game)) {
        group.addBlocker(blockerId, playerId, game);
        game.getCombat().addBlockingGroup(blockerId, attackerId, playerId, game);
    } else if (this.isHuman() && !game.isSimulation()) {
        game.informPlayer(this, "You can't block this creature.");
    }
}
Also used : Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetPermanent(mage.target.TargetPermanent) CombatGroup(mage.game.combat.CombatGroup)

Example 24 with CombatGroup

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

the class RagingRiverEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> left = new ArrayList<>();
        List<Permanent> right = new ArrayList<>();
        for (UUID defenderId : game.getCombat().getPlayerDefenders(game)) {
            Player defender = game.getPlayer(defenderId);
            if (defender != null) {
                List<Permanent> leftLog = new ArrayList<>();
                List<Permanent> rightLog = new ArrayList<>();
                FilterControlledCreaturePermanent filterBlockers = new FilterControlledCreaturePermanent("creatures without flying you control to assign to the \"left\" pile (creatures not chosen will be assigned to the \"right\" pile)");
                filterBlockers.add(Predicates.not(new AbilityPredicate(FlyingAbility.class)));
                Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filterBlockers, true);
                if (target.canChoose(source.getSourceId(), defenderId, game)) {
                    if (defender.chooseTarget(Outcome.Neutral, target, source, game)) {
                        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), defenderId, game)) {
                            if (target.getTargets().contains(permanent.getId())) {
                                left.add(permanent);
                                leftLog.add(permanent);
                            } else if (filterBlockers.match(permanent, source.getSourceId(), defenderId, game)) {
                                right.add(permanent);
                                rightLog.add(permanent);
                            }
                        }
                    }
                    // it could be nice to invoke some graphic indicator of which creature is Left or Right in this spot
                    StringBuilder sb = new StringBuilder("Left pile of ").append(defender.getLogName()).append(": ");
                    sb.append(leftLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                    sb = new StringBuilder("Right pile of ").append(defender.getLogName()).append(": ");
                    sb.append(rightLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                }
            }
        }
        for (UUID attackers : game.getCombat().getAttackers()) {
            Permanent attacker = game.getPermanent(attackers);
            if (attacker != null && Objects.equals(attacker.getControllerId(), controller.getId())) {
                CombatGroup combatGroup = game.getCombat().findGroup(attacker.getId());
                if (combatGroup != null) {
                    FilterCreaturePermanent filter = new FilterCreaturePermanent();
                    Player defender = game.getPlayer(combatGroup.getDefendingPlayerId());
                    if (defender != null) {
                        if (left.isEmpty() && right.isEmpty()) {
                            // shortcut in case of no labeled blockers available
                            filter.add(Predicates.not(new AbilityPredicate(FlyingAbility.class)));
                        } else {
                            List<Permanent> leftLog = left.stream().filter(permanent -> permanent.getControllerId() != null).filter(permanent -> permanent.isControlledBy(defender.getId())).collect(Collectors.toList());
                            List<Permanent> rightLog = right.stream().filter(permanent -> permanent.getControllerId() != null).filter(permanent -> permanent.isControlledBy(defender.getId())).collect(Collectors.toList());
                            if (controller.choosePile(outcome, attacker.getName() + ": attacking " + defender.getName(), leftLog, rightLog, game)) {
                                filter.add(Predicates.not(Predicates.or(new AbilityPredicate(FlyingAbility.class), new PermanentInListPredicate(left))));
                                game.informPlayers(attacker.getLogName() + ": attacks left (" + defender.getLogName() + ")");
                            } else {
                                filter.add(Predicates.not(Predicates.or(new AbilityPredicate(FlyingAbility.class), new PermanentInListPredicate(right))));
                                game.informPlayers(attacker.getLogName() + ": attacks right (" + defender.getLogName() + ")");
                            }
                        }
                        RestrictionEffect effect = new CantBeBlockedByAllTargetEffect(filter, Duration.EndOfCombat);
                        effect.setTargetPointer(new FixedTarget(attacker.getId(), game));
                        game.addEffect(effect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Target(mage.target.Target) RestrictionEffect(mage.abilities.effects.RestrictionEffect) CantBeBlockedByAllTargetEffect(mage.abilities.effects.common.combat.CantBeBlockedByAllTargetEffect) Predicates(mage.filter.predicate.Predicates) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) ArrayList(java.util.ArrayList) AttacksWithCreaturesTriggeredAbility(mage.abilities.common.AttacksWithCreaturesTriggeredAbility) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CombatGroup(mage.game.combat.CombatGroup) FlyingAbility(mage.abilities.keyword.FlyingAbility) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FlyingAbility(mage.abilities.keyword.FlyingAbility) UUID(java.util.UUID) RestrictionEffect(mage.abilities.effects.RestrictionEffect) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate) CombatGroup(mage.game.combat.CombatGroup) CantBeBlockedByAllTargetEffect(mage.abilities.effects.common.combat.CantBeBlockedByAllTargetEffect)

Example 25 with CombatGroup

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

the class TidalFlatsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Player player = game.getPlayer(game.getActivePlayerId());
    if (player == null) {
        return false;
    }
    Cost cost = new ManaCostsImpl("{1}");
    List<Permanent> affectedPermanents = new ArrayList<>();
    for (Permanent permanent : game.getState().getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
        cost.clearPaid();
        String message = "Pay " + cost.getText() + " for " + permanent.getLogName() + "? If you don't, creatures " + controller.getLogName() + " controls blocking it gain first strike until end of turn.";
        if (player.chooseUse(Outcome.Benefit, message, source, game)) {
            if (cost.pay(source, game, source, player.getId(), false, null)) {
                game.informPlayers(player.getLogName() + " paid " + cost.getText() + " for " + permanent.getLogName());
            } else {
                game.informPlayers(player.getLogName() + " didn't pay " + cost.getText() + " for " + permanent.getLogName());
                affectedPermanents.add(permanent);
            }
        } else {
            game.informPlayers(player.getLogName() + " didn't pay " + cost.getText() + " for " + permanent.getLogName());
            affectedPermanents.add(permanent);
        }
    }
    for (Permanent permanent : affectedPermanents) {
        CombatGroup group = game.getCombat().findGroup(permanent.getId());
        if (group != null) {
            for (UUID blockerId : group.getBlockers()) {
                Permanent blocker = game.getPermanent(blockerId);
                if (blocker != null && Objects.equals(blocker.getControllerId(), controller.getId())) {
                    ContinuousEffect effect = new GainAbilityTargetEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn);
                    effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
                    game.addEffect(effect, source);
                }
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) 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