Fix pet drinks

This commit is contained in:
brenoepic 2022-04-11 16:14:07 -03:00
parent a11544ffdc
commit 278da94db6
3 changed files with 76 additions and 29 deletions

View File

@ -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);
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().removeStatus(RoomUnitStatus.MOVE);
pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, "0");
pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
pet.packetUpdate = true;
Emulator.getThreading().run(() -> {
pet.addThirst(-75);
room.sendComposer(new RoomUserStatusComposer(roomUnit).compose());
Emulator.getThreading().run(new PetClearPosture(pet, RoomUnitStatus.EAT, null, true), 500);
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);
}
}
}
}
@ -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);
}
}

View File

@ -460,13 +460,20 @@ 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);
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;
}
public void eat() {

View File

@ -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));
else pet.say(pet.getPetData().randomVocal(PetVocalsType.DRINKING));
return true;
} else {
pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY));
}
return false;
}
}