Game timers fixed

This commit is contained in:
Beny 2019-05-04 21:41:18 +01:00
parent 83fcc87a88
commit a692d2fbf0
9 changed files with 396 additions and 388 deletions

View File

@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.games;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredHighscore; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredHighscore;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob;
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamLoses; import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamLoses;
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamWins; import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamWins;
@ -170,32 +171,7 @@ public abstract class Game implements Runnable
} }
} }
public void onEnd() {
public abstract void run();
public void pause()
{
if (this.state.equals(GameState.RUNNING))
{
this.state = GameState.PAUSED;
this.pauseTime = Emulator.getIntUnixTimestamp();
}
}
public void unpause()
{
if (this.state.equals(GameState.PAUSED))
{
this.state = GameState.RUNNING;
this.endTime = Emulator.getIntUnixTimestamp() + (this.endTime - this.pauseTime);
}
}
public void stop()
{
this.state = GameState.IDLE;
this.endTime = Emulator.getIntUnixTimestamp();
this.saveScores(); this.saveScores();
GameTeam winningTeam = null; GameTeam winningTeam = null;
@ -225,18 +201,55 @@ public abstract class Game implements Runnable
} }
} }
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class))
{
this.room.updateItem(item);
}
}
public abstract void run();
public void pause()
{
if (this.state.equals(GameState.RUNNING))
{
this.state = GameState.PAUSED;
this.pauseTime = Emulator.getIntUnixTimestamp();
}
}
public void unpause()
{
if (this.state.equals(GameState.PAUSED))
{
this.state = GameState.RUNNING;
this.endTime = Emulator.getIntUnixTimestamp() + (this.endTime - this.pauseTime);
}
}
public void stop()
{
this.state = GameState.IDLE;
this.endTime = Emulator.getIntUnixTimestamp();
boolean gamesActive = false;
for(HabboItem timer : room.getFloorItems())
{
if(timer instanceof InteractionGameTimer) {
if(((InteractionGameTimer) timer).isRunning())
gamesActive = true;
}
}
if(gamesActive) {
return;
}
if(Emulator.getPluginManager().isRegistered(GameStoppedEvent.class, true)) if(Emulator.getPluginManager().isRegistered(GameStoppedEvent.class, true))
{ {
Event gameStoppedEvent = new GameStoppedEvent(this); Event gameStoppedEvent = new GameStoppedEvent(this);
Emulator.getPluginManager().fireEvent(gameStoppedEvent); Emulator.getPluginManager().fireEvent(gameStoppedEvent);
} }
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, this.room, new Object[]{this});
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class))
{
this.room.updateItem(item);
}
} }

View File

