RuneHive-Game
Loading...
Searching...
No Matches
CollectionLog.java
Go to the documentation of this file.
1package com.runehive.content.collectionlog;
2
3import com.runehive.game.world.entity.mob.player.Player;
4import com.runehive.game.world.items.Item;
5import com.runehive.game.world.items.ItemDefinition;
6import com.runehive.net.packet.out.SendConfig;
7import com.runehive.net.packet.out.SendItemOnInterface;
8import com.runehive.net.packet.out.SendMessage;
9import com.runehive.net.packet.out.SendString;
10
11import java.util.ArrayList;
12
13public class CollectionLog {
14
15 public static final int INTERFACE_ID = 44500;
16 public static final int NAME_ID = 44516;
17 public static final int OBTAINED_ID = 44517;
18 public static final int KC_ID = 44518;
19 public static final int ITEM_CONTAINER = 44521;
20
21 private ArrayList<CollectionLogItem> log;
22
23 public CollectionLog() {
24 log = new ArrayList<>();
25 }
26
27 public ArrayList<CollectionLogItem> getLog() {
28 return this.log;
29 }
30
31 public static void open(Player player) {
33
34 if (player.collectionLogPageOpen != null)
35 loadPage(player, player.collectionLogPageOpen);
36 else
38
39 if (player.collectionLogView != null)
40 selectLog(player, player.collectionLogView, -1);
41 else
43 }
44
45 public static void loadPage(Player player, CollectionLogPage page) {
46 player.collectionLogPageOpen = page;
47 player.send(new SendConfig(906, page.ordinal()));
48 player.send(new SendConfig(907, 0));
49 sendButtons(player, page);
50
51 ArrayList<CollectionLogData> list = CollectionLogData.getPageList(player.collectionLogPageOpen);
52 CollectionLogData selected = list.get(0);
53 selectLog(player, selected, 0);
54 }
55
56 public static void sendButtons(Player player, CollectionLogPage page) {
57 ArrayList<CollectionLogData> list = CollectionLogData.getPageList(page);
58 int index = 44524;
59 for (int i = 0; i < list.size(); ++i, index += 2) {
60 int color = 0;
61 CollectionLogData selected = list.get(i);
62 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
63 if (cli.getData() == selected) {
64 if (cli.hasClaimed()) {
65 color = 1;
66 }
67 }
68 }
69
70 player.send(new SendString(color > 0 ? "@gre@" + list.get(i).getName() : list.get(i).getName(), index));
71 }
72
73 for(int i = list.size(); i < 17; i++, index += 2)
74 player.send(new SendString("", index));
75 }
76
77 public static void selectLog(Player player, CollectionLogData selected, int slot) {
78 if(slot != -1)
79 player.send(new SendConfig(907, slot));
80
81 player.send(new SendString(selected.getName(), NAME_ID));
82
83
84 ArrayList<Item> items = new ArrayList<>();
85
86 int[] itemIds = selected.getItems();
87 int total = itemIds == null ? 0 : itemIds.length;
88
89 if (itemIds != null) {
90 for (int i : itemIds) {
91 items.add(new Item(i, getLogItemAmount(player, selected, i)));
92 }
93 }
94
95 int obtained = 0;
96 for (Item gi : items) {
97 if (gi.getAmount() > 0) {
98 obtained++;
99 }
100 }
101
102 String colorCode = obtained >= total ? "65280" : obtained > 0 ? "FFFF00" : "FF0000";
103 player.send(new SendString("Obtained: <col="+colorCode+">" + obtained + "/" + total + "</col>", OBTAINED_ID));
104
105 String outcome = "";
106 int counter = getCounter(player.getCollectionLog(), selected);
107 if (selected.getType().equals(CollectionCategory.BOSSES))
108 outcome = selected.getName() + " kills: <col=FFFFFF>" + counter + "</col>";
109 else if (selected.getCounterText() != null)
110 outcome = selected.getCounterText() + ": <col=FFFFFF>" + counter + "</col>";
111
112 player.send(new SendString(outcome, KC_ID));
113
114 player.send(new SendItemOnInterface(ITEM_CONTAINER, items.toArray(new Item[0])));
115
116 player.collectionLogView = selected;
117 }
118
119 public static void selectLogButton(Player player, int slot) {
120 ArrayList<CollectionLogData> list = CollectionLogData.getPageList(player.collectionLogPageOpen);
121 if (slot > list.size() - 1) {
122 return;
123 }
124 CollectionLogData selected = list.get(slot);
125 selectLog(player, selected, slot);
126 }
127
128 public static boolean clickButton(Player player, int button) {
130 if (page != null) {
131 loadPage(player, page);
132 return true;
133 }
134 if (button >= -21013 && button < -20915) {
135 selectLogButton(player, (button - -21013) / 2);
136 return true;
137 }
138 return false;
139 }
140
141
142 public static int getCounter(CollectionLog cl, CollectionLogData data) {
143 for (CollectionLogItem i : cl.getLog()) {
144 if (i.getData() == data) {
145 return i.getCounter();
146 }
147 }
148 return 0;
149 }
150
151 public static int getLogItemAmount(Player player, CollectionLogData data, int item) {
152 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
153 if (cli.getData() == data) {
154 for (int i = 0; i < cli.getItems().size(); ++i) {
155 if (cli.getItems().get(i).getId() == item) {
156 return cli.getItems().get(i).getAmount();
157 }
158 }
159 }
160 }
161 return 0;
162 }
163
164 public static void checkItemDrop(Player player, int npcId, int itemId, int amount) {
165 if (npcId < 1) {
166 return;
167 }
168 for (CollectionLogData data : CollectionLogData.values()) {
169 for(int npc : data.getNpcIds()) {
170 if (npc == npcId) {
171 logItem(player, data, itemId, amount);
172 return;
173 }
174 }
175 }
176 }
177
178 public static void logItem(Player player, CollectionLogData data, int item, int amount) {
179 boolean valid = false;
180 for (int i : data.getItems()) {
181 if (i == item) {
182 valid = true;
183 break;
184 }
185 }
186 if (!valid) {
187 return;
188 }
189 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
190 if (cli.getData() == data) {
191 cli.addItem(item, amount);
192 player.send(new SendMessage("@red@An item was added to your collection log: " + amount + "x " + ItemDefinition.get(item).getName() + "!"));
194 return;
195 }
196 }
197 player.send(new SendMessage("@red@An item was added to your collection log: " + amount + "x " + ItemDefinition.get(item).getName() + "!"));
198 CollectionLogItem addLog = new CollectionLogItem(data);
199 addLog.addItem(item, amount);
200 player.getCollectionLog().getLog().add(addLog);
202 }
203
204 public static void onNpcKill(Player player, int npcId) {
205 if (npcId < 1) {
206 return;
207 }
208 for (CollectionLogData data : CollectionLogData.values()) {
209 for(int npc : data.getNpcIds()) {
210 if (npc == npcId) {
211 increaseCounter(player, data);
212 return;
213 }
214 }
215 }
216 }
217
218 public static void increaseCounter(Player player, CollectionLogData data) {
219 for (CollectionLogItem cli : player.getCollectionLog().getLog()) {
220 if (cli.getData() == data) {
221 cli.setCounter(cli.getCounter() + 1);
222 return;
223 }
224 }
225 CollectionLogItem addLog = new CollectionLogItem(data);
226 addLog.setCounter(1);
227 player.getCollectionLog().getLog().add(addLog);
228 }
229}
static int getCounter(CollectionLog cl, CollectionLogData data)
static int getLogItemAmount(Player player, CollectionLogData data, int item)
static void sendButtons(Player player, CollectionLogPage page)
static void checkItemDrop(Player player, int npcId, int itemId, int amount)
static void logItem(Player player, CollectionLogData data, int item, int amount)
static void selectLog(Player player, CollectionLogData selected, int slot)
static void increaseCounter(Player player, CollectionLogData data)
static void onNpcKill(Player player, int npcId)
static boolean clickButton(Player player, int button)
static void loadPage(Player player, CollectionLogPage page)
static void selectLogButton(Player player, int slot)
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
The container class that represents an item that can be interacted with.
Definition Item.java:21
The OutgoingPacket responsible for changing settings on a client.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
static ArrayList< CollectionLogData > getPageList(CollectionLogPage page)