Merge branch 'fix-bottle-infinite-roll' into 'ms4/dev'

New InteractionSpinningBottle for spinning bottles

See merge request morningstar/Arcturus-Community!50
This commit is contained in:
John 2023-01-23 21:47:06 +00:00
commit 6944d4b73a
7 changed files with 136 additions and 3 deletions

View File

@ -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';

View File

@ -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));

View File

@ -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;
}
}

View File

@ -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});
}
}

View File

@ -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[]{});
}

View File

@ -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);

View File

@ -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);
}
}