@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.games.battlebanzai;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.games.*; import com.eu.habbo.habbohotel.games.*;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTimer; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTimer;
@ -13,6 +14,8 @@ import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUserAction; import com.eu.habbo.habbohotel.rooms.RoomUserAction;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserActionComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserActionComposer;
import com.eu.habbo.threading.runnables.BattleBanzaiTilesFlicker; import com.eu.habbo.threading.runnables.BattleBanzaiTilesFlicker;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
@ -35,8 +38,6 @@ public class BattleBanzaiGame extends Game
public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock"); public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock");
private int timeLeft;
private int tileCount; private int tileCount;
private int countDown; private int countDown;
@ -62,22 +63,10 @@ public class BattleBanzaiGame extends Game
if(!this.state.equals(GameState.IDLE)) if(!this.state.equals(GameState.IDLE))
return; return;
int highestTime = 0;
this.countDown = 3; this.countDown = 3;
this.resetMap(); this.resetMap();
for (Map.Entry<Integer, InteractionBattleBanzaiTimer> set : this.room.getRoomSpecialTypes().getBattleBanzaiTimers().entrySet())
{
if(set.getValue().getExtradata().isEmpty())
continue;
if(highestTime < Integer.valueOf(set.getValue().getExtradata()))
{
highestTime = Integer.valueOf(set.getValue().getExtradata());
}
}
synchronized (this.teams) synchronized (this.teams)
{ {
for (GameTeam t : this.teams.values()) for (GameTeam t : this.teams.values())
@ -92,13 +81,6 @@ public class BattleBanzaiGame extends Game
this.room.updateItemState(item); this.room.updateItemState(item);
} }
this.timeLeft = highestTime;
if (this.timeLeft == 0)
{
this.timeLeft = 30;
}
this.start(); this.start();
} }
@ -150,99 +132,50 @@ public class BattleBanzaiGame extends Game
} }
} }
if (this.timeLeft > 0) Emulator.getThreading().run(this, 1000);
if (this.state.equals(GameState.PAUSED)) return;
int total = 0;
synchronized (this.lockedTiles)
{ {
Emulator.getThreading().run(this, 1000); for (Map.Entry<GameTeamColors, THashSet<HabboItem>> set : this.lockedTiles.entrySet())
if (this.state.equals(GameState.PAUSED)) return;
this.timeLeft--;
for (Map.Entry<Integer, InteractionBattleBanzaiTimer> set : this.room.getRoomSpecialTypes().getBattleBanzaiTimers().entrySet())
{ {
set.getValue().setExtradata(this.timeLeft + ""); total += set.getValue().size();
this.room.updateItemState(set.getValue());
}
int total = 0;
synchronized (this.lockedTiles)
{
for (Map.Entry<GameTeamColors, THashSet<HabboItem>> set : this.lockedTiles.entrySet())
{
total += set.getValue().size();
}
}
GameTeam highestScore = null;
synchronized (this.teams)
{
for (Map.Entry<GameTeamColors, GameTeam> set : this.teams.entrySet())
{
if (highestScore == null || highestScore.getTotalScore() < set.getValue().getTotalScore())
{
highestScore = set.getValue();
}
}
}
if(highestScore != null)
{
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class))
{
item.setExtradata((highestScore.teamColor.type + 3) + "");
this.room.updateItemState(item);
}
}
if(total >= this.tileCount && this.tileCount != 0)
{
this.timeLeft = 0;
} }
} }
else
GameTeam highestScore = null;
synchronized (this.teams)
{ {
for (Map.Entry<GameTeamColors, GameTeam> set : this.teams.entrySet())
GameTeam winningTeam = null;
for (GameTeam team : this.teams.values())
{ {
for(GamePlayer player : team.getMembers()) if (highestScore == null || highestScore.getTotalScore() < set.getValue().getTotalScore())
{ {
if (player.getScore() > 0) highestScore = set.getValue();
{
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallPlayer"));
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallQuestCompleted"));
}
}
if (winningTeam == null || team.getTotalScore() > winningTeam.getTotalScore())
{
winningTeam = team;
} }
} }
}
if (winningTeam != null) if(highestScore != null)
{
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class))
{ {
for (GamePlayer player : winningTeam.getMembers()) item.setExtradata((highestScore.teamColor.type + 3) + "");
{ this.room.updateItemState(item);
if (player.getScore() > 0)
{
this.room.sendComposer(new RoomUserActionComposer(player.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose());
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallWinner"));
}
}
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class))
{
item.setExtradata((7 + winningTeam.teamColor.type) + "");
this.room.updateItemState(item);
}
Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room));
} }
}
this.stop();
if(total >= this.tileCount && this.tileCount != 0)
{
for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values())
{
if(timer.isRunning())
timer.setRunning(false);
}
InteractionGameTimer.endGames(room);
} }
} }
catch (Exception e) catch (Exception e)
@ -251,13 +184,55 @@ public class BattleBanzaiGame extends Game
} }
} }
@Override
public void onEnd() {
GameTeam winningTeam = null;
for (GameTeam team : this.teams.values())
{
for(GamePlayer player : team.getMembers())
{
if (player.getScore() > 0)
{
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallPlayer"));
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallQuestCompleted"));
}
}
if (winningTeam == null || team.getTotalScore() > winningTeam.getTotalScore())
{
winningTeam = team;
}
}
if (winningTeam != null)
{
for (GamePlayer player : winningTeam.getMembers())
{
if (player.getScore() > 0)
{
this.room.sendComposer(new RoomUserActionComposer(player.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose());
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallWinner"));
}
}
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class))
{
item.setExtradata((7 + winningTeam.teamColor.type) + "");
this.room.updateItemState(item);
}
Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room));
}
super.onEnd();
}
@Override @Override
public void stop() public void stop()
{ {
super.stop(); super.stop();
this.timeLeft = 0;
this.refreshGates(); this.refreshGates();
for (HabboItem tile : this.gameTiles.values()) for (HabboItem tile : this.gameTiles.values())
@ -265,7 +240,7 @@ public class BattleBanzaiGame extends Game
if (tile.getExtradata().equals("1")) if (tile.getExtradata().equals("1"))
{ {
tile.setExtradata("0"); tile.setExtradata("0");
this.room.updateItemState(tile); this.room.updateItem(tile);
} }
} }
this.lockedTiles.clear(); this.lockedTiles.clear();

View File

@ -45,8 +45,6 @@ public class FreezeGame extends Game
public static int FREEZE_LOOSE_POINTS; public static int FREEZE_LOOSE_POINTS;
public static boolean POWERUP_STACK; public static boolean POWERUP_STACK;
private int timeLeft;
public FreezeGame(Room room) public FreezeGame(Room room)
{ {
super(FreezeGameTeam.class, FreezeGamePlayer.class, room, true); super(FreezeGameTeam.class, FreezeGamePlayer.class, room, true);
@ -59,21 +57,8 @@ public class FreezeGame extends Game
if(this.state == GameState.RUNNING) if(this.state == GameState.RUNNING)
return; return;
int highestTime = 0;
this.resetMap(); this.resetMap();
for (Map.Entry<Integer, InteractionFreezeTimer> set : this.room.getRoomSpecialTypes().getFreezeTimers().entrySet())
{
if(set.getValue().getExtradata().isEmpty())
continue;
if(highestTime < Integer.valueOf(set.getValue().getExtradata()))
{
highestTime = Integer.valueOf(set.getValue().getExtradata());
}
}
for (GameTeam t : this.teams.values()) for (GameTeam t : this.teams.values())
{ {
t.initialise(); t.initialise();
@ -95,12 +80,6 @@ public class FreezeGame extends Game
} }
} }
} }
this.timeLeft = highestTime;
if (this.timeLeft == 0)
{
this.timeLeft = 30;
}
this.start(); this.start();
} }
@ -281,8 +260,7 @@ public class FreezeGame extends Game
super.start(); super.start();
this.refreshGates(); this.refreshGates();
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, this.room, null);
this.setFreezeTileState("1"); this.setFreezeTileState("1");
this.run(); this.run();
} }
@ -295,50 +273,36 @@ public class FreezeGame extends Game
if (this.state.equals(GameState.IDLE)) if (this.state.equals(GameState.IDLE))
return; return;
if (this.timeLeft > 0) Emulator.getThreading().run(this, 1000);
if (this.state.equals(GameState.PAUSED)) return;
for (GameTeam team : this.teams.values())
{ {
Emulator.getThreading().run(this, 1000); for (GamePlayer player : team.getMembers())
if (this.state.equals(GameState.PAUSED)) return;
this.timeLeft--;
for (GameTeam team : this.teams.values())
{ {
for (GamePlayer player : team.getMembers()) ((FreezeGamePlayer)player).cycle();
{
((FreezeGamePlayer)player).cycle();
}
int totalScore = team.getTotalScore();
THashMap<Integer, InteractionFreezeScoreboard> scoreBoards = this.room.getRoomSpecialTypes().getFreezeScoreboards(team.teamColor);
for (InteractionFreezeScoreboard scoreboard : scoreBoards.values())
{
if(scoreboard.getExtradata().isEmpty())
{
scoreboard.setExtradata("0");
}
int oldScore = Integer.valueOf(scoreboard.getExtradata());
if(oldScore == totalScore)
continue;
scoreboard.setExtradata(totalScore + "");
this.room.updateItemState(scoreboard);
}
} }
for (Map.Entry<Integer, InteractionFreezeTimer> set : this.room.getRoomSpecialTypes().getFreezeTimers().entrySet()) int totalScore = team.getTotalScore();
THashMap<Integer, InteractionFreezeScoreboard> scoreBoards = this.room.getRoomSpecialTypes().getFreezeScoreboards(team.teamColor);
for (InteractionFreezeScoreboard scoreboard : scoreBoards.values())
{ {
set.getValue().setExtradata(this.timeLeft + ""); if(scoreboard.getExtradata().isEmpty())
this.room.updateItemState(set.getValue()); {
scoreboard.setExtradata("0");
}
int oldScore = Integer.valueOf(scoreboard.getExtradata());
if(oldScore == totalScore)
continue;
scoreboard.setExtradata(totalScore + "");
this.room.updateItemState(scoreboard);
} }
} else
{
this.stop();
} }
} }
catch (Exception e) catch (Exception e)
@ -352,8 +316,6 @@ public class FreezeGame extends Game
{ {
super.stop(); super.stop();
this.timeLeft = 0;
GameTeam winningTeam = null; GameTeam winningTeam = null;
for(GameTeam team : this.teams.values()) for(GameTeam team : this.teams.values())

View File

@ -14,51 +14,19 @@ import java.util.Map;
public class WiredGame extends Game public class WiredGame extends Game
{ {
private int timeLeft = 30;
public WiredGame(Room room) public WiredGame(Room room)
{ {
super(GameTeam.class, GamePlayer.class, room , false); super(GameTeam.class, GamePlayer.class, room , false);
} }
@Override @Override
public void initialise() public void initialise() {
{
for (Map.Entry<Integer, InteractionGameTimer> set : this.room.getRoomSpecialTypes().getGameTimers().entrySet())
{
if(set.getValue().getExtradata().isEmpty())
continue;
if(this.timeLeft < Integer.valueOf(set.getValue().getExtradata()))
{
this.timeLeft = Integer.valueOf(set.getValue().getExtradata());
}
}
if (this.timeLeft <= 30)
{
this.timeLeft = 30;
}
this.run();
} }
@Override @Override
public void run() public void run() {
{
if (this.timeLeft > 0)
{
Emulator.getThreading().run(this, 1000);
this.timeLeft--;
for (Map.Entry<Integer, InteractionGameTimer> set : this.room.getRoomSpecialTypes().getGameTimers().entrySet())
{
set.getValue().setExtradata(this.timeLeft + "");
this.room.updateItemState(set.getValue());
}
}
else
{
this.stop();
}
} }
@Override @Override

View File

@ -4,6 +4,8 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.GameState; import com.eu.habbo.habbohotel.games.GameState;
import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame;
import com.eu.habbo.habbohotel.games.freeze.FreezeGame;
import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.games.wired.WiredGame;
import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.Permission;
@ -11,15 +13,22 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
public abstract class InteractionGameTimer extends HabboItem public abstract class InteractionGameTimer extends HabboItem implements Runnable
{ {
private int baseTime = 0; private int baseTime = 0;
private int lastToggle = 0; private int timeNow = 0;
private boolean isRunning = false;
private boolean isPaused = false;
public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException
{ {
@ -30,6 +39,7 @@ public abstract class InteractionGameTimer extends HabboItem
if (data.length >= 2) if (data.length >= 2)
{ {
this.baseTime = Integer.valueOf(data[1]); this.baseTime = Integer.valueOf(data[1]);
this.timeNow = this.baseTime;
} }
if (data.length >= 1) if (data.length >= 1)
@ -43,6 +53,54 @@ public abstract class InteractionGameTimer extends HabboItem
super(id, userId, item, extradata, limitedStack, limitedSells); super(id, userId, item, extradata, limitedStack, limitedSells);
} }
@Override
public void run() {
if(this.needsUpdate() || this.needsDelete()) {
super.run();
}
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if(room == null || !this.isRunning || this.isPaused)
return;
if(this.timeNow > 0) {
Emulator.getThreading().run(this, 1000);
this.timeNow--;
room.updateItem(this);
}
else {
this.isRunning = false;
this.isPaused = false;
endGamesIfLastTimer(room);
}
}
public static void endGamesIfLastTimer(Room room) {
boolean gamesActive = false;
for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) {
if (timer.isRunning())
gamesActive = true;
}
if (!gamesActive) {
endGames(room);
}
}
public static void endGames(Room room) {
//end existing games
for (Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = InteractionGameTimer.getOrCreateGame(room, gameClass);
if (!game.state.equals(GameState.IDLE)) {
game.onEnd();
game.stop();
}
}
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[] { });
}
@Override @Override
public void onPickUp(Room room) public void onPickUp(Room room)
{ {
@ -52,8 +110,12 @@ public abstract class InteractionGameTimer extends HabboItem
@Override @Override
public void onPlace(Room room) public void onPlace(Room room)
{ {
this.baseTime = 30; if(this.baseTime == 0) {
this.setExtradata("30"); this.baseTime = 30;
this.timeNow = this.baseTime;
}
this.setExtradata(this.timeNow + "\t" + this.baseTime);
room.updateItem(this); room.updateItem(this);
} }
@ -61,7 +123,7 @@ public abstract class InteractionGameTimer extends HabboItem
public void serializeExtradata(ServerMessage serverMessage) public void serializeExtradata(ServerMessage serverMessage)
{ {
serverMessage.appendInt((this.isLimited() ? 256 : 0)); serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata()); serverMessage.appendString("" + timeNow);
super.serializeExtradata(serverMessage); super.serializeExtradata(serverMessage);
} }
@ -81,65 +143,131 @@ public abstract class InteractionGameTimer extends HabboItem
@Override @Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception public void onClick(GameClient client, Room room, Object[] objects) throws Exception
{ {
if (client != null)
{
if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)))
return;
}
if (client == null)
{
int now = Emulator.getIntUnixTimestamp();
if (now - this.lastToggle < 3) return;
this.lastToggle = now;
}
if(this.getExtradata().isEmpty()) if(this.getExtradata().isEmpty())
{ {
this.setExtradata("0"); this.setExtradata("0");
} }
Game game = this.getOrCreateGame(room); // if wired triggered it
if (objects.length >= 2 && objects[1] instanceof WiredEffectType && !this.isRunning)
if ((objects.length >= 2 && objects[1] instanceof WiredEffectType))
{ {
if (game == null || !game.isRunning) boolean gamesActive = false;
startGame(room); for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values())
else if (game.isRunning) {
stopGame(room); if(timer.isRunning())
gamesActive = true;
}
if(gamesActive) {
//stop existing games
for(Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = getOrCreateGame(room, gameClass);
if(game.isRunning) {
game.stop();
}
}
}
for(Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = getOrCreateGame(room, gameClass);
if(!game.isRunning) {
game.start();
}
}
timeNow = this.baseTime;
this.isRunning = true;
room.updateItem(this);
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[] { });
Emulator.getThreading().run(this);
} }
else if(client != null)
if(objects.length >= 1 && objects[0] instanceof Integer && client != null)
{ {
int state = (Integer)objects[0]; if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)))
return;
int state = 1;
if(objects.length >= 1 && objects[0] instanceof Integer) {
state = (Integer) objects[0];
}
switch (state) switch (state)
{ {
case 1: case 1:
{
this.startGame(room); if(this.isRunning) {
this.isPaused = !this.isPaused;
for(Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = getOrCreateGame(room, gameClass);
if(this.isPaused) {
game.pause();
}
else {
game.unpause();
}
}
if(!this.isPaused) {
Emulator.getThreading().run(this);
}
}
if(!this.isRunning) {
for(Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = getOrCreateGame(room, gameClass);
game.initialise();
}
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[] { });
Emulator.getThreading().run(this);
}
if(!this.isRunning) {
timeNow = this.baseTime;
this.isRunning = true;
room.updateItem(this);
}
break; break;
}
case 2: case 2:
{ if(!this.isRunning) {
this.increaseTimer(room); this.increaseTimer(room);
} return;
break; }
if(this.isPaused) {
this.isPaused = false;
this.isRunning = false;
timeNow = this.baseTime;
room.updateItem(this);
endGamesIfLastTimer(room);
}
break;
case 3: case 3:
{
this.stopGame(room);
}
break;
}
}
else
{
if (game != null && game.state.equals(GameState.IDLE)) this.isPaused = false;
{ this.isRunning = false;
this.startGame(room);
timeNow = this.baseTime;
room.updateItem(this);
boolean gamesActive = false;
for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) {
if (timer.isRunning())
gamesActive = true;
}
if (!gamesActive) {
endGames(room);
}
break;
} }
} }
@ -152,87 +280,30 @@ public abstract class InteractionGameTimer extends HabboItem
} }
private Game getOrCreateGame(Room room) public static Game getOrCreateGame(Room room, Class<? extends Game> gameClass)
{ {
Game game = (this.getGameType().cast(room.getGame(this.getGameType()))); Game game = (gameClass.cast(room.getGame(gameClass)));
if (game == null) if (game == null) {
{ try {
try System.out.println(gameClass.getName());
{ game = gameClass.getDeclaredConstructor(Room.class).newInstance(room);
game = this.getGameType().getDeclaredConstructor(Room.class).newInstance(room);
room.addGame(game); room.addGame(game);
} } catch (Exception e) {
catch (Exception e) Emulator.getLogging().logErrorLine(e);
{
} }
} }
return game; return game;
} }
private void startGame(Room room)
{
this.needsUpdate(true);
try
{
room.updateItem(this);
Game game = this.getOrCreateGame(room);
if (game.state.equals(GameState.IDLE))
{
this.setExtradata(this.baseTime + "");
game.initialise();
}
else if (game.state.equals(GameState.PAUSED))
{
game.unpause();
}
else if (game.state.equals(GameState.RUNNING))
{
game.pause();
}
//}
}
catch (Exception e)
{
Emulator.getLogging().logErrorLine(e);
}
}
private void stopGame(Room room)
{
this.setExtradata(this.baseTime + "");
this.needsUpdate(true);
Game game = this.getOrCreateGame(room);
if(game != null && game.state != GameState.IDLE)
{
this.setExtradata(this.baseTime + "");
game.stop();
stopGame(room);
}
room.updateItem(this);
}
private void increaseTimer(Room room) private void increaseTimer(Room room)
{ {
Game game = this.getOrCreateGame(room); if(this.isRunning)
if (game == null) return;
if (game.state.equals(GameState.PAUSED))
{
stopGame(room);
return; return;
}
if (game.state.equals(GameState.RUNNING)) return;
this.needsUpdate(true); this.needsUpdate(true);
switch(this.baseTime) switch(this.baseTime)
{ {
case 0: this.baseTime = 30; break; case 0: this.baseTime = 30; break;
@ -247,9 +318,9 @@ public abstract class InteractionGameTimer extends HabboItem
this.baseTime = 30; this.baseTime = 30;
} }
this.setExtradata(this.baseTime + ""); this.timeNow = this.baseTime;
room.updateItem(this); room.updateItem(this);
this.needsUpdate(true);
} }
@Override @Override
@ -265,4 +336,20 @@ public abstract class InteractionGameTimer extends HabboItem
{ {
return true; return true;
} }
public boolean isRunning() {
return isRunning;
}
public void setRunning(boolean running) {
isRunning = running;
}
public int getTimeNow() {
return timeNow;
}
public void setTimeNow(int timeNow) {
this.timeNow = timeNow;
}
} }

View File

@ -1013,6 +1013,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
this.mutedHabbos.clear(); this.mutedHabbos.clear();
} }
for(InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) {
timer.setRunning(false);
}
for (Game game : this.games) for (Game game : this.games)
{ {
game.stop(); game.stop();

View File

@ -4,6 +4,15 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.core.RoomUserPetComposer; import com.eu.habbo.core.RoomUserPetComposer;
import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame;
import com.eu.habbo.habbohotel.games.football.FootballGame;
import com.eu.habbo.habbohotel.games.freeze.FreezeGame;
import com.eu.habbo.habbohotel.games.tag.BunnyrunGame;
import com.eu.habbo.habbohotel.games.tag.IceTagGame;
import com.eu.habbo.habbohotel.games.tag.RollerskateGame;
import com.eu.habbo.habbohotel.games.tag.TagGame;
import com.eu.habbo.habbohotel.games.wired.WiredGame;
import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.items.interactions.InteractionWired;
import com.eu.habbo.habbohotel.messenger.MessengerBuddy; import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
@ -57,6 +66,7 @@ public class RoomManager
private final THashMap<Integer, RoomCategory> roomCategories; private final THashMap<Integer, RoomCategory> roomCategories;
private final List<String> mapNames; private final List<String> mapNames;
private final ConcurrentHashMap<Integer, Room> activeRooms; private final ConcurrentHashMap<Integer, Room> activeRooms;
private final ArrayList<Class<? extends Game>> gameTypes;
public RoomManager() public RoomManager()
{ {
@ -67,6 +77,16 @@ public class RoomManager
this.loadRoomCategories(); this.loadRoomCategories();
this.loadRoomModels(); this.loadRoomModels();
this.gameTypes = new ArrayList<>();
registerGameType(BattleBanzaiGame.class);
registerGameType(FreezeGame.class);
registerGameType(WiredGame.class);
registerGameType(FootballGame.class);
registerGameType(BunnyrunGame.class);
registerGameType(IceTagGame.class);
registerGameType(RollerskateGame.class);
Emulator.getLogging().logStart("Room Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)"); Emulator.getLogging().logStart("Room Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)");
} }
@ -1760,4 +1780,16 @@ public class RoomManager
this.duration = duration; this.duration = duration;
} }
} }
public void registerGameType(Class<? extends Game> gameClass) {
gameTypes.add(gameClass);
}
public void unregisterGameType(Class<? extends Game> gameClass) {
gameTypes.remove(gameClass);
}
public ArrayList<Class<? extends Game>> getGameTypes() {
return gameTypes;
}
} }

View File

@ -774,43 +774,6 @@ public class RoomSpecialTypes
return this.gameTimers; return this.gameTimers;
} }
public THashMap<Integer, InteractionFreezeTimer> getFreezeTimers()
{
synchronized (this.gameTimers)
{
THashMap<Integer, InteractionFreezeTimer> timers = new THashMap<>();
for (Map.Entry<Integer, InteractionGameTimer> set : this.gameTimers.entrySet())
{
if (set.getValue() instanceof InteractionFreezeTimer)
{
timers.put(set.getValue().getId(), (InteractionFreezeTimer) set.getValue());
}
}
return timers;
}
}
public THashMap<Integer, InteractionBattleBanzaiTimer> getBattleBanzaiTimers()
{
synchronized (this.gameTimers)
{
THashMap<Integer, InteractionBattleBanzaiTimer> timers = new THashMap<>();
for (Map.Entry<Integer, InteractionGameTimer> set : this.gameTimers.entrySet())
{
if (set.getValue() instanceof InteractionBattleBanzaiTimer)
{
timers.put(set.getValue().getId(), (InteractionBattleBanzaiTimer) set.getValue());
}
}
return timers;
}
}
public InteractionFreezeExitTile getFreezeExitTile() public InteractionFreezeExitTile getFreezeExitTile()
{ {
for(InteractionFreezeExitTile t : this.freezeExitTile.values()) for(InteractionFreezeExitTile t : this.freezeExitTile.values())

View File

@ -221,6 +221,10 @@ public abstract class HabboItem implements Runnable, IEventTriggers
return this.needsUpdate; return this.needsUpdate;
} }
public boolean needsDelete() {
return needsDelete;
}
public void needsUpdate(boolean value) public void needsUpdate(boolean value)
{ {
this.needsUpdate = value; this.needsUpdate = value;