2022-12-08 12:46:22 +01:00
|
|
|
-- Table of items which can be counted in this Bowl
|
|
|
|
-- Each entry has 2 things to enter
|
|
|
|
-- a name (what is in the name field of that object)
|
|
|
|
-- a value (how much it is worth)
|
|
|
|
-- a number in the items description will override the number entry in this table
|
|
|
|
local validCountItemList = {
|
|
|
|
["Clue"] = 1,
|
|
|
|
[""] = 1
|
2021-10-06 20:37:31 -07:00
|
|
|
}
|
2022-12-08 12:46:22 +01:00
|
|
|
exposedValue = 0
|
2021-10-06 20:37:31 -07:00
|
|
|
|
|
|
|
function onLoad()
|
2022-12-08 12:46:22 +01:00
|
|
|
self.createButton({
|
|
|
|
label = "",
|
2023-10-02 13:51:10 +02:00
|
|
|
click_function = "countItems",
|
2022-12-08 12:46:22 +01:00
|
|
|
function_owner = self,
|
|
|
|
position = { 0, 0.1, 0 },
|
|
|
|
height = 0,
|
|
|
|
width = 0,
|
|
|
|
font_color = { 0, 0, 0 },
|
|
|
|
font_size = 2000
|
|
|
|
})
|
|
|
|
loopID = Wait.time(countItems, 1, -1)
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
|
|
|
|
2022-12-08 12:46:22 +01:00
|
|
|
-- Activated once per second, counts items in bowls
|
2021-10-06 20:37:31 -07:00
|
|
|
function countItems()
|
2023-01-08 22:48:34 +01:00
|
|
|
local totalValue = 0
|
2023-10-18 20:55:38 +02:00
|
|
|
for _, item in ipairs(findValidItemsInSphere()) do
|
|
|
|
local descValue = tonumber(item.getDescription())
|
|
|
|
local stackMult = math.abs(item.getQuantity())
|
2022-12-08 12:46:22 +01:00
|
|
|
-- Use value in description if available
|
|
|
|
if descValue ~= nil then
|
|
|
|
totalValue = totalValue + descValue * stackMult
|
|
|
|
else
|
|
|
|
-- Otherwise use the value in validCountItemList
|
2023-10-18 20:55:38 +02:00
|
|
|
totalValue = totalValue + validCountItemList[item.getName()] * stackMult
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
2022-12-08 12:46:22 +01:00
|
|
|
end
|
|
|
|
exposedValue = totalValue
|
|
|
|
self.editButton({ index = 0, label = totalValue })
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
|
|
|
|
2022-12-08 12:46:22 +01:00
|
|
|
function findValidItemsInSphere()
|
|
|
|
local items = Physics.cast({
|
|
|
|
origin = self.getPosition(),
|
|
|
|
direction = { 0, 1, 0 },
|
|
|
|
type = 2,
|
|
|
|
max_distance = 0,
|
2023-10-01 11:28:31 +02:00
|
|
|
size = { 2, 2, 2 }
|
2022-12-08 12:46:22 +01:00
|
|
|
})
|
2021-10-06 20:37:31 -07:00
|
|
|
|
2023-10-18 20:55:38 +02:00
|
|
|
local validItemList = {}
|
2022-12-08 12:46:22 +01:00
|
|
|
for _, entry in ipairs(items) do
|
|
|
|
if entry.hit_object ~= self then
|
2023-10-18 20:55:38 +02:00
|
|
|
if validCountItemList[entry.hit_object.getName()] ~= nil then
|
|
|
|
table.insert(validItemList, entry.hit_object)
|
2022-12-08 12:46:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-10-18 20:55:38 +02:00
|
|
|
return validItemList
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
|
|
|
|
2023-10-02 13:51:10 +02:00
|
|
|
function removeAllClues(trash)
|
|
|
|
for _, obj in ipairs(findValidItemsInSphere()) do
|
|
|
|
trash.putObject(obj)
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
2023-10-02 13:51:10 +02:00
|
|
|
end
|