Merge branch 'new-timers' into 'dev'

Make game timers work properly

See merge request morningstar/Arcturus-Community!42
This commit is contained in:
Beny 2019-06-03 16:49:17 -04:00
commit 72c7e43b69
9 changed files with 158 additions and 262 deletions

View File

@ -20,4 +20,6 @@ ADD COLUMN `comment_id` int(11) NOT NULL AFTER `thread_id`;
ALTER TABLE `pet_actions`
ADD COLUMN `can_swim` enum('1','0') NULL DEFAULT '0' AFTER `random_actions`;
UPDATE `pet_actions` SET `can_swim` = '1' WHERE `pet_type` = 9 OR `pet_type` = 14 OR `pet_type` = 23 OR `pet_type` = 24 OR `pet_type` = 25 OR `pet_type` = 28 OR `pet_type` = 29 OR `pet_type` = 30 OR `pet_type` = 32;
UPDATE `pet_actions` SET `can_swim` = '1' WHERE `pet_type` = 9 OR `pet_type` = 14 OR `pet_type` = 23 OR `pet_type` = 24 OR `pet_type` = 25 OR `pet_type` = 28 OR `pet_type` = 29 OR `pet_type` = 30 OR `pet_type` = 32;
UPDATE `items_base` SET `customparams` = '30,60,120,180,300,600', `interaction_type` = 'game_timer', `interaction_modes_count` = 1 WHERE `item_name` IN ('fball_counter','bb_counter','es_counter');

View File

@ -129,8 +129,6 @@ public abstract class Game implements Runnable {
Emulator.getPluginManager().fireEvent(gameStartedEvent);
}
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, this.room, new Object[]{this});
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) {
item.setExtradata("0");
this.room.updateItem(item);

View File

@ -143,11 +143,10 @@ public class BattleBanzaiGame extends Game {
if (total >= this.tileCount && this.tileCount != 0) {
for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) {
if (timer.isRunning())
timer.setRunning(false);
if (timer.isRunning()) {
timer.endGame(room);
}
}
InteractionGameTimer.endGames(room, true);
}
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);

View File

@ -211,4 +211,8 @@ public class Item {
public double[] getMultiHeights() {
return this.multiHeights;
}
public String getCustomParams() {
return customParams;
}
}

View File

@ -25,7 +25,6 @@ import com.eu.habbo.habbohotel.items.interactions.games.football.scoreboards.Int
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTimer;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGateBlue;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGateGreen;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGateRed;
@ -168,11 +167,11 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("effect_vendingmachine", InteractionEffectVendingMachine.class));
this.interactionsList.add(new ItemInteraction("crackable_monster", InteractionMonsterCrackable.class));
this.interactionsList.add(new ItemInteraction("snowboard_slope", InteractionSnowboardSlope.class));
this.interactionsList.add(new ItemInteraction("timer", InteractionGameTimer.class));
this.interactionsList.add(new ItemInteraction("pressureplate_group", InteractionGroupPressurePlate.class));
this.interactionsList.add(new ItemInteraction("effect_tile_group", InteractionEffectTile.class));
this.interactionsList.add(new ItemInteraction("crackable_subscription_box", InteractionRedeemableSubscriptionBox.class));
this.interactionsList.add(new ItemInteraction("game_timer", InteractionGameTimer.class));
this.interactionsList.add(new ItemInteraction("wf_trg_walks_on_furni", WiredTriggerHabboWalkOnFurni.class));
this.interactionsList.add(new ItemInteraction("wf_trg_walks_off_furni", WiredTriggerHabboWalkOffFurni.class));
@ -292,9 +291,6 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("wf_highscore", InteractionWiredHighscore.class));
//battlebanzai_pyramid
//battlebanzai_puck extends pushable
this.interactionsList.add(new ItemInteraction("battlebanzai_timer", InteractionBattleBanzaiTimer.class));
this.interactionsList.add(new ItemInteraction("battlebanzai_tile", InteractionBattleBanzaiTile.class));
this.interactionsList.add(new ItemInteraction("battlebanzai_random_teleport", InteractionBattleBanzaiTeleporter.class));
this.interactionsList.add(new ItemInteraction("battlebanzai_sphere", InteractionBattleBanzaiSphere.class));
@ -316,7 +312,6 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("freeze_block", InteractionFreezeBlock.class));
this.interactionsList.add(new ItemInteraction("freeze_tile", InteractionFreezeTile.class));
this.interactionsList.add(new ItemInteraction("freeze_exit", InteractionFreezeExitTile.class));
this.interactionsList.add(new ItemInteraction("freeze_timer", InteractionFreezeTimer.class));
this.interactionsList.add(new ItemInteraction("freeze_gate_blue", InteractionFreezeGateBlue.class));

View File

@ -17,80 +17,120 @@ import com.eu.habbo.messages.ServerMessage;
import java.sql.ResultSet;
import java.sql.SQLException;
public abstract class InteractionGameTimer extends HabboItem implements Runnable {
public class InteractionGameTimer extends HabboItem implements Runnable {
private int[] TIMER_INTERVAL_STEPS = new int[] { 30, 60, 120, 180, 300, 600 };
private int baseTime = 0;
private int timeNow = 0;
private boolean isRunning = false;
private boolean isPaused = false;
private boolean threadActive = false;
public enum InteractionGameTimerAction {
START_STOP(1),
INCREASE_TIME(2);
private int action;
InteractionGameTimerAction(int action) {
this.action = action;
}
public int getAction() {
return action;
}
public static InteractionGameTimerAction getByAction(int action) {
if (action == 1) return START_STOP;
if (action == 2) return INCREASE_TIME;
return START_STOP;
}
}
public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
String[] data = set.getString("extra_data").split("\t");
parseCustomParams(baseItem);
if (data.length >= 2) {
this.baseTime = Integer.valueOf(data[1]);
this.timeNow = this.baseTime;
try {
String[] data = set.getString("extra_data").split("\t");
if (data.length >= 2) {
this.baseTime = Integer.valueOf(data[1]);
this.timeNow = this.baseTime;
}
if (data.length >= 1) {
this.setExtradata(data[0] + "\t0");
}
}
if (data.length >= 1) {
this.setExtradata(data[0]);
catch (Exception e) {
this.baseTime = TIMER_INTERVAL_STEPS[0];
this.timeNow = this.baseTime;
}
}
public InteractionGameTimer(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
parseCustomParams(item);
}
public static void endGamesIfLastTimer(Room room) {
boolean gamesActive = false;
for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) {
if (timer.isRunning())
gamesActive = true;
public void parseCustomParams(Item baseItem) {
try {
String[] intervalSteps = baseItem.getCustomParams().split(",");
int[] finalSteps = new int[intervalSteps.length];
for (int i = 0; i < intervalSteps.length; i++) {
finalSteps[i] = Integer.parseInt(intervalSteps[i]);
}
TIMER_INTERVAL_STEPS = finalSteps;
}
if (!gamesActive) {
endGames(room);
catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
}
public static void endGames(Room room) {
endGames(room, false);
}
public void endGame(Room room) {
this.isRunning = false;
this.isPaused = false;
public static void endGames(Room room, boolean overrideTriggerWired) {
boolean triggerWired = false;
//end existing games
for (Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = InteractionGameTimer.getOrCreateGame(room, gameClass);
if (!game.state.equals(GameState.IDLE)) {
triggerWired = true;
for (Game game : room.getGames()) {
if (!game.getState().equals(GameState.IDLE)) {
game.onEnd();
game.stop();
}
}
}
if (triggerWired) {
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
private void createNewGame(Room room) {
for(Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game existingGame = room.getGame(gameClass);
if (existingGame != null) {
existingGame.initialise();
} else {
try {
Game game = gameClass.getDeclaredConstructor(Room.class).newInstance(room);
room.addGame(game);
game.initialise();
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
}
}
}
public static Game getOrCreateGame(Room room, Class<? extends Game> gameClass) {
Game game = (gameClass.cast(room.getGame(gameClass)));
if (game == null) {
try {
game = gameClass.getDeclaredConstructor(Room.class).newInstance(room);
room.addGame(game);
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
private void pause(Room room) {
for (Game game : room.getGames()) {
game.pause();
}
}
return game;
private void unpause(Room room) {
for (Game game : room.getGames()) {
game.unpause();
}
}
@Override
@ -117,27 +157,31 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
this.timeNow--;
room.updateItem(this);
} else {
this.isRunning = false;
this.isPaused = false;
this.threadActive = false;
endGamesIfLastTimer(room);
this.endGame(room);
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
}
}
@Override
public void onPickUp(Room room) {
this.setExtradata("0");
this.endGame(room);
this.setExtradata(this.baseTime + "\t" + this.baseTime);
this.needsUpdate(true);
}
@Override
public void onPlace(Room room) {
if (this.baseTime == 0) {
this.baseTime = 30;
this.timeNow = this.baseTime;
if (this.baseTime < this.TIMER_INTERVAL_STEPS[0]) {
this.baseTime = this.TIMER_INTERVAL_STEPS[0];
}
this.timeNow = this.baseTime;
this.setExtradata(this.timeNow + "\t" + this.baseTime);
room.updateItem(this);
this.needsUpdate(true);
super.onPlace(room);
}
@ -163,126 +207,84 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
if (this.getExtradata().isEmpty()) {
this.setExtradata("0");
this.setExtradata("0\t" + this.TIMER_INTERVAL_STEPS[0]);
}
// if wired triggered it
if (objects.length >= 2 && objects[1] instanceof WiredEffectType && !this.isRunning) {
endGamesIfLastTimer(room);
if (objects.length >= 2 && objects[1] instanceof WiredEffectType) {
if(!(!this.isRunning || this.isPaused))
return;
for (Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = getOrCreateGame(room, gameClass);
if (!game.isRunning) {
game.initialise();
}
boolean wasPaused = this.isPaused;
this.endGame(room);
if(wasPaused) {
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
}
timeNow = this.baseTime;
this.createNewGame(room);
this.timeNow = this.baseTime;
this.isRunning = true;
this.isPaused = false;
room.updateItem(this);
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{});
if (!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this);
Emulator.getThreading().run(this, 1000);
}
} else if (client != null) {
if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)))
return;
int state = 1;
InteractionGameTimerAction state = InteractionGameTimerAction.START_STOP;
if (objects.length >= 1 && objects[0] instanceof Integer) {
state = (Integer) objects[0];
state = InteractionGameTimerAction.getByAction((int) objects[0]);
}
switch (state) {
case 1:
if (this.isRunning) {
case START_STOP:
if (this.isRunning) { // a game has been started
this.isPaused = !this.isPaused;
boolean allPaused = this.isPaused;
for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) {
if (!timer.isPaused)
allPaused = false;
}
for (Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
Game game = getOrCreateGame(room, gameClass);
if (allPaused) {
game.pause();
} else {
game.unpause();
}
}
if (!this.isPaused) {
this.isRunning = true;
timeNow = this.baseTime;
room.updateItem(this);
if (this.isPaused) {
this.pause(room);
} else {
this.unpause(room);
if (!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this);
}
}
}
if (!this.isRunning) {
endGamesIfLastTimer(room);
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[]{});
} else {
this.isPaused = false;
this.isRunning = true;
timeNow = this.baseTime;
this.timeNow = this.baseTime;
room.updateItem(this);
this.createNewGame(room);
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{this});
if (!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this);
Emulator.getThreading().run(this, 1000);
}
}
break;
case 2:
case INCREASE_TIME:
if (!this.isRunning) {
this.increaseTimer(room);
return;
} else if (this.isPaused) {
this.endGame(room);
this.increaseTimer(room);
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
}
if (this.isPaused) {
this.isPaused = false;
this.isRunning = false;
timeNow = this.baseTime;
room.updateItem(this);
endGamesIfLastTimer(room);
}
break;
case 3:
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;
}
}
@ -299,33 +301,24 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
if (this.isRunning)
return;
this.needsUpdate(true);
int baseTime = -1;
switch (this.baseTime) {
case 0:
this.baseTime = 30;
break;
case 30:
this.baseTime = 60;
break;
case 60:
this.baseTime = 120;
break;
case 120:
this.baseTime = 180;
break;
case 180:
this.baseTime = 300;
break;
case 300:
this.baseTime = 600;
break;
//case 600: this.baseTime = 0; break;
if (this.timeNow != this.baseTime) {
baseTime = this.baseTime;
} else {
for (int step : this.TIMER_INTERVAL_STEPS) {
if (this.timeNow < step) {
baseTime = step;
break;
}
}
default:
this.baseTime = 30;
if (baseTime == -1) baseTime = this.TIMER_INTERVAL_STEPS[0];
}
this.baseTime = baseTime;
this.setExtradata(this.timeNow + "\t" + this.baseTime);
this.timeNow = this.baseTime;
room.updateItem(this);
this.needsUpdate(true);
@ -333,11 +326,9 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
@Override
public String getDatabaseExtraData() {
return this.getExtradata() + "\t" + this.baseTime;
return this.getExtradata();
}
public abstract Class<? extends Game> getGameType();
@Override
public boolean allowWiredResetState() {
return true;
@ -350,12 +341,4 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
public void setRunning(boolean running) {
isRunning = running;
}
public int getTimeNow() {
return timeNow;
}
public void setTimeNow(int timeNow) {
this.timeNow = timeNow;
}
}

View File

@ -1,41 +0,0 @@
package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionBattleBanzaiTimer extends InteractionGameTimer {
public InteractionBattleBanzaiTimer(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
public InteractionBattleBanzaiTimer(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public Class<? extends Game> getGameType() {
return BattleBanzaiGame.class;
}
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
return false;
}
@Override
public boolean isWalkable() {
return false;
}
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
}
}

View File

@ -1,48 +0,0 @@
package com.eu.habbo.habbohotel.items.interactions.games.freeze;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.freeze.FreezeGame;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionFreezeTimer extends InteractionGameTimer {
public InteractionFreezeTimer(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
public InteractionFreezeTimer(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
return false;
}
@Override
public boolean isWalkable() {
return false;
}
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, objects);
}
@Override
public Class<? extends Game> getGameType() {
return FreezeGame.class;
}
}

View File

@ -2147,6 +2147,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return null;
}
public ConcurrentSet<Game> getGames() {
return this.games;
}
public int getUserCount() {
return this.currentHabbos.size();
}