* Combat - Creatures forced to attack can no longer be removed from attack by using the undo button (e.g. Bident of Thassa).

This commit is contained in:
LevelX2 2014-06-20 14:19:03 +02:00
parent e51213a72a
commit 7d2b1c076a
10 changed files with 24 additions and 20 deletions

View file

@ -971,7 +971,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements Player {
List<Permanent> killers = CombatUtil.canKillOpponent(game, attackersList, possibleBlockers, defender); List<Permanent> killers = CombatUtil.canKillOpponent(game, attackersList, possibleBlockers, defender);
if (!killers.isEmpty()) { if (!killers.isEmpty()) {
for (Permanent attacker : killers) { for (Permanent attacker : killers) {
attackingPlayer.declareAttacker(attacker.getId(), defenderId, game); attackingPlayer.declareAttacker(attacker.getId(), defenderId, game, false);
} }
return; return;
} }
@ -1133,7 +1133,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements Player {
safeToAttack = false; safeToAttack = false;
} }
if (safeToAttack) { if (safeToAttack) {
attackingPlayer.declareAttacker(attacker.getId(), defenderId, game); attackingPlayer.declareAttacker(attacker.getId(), defenderId, game, false);
} }
} }
} }
@ -1240,7 +1240,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements Player {
UUID defenderId = game.getOpponents(playerId).iterator().next(); UUID defenderId = game.getOpponents(playerId).iterator().next();
for (CombatGroup group : engagement.getGroups()) { for (CombatGroup group : engagement.getGroups()) {
for (UUID attackerId : group.getAttackers()) { for (UUID attackerId : group.getAttackers()) {
sim.getPlayer(activePlayerId).declareAttacker(attackerId, defenderId, sim); sim.getPlayer(activePlayerId).declareAttacker(attackerId, defenderId, sim, false);
} }
} }
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId)); sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));

View file

@ -1254,12 +1254,12 @@ public class ComputerPlayer extends PlayerImpl implements Player {
CombatSimulator combat = simulateAttack(attackers, blockers, opponentId, game); CombatSimulator combat = simulateAttack(attackers, blockers, opponentId, game);
if (combat.rating > 2) { if (combat.rating > 2) {
for (CombatGroupSimulator group: combat.groups) { for (CombatGroupSimulator group: combat.groups) {
this.declareAttacker(group.attackers.get(0).id, group.defenderId, game); this.declareAttacker(group.attackers.get(0).id, group.defenderId, game, false);
} }
} }
} }
for (Permanent attacker: actualAttackers) { for (Permanent attacker: actualAttackers) {
this.declareAttacker(attacker.getId(), opponentId, game); this.declareAttacker(attacker.getId(), opponentId, game, false);
} }
} }

View file

@ -201,7 +201,7 @@ public class ComputerPlayerMCTS extends ComputerPlayer implements Player {
Combat combat = root.getCombat(); Combat combat = root.getCombat();
UUID opponentId = game.getCombat().getDefenders().iterator().next(); UUID opponentId = game.getCombat().getDefenders().iterator().next();
for (UUID attackerId: combat.getAttackers()) { for (UUID attackerId: combat.getAttackers()) {
this.declareAttacker(attackerId, opponentId, game); this.declareAttacker(attackerId, opponentId, game, false);
} }
} }

View file

@ -159,7 +159,7 @@ public class MCTSNode {
Game sim = game.copy(); Game sim = game.copy();
MCTSPlayer simPlayer = (MCTSPlayer) sim.getPlayer(player.getId()); MCTSPlayer simPlayer = (MCTSPlayer) sim.getPlayer(player.getId());
for (UUID attackerId: attack) { for (UUID attackerId: attack) {
simPlayer.declareAttacker(attackerId, defenderId, sim); simPlayer.declareAttacker(attackerId, defenderId, sim, false);
} }
sim.resume(); sim.resume();
children.add(new MCTSNode(this, sim, sim.getCombat())); children.add(new MCTSNode(this, sim, sim.getCombat()));

View file

@ -602,7 +602,7 @@ public class ComputerPlayer2 extends ComputerPlayer implements Player {
UUID defenderId = game.getOpponents(playerId).iterator().next(); UUID defenderId = game.getOpponents(playerId).iterator().next();
for (CombatGroup group: engagement.getGroups()) { for (CombatGroup group: engagement.getGroups()) {
for (UUID attackerId: group.getAttackers()) { for (UUID attackerId: group.getAttackers()) {
sim.getPlayer(activePlayerId).declareAttacker(attackerId, defenderId, sim); sim.getPlayer(activePlayerId).declareAttacker(attackerId, defenderId, sim, false);
} }
} }
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId)); sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
@ -651,16 +651,18 @@ public class ComputerPlayer2 extends ComputerPlayer implements Player {
@Override @Override
public void selectAttackers(Game game, UUID attackingPlayerId) { public void selectAttackers(Game game, UUID attackingPlayerId) {
if (logger.isDebugEnabled() && (combat == null || combat.getGroups().isEmpty())) if (logger.isDebugEnabled() && (combat == null || combat.getGroups().isEmpty())) {
logger.debug("not attacking"); logger.debug("not attacking");
}
if (combat != null) { if (combat != null) {
UUID opponentId = game.getCombat().getDefenders().iterator().next(); UUID opponentId = game.getCombat().getDefenders().iterator().next();
for (UUID attackerId: combat.getAttackers()) { for (UUID attackerId: combat.getAttackers()) {
this.declareAttacker(attackerId, opponentId, game); this.declareAttacker(attackerId, opponentId, game, false);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
Permanent p = game.getPermanent(attackerId); Permanent p = game.getPermanent(attackerId);
if (p != null) if (p != null) {
logger.debug("attacking with:" + p.getName()); logger.debug("attacking with:" + p.getName());
}
} }
} }
} }

View file

@ -319,7 +319,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
UUID defenderId = game.getOpponents(attackerId).iterator().next(); UUID defenderId = game.getOpponents(attackerId).iterator().next();
for (CombatGroup group: engagement.getGroups()) { for (CombatGroup group: engagement.getGroups()) {
for (UUID attackId: group.getAttackers()) { for (UUID attackId: group.getAttackers()) {
sim.getPlayer(attackerId).declareAttacker(attackId, defenderId, sim); sim.getPlayer(attackerId).declareAttacker(attackId, defenderId, sim, false);
} }
} }
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId)); sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId));

