RuneHive-Game
Loading...
Searching...
No Matches
Simulation.java
Go to the documentation of this file.
1package com.runehive.content.simulator;
2
3import com.runehive.content.activity.impl.barrows.BarrowsUtility;
4import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
5import com.runehive.game.world.entity.mob.npc.drop.NpcDrop;
6import com.runehive.game.world.entity.mob.npc.drop.NpcDropManager;
7import com.runehive.game.world.entity.mob.npc.drop.NpcDropTable;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.game.world.items.Item;
10import com.runehive.game.world.items.containers.pricechecker.PriceType;
11import com.runehive.net.packet.out.SendItemOnInterface;
12import com.runehive.net.packet.out.SendScrollbar;
13import com.runehive.net.packet.out.SendString;
14import com.runehive.util.RandomGen;
15import com.runehive.util.Utility;
16
17import java.util.*;
18
19/**
20 * Created by Daniel on 2018-02-03.
21 */
22public enum Simulation implements SimulationFunction {
24 @Override
25 public void execute(Player player, int id, int amount) {
26 Map<Integer, Integer> items = new HashMap<>();
27 int count = 0;
28 long value = 0;
29
30 for (int index = 0; index < amount; index++) {
31 Item money = new Item(13307, Utility.random(5000, 8000));
32 value += money.getValue() * money.getAmount();
33
34 if (items.containsKey(money.getId())) {
35 int toAdd = items.get(money.getId()) + money.getAmount();
36
37 items.replace(money.getId(), toAdd);
38 } else {
39 items.put(money.getId(), money.getAmount());
40 }
41 count++;
42
44 value += piece.getValue() * piece.getAmount();
45 if (items.containsKey(piece.getId())) {
46 int toAdd = items.get(piece.getId()) + piece.getAmount();
47 items.replace(piece.getId(), toAdd);
48 } else {
49 items.put(piece.getId(), piece.getAmount());
50 }
51 count++;
52 }
53
54 Iterator it = items.entrySet().iterator();
55 while (it.hasNext()) {
56 Map.Entry pair = (Map.Entry) it.next();
57 int mapValue = (int) pair.getValue();
58
59
60
61 Item item = new Item((int) pair.getKey(), (int) pair.getValue());
62
63
64
65 System.out.println(pair.getKey() + " = " + pair.getValue());
66// player.send(new SendItemOnInterfaceSlot(26816, item, count));
67 it.remove();
68 count++;
69 }
70
71 int scroll = (items.size() / 6 + (items.size() % 6 > 0 ? 1 : 0)) * 44;
72 player.send(new SendString(amount, 26811, true));
73 player.send(new SendString("<col=C1A875>Blood Money Chest", 26806));
74 player.send(new SendString("Simulated <col=C1A875>" + Utility.formatDigits(amount) + "</col> drops", 26807));
75 player.send(new SendString("Total value: <col=01FF80>" + Utility.formatDigits(value) + "</col>", 26808));
76 player.send(new SendScrollbar(26815, scroll));
77 player.attributes.set("DROP_SIMULATOR_CUSTOM_KEY", 0);
78 }
79 },
81 @Override
82 public void execute(Player player, int id, int amount) {
83 if (amount > 100_000) {
84 amount = 100_000;
85 }
87 if (npc == null)
88 return;
90 if (drop == null)
91 return;
92 Map<Integer, Item> items = new HashMap<>();
93 long value = 0;
94 for (int index = 0; index < amount; index++) {
95 List<NpcDrop> npc_drops = drop.generate(player, true);
96 RandomGen gen = new RandomGen();
97 for (NpcDrop drops : npc_drops) {
98 Item item = drops.toItem(gen);
99 value += item.getValue(PriceType.VALUE) * item.getAmount();
100 items.compute(item.getId(), (key, val) -> val == null ? item : val.getId() == item.getId() ? val.createAndIncrement(item.getAmount()) : val);
101 }
102 }
103
104 List<Item> sorted = new ArrayList<>(items.values());
105 sorted.sort((first, second) -> second.getValue() - first.getValue());
106
107 player.attributes.set("DROP_SIMULATOR_SORTED_LIST", sorted.toArray(new Item[0]));
108 int scroll = (items.size() / 6 + (items.size() % 6 > 0 ? 1 : 0)) * 44;
109 player.send(new SendScrollbar(26815, scroll));
110 player.send(new SendItemOnInterface(26816, sorted.toArray(new Item[0])));
111 player.send(new SendString(amount, 26811, true));
112 player.send(new SendString("<col=C1A875>" + npc.getName(), 26806));
113 player.send(new SendString("Simulated <col=C1A875>" + Utility.formatDigits(amount) + "</col> drops", 26807));
114 player.send(new SendString("Total value: <col=01FF80>" + Utility.formatDigits(value) + "</col>", 26808));
115 player.attributes.set("DROP_SIMULATOR_KEY", id);
116 }
117 }
118}
119
121
122 void execute(Player player, int id, int amount);
123
124}
final GenericAttributes attributes
Definition Mob.java:95
static NpcDefinition get(int id)
Gets a npc definition from the definition array.
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.
List< NpcDrop > generate(Player player, boolean simulated)
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 int getAmount()
Gets the quantity of this item.
Definition Item.java:342
int getValue(PriceType type)
Gets the value for this item.
Definition Item.java:98
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
The ThreadLocalRandom wrapper that provides additional functionality for generating pseudo-random num...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
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 > 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)