From ab6d1ccac611708512f78e99307e901e54104cdb Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Sat, 28 Dec 2019 01:52:09 +0000 Subject: [PATCH] Totems --- .../habbo/habbohotel/items/ItemManager.java | 7 ++ .../totems/InteractionTotemHead.java | 85 +++++++++++++++++++ .../totems/InteractionTotemLegs.java | 56 ++++++++++++ .../totems/InteractionTotemPlanet.java | 85 +++++++++++++++++++ .../items/interactions/totems/TotemColor.java | 24 ++++++ .../interactions/totems/TotemPlanetType.java | 22 +++++ .../items/interactions/totems/TotemType.java | 24 ++++++ .../rooms/items/ToggleFloorItemEvent.java | 3 +- 8 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemColor.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemPlanetType.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemType.java 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 e0c533a7..a2d7f55c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -38,6 +38,9 @@ import com.eu.habbo.habbohotel.items.interactions.games.tag.bunnyrun.Interaction import com.eu.habbo.habbohotel.items.interactions.games.tag.icetag.InteractionIceTagField; import com.eu.habbo.habbohotel.items.interactions.games.tag.icetag.InteractionIceTagPole; import com.eu.habbo.habbohotel.items.interactions.games.tag.rollerskate.InteractionRollerskateField; +import com.eu.habbo.habbohotel.items.interactions.totems.InteractionTotemHead; +import com.eu.habbo.habbohotel.items.interactions.totems.InteractionTotemLegs; +import com.eu.habbo.habbohotel.items.interactions.totems.InteractionTotemPlanet; import com.eu.habbo.habbohotel.items.interactions.wired.conditions.*; import com.eu.habbo.habbohotel.items.interactions.wired.effects.*; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; @@ -357,6 +360,10 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("snowstorm_pile", null)); this.interactionsList.add(new ItemInteraction("vote_counter", InteractionVoteCounter.class)); + + this.interactionsList.add(new ItemInteraction("totem_leg", InteractionTotemLegs.class)); + this.interactionsList.add(new ItemInteraction("totem_head", InteractionTotemHead.class)); + this.interactionsList.add(new ItemInteraction("totem_planet", InteractionTotemPlanet.class)); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java new file mode 100644 index 00000000..65036015 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java @@ -0,0 +1,85 @@ +package com.eu.habbo.habbohotel.items.interactions.totems; + +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.wired.WiredEffectType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionTotemHead extends InteractionDefault { + + public InteractionTotemHead(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public InteractionTotemHead(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + public TotemType getTotemType() { + int extraData = Integer.parseInt(this.getExtradata()); + if(extraData < 3) { + return TotemType.fromInt(extraData + 1); + } + return TotemType.fromInt((int)Math.ceil((extraData - 2) / 4.0f)); + } + + public TotemColor getTotemColor() { + int extraData = Integer.parseInt(this.getExtradata()); + if(extraData < 3) { + return TotemColor.NONE; + } + return TotemColor.fromInt(extraData - 3 - (4 * (getTotemType().type - 1))); + } + + private void update(Room room, RoomTile tile) { + InteractionTotemLegs legs = null; + + for(HabboItem item : room.getItemsAt(tile)) { + if(item instanceof InteractionTotemLegs && item.getZ() < this.getZ()) + legs = (InteractionTotemLegs)item; + } + + if(legs == null) + return; + + this.setExtradata(((4 * this.getTotemType().type) + legs.getTotemColor().color) - 1 + ""); + } + + public void updateTotemState(Room room) { + updateTotemState(room, room.getLayout().getTile(this.getX(), this.getY())); + } + + public void updateTotemState(Room room, RoomTile tile) { + this.setExtradata(getTotemType().type - 1 + ""); + update(room, tile); + this.needsUpdate(true); + room.updateItem(this); + } + + @Override + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) + return; + + TotemType newType = TotemType.fromInt(getTotemType().type + 1); + if(newType == TotemType.NONE) { + newType = TotemType.TROLL; + } + + this.setExtradata(newType.type - 1 + ""); + + updateTotemState(room); + } + + @Override + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + super.onMove(room, oldLocation, newLocation); + updateTotemState(room, newLocation); + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java new file mode 100644 index 00000000..4070a876 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java @@ -0,0 +1,56 @@ +package com.eu.habbo.habbohotel.items.interactions.totems; + +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.wired.WiredEffectType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionTotemLegs extends InteractionDefault { + public InteractionTotemLegs(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public InteractionTotemLegs(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + public TotemType getTotemType() { + int extraData = Integer.parseInt(this.getExtradata()); + return TotemType.fromInt((int)Math.ceil((extraData + 1) / 4.0f)); + } + + public TotemColor getTotemColor() { + int extraData = Integer.parseInt(this.getExtradata()); + return TotemColor.fromInt(extraData - (4 * (getTotemType().type - 1))); + } + + private void updateHead(Room room, RoomTile tile) { + for(HabboItem item : room.getItemsAt(tile)) { + if(item instanceof InteractionTotemHead && item.getZ() > this.getZ()) + ((InteractionTotemHead)item).updateTotemState(room); + } + } + + @Override + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + super.onClick(client, room, objects); + + if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) + return; + + updateHead(room, room.getLayout().getTile(this.getX(), this.getY())); + } + + @Override + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + super.onMove(room, oldLocation, newLocation); + + updateHead(room, oldLocation); + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java new file mode 100644 index 00000000..bff2b26c --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java @@ -0,0 +1,85 @@ +package com.eu.habbo.habbohotel.items.interactions.totems; + +import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.inventory.EffectsComponent; +import com.eu.habbo.messages.outgoing.inventory.UserEffectsListComposer; +import gnu.trove.set.hash.THashSet; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionTotemPlanet extends InteractionDefault { + public InteractionTotemPlanet(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public InteractionTotemPlanet(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + public TotemPlanetType getPlanetType() { + int extraData = Integer.parseInt(this.getExtradata()); + return TotemPlanetType.fromInt(extraData); + } + + @Override + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + InteractionTotemLegs legs = null; + InteractionTotemHead head = null; + + THashSet items = room.getItemsAt(room.getLayout().getTile(this.getX(), this.getY())); + + for(HabboItem item : items) { + if(item instanceof InteractionTotemLegs && item.getZ() < this.getZ()) + legs = (InteractionTotemLegs)item; + } + + if(legs == null) { + super.onClick(client, room, objects); + return; + } + + for(HabboItem item : items) { + if(item instanceof InteractionTotemHead && item.getZ() > legs.getZ()) + head = (InteractionTotemHead)item; + } + + if(head == null) { + super.onClick(client, room, objects); + return; + } + + int effectId = 0; + + if(getPlanetType() == TotemPlanetType.SUN && head.getTotemType() == TotemType.BIRD && legs.getTotemType() == TotemType.BIRD && legs.getTotemColor() == TotemColor.RED) { + effectId = 25; + } + else if(getPlanetType() == TotemPlanetType.EARTH && head.getTotemType() == TotemType.TROLL && legs.getTotemType() == TotemType.TROLL && legs.getTotemColor() == TotemColor.YELLOW) { + effectId = 23; + } + else if(getPlanetType() == TotemPlanetType.EARTH && head.getTotemType() == TotemType.SNAKE && legs.getTotemType() == TotemType.BIRD && legs.getTotemColor() == TotemColor.YELLOW) { + effectId = 26; + } + else if(getPlanetType() == TotemPlanetType.MOON && head.getTotemType() == TotemType.SNAKE && legs.getTotemType() == TotemType.SNAKE && legs.getTotemColor() == TotemColor.BLUE) { + effectId = 24; + } + + if(effectId > 0) { + if(client.getHabbo().getInventory().getEffectsComponent().ownsEffect(effectId)) { + client.getHabbo().getInventory().getEffectsComponent().enableEffect(effectId); + return; + } + + client.getHabbo().getInventory().getEffectsComponent().createEffect(effectId); + client.sendResponse(new UserEffectsListComposer(client.getHabbo())); + client.getHabbo().getInventory().getEffectsComponent().enableEffect(effectId); + return; + } + + super.onClick(client, room, objects); + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemColor.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemColor.java new file mode 100644 index 00000000..340bb47f --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemColor.java @@ -0,0 +1,24 @@ +package com.eu.habbo.habbohotel.items.interactions.totems; + +public enum TotemColor { + + NONE(0), + RED(1), + YELLOW(2), + BLUE(3); + + public final int color; + + TotemColor(int color) { + this.color = color; + } + + public static TotemColor fromInt(int color) { + for(TotemColor totemColor : TotemColor.values()) { + if(totemColor.color == color) + return totemColor; + } + + return NONE; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemPlanetType.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemPlanetType.java new file mode 100644 index 00000000..bf8c7378 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemPlanetType.java @@ -0,0 +1,22 @@ +package com.eu.habbo.habbohotel.items.interactions.totems; + +public enum TotemPlanetType { + MOON(0), + SUN(1), + EARTH(2); + + public final int type; + + TotemPlanetType(int type) { + this.type = type; + } + + public static TotemPlanetType fromInt(int type) { + for(TotemPlanetType planetType : TotemPlanetType.values()) { + if(planetType.type == type) + return planetType; + } + + return MOON; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemType.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemType.java new file mode 100644 index 00000000..b82d909b --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/TotemType.java @@ -0,0 +1,24 @@ +package com.eu.habbo.habbohotel.items.interactions.totems; + +public enum TotemType { + + NONE(0), + TROLL(1), + SNAKE(2), + BIRD(3); + + public final int type; + + TotemType(int type) { + this.type = type; + } + + public static TotemType fromInt(int type) { + for(TotemType totemType : TotemType.values()) { + if(totemType.type == type) + return totemType; + } + + return NONE; + } +} diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java index 66f02e49..c64d111e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java @@ -31,6 +31,7 @@ public class ToggleFloorItemEvent extends MessageHandler { if (item == null || item instanceof InteractionDice) return; + /* if (item.getBaseItem().getName().equalsIgnoreCase("totem_planet")) { THashSet items = room.getItemsAt(room.getLayout().getTile(item.getX(), item.getY())); HabboItem totemLeg = null; @@ -75,7 +76,7 @@ public class ToggleFloorItemEvent extends MessageHandler { } } } - } + }*/ //Do not move to onClick(). Wired could trigger it. if (item instanceof InteractionMonsterPlantSeed) {