aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-04-09 23:55:05 +0200
committerPacien TRAN-GIRARD2016-04-09 23:55:05 +0200
commit67959ff058abc5fa0f943b031c6a1369c0f3a5c7 (patch)
treea3a5a5c861e2ae6453bd4c49d34ed93cc71518c7
parentb91369a41a605c5b941479c43aa6fc1221e78067 (diff)
downloadxblast-67959ff058abc5fa0f943b031c6a1369c0f3a5c7.tar.gz
Fix bomb dropping after max reached
-rw-r--r--src/ch/epfl/xblast/server/GameState.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/server/GameState.java b/src/ch/epfl/xblast/server/GameState.java
index 8a9d5a9..3d14bd0 100644
--- a/src/ch/epfl/xblast/server/GameState.java
+++ b/src/ch/epfl/xblast/server/GameState.java
@@ -81,6 +81,16 @@ public final class GameState {
81 } 81 }
82 82
83 /** 83 /**
84 * Maps bombs to their owning player ID.
85 *
86 * @param b the list of bombs
87 * @return the mapping
88 */
89 private static Map<PlayerID, List<Bomb>> mapBombsToPlayers(List<Bomb> b) {
90 return b.stream().collect(Collectors.groupingBy(Bomb::ownerId));
91 }
92
93 /**
84 * Returns a set of cells that contains at least one blast in the given blasts sequences. 94 * Returns a set of cells that contains at least one blast in the given blasts sequences.
85 * 95 *
86 * @param blasts the list of blast sequences 96 * @param blasts the list of blast sequences
@@ -357,12 +367,16 @@ public final class GameState {
357 */ 367 */
358 private static List<Bomb> newlyDroppedBombs(List<Player> players0, Set<PlayerID> bombDropEvents, List<Bomb> bombs0) { 368 private static List<Bomb> newlyDroppedBombs(List<Player> players0, Set<PlayerID> bombDropEvents, List<Bomb> bombs0) {
359 HashSet<Cell> bombedCells = new HashSet<>(GameState.bombedCells(bombs0).keySet()); 369 HashSet<Cell> bombedCells = new HashSet<>(GameState.bombedCells(bombs0).keySet());
370 Map<PlayerID, List<Bomb>> bombOwnerMap = GameState.mapBombsToPlayers(bombs0);
360 List<Bomb> bombs1 = new ArrayList<>(bombs0); 371 List<Bomb> bombs1 = new ArrayList<>(bombs0);
361 372
362 for (Player p : GameState.alivePlayers(players0)) { 373 for (Player p : GameState.alivePlayers(players0)) {
363 if (!bombDropEvents.contains(p.id())) continue; 374 if (!bombDropEvents.contains(p.id())) continue;
364 if (bombedCells.contains(p.position().containingCell())) continue; 375 if (bombedCells.contains(p.position().containingCell())) continue;
365 376
377 List<Bomb> ownedBombs = bombOwnerMap.get(p.id());
378 if (ownedBombs != null && ownedBombs.size() >= p.maxBombs()) continue;
379
366 Bomb b = new Bomb(p.id(), p.position().containingCell(), Ticks.BOMB_FUSE_TICKS, p.bombRange()); 380 Bomb b = new Bomb(p.id(), p.position().containingCell(), Ticks.BOMB_FUSE_TICKS, p.bombRange());
367 bombedCells.add(b.position()); 381 bombedCells.add(b.position());
368 bombs1.add(b); 382 bombs1.add(b);