Combat.getAttackers and Combat.getBlockers now return a Set instead of a List, so that two-headed blockers aren't included twice

This commit is contained in:
Alex W. Jackson 2022-09-07 22:36:05 -04:00
parent efaccf8564
commit a6c5209a2a
20 changed files with 192 additions and 354 deletions

View file

@ -115,16 +115,16 @@ public class Combat implements Serializable, Copyable<Combat> {
return defenders;
}
public List<UUID> getAttackers() {
List<UUID> attackers = new ArrayList<>();
public Set<UUID> getAttackers() {
Set<UUID> attackers = new HashSet<>();
for (CombatGroup group : groups) {
attackers.addAll(group.attackers);
}
return attackers;
}
public List<UUID> getBlockers() {
List<UUID> blockers = new ArrayList<>();
public Set<UUID> getBlockers() {
Set<UUID> blockers = new HashSet<>();
for (CombatGroup group : groups) {
blockers.addAll(group.blockers);
}
@ -1160,14 +1160,13 @@ public class Combat implements Serializable, Copyable<Combat> {
Set<UUID> blockedSet = mustBeBlockedByAtLeastX.get(blockedAttackerId);
Set<UUID> toBlockSet = mustBeBlockedByAtLeastX.get(toBeBlockedCreatureId);
if (toBlockSet == null) {
// This should never happen.
// This should never happen.
return null;
} else if (toBlockSet.containsAll(blockedSet)) {
// the creature already blocks alone a creature that has to be blocked by at least one
// and has more possible blockers, so this is ok
// the creature already blocks alone a creature that has to be blocked by at least one
// and has more possible blockers, so this is ok
return null;
}
}
// TODO: Check if the attacker is already blocked by another creature
// and despite there is need that this attacker blocks this attacker also