2022-12-13 14:02:30 -05:00
|
|
|
-- Bundled by luabundle {"version":"1.6.0"}
|
|
|
|
local __bundle_require, __bundle_loaded, __bundle_register, __bundle_modules = (function(superRequire)
|
|
|
|
local loadingPlaceholder = {[{}] = true}
|
|
|
|
|
|
|
|
local register
|
|
|
|
local modules = {}
|
|
|
|
|
|
|
|
local require
|
|
|
|
local loaded = {}
|
|
|
|
|
|
|
|
register = function(name, body)
|
|
|
|
if not modules[name] then
|
|
|
|
modules[name] = body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require = function(name)
|
|
|
|
local loadedModule = loaded[name]
|
|
|
|
|
|
|
|
if loadedModule then
|
|
|
|
if loadedModule == loadingPlaceholder then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if not modules[name] then
|
|
|
|
if not superRequire then
|
|
|
|
local identifier = type(name) == 'string' and '\"' .. name .. '\"' or tostring(name)
|
|
|
|
error('Tried to require ' .. identifier .. ', but no such module has been registered')
|
|
|
|
else
|
|
|
|
return superRequire(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
loaded[name] = loadingPlaceholder
|
|
|
|
loadedModule = modules[name](require, loaded, register, modules)
|
|
|
|
loaded[name] = loadedModule
|
|
|
|
end
|
|
|
|
|
|
|
|
return loadedModule
|
|
|
|
end
|
|
|
|
|
|
|
|
return require, loaded, register, modules
|
|
|
|
end)(nil)
|
|
|
|
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
|
|
require("core/PlayArea")
|
|
|
|
end)
|
|
|
|
__bundle_register("core/PlayArea", function(require, _LOADED, __bundle_register, __bundle_modules)
|
|
|
|
---------------------------------------------------------
|
|
|
|
-- general setup
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
2020-11-28 13:23:58 -05:00
|
|
|
-- set true to enable debug logging
|
|
|
|
DEBUG = false
|
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
-- we use this to turn off collision handling until onLoad() is complete
|
2020-11-28 13:23:58 -05:00
|
|
|
COLLISION_ENABLED = false
|
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
local INVESTIGATOR_COUNTER_GUID = "f182ee"
|
|
|
|
local clueData = {}
|
|
|
|
spawnedLocationGUIDs = {}
|
2020-11-28 13:23:58 -05:00
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
---------------------------------------------------------
|
|
|
|
-- general code
|
|
|
|
---------------------------------------------------------
|
2020-11-28 13:23:58 -05:00
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
function onSave() return JSON.encode(spawnedLocationGUIDs) end
|
2020-11-28 13:23:58 -05:00
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
function onLoad(save_state)
|
|
|
|
-- records locations we have spawned clues for
|
|
|
|
spawnedLocationGUIDs = JSON.decode(save_state) or {}
|
2020-11-28 13:23:58 -05:00
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
local TOKEN_DATA = Global.getTable('TOKEN_DATA')
|
|
|
|
clueData = {
|
|
|
|
thickness = 0.1,
|
|
|
|
stackable = true,
|
|
|
|
type = 2,
|
|
|
|
image = TOKEN_DATA.clue.image,
|
|
|
|
image_bottom = TOKEN_DATA.doom.image
|
|
|
|
}
|
2020-11-28 13:23:58 -05:00
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
local dataHelper = getObjectFromGUID('708279')
|
|
|
|
LOCATIONS = dataHelper.getTable('LOCATIONS_DATA')
|
2020-11-28 13:23:58 -05:00
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
self.interactable = DEBUG
|
|
|
|
Wait.time(function() COLLISION_ENABLED = true end, 1)
|
2020-11-28 13:23:58 -05:00
|
|
|
end
|
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
function log(message)
|
|
|
|
if DEBUG then print(message) end
|
2020-11-28 13:23:58 -05:00
|
|
|
end
|
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
---------------------------------------------------------
|
|
|
|
-- clue spawning
|
|
|
|
---------------------------------------------------------
|
2020-11-28 13:23:58 -05:00
|
|
|
|
|
|
|
-- try the compound key then the name alone as default
|
|
|
|
function getLocation(object)
|
2022-12-13 14:02:30 -05:00
|
|
|
return LOCATIONS[object.getName() .. '_' .. object.getGUID()] or LOCATIONS[object.getName()]
|
2020-11-28 13:23:58 -05:00
|
|
|
end
|
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
-- Return the number of clues to spawn on this location
|
2020-11-28 13:23:58 -05:00
|
|
|
function getClueCount(object, isFaceDown, playerCount)
|
2022-12-13 14:02:30 -05:00
|
|
|
local details = getLocation(object)
|
|
|
|
if details == nil then
|
2020-11-28 13:23:58 -05:00
|
|
|
error('attempted to get clue for unexpected object: ' .. object.getName())
|
|
|
|
end
|
2022-12-13 14:02:30 -05:00
|
|
|
|
2020-11-28 13:23:58 -05:00
|
|
|
log(object.getName() .. ' : ' .. details['type'] .. ' : ' .. details['value'] .. ' : ' .. details['clueSide'])
|
2022-12-13 14:02:30 -05:00
|
|
|
if ((isFaceDown and details['clueSide'] == 'back') or (not isFaceDown and details['clueSide'] == 'front')) then
|
2020-11-28 13:23:58 -05:00
|
|
|
if details['type'] == 'fixed' then
|
|
|
|
return details['value']
|
|
|
|
elseif details['type'] == 'perPlayer' then
|
|
|
|
return details['value'] * playerCount
|
|
|
|
end
|
|
|
|
error('unexpected location type: ' .. details['type'])
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
function spawnCluesAtLocation(clueCount, object)
|
|
|
|
if spawnedLocationGUIDs[object.getGUID()] ~= nil then
|
2020-11-28 13:23:58 -05:00
|
|
|
error('tried to spawn clue for already spawned location:' .. object.getName())
|
|
|
|
end
|
|
|
|
|
|
|
|
log('spawning clues for ' .. object.getName() .. '_' .. object.getGUID())
|
2022-12-13 14:02:30 -05:00
|
|
|
log('player count is ' .. getInvestigatorCount() .. ', clue count is ' .. clueCount)
|
|
|
|
|
2020-11-28 13:23:58 -05:00
|
|
|
-- mark this location as spawned, can't happen again
|
2022-12-13 14:02:30 -05:00
|
|
|
spawnedLocationGUIDs[object.getGUID()] = true
|
|
|
|
|
2022-12-13 18:01:00 -05:00
|
|
|
-- spawn clues (starting top right, moving to the next column after 4 clues)
|
2022-12-13 14:02:30 -05:00
|
|
|
local pos = object.getPosition()
|
|
|
|
for i = 1, clueCount do
|
2022-12-13 18:01:00 -05:00
|
|
|
local column = math.floor((i - 1) / 4)
|
|
|
|
local row = (i - 1) % 4
|
|
|
|
spawnClue({ pos.x - 1 + 0.55 * row, pos.y, pos.z - 1.4 - 0.55 * column })
|
2020-11-28 13:23:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
function spawnClue(position)
|
|
|
|
local token = spawnObject({
|
|
|
|
position = position,
|
|
|
|
rotation = { 3.88, -90, 0.24 },
|
|
|
|
type = 'Custom_Tile'
|
|
|
|
})
|
|
|
|
|
|
|
|
token.setCustomObject(clueData)
|
|
|
|
token.scale { 0.25, 1, 0.25 }
|
|
|
|
token.use_snap_points = false
|
|
|
|
end
|
2020-11-28 13:23:58 -05:00
|
|
|
|
|
|
|
function updateLocations(args)
|
2022-12-13 14:02:30 -05:00
|
|
|
custom_data_helper_guid = args[1]
|
|
|
|
local custom_data_helper = getObjectFromGUID(args[1])
|
|
|
|
|
|
|
|
for k, v in pairs(custom_data_helper.getTable("LOCATIONS_DATA")) do
|
|
|
|
LOCATIONS[k] = v
|
|
|
|
end
|
2020-11-28 13:23:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function onCollisionEnter(collision_info)
|
2022-12-13 14:02:30 -05:00
|
|
|
if not COLLISION_ENABLED then return end
|
2020-11-28 13:23:58 -05:00
|
|
|
|
2022-12-13 14:02:30 -05:00
|
|
|
-- check if we should spawn clues here and do so according to playercount
|
2020-11-28 13:23:58 -05:00
|
|
|
local object = collision_info.collision_object
|
2022-12-13 14:02:30 -05:00
|
|
|
if getLocation(object) ~= nil and spawnedLocationGUIDs[object.getGUID()] == nil then
|
|
|
|
local clueCount = getClueCount(object, object.is_face_down, getInvestigatorCount())
|
|
|
|
if clueCount > 0 then spawnCluesAtLocation(clueCount, object) end
|
2020-11-28 13:23:58 -05:00
|
|
|
end
|
2022-12-13 14:02:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function getInvestigatorCount()
|
|
|
|
local investigatorCounter = getObjectFromGUID('f182ee')
|
|
|
|
return investigatorCounter.getVar("val")
|
|
|
|
end
|
|
|
|
end)
|
2022-12-13 18:01:00 -05:00
|
|
|
return __bundle_require("__root")
|