mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-26 16:30:52 +01:00
Battle Banzai nullpointers and disconnect fix
This commit is contained in:
parent
1b82658bd3
commit
7cbc8cc162
@ -203,8 +203,9 @@ public class BattleBanzaiGame extends Game {
|
||||
item.setExtradata((6 + winningTeam.teamColor.type) + "");
|
||||
this.room.updateItemState(item);
|
||||
}
|
||||
|
||||
Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room));
|
||||
synchronized (this.lockedTiles) {
|
||||
Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room));
|
||||
}
|
||||
}
|
||||
|
||||
super.onEnd();
|
||||
@ -222,7 +223,9 @@ public class BattleBanzaiGame extends Game {
|
||||
this.room.updateItem(tile);
|
||||
}
|
||||
}
|
||||
this.lockedTiles.clear();
|
||||
synchronized (this.lockedTiles) {
|
||||
this.lockedTiles.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -249,52 +252,54 @@ public class BattleBanzaiGame extends Game {
|
||||
}
|
||||
|
||||
public void tileLocked(GameTeamColors teamColor, HabboItem item, Habbo habbo, boolean doNotCheckFill) {
|
||||
if (item instanceof InteractionBattleBanzaiTile) {
|
||||
if (!this.lockedTiles.containsKey(teamColor)) {
|
||||
this.lockedTiles.put(teamColor, new THashSet<>());
|
||||
}
|
||||
|
||||
this.lockedTiles.get(teamColor).add(item);
|
||||
}
|
||||
|
||||
if (habbo != null) {
|
||||
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallTilesLocked"));
|
||||
}
|
||||
|
||||
if (doNotCheckFill) return;
|
||||
|
||||
final int x = item.getX();
|
||||
final int y = item.getY();
|
||||
|
||||
final List<List<RoomTile>> filledAreas = new ArrayList<>();
|
||||
final THashSet<HabboItem> lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor));
|
||||
|
||||
executor.execute(() -> {
|
||||
filledAreas.add(this.floodFill(x, y - 1, lockedTiles, new ArrayList<>(), teamColor));
|
||||
filledAreas.add(this.floodFill(x, y + 1, lockedTiles, new ArrayList<>(), teamColor));
|
||||
filledAreas.add(this.floodFill(x - 1, y, lockedTiles, new ArrayList<>(), teamColor));
|
||||
filledAreas.add(this.floodFill(x + 1, y, lockedTiles, new ArrayList<>(), teamColor));
|
||||
|
||||
Optional<List<RoomTile>> largestAreaOfAll = filledAreas.stream().filter(Objects::nonNull).max(Comparator.comparing(List::size));
|
||||
|
||||
if (largestAreaOfAll.isPresent()) {
|
||||
for (RoomTile tile : largestAreaOfAll.get()) {
|
||||
Optional<HabboItem> tileItem = this.gameTiles.values().stream().filter(i -> i.getX() == tile.x && i.getY() == tile.y && i instanceof InteractionBattleBanzaiTile).findAny();
|
||||
|
||||
tileItem.ifPresent(habboItem -> {
|
||||
this.tileLocked(teamColor, habboItem, habbo, true);
|
||||
|
||||
habboItem.setExtradata((2 + (teamColor.type * 3)) + "");
|
||||
this.room.updateItem(habboItem);
|
||||
});
|
||||
synchronized (this.lockedTiles) {
|
||||
if (item instanceof InteractionBattleBanzaiTile) {
|
||||
if (!this.lockedTiles.containsKey(teamColor)) {
|
||||
this.lockedTiles.put(teamColor, new THashSet<>());
|
||||
}
|
||||
|
||||
this.refreshCounters(teamColor);
|
||||
if (habbo != null) {
|
||||
habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size());
|
||||
}
|
||||
this.lockedTiles.get(teamColor).add(item);
|
||||
}
|
||||
});
|
||||
|
||||
if (habbo != null) {
|
||||
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallTilesLocked"));
|
||||
}
|
||||
|
||||
if (doNotCheckFill) return;
|
||||
|
||||
final int x = item.getX();
|
||||
final int y = item.getY();
|
||||
|
||||
final List<List<RoomTile>> filledAreas = new ArrayList<>();
|
||||
final THashSet<HabboItem> lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor));
|
||||
|
||||
executor.execute(() -> {
|
||||
filledAreas.add(this.floodFill(x, y - 1, lockedTiles, new ArrayList<>(), teamColor));
|
||||
filledAreas.add(this.floodFill(x, y + 1, lockedTiles, new ArrayList<>(), teamColor));
|
||||
filledAreas.add(this.floodFill(x - 1, y, lockedTiles, new ArrayList<>(), teamColor));
|
||||
filledAreas.add(this.floodFill(x + 1, y, lockedTiles, new ArrayList<>(), teamColor));
|
||||
|
||||
Optional<List<RoomTile>> largestAreaOfAll = filledAreas.stream().filter(Objects::nonNull).max(Comparator.comparing(List::size));
|
||||
|
||||
if (largestAreaOfAll.isPresent()) {
|
||||
for (RoomTile tile : largestAreaOfAll.get()) {
|
||||
Optional<HabboItem> tileItem = this.gameTiles.values().stream().filter(i -> i.getX() == tile.x && i.getY() == tile.y && i instanceof InteractionBattleBanzaiTile).findAny();
|
||||
|
||||
tileItem.ifPresent(habboItem -> {
|
||||
this.tileLocked(teamColor, habboItem, habbo, true);
|
||||
|
||||
habboItem.setExtradata((2 + (teamColor.type * 3)) + "");
|
||||
this.room.updateItem(habboItem);
|
||||
});
|
||||
}
|
||||
|
||||
this.refreshCounters(teamColor);
|
||||
if (habbo != null) {
|
||||
habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private List<RoomTile> floodFill(int x, int y, THashSet<HabboItem> lockedTiles, List<RoomTile> stack, GameTeamColors color) {
|
||||
|
@ -110,15 +110,23 @@ public class InteractionWiredHighscore extends HabboItem {
|
||||
serverMessage.appendInt(this.clearType.type);
|
||||
|
||||
if (this.data != null) {
|
||||
serverMessage.appendInt(this.data.size());
|
||||
int size = this.data.size();
|
||||
if(size > 50) {
|
||||
size = 50;
|
||||
}
|
||||
serverMessage.appendInt(size);
|
||||
|
||||
int count = 0;
|
||||
for (WiredHighscoreRow row : this.data) {
|
||||
serverMessage.appendInt(row.getValue());
|
||||
if(count < 50) {
|
||||
serverMessage.appendInt(row.getValue());
|
||||
|
||||
serverMessage.appendInt(row.getUsers().size());
|
||||
for (String username : row.getUsers()) {
|
||||
serverMessage.appendString(username);
|
||||
serverMessage.appendInt(row.getUsers().size());
|
||||
for (String username : row.getUsers()) {
|
||||
serverMessage.appendString(username);
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
} else {
|
||||
serverMessage.appendInt(0);
|
||||
|
@ -52,15 +52,19 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
|
||||
if (game == null)
|
||||
return false;
|
||||
|
||||
TObjectIntIterator<Map.Entry<Integer, Integer>> iterator = this.data.iterator();
|
||||
int gameStartTime = game.getStartTime();
|
||||
|
||||
for (int i = this.data.size(); i-- > 0; ) {
|
||||
TObjectIntMap<Map.Entry<Integer, Integer>> dataClone = new TObjectIntHashMap<>(this.data);
|
||||
|
||||
TObjectIntIterator<Map.Entry<Integer, Integer>> iterator = dataClone.iterator();
|
||||
|
||||
for (int i = dataClone.size(); i-- > 0; ) {
|
||||
iterator.advance();
|
||||
|
||||
Map.Entry<Integer, Integer> map = iterator.key();
|
||||
|
||||
if (map.getValue() == habbo.getHabboInfo().getId()) {
|
||||
if (map.getKey() == game.getStartTime()) {
|
||||
if (map.getKey() == gameStartTime) {
|
||||
if (iterator.value() < this.count) {
|
||||
iterator.setValue(iterator.value() + 1);
|
||||
|
||||
@ -74,7 +78,13 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
|
||||
}
|
||||
}
|
||||
|
||||
this.data.put(new AbstractMap.SimpleEntry<>(game.getStartTime(), habbo.getHabboInfo().getId()), 1);
|
||||
try {
|
||||
this.data.put(new AbstractMap.SimpleEntry<>(gameStartTime, habbo.getHabboInfo().getId()), 1);
|
||||
}
|
||||
catch(IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (habbo.getHabboInfo().getGamePlayer() != null) {
|
||||
habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
|
||||
|
Loading…
Reference in New Issue
Block a user