RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
CollectionLog.java
1package com.osroyale.content.collectionlog;
2
3import com.osroyale.game.world.entity.mob.player.Player;
4import com.osroyale.game.world.items.Item;
5import com.osroyale.game.world.items.ItemDefinition;
6import com.osroyale.net.packet.out.SendConfig;
7import com.osroyale.net.packet.out.SendItemOnInterface;
8import com.osroyale.net.packet.out.SendMessage;
9import com.osroyale.net.packet.out.SendString;
10
11import java.util.ArrayList;
12
46
47public class CollectionLog {
48
49 public static final int INTERFACE_ID = 44500;
50 public static final int NAME_ID = 44516;
51 public static final int OBTAINED_ID = 44517;
52 public static final int KC_ID = 44518;
53 public static final int ITEM_CONTAINER = 44521;
54
55 private ArrayList<CollectionLogItem> log;
56
57 public CollectionLog() {
58 log = new ArrayList<>();
59 }
60
61 public ArrayList<CollectionLogItem> getLog() {
62 return this.log;
63 }
64
65 public static void open(Player player) {
66 player.interfaceManager.open(INTERFACE_ID);
67
68 if (player.collectionLogPageOpen != null)
69 loadPage(player, player.collectionLogPageOpen);
70 else
71 loadPage(player, CollectionLogPage.BOSSES);
72
73 if (player.collectionLogView != null)
74 selectLog(player, player.collectionLogView, -1);
75 else
76 selectLog(player, CollectionLogData.BARROWS, 0);
77 }
78
79 public static void loadPage(Player player, CollectionLogPage page) {
80 player.collectionLogPageOpen = page;
81 player.send(new SendConfig(906, page.ordinal()));
82 player.send(new SendConfig(907, 0));
83 sendButtons(player, page);
84
85 ArrayList<CollectionLogData> list = CollectionLogData.getPageList(player.collectionLogPageOpen);
86 CollectionLogData selected = list.get(0);
87 selectLog(player, selected, 0);
88 }
89
90 public static void sendButtons(Player player, CollectionLogPage page) {
91 ArrayList<CollectionLogData> list = CollectionLogData.getPageList(page);
92 int index = 44524;
93 for (int i = 0; i < list.size(); ++i, index += 2) {
94 int color = 0;
95 CollectionLogData selected = list.get(i);
96 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
97 if (cli.getData() == selected) {
98 if (cli.hasClaimed()) {
99 color = 1;
100 }
101 }
102 }
103
104 player.send(new SendString(color > 0 ? "@gre@" + list.get(i).getName() : list.get(i).getName(), index));
105 }
106
107 for(int i = list.size(); i < 17; i++, index += 2)
108 player.send(new SendString("", index));
109 }
110
111 public static void selectLog(Player player, CollectionLogData selected, int slot) {
112 if(slot != -1)
113 player.send(new SendConfig(907, slot));
114
115 player.send(new SendString(selected.getName(), NAME_ID));
116
117
118 ArrayList<Item> items = new ArrayList<>();
119
120 int[] itemIds = selected.getItems();
121 int total = itemIds == null ? 0 : itemIds.length;
122
123 if (itemIds != null) {
124 for (int i : itemIds) {
125 items.add(new Item(i, getLogItemAmount(player, selected, i)));
126 }
127 }
128
129 int obtained = 0;
130 for (Item gi : items) {
131 if (gi.getAmount() > 0) {
132 obtained++;
133 }
134 }
135
136 String colorCode = obtained >= total ? "65280" : obtained > 0 ? "FFFF00" : "FF0000";
137 player.send(new SendString("Obtained: <col="+colorCode+">" + obtained + "/" + total + "</col>", OBTAINED_ID));
138
139 String outcome = "";
140 int counter = getCounter(player.getCollectionLog(), selected);
141 if (selected.getType().equals(CollectionCategory.BOSSES))
142 outcome = selected.getName() + " kills: <col=FFFFFF>" + counter + "</col>";
143 else if (selected.getCounterText() != null)
144 outcome = selected.getCounterText() + ": <col=FFFFFF>" + counter + "</col>";
145
146 player.send(new SendString(outcome, KC_ID));
147
148 player.send(new SendItemOnInterface(ITEM_CONTAINER, items.toArray(new Item[0])));
149
150 player.collectionLogView = selected;
151 }
152
153 public static void selectLogButton(Player player, int slot) {
154 ArrayList<CollectionLogData> list = CollectionLogData.getPageList(player.collectionLogPageOpen);
155 if (slot > list.size() - 1) {
156 return;
157 }
158 CollectionLogData selected = list.get(slot);
159 selectLog(player, selected, slot);
160 }
161
162 public static boolean clickButton(Player player, int button) {
163 CollectionLogPage page = CollectionLogPage.forButton(button);
164 if (page != null) {
165 loadPage(player, page);
166 return true;
167 }
168 if (button >= -21013 && button < -20915) {
169 selectLogButton(player, (button - -21013) / 2);
170 return true;
171 }
172 return false;
173 }
174
175
176 public static int getCounter(CollectionLog cl, CollectionLogData data) {
177 for (CollectionLogItem i : cl.getLog()) {
178 if (i.getData() == data) {
179 return i.getCounter();
180 }
181 }
182 return 0;
183 }
184
185 public static int getLogItemAmount(Player player, CollectionLogData data, int item) {
186 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
187 if (cli.getData() == data) {
188 for (int i = 0; i < cli.getItems().size(); ++i) {
189 if (cli.getItems().get(i).getId() == item) {
190 return cli.getItems().get(i).getAmount();
191 }
192 }
193 }
194 }
195 return 0;
196 }
197
198 public static void checkItemDrop(Player player, int npcId, int itemId, int amount) {
199 if (npcId < 1) {
200 return;
201 }
202 for (CollectionLogData data : CollectionLogData.values()) {
203 for(int npc : data.getNpcIds()) {
204 if (npc == npcId) {
205 logItem(player, data, itemId, amount);
206 return;
207 }
208 }
209 }
210 }
211
212 public static void logItem(Player player, CollectionLogData data, int item, int amount) {
213 boolean valid = false;
214 for (int i : data.getItems()) {
215 if (i == item) {
216 valid = true;
217 break;
218 }
219 }
220 if (!valid) {
221 return;
222 }
223 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
224 if (cli.getData() == data) {
225 cli.addItem(item, amount);
226 player.send(new SendMessage("@red@An item was added to your collection log: " + amount + "x " + ItemDefinition.get(item).getName() + "!"));
227 CollectionLogSaving.save(player);
228 return;
229 }
230 }
231 player.send(new SendMessage("@red@An item was added to your collection log: " + amount + "x " + ItemDefinition.get(item).getName() + "!"));
232 CollectionLogItem addLog = new CollectionLogItem(data);
233 addLog.addItem(item, amount);
234 player.getCollectionLog().getLog().add(addLog);
235 CollectionLogSaving.save(player);
236 }
237
238 public static void onNpcKill(Player player, int npcId) {
239 if (npcId < 1) {
240 return;
241 }
242 for (CollectionLogData data : CollectionLogData.values()) {
243 for(int npc : data.getNpcIds()) {
244 if (npc == npcId) {
245 increaseCounter(player, data);
246 return;
247 }
248 }
249 }
250 }
251
252 public static void increaseCounter(Player player, CollectionLogData data) {
253 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
254 if (cli.getData() == data) {
255 cli.setCounter(cli.getCounter() + 1);
256 return;
257 }
258 }
259 CollectionLogItem addLog = new CollectionLogItem(data);
260 addLog.setCounter(1);
261 player.getCollectionLog().getLog().add(addLog);
262 }
263}