From 54519ac4e4a6c27f3093e9c30bb80b69c0cea084 Mon Sep 17 00:00:00 2001 From: Swirny Date: Mon, 25 May 2020 21:29:39 +0200 Subject: [PATCH 1/2] Added RateLimit to ScratchPetEvent --- .../habbo/messages/incoming/rooms/pets/ScratchPetEvent.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java index 6189f3e8..84807035 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java @@ -5,6 +5,12 @@ import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.messages.incoming.MessageHandler; public class ScratchPetEvent extends MessageHandler { + + @Override + public int getRatelimit() { + return 1000; + } + @Override public void handle() throws Exception { int petId = this.packet.readInt(); From 2e98d5d21c1f334ff8ab521b0c680372a59ffde7 Mon Sep 17 00:00:00 2001 From: Mike <76-Mike@users.noreply.git.krews.org> Date: Sun, 7 Jun 2020 04:21:38 +0200 Subject: [PATCH 2/2] Proper monster plant fix --- .../habbohotel/pets/MonsterplantPet.java | 29 ++++++++++++++----- .../incoming/rooms/pets/ScratchPetEvent.java | 22 +++++++------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java b/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java index 7d4d0300..c362cf58 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java @@ -353,6 +353,19 @@ public class MonsterplantPet extends Pet implements IPetLook { } } + private boolean mayScratch() { + // Monsterplant petting is available when: + // ((energy / max_energy) < 0.98) = true + // You can find the minimum deathTimestamp by solving (insert a timestamp for timestamp, solve for death_timestamp): + // (((death_timestamp - timestamp) / 259200)) < 0.98 + // This information was found in the Habbo swf, com.sulake.habbo.ui.widget.infostand.InfoStandPetView.as + // this._Str_2304("pettreat", ((_local_3 / _local_4) < 0.98)); + final float energy = this.getEnergy(); + final float energyMax = this.getMaxEnergy(); + + return ((energy / energyMax) < 0.98); + } + @Override public int getMaxEnergy() { return MonsterplantPet.timeToLive; @@ -368,13 +381,15 @@ public class MonsterplantPet extends Pet implements IPetLook { } @Override - public void scratched(Habbo habbo) { - AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantTreater"), 5); - this.setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.timeToLive); - this.addHappyness(10); - this.addExperience(10); - this.room.sendComposer(new PetStatusUpdateComposer(this).compose()); - this.room.sendComposer(new RoomPetRespectComposer(this, RoomPetRespectComposer.PET_TREATED).compose()); + public synchronized void scratched(Habbo habbo) { + if (this.mayScratch()) { + AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantTreater"), 5); + this.setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.timeToLive); + this.addHappyness(10); + this.addExperience(10); + this.room.sendComposer(new PetStatusUpdateComposer(this).compose()); + this.room.sendComposer(new RoomPetRespectComposer(this, RoomPetRespectComposer.PET_TREATED).compose()); + } } @Override diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java index 84807035..4621c044 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ScratchPetEvent.java @@ -6,24 +6,22 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class ScratchPetEvent extends MessageHandler { - @Override - public int getRatelimit() { - return 1000; - } - @Override public void handle() throws Exception { - int petId = this.packet.readInt(); + final int petId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) { return; + } - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); + final Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); - if (pet != null) { - if (this.client.getHabbo().getHabboStats().petRespectPointsToGive > 0 || pet instanceof MonsterplantPet) { - pet.scratched(this.client.getHabbo()); - } + if (pet == null) { + return; + } + + if (this.client.getHabbo().getHabboStats().petRespectPointsToGive > 0 || pet instanceof MonsterplantPet) { + pet.scratched(this.client.getHabbo()); } } }