RuneHive-Game
Loading...
Searching...
No Matches
DropDisplay.java
Go to the documentation of this file.
1package com.runehive.content;
2
3import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
4import com.runehive.game.world.entity.mob.npc.drop.NpcDrop;
5import com.runehive.game.world.entity.mob.npc.drop.NpcDropManager;
6import com.runehive.game.world.entity.mob.npc.drop.NpcDropTable;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.items.Item;
9import com.runehive.game.world.items.ItemDefinition;
10import com.runehive.net.packet.out.SendItemOnInterfaceSlot;
11import com.runehive.net.packet.out.SendScrollbar;
12import com.runehive.net.packet.out.SendString;
13import com.runehive.net.packet.out.SendTooltip;
14import com.runehive.util.Utility;
15
16import java.util.ArrayList;
17import java.util.List;
18import java.util.Map;
19
20/**
21 * Handles displaying the npc drops on an itemcontainer.
22 *
23 * @author Daniel
24 */
25public class DropDisplay {
26
27 public enum DropType {
30 }
31
32 private static final String[] DEFAULT = {
33 "King black dragon",
34 "Skotizo",
35 "Zulrah",
36 "Callisto",
37 "Commander",
38 "Vene",
39 "Kraken",
40 "Chaos fanatic",
41 "Scorpia",
42 "Corporeal beast",
43 "Lizard shaman",
44 "Cerberus",
45 "Vorkath",
46 "Skeletal wyverns",
47 };
48
49 public static void open(Player player) {
51 List<Integer> key = player.attributes.get("DROP_DISPLAY_KEY", List.class);
52 display(player, NpcDropManager.NPC_DROPS.get(key.get(0)));
53 player.interfaceManager.open(54500);
54 }
55
56 public static void search(Player player, String context, DropType type) {
57 context = context.trim().toLowerCase();
58 List<String> npc = new ArrayList<>();
59 List<Integer> integer = new ArrayList<>();
60 for (Map.Entry<Integer, NpcDropTable> drop : NpcDropManager.NPC_DROPS.entrySet()) {
61 NpcDropTable definition = drop.getValue();
62 if (NpcDefinition.get(definition.npcIds[0]) == null)
63 continue;
64 String name = NpcDefinition.get(definition.npcIds[0]).getName();
65 if (type == DropType.NPC) {
66 if (name.toLowerCase().contains(context)) {
67 if (!npc.contains(name)) {
68 npc.add(name);
69 integer.add(definition.npcIds[0]);
70 }
71 }
72 } else if (type == DropType.ITEM) {
73 for (NpcDrop item : definition.drops) {
74 String itemName = ItemDefinition.get(item.id).getName();
75 if (itemName.toLowerCase().contains(context)) {
76 if (!npc.contains(name)) {
77 npc.add(name);
78 integer.add(definition.npcIds[0]);
79 }
80 }
81 }
82 }
83 }
84
85 if (integer.isEmpty()) {
86 player.dialogueFactory.sendStatement("No search was found for your entry!").execute();
87 return;
88 }
89
90 int size = npc.size() < 10 ? 10 : npc.size();
91 for (int index = 0, string = 54516; index < size; index++, string += 2) {
92 if (string >= 54551)
93 break;
94 String name = index >= npc.size() ? "" : npc.get(index);
95 player.send(new SendTooltip(name.isEmpty() ? "" : "View drop table of <col=ff9933>" + name, string));
96 player.send(new SendString(name, string + 1));
97 }
98
99 player.attributes.set("DROP_DISPLAY_KEY", integer);
100 player.send(new SendScrollbar(54515, 280));
101 display(player, NpcDropManager.NPC_DROPS.get(0));
102 }
103
104 public static void display(Player player, NpcDropTable definition) {
105 int size = definition == null ? 9 : definition.drops.length < 9 ? 9 : definition.drops.length;
106 player.send(new SendScrollbar(54550, definition == null ? 350 : (size * 32)));
107 player.send(new SendString(definition == null ? "" : "Drops: " + definition.drops.length, 54514));
108 player.send(new SendString(definition == null ? "" : "" + NpcDefinition.get(definition.npcIds[0]).getName(), 54513));
109 for (int index = 0, string = 54552; index < size; index++) {
110 boolean valid = definition != null && (index < definition.drops.length && (NpcDefinition.get(definition.npcIds[0]) != null));
111 NpcDrop drop = valid ? definition.drops[index] : null;
112 Item item = valid ? new Item(drop.id, drop.maximum) : null;
113 player.send(new SendItemOnInterfaceSlot(54551, item, index));
114 string++;
115 player.send(new SendString(!valid ? "" : item.getName(), string));
116// player.send(new SendString(!valid ? "" : item.getName() + " (<col=ffffff>" + item.getId() + "</col>)", string));
117 string++;
118 player.send(new SendString(!valid ? "" : Utility.formatDigits(drop.minimum), string));
119 string++;
120 player.send(new SendString(!valid ? "" : Utility.formatDigits(drop.maximum), string));
121 string++;
122 player.send(new SendString(!valid ? "" : drop.type.toString(), string));
123 string++;
124 }
125 }
126}
Handles displaying the npc drops on an itemcontainer.
static void search(Player player, String context, DropType type)
static void display(Player player, NpcDropTable definition)
static final String[] DEFAULT
static void open(Player player)
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
final GenericAttributes attributes
Definition Mob.java:95
static NpcDefinition get(int id)
Gets a npc definition from the definition array.
final int maximum
The maximum amount of this drop.
Definition NpcDrop.java:25
NpcDropChance type
The chance this item is dropped.
Definition NpcDrop.java:12
final int minimum
The minimum amount of this drop.
Definition NpcDrop.java:22
The manager class which holds the static entries of drop tables and has a method to execute a drop ta...
static final Map< Integer, NpcDropTable > NPC_DROPS
The collection of npc ids by their representative drop tables.
The class which represents a npc drop table.
final NpcDrop[] drops
The cached array of NpcDrops.
final int[] npcIds
The npc ids that share this drop table.
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
The container class that represents an item that can be interacted with.
Definition Item.java:21
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
public< K, E > E get(K key)
Gets a generic attribute.
public< K, E > void set(K key, E attribute)
Sets a generic attribute.