From f1eb200c8367a62ee215fd2e4aa2e8d739aa744a Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Sun, 12 Dec 2021 15:21:02 +0800 Subject: Added guild event thing for sbg --- features/lockedFeatures/index.js | 129 ++++++++++++++++++++++++++++++++++ features/lockedFeatures/metadata.json | 8 +++ features/slayers/index.js | 10 +-- 3 files changed, 138 insertions(+), 9 deletions(-) create mode 100644 features/lockedFeatures/index.js create mode 100644 features/lockedFeatures/metadata.json (limited to 'features') diff --git a/features/lockedFeatures/index.js b/features/lockedFeatures/index.js new file mode 100644 index 0000000..551922b --- /dev/null +++ b/features/lockedFeatures/index.js @@ -0,0 +1,129 @@ +/// +/// +import Feature from "../../featureClass/class"; +import ToggleSetting from "../settings/settingThings/toggle"; +import SoopyV2Server from "../../socketConnection" +import HudTextElement from "../hud/HudTextElement"; +import LocationSetting from "../settings/settingThings/location"; +import { numberWithCommas, timeNumber, timeSince } from "../../utils/numberUtils"; + +class LockedFeatures extends Feature { + constructor() { + super() + } + + onEnable(){ + this.initVariables() + + this.guildEventLbPossible = new FakeRequireToggle(false) + this.guildEventLb = new ToggleSetting("Guild event leaderboard", "A gui element for guild leaderboard progress", true, "guild_event_lb", this).requires(this.guildEventLbPossible) + + this.hudElements = [] + this.guildLbElement = new HudTextElement() + .setToggleSetting(this.guildEventLb) + .setLocationSetting(new LocationSetting("Guild Lb Location", "Allows you to edit the location of the guild leaderboard", "guild_lb_location", this, [50, 40, 1, 1]) + .requires(this.guildEventLb)) + this.hudElements.push(this.guildLbElement) + + this.registerStep(true, 1, this.step) + this.registerEvent("renderOverlay", this.renderOverlay) + } + + step(){ + if(!SoopyV2Server.lbdatathing){ + this.guildEventLbPossible.set(false) + return; + } + + this.guildEventLbPossible.set(true) + + if(!this.guildEventLb.getValue()) return + + let text = "" + + let playerPos = 0 + + SoopyV2Server.lbdatathing.forEach((u, i)=>{ + if(u.uuid === Player.getUUID().toString().replace(/-/g, "")) playerPos = i + }) + + let prevProgress + let playerProgress + let nextProgress + + SoopyV2Server.lbdatathing.forEach((u, i)=>{ + if(i === playerPos-1) nextProgress = [parseFloat(u.startingAmount), u.progress] + if(i === playerPos) playerProgress = [parseFloat(u.startingAmount), u.progress] + if(i === playerPos+1) prevProgress = [parseFloat(u.startingAmount), u.progress] + if(i === playerPos-1 || i === playerPos || i === playerPos+1){ + text += "§6#" + (i+1) + text += "§7 - " + text += "§e"+u.username + text += "&7: §r"+numberWithCommas(Math.round(parseFloat(u.startingAmount))) + if(u.progress) text += " §7("+ (u.progress>0?"+":"-")+Math.abs(Math.round(u.progress)) + "/h)" + text += "\n" + } + }) + + text += "&dLast updated " + timeSince(SoopyV2Server.lbdatathingupdated) + " ago" + + let timeTillIncrease = Infinity + let timeTillDecrease = Infinity + if(nextProgress[1]-playerProgress[1] < 0){ + timeTillIncrease = Math.abs((nextProgress[0]-playerProgress[0])/(nextProgress[1]-playerProgress[1])*60*60*1000) + } + if(prevProgress[1]-playerProgress[1] < 0){ + timeTillDecrease = Math.abs((prevProgress[0]-playerProgress[0])/(prevProgress[1]-playerProgress[1])*60*60*1000) + } + + if(timeTillIncrease < timeTillDecrease && timeTillIncrease < 10000000000){ + text = "&dRank increasing in ~" + timeNumber(timeTillIncrease) + "\n"+text + } + if(timeTillIncrease > timeTillDecrease && timeTillDecrease < 10000000000){ + text = "&dRank decreasing in ~" + timeNumber(timeTillDecrease) + "\n"+text + } + + this.guildLbElement.setText(text) + } + + renderOverlay(){ + this.hudElements.forEach(a=>a.render()) + } + + initVariables(){ + + } + + onDisable(){ + this.initVariables() + } +} + +module.exports = { + class: new LockedFeatures() +} + +class FakeRequireToggle{ + constructor(val){ + this.val = val + + this.thisToggleEvents = [] + + this.toggleObject = { + addEvent: (event)=>{ + this.thisToggleEvents.push(event) + } + } + } + + set(newVal){ + if(this.val === newVal) return + this.val = newVal + + this.thisToggleEvents.forEach(e=>e._trigger(this, [this.val])) + } + + getValue(){ + return this.val + } +} \ No newline at end of file diff --git a/features/lockedFeatures/metadata.json b/features/lockedFeatures/metadata.json new file mode 100644 index 0000000..7506cc2 --- /dev/null +++ b/features/lockedFeatures/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "Locked Features", + "description": "A bunch of random features that are only accessable to some people\n§0(eg only people in specific guild)", + "isHidden": false, + "isTogglable": true, + "defaultEnabled": true, + "sortA": 1 +} \ No newline at end of file diff --git a/features/slayers/index.js b/features/slayers/index.js index 347cfaa..5b6e5ac 100644 --- a/features/slayers/index.js +++ b/features/slayers/index.js @@ -2,7 +2,7 @@ /// import Feature from "../../featureClass/class"; import { f, m } from "../../../mappings/mappings"; -import { numberWithCommas } from "../../utils/numberUtils"; +import { numberWithCommas, timeNumber } from "../../utils/numberUtils"; import { drawBoxAtBlock, drawBoxAtEntity, drawFilledBox, drawLine } from "../../utils/renderUtils"; import HudTextElement from "../hud/HudTextElement"; import LocationSetting from "../settings/settingThings/location"; @@ -380,11 +380,3 @@ class Slayers extends Feature { module.exports = { class: new Slayers() } - -function timeNumber(time){ - let mins = Math.floor(time/1000/60) - let secs = Math.floor(time/1000)%60 - - if(mins === 0) return secs + "s" - return `${mins}m ${secs}s` -} \ No newline at end of file -- cgit From 243403b0274956c2e781392d07a785386354f1c5 Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Sun, 12 Dec 2021 19:02:53 +0800 Subject: fix incorrect rank changing calculations --- features/lockedFeatures/index.js | 14 +++++++------- utils/numberUtils.js | 7 +++++++ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'features') diff --git a/features/lockedFeatures/index.js b/features/lockedFeatures/index.js index 551922b..04ac729 100644 --- a/features/lockedFeatures/index.js +++ b/features/lockedFeatures/index.js @@ -5,7 +5,7 @@ import ToggleSetting from "../settings/settingThings/toggle"; import SoopyV2Server from "../../socketConnection" import HudTextElement from "../hud/HudTextElement"; import LocationSetting from "../settings/settingThings/location"; -import { numberWithCommas, timeNumber, timeSince } from "../../utils/numberUtils"; +import { numberWithCommas, timeNumber2, timeSince } from "../../utils/numberUtils"; class LockedFeatures extends Feature { constructor() { @@ -70,17 +70,17 @@ class LockedFeatures extends Feature { let timeTillIncrease = Infinity let timeTillDecrease = Infinity if(nextProgress[1]-playerProgress[1] < 0){ - timeTillIncrease = Math.abs((nextProgress[0]-playerProgress[0])/(nextProgress[1]-playerProgress[1])*60*60*1000) + timeTillIncrease = ((nextProgress[0]-playerProgress[0])/(playerProgress[1]-nextProgress[1])*60*60*1000) } if(prevProgress[1]-playerProgress[1] < 0){ - timeTillDecrease = Math.abs((prevProgress[0]-playerProgress[0])/(prevProgress[1]-playerProgress[1])*60*60*1000) + timeTillDecrease = ((playerProgress[0]-prevProgress[0])/(prevProgress[1]-playerProgress[1])*60*60*1000) } - if(timeTillIncrease < timeTillDecrease && timeTillIncrease < 10000000000){ - text = "&dRank increasing in ~" + timeNumber(timeTillIncrease) + "\n"+text + if((timeTillIncrease < timeTillDecrease || (timeTillIncrease > 0)) && timeTillDecrease < 0 && timeTillIncrease < 10000000000){ + text = "&d ^ in " + timeNumber2(timeTillIncrease) + "\n"+text } - if(timeTillIncrease > timeTillDecrease && timeTillDecrease < 10000000000){ - text = "&dRank decreasing in ~" + timeNumber(timeTillDecrease) + "\n"+text + if((timeTillIncrease > timeTillDecrease || (timeTillDecrease>0))&&timeTillIncrease<0 && timeTillDecrease < 10000000000){ + text = "&d V in " + timeNumber2(timeTillDecrease) + "\n"+text } this.guildLbElement.setText(text) diff --git a/utils/numberUtils.js b/utils/numberUtils.js index 1258d90..96a6b74 100644 --- a/utils/numberUtils.js +++ b/utils/numberUtils.js @@ -82,5 +82,12 @@ module.exports = { if(mins === 0) return secs + "s" return `${mins}m ${secs}s` + }, + timeNumber2: function(time){ + let hours = Math.floor(time/1000/60/60) + let mins = Math.floor(time/1000/60)%60 + + if(hours === 0) return mins + "m" + return `${hours}h ${mins}m` } } \ No newline at end of file -- cgit