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 e62b1f0a..17b3c05c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -133,6 +133,7 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("pet_drink", InteractionPetDrink.class)); this.interactionsList.add(new ItemInteraction("pet_food", InteractionPetFood.class)); this.interactionsList.add(new ItemInteraction("pet_toy", InteractionPetToy.class)); + this.interactionsList.add(new ItemInteraction("pet_tree", InteractionPetTree.class)); this.interactionsList.add(new ItemInteraction("breeding_nest", InteractionPetBreedingNest.class)); this.interactionsList.add(new ItemInteraction("obstacle", InteractionObstacle.class)); this.interactionsList.add(new ItemInteraction("monsterplant_seed", InteractionMonsterPlantSeed.class)); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java new file mode 100644 index 00000000..9e273ebd --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java @@ -0,0 +1,108 @@ +package com.eu.habbo.habbohotel.items.interactions.pets; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; +import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; +import com.eu.habbo.threading.runnables.PetClearPosture; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionPetTree extends InteractionDefault { + public InteractionPetTree(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public InteractionPetTree(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + @Override + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + for (Pet pet : room.getPetsAt(oldLocation)) { + pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().setStatus(RoomUnitStatus.RELAX, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.packetUpdate = true; + } + } + @Override + public void onPickUp(Room room) { + for (Pet pet : room.getPetsOnItem(this)) { + pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().setStatus(RoomUnitStatus.RELAX, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.packetUpdate = true; + } + } + + @Override + public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { + Pet pet = room.getPet(roomUnit); + return (roomUnit.getRoomUnitType() == RoomUnitType.PET && pet != null && pet.getPetData().getType() == 12); + } + + @Override + public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { + super.onWalkOn(roomUnit, room, objects); + + Pet pet = room.getPet(roomUnit); + if (pet != null && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) { + RoomUnitStatus task = RoomUnitStatus.HANG; + switch(pet.getTask()){ + case RING_OF_FIRE: task = RoomUnitStatus.RINGOFFIRE; break; + case SWING: task = RoomUnitStatus.SWING; break; + case ROLL: task = RoomUnitStatus.ROLL; break; + } + + if (pet.getEnergy() >= 35 && task != RoomUnitStatus.HANG) { + + pet.getRoomUnit().setCanWalk(false); + pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().setStatus(task, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.packetUpdate = true; + RoomUnitStatus finalTask = task; + Emulator.getThreading().run(() -> { + pet.addHappyness(25); + pet.getRoomUnit().clearStatus(); + new PetClearPosture(pet, finalTask, null, true); + if (this.getRoomId() == room.getId() && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getCurrentLocation())) { + pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + } else { + pet.getRoomUnit().setStatus(RoomUnitStatus.RELAX, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + } + pet.getRoomUnit().setCanWalk(true); + pet.packetUpdate = true; + }, 2500 + (Emulator.getRandom().nextInt(20) * 500)); + } else { + pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.packetUpdate = true; + } + } + } + + @Override + public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { + super.onWalkOff(roomUnit, room, objects); + + Pet pet = room.getPet(roomUnit); + + if (pet != null) { + pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().setStatus(RoomUnitStatus.RELAX, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.packetUpdate = true; + } + } + @Override + public boolean allowWiredResetState() { + return false; + } +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index 09c54558..4958cefa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -20,10 +20,7 @@ import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.Interaction import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; -import com.eu.habbo.habbohotel.items.interactions.pets.InteractionNest; -import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetBreedingNest; -import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetDrink; -import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetFood; +import com.eu.habbo.habbohotel.items.interactions.pets.*; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; import com.eu.habbo.habbohotel.messenger.MessengerBuddy; import com.eu.habbo.habbohotel.permissions.Permission; @@ -2391,6 +2388,8 @@ public class Room implements Comparable, ISerialize, Runnable { this.roomSpecialTypes.addPetDrink((InteractionPetDrink) item); } else if (item instanceof InteractionPetFood) { this.roomSpecialTypes.addPetFood((InteractionPetFood) item); + } else if (item instanceof InteractionPetTree) { + this.roomSpecialTypes.addUndefined(item); } else if (item instanceof InteractionMoodLight) { this.roomSpecialTypes.addUndefined(item); } else if (item instanceof InteractionPyramid) { @@ -2921,6 +2920,27 @@ public class Room implements Comparable, ISerialize, Runnable { return false; } + public THashSet getPetsAt(RoomTile tile) { + THashSet pets = new THashSet<>(); + synchronized (this.currentPets) { + TIntObjectIterator petIterator = this.currentPets.iterator(); + + for (int i = this.currentPets.size(); i-- > 0; ) { + try { + petIterator.advance(); + + if (petIterator.value().getRoomUnit().getCurrentLocation().equals(tile)) { + pets.add(petIterator.value()); + } + } catch (Exception e) { + break; + } + } + } + + return pets; + } + public THashSet getBotsAt(RoomTile tile) { THashSet bots = new THashSet<>(); synchronized (this.currentBots) { @@ -2998,6 +3018,17 @@ public class Room implements Comparable, ISerialize, Runnable { return bots; } + public THashSet getPetsOnItem(HabboItem item) { + THashSet pets = new THashSet<>(); + for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) { + for (short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++) { + pets.addAll(this.getPetsAt(this.getLayout().getTile(x, y))); + } + } + + return pets; + } + public void teleportHabboToItem(Habbo habbo, HabboItem item) { this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); }