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) + "");
|
item.setExtradata((6 + winningTeam.teamColor.type) + "");
|
||||||
this.room.updateItemState(item);
|
this.room.updateItemState(item);
|
||||||
}
|
}
|
||||||
|
synchronized (this.lockedTiles) {
|
||||||
Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room));
|
Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onEnd();
|
super.onEnd();
|
||||||
@ -222,7 +223,9 @@ public class BattleBanzaiGame extends Game {
|
|||||||
this.room.updateItem(tile);
|
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) {
|
public void tileLocked(GameTeamColors teamColor, HabboItem item, Habbo habbo, boolean doNotCheckFill) {
|
||||||
if (item instanceof InteractionBattleBanzaiTile) {
|
synchronized (this.lockedTiles) {
|
||||||
if (!this.lockedTiles.containsKey(teamColor)) {
|
if (item instanceof InteractionBattleBanzaiTile) {
|
||||||
this.lockedTiles.put(teamColor, new THashSet<>());
|
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.refreshCounters(teamColor);
|
this.lockedTiles.get(teamColor).add(item);
|
||||||
if (habbo != null) {
|
|
||||||
habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
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) {
|
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);
|
serverMessage.appendInt(this.clearType.type);
|
||||||
|
|
||||||
if (this.data != null) {
|
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) {
|
for (WiredHighscoreRow row : this.data) {
|
||||||
serverMessage.appendInt(row.getValue());
|
if(count < 50) {
|
||||||
|
serverMessage.appendInt(row.getValue());
|
||||||
|
|
||||||
serverMessage.appendInt(row.getUsers().size());
|
serverMessage.appendInt(row.getUsers().size());
|
||||||
for (String username : row.getUsers()) {
|
for (String username : row.getUsers()) {
|
||||||
serverMessage.appendString(username);
|
serverMessage.appendString(username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
serverMessage.appendInt(0);
|
serverMessage.appendInt(0);
|
||||||
|
@ -52,15 +52,19 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
|
|||||||
if (game == null)
|
if (game == null)
|
||||||
return false;
|
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();
|
iterator.advance();
|
||||||
|
|
||||||
Map.Entry<Integer, Integer> map = iterator.key();
|
Map.Entry<Integer, Integer> map = iterator.key();
|
||||||
|
|
||||||
if (map.getValue() == habbo.getHabboInfo().getId()) {
|
if (map.getValue() == habbo.getHabboInfo().getId()) {
|
||||||
if (map.getKey() == game.getStartTime()) {
|
if (map.getKey() == gameStartTime) {
|
||||||
if (iterator.value() < this.count) {
|
if (iterator.value() < this.count) {
|
||||||
iterator.setValue(iterator.value() + 1);
|
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) {
|
if (habbo.getHabboInfo().getGamePlayer() != null) {
|
||||||
habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
|
habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user