Merge branch 'improvement/walk-to-pet-upon-scratching' into 'dev'

Avatar now walks to the nearest adjacent tile before scratching a pet #1886

See merge request morningstar/Arcturus-Community!96
This commit is contained in:
ArpyAge 2024-10-17 22:34:45 +00:00
commit c9549f1606

View File

@ -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.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
import java.util.ArrayList;
import java.util.List;
public class ScratchPetEvent extends MessageHandler {
@ -11,21 +18,34 @@ public class ScratchPetEvent extends MessageHandler {
public void handle() throws Exception {
final int petId = this.packet.readInt();
if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) {
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;
}
final Pet pet = room.getPet(petId);
if (pet == null) {
return;
}
if (this.client.getHabbo().getHabboStats().petRespectPointsToGive > 0 || pet instanceof MonsterplantPet) {
pet.scratched(this.client.getHabbo());
if (habbo.getHabboStats().petRespectPointsToGive > 0 || pet instanceof MonsterplantPet) {
// Update the stats to the database.
Emulator.getThreading().run(pet);
List<Runnable> tasks = new ArrayList<>();
tasks.add(() -> {
pet.scratched(habbo);
Emulator.getThreading().run(pet);
});
RoomTile closestTile = habbo.getRoomUnit().getClosestAdjacentTile(pet.getRoomUnit().getX(), pet.getRoomUnit().getY(), true);
if (closestTile != null) {
habbo.getRoomUnit().setGoalLocation(closestTile);
Emulator.getThreading().run(new RoomUnitWalkToLocation(habbo.getRoomUnit(), closestTile, room, tasks, tasks));
}
}
}
}