View file

@ -668,7 +668,7 @@ public class HumanPlayer extends PlayerImpl {
possibleDefender = defenders; possibleDefender = defenders;
} }
if (possibleDefender.size() == 1) { if (possibleDefender.size() == 1) {
declareAttacker(attackerId, defenders.iterator().next(), game); declareAttacker(attackerId, defenders.iterator().next(), game, true);
return true; return true;
} }
else { else {
@ -683,7 +683,7 @@ public class HumanPlayer extends PlayerImpl {
} }
} }
if (chooseTarget(Outcome.Damage, target, null, game)) { if (chooseTarget(Outcome.Damage, target, null, game)) {
declareAttacker(attackerId, response.getUUID(), game); declareAttacker(attackerId, response.getUUID(), game, true);
return true; return true;
} }
} }

View file

@ -232,16 +232,16 @@ public class Combat implements Serializable, Copyable<Combat> {
creaturesForcedToAttack.put(creature.getId(), defendersForcedToAttack); creaturesForcedToAttack.put(creature.getId(), defendersForcedToAttack);
if (defendersForcedToAttack.isEmpty()) { if (defendersForcedToAttack.isEmpty()) {
if (defenders.size() == 1) { if (defenders.size() == 1) {
player.declareAttacker(creature.getId(), defenders.iterator().next(), game); player.declareAttacker(creature.getId(), defenders.iterator().next(), game, false);
} else { } else {
TargetDefender target = new TargetDefender(defenders, creature.getId()); TargetDefender target = new TargetDefender(defenders, creature.getId());
target.setRequired(true); target.setRequired(true);
if (player.chooseTarget(Outcome.Damage, target, null, game)) { if (player.chooseTarget(Outcome.Damage, target, null, game)) {
player.declareAttacker(creature.getId(), target.getFirstTarget(), game); player.declareAttacker(creature.getId(), target.getFirstTarget(), game, false);
} }
} }
} else { } else {
player.declareAttacker(creature.getId(), defendersForcedToAttack.iterator().next(), game); player.declareAttacker(creature.getId(), defendersForcedToAttack.iterator().next(), game, false);
} }
} }

View file

@ -325,7 +325,7 @@ public interface Player extends MageItem, Copyable<Player> {
void construct(Tournament tournament, Deck deck); void construct(Tournament tournament, Deck deck);
void pickCard(List<Card> cards, Deck deck, Draft draft); void pickCard(List<Card> cards, Deck deck, Draft draft);
void declareAttacker(UUID attackerId, UUID defenderId, Game game); void declareAttacker(UUID attackerId, UUID defenderId, Game game, boolean allowUndo);
void declareBlocker(UUID defenderId, UUID blockerId, UUID attackerId, Game game); void declareBlocker(UUID defenderId, UUID blockerId, UUID attackerId, Game game);
List<Permanent> getAvailableAttackers(Game game); List<Permanent> getAvailableAttackers(Game game);
List<Permanent> getAvailableBlockers(Game game); List<Permanent> getAvailableBlockers(Game game);

View file

@ -1650,8 +1650,10 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
@Override @Override
public void declareAttacker(UUID attackerId, UUID defenderId, Game game) { public void declareAttacker(UUID attackerId, UUID defenderId, Game game, boolean allowUndo) {
setStoredBookmark(game.bookmarkState()); // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda if (allowUndo) {
setStoredBookmark(game.bookmarkState()); // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda
}
Permanent attacker = game.getPermanent(attackerId); Permanent attacker = game.getPermanent(attackerId);
if (attacker != null && attacker.canAttack(game) && attacker.getControllerId().equals(playerId)) { if (attacker != null && attacker.canAttack(game) && attacker.getControllerId().equals(playerId)) {
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKER, defenderId, attackerId, playerId))) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKER, defenderId, attackerId, playerId))) {