2022-11-12 11:46:05 +01:00
|
|
|
---------------------------------------------------------
|
|
|
|
-- general setup
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
2021-10-06 20:37:31 -07:00
|
|
|
-- set true to enable debug logging
|
|
|
|
DEBUG = false
|
|
|
|
|
2022-11-12 11:46:05 +01:00
|
|
|
-- we use this to turn off collision handling until onLoad() is complete
|
2021-10-06 20:37:31 -07:00
|
|
|
COLLISION_ENABLED = false
|
|
|
|
|
2023-01-01 17:29:24 +01:00
|
|
|
-- used for recreating the link to a custom data helper after image change
|
|
|
|
customDataHelper = nil
|
|
|
|
|
2022-12-12 18:56:04 -08:00
|
|
|
local SHIFT_OFFSETS = {
|
|
|
|
left = { x = 0.00, y = 0, z = 7.67 },
|
|
|
|
right = { x = 0.00, y = 0, z = -7.67 },
|
|
|
|
up = { x = 6.54, y = 0, z = 0.00 },
|
|
|
|
down = { x = -6.54, y = 0, z = 0.00 }
|
|
|
|
}
|
|
|
|
local SHIFT_EXCLUSION = {
|
|
|
|
["b7b45b"] = true,
|
|
|
|
["f182ee"] = true,
|
|
|
|
["721ba2"] = true
|
|
|
|
}
|
|
|
|
|
2023-01-01 23:35:16 +01:00
|
|
|
local tokenManager = require("core/token/TokenManager")
|
2022-11-24 13:38:29 -08:00
|
|
|
local INVESTIGATOR_COUNTER_GUID = "f182ee"
|
2022-12-12 18:56:04 -08:00
|
|
|
local PLAY_AREA_ZONE_GUID = "a2f932"
|
2023-01-01 23:35:16 +01:00
|
|
|
local lastCollisionObject
|
2022-12-15 00:29:56 -08:00
|
|
|
local currentScenario
|
2022-11-13 01:12:01 +01:00
|
|
|
|
2022-11-12 11:46:05 +01:00
|
|
|
---------------------------------------------------------
|
|
|
|
-- general code
|
|
|
|
---------------------------------------------------------
|
2021-10-06 20:37:31 -07:00
|
|
|
|
2022-12-15 00:29:56 -08:00
|
|
|
function onSave()
|
|
|
|
return JSON.encode({
|
|
|
|
currentScenario = currentScenario
|
|
|
|
})
|
|
|
|
end
|
2021-10-06 20:37:31 -07:00
|
|
|
|
2022-12-15 00:29:56 -08:00
|
|
|
function onLoad(saveState)
|
2022-11-12 11:46:05 +01:00
|
|
|
-- records locations we have spawned clues for
|
2022-12-15 00:29:56 -08:00
|
|
|
local saveData = JSON.decode(saveState) or {}
|
|
|
|
currentScenario = saveData.currentScenario
|
2021-10-06 20:37:31 -07:00
|
|
|
|
2022-11-12 11:46:05 +01:00
|
|
|
self.interactable = DEBUG
|
|
|
|
Wait.time(function() COLLISION_ENABLED = true end, 1)
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
|
|
|
|
2022-11-12 11:46:05 +01:00
|
|
|
function log(message)
|
|
|
|
if DEBUG then print(message) end
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
|
|
|
|
2022-12-28 02:57:43 -08:00
|
|
|
-- Called by Custom Data Helpers to push their location data into the Data Helper. This adds the
|
|
|
|
-- data to the local token manager instance.
|
|
|
|
---@param args Table Single-value array holding the GUID of the Custom Data Helper making the call
|
2021-10-06 20:37:31 -07:00
|
|
|
function updateLocations(args)
|
2023-01-01 17:29:24 +01:00
|
|
|
customDataHelper = getObjectFromGUID(args[1])
|
2022-12-28 02:57:43 -08:00
|
|
|
if customDataHelper ~= nil then
|
|
|
|
tokenManager.addLocationData(customDataHelper.getTable("LOCATIONS_DATA"))
|
2022-11-12 11:46:05 +01:00
|
|
|
end
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
function onCollisionEnter(collision_info)
|
2023-01-01 23:35:16 +01:00
|
|
|
local obj = collision_info.collision_object
|
|
|
|
|
|
|
|
-- only trigger the following once every 0.1s for each object
|
|
|
|
-- (otherwise TTS fires this event 20 times and that causes 20 JSON decodes)
|
|
|
|
if not COLLISION_ENABLED or lastCollisionObject == obj then return end
|
|
|
|
lastCollisionObject = obj
|
|
|
|
Wait.time(function() lastCollisionObject = nil end, 0.1)
|
2021-10-06 20:37:31 -07:00
|
|
|
|
2022-11-12 11:46:05 +01:00
|
|
|
-- check if we should spawn clues here and do so according to playercount
|
2023-01-01 23:35:16 +01:00
|
|
|
if shouldSpawnTokens(obj) then
|
|
|
|
tokenManager.spawnForCard(obj)
|
2022-12-28 02:57:43 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function shouldSpawnTokens(card)
|
|
|
|
local metadata = JSON.decode(card.getGMNotes())
|
|
|
|
if metadata == nil then
|
2023-01-01 23:35:16 +01:00
|
|
|
return tokenManager.hasLocationData(card)
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
2022-12-28 02:57:43 -08:00
|
|
|
return metadata.type == "Location"
|
|
|
|
or metadata.type == "Enemy"
|
|
|
|
or metadata.type == "Treachery"
|
|
|
|
or metadata.weakness
|
2021-10-06 20:37:31 -07:00
|
|
|
end
|
2022-11-24 11:58:57 -08:00
|
|
|
|
2022-12-13 02:15:16 -08:00
|
|
|
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain
|
2023-01-01 23:35:16 +01:00
|
|
|
-- fixed objects will be ignored, as will anything the player has tagged with 'displacement_excluded'
|
|
|
|
---@param playerColor String Color of the player requesting the shift. Used solely to send an error
|
2022-12-12 18:56:04 -08:00
|
|
|
--- message in the unlikely case that the scripting zone has been deleted
|
|
|
|
function shiftContentsUp(playerColor)
|
|
|
|
shiftContents(playerColor, "up")
|
|
|
|
end
|
|
|
|
|
|
|
|
function shiftContentsDown(playerColor)
|
|
|
|
shiftContents(playerColor, "down")
|
|
|
|
end
|
|
|
|
|
|
|
|
function shiftContentsLeft(playerColor)
|
|
|
|
shiftContents(playerColor, "left")
|
|
|
|
end
|
|
|
|
|
|
|
|
function shiftContentsRight(playerColor)
|
|
|
|
shiftContents(playerColor, "right")
|
|
|
|
end
|
|
|
|
|
|
|
|
function shiftContents(playerColor, direction)
|
|
|
|
local zone = getObjectFromGUID(PLAY_AREA_ZONE_GUID)
|
|
|
|
if not zone then
|
|
|
|
broadcastToColor("Scripting zone couldn't be found.", playerColor, "Red")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, object in ipairs(zone.getObjects()) do
|
|
|
|
if not (SHIFT_EXCLUSION[object.getGUID()] or object.hasTag("displacement_excluded")) then
|
|
|
|
object.translate(SHIFT_OFFSETS[direction])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Returns the current value of the investigator counter from the playmat
|
|
|
|
---@return Integer. Number of investigators currently set on the counter
|
2022-11-24 11:58:57 -08:00
|
|
|
function getInvestigatorCount()
|
2022-12-12 18:56:04 -08:00
|
|
|
local investigatorCounter = getObjectFromGUID("f182ee")
|
2022-11-24 11:58:57 -08:00
|
|
|
return investigatorCounter.getVar("val")
|
|
|
|
end
|
2022-12-12 18:56:04 -08:00
|
|
|
|
|
|
|
-- Reset the play area's tracking of which cards have had tokens spawned.
|
|
|
|
function resetSpawnedCards()
|
|
|
|
spawnedLocationGUIDs = {}
|
|
|
|
end
|
2022-12-15 00:29:56 -08:00
|
|
|
|
|
|
|
function onScenarioChanged(scenarioName)
|
|
|
|
currentScenario = scenarioName
|
|
|
|
end
|