RuneHive-Game
Loading...
Searching...
No Matches
DropSimulator.java
Go to the documentation of this file.
1package com.runehive.content.simulator;
2
3import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
4import com.runehive.game.world.entity.mob.npc.drop.NpcDropManager;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.net.packet.out.SendScrollbar;
7import com.runehive.net.packet.out.SendString;
8import com.runehive.net.packet.out.SendTooltip;
9import com.runehive.util.Utility;
10
11import java.util.ArrayList;
12import java.util.List;
13
14import static com.runehive.content.simulator.Simulation.BLOOD_MONEY_CHEST;
15
16/**
17 * This class simulates drops of an npc and places it on an itemcontainer.
18 *
19 * @author Daniel.
20 */
21public class DropSimulator {
22
23 /** The default NPCs that will have their drops simulated. */
24 private static final int[] DEFAULT = {3080};
25
26 public static final Simulation[] CUSTOM_SIMULATIONS = { };
27
28 /** Handles opening the drop simulator itemcontainer. */
29 public static void open(Player player) {
30 int npc = Utility.randomElement(DEFAULT);
31 String name = NpcDefinition.get(npc).getName();
32 drawList(player, name);
33 simulate(player, Simulation.NPC_DROP, npc, 100);
34 player.send(new SendString(name, 26810, true));
35 player.interfaceManager.open(26800);
36 }
37
38 /** Handles drawing the lsit of npcs based off the search context. */
39 public static void drawList(Player player, String context) {
40 for (int index = 0, string = 26851; index < CUSTOM_SIMULATIONS.length; index++, string++) {
41 Simulation simuation = CUSTOM_SIMULATIONS[index];
42 String name = Utility.formatEnum(simuation.name());
43
44 player.send(new SendTooltip("Open simulator for " + name, string));
45 player.send(new SendString(name, string));
46 }
47
48 List<String> npc = new ArrayList<>();
49 List<Integer> button = new ArrayList<>();
50 for (NpcDefinition definition : NpcDefinition.DEFINITIONS) {
51 if (npc.size() >= 50)
52 break;
53 if (definition == null)
54 continue;
55 if (!NpcDropManager.NPC_DROPS.containsKey(definition.getId())) {
56 continue;
57 }
58 if (!definition.getName().toLowerCase().contains(context.toLowerCase())) {
59 continue;
60 }
61 if (npc.contains(definition.getName()))
62 continue;
63 npc.add(definition.getName());
64 button.add(definition.getId());
65 }
66 int size = npc.size() < 14 ? 14 : npc.size();
67 for (int index = 0, string = 26851 + CUSTOM_SIMULATIONS.length; index < size; index++, string++) {
68 String name = index >= npc.size() ? "" : npc.get(index);
69 player.send(new SendTooltip(name.isEmpty() ? "" : "Open drop simulator for " + name, string));
70 player.send(new SendString(name, string));
71 }
72 player.attributes.set("DROP_SIMULATOR_BUTTON_KEY", button);
73 player.send(new SendScrollbar(26850, size * 15));
74 }
75
76 /** Handles displaying the simulated drops. */
77 public static void simulate(Player player, Simulation simulation, int id, int amount) {
78 simulation.execute(player, id, amount);
79 }
80}
This class simulates drops of an npc and places it on an itemcontainer.
static final int[] DEFAULT
The default NPCs that will have their drops simulated.
static void drawList(Player player, String context)
Handles drawing the lsit of npcs based off the search context.
static void simulate(Player player, Simulation simulation, int id, int amount)
Handles displaying the simulated drops.
static void open(Player player)
Handles opening the drop simulator itemcontainer.
final GenericAttributes attributes
Definition Mob.java:95
static NpcDefinition get(int id)
Gets a npc definition from the definition array.
static final NpcDefinition[] DEFINITIONS
The array of npc definitions.
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.
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
The OutgoingPacket that sends a string to a Players itemcontainer 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
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
Created by Daniel on 2018-02-03.
void execute(Player player, int id, int amount)