Trampoline interaction

This commit is contained in:
brenoepic 2022-04-11 20:21:11 -03:00
parent c8d3308523
commit 7fef24fa85
11 changed files with 131 additions and 22 deletions

View File

@ -134,6 +134,7 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("pet_food", InteractionPetFood.class)); this.interactionsList.add(new ItemInteraction("pet_food", InteractionPetFood.class));
this.interactionsList.add(new ItemInteraction("pet_toy", InteractionPetToy.class)); this.interactionsList.add(new ItemInteraction("pet_toy", InteractionPetToy.class));
this.interactionsList.add(new ItemInteraction("pet_tree", InteractionPetTree.class)); this.interactionsList.add(new ItemInteraction("pet_tree", InteractionPetTree.class));
this.interactionsList.add(new ItemInteraction("pet_trampoline", InteractionPetTrampoline.class));
this.interactionsList.add(new ItemInteraction("breeding_nest", InteractionPetBreedingNest.class)); this.interactionsList.add(new ItemInteraction("breeding_nest", InteractionPetBreedingNest.class));
this.interactionsList.add(new ItemInteraction("obstacle", InteractionObstacle.class)); this.interactionsList.add(new ItemInteraction("obstacle", InteractionObstacle.class));
this.interactionsList.add(new ItemInteraction("monsterplant_seed", InteractionMonsterPlantSeed.class)); this.interactionsList.add(new ItemInteraction("monsterplant_seed", InteractionMonsterPlantSeed.class));

View File

@ -0,0 +1,102 @@
package com.eu.habbo.habbohotel.items.interactions.pets;
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.interactions.InteractionDefault;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.PetTasks;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.threading.runnables.PetClearPosture;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionPetTrampoline extends InteractionDefault {
public InteractionPetTrampoline(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
}
public InteractionPetTrampoline(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.setExtradata("0");
}
@Override
public void onClick(GameClient client, Room room, Object[] objects) {}
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
this.setExtradata("0");
room.updateItem(this);
for (Pet pet : room.getPetsAt(oldLocation)) {
pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
pet.packetUpdate = true;
}
}
@Override
public void onPickUp(Room room) {
this.setExtradata("0");
for (Pet pet : room.getPetsOnItem(this)) {
pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
pet.packetUpdate = true;
}
}
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
Pet pet = room.getPet(roomUnit);
if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoal())) {
if (pet.getEnergy() <= 35) {
return;
}
pet.clearPosture();
pet.setTask(PetTasks.JUMP);
pet.getRoomUnit().setStatus(RoomUnitStatus.JUMP, "");
Emulator.getThreading().run(() -> {
new PetClearPosture(pet, RoomUnitStatus.JUMP, null, false);
pet.getRoomUnit().setGoalLocation(room.getRandomWalkableTile());
this.setExtradata("0");
room.updateItemState(this);
}, 4000);
pet.addHappyness(25);
this.setExtradata("1");
room.updateItemState(this);
}
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOff(roomUnit, room, objects);
Pet pet = room.getPet(roomUnit);
if (pet != null) {
this.setExtradata("0");
room.updateItem(this);
pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
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
public boolean allowWiredResetState() {
return false;
}
}

View File

