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.Emulator;
import com.eu.habbo.habbohotel.achievements.AchievementManager; 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.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault;
import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.pets.PetTasks;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.*;
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.threading.runnables.PetClearPosture; import com.eu.habbo.threading.runnables.PetClearPosture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
public class InteractionPetDrink extends InteractionDefault { public class InteractionPetDrink extends InteractionDefault {
private static final Logger LOGGER = LoggerFactory.getLogger(InteractionPetDrink.class);
public InteractionPetDrink(ResultSet set, Item baseItem) throws SQLException { public InteractionPetDrink(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
} }
@ -25,28 +27,38 @@ public class InteractionPetDrink extends InteractionDefault {
super(id, userId, item, extradata, limitedStack, limitedSells); super(id, userId, item, extradata, limitedStack, limitedSells);
} }
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
this.change(room, 1);
}
@Override @Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects); super.onWalkOn(roomUnit, room, objects);
if (this.getExtradata() == null || this.getExtradata().isEmpty())
this.setExtradata("0");
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
if (pet != null) { if (pet != null && pet.getPetData().haveDrinkItem(this) && pet.levelThirst >= 35) {
if (pet.getPetData().haveDrinkItem(this)) { pet.clearPosture();
if (pet.levelThirst >= 35) { pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY()));
pet.setTask(PetTasks.EAT); pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]);
pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); pet.getRoomUnit().clearStatus();
pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
pet.getRoomUnit().clearStatus(); pet.packetUpdate = true;
pet.getRoomUnit().removeStatus(RoomUnitStatus.MOVE);
pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, "0"); Emulator.getThreading().run(() -> {
pet.addThirst(-75); pet.addThirst(-75);
room.sendComposer(new RoomUserStatusComposer(roomUnit).compose()); this.change(room, -1);
Emulator.getThreading().run(new PetClearPosture(pet, RoomUnitStatus.EAT, null, true), 500); 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() { public boolean allowWiredResetState() {
return false; 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,12 +460,19 @@ public class Pet implements ISerialize, Runnable {
} }
public void drink() { public boolean drink() {
HabboItem item = this.petData.randomDrinkItem(this.room.getRoomSpecialTypes().getPetDrinks()); HabboItem item = this.petData.randomDrinkItem(this.room.getRoomSpecialTypes().getPetDrinks());
if (item != null) { if (item != null) {
this.roomUnit.setCanWalk(true); 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;
} }

View File

@ -12,17 +12,17 @@ public class ActionDrink extends PetAction {
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { 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) 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; return true;
} else {
pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY));
}
return false;
} }
} }