RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
DropDisplay.java
1package com.osroyale.content;
2
3import com.osroyale.game.world.entity.mob.npc.definition.NpcDefinition;
4import com.osroyale.game.world.entity.mob.npc.drop.NpcDrop;
5import com.osroyale.game.world.entity.mob.npc.drop.NpcDropManager;
6import com.osroyale.game.world.entity.mob.npc.drop.NpcDropTable;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.items.Item;
9import com.osroyale.game.world.items.ItemDefinition;
10import com.osroyale.net.packet.out.SendItemOnInterfaceSlot;
11import com.osroyale.net.packet.out.SendScrollbar;
12import com.osroyale.net.packet.out.SendString;
13import com.osroyale.net.packet.out.SendTooltip;
14import com.osroyale.util.Utility;
15
16import java.util.ArrayList;
17import java.util.List;
18import java.util.Map;
19
46
47public class DropDisplay {
48
49public enum DropType {
50 ITEM,
51 NPC
52 }
53
54 private static final String[] DEFAULT = {
55 "King black dragon",
56 "Skotizo",
57 "Zulrah",
58 "Callisto",
59 "Commander",
60 "Vene",
61 "Kraken",
62 "Chaos fanatic",
63 "Scorpia",
64 "Corporeal beast",
65 "Lizard shaman",
66 "Cerberus",
67 "Vorkath",
68 "Skeletal wyverns",
69 };
70
71 public static void open(Player player) {
72 search(player, Utility.randomElement(DEFAULT), DropType.NPC);
73 List<Integer> key = player.attributes.get("DROP_DISPLAY_KEY", List.class);
74 display(player, NpcDropManager.NPC_DROPS.get(key.get(0)));
75 player.interfaceManager.open(54500);
76 }
77
78 public static void search(Player player, String context, DropType type) {
79 context = context.trim().toLowerCase();
80 List<String> npc = new ArrayList<>();
81 List<Integer> integer = new ArrayList<>();
82 for (Map.Entry<Integer, NpcDropTable> drop : NpcDropManager.NPC_DROPS.entrySet()) {
83 NpcDropTable definition = drop.getValue();
84 if (NpcDefinition.get(definition.npcIds[0]) == null)
85 continue;
86 String name = NpcDefinition.get(definition.npcIds[0]).getName();
87 if (type == DropType.NPC) {
88 if (name.toLowerCase().contains(context)) {
89 if (!npc.contains(name)) {
90 npc.add(name);
91 integer.add(definition.npcIds[0]);
92 }
93 }
94 } else if (type == DropType.ITEM) {
95 for (NpcDrop item : definition.drops) {
96 String itemName = ItemDefinition.get(item.id).getName();
97 if (itemName.toLowerCase().contains(context)) {
98 if (!npc.contains(name)) {
99 npc.add(name);
100 integer.add(definition.npcIds[0]);
101 }
102 }
103 }
104 }
105 }
106
107 if (integer.isEmpty()) {
108 player.dialogueFactory.sendStatement("No search was found for your entry!").execute();
109 return;
110 }
111
112 int size = npc.size() < 10 ? 10 : npc.size();
113 for (int index = 0, string = 54516; index < size; index++, string += 2) {
114 if (string >= 54551)
115 break;
116 String name = index >= npc.size() ? "" : npc.get(index);
117 player.send(new SendTooltip(name.isEmpty() ? "" : "View drop table of <col=ff9933>" + name, string));
118 player.send(new SendString(name, string + 1));
119 }
120
121 player.attributes.set("DROP_DISPLAY_KEY", integer);
122 player.send(new SendScrollbar(54515, 280));
123 display(player, NpcDropManager.NPC_DROPS.get(0));
124 }
125
126 public static void display(Player player, NpcDropTable definition) {
127 int size = definition == null ? 9 : definition.drops.length < 9 ? 9 : definition.drops.length;
128 player.send(new SendScrollbar(54550, definition == null ? 350 : (size * 32)));
129 player.send(new SendString(definition == null ? "" : "Drops: " + definition.drops.length, 54514));
130 player.send(new SendString(definition == null ? "" : "" + NpcDefinition.get(definition.npcIds[0]).getName(), 54513));
131 for (int index = 0, string = 54552; index < size; index++) {
132 boolean valid = definition != null && (index < definition.drops.length && (NpcDefinition.get(definition.npcIds[0]) != null));
133 NpcDrop drop = valid ? definition.drops[index] : null;
134 Item item = valid ? new Item(drop.id, drop.maximum) : null;
135 player.send(new SendItemOnInterfaceSlot(54551, item, index));
136 string++;
137 player.send(new SendString(!valid ? "" : item.getName(), string));
138// player.send(new SendString(!valid ? "" : item.getName() + " (<col=ffffff>" + item.getId() + "</col>)", string));
139 string++;
140 player.send(new SendString(!valid ? "" : Utility.formatDigits(drop.minimum), string));
141 string++;
142 player.send(new SendString(!valid ? "" : Utility.formatDigits(drop.maximum), string));
143 string++;
144 player.send(new SendString(!valid ? "" : drop.type.toString(), string));
145 string++;
146 }
147 }
148}
final DialogueFactory sendStatement(String... lines)
static String formatDigits(final int amount)
Definition Utility.java:78
static< T > T randomElement(Collection< T > collection)
Definition Utility.java:285