aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java
blob: 0ec3aa1cddbe27643b03dba5e8ae219769c13867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
 * Copyright (C) 2023 NotEnoughUpdates contributors
 *
 * This file is part of NotEnoughUpdates.
 *
 * NotEnoughUpdates is free software: you can redistribute it
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * NotEnoughUpdates is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
 */

package io.github.moulberry.notenoughupdates.profileviewer.level.task;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.profileviewer.CrimsonIslePage;
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer;
import io.github.moulberry.notenoughupdates.profileviewer.SkyblockProfiles;
import io.github.moulberry.notenoughupdates.profileviewer.level.LevelPage;
import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SlayingTaskLevel extends GuiTaskLevel {

	private final int[] bossLow = {25, 50, 100, 150, 250, 1000};
	private final int[] thorn = {25, 50, 150, 250, 400, 1000};
	private final int[] bossHigh = {50, 100, 150, 250, 500, 750, 1000};

	public SlayingTaskLevel(LevelPage levelPage) {
		super(levelPage);
	}

	@Override
	public void drawTask(JsonObject object, int mouseX, int mouseY, int guiLeft, int guiTop) {
		// slayer
		JsonObject slayingTask = levelPage.getConstant().get("slaying_task").getAsJsonObject();
		JsonArray slayerLevelUpXp = slayingTask.get("slayer_level_up_xp").getAsJsonArray();

		SkyblockProfiles.SkyblockProfile selectedProfile = GuiProfileViewer.getSelectedProfile();
		if (selectedProfile == null) {
			return;
		}

		Map<String, ProfileViewer.Level> skyblockInfo = selectedProfile.getLevelingInfo();
		int sbXpGainedSlayer = 0;
		if (skyblockInfo != null) {
			for (String slayer : Weight.SLAYER_NAMES) {
				ProfileViewer.Level level = skyblockInfo.get(slayer);
				for (int i = 0; i < (int) level.level; i++) {
					int asInt = slayerLevelUpXp.get(i).getAsInt();
					sbXpGainedSlayer += asInt;
				}
			}
		}

		JsonObject bossCollectionsXp = slayingTask.getAsJsonObject("boss_collections_xp");

		HashMap<String, Double> allComps = new HashMap<>();
		JsonElement normalCompletions = Utils
			.getElement(object, "dungeons.dungeon_types.catacombs.tier_completions");

		JsonElement masterCompletions = Utils
			.getElement(object, "dungeons.dungeon_types.master_catacombs.tier_completions");

		if (normalCompletions != null) {
			HashMap<String, Double> normalCompMap = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(
				normalCompletions.getAsJsonObject(),
				HashMap.class
			);
			normalCompMap.forEach((floor, value) -> {
				if (allComps.containsKey(floor)) {
					allComps.put(floor, allComps.get(floor) + value);
				} else {
					allComps.put(floor, value);
				}
			});
		}
		if (masterCompletions != null) {
			HashMap<String, Double> masterCompMap = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(
				masterCompletions.getAsJsonObject(),
				HashMap.class
			);

			masterCompMap.forEach((floor, value) -> {
				if (allComps.containsKey(floor)) {
					allComps.put(floor, allComps.get(floor) + value * 2);
				} else {
					allComps.put(floor, value);
				}
			});
		}
		// THIS SERVER IS AWESOME I LOVE CONSISTENCY!!!!!!!

		int bossCollectionXp = 0;
		JsonArray dungeonCollectionXp = bossCollectionsXp.getAsJsonArray("dungeon_collection_xp");
		for (int i = 1; i <= 7; i++) {
			if (!allComps.containsKey(String.valueOf(i))) continue;
			double value = allComps.get(String.valueOf(i));
			switch (i) {
				case 1:
				case 2:
				case 3:
					bossCollectionXp += loopThroughCollection(bossLow, value, dungeonCollectionXp);
					break;
				case 4:
					bossCollectionXp += loopThroughCollection(thorn, value, dungeonCollectionXp);
					break;
				case 5:
				case 6:
				case 7:
					bossCollectionXp += loopThroughCollection(bossHigh, value, dungeonCollectionXp);
					break;
			}
		}

		JsonArray defeatKuudraXp = slayingTask.get("defeat_kuudra_xp").getAsJsonArray();
		// kuudra

		int sbXpDefeatKuudra = 0;

		int kuudraBossCollection = 0;
		if (object.has("nether_island_player_data")) {
			JsonObject kuudraCompletedTiers = Utils.getElementOrDefault(
				selectedProfile.getProfileJson(),
				"nether_island_player_data.kuudra_completed_tiers",
				new JsonObject()
			).getAsJsonObject();
			for (Map.Entry<String, JsonElement> stringJsonElementEntry : kuudraCompletedTiers.entrySet()) {
				String key = stringJsonElementEntry.getKey();
				int value = stringJsonElementEntry.getValue().getAsInt();

				int i = 0;
				for (String kuudraTier : CrimsonIslePage.KUUDRA_TIERS) {
					if (key.equals(kuudraTier)) {
						sbXpDefeatKuudra += defeatKuudraXp.get(i).getAsInt();
						kuudraBossCollection += (i + 1) * value;
					}
					i++;
				}
			}
			if (kuudraBossCollection >= 10) bossCollectionXp += 10;
			if (kuudraBossCollection >= 100) bossCollectionXp += 15;
			if (kuudraBossCollection >= 500) bossCollectionXp += 20;
			if (kuudraBossCollection >= 2000) bossCollectionXp += 25;
			if (kuudraBossCollection >= 5000) bossCollectionXp += 30;
		}

		int sbXpBestiary = GuiProfileViewer.getSelectedProfile().getBestiaryXp();

		int mythologicalKillsXp = Utils.getElementAsInt(Utils.getElement(
			selectedProfile.getProfileJson(),
			"player_stats.mythos.kills"
		), 0) / 100;

		int mythologicalKillsMax = slayingTask.get("mythological_kills").getAsInt();
		if (mythologicalKillsXp > mythologicalKillsMax) mythologicalKillsXp = mythologicalKillsMax;

		// dragons
		int sbXpFromDragonKills = 0;
		JsonObject slayDragonsXp = slayingTask.getAsJsonObject("slay_dragons_xp");
		for (Map.Entry<String, JsonElement> stringJsonElementEntry : slayDragonsXp.entrySet()) {
			sbXpFromDragonKills += stringJsonElementEntry.getValue().getAsInt();
		}

		// slayer kills
		int sbXpFromSlayerDefeat = 0;

		JsonArray defeatSlayersXp = slayingTask.get("defeat_slayers_xp").getAsJsonArray();
		JsonObject slayerToTier = Constants.LEVELING.getAsJsonObject("slayer_to_highest_tier");
		if (slayerToTier == null) {
			Utils.showOutdatedRepoNotification("slayer_to_highest_tier from leveling.json");
			return;
		}
		for (Map.Entry<String, JsonElement> entry : slayerToTier.entrySet()) {
			int maxLevel = entry.getValue().getAsInt();
			for (int i = 0; i < 5; i++) {
				if (i >= maxLevel) break;
				float tier = Utils.getElementAsFloat(
					Utils.getElement(object, "slayer.slayer_bosses." + entry.getKey() + ".boss_kills_tier_" + i),
					0
				);
				if (tier != 0) {
					int value = defeatSlayersXp.get(i).getAsInt();
					sbXpFromSlayerDefeat += value;
				}
			}
		}

		// arachne
		JsonArray defeatArachneXp = slayingTask.get("defeat_arachne_xp").getAsJsonArray();
		int sbXpGainedArachne = 0;
		for (JsonElement jsonElement : defeatArachneXp) {
			sbXpGainedArachne += jsonElement.getAsInt();
		}

		List<String> lore = new ArrayList<>();

		int slayerLevelUpMax = slayingTask.get("slayer_level_up").getAsInt();
		int bossCollectionsMax = slayingTask.get("boss_collections").getAsInt();
		int bestiaryXpMax = slayingTask.get("bestiary_progress").getAsInt();
		int slayDragonsMax = slayingTask