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 7fa15684..9627ea5e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -168,6 +168,7 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("youtube", InteractionYoutubeTV.class)); this.interactionsList.add(new ItemInteraction("jukebox", InteractionJukeBox.class)); this.interactionsList.add(new ItemInteraction("switch", InteractionSwitch.class)); + this.interactionsList.add(new ItemInteraction("switch_remote_control", InteractionSwitchRemoteControl.class)); this.interactionsList.add(new ItemInteraction("fx_box", InteractionFXBox.class)); this.interactionsList.add(new ItemInteraction("blackhole", InteractionBlackHole.class)); this.interactionsList.add(new ItemInteraction("effect_toggle", InteractionEffectToggle.class)); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitchRemoteControl.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitchRemoteControl.java new file mode 100644 index 00000000..e7fd1331 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitchRemoteControl.java @@ -0,0 +1,53 @@ +package com.eu.habbo.habbohotel.items.interactions; + +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.rooms.Room; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionSwitchRemoteControl extends InteractionDefault { + private static final Logger LOGGER = LoggerFactory.getLogger(InteractionSwitchRemoteControl.class); + + public InteractionSwitchRemoteControl(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public InteractionSwitchRemoteControl(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + + @Override + public boolean isUsable() { + return true; + } + + @Override + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + if (room != null) { + super.onClick(client, room, objects); + + if (this.getExtradata().isEmpty()) + this.setExtradata("0"); + + if (this.getBaseItem().getStateCount() > 0) { + int currentState = 0; + + try { + currentState = Integer.parseInt(this.getExtradata()); + } catch (NumberFormatException e) { + LOGGER.error("Incorrect extradata ({}) for item ID ({}) of type ({})", this.getExtradata(), this.getId(), this.getBaseItem().getName()); + } + + this.setExtradata("" + (currentState + 1) % this.getBaseItem().getStateCount()); + this.needsUpdate(true); + + room.updateItemState(this); + } + } + } +} diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/AddFloorItemComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/AddFloorItemComposer.java index b27e75d9..8ea9de9a 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/AddFloorItemComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/AddFloorItemComposer.java @@ -1,7 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.items.interactions.InteractionGift; -import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc; +import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; @@ -23,7 +22,7 @@ public class AddFloorItemComposer extends MessageComposer { this.response.appendInt(this.item instanceof InteractionGift ? ((((InteractionGift) this.item).getColorId() * 1000) + ((InteractionGift) this.item).getRibbonId()) : (this.item instanceof InteractionMusicDisc ? ((InteractionMusicDisc) this.item).getSongId() : 1)); this.item.serializeExtradata(this.response); this.response.appendInt(-1); - this.response.appendInt(this.item.isUsable()); + this.response.appendInt(this.item instanceof InteractionTeleport || this.item instanceof InteractionSwitch || this.item instanceof InteractionSwitchRemoteControl || this.item instanceof InteractionVendingMachine || this.item instanceof InteractionInformationTerminal || this.item instanceof InteractionPostIt|| this.item instanceof InteractionPuzzleBox ? 2 : this.item.isUsable() ? 1 : 0); this.response.appendInt(this.item.getUserId()); this.response.appendString(this.itemOwnerName); return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RoomFloorItemsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RoomFloorItemsComposer.java index 35210fa2..eb5a9d0f 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RoomFloorItemsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RoomFloorItemsComposer.java @@ -1,7 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.items.interactions.InteractionGift; -import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc; +import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; @@ -45,7 +44,7 @@ public class RoomFloorItemsComposer extends MessageComposer { this.response.appendInt(item instanceof InteractionGift ? ((((InteractionGift) item).getColorId() * 1000) + ((InteractionGift) item).getRibbonId()) : (item instanceof InteractionMusicDisc ? ((InteractionMusicDisc) item).getSongId() : 1)); item.serializeExtradata(this.response); this.response.appendInt(-1); - this.response.appendInt(item.isUsable() ? 1 : 0); + this.response.appendInt(item instanceof InteractionTeleport || item instanceof InteractionSwitch || item instanceof InteractionSwitchRemoteControl || item instanceof InteractionVendingMachine || item instanceof InteractionInformationTerminal || item instanceof InteractionPostIt || item instanceof InteractionPuzzleBox ? 2 : item.isUsable() ? 1 : 0); this.response.appendInt(item.getUserId()); } return this.response;