From c8d33085230839c4c2bc8a70c972eacf163c2ac0 Mon Sep 17 00:00:00 2001 From: brenoepic <59066707+brenoepics@users.noreply.github.com> Date: Mon, 11 Apr 2022 17:51:37 -0300 Subject: [PATCH] Update InteractionPetDrink.java --- .../pets/InteractionPetDrink.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java index 2e3de3bb..0a140f9e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java @@ -8,12 +8,16 @@ 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.threading.runnables.PetClearPosture; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class InteractionPetDrink extends InteractionDefault { private static final Logger LOGGER = LoggerFactory.getLogger(InteractionPetDrink.class); @@ -27,9 +31,35 @@ public class InteractionPetDrink extends InteractionDefault { super(id, userId, item, extradata, limitedStack, limitedSells); } + @Override + public boolean canToggle(Habbo habbo, Room room) { + return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), habbo.getRoomUnit().getCurrentLocation()); + } + @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - this.change(room, 1); + if (client == null) + return; + + if (!this.canToggle(client.getHabbo(), room)) { + RoomTile closestTile = null; + for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) { + if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()))) { + closestTile = tile; + } + } + + if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) { + List onSuccess = new ArrayList<>(); + onSuccess.add(() -> { + this.change(room, this.getBaseItem().getStateCount() - 1); + }); + + client.getHabbo().getRoomUnit().setGoalLocation(closestTile); + Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), closestTile, room, onSuccess, new ArrayList<>())); + } + } + } @Override