Skip to content

Commit

Permalink
add capability to clear data for guild
Browse files Browse the repository at this point in the history
  • Loading branch information
Frechetta committed Jun 9, 2024
1 parent 4c65211 commit a6dbffc
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
38 changes: 34 additions & 4 deletions CalamityEPGP/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
}
}
}
Expand Down Expand Up @@ -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
-------------------------
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions CalamityEPGP/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 44 additions & 0 deletions CalamityEPGP/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions CalamityEPGP/values.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ns.values.epgpReasons = {
DECAY = 2,
AWARD = 3,
BOSS_KILL = 4,
CLEAR = 5,
}

ns.values.gpDefaults = {
Expand Down

0 comments on commit a6dbffc

Please sign in to comment.