aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/DungeonTaskLevel.java
blob: dfbfb834ebf0b2a7416731594cb189439a522581 (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
/*
 * 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.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.Utils;

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

public class DungeonTaskLevel extends GuiTaskLevel {

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

	@Override
	public void drawTask(JsonObject object, int mouseX, int mouseY, int guiLeft, int guiTop) {
		JsonObject dungeonTask = levelPage.getConstant().get("dungeon_task").getAsJsonObject();

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

		Map<String, ProfileViewer.Level> skyblockInfo = selectedProfile.getLevelingInfo();

		int sbLevelGainedFloor = 0;
		int sbXpGainedClass = 0;
		int sbXpGainedLvl = 0;
		int catacombsLvl = 0;
		if (skyblockInfo != null && skyblockInfo.containsKey("catacombs")) {
			ProfileViewer.Level catacombs = skyblockInfo.get("catacombs");

			catacombsLvl = (int) catacombs.level;
			for (int i = 1; i <= catacombs.level; i++) {
				if (40 > i) {
					sbXpGainedLvl += 20;
				} else {
					sbXpGainedLvl += 40;
				}
			}

			for (String dungeonClass : Weight.DUNGEON_CLASS_NAMES) {
				ProfileViewer.Level level = skyblockInfo.get(dungeonClass);
				for (int i = 1; i <= level.level; i++) {
					if (i <= 50) sbXpGainedClass += dungeonTask.get("class_xp").getAsInt();
				}
			}

			JsonArray completeCatacombs = dungeonTask.get("complete_catacombs").getAsJsonArray();
			int index = 0;
			for (JsonElement completeCatacomb : completeCatacombs) {
				int value = completeCatacomb.getAsInt();
				JsonElement normalCompletions = Utils
					.getElementOrDefault(object, "dungeons.dungeon_types.catacombs.tier_completions", null);
				if (normalCompletions != null && normalCompletions.getAsJsonObject().has("" + index)) {
					sbLevelGainedFloor += value;
				}
				index++;
			}

			int masterCatacombs = dungeonTask.get("complete_master_catacombs").getAsInt();
			for (int i = 0; i <= 7; i++) {
				JsonElement masterCompletions = Utils
					.getElementOrDefault(object, "dungeons.dungeon_types.master_catacombs.tier_completions", null);
				if (masterCompletions != null) {
					if (masterCompletions.getAsJsonObject().has("" + i)) {
						sbLevelGainedFloor += masterCatacombs;
					}
				}
			}
		}

		int catacombsLevelUp = dungeonTask.get("catacombs_level_up").getAsInt();
		int classLevelUp = dungeonTask.get("class_level_up").getAsInt();
		int completeDungeon = dungeonTask.get("complete_dungeon").getAsInt();
		int totalGainful = catacombsLevelUp + classLevelUp + completeDungeon;
		double totalXp = sbXpGainedLvl + sbXpGainedClass + sbLevelGainedFloor;

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

		lore.add(levelPage.buildLore("Catacombs Level Up", sbXpGainedLvl, catacombsLevelUp, false));
		lore.add(levelPage.buildLore("Class Level Up", sbXpGainedClass, classLevelUp, false));
		lore.add(levelPage.buildLore("Complete Dungeons", sbLevelGainedFloor, completeDungeon, false));

		levelPage.renderLevelBar(
			"Dungeon Task",
			NotEnoughUpdates.INSTANCE.manager
				.createItemResolutionQuery()
				.withKnownInternalName("WITHER_RELIC")
				.resolveToItemStack(),
			guiLeft + 23, guiTop + 55,
			110,
			catacombsLvl,
			totalXp,
			totalGainful,
			mouseX, mouseY,
			true,
			lore
		);
	}
}