87 lines
2.3 KiB
Plaintext
87 lines
2.3 KiB
Plaintext
-- 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
|
|
}
|
|
local trashGUID = "70b9f6"
|
|
exposedValue = 0
|
|
|
|
function onLoad()
|
|
self.createButton({
|
|
label = "",
|
|
click_function = "removeAllClues",
|
|
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)
|
|
end
|
|
|
|
-- Activated once per second, counts items in bowls
|
|
function countItems()
|
|
local totalValue = 0
|
|
local countableItems = findValidItemsInSphere()
|
|
for _, entry in ipairs(countableItems) do
|
|
local descValue = tonumber(entry.hit_object.getDescription())
|
|
local stackMult = math.abs(entry.hit_object.getQuantity())
|
|
-- Use value in description if available
|
|
if descValue ~= nil then
|
|
totalValue = totalValue + descValue * stackMult
|
|
else
|
|
-- Otherwise use the value in validCountItemList
|
|
totalValue = totalValue + validCountItemList[entry.hit_object.getName()] * stackMult
|
|
end
|
|
end
|
|
exposedValue = totalValue
|
|
self.editButton({ index = 0, label = totalValue })
|
|
end
|
|
|
|
function findValidItemsInSphere()
|
|
local items = Physics.cast({
|
|
origin = self.getPosition(),
|
|
direction = { 0, 1, 0 },
|
|
type = 2,
|
|
max_distance = 0,
|
|
size = { 2, 2, 2 },
|
|
--debug=true
|
|
})
|
|
|
|
retval = {}
|
|
for _, entry in ipairs(items) do
|
|
--Ignore the bowl
|
|
if entry.hit_object ~= self then
|
|
--Ignore if not in validCountItemList
|
|
local tableEntry = validCountItemList[entry.hit_object.getName()]
|
|
if tableEntry ~= nil then
|
|
table.insert(retval, entry)
|
|
end
|
|
end
|
|
end
|
|
return retval
|
|
end
|
|
|
|
function removeAllClues()
|
|
startLuaCoroutine(self, "clueRemovalCoroutine")
|
|
end
|
|
|
|
function clueRemovalCoroutine()
|
|
for _, entry in ipairs(findValidItemsInSphere()) do
|
|
-- Do not put the table in the garbage
|
|
if entry.hit_object.getGUID() ~= "4ee1f2" then
|
|
-- delay for animation purposes
|
|
for k = 1, 10 do
|
|
coroutine.yield(0)
|
|
end
|
|
getObjectFromGUID(trashGUID).putObject(entry.hit_object)
|
|
end
|
|
end
|
|
return 1
|
|
end
|