WIP clue counting method swapping

This commit is contained in:
Chr1Z93 2022-12-08 12:46:22 +01:00
parent d53302c9e0
commit 19e538fbd9
10 changed files with 103 additions and 96 deletions

View File

@ -52,7 +52,7 @@
"Tooltip": true,
"Transform": {
"posX": -31.911,
"posY": 1.57,
"posY": 1.52,
"posZ": 30.97,
"rotX": 0,
"rotY": 0,

View File

@ -52,7 +52,7 @@
"Tooltip": true,
"Transform": {
"posX": -59.449,
"posY": 1.57,
"posY": 1.52,
"posZ": -22.628,
"rotX": 0,
"rotY": 270,

View File

@ -52,7 +52,7 @@
"Tooltip": true,
"Transform": {
"posX": -18.983,
"posY": 1.57,
"posY": 1.52,
"posZ": -31.01,
"rotX": 0,
"rotY": 180,

View File

@ -52,7 +52,7 @@
"Tooltip": true,
"Transform": {
"posX": -59.499,
"posY": 1.57,
"posY": 1.52,
"posZ": 9.561,
"rotX": 0,
"rotY": 270,

View File

@ -11,5 +11,6 @@ DISCARD_PILE_POSITION = { x = -58.9, y = 4, z = 4.29 }
TRASHCAN_GUID = "147e80"
STAT_TRACKER_GUID = "e598c2"
RESOURCE_COUNTER_GUID = "4406f0"
CLUE_COUNTER_GUID = "d86b7c"
require("playermat/Playmat")

View File

@ -11,5 +11,6 @@ DISCARD_PILE_POSITION = { x = -58.96, y = 4, z = -27.82 }
TRASHCAN_GUID = "f7b6c8"
STAT_TRACKER_GUID = "b4a5f7"
RESOURCE_COUNTER_GUID = "816d84"
CLUE_COUNTER_GUID = "1769ed"
require("playermat/Playmat")

View File

@ -11,5 +11,6 @@ DISCARD_PILE_POSITION = { x = -37.26, y = 4, z = 30.50 }
TRASHCAN_GUID = "5f896a"
STAT_TRACKER_GUID = "af7ed7"
RESOURCE_COUNTER_GUID = "cd15ac"
CLUE_COUNTER_GUID = "032300"
require("playermat/Playmat")

View File

@ -11,5 +11,6 @@ DISCARD_PILE_POSITION = { x = -13.78, y = 4, z = -30.48 }
TRASHCAN_GUID = "4b8594"
STAT_TRACKER_GUID = "e74881"
RESOURCE_COUNTER_GUID = "a4b60d"
CLUE_COUNTER_GUID = "37be78"
require("playermat/Playmat")

View File

@ -1,91 +1,70 @@
--Counting Bowl by MrStump
--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
validCountItemList = {
["Clue"] = 1,
[""] = 1,
--["Name3"] = 2,
--["Name4"] = 31,
--Add more entries as needed
--Remove the -- from before a line for the script to use it
-- 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
}
--END OF CODE TO EDIT
local trashGUID = "70b9f6"
exposedValue = 0
function onLoad()
timerID = self.getGUID()..math.random(9999999999999)
--Sets position/color for the button, spawns it
self.createButton({
label="", click_function="removeAllClues", function_owner=self,
position={0,0,0}, rotation={0,8,0}, height=0, width=0,
font_color={0,0,0}, font_size=2000
})
--Start timer which repeats forever, running countItems() every second
Timer.create({
identifier=timerID,
function_name="countItems", function_owner=self,
repetitions=0, delay=1
})
exposedValue = 0
trashCan = getObjectFromGUID("147e80")
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 = -1
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()
return filterByValidity(findItemsInSphere())
end
local items = Physics.cast({
origin = self.getPosition(),
direction = { 0, 1, 0 },
type = 2,
max_distance = 0,
size = { 2, 2, 2 },
--debug=true
})
--Activated once per second, counts items in bowls
function countItems()
local totalValue = -1
local countableItems = findValidItemsInSphere()
for ind, 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
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
exposedValue = totalValue
--Updates the number display
self.editButton({index=0, label=totalValue})
end
function filterByValidity(items)
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
--Gets the items in the bowl for countItems to count
function findItemsInSphere()
--Find scaling factor
local scale = self.getScale()
--Set position for the sphere
local pos = self.getPosition()
pos.y=pos.y+(1.25*scale.y)
--Ray trace to get all objects
return Physics.cast({
origin=pos, direction={0,1,0}, type=2, max_distance=0,
size={6*scale.x,6*scale.y,6*scale.z}, --debug=true
})
end
return retval
end
function removeAllClues()
@ -96,19 +75,12 @@ 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
-- delay for animation purposes
for k = 1, 10 do
coroutine.yield(0)
end
trashCan.putObject(entry.hit_object)
getObjectFromGUID(trashGUID).putObject(entry.hit_object)
end
end
--coroutines must return a value
return 1
end
function onDestroy()
if timerID and type(timerID) == 'object' then
Timer.destroy(timerID)
end
end

View File

@ -675,10 +675,41 @@ function showDrawButton(visibleButton)
end
end
-- Spawns / destroys a clickable clue counter for this playmat
-- Spawns / destroys a clickable clue counter for this playmat with the correct amount of clues
---@param clickableCounter Boolean. Whether the clickable clue counter should be present
function clickableClues(clickableCounter)
print("dummy function for clue counters")
local CLUE_COUNTER = getObjectFromGUID(CLUE_COUNTER_GUID)
local pos = self.positionToWorld({x = -1.03, y = 0.05, z = 0.69})
local clueCount = 0
if clickableCounter then
-- current clue count
clueCount = CLUE_COUNTER.getVar("exposedValue")
-- remove clues
CLUE_COUNTER.call("removeAllClues")
-- spawn clue counter
-- update master clue counter
else
-- current clue count
-- remove clue counter
-- spawn clues
for i = 1, clueCount do
pos.y = pos.y + 0.1 * i
spawnToken(pos, "clue")
end
-- rotation = {x= 0, y= PLAY_ZONE_ROTATION.y + 15, z =0 }
-- update master clue counter
end
end
-- Sets this playermat's snap points to limit snapping to matching card types or not. If matchTypes