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();
}
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();
}
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.");
}
}
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;
}
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;
}
Aggregations