From a6dbffc48bd85c2f660033ab5b96ff7308c74111 Mon Sep 17 00:00:00 2001 From: Eric Frechette Date: Sat, 8 Jun 2024 23:21:22 -0500 Subject: [PATCH] add capability to clear data for guild --- CalamityEPGP/config.lua | 38 +++++++++++++++++++++++++++++++---- CalamityEPGP/lib.lua | 4 ++++ CalamityEPGP/main.lua | 44 +++++++++++++++++++++++++++++++++++++++++ CalamityEPGP/values.lua | 1 + 4 files changed, 83 insertions(+), 4 deletions(-) diff --git a/CalamityEPGP/config.lua b/CalamityEPGP/config.lua index 1df26fa..81c52fa 100644 --- a/CalamityEPGP/config.lua +++ b/CalamityEPGP/config.lua @@ -147,9 +147,17 @@ function Config:init() debugMode = { type = 'toggle', name = 'Debug Mode', + order = 1, get = 'getDebugMode', set = 'setDebugMode', - } + }, + clearDataForAll = { + type = 'execute', + name = 'Clear all data for everyone', + order = 2, + func = 'clearDataForAll', + disabled = 'getClearDataForAllDisabled', + }, } } } @@ -940,6 +948,24 @@ function Config.clearData() end +function Config.clearDataForAll() + if not ns.Lib.isOfficer() then + error('Non-officers cannot clear data for everyone') + return + end + + if not ns.cfg.lmMode then + error('Cannot clear data for everyone when loot master mode is off') + return + end + + ns.ConfirmWindow:show( + 'Are you sure you want to clear all data for everyone?\nWARNING: this is irreversible!', + function() ns.addon:clearDataForAll() end + ) +end + + ------------------------- -- OPTION GETTERS/SETTERS ------------------------- @@ -1034,13 +1060,17 @@ function Config:getLmModeDisabled() end function Config:getDefaultDecayEpDisabled() - return not ns.cfg.lmMode + return not ns.Lib.isOfficer() or not ns.cfg.lmMode end function Config:getDefaultDecayGpDisabled() - return not ns.cfg.lmMode + return not ns.Lib.isOfficer() or not ns.cfg.lmMode end function Config:getGpManagementDisabled() - return not ns.cfg.lmMode + return not ns.Lib.isOfficer() or not ns.cfg.lmMode +end + +function Config:getClearDataForAllDisabled() + return not ns.Lib.isOfficer() or not ns.cfg.lmMode end diff --git a/CalamityEPGP/lib.lua b/CalamityEPGP/lib.lua index d998da4..74bc576 100644 --- a/CalamityEPGP/lib.lua +++ b/CalamityEPGP/lib.lua @@ -768,6 +768,10 @@ function Lib.getEventReason(reason, ...) return reasonStr end + if reason == ns.values.epgpReasons.CLEAR then + return ('%d:'):format(ns.values.epgpReasons.CLEAR) + end + error(('Unknown event reason: %s'):format(reason)) end diff --git a/CalamityEPGP/main.lua b/CalamityEPGP/main.lua index b5f59c0..be04712 100644 --- a/CalamityEPGP/main.lua +++ b/CalamityEPGP/main.lua @@ -572,10 +572,32 @@ function addon:computeStandingsWithEvents(events, callback) local players = event[3] local mode = event[4] local value = event[5] + local reason = event[6] local percent = event[7] -- local minGp = event[8] local minGp = ns.cfg.gpBase + local reasonType = string.match(reason, '^(%d):.*$') + reasonType = tonumber(reasonType) + + if reasonType == ns.values.epgpReasons.CLEAR then + local newHistory = {} + for _, historyEventAndHash in ipairs(ns.db.history) do + local historyEvent = historyEventAndHash[1] + local historyTs = historyEvent[1] + + if historyTs >= ts then + tinsert(newHistory, historyEventAndHash) + end + end + + ns.db.history = newHistory + + playerDiffs:clear() + ns.standings:clear() + ns.playersLastUpdated:clear() + end + local mains = Set:new() for _, guidShort in ipairs(players) do @@ -1088,6 +1110,28 @@ function addon:clearData() end +function addon:clearDataForAll() + if not ns.Lib.isOfficer() then + error('Non-officers cannot clear history') + return + end + + if not ns.cfg.lmMode then + error('Cannot modify EPGP when loot master mode is off') + return + end + + local event = self.createHistoryEvent({}, 'ep', 0, ns.Lib.getEventReason(ns.values.epgpReasons.CLEAR)) + + self:clearData() + + tinsert(ns.db.history, event) + + ns.Sync:computeIndices(false) + ns.Sync:sendEventsToGuild({event}) +end + + function addon.modifiedLmSettings() ns.db.lmSettingsLastChange = time() ns.Sync:sendLmSettingsToGuild() diff --git a/CalamityEPGP/values.lua b/CalamityEPGP/values.lua index 7cd4016..0e5bdb9 100644 --- a/CalamityEPGP/values.lua +++ b/CalamityEPGP/values.lua @@ -8,6 +8,7 @@ ns.values.epgpReasons = { DECAY = 2, AWARD = 3, BOSS_KILL = 4, + CLEAR = 5, } ns.values.gpDefaults = {