From ac60af6cc10656b85d803d41c2173cc4d87c5928 Mon Sep 17 00:00:00 2001 From: brenoepic <59066707+brenoepics@users.noreply.github.com> Date: Sat, 9 Apr 2022 00:19:20 -0300 Subject: [PATCH] Create ActionSwing.java --- .../habbohotel/pets/actions/ActionSwing.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java new file mode 100644 index 00000000..0f7b89f4 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java @@ -0,0 +1,70 @@ +package com.eu.habbo.habbohotel.pets.actions; + +import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetTree; +import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.PetAction; +import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.pets.PetVocalsType; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboItem; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; + +public class ActionSwing extends PetAction { + public ActionSwing() { + super(null, true); + } + + @Override + public boolean apply(Pet pet, Habbo habbo, String[] data) { + if (pet.getHappyness() < 50) { + pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY)); + return false; + } else { + + Set petTrees = pet.getRoom().getRoomSpecialTypes().getItemsOfType(InteractionPetTree.class); + + if (petTrees == null || petTrees.isEmpty()) { + pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY)); + return false; + } + + ArrayList tileList = new ArrayList<>(); + + for (HabboItem petTree : petTrees) { + if (petTree == null || petTree.getRoomId() != pet.getRoom().getId()) continue; + tileList.addAll(petTree.getOccupyingTiles(pet.getRoom().getLayout())); + } + + if (!tileList.isEmpty()) { + Collections.shuffle(tileList); + RoomTile goal = tileList.get(0); + pet.say(pet.getPetData().randomVocal(PetVocalsType.GENERIC_NEUTRAL)); + + if (goal == null || goal.state == RoomTileState.BLOCKED) { + goal = pet.getRoomUnit().getClosestTile(tileList); + } + pet.setTask(PetTasks.SWING); + if (goal.distance(pet.getRoomUnit().getCurrentLocation()) == 0) { + HabboItem tree = pet.getRoom().getItemsAt(goal).stream().filter(habboItem -> habboItem instanceof InteractionPetTree).findAny().orElse(null); + if (tree != null) { + try { + tree.onWalkOn(pet.getRoomUnit(), pet.getRoom(), null); + } catch (Exception ignored) {} + } else { + pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY)); + return false; + } + } else pet.getRoomUnit().setGoalLocation(goal); + return true; + } else { + pet.say(pet.getPetData().randomVocal(PetVocalsType.DISOBEY)); + return false; + } + } + } +} \ No newline at end of file