diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/features/bestiary/index.js | 122 | ||||
-rw-r--r-- | src/features/hud/index.js | 1 | ||||
-rw-r--r-- | src/features/stat_next_to_name/index.js | 18 | ||||
-rw-r--r-- | src/metadata.json | 4 | ||||
-rw-r--r-- | src/utils/statUtils.js | 57 |
5 files changed, 104 insertions, 98 deletions
diff --git a/src/features/bestiary/index.js b/src/features/bestiary/index.js index da09463..8d00122 100644 --- a/src/features/bestiary/index.js +++ b/src/features/bestiary/index.js @@ -2,6 +2,8 @@ /// <reference lib="es2015" /> import Feature from "../../featureClass/class"; import { numberWithCommas } from "../../utils/numberUtils"; +import { getBestiaryTier } from "../../utils/statUtils"; +import { firstLetterWordCapital } from "../../utils/stringUtils"; import HudTextElement from "../hud/HudTextElement"; import DropdownSetting from "../settings/settingThings/dropdownSetting"; import LocationSetting from "../settings/settingThings/location"; @@ -25,23 +27,12 @@ class Bestiary extends Feature { } onEnable() { - this.bestiaryData = JSON.parse(FileLib.read("soopyAddonsData", "bestiaryData.json") || "{}") - this.bestiaryChanged = false - - this.bestiaryApiTracking = {} - - this.registerStep(true, 5, this.scanInv) - this.registerStep(false, 5, this.saveData) - this.bestiaryStatTypes = { "barbarian_duke_x": "Barbarian Duke X" } - Object.keys(this.bestiaryData).forEach(k => { - if (this.bestiaryData[k].guiName) this.bestiaryStatTypes[k] = this.bestiaryData[k].guiName - }) + this.bestiaryData = {} - new SettingBase("NOTE: u need to open ur bestiary menu", "before this will work", true, "info_bestiary", this) this.hudStat = [] for (let i = 0; i < 10; i++) { this.hudStat[i] = {} @@ -105,8 +96,13 @@ class Bestiary extends Feature { } if (thing) { - this.bestiaryData[thing].guessCount++ - this.bestiaryChanged = true + this.bestiaryData[thing].totalKills++ + + let { level, killsLeft, killsForNext } = getBestiaryTier(thing, this.bestiaryData[thing].totalKills) + + this.bestiaryData[thing].tier = level + this.bestiaryData[thing].killsThisTier = killsLeft + this.bestiaryData[thing].killsForNext = killsForNext } }) this.registerSoopy("apiLoad", this.apiLoad); @@ -118,17 +114,8 @@ class Bestiary extends Feature { getBestiaryCount(id) { if (!this.bestiaryData[id]) return "???" - let count = this.bestiaryData[id].count - - if (!dontUseApi.has(id)) { - let currApiData = this.bestiaryApiTracking[id] - - count += currApiData - this.bestiaryData[id].apiCount - } - - count += this.bestiaryData[id].guessCount - return count + return `${this.bestiaryData[id].tier}&7:&f ${this.bestiaryData[id].killsThisTier}&7/&f${this.bestiaryData[id].killsForNext}` } updateHudElements() { @@ -145,7 +132,7 @@ class Bestiary extends Feature { let type = stat.type.getValue() - stat.textElement.setText(`&6${this.bestiaryData[type]?.guiName}&7> &f${numberWithCommas(this.getBestiaryCount(type))}`) + stat.textElement.setText(`&6${this.bestiaryStatTypes[type]}&7> &f${numberWithCommas(this.getBestiaryCount(type))}`) } else { stat.textElement.setText("") } @@ -166,84 +153,45 @@ class Bestiary extends Feature { } }) - Object.keys(currentProfile.stats).forEach(key => { - if (key.startsWith("kills_")) { - this.bestiaryApiTracking[key.replace("kills_", "")] = currentProfile.stats[key] - } - }) - } - - scanInv() { - if (!Player.getContainer()) return - if (!Player.getContainer().getName().startsWith("Bestiary ➜ ")) return - let tempChanged = false - let seen = new Set() - - for (let item of Player.getContainer().getItems()) { - if (!item) continue - let name = ChatLib.removeFormatting(item.getName()).split(" ") - name.pop() - let apiName = name.join("_").toLowerCase() - if (seen.has(apiName)) continue - seen.add(apiName) - - if (apiName === "skeletor_prime") continue - - if (this.bestiaryApiTracking[apiName] || dontUseApi.has(apiName)) { + Object.entries(currentProfile.bestiary).forEach(([key, val]) => { + if (key.startsWith("kills_family_")) { + let family = key.replace("kills_family_", "") - let count = 0 - - for (let l of item.getLore()) { - l = ChatLib.removeFormatting(l) - - if (l.startsWith("Kills: ")) { - count = parseInt(l.split("Kills: ")[1].replace(/,/g, "")) - break; + if (!this.bestiaryData[family]) { + this.bestiaryData[family] = { + tier: 0, + totalKills: 0, + killsThisTier: 0, + killsForNext: 0 } } - let needsChange = !this.bestiaryData[apiName] || this.bestiaryData[apiName].guiName !== name.join(" ") || this.bestiaryData[apiName].count !== count || this.bestiaryData[apiName].apiCount !== (this.bestiaryApiTracking[apiName] || 0) || this.bestiaryData[apiName].guessCount !== 0 - if (needsChange) { - this.bestiaryData[apiName] = { - guiName: name.join(" "), - count, - apiCount: this.bestiaryApiTracking[apiName] || 0, - guessCount: 0 - } - this.bestiaryChanged = true + this.bestiaryData[family].totalKills = val - tempChanged = true + let { level, killsLeft, killsForNext } = getBestiaryTier(family, val) - } + this.bestiaryData[family].tier = level + this.bestiaryData[family].killsThisTier = killsLeft + this.bestiaryData[family].killsForNext = killsForNext } - } - - if (tempChanged) { - this.bestiaryStatTypes = {} - Object.keys(this.bestiaryData).forEach(k => { - if (this.bestiaryData[k]?.guiName) this.bestiaryStatTypes[k] = this.bestiaryData[k].guiName - }) - + }) + let changed = false + Object.keys(this.bestiaryData).forEach(k => { + if (!this.bestiaryStatTypes[k]) { + this.bestiaryStatTypes[k] = firstLetterWordCapital(k.replace(/_/g, " ")) + changed = true + } + }) + if (changed) { this.hudStat.forEach(s => { s.type.dropdownObject.setOptions(this.bestiaryStatTypes) }) - - this.updateHudElements() - } - start = Date.now() - } - - saveData() { - if (this.bestiaryChanged) { - FileLib.write("soopyAddonsData", "bestiaryData.json", JSON.stringify(this.bestiaryData)) } } onDisable() { this.hudStat.forEach(h => h.textElement.delete()) - this.saveData() } - } module.exports = { class: new Bestiary() diff --git a/src/features/hud/index.js b/src/features/hud/index.js index f4d7e16..f1cfa33 100644 --- a/src/features/hud/index.js +++ b/src/features/hud/index.js @@ -676,6 +676,7 @@ class Hud extends Feature { updatePotsData(data) { this.potsExpireAt = {} let now = Date.now() + if (Date.now() - data.last_save < 5 * 60000) now = data.last_save data.active_effects.forEach(e => { this.potsExpireAt[e.effect] = { level: e.level, diff --git a/src/features/stat_next_to_name/index.js b/src/features/stat_next_to_name/index.js index 2045db5..3845b66 100644 --- a/src/features/stat_next_to_name/index.js +++ b/src/features/stat_next_to_name/index.js @@ -6,6 +6,7 @@ import SettingBase from "../settings/settingThings/settingBase"; import * as numberUtils from "../../utils/numberUtils"; import DropdownSetting from "../settings/settingThings/dropdownSetting"; import ToggleSetting from "../settings/settingThings/toggle"; +import NonPooledThread from "../../utils/nonPooledThread"; class StatNextToName extends Feature { constructor() { @@ -73,12 +74,19 @@ class StatNextToName extends Feature { }) let keyValid = false - let key = this.FeatureManager.features["globalSettings"].class.apiKeySetting.getValue() - fetch("https://api.hypixel.net/key?key=" + key).json().then(d => { - if (d.success) { - keyValid = true + let key = undefined + new NonPooledThread(() => { + while (!this.FeatureManager.features["globalSettings"]?.class) { + Thread.sleep(1000) } - }) + + key = this.FeatureManager.features["globalSettings"].class.apiKeySetting.getValue() + fetch("https://api.hypixel.net/key?key=" + key).json().then(d => { + if (d.success) { + keyValid = true + } + }) + }).start() } loadPlayerStatsTick() { diff --git a/src/metadata.json b/src/metadata.json index ccf0d60..359cfd6 100644 --- a/src/metadata.json +++ b/src/metadata.json @@ -5,8 +5,8 @@ "entry": "index.js", "description": "SoopyV2", "name": "SoopyV2", - "version": "2.1.162", - "versionId": 289, + "version": "2.1.163", + "versionId": 290, "requires": [ "soopyApis", "soopyAddonsData", diff --git a/src/utils/statUtils.js b/src/utils/statUtils.js index 89b467d..f827454 100644 --- a/src/utils/statUtils.js +++ b/src/utils/statUtils.js @@ -1,13 +1,62 @@ let utils = { - getHotmLevel: getHotmLevel, - getDungeoneeringLevel: getDungeoneeringLevel, - getPetLevel: getPetLevel, - getLevelByXp: getLevelByXp, + getHotmLevel, + getDungeoneeringLevel, + getPetLevel, + getLevelByXp, + getBestiaryTier } module.exports = utils +let bossmobs = new Set() +bossmobs.add("dragon") +bossmobs.add("arachne") +bossmobs.add("headless_horseman") +bossmobs.add("magma_cube_boss") +bossmobs.add("arachne") +bossmobs.add("barbarian_duke_x") +bossmobs.add("bladesoul") +bossmobs.add("mage_outlaw") +bossmobs.add("ashfang") +bossmobs.add("corrupted_protector") + +let islandmobs = new Set() +islandmobs.add("cave_spider") +islandmobs.add("enderman_private") +islandmobs.add("skeleton") +islandmobs.add("slime") +islandmobs.add("spider") +islandmobs.add("witch") +islandmobs.add("zombie") + +let bestiaryData = { + mob: [10, 15, 75, 150, 250, 500, 1500, 2500, 5000, 15000, 25000, 50000, ...(new Array(42 - 13).fill(100000))], + boss: [2, 3, 5, 10, 10, 10, 10, 25, 25, 50, 50, 100, ...(new Array(42 - 13).fill(100))], + private: [10, 15, 75, 150, 250] +} + +function getBestiaryTier(family, kills) { + let type = "mob" + + if (islandmobs.has(family)) type = "private" + if (bossmobs.has(family)) type = "boss" + + let killsLeft = kills + let data = bestiaryData[type] + + let dataI = 0 + while (dataI < data.length && killsLeft >= data[dataI]) { + killsLeft -= data[dataI] + dataI++ + } + + return { + level: dataI, + killsLeft, + killsForNext: data[dataI] || null + } +} let someData = { leveling_xp: { 1: 50, |