RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ItemsKeptOnDeath.java
1package com.osroyale.content;
2
3import com.osroyale.net.packet.out.SendItemOnInterface;
4import com.osroyale.net.packet.out.SendString;
5import com.osroyale.game.world.entity.mob.player.Player;
6import com.osroyale.game.world.entity.mob.prayer.Prayer;
7import com.osroyale.game.world.items.Item;
8import com.osroyale.game.world.items.ItemComparator;
9import com.osroyale.game.world.items.containers.pricechecker.PriceType;
10import com.osroyale.util.Utility;
11
12import java.math.BigInteger;
13import java.text.NumberFormat;
14import java.util.Locale;
15import java.util.PriorityQueue;
16import java.util.Queue;
17
39
40public class ItemsKeptOnDeath {
41
42 public static void open(Player player) {
43 int kept = 3;
44 if (player.skulling.isSkulled()) {
45 kept = player.prayer.isActive(Prayer.PROTECT_ITEM) ? 1 : 0;
46 } else {
47 kept = player.prayer.isActive(Prayer.PROTECT_ITEM) ? 4 : 3;
48 }
49
50 final Item[] keep = new Item[kept];
51
52 final Queue<Item> items = new PriorityQueue<Item>(ItemComparator.SHOP_VALUE_COMPARATOR);
53
54 for (final Item item : player.inventory.toArray()) {
55 if (item != null) {
56 items.add(item.copy());
57 }
58 }
59
60 for (final Item item : player.equipment.toArray()) {
61 if (item != null) {
62 items.add(item.copy());
63 }
64 }
65
66 final Queue<Item> temp = new PriorityQueue<>(items);
67
68 for (int index = 0, taken = 0; index < keep.length; index++) {
69 keep[index] = temp.poll();
70 items.remove(keep[index]);
71
72 if (keep[index] != null) {
73 if (keep[index].getAmount() == keep.length - taken) {
74 break;
75 }
76
77 if (keep[index].getAmount() > keep.length - taken) {
78 items.add(new Item(keep[index].getId(), keep[index].getAmount() - (keep.length - taken)));
79 keep[index].setAmount(keep.length - taken);
80 break;
81 }
82
83 taken += keep[index].getAmount();
84 }
85 }
86
87 player.send(new SendString("~ " + kept + " ~", 17112));
88
89 switch (kept) {
90 case 0:
91 default:
92 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));
93 break;
94 case 1:
95 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));
96 break;
97 case 3:
98 player.send(new SendString("You have no factors affecting \\nthe items you keep.", 17110));
99 break;
100 case 4:
101 player.send(new SendString("You have the <col=ff0000>Protect Item</col> \\nprayer active, which saves \\nyou none extra item!", 17110));
102 break;
103 }
104
105 long carried = (player.inventory.containerValue(PriceType.VALUE) + player.equipment.containerValue(PriceType.VALUE));
106
107 if (carried <= 0) {
108 player.send(new SendString("Carried wealth: \\n<col=ff0000>Nothing!", 17115));
109 } else if (carried >= Long.MAX_VALUE) {
110 player.send(new SendString("Carried wealth: \\n<col=ff0000>Too much!", 17115));
111 } else {
112 player.send(new SendString("Carried wealth: \\n<col=ff0000>" + Utility.formatDigits(carried) + "</col> coins.", 17115));
113 }
114
115 Item[] dropped = items.toArray(new Item[0]);
116
117 BigInteger risked = BigInteger.ZERO;
118 while (items.peek() != null) {
119 final Item dropping = items.poll();
120
121 if (dropping == null) {
122 continue;
123 }
124
125 risked = risked.add(new BigInteger(String.valueOf(dropping.getValue(PriceType.VALUE))).multiply(new BigInteger(String.valueOf(dropping.getAmount()))));
126 }
127
128 player.send(new SendString("Risked wealth:", 17124));
129
130 if (risked.equals(BigInteger.ZERO)) {
131 player.send(new SendString("Risked wealth: \\n<col=ff0000>Nothing!", 17116));
132 } else {
133 player.send(new SendString("Risked wealth: \\n<col=ff0000>" + NumberFormat.getNumberInstance(Locale.US).format(risked) + "</col> coins.", 17116));
134 }
135
136 player.send(new SendItemOnInterface(17113, keep));
137 player.send(new SendItemOnInterface(17114, dropped));
138 player.interfaceManager.open(17100);
139 }
140
141}
static String formatDigits(final int amount)
Definition Utility.java:78