From 22810c13e6642c105efdd465f1c3b34b32936583 Mon Sep 17 00:00:00 2001 From: Yordi Date: Tue, 17 Jan 2023 11:30:25 +0100 Subject: [PATCH] Avatar will walk to an adjacent tile before scratching the pet #1886 --- .../incoming/rooms/pets/RespectPetEvent.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java index baf8bfb7..23ea7f00 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java @@ -3,7 +3,14 @@ package com.eu.habbo.messages.incoming.rooms.pets; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.pets.MonsterplantPet; import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; +import com.eu.habbo.habbohotel.users.Habbo; + +import java.util.ArrayList; +import java.util.List; public class RespectPetEvent extends MessageHandler { @@ -11,21 +18,29 @@ public class RespectPetEvent extends MessageHandler { public void handle() { final int petId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) { - return; - } + final Habbo habbo = this.client.getHabbo(); + if (habbo == null) { return; } - final Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); + final Room room = habbo.getHabboInfo().getCurrentRoom(); + if (room == null) { return; } - if (pet == null) { - return; - } + final Pet pet = room.getPet(petId); + if (pet == null) { return; } - if (this.client.getHabbo().getHabboStats().getPetRespectPointsToGive() > 0 || pet instanceof MonsterplantPet) { - pet.scratched(this.client.getHabbo()); + if (habbo.getHabboStats().getPetRespectPointsToGive() > 0 || pet instanceof MonsterplantPet) { - // Update the stats to the database. - Emulator.getThreading().run(pet); + List tasks = new ArrayList<>(); + tasks.add(() -> { + pet.scratched(habbo); + Emulator.getThreading().run(pet); + }); + + RoomTile tile = habbo.getRoomUnit().getClosestAdjacentTile(pet.getRoomUnit().getX(), pet.getRoomUnit().getY(), true); + if(tile != null) { + habbo.getRoomUnit().setGoalLocation(tile); + } + + Emulator.getThreading().run(new RoomUnitWalkToLocation(habbo.getRoomUnit(), tile, room, tasks, tasks)); } } -} +} \ No newline at end of file