Fixed that in multiplayer games attacked players could block attacking creatures that attacked other players.

This commit is contained in:
LevelX2 2013-08-05 15:32:26 +02:00
parent ab0e0a7735
commit 56dbd4b284
2 changed files with 10 additions and 4 deletions

View file

@ -404,7 +404,7 @@ public class Combat implements Serializable, Copyable<Combat> {
return;
}
Permanent defender = game.getPermanent(defenderId);
CombatGroup newGroup = new CombatGroup(defenderId, defender != null);
CombatGroup newGroup = new CombatGroup(defenderId, defender != null, defender != null ? defender.getControllerId(): defenderId);
newGroup.attackers.add(attackerId);
Permanent attacker = game.getPermanent(attackerId);
if (!attacker.getAbilities().containsKey(VigilanceAbility.getInstance().getId())) {
@ -419,7 +419,7 @@ public class Combat implements Serializable, Copyable<Combat> {
Permanent blocker = game.getPermanent(blockerId);
if (blockerId != null && blocker != null && blocker.getBlocking() > 1) {
if (!blockingGroups.containsKey(blockerId)) {
CombatGroup newGroup = new CombatGroup(playerId, playerId != null);
CombatGroup newGroup = new CombatGroup(playerId, false, playerId);
newGroup.blockers.add(blockerId);
// add all blocked attackers
for (CombatGroup group : groups) {

View file

@ -52,12 +52,14 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
protected List<UUID> attackerOrder = new ArrayList<UUID>();
protected Map<UUID, UUID> players = new HashMap<UUID, UUID>();
protected boolean blocked;
protected UUID defenderId;
protected UUID defenderId; // planeswalker or player
protected UUID defendingPlayerId;
protected boolean defenderIsPlaneswalker;
public CombatGroup(UUID defenderId, boolean defenderIsPlaneswalker) {
public CombatGroup(UUID defenderId, boolean defenderIsPlaneswalker, UUID defendingPlayerId) {
this.defenderId = defenderId;
this.defenderIsPlaneswalker = defenderIsPlaneswalker;
this.defendingPlayerId = defendingPlayerId;
}
public CombatGroup(final CombatGroup group) {
@ -379,6 +381,10 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
}
public boolean canBlock(Permanent blocker, Game game) {
// you can't block if combat group attacks another player
if (!defendingPlayerId.equals(blocker.getControllerId()) ) {
return false;
}
for (UUID attackerId: attackers) {
if (!blocker.canBlock(attackerId, game)) {
return false;