From 9ad10c89a7c9e9bd0cd72764a5f64545ba46ec51 Mon Sep 17 00:00:00 2001 From: Yordi Date: Mon, 23 Jan 2023 21:47:05 +0000 Subject: [PATCH] New InteractionSpinningBottle for spinning bottles --- sqlupdates/3_5_0 to 4_0_0.sql | 2 + .../habbo/habbohotel/items/ItemManager.java | 1 + .../InteractionSpinningBottle.java | 89 +++++++++++++++++++ .../eu/habbo/habbohotel/users/HabboItem.java | 2 +- .../incoming/rooms/items/ThrowDiceEvent.java | 3 +- .../rooms/items/UseFurnitureEvent.java | 3 +- .../runnables/RandomSpinningBottleNumber.java | 39 ++++++++ 7 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java create mode 100644 src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java diff --git a/sqlupdates/3_5_0 to 4_0_0.sql b/sqlupdates/3_5_0 to 4_0_0.sql index fab7b232..7b308684 100644 --- a/sqlupdates/3_5_0 to 4_0_0.sql +++ b/sqlupdates/3_5_0 to 4_0_0.sql @@ -13,3 +13,5 @@ UPDATE `emulator_texts` SET `key` = 'generic.pet.happiness', `value` = 'Happines ALTER TABLE `pet_commands_data` CHANGE `cost_happyness` `cost_happiness` int(11) NOT NULL DEFAULT '0'; ALTER TABLE `users_pets` CHANGE `happyness` `happiness` int(11) NOT NULL DEFAULT '100'; + +UPDATE `items_base` SET `interaction_type` = 'spinning_bottle', `interaction_modes_count` = '8' WHERE `item_name` = 'bottle'; \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java index 01eb1c77..468356f0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -193,6 +193,7 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("crackable_subscription_box", InteractionRedeemableSubscriptionBox.class)); this.interactionsList.add(new ItemInteraction("random_state", InteractionRandomState.class)); this.interactionsList.add(new ItemInteraction("vendingmachine_no_sides", InteractionNoSidesVendingMachine.class)); + this.interactionsList.add(new ItemInteraction("spinning_bottle", InteractionSpinningBottle.class)); this.interactionsList.add(new ItemInteraction("game_timer", InteractionGameTimer.class)); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java new file mode 100644 index 00000000..e3e62bbb --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java @@ -0,0 +1,89 @@ +package com.eu.habbo.habbohotel.items.interactions; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomLayout; +import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.plugin.events.furniture.FurnitureDiceRolledEvent; +import com.eu.habbo.threading.runnables.RandomSpinningBottleNumber; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionSpinningBottle extends HabboItem { + public InteractionSpinningBottle(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + public InteractionSpinningBottle(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + @Override + public void serializeExtradata(ServerMessage serverMessage) { + serverMessage.appendInt((this.isLimited() ? 256 : 0)); + serverMessage.appendString(this.getExtradata()); + + super.serializeExtradata(serverMessage); + } + + @Override + public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { + return true; + } + + @Override + public boolean isWalkable() { + return false; + } + + @Override + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + super.onClick(client, room, objects); + + if (client != null) { + if (RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), client.getHabbo().getRoomUnit().getCurrentLocation())) { + if (!this.getExtradata().equalsIgnoreCase("-1")) { + FurnitureDiceRolledEvent event = Emulator.getPluginManager().fireEvent(new FurnitureDiceRolledEvent(this, client.getHabbo(), -1)); + + if (event.isCancelled()) + return; + + this.setExtradata("-1"); + room.updateItemState(this); + Emulator.getThreading().run(this); + + if (event.getResult() > 0) { + Emulator.getThreading().run(new RandomSpinningBottleNumber(room, this, event.getResult()), 1500); + } else { + Emulator.getThreading().run(new RandomSpinningBottleNumber(this, room, this.getBaseItem().getStateCount()), 1500); + } + } + } + } + } + + @Override + public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) { + + } + + @Override + public void onPickUp(Room room) { + this.setExtradata("0"); + } + + @Override + public boolean allowWiredResetState() { + return false; + } + + @Override + public boolean isUsable() { + return true; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java index f348a4e6..9f1cfd7f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java @@ -243,7 +243,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers { return; } - if ((this.getBaseItem().getStateCount() > 1 && !(this instanceof InteractionDice)) || Arrays.asList(HabboItem.TOGGLING_INTERACTIONS).contains(this.getClass()) || (objects != null && objects.length == 1 && objects[0].equals("TOGGLE_OVERRIDE"))) { + if ((this.getBaseItem().getStateCount() > 1 && !(this instanceof InteractionDice) || !(this instanceof InteractionSpinningBottle)) || Arrays.asList(HabboItem.TOGGLING_INTERACTIONS).contains(this.getClass()) || (objects != null && objects.length == 1 && objects[0].equals("TOGGLE_OVERRIDE"))) { WiredHandler.handle(WiredTriggerType.STATE_CHANGED, client.getHabbo().getRoomUnit(), room, new Object[]{this}); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java index 00c85cde..f04ddc35 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionDice; +import com.eu.habbo.habbohotel.items.interactions.InteractionSpinningBottle; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.users.HabboItem; @@ -20,7 +21,7 @@ public class ThrowDiceEvent extends MessageHandler { HabboItem item = room.getHabboItem(itemId); if (item != null) { - if (item instanceof InteractionDice) { + if (item instanceof InteractionDice || item instanceof InteractionSpinningBottle) { if (RoomLayout.tilesAdjecent(room.getLayout().getTile(item.getX(), item.getY()), this.client.getHabbo().getRoomUnit().getCurrentLocation())) { item.onClick(this.client, room, new Object[]{}); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java index 215c7c5e..e500c8c7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionDice; +import com.eu.habbo.habbohotel.items.interactions.InteractionSpinningBottle; import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionMonsterPlantSeed; import com.eu.habbo.habbohotel.pets.MonsterplantPet; @@ -36,7 +37,7 @@ public class UseFurnitureEvent extends MessageHandler { HabboItem item = room.getHabboItem(itemId); - if (item == null || item instanceof InteractionDice) + if (item == null || item instanceof InteractionDice || item instanceof InteractionSpinningBottle) return; Event furnitureToggleEvent = new FurnitureToggleEvent(item, this.client.getHabbo(), state); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java b/src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java new file mode 100644 index 00000000..53f17b63 --- /dev/null +++ b/src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java @@ -0,0 +1,39 @@ +package com.eu.habbo.threading.runnables; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboItem; + +public class RandomSpinningBottleNumber implements Runnable { + private final HabboItem item; + private final Room room; + private final int maxNumber; + private int result; + + public RandomSpinningBottleNumber(HabboItem item, Room room, int maxNumber) { + this.item = item; + this.room = room; + this.maxNumber = maxNumber; + this.result = -1; + } + + public RandomSpinningBottleNumber(Room room, HabboItem item, int result) { + this.item = item; + this.room = room; + this.maxNumber = -1; + this.result = result; + } + + @Override + public void run() { + if (this.result <= 0) + this.result = Emulator.getRandom().nextInt(this.maxNumber); + + this.item.setExtradata(this.result + ""); + this.item.needsUpdate(true); + Emulator.getThreading().run(this.item); + + this.room.updateItem(this.item); + } +} +