Fix: GameTimer

This commit is contained in:
duckietm 2024-07-03 09:48:55 +02:00
parent 15a399a263
commit b2ffaf5a7c
2 changed files with 27 additions and 32 deletions

View File

@ -234,53 +234,48 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
state = InteractionGameTimerAction.getByAction((int) objects[0]); state = InteractionGameTimerAction.getByAction((int) objects[0]);
} }
switch (state) { if (state == InteractionGameTimer.InteractionGameTimerAction.START_STOP) {
case START_STOP: if (this.isRunning) { // a game has been started
if (this.isRunning) { // a game has been started this.isPaused = !this.isPaused;
this.isPaused = !this.isPaused; if (this.isPaused) {
if (this.isPaused) { this.pause(room);
this.pause(room);
} else {
this.unpause(room);
if (!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(new GameTimer(this));
}
}
} else { } else {
this.isPaused = false; this.unpause(room);
this.isRunning = true;
this.timeNow = this.baseTime;
room.updateItem(this);
this.createNewGame(room);
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{this});
if (!this.threadActive) { if (!this.threadActive) {
this.threadActive = true; this.threadActive = true;
Emulator.getThreading().run(new GameTimer(this), 1000); Emulator.getThreading().run(new GameTimer(this));
} }
} }
} else {
this.isPaused = false;
this.isRunning = true;
this.timeNow = this.baseTime;
room.updateItem(this);
break; this.createNewGame(room);
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{this});
case INCREASE_TIME: if (!this.threadActive) {
if (!this.isRunning) { this.threadActive = true;
this.increaseTimer(room); Emulator.getThreading().run(new GameTimer(this), 1000);
} else if (this.isPaused) {
this.endGame(room);
this.increaseTimer(room);
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
} }
}
break; } else if (state == InteractionGameTimer.InteractionGameTimerAction.INCREASE_TIME) {
if (!this.isRunning) {
this.increaseTimer(room);
} else if (this.isPaused) {
this.endGame(room);
this.increaseTimer(room);
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
}
} }
} }
super.onClick(client, room, objects); super.onClick(client, room, objects);
} }
@Override @Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {