Proper monster plant fix

This commit is contained in:
Mike 2020-06-07 04:21:38 +02:00
parent 54519ac4e4
commit 2e98d5d21c
2 changed files with 32 additions and 19 deletions

View File

@ -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

View File

@ -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());
}
}
}