Merge pull request #840 from argonui/bless-curse

Added anti-spam handling to Bless/Curse Manager
This commit is contained in:
dscarpac 2024-08-23 15:07:11 -05:00 committed by GitHub
commit 8d732e7162
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,8 @@ buttonParamaters.width = 700
buttonParamaters.height = 700
local updating
local waitIds = {}
local currentCount = {}
---------------------------------------------------------
-- creating buttons and menus + initializing tables
@ -162,8 +164,11 @@ function doRemove(color)
end
end
broadcastToColor("Removed " .. count.Bless .. " Bless and " .. count.Curse .. " Curse tokens from the chaos bag.", color, "White")
broadcastToColor("Removed " .. removeTakenTokens("Bless") .. " Bless and " .. removeTakenTokens("Curse") .. " Curse tokens from play.", color, "White")
broadcastToColor("Removed " .. count.Bless .. " Bless and " .. count.Curse .. " Curse tokens from the chaos bag.",
color, "White")
broadcastToColor(
"Removed " .. removeTakenTokens("Bless") .. " Bless and " .. removeTakenTokens("Curse") .. " Curse tokens from play.",
color, "White")
resetTables()
updateButtonLabels()
@ -286,8 +291,8 @@ function addToken(type)
printToColor("10 tokens already in play, not adding any.", playerColor)
return
end
printCountWithDelay(type)
numInPlay[type] = numInPlay[type] + 1
printToAll("Adding " .. type .. " token " .. formatTokenCount(type))
updateButtonLabels()
return chaosBagApi.spawnChaosToken(type)
end
@ -307,12 +312,13 @@ function removeToken(type)
return
end
printCountWithDelay(type)
chaosBag.takeObject({
guid = table.remove(tokens),
smooth = false,
callback_function = function(obj)
numInPlay[type] = numInPlay[type] - 1
printToAll("Removing " .. type .. " token " .. formatTokenCount(type))
updateButtonLabels()
obj.destruct()
tokenArrangerApi.layout()
@ -333,6 +339,31 @@ function removeTakenTokens(type)
return count
end
-- prints the changes to the chaos bag after 1s delay, bundles them into a single message
function printCountWithDelay(type)
if waitIds[type] then
Wait.stop(waitIds[type])
else
currentCount[type] = numInPlay[type]
end
waitIds[type] = Wait.time(function()
local diff = numInPlay[type] - currentCount[type]
local tokenString = " tokens "
if diff == 1 then
tokenString = " token "
end
if diff > 0 then
printToAll("Added " .. math.abs(diff) .. " " .. type .. tokenString .. formatTokenCount(type))
elseif diff < 0 then
printToAll("Removed " .. math.abs(diff) .. " " .. type .. tokenString .. formatTokenCount(type))
end
waitIds[type] = nil
currentCount[type] = nil
end, 1)
end
---------------------------------------------------------
-- Wendy's Menu (context menu for cards on hotkey press)
---------------------------------------------------------