RuneHive-Game
Loading...
Searching...
No Matches
EmoteHandler.java
Go to the documentation of this file.
1package com.runehive.content.emote;
2
3import com.runehive.net.packet.out.SendConfig;
4import com.runehive.net.packet.out.SendMessage;
5import com.runehive.game.action.impl.EmoteAction;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.items.Item;
8import com.runehive.game.world.items.containers.equipment.Equipment;
9import com.runehive.util.Utility;
10
11import java.util.ArrayList;
12import java.util.Arrays;
13import java.util.List;
14
15/**
16 * This class handles emotes from the emote tab and skill cape.
17 *
18 * @author Daniel | Obey
19 */
20public class EmoteHandler {
21
22 /**
23 * Handles refreshing the emote tab.
24 *
25 * @param player
26 * The player refreshing the emote tab.
27 */
28 public static void refresh(Player player) {
29 for (Emote emote : Emote.values()) {
30 if (emote.getConfig() != -1) {
31 int flag = emote.activated(player) ? 0 : 1;
32 player.send(new SendConfig(emote.getConfig(), flag));
33 }
34 }
35 updateSkillcape(player);
36 }
37
38 /**
39 * Updates the skillcape emote.
40 *
41 * @param player
42 * The player instance.
43 */
44 public static void updateSkillcape(Player player) {
45 int flag = 1;
46 Item item = player.equipment.get(Equipment.CAPE_SLOT);
47
48 if (item != null) {
50 if (skillcape != null) {
51 flag = 0;
52 }
53 }
54
55 player.send(new SendConfig(1114, flag));
56 }
57
58 public static boolean contains(Player player, EmoteUnlockable emote) {
59 return player.emoteUnlockable.contains(emote);
60 }
61
62 public static boolean containsAll(Player player, EmoteUnlockable... emotes) {
63 for (EmoteUnlockable emote : emotes) {
64 if (!contains(player, emote)) {
65 return false;
66 }
67 }
68 return true;
69 }
70
71 public static EmoteUnlockable selectRandom(Player player, EmoteUnlockable... emotes) {
72 List<EmoteUnlockable> selected = new ArrayList<>(emotes.length);
73 for (EmoteUnlockable emote : emotes) {
74 if (!contains(player, emote)) {
75 selected.add(emote);
76 }
77 }
78 return selected.isEmpty() ? null : Utility.randomElement(selected);
79 }
80
81 /**
82 * Handles unlocking an emote.
83 *
84 * @param player
85 * the player unlocking the emote.
86 * @param emote
87 * The emote being activated.
88 */
89 public static void unlock(Player player, EmoteUnlockable emote) {
90 if (!player.emoteUnlockable.contains(emote)) {
91 player.emoteUnlockable.add(emote);
92 refresh(player);
93 player.send(new SendMessage("Congratulations, you have unlocked the " + Utility.formatEnum(emote.name()) + " emote."));
94 }
95 }
96
97 /**
98 * Handles unlocking all the emotes.
99 *
100 * @param player
101 * The player unlocking all the emotes.
102 */
103 public static void unlockAll(Player player) {
104 Arrays.stream(EmoteUnlockable.values()).forEach(e -> {
105 if (!player.emoteUnlockable.contains(e)) {
106 player.emoteUnlockable.add(e);
107 }
108 });
109 refresh(player);
110 player.send(new SendMessage("You have successfully unlocked all the emotes."));
111 }
112
113}
This class handles emotes from the emote tab and skill cape.
static void refresh(Player player)
Handles refreshing the emote tab.
static boolean contains(Player player, EmoteUnlockable emote)
static void updateSkillcape(Player player)
Updates the skillcape emote.
static void unlock(Player player, EmoteUnlockable emote)
Handles unlocking an emote.
static void unlockAll(Player player)
Handles unlocking all the emotes.
static boolean containsAll(Player player, EmoteUnlockable... emotes)
static EmoteUnlockable selectRandom(Player player, EmoteUnlockable... emotes)
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
final Item get(int index)
Gets the Item located on index.
The container that manages the equipment for a player.
The OutgoingPacket responsible for changing settings on a client.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
static String formatEnum(final String string)
Formats name of enum.
Definition Utility.java:89
Holds all the emote data.
Definition Emote.java:18
Holds the data for skillcape emotes.
static Skillcape forId(int id)