@ -389,9 +389,7 @@ public class Pet implements ISerialize, Runnable {
keys.put(RoomUnitStatus.GESTURE, this.roomUnit.getStatus(RoomUnitStatus.GESTURE)); keys.put(RoomUnitStatus.GESTURE, this.roomUnit.getStatus(RoomUnitStatus.GESTURE));
if (this.task == null) { if (this.task == null) {
boolean isDead = false; boolean isDead = this.roomUnit.hasStatus(RoomUnitStatus.RIP);
if (this.roomUnit.hasStatus(RoomUnitStatus.RIP))
isDead = true;
this.roomUnit.clearStatus(); this.roomUnit.clearStatus();
@ -505,8 +503,8 @@ public class Pet implements ISerialize, Runnable {
return false; return false;
} }
public boolean findTree(PetTasks task) { public boolean findPetItem(PetTasks task, Class<? extends HabboItem> type) {
HabboItem item = this.petData.randomTreeItem(this.room.getRoomSpecialTypes().getItemsOfType(InteractionPetTree.class)); HabboItem item = this.petData.randomToyHabboItem(this.room.getRoomSpecialTypes().getItemsOfType(type));
if (item != null) { if (item != null) {
this.roomUnit.setCanWalk(true); this.roomUnit.setCanWalk(true);

View File

@ -230,18 +230,18 @@ public class PetData implements Comparable<PetData> {
return null; return null;
} }
public HabboItem randomTreeItem(THashSet<HabboItem> trees) { public HabboItem randomToyHabboItem(THashSet<HabboItem> items) {
List<HabboItem> treeList = new ArrayList<>(); List<HabboItem> itemList = new ArrayList<>();
for (HabboItem tree : trees) { for (HabboItem item : items) {
if (this.haveToyItem(tree)) { if (this.haveToyItem(item)) {
treeList.add(tree); itemList.add(item);
} }
} }
if (!treeList.isEmpty()) { if (!itemList.isEmpty()) {
Collections.shuffle(treeList); Collections.shuffle(itemList);
return treeList.get(0); return itemList.get(0);
} }
return null; return null;

View File

@ -208,7 +208,7 @@ public class PetManager {
PetData.generalFoodItems.add(baseItem); PetData.generalFoodItems.add(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetDrink.class) else if (baseItem.getInteractionType().getType() == InteractionPetDrink.class)
PetData.generalDrinkItems.add(baseItem); PetData.generalDrinkItems.add(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetToy.class || baseItem.getInteractionType().getType() == InteractionPetTree.class) else if (baseItem.getInteractionType().getType() == InteractionPetToy.class || baseItem.getInteractionType().getType() == InteractionPetTree.class || baseItem.getInteractionType().getType() == InteractionPetTrampoline.class)
PetData.generalToyItems.add(baseItem); PetData.generalToyItems.add(baseItem);
} else { } else {
PetData data = this.getPetData(set.getInt("pet_id")); PetData data = this.getPetData(set.getInt("pet_id"));
@ -220,7 +220,7 @@ public class PetManager {
data.addFoodItem(baseItem); data.addFoodItem(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetDrink.class) else if (baseItem.getInteractionType().getType() == InteractionPetDrink.class)
data.addDrinkItem(baseItem); data.addDrinkItem(baseItem);
else if (baseItem.getInteractionType().getType() == InteractionPetToy.class || baseItem.getInteractionType().getType() == InteractionPetTree.class) else if (baseItem.getInteractionType().getType() == InteractionPetToy.class || baseItem.getInteractionType().getType() == InteractionPetTree.class || baseItem.getInteractionType().getType() == InteractionPetTrampoline.class)
data.addToyItem(baseItem); data.addToyItem(baseItem);
} }
} }

View File

@ -18,7 +18,7 @@ public class ActionHang extends PetAction {
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { public boolean apply(Pet pet, Habbo habbo, String[] data) {
boolean findTree = pet.findTree(PetTasks.HANG); boolean findTree = pet.findPetItem(PetTasks.HANG, InteractionPetTree.class);
if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) {
pet.getRoomUnit().setCanWalk(false); pet.getRoomUnit().setCanWalk(false);
pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");

View File

@ -1,25 +1,29 @@
package com.eu.habbo.habbohotel.pets.actions; package com.eu.habbo.habbohotel.pets.actions;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetTrampoline;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetTree;
import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.PetAction; import com.eu.habbo.habbohotel.pets.PetAction;
import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.pets.PetTasks;
import com.eu.habbo.habbohotel.pets.PetVocalsType; import com.eu.habbo.habbohotel.pets.PetVocalsType;
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.threading.runnables.PetClearPosture; import com.eu.habbo.threading.runnables.PetClearPosture;
public class ActionJump extends PetAction { public class ActionJump extends PetAction {
public ActionJump() { public ActionJump() {
super(PetTasks.JUMP, true); super(null, false);
this.minimumActionDuration = 2000; this.minimumActionDuration = 2000;
this.statusToSet.add(RoomUnitStatus.JUMP);
} }
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { public boolean apply(Pet pet, Habbo habbo, String[] data) {
pet.clearPosture(); if(pet.findPetItem(PetTasks.JUMP, InteractionPetTrampoline.class)) return true;
pet.clearPosture();
pet.setTask(PetTasks.JUMP);
Emulator.getThreading().run(new PetClearPosture(pet, RoomUnitStatus.JUMP, null, false), this.minimumActionDuration); Emulator.getThreading().run(new PetClearPosture(pet, RoomUnitStatus.JUMP, null, false), this.minimumActionDuration);
if (pet.getHappyness() > 60) if (pet.getHappyness() > 60)

View File

@ -18,7 +18,7 @@ public class ActionRingOfFire extends PetAction {
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { public boolean apply(Pet pet, Habbo habbo, String[] data) {
boolean findTree = pet.findTree(PetTasks.RING_OF_FIRE); boolean findTree = pet.findPetItem(PetTasks.RING_OF_FIRE, InteractionPetTree.class);
if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) {
pet.getRoomUnit().setCanWalk(false); pet.getRoomUnit().setCanWalk(false);
pet.getRoomUnit().setStatus(RoomUnitStatus.RINGOFFIRE, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.RINGOFFIRE, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");

View File

@ -18,7 +18,7 @@ public class ActionRoll extends PetAction {
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { public boolean apply(Pet pet, Habbo habbo, String[] data) {
boolean findTree = pet.findTree(PetTasks.ROLL); boolean findTree = pet.findPetItem(PetTasks.ROLL, InteractionPetTree.class);
if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) {
pet.getRoomUnit().setCanWalk(false); pet.getRoomUnit().setCanWalk(false);
pet.getRoomUnit().setStatus(RoomUnitStatus.ROLL, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.ROLL, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");

View File

@ -18,7 +18,7 @@ public class ActionSwing extends PetAction {
@Override @Override
public boolean apply(Pet pet, Habbo habbo, String[] data) { public boolean apply(Pet pet, Habbo habbo, String[] data) {
boolean findTree = pet.findTree(PetTasks.SWING); boolean findTree = pet.findPetItem(PetTasks.SWING, InteractionPetTree.class);
if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) {
pet.getRoomUnit().setCanWalk(false); pet.getRoomUnit().setCanWalk(false);
pet.getRoomUnit().setStatus(RoomUnitStatus.SWING, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); pet.getRoomUnit().setStatus(RoomUnitStatus.SWING, pet.getRoomUnit().getCurrentLocation().getStackHeight() + "");

View File

@ -2394,6 +2394,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.roomSpecialTypes.addPetToy((InteractionPetToy) item); 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 InteractionPetTrampoline) {
this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionMoodLight) { } else if (item instanceof InteractionMoodLight) {
this.roomSpecialTypes.addUndefined(item); this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionPyramid) { } else if (item instanceof InteractionPyramid) {
@ -2548,6 +2550,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.roomSpecialTypes.removePetToy((InteractionPetToy) item); 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 InteractionPetTrampoline) {
this.roomSpecialTypes.removeUndefined(item);
} else if (item instanceof InteractionMoodLight) { } else if (item instanceof InteractionMoodLight) {
this.roomSpecialTypes.removeUndefined(item); this.roomSpecialTypes.removeUndefined(item);
} else if (item instanceof InteractionPyramid) { } else if (item instanceof InteractionPyramid) {