2020-02-06 13:01:21 +01:00
|
|
|
package com.eu.habbo.habbohotel.items.interactions.pets;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.Emulator;
|
|
|
|
import com.eu.habbo.habbohotel.achievements.AchievementManager;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.items.Item;
|
2018-09-12 18:45:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.pets.Pet;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.habbohotel.pets.PetManager;
|
|
|
|
import com.eu.habbo.habbohotel.pets.PetTasks;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.habbohotel.rooms.Room;
|
|
|
|
import com.eu.habbo.habbohotel.rooms.RoomUnit;
|
|
|
|
import com.eu.habbo.habbohotel.users.Habbo;
|
|
|
|
import com.eu.habbo.habbohotel.users.HabboItem;
|
|
|
|
import com.eu.habbo.messages.ServerMessage;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.messages.outgoing.rooms.pets.PetPackageNameValidationComposer;
|
|
|
|
import com.eu.habbo.messages.outgoing.rooms.pets.breeding.PetBreedingCompleted;
|
2018-07-06 15:30:00 +02:00
|
|
|
import com.eu.habbo.messages.outgoing.rooms.pets.breeding.PetBreedingResultComposer;
|
2018-12-22 11:39:00 +01:00
|
|
|
import com.eu.habbo.threading.runnables.QueryDeleteHabboItem;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public class InteractionPetBreedingNest extends HabboItem {
|
2018-09-12 18:45:00 +02:00
|
|
|
public Pet petOne = null;
|
|
|
|
public Pet petTwo = null;
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionPetBreedingNest(ResultSet set, Item baseItem) throws SQLException {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(set, baseItem);
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public InteractionPetBreedingNest(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
|
2018-07-06 15:30:00 +02:00
|
|
|
super(id, userId, item, extradata, limitedStack, limitedSells);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
|
2018-07-06 15:30:00 +02:00
|
|
|
return room.getPet(roomUnit) != null && !this.boxFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean isWalkable() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void serializeExtradata(ServerMessage serverMessage) {
|
2018-07-06 15:30:00 +02:00
|
|
|
serverMessage.appendInt((this.isLimited() ? 256 : 0));
|
|
|
|
serverMessage.appendString(this.getExtradata());
|
|
|
|
|
|
|
|
super.serializeExtradata(serverMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
|
2018-07-06 15:30:00 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
|
2018-09-12 18:45:00 +02:00
|
|
|
Pet pet = room.getPet(roomUnit);
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (pet != null) {
|
|
|
|
if (!this.boxFull()) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.addPet(pet);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.boxFull()) {
|
2018-12-22 11:39:00 +01:00
|
|
|
Habbo ownerPetOne = room.getHabbo(this.petOne.getUserId());
|
|
|
|
Habbo ownerPetTwo = room.getHabbo(this.petTwo.getUserId());
|
2018-07-06 15:30:00 +02:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (ownerPetOne != null && ownerPetTwo != null && this.petOne.getPetData().getType() == this.petTwo.getPetData().getType() && this.petOne.getPetData().getOffspringType() != -1) {
|
2018-12-22 11:39:00 +01:00
|
|
|
ownerPetTwo.getClient().sendResponse(new PetBreedingResultComposer(this.getId(), this.petOne.getPetData().getOffspringType(), this.petOne, ownerPetOne.getHabboInfo().getUsername(), this.petTwo, ownerPetTwo.getHabboInfo().getUsername()));
|
|
|
|
this.setExtradata("1");
|
|
|
|
room.updateItem(this);
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean addPet(Pet pet) {
|
|
|
|
if (this.petOne == null) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.petOne = pet;
|
2018-12-22 11:39:00 +01:00
|
|
|
this.petOne.getRoomUnit().setCanWalk(false);
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
2019-05-26 20:14:53 +02:00
|
|
|
} else if (this.petTwo == null && this.petOne != pet) {
|
2018-07-06 15:30:00 +02:00
|
|
|
this.petTwo = pet;
|
2018-12-22 11:39:00 +01:00
|
|
|
this.petTwo.getRoomUnit().setCanWalk(false);
|
2018-07-06 15:30:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean boxFull() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return this.petOne != null && this.petTwo != null;
|
|
|
|
}
|
|
|
|
|
2018-12-22 11:39:00 +01:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
|
2018-12-22 11:39:00 +01:00
|
|
|
if (this.petOne != null && this.petOne.getRoomUnit() == roomUnit) this.petOne = null;
|
|
|
|
if (this.petTwo != null && this.petTwo.getRoomUnit() == roomUnit) this.petTwo = null;
|
|
|
|
|
|
|
|
this.setExtradata("0");
|
|
|
|
room.updateItem(this);
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:30:00 +02:00
|
|
|
@Override
|
2019-05-26 20:14:53 +02:00
|
|
|
public boolean allowWiredResetState() {
|
2018-07-06 15:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-12-22 11:39:00 +01:00
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void stopBreeding(Habbo habbo) {
|
2018-12-22 11:39:00 +01:00
|
|
|
this.setExtradata("0");
|
|
|
|
habbo.getHabboInfo().getCurrentRoom().updateItem(this);
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.petOne != null) {
|
2018-12-22 11:39:00 +01:00
|
|
|
habbo.getClient().sendResponse(new PetPackageNameValidationComposer(this.getId(), PetPackageNameValidationComposer.CLOSE_WIDGET, ""));
|
|
|
|
}
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.petTwo.getUserId() != habbo.getHabboInfo().getId()) {
|
2018-12-22 11:39:00 +01:00
|
|
|
Habbo owner = this.petTwo.getRoom().getHabbo(this.petTwo.getUserId());
|
2019-05-26 20:14:53 +02:00
|
|
|
if (owner != null) {
|
2018-12-22 11:39:00 +01:00
|
|
|
owner.getClient().sendResponse(new PetPackageNameValidationComposer(this.getId(), PetPackageNameValidationComposer.CLOSE_WIDGET, ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.freePets();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
private void freePets() {
|
|
|
|
if (this.petOne != null) {
|
2018-12-22 11:39:00 +01:00
|
|
|
this.petOne.getRoomUnit().setCanWalk(true);
|
|
|
|
this.petOne.setTask(PetTasks.FREE);
|
|
|
|
this.petOne = null;
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
if (this.petTwo != null) {
|
2018-12-22 11:39:00 +01:00
|
|
|
this.petTwo.getRoomUnit().setCanWalk(true);
|
|
|
|
this.petTwo.setTask(PetTasks.FREE);
|
|
|
|
this.petTwo = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:14:53 +02:00
|
|
|
public void breed(Habbo habbo, String name, int petOneId, int petTwoId) {
|
2019-05-16 00:39:39 +02:00
|
|
|
Emulator.getThreading().run(new QueryDeleteHabboItem(this.getId()));
|
2018-12-22 11:39:00 +01:00
|
|
|
|
|
|
|
this.setExtradata("2");
|
|
|
|
habbo.getHabboInfo().getCurrentRoom().updateItem(this);
|
|
|
|
|
|
|
|
HabboItem box = this;
|
|
|
|
Pet petOne = this.petOne;
|
|
|
|
Pet petTwo = this.petTwo;
|
2020-04-23 19:08:37 +02:00
|
|
|
Emulator.getThreading().run(() -> {
|
|
|
|
Pet offspring = Emulator.getGameEnvironment().getPetManager().createPet(petOne.getPetData().getOffspringType(), (int) Math.min(Math.round(Math.max(1d, PetManager.getNormalDistributionForBreeding(petOne.getLevel(), petTwo.getLevel()).sample())), 20), name, habbo.getClient());
|
|
|
|
|
|
|
|
//habbo.getClient().sendResponse(new PetPackageNameValidationComposer(box.getId(), PetPackageNameValidationComposer.CLOSE_WIDGET, ""));
|
|
|
|
habbo.getHabboInfo().getCurrentRoom().placePet(offspring, box.getX(), box.getY(), box.getZ(), box.getRotation());
|
|
|
|
offspring.needsUpdate = true;
|
|
|
|
offspring.run();
|
|
|
|
InteractionPetBreedingNest.this.freePets();
|
|
|
|
habbo.getHabboInfo().getCurrentRoom().removeHabboItem(box);
|
|
|
|
habbo.getClient().sendResponse(new PetBreedingCompleted(offspring.getId(), Emulator.getGameEnvironment().getPetManager().getRarityForOffspring(offspring)));
|
|
|
|
|
|
|
|
if (box.getBaseItem().getName().startsWith("pet_breeding_")) {
|
|
|
|
String boxType = box.getBaseItem().getName().replace("pet_breeding_", "");
|
|
|
|
String achievement = boxType.substring(0, 1).toUpperCase() + boxType.substring(1) + "Breeder";
|
|
|
|
AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement(achievement));
|
2018-12-22 11:39:00 +01:00
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
}
|
2018-07-06 15:30:00 +02:00
|
|
|
}
|