mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-23 07:20:50 +01:00
Merge branch 'new-timers' into 'dev'
Make game timers work properly See merge request morningstar/Arcturus-Community!42
This commit is contained in:
commit
72c7e43b69
@ -21,3 +21,5 @@ ALTER TABLE `pet_actions`
|
|||||||
ADD COLUMN `can_swim` enum('1','0') NULL DEFAULT '0' AFTER `random_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');
|
||||||
|
@ -129,8 +129,6 @@ public abstract class Game implements Runnable {
|
|||||||
Emulator.getPluginManager().fireEvent(gameStartedEvent);
|
Emulator.getPluginManager().fireEvent(gameStartedEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, this.room, new Object[]{this});
|
|
||||||
|
|
||||||
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) {
|
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) {
|
||||||
item.setExtradata("0");
|
item.setExtradata("0");
|
||||||
this.room.updateItem(item);
|
this.room.updateItem(item);
|
||||||
|
@ -143,11 +143,10 @@ public class BattleBanzaiGame extends Game {
|
|||||||
|
|
||||||
if (total >= this.tileCount && this.tileCount != 0) {
|
if (total >= this.tileCount && this.tileCount != 0) {
|
||||||
for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) {
|
for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) {
|
||||||
if (timer.isRunning())
|
if (timer.isRunning()) {
|
||||||
timer.setRunning(false);
|
timer.endGame(room);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InteractionGameTimer.endGames(room, true);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Emulator.getLogging().logErrorLine(e);
|
Emulator.getLogging().logErrorLine(e);
|
||||||
|
@ -211,4 +211,8 @@ public class Item {
|
|||||||
public double[] getMultiHeights() {
|
public double[] getMultiHeights() {
|
||||||
return this.multiHeights;
|
return this.multiHeights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCustomParams() {
|
||||||
|
return customParams;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.InteractionFreezeBlock;
|
||||||
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile;
|
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.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.InteractionFreezeGateBlue;
|
||||||
import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGateGreen;
|
import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGateGreen;
|
||||||
import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGateRed;
|
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("effect_vendingmachine", InteractionEffectVendingMachine.class));
|
||||||
this.interactionsList.add(new ItemInteraction("crackable_monster", InteractionMonsterCrackable.class));
|
this.interactionsList.add(new ItemInteraction("crackable_monster", InteractionMonsterCrackable.class));
|
||||||
this.interactionsList.add(new ItemInteraction("snowboard_slope", InteractionSnowboardSlope.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("pressureplate_group", InteractionGroupPressurePlate.class));
|
||||||
this.interactionsList.add(new ItemInteraction("effect_tile_group", InteractionEffectTile.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("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_on_furni", WiredTriggerHabboWalkOnFurni.class));
|
||||||
this.interactionsList.add(new ItemInteraction("wf_trg_walks_off_furni", WiredTriggerHabboWalkOffFurni.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));
|
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_tile", InteractionBattleBanzaiTile.class));
|
||||||
this.interactionsList.add(new ItemInteraction("battlebanzai_random_teleport", InteractionBattleBanzaiTeleporter.class));
|
this.interactionsList.add(new ItemInteraction("battlebanzai_random_teleport", InteractionBattleBanzaiTeleporter.class));
|
||||||
this.interactionsList.add(new ItemInteraction("battlebanzai_sphere", InteractionBattleBanzaiSphere.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_block", InteractionFreezeBlock.class));
|
||||||
this.interactionsList.add(new ItemInteraction("freeze_tile", InteractionFreezeTile.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_exit", InteractionFreezeExitTile.class));
|
||||||
this.interactionsList.add(new ItemInteraction("freeze_timer", InteractionFreezeTimer.class));
|
|
||||||
|
|
||||||
|
|
||||||
this.interactionsList.add(new ItemInteraction("freeze_gate_blue", InteractionFreezeGateBlue.class));
|
this.interactionsList.add(new ItemInteraction("freeze_gate_blue", InteractionFreezeGateBlue.class));
|
||||||
|
@ -17,16 +17,43 @@ import com.eu.habbo.messages.ServerMessage;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
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 baseTime = 0;
|
||||||
private int timeNow = 0;
|
private int timeNow = 0;
|
||||||
private boolean isRunning = false;
|
private boolean isRunning = false;
|
||||||
private boolean isPaused = false;
|
private boolean isPaused = false;
|
||||||
private boolean threadActive = 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 {
|
public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException {
|
||||||
super(set, baseItem);
|
super(set, baseItem);
|
||||||
|
|
||||||
|
parseCustomParams(baseItem);
|
||||||
|
|
||||||
|
try {
|
||||||
String[] data = set.getString("extra_data").split("\t");
|
String[] data = set.getString("extra_data").split("\t");
|
||||||
|
|
||||||
if (data.length >= 2) {
|
if (data.length >= 2) {
|
||||||
@ -35,62 +62,75 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.length >= 1) {
|
if (data.length >= 1) {
|
||||||
this.setExtradata(data[0]);
|
this.setExtradata(data[0] + "\t0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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) {
|
public InteractionGameTimer(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
||||||
super(id, userId, item, extradata, limitedStack, limitedSells);
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
||||||
|
|
||||||
|
parseCustomParams(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void endGamesIfLastTimer(Room room) {
|
public void parseCustomParams(Item baseItem) {
|
||||||
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) {
|
|
||||||
endGames(room, 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;
|
|
||||||
game.onEnd();
|
|
||||||
game.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (triggerWired) {
|
|
||||||
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Game getOrCreateGame(Room room, Class<? extends Game> gameClass) {
|
|
||||||
Game game = (gameClass.cast(room.getGame(gameClass)));
|
|
||||||
|
|
||||||
if (game == null) {
|
|
||||||
try {
|
try {
|
||||||
game = gameClass.getDeclaredConstructor(Room.class).newInstance(room);
|
String[] intervalSteps = baseItem.getCustomParams().split(",");
|
||||||
room.addGame(game);
|
int[] finalSteps = new int[intervalSteps.length];
|
||||||
} catch (Exception e) {
|
for (int i = 0; i < intervalSteps.length; i++) {
|
||||||
|
finalSteps[i] = Integer.parseInt(intervalSteps[i]);
|
||||||
|
}
|
||||||
|
TIMER_INTERVAL_STEPS = finalSteps;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
Emulator.getLogging().logErrorLine(e);
|
Emulator.getLogging().logErrorLine(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return game;
|
public void endGame(Room room) {
|
||||||
|
this.isRunning = false;
|
||||||
|
this.isPaused = false;
|
||||||
|
|
||||||
|
for (Game game : room.getGames()) {
|
||||||
|
if (!game.getState().equals(GameState.IDLE)) {
|
||||||
|
game.onEnd();
|
||||||
|
game.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pause(Room room) {
|
||||||
|
for (Game game : room.getGames()) {
|
||||||
|
game.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unpause(Room room) {
|
||||||
|
for (Game game : room.getGames()) {
|
||||||
|
game.unpause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -117,27 +157,31 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
|
|||||||
this.timeNow--;
|
this.timeNow--;
|
||||||
room.updateItem(this);
|
room.updateItem(this);
|
||||||
} else {
|
} else {
|
||||||
this.isRunning = false;
|
|
||||||
this.isPaused = false;
|
|
||||||
this.threadActive = false;
|
this.threadActive = false;
|
||||||
endGamesIfLastTimer(room);
|
this.endGame(room);
|
||||||
|
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPickUp(Room room) {
|
public void onPickUp(Room room) {
|
||||||
this.setExtradata("0");
|
this.endGame(room);
|
||||||
|
|
||||||
|
this.setExtradata(this.baseTime + "\t" + this.baseTime);
|
||||||
|
this.needsUpdate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlace(Room room) {
|
public void onPlace(Room room) {
|
||||||
if (this.baseTime == 0) {
|
if (this.baseTime < this.TIMER_INTERVAL_STEPS[0]) {
|
||||||
this.baseTime = 30;
|
this.baseTime = this.TIMER_INTERVAL_STEPS[0];
|
||||||
this.timeNow = this.baseTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.timeNow = this.baseTime;
|
||||||
|
|
||||||
this.setExtradata(this.timeNow + "\t" + this.baseTime);
|
this.setExtradata(this.timeNow + "\t" + this.baseTime);
|
||||||
room.updateItem(this);
|
room.updateItem(this);
|
||||||
|
this.needsUpdate(true);
|
||||||
|
|
||||||
super.onPlace(room);
|
super.onPlace(room);
|
||||||
}
|
}
|
||||||
@ -163,126 +207,84 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
|
|||||||
@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 (this.getExtradata().isEmpty()) {
|
if (this.getExtradata().isEmpty()) {
|
||||||
this.setExtradata("0");
|
this.setExtradata("0\t" + this.TIMER_INTERVAL_STEPS[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if wired triggered it
|
// if wired triggered it
|
||||||
if (objects.length >= 2 && objects[1] instanceof WiredEffectType && !this.isRunning) {
|
if (objects.length >= 2 && objects[1] instanceof WiredEffectType) {
|
||||||
endGamesIfLastTimer(room);
|
if(!(!this.isRunning || this.isPaused))
|
||||||
|
return;
|
||||||
|
|
||||||
for (Class<? extends Game> gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) {
|
boolean wasPaused = this.isPaused;
|
||||||
Game game = getOrCreateGame(room, gameClass);
|
this.endGame(room);
|
||||||
if (!game.isRunning) {
|
|
||||||
game.initialise();
|
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.isRunning = true;
|
||||||
|
this.isPaused = false;
|
||||||
|
|
||||||
room.updateItem(this);
|
room.updateItem(this);
|
||||||
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{});
|
WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[]{});
|
||||||
|
|
||||||
if (!this.threadActive) {
|
if (!this.threadActive) {
|
||||||
this.threadActive = true;
|
this.threadActive = true;
|
||||||
Emulator.getThreading().run(this);
|
Emulator.getThreading().run(this, 1000);
|
||||||
}
|
}
|
||||||
} else if (client != null) {
|
} else if (client != null) {
|
||||||
if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)))
|
if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int state = 1;
|
InteractionGameTimerAction state = InteractionGameTimerAction.START_STOP;
|
||||||
|
|
||||||
if (objects.length >= 1 && objects[0] instanceof Integer) {
|
if (objects.length >= 1 && objects[0] instanceof Integer) {
|
||||||
state = (Integer) objects[0];
|
state = InteractionGameTimerAction.getByAction((int) objects[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 1:
|
case START_STOP:
|
||||||
if (this.isRunning) {
|
if (this.isRunning) { // a game has been started
|
||||||
this.isPaused = !this.isPaused;
|
this.isPaused = !this.isPaused;
|
||||||
|
if (this.isPaused) {
|
||||||
boolean allPaused = this.isPaused;
|
this.pause(room);
|
||||||
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 {
|
} else {
|
||||||
game.unpause();
|
this.unpause(room);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.isPaused) {
|
|
||||||
this.isRunning = true;
|
|
||||||
timeNow = this.baseTime;
|
|
||||||
room.updateItem(this);
|
|
||||||
|
|
||||||
if (!this.threadActive) {
|
if (!this.threadActive) {
|
||||||
this.threadActive = true;
|
this.threadActive = true;
|
||||||
Emulator.getThreading().run(this);
|
Emulator.getThreading().run(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
this.isPaused = false;
|
||||||
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[]{});
|
|
||||||
this.isRunning = true;
|
this.isRunning = true;
|
||||||
timeNow = this.baseTime;
|
this.timeNow = this.baseTime;
|
||||||
room.updateItem(this);
|
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(this);
|
Emulator.getThreading().run(this, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case INCREASE_TIME:
|
||||||
if (!this.isRunning) {
|
if (!this.isRunning) {
|
||||||
this.increaseTimer(room);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,32 +301,23 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
|
|||||||
if (this.isRunning)
|
if (this.isRunning)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.needsUpdate(true);
|
int baseTime = -1;
|
||||||
|
|
||||||
switch (this.baseTime) {
|
if (this.timeNow != this.baseTime) {
|
||||||
case 0:
|
baseTime = this.baseTime;
|
||||||
this.baseTime = 30;
|
} else {
|
||||||
|
for (int step : this.TIMER_INTERVAL_STEPS) {
|
||||||
|
if (this.timeNow < step) {
|
||||||
|
baseTime = step;
|
||||||
break;
|
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;
|
|
||||||
|
|
||||||
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;
|
this.timeNow = this.baseTime;
|
||||||
room.updateItem(this);
|
room.updateItem(this);
|
||||||
@ -333,11 +326,9 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDatabaseExtraData() {
|
public String getDatabaseExtraData() {
|
||||||
return this.getExtradata() + "\t" + this.baseTime;
|
return this.getExtradata();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Class<? extends Game> getGameType();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowWiredResetState() {
|
public boolean allowWiredResetState() {
|
||||||
return true;
|
return true;
|
||||||
@ -350,12 +341,4 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable
|
|||||||
public void setRunning(boolean running) {
|
public void setRunning(boolean running) {
|
||||||
isRunning = running;
|
isRunning = running;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTimeNow() {
|
|
||||||
return timeNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeNow(int timeNow) {
|
|
||||||
this.timeNow = timeNow;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2147,6 +2147,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConcurrentSet<Game> getGames() {
|
||||||
|
return this.games;
|
||||||
|
}
|
||||||
|
|
||||||
public int getUserCount() {
|
public int getUserCount() {
|
||||||
return this.currentHabbos.size();
|
return this.currentHabbos.size();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user