doom counter update

This commit is contained in:
Chr1Z93 2023-09-30 01:56:34 +02:00
parent b1cff2fc28
commit 2d85f913b1

View File

@ -20,38 +20,60 @@ function onLoad()
color = { 0, 0, 0, 0 } color = { 0, 0, 0, 0 }
}) })
trash = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "Trash"}) trash = Global.call("getObjectFromMemo", { matColor = "Mythos", type = "Trash" })
ZONE = Global.call("getObjectFromMemo", {matColor = "Mythos", type = "PlayAreaZone"}) ZONE = Global.call("getObjectFromMemo", { matColor = "Mythos", type = "PlayAreaZone" })
loopID = Wait.time(countDoom, 2, -1) loopID = Wait.time(countDoom, 2, -1)
end end
-- main function -- main function
function countDoom() function countDoom()
local doom = 0 local objList = {}
for i = 1, 4 do
doom = doom + countDoomFromList(playmatApi.searchAroundPlaymat(COLORS[i])) -- get doom objects in play area zone
for _, obj in ipairs(ZONE.getObjects()) do
if filterDoom(obj) then
table.insert(objList, obj)
end
end end
doom = doom + countDoomFromList(ZONE.getObjects())
-- get doom objects on playmats
for i = 1, 4 do
local playmatList = playmatApi.searchAroundPlaymat(COLORS[i])
for _, obj in ipairs(playmatList) do
if filterDoom(obj) then
table.insert(objList, obj)
end
end
end
local doom = countDoomFromList(objList)
self.editButton({ index = 0, label = tostring(doom) }) self.editButton({ index = 0, label = tostring(doom) })
end end
function countDoomFromList(objList) function countDoomFromList(objList)
local count = 0 local count = 0
for _, obj in ipairs(objList) do for _, obj in ipairs(objList) do
count = count + isDoom(obj) count = count + getDoomAmount(obj)
end end
return count return count
end end
-- checks an object for the doom image and gets quantity (for stacks) function filterDoom(obj)
function isDoom(obj) if (obj.is_face_down and obj.getCustomObject().image_bottom == doomURL)
if (obj.is_face_down and obj.getCustomObject().image_bottom == doomURL) or or (obj.name == "Custom_Token" and obj.getCustomObject().image == doomURL) then
(obj.name == "Custom_Token" and obj.getCustomObject().image == doomURL) then return true
if not obj.hasTag(IGNORE_TAG) then else
return math.abs(obj.getQuantity()) return false
end end
end
-- gets quantity (for stacks) of doom
function getDoomAmount(obj)
if not obj.hasTag(IGNORE_TAG) then
return math.abs(obj.getQuantity())
else
return 0
end end
return 0
end end
-- removes doom from playermats / playarea -- removes doom from playermats / playarea
@ -64,7 +86,7 @@ function removeDoom(options)
end end
broadcastToAll(count .. " doom removed from Playermats.", "White") broadcastToAll(count .. " doom removed from Playermats.", "White")
end end
if options.Playarea then if options.Playarea then
count = removeDoomFromList(ZONE.getObjects()) count = removeDoomFromList(ZONE.getObjects())
broadcastToAll(count .. " doom removed from Playerarea.", "White") broadcastToAll(count .. " doom removed from Playerarea.", "White")
@ -75,7 +97,7 @@ end
function removeDoomFromList(objList) function removeDoomFromList(objList)
local count = 0 local count = 0
for _, obj in ipairs(objList) do for _, obj in ipairs(objList) do
local amount = isDoom(obj) local amount = getDoomAmount(obj)
if amount > 0 then if amount > 0 then
TRASH.putObject(obj) TRASH.putObject(obj)
count = count + amount count = count + amount