RuneHive-Game
Loading...
Searching...
No Matches
ItemsKeptOnDeath.java
Go to the documentation of this file.
1package com.runehive.content;
2
3import com.runehive.net.packet.out.SendItemOnInterface;
4import com.runehive.net.packet.out.SendString;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.entity.mob.prayer.Prayer;
7import com.runehive.game.world.items.Item;
8import com.runehive.game.world.items.ItemComparator;
9import com.runehive.game.world.items.containers.pricechecker.PriceType;
10import com.runehive.util.Utility;
11
12import java.math.BigInteger;
13import java.text.NumberFormat;
14import java.util.Locale;
15import java.util.PriorityQueue;
16import java.util.Queue;
17
18public class ItemsKeptOnDeath {
19
20 public static void open(Player player) {
21 int kept = 3;
22 if (player.skulling.isSkulled()) {
23 kept = player.prayer.isActive(Prayer.PROTECT_ITEM) ? 1 : 0;
24 } else {
25 kept = player.prayer.isActive(Prayer.PROTECT_ITEM) ? 4 : 3;
26 }
27
28 final Item[] keep = new Item[kept];
29
30 final Queue<Item> items = new PriorityQueue<Item>(ItemComparator.SHOP_VALUE_COMPARATOR);
31
32 for (final Item item : player.inventory.toArray()) {
33 if (item != null) {
34 items.add(item.copy());
35 }
36 }
37
38 for (final Item item : player.equipment.toArray()) {
39 if (item != null) {
40 items.add(item.copy());
41 }
42 }
43
44 final Queue<Item> temp = new PriorityQueue<>(items);
45
46 for (int index = 0, taken = 0; index < keep.length; index++) {
47 keep[index] = temp.poll();
48 items.remove(keep[index]);
49
50 if (keep[index] != null) {
51 if (keep[index].getAmount() == keep.length - taken) {
52 break;
53 }
54
55 if (keep[index].getAmount() > keep.length - taken) {
56 items.add(new Item(keep[index].getId(), keep[index].getAmount() - (keep.length - taken)));
57 keep[index].setAmount(keep.length - taken);
58 break;
59 }
60
61 taken += keep[index].getAmount();
62 }
63 }
64
65 player.send(new SendString("~ " + kept + " ~", 17112));
66
67 switch (kept) {
68 case 0:
69 default:
70 player.send(new SendString("You're marked with a \\n<col=ff0000>skull. </col>This reduces the \\nitems you keep from \\nthree to zero!", 17110));
71 break;
72 case 1:
73 player.send(new SendString("You're marked with a \\n<col=ff0000>skull. </col>This reduces the \\nitems you keep from \\nthree to zero! \\nHowever, you also have the \\n<col=ff0000>Protect </col>Items prayer \\nactive, which saves you \\none extra item!", 17110));
74 break;
75 case 3:
76 player.send(new SendString("You have no factors affecting \\nthe items you keep.", 17110));
77 break;
78 case 4:
79 player.send(new SendString("You have the <col=ff0000>Protect Item</col> \\nprayer active, which saves \\nyou none extra item!", 17110));
80 break;
81 }
82
84
85 if (carried <= 0) {
86 player.send(new SendString("Carried wealth: \\n<col=ff0000>Nothing!", 17115));
87 } else if (carried >= Long.MAX_VALUE) {
88 player.send(new SendString("Carried wealth: \\n<col=ff0000>Too much!", 17115));
89 } else {
90 player.send(new SendString("Carried wealth: \\n<col=ff0000>" + Utility.formatDigits(carried) + "</col> coins.", 17115));
91 }
92
93 Item[] dropped = items.toArray(new Item[0]);
94
95 BigInteger risked = BigInteger.ZERO;
96 while (items.peek() != null) {
97 final Item dropping = items.poll();
98
99 if (dropping == null) {
100 continue;
101 }
102
103 risked = risked.add(new BigInteger(String.valueOf(dropping.getValue(PriceType.VALUE))).multiply(new BigInteger(String.valueOf(dropping.getAmount()))));
104 }
105
106 player.send(new SendString("Risked wealth:", 17124));
107
108 if (risked.equals(BigInteger.ZERO)) {
109 player.send(new SendString("Risked wealth: \\n<col=ff0000>Nothing!", 17116));
110 } else {
111 player.send(new SendString("Risked wealth: \\n<col=ff0000>" + NumberFormat.getNumberInstance(Locale.US).format(risked) + "</col> coins.", 17116));
112 }
113
114 player.send(new SendItemOnInterface(17113, keep));
115 player.send(new SendItemOnInterface(17114, dropped));
116 player.interfaceManager.open(17100);
117 }
118
119}
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
boolean isActive(Prayer... prayers)
Checks if all given prayers are active.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final void setAmount(int amount)
Sets the quantity of this item.
Definition Item.java:351
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
long containerValue(PriceType type)
Gets the total worth of the container using the item's values.
final Item[] toArray()
Returns a shallow copy of the backing array.
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