mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-18 23:46:28 +01:00
Game timers fixed
This commit is contained in:
parent
83fcc87a88
commit
a692d2fbf0
@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.games;
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
||||
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.triggers.WiredTriggerTeamLoses;
|
||||
import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamWins;
|
||||
@ -170,32 +171,7 @@ public abstract class Game implements Runnable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
||||
public void onEnd() {
|
||||
this.saveScores();
|
||||
|
||||
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))
|
||||
{
|
||||
Event gameStoppedEvent = new GameStoppedEvent(this);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.games.battlebanzai;
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
||||
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.InteractionBattleBanzaiTile;
|
||||
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.users.Habbo;
|
||||
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.threading.runnables.BattleBanzaiTilesFlicker;
|
||||
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");
|
||||
|
||||
private int timeLeft;
|
||||
|
||||
private int tileCount;
|
||||
|
||||
private int countDown;
|
||||
@ -62,22 +63,10 @@ public class BattleBanzaiGame extends Game
|
||||
if(!this.state.equals(GameState.IDLE))
|
||||
return;
|
||||
|
||||
int highestTime = 0;
|
||||
this.countDown = 3;
|
||||
|
||||
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)
|
||||
{
|
||||
for (GameTeam t : this.teams.values())
|
||||
@ -92,13 +81,6 @@ public class BattleBanzaiGame extends Game
|
||||
this.room.updateItemState(item);
|
||||
}
|
||||
|
||||
this.timeLeft = highestTime;
|
||||
|
||||
if (this.timeLeft == 0)
|
||||
{
|
||||
this.timeLeft = 30;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (this.state.equals(GameState.PAUSED)) return;
|
||||
|
||||
this.timeLeft--;
|
||||
|
||||
for (Map.Entry<Integer, InteractionBattleBanzaiTimer> set : this.room.getRoomSpecialTypes().getBattleBanzaiTimers().entrySet())
|
||||
for (Map.Entry<GameTeamColors, THashSet<HabboItem>> set : this.lockedTiles.entrySet())
|
||||
{
|
||||
set.getValue().setExtradata(this.timeLeft + "");
|
||||
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;
|
||||
total += set.getValue().size();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
GameTeam highestScore = null;
|
||||
|
||||
synchronized (this.teams)
|
||||
{
|
||||
|
||||
GameTeam winningTeam = null;
|
||||
|
||||
for (GameTeam team : this.teams.values())
|
||||
for (Map.Entry<GameTeamColors, GameTeam> set : this.teams.entrySet())
|
||||
{
|
||||
for(GamePlayer player : team.getMembers())
|
||||
if (highestScore == null || highestScore.getTotalScore() < set.getValue().getTotalScore())
|
||||
{
|
||||
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;
|
||||
highestScore = set.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (winningTeam != null)
|
||||
if(highestScore != null)
|
||||
{
|
||||
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class))
|
||||
{
|
||||
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"));
|
||||
}
|
||||
}
|
||||
item.setExtradata((highestScore.teamColor.type + 3) + "");
|
||||
this.room.updateItemState(item);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
if(total >= this.tileCount && this.tileCount != 0)
|
||||
{
|
||||
for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values())
|
||||
{
|
||||
if(timer.isRunning())
|
||||
timer.setRunning(false);
|
||||
}
|
||||
|
||||
this.stop();
|
||||
InteractionGameTimer.endGames(room);
|
||||
}
|
||||
}
|
||||
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
|
||||
public void stop()
|
||||
{
|
||||
super.stop();
|
||||
|
||||
this.timeLeft = 0;
|
||||
|
||||
this.refreshGates();
|
||||
|
||||
for (HabboItem tile : this.gameTiles.values())
|
||||
@ -265,7 +240,7 @@ public class BattleBanzaiGame extends Game
|
||||
if (tile.getExtradata().equals("1"))
|
||||
{
|
||||
tile.setExtradata("0");
|
||||
this.room.updateItemState(tile);
|
||||
this.room.updateItem(tile);
|
||||
}
|
||||
}
|
||||
this.lockedTiles.clear();
|
||||
|
@ -45,8 +45,6 @@ public class FreezeGame extends Game
|
||||
public static int FREEZE_LOOSE_POINTS;
|
||||
public static boolean POWERUP_STACK;
|
||||
|
||||
private int timeLeft;
|
||||
|
||||
public FreezeGame(Room room)
|
||||
{
|
||||
super(FreezeGameTeam.class, FreezeGamePlayer.class, room, true);
|
||||
@ -59,21 +57,8 @@ public class FreezeGame extends Game
|
||||
if(this.state == GameState.RUNNING)
|
||||
return;
|
||||
|
||||
int highestTime = 0;
|
||||
|
||||
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())
|
||||
{
|
||||
t.initialise();
|
||||
@ -95,12 +80,6 @@ public class FreezeGame extends Game
|
||||
}
|
||||
}
|
||||
}
|
||||
this.timeLeft = highestTime;
|
||||
|
||||
if (this.timeLeft == 0)
|
||||
{
|
||||
this.timeLeft = 30;
|
||||
}
|
||||
|
||||
this.start();
|
||||
}
|
||||
@ -282,7 +261,6 @@ public class FreezeGame extends Game
|
||||
|
||||
this.refreshGates();
|
||||
|
||||
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, this.room, null);
|
||||
this.setFreezeTileState("1");
|
||||
this.run();
|
||||
}
|
||||
@ -295,50 +273,36 @@ public class FreezeGame extends Game
|
||||
if (this.state.equals(GameState.IDLE))
|
||||
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);
|
||||
|
||||
if (this.state.equals(GameState.PAUSED)) return;
|
||||
|
||||
this.timeLeft--;
|
||||
|
||||
for (GameTeam team : this.teams.values())
|
||||
for (GamePlayer player : team.getMembers())
|
||||
{
|
||||
for (GamePlayer player : team.getMembers())
|
||||
{
|
||||
((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);
|
||||
}
|
||||
((FreezeGamePlayer)player).cycle();
|
||||
}
|
||||
|
||||
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 + "");
|
||||
this.room.updateItemState(set.getValue());
|
||||
if(scoreboard.getExtradata().isEmpty())
|
||||
{
|
||||
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)
|
||||
@ -352,8 +316,6 @@ public class FreezeGame extends Game
|
||||
{
|
||||
super.stop();
|
||||
|
||||
this.timeLeft = 0;
|
||||
|
||||
GameTeam winningTeam = null;
|
||||
|
||||
for(GameTeam team : this.teams.values())
|
||||
|
@ -14,51 +14,19 @@ import java.util.Map;
|
||||
|
||||
public class WiredGame extends Game
|
||||
{
|
||||
private int timeLeft = 30;
|
||||
public WiredGame(Room room)
|
||||
{
|
||||
super(GameTeam.class, GamePlayer.class, room , false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialise()
|
||||
{
|
||||
for (Map.Entry<Integer, InteractionGameTimer> set : this.room.getRoomSpecialTypes().getGameTimers().entrySet())
|
||||
{
|
||||
if(set.getValue().getExtradata().isEmpty())
|
||||
continue;
|
||||
public void initialise() {
|
||||
|
||||
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
|
||||
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();
|
||||
}
|
||||
public void run() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,8 @@ import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
||||
import com.eu.habbo.habbohotel.games.Game;
|
||||
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.items.Item;
|
||||
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.users.HabboItem;
|
||||
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 java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.ResultSet;
|
||||
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 lastToggle = 0;
|
||||
private int timeNow = 0;
|
||||
private boolean isRunning = false;
|
||||
private boolean isPaused = false;
|
||||
|
||||
public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException
|
||||
{
|
||||
@ -30,6 +39,7 @@ public abstract class InteractionGameTimer extends HabboItem
|
||||
if (data.length >= 2)
|
||||
{
|
||||
this.baseTime = Integer.valueOf(data[1]);
|
||||
this.timeNow = this.baseTime;
|
||||
}
|
||||
|
||||
if (data.length >= 1)
|
||||
@ -43,6 +53,54 @@ public abstract class InteractionGameTimer extends HabboItem
|
||||
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
|
||||
public void onPickUp(Room room)
|
||||
{
|
||||
@ -52,8 +110,12 @@ public abstract class InteractionGameTimer extends HabboItem
|
||||
@Override
|
||||
public void onPlace(Room room)
|
||||
{
|
||||
this.baseTime = 30;
|
||||
this.setExtradata("30");
|
||||
if(this.baseTime == 0) {
|
||||
this.baseTime = 30;
|
||||
this.timeNow = this.baseTime;
|
||||
}
|
||||
|
||||
this.setExtradata(this.timeNow + "\t" + this.baseTime);
|
||||
room.updateItem(this);
|
||||
}
|
||||
|
||||
@ -61,7 +123,7 @@ public abstract class InteractionGameTimer extends HabboItem
|
||||
public void serializeExtradata(ServerMessage serverMessage)
|
||||
{
|
||||
serverMessage.appendInt((this.isLimited() ? 256 : 0));
|
||||
serverMessage.appendString(this.getExtradata());
|
||||
serverMessage.appendString("" + timeNow);
|
||||
|
||||
super.serializeExtradata(serverMessage);
|
||||
}
|
||||
@ -81,65 +143,131 @@ public abstract class InteractionGameTimer extends HabboItem
|
||||
@Override
|
||||
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())
|
||||
{
|
||||
this.setExtradata("0");
|
||||
}
|
||||
|
||||
Game game = this.getOrCreateGame(room);
|
||||
|
||||
if ((objects.length >= 2 && objects[1] instanceof WiredEffectType))
|
||||
// if wired triggered it
|
||||
if (objects.length >= 2 && objects[1] instanceof WiredEffectType && !this.isRunning)
|
||||
{
|
||||
if (game == null || !game.isRunning)
|
||||
startGame(room);
|
||||
else if (game.isRunning)
|
||||
stopGame(room);
|
||||
boolean gamesActive = false;
|
||||
for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if(objects.length >= 1 && objects[0] instanceof Integer && client != null)
|
||||
else if(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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
this.increaseTimer(room);
|
||||
}
|
||||
break;
|
||||
if(!this.isRunning) {
|
||||
this.increaseTimer(room);
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.isPaused) {
|
||||
this.isPaused = false;
|
||||
this.isRunning = false;
|
||||
|
||||
timeNow = this.baseTime;
|
||||
room.updateItem(this);
|
||||
|
||||
endGamesIfLastTimer(room);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
this.stopGame(room);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (game != null && game.state.equals(GameState.IDLE))
|
||||
{
|
||||
this.startGame(room);
|
||||
this.isPaused = false;
|
||||
this.isRunning = false;
|
||||
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
game = this.getGameType().getDeclaredConstructor(Room.class).newInstance(room);
|
||||
if (game == null) {
|
||||
try {
|
||||
System.out.println(gameClass.getName());
|
||||
game = gameClass.getDeclaredConstructor(Room.class).newInstance(room);
|
||||
room.addGame(game);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
} catch (Exception e) {
|
||||
Emulator.getLogging().logErrorLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Game game = this.getOrCreateGame(room);
|
||||
|
||||
if (game == null) return;
|
||||
if (game.state.equals(GameState.PAUSED))
|
||||
{
|
||||
stopGame(room);
|
||||
if(this.isRunning)
|
||||
return;
|
||||
}
|
||||
if (game.state.equals(GameState.RUNNING)) return;
|
||||
|
||||
this.needsUpdate(true);
|
||||
|
||||
switch(this.baseTime)
|
||||
{
|
||||
case 0: this.baseTime = 30; break;
|
||||
@ -247,9 +318,9 @@ public abstract class InteractionGameTimer extends HabboItem
|
||||
this.baseTime = 30;
|
||||
}
|
||||
|
||||
this.setExtradata(this.baseTime + "");
|
||||
|
||||
this.timeNow = this.baseTime;
|
||||
room.updateItem(this);
|
||||
this.needsUpdate(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -265,4 +336,20 @@ public abstract class InteractionGameTimer extends HabboItem
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1013,6 +1013,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
|
||||
this.mutedHabbos.clear();
|
||||
}
|
||||
|
||||
for(InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) {
|
||||
timer.setRunning(false);
|
||||
}
|
||||
|
||||
for (Game game : this.games)
|
||||
{
|
||||
game.stop();
|
||||
|
@ -4,6 +4,15 @@ import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.core.RoomUserPetComposer;
|
||||
import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
||||
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.items.interactions.InteractionWired;
|
||||
import com.eu.habbo.habbohotel.messenger.MessengerBuddy;
|
||||
@ -57,6 +66,7 @@ public class RoomManager
|
||||
private final THashMap<Integer, RoomCategory> roomCategories;
|
||||
private final List<String> mapNames;
|
||||
private final ConcurrentHashMap<Integer, Room> activeRooms;
|
||||
private final ArrayList<Class<? extends Game>> gameTypes;
|
||||
|
||||
public RoomManager()
|
||||
{
|
||||
@ -67,6 +77,16 @@ public class RoomManager
|
||||
this.loadRoomCategories();
|
||||
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)");
|
||||
}
|
||||
|
||||
@ -1760,4 +1780,16 @@ public class RoomManager
|
||||
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;
|
||||
}
|
||||
}
|
@ -774,43 +774,6 @@ public class RoomSpecialTypes
|
||||
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()
|
||||
{
|
||||
for(InteractionFreezeExitTile t : this.freezeExitTile.values())
|
||||
|
@ -221,6 +221,10 @@ public abstract class HabboItem implements Runnable, IEventTriggers
|
||||
return this.needsUpdate;
|
||||
}
|
||||
|
||||
public boolean needsDelete() {
|
||||
return needsDelete;
|
||||
}
|
||||
|
||||
public void needsUpdate(boolean value)
|
||||
{
|
||||
this.needsUpdate = value;
|
||||
|
Loading…
Reference in New Issue
Block a user