Feature: InteractionPetToy

This commit is contained in:
brenoepic 2022-04-11 14:45:14 -03:00
parent 0cc5b5cb73
commit f54d185772
2 changed files with 35 additions and 9 deletions

View File

@ -1,14 +1,12 @@
package com.eu.habbo.habbohotel.items.interactions.pets; package com.eu.habbo.habbohotel.items.interactions.pets;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
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.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.threading.runnables.PetClearPosture; import com.eu.habbo.threading.runnables.PetClearPosture;
@ -26,13 +24,30 @@ public class InteractionPetToy extends InteractionDefault {
this.setExtradata("0"); this.setExtradata("0");
} }
@Override
public void onClick(GameClient client, Room room, Object[] objects) {}
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
for (Pet pet : room.getPetsAt(oldLocation)) {
pet.getRoomUnit().clearStatus();
pet.packetUpdate = true;
}
}
@Override
public void onPickUp(Room room) {
for (Pet pet : room.getPetsOnItem(this)) {
pet.getRoomUnit().clearStatus();
pet.packetUpdate = true;
}
}
@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);
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
if (pet != null) { if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) {
if (pet.getEnergy() <= 35) { if (pet.getEnergy() <= 35) {
return; return;
} }
@ -41,15 +56,16 @@ public class InteractionPetToy extends InteractionDefault {
pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY()));
pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]);
pet.getRoomUnit().clearStatus(); pet.getRoomUnit().clearStatus();
pet.getRoomUnit().removeStatus(RoomUnitStatus.MOVE); pet.getRoomUnit().setStatus(RoomUnitStatus.PLAY, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");
pet.getRoomUnit().setStatus(RoomUnitStatus.PLAY, "0");
pet.packetUpdate = true; pet.packetUpdate = true;
HabboItem item = this; HabboItem item = this;
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
pet.addHappyness(25); pet.addHappyness(25);
item.setExtradata("0"); item.setExtradata("0");
room.updateItem(item); room.updateItem(item);
pet.getRoomUnit().clearStatus();
new PetClearPosture(pet, RoomUnitStatus.PLAY, null, true).run(); new PetClearPosture(pet, RoomUnitStatus.PLAY, null, true).run();
pet.packetUpdate = true;
}, 2500 + (Emulator.getRandom().nextInt(20) * 500)); }, 2500 + (Emulator.getRandom().nextInt(20) * 500));
this.setExtradata("1"); this.setExtradata("1");
room.updateItemState(this); room.updateItemState(this);
@ -63,11 +79,17 @@ public class InteractionPetToy extends InteractionDefault {
Pet pet = room.getPet(roomUnit); Pet pet = room.getPet(roomUnit);
if (pet != null) { if (pet != null) {
this.setExtradata("0"); pet.getRoomUnit().clearStatus();
room.updateItemState(this); pet.packetUpdate = true;
} }
} }
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
Pet pet = room.getPet(roomUnit);
return roomUnit.getRoomUnitType() == RoomUnitType.PET && pet != null && pet.getPetData().haveToyItem(this.getBaseItem());
}
@Override @Override
public boolean allowWiredResetState() { public boolean allowWiredResetState() {
return false; return false;

View File

@ -2390,6 +2390,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.roomSpecialTypes.addPetDrink((InteractionPetDrink) item); this.roomSpecialTypes.addPetDrink((InteractionPetDrink) item);
} else if (item instanceof InteractionPetFood) { } else if (item instanceof InteractionPetFood) {
this.roomSpecialTypes.addPetFood((InteractionPetFood) item); this.roomSpecialTypes.addPetFood((InteractionPetFood) item);
} else if (item instanceof InteractionPetToy) {
this.roomSpecialTypes.addPetToy((InteractionPetToy) item);
} else if (item instanceof InteractionPetTree) { } else if (item instanceof InteractionPetTree) {
this.roomSpecialTypes.addUndefined(item); this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionMoodLight) { } else if (item instanceof InteractionMoodLight) {
@ -2542,6 +2544,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.roomSpecialTypes.removePetDrink((InteractionPetDrink) item); this.roomSpecialTypes.removePetDrink((InteractionPetDrink) item);
} else if (item instanceof InteractionPetFood) { } else if (item instanceof InteractionPetFood) {
this.roomSpecialTypes.removePetFood((InteractionPetFood) item); this.roomSpecialTypes.removePetFood((InteractionPetFood) item);
} else if (item instanceof InteractionPetToy) {
this.roomSpecialTypes.removePetToy((InteractionPetToy) item);
} else if (item instanceof InteractionPetTree) { } else if (item instanceof InteractionPetTree) {
this.roomSpecialTypes.removeUndefined(item); this.roomSpecialTypes.removeUndefined(item);
} else if (item instanceof InteractionMoodLight) { } else if (item instanceof InteractionMoodLight) {