From 278da94db658316ea31c31c66846776b2fda0b34 Mon Sep 17 00:00:00 2001 From: brenoepic <59066707+brenoepics@users.noreply.github.com> Date: Mon, 11 Apr 2022 16:14:07 -0300 Subject: [PATCH] Fix pet drinks --- .../pets/InteractionPetDrink.java | 80 ++++++++++++++----- .../com/eu/habbo/habbohotel/pets/Pet.java | 11 ++- .../habbohotel/pets/actions/ActionDrink.java | 14 ++-- 3 files changed, 76 insertions(+), 29 deletions(-) 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 a18ada6b..2e3de3bb 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 @@ -2,21 +2,23 @@ package com.eu.habbo.habbohotel.items.interactions.pets; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; +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.pets.Pet; import com.eu.habbo.habbohotel.pets.PetTasks; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; -import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; +import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.threading.runnables.PetClearPosture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.sql.ResultSet; import java.sql.SQLException; public class InteractionPetDrink extends InteractionDefault { + private static final Logger LOGGER = LoggerFactory.getLogger(InteractionPetDrink.class); + + public InteractionPetDrink(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } @@ -25,28 +27,38 @@ public class InteractionPetDrink extends InteractionDefault { super(id, userId, item, extradata, limitedStack, limitedSells); } + @Override + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + this.change(room, 1); + } + @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); + if (this.getExtradata() == null || this.getExtradata().isEmpty()) + this.setExtradata("0"); + Pet pet = room.getPet(roomUnit); - if (pet != null) { - if (pet.getPetData().haveDrinkItem(this)) { - if (pet.levelThirst >= 35) { - pet.setTask(PetTasks.EAT); - pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); - pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().removeStatus(RoomUnitStatus.MOVE); - pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, "0"); - pet.addThirst(-75); - room.sendComposer(new RoomUserStatusComposer(roomUnit).compose()); - Emulator.getThreading().run(new PetClearPosture(pet, RoomUnitStatus.EAT, null, true), 500); + if (pet != null && pet.getPetData().haveDrinkItem(this) && pet.levelThirst >= 35) { + pet.clearPosture(); + pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); + pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.packetUpdate = true; + + Emulator.getThreading().run(() -> { + pet.addThirst(-75); + this.change(room, -1); + pet.getRoomUnit().clearStatus(); + new PetClearPosture(pet, RoomUnitStatus.EAT, null, true); + pet.packetUpdate = true; + }, 1000); + + AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetFeeding"), 75); - AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetFeeding"), 75); - } - } } } @@ -54,4 +66,32 @@ public class InteractionPetDrink extends InteractionDefault { public boolean allowWiredResetState() { return false; } + + private void change(Room room, int amount) { + int state = 0; + + if (this.getExtradata() == null || this.getExtradata().isEmpty()) { + this.setExtradata("0"); + } + + try { + state = Integer.parseInt(this.getExtradata()); + } catch (Exception e) { + LOGGER.error("Caught exception", e); + } + + state += amount; + if (state > this.getBaseItem().getStateCount() - 1) { + state = this.getBaseItem().getStateCount() - 1; + } + + if (state < 0) { + state = 0; + } + + this.setExtradata(state + ""); + this.needsUpdate(true); + room.updateItemState(this); + } + } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java index 883deb5d..70147f37 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java @@ -460,12 +460,19 @@ public class Pet implements ISerialize, Runnable { } - public void drink() { + public boolean drink() { HabboItem item = this.petData.randomDrinkItem(this.room.getRoomSpecialTypes().getPetDrinks()); if (item != null) { this.roomUnit.setCanWalk(true); - this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); + if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) { + try { + item.onWalkOn(this.getRoomUnit(), this.getRoom(), null); + } catch (Exception ignored) {} + } else { + this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); + } } + return item != null; } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDrink.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDrink.java index 7d56c1c2..274b4f9c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDrink.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDrink.java @@ -12,17 +12,17 @@ public class ActionDrink extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - if (pet.getLevelThirst() > 40) { - pet.drink(); + + if (pet.levelThirst < 35 || !pet.drink()) { + pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY)); + return false; + } if (pet.getLevelThirst() > 65) - pet.say(pet.getPetData().randomVocal(PetVocalsType.THIRSTY)); + pet.say(pet.getPetData().randomVocal(PetVocalsType.THIRSTY)); + else pet.say(pet.getPetData().randomVocal(PetVocalsType.DRINKING)); return true; - } else { - pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY)); - } - return false; } }