ah_sce_unpacked/unpacked.ttslua

2310 lines
78 KiB
Plaintext
Raw Normal View History

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}
2020-12-06 09:42:32 -05:00
2022-12-13 14:02:30 -05:00
local register
local modules = {}
2020-12-06 09:42:32 -05:00
2022-12-13 14:02:30 -05:00
local require
local loaded = {}
2020-12-06 09:42:32 -05:00
2022-12-13 14:02:30 -05:00
register = function(name, body)
if not modules[name] then
modules[name] = body
end
end
2020-12-06 09:42:32 -05:00
2022-12-13 14:02:30 -05:00
require = function(name)
local loadedModule = loaded[name]
2021-03-23 10:59:55 -04:00
2022-12-13 14:02:30 -05:00
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)
2024-01-06 21:32:07 -05:00
__bundle_register("core/SoundCubeApi", function(require, _LOADED, __bundle_register, __bundle_modules)
2023-01-29 19:31:52 -05:00
do
2024-01-06 21:32:07 -05:00
local SoundCubeApi = {}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- this table links the name of a trigger effect to its index
local soundIndices = {
["Vacuum"] = 0,
["Deep Bell"] = 1,
["Dark Souls"] = 2
}
local function playTriggerEffect(index)
getObjectsWithTag("SoundCube")[1].AssetBundle.playTriggerEffect(index)
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- plays the by name requested sound
---@param soundName String Name of the sound to play
SoundCubeApi.playSoundByName = function(soundName)
playTriggerEffect(soundIndices[soundName])
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
return SoundCubeApi
2023-04-22 16:56:01 -04:00
end
end)
2024-01-06 21:32:07 -05:00
__bundle_register("core/token/TokenChecker", function(require, _LOADED, __bundle_register, __bundle_modules)
2023-04-22 16:56:01 -04:00
do
2024-01-06 21:32:07 -05:00
local CHAOS_TOKEN_NAMES = {
["Elder Sign"] = true,
["+1"] = true,
["0"] = true,
["-1"] = true,
["-2"] = true,
["-3"] = true,
["-4"] = true,
["-5"] = true,
["-6"] = true,
["-7"] = true,
["-8"] = true,
["Skull"] = true,
["Cultist"] = true,
["Tablet"] = true,
["Elder Thing"] = true,
["Auto-fail"] = true,
["Bless"] = true,
["Curse"] = true,
["Frost"] = true
}
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
local TokenChecker = {}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- returns true if the passed object is a chaos token (by name)
TokenChecker.isChaosToken = function(obj)
if CHAOS_TOKEN_NAMES[obj.getName()] then
return true
else
return false
end
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
return TokenChecker
end
end)
__bundle_register("playermat/PlaymatApi", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local PlaymatApi = { }
local internal = { }
local MAT_IDS = {
White = "8b081b",
Orange = "bd0ff4",
Green = "383d8b",
Red = "0840d5"
}
local CLUE_COUNTER_GUIDS = {
White = "37be78",
Orange = "1769ed",
Green = "032300",
Red = "d86b7c"
}
local CLUE_CLICKER_GUIDS = {
White = "db85d6",
Orange = "3f22e5",
Green = "891403",
Red = "4111de"
}
-- Returns the color of the by position requested playermat as string
---@param startPos Table Position of the search, table get's roughly cut into 4 quarters to assign a playermat
PlaymatApi.getMatColorByPosition = function(startPos)
if startPos.x < -42 then
if startPos.z > 0 then
return "White"
else
return "Orange"
end
else
if startPos.z > 0 then
return "Green"
else
return "Red"
end
end
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns the color of the player's hand that is seated next to the playermat
---@param matColor String Color of the playermat
PlaymatApi.getPlayerColor = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.getVar("playerColor")
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns the color of the playermat that owns the playercolor's hand
---@param handColor String Color of the playermat
PlaymatApi.getMatColor = function(handColor)
local matColors = {"White", "Orange", "Green", "Red"}
for i, mat in ipairs(internal.getMatForColor("All")) do
local color = mat.getVar("playerColor")
if color == handColor then return matColors[i] end
end
return "NOT_FOUND"
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns the result of a cast in the specificed playermat's area
---@param matColor String Color of the playermat
PlaymatApi.searchPlaymat = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.call("searchAroundSelf")
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns if there is the card "Dream-Enhancing Serum" on the requested playermat
---@param matColor String Color of the playermat
PlaymatApi.isDES = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.getVar("isDES")
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns the draw deck of the requested playmat
---@param matColor String Color of the playermat
PlaymatApi.getDrawDeck = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
mat.call("getDrawDiscardDecks")
return mat.getVar("drawDeck")
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns the position of the discard pile of the requested playmat
---@param matColor String Color of the playermat
PlaymatApi.getDiscardPosition = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.call("returnGlobalDiscardPosition")
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Transforms a local position into a global position
---@param localPos Table Local position to be transformed
---@param matColor String Color of the playermat
PlaymatApi.transformLocalPosition = function(localPos, matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.positionToWorld(localPos)
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns the rotation of the requested playmat
---@param matColor String Color of the playermat
PlaymatApi.returnRotation = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.getRotation()
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Triggers the Upkeep for the requested playmat
---@param matColor String Color of the playermat
---@param playerColor String Color of the calling player (for messages)
PlaymatApi.doUpkeepFromHotkey = function(matColor, playerColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.call("doUpkeepFromHotkey", playerColor)
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Returns the active investigator id
---@param matColor String Color of the playermat
PlaymatApi.returnInvestigatorId = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.getVar("activeInvestigatorId")
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Sets the requested playermat's snap points to limit snapping to matching card types or not. If
-- matchTypes is true, the main card slot snap points will only snap assets, while the
-- investigator area point will only snap Investigators. If matchTypes is false, snap points will
-- be reset to snap all cards.
---@param matchCardTypes Boolean. Whether snap points should only snap for the matching card
-- types.
---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also
-- accepts "All" as a special value which will apply the setting to all four mats.
PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("setLimitSnapsByType", matchCardTypes)
end
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Sets the requested playermat's draw 1 button to visible
---@param isDrawButtonVisible Boolean. Whether the draw 1 button should be visible or not
---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also
-- accepts "All" as a special value which will apply the setting to all four mats.
PlaymatApi.showDrawButton = function(isDrawButtonVisible, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("showDrawButton", isDrawButtonVisible)
end
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Shows or hides the clickable clue counter for the requested playermat
---@param showCounter Boolean. Whether the clickable counter should be present or not
---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also
-- accepts "All" as a special value which will apply the setting to all four mats.
PlaymatApi.clickableClues = function(showCounter, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("clickableClues", showCounter)
end
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
-- Removes all clues (to the trash for tokens and counters set to 0) for the requested playermat
---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also
-- accepts "All" as a special value which will apply the setting to all four mats.
PlaymatApi.removeClues = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("removeClues")
end
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
-- Reports the clue count for the requested playermat
---@param useClickableCounters Boolean Controls which type of counter is getting checked
PlaymatApi.getClueCount = function(useClickableCounters, matColor)
local count = 0
for _, mat in ipairs(internal.getMatForColor(matColor)) do
count = count + tonumber(mat.call("getClueCount", useClickableCounters))
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
return count
2023-04-22 16:56:01 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Adds the specified amount of resources to the requested playermat's resource counter
PlaymatApi.gainResources = function(amount, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("gainResources", amount)
2023-08-27 21:09:46 -04:00
end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- Returns the resource counter amount for the requested playermat
PlaymatApi.getResourceCount = function(matColor)
local mat = getObjectFromGUID(MAT_IDS[matColor])
return mat.call("getResourceCount")
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- Discard a non-hidden card from the corresponding player's hand
PlaymatApi.doDiscardOne = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("doDiscardOne")
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
PlaymatApi.syncAllCustomizableCards = function()
for _, mat in ipairs(internal.getMatForColor("All")) do
mat.call("syncAllCustomizableCards")
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
PlaymatApi.updateClueClicker = function(playerColor, val)
return getObjectFromGUID(CLUE_CLICKER_GUIDS[playerColor]).call("updateVal", val)
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- Convenience function to look up a mat's object by color, or get all mats.
---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also
-- accepts "All" as a special value which will return all four mats.
---@return: Array of playermat objects. If a single mat is requested, will return a single-element
-- array to simplify processing by consumers.
internal.getMatForColor = function(matColor)
local targetMatGuid = MAT_IDS[matColor]
if targetMatGuid != nil then
return { getObjectFromGUID(targetMatGuid) }
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
if matColor == "All" then
return {
getObjectFromGUID(MAT_IDS.White),
getObjectFromGUID(MAT_IDS.Orange),
getObjectFromGUID(MAT_IDS.Green),
getObjectFromGUID(MAT_IDS.Red),
}
2023-08-27 21:09:46 -04:00
end
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
return PlaymatApi
end
end)
__bundle_register("__root", function(require, _LOADED, __bundle_register, __bundle_modules)
require("core/Global")
end)
__bundle_register("core/Global", function(require, _LOADED, __bundle_register, __bundle_modules)
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local mythosAreaApi = require("core/MythosAreaApi")
local navigationOverlayApi = require("core/NavigationOverlayApi")
local playAreaApi = require("core/PlayAreaApi")
local playmatApi = require("playermat/PlaymatApi")
local soundCubeApi = require("core/SoundCubeApi")
local tokenArrangerApi = require("accessories/TokenArrangerApi")
local tokenChecker = require("core/token/TokenChecker")
local tokenManager = require("core/token/TokenManager")
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- general setup
---------------------------------------------------------
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
ENCOUNTER_DECK_POS = {-3.93, 1, 5.76}
ENCOUNTER_DECK_DISCARD_POSITION = {-3.85, 1, 10.38}
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- GUID of data helper
DATA_HELPER_GUID = "708279"
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- GUIDs that will not be interactable (e.g. parts of the table)
local NOT_INTERACTABLE = {
"6161b4", -- Decoration-Map
"721ba2", -- PlayArea
"9f334f", -- MythosArea
"463022", -- Panel behind tentacle stand
"f182ee", -- InvestigatorCount
"7bff34", -- Tentacle stand
"8646eb", -- horizontal border left
"75937e", -- horizontal border right
"612072", -- vertical border left
"975c39", -- vertical border right
}
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- global variable for access
chaosTokens = {}
local chaosTokensLastMat = nil
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
local bagSearchers = {}
local MAT_COLORS = {"White", "Orange", "Green", "Red"}
local hideTitleSplashWaitFunctionId = nil
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- online functionality related variables
local MOD_VERSION = "3.3.0"
local SOURCE_REPO = 'https://raw.githubusercontent.com/chr1z93/loadable-objects/main'
local library, requestObj, modMeta, notificationVisible
local acknowledgedUpgradeVersions = {}
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- optionPanel data
optionPanel = {}
local LANGUAGES = {
{ code = "zh_CN", name = "简体中文" },
{ code = "zh_TW", name = "繁體中文" },
{ code = "de", name = "Deutsch" },
{ code = "en", name = "English" },
{ code = "es", name = "Español" },
{ code = "fr", name = "Français" },
{ code = "it", name = "Italiano" }
}
local RESOURCE_OPTIONS = {
"enabled",
"custom",
"disabled"
}
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- data for tokens
---------------------------------------------------------
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
TOKEN_DATA = {
damage = {image = "http://cloud-3.steamusercontent.com/ugc/1758068501357115146/903D11AAE7BD5C254C8DC136E9202EE516289DEA/", scale = {0.17, 0.17, 0.17}},
horror = {image = "http://cloud-3.steamusercontent.com/ugc/1758068501357163535/6D9E0756503664D65BDB384656AC6D4BD713F5FC/", scale = {0.17, 0.17, 0.17}},
resource = {image = "http://cloud-3.steamusercontent.com/ugc/1758068501357192910/11DDDC7EF621320962FDCF3AE3211D5EDC3D1573/", scale = {0.17, 0.17, 0.17}},
doom = {image = "https://i.imgur.com/EoL7yaZ.png", scale = {0.17, 0.17, 0.17}},
clue = {image = "http://cloud-3.steamusercontent.com/ugc/1758068501357164917/1D06F1DC4D6888B6F57124BD2AFE20D0B0DA15A8/", scale = {0.15, 0.15, 0.15}}
}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
ID_URL_MAP = {
['blue'] = {name = "Elder Sign", url = 'https://i.imgur.com/nEmqjmj.png'},
['p1'] = {name = "+1", url = 'https://i.imgur.com/uIx8jbY.png'},
['0'] = {name = "0", url = 'https://i.imgur.com/btEtVfd.png'},
['m1'] = {name = "-1", url = 'https://i.imgur.com/w3XbrCC.png'},
['m2'] = {name = "-2", url = 'https://i.imgur.com/bfTg2hb.png'},
['m3'] = {name = "-3", url = 'https://i.imgur.com/yfs8gHq.png'},
['m4'] = {name = "-4", url = 'https://i.imgur.com/qrgGQRD.png'},
['m5'] = {name = "-5", url = 'https://i.imgur.com/3Ym1IeG.png'},
['m6'] = {name = "-6", url = 'https://i.imgur.com/c9qdSzS.png'},
['m7'] = {name = "-7", url = 'https://i.imgur.com/4WRD42n.png'},
['m8'] = {name = "-8", url = 'https://i.imgur.com/9t3rPTQ.png'},
['skull'] = {name = "Skull", url = 'https://i.imgur.com/stbBxtx.png'},
['cultist'] = {name = "Cultist", url = 'https://i.imgur.com/VzhJJaH.png'},
['tablet'] = {name = "Tablet", url = 'https://i.imgur.com/1plY463.png'},
['elder'] = {name = "Elder Thing", url = 'https://i.imgur.com/ttnspKt.png'},
['red'] = {name = "Auto-fail", url = 'https://i.imgur.com/lns4fhz.png'},
['bless'] = {name = "Bless", url = 'http://cloud-3.steamusercontent.com/ugc/1655601092778627699/339FB716CB25CA6025C338F13AFDFD9AC6FA8356/'},
['curse'] = {name = "Curse", url = 'http://cloud-3.steamusercontent.com/ugc/1655601092778636039/2A25BD38E8C44701D80DD96BF0121DA21843672E/'},
['frost'] = {name = "Frost", url = 'http://cloud-3.steamusercontent.com/ugc/1858293462583104677/195F93C063A8881B805CE2FD4767A9718B27B6AE/'}
}
---------------------------------------------------------
-- data for chaos token stat tracker
---------------------------------------------------------
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
local MAT_GUID_TO_COLOR = {
["Overall"] = "Overall",
["8b081b"] = "White",
["bd0ff4"] = "Orange",
["383d8b"] = "Green",
["0840d5"] = "Red"
}
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
local tokenDrawingStats = {
["Overall"] = {},
["8b081b"] = {},
["bd0ff4"] = {},
["383d8b"] = {},
["0840d5"] = {}
}
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- general code
---------------------------------------------------------
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- saving state of optionPanel to restore later
function onSave() return JSON.encode({ optionPanel = optionPanel, acknowledgedUpgradeVersions = acknowledgedUpgradeVersions }) end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function onLoad(savedData)
if savedData then
loadedData = JSON.decode(savedData)
optionPanel = loadedData.optionPanel
acknowledgedUpgradeVersions = loadedData.acknowledgedUpgradeVersions
updateOptionPanelState()
else
print("Saved state could not be found!")
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
for _, guid in ipairs(NOT_INTERACTABLE) do
local obj = getObjectFromGUID(guid)
if obj ~= nil then obj.interactable = false end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
resetChaosTokenStatTracker()
getModVersion()
math.randomseed(os.time())
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- Event hook for any object search. When chaos tokens are manipulated while the chaos bag
-- container is being searched, a TTS bug can cause tokens to duplicate or vanish. We lock the
-- chaos bag during search operations to avoid this.
function onObjectSearchStart(object, playerColor)
chaosbag = findChaosBag()
if object == chaosbag then
bagSearchers[playerColor] = true
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Event hook for any object search. When chaos tokens are manipulated while the chaos bag
-- container is being searched, a TTS bug can cause tokens to duplicate or vanish. We lock the
-- chaos bag during search operations to avoid this.
function onObjectSearchEnd(object, playerColor)
chaosbag = findChaosBag()
if object == chaosbag then
bagSearchers[playerColor] = nil
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Pass object enter container events to the PlayArea to clear vector lines from dragged cards.
-- This requires the try method as cards won't exist any more after they enter a deck, so the lines
-- can't be cleared.
function tryObjectEnterContainer(container, object)
playAreaApi.tryObjectEnterContainer(container, object)
return true
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- chaos token drawing
---------------------------------------------------------
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- checks scripting zone for chaos bag (also called by a lot of objects!)
function findChaosBag()
local chaosbag_zone = getObjectFromGUID("83ef06")
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- error handling: scripting zone not found
if chaosbag_zone == nil then
printToAll("Zone for chaos bag detection couldn't be found.", "Red")
return
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
for _, item in ipairs(chaosbag_zone.getObjects()) do
if item.getDescription() == "Chaos Bag" then
return item
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- error handling: chaos bag not found
printToAll("Chaos bag couldn't be found.", "Red")
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function returnChaosTokens()
for _, token in pairs(chaosTokens) do
if token ~= nil then chaosbag.putObject(token) end
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
chaosTokens = {}
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- Checks to see if the chaos bag can be manipulated. If a player is searching the bag when tokens
-- are drawn or replaced a TTS bug can cause those tokens to vanish. Any functions which change the
-- contents of the bag should check this method before doing so.
-- This method will broadcast a message to all players if the bag is being searched.
---@return Boolean. True if the bag is manipulated, false if it should be blocked.
function canTouchChaosTokens()
for color, searching in pairs(bagSearchers) do
if searching then
broadcastToAll("Someone is searching the chaos bag, can't touch the tokens.", "Red")
return false
end
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
return true
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- called by playermats (by the "Draw chaos token" button)
function drawChaosToken(params)
if not canTouchChaosTokens() then return end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
local mat = params[1]
local tokenOffset = params[2]
local isRightClick = params[3]
chaosbag = findChaosBag()
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- return token(s) on other playmat first
if chaosTokensLastMat ~= nil and chaosTokensLastMat ~= mat and #chaosTokens ~= 0 then
returnChaosTokens()
chaosTokensLastMat = nil
return
2023-08-27 21:09:46 -04:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
chaosTokensLastMat = mat
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- if we have left clicked and have no tokens OR if we have right clicked
if isRightClick or #chaosTokens == 0 then
if #chaosbag.getObjects() == 0 then return end
chaosbag.shuffle()
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- add the token to the list, compute new position based on list length
tokenOffset[1] = tokenOffset[1] + (0.17 * #chaosTokens)
local token = chaosbag.takeObject({
index = 0,
position = mat.positionToWorld(tokenOffset),
rotation = mat.getRotation()
})
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- get data for token description
local name = token.getName()
local tokenData = mythosAreaApi.returnTokenData().tokenData or {}
local specificData = tokenData[name] or {}
token.setDescription(specificData.description or "")
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- track the chaos token (for stat tracker and future returning)
trackChaosToken(name, mat.getGUID())
chaosTokens[#chaosTokens + 1] = token
return
else
returnChaosTokens()
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- token spawning
---------------------------------------------------------
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- DEPRECATED. Use TokenManager instead.
-- Spawns a single token.
---@param params Table. Array with arguments to the method. 1 = position, 2 = type, 3 = rotation
function spawnToken(params)
return tokenManager.spawnToken(params[1], params[2], params[3])
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- chaos token stat tracker
---------------------------------------------------------
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function trackChaosToken(tokenName, matGUID)
tokenDrawingStats["Overall"][tokenName] = (tokenDrawingStats["Overall"][tokenName] or 0) + 1
tokenDrawingStats[matGUID][tokenName] = (tokenDrawingStats[matGUID][tokenName] or 0) + 1
2023-08-27 21:09:46 -04:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- Left-click: print stats, Right-click: reset stats
function handleStatTrackerClick(_, _, isRightClick)
if isRightClick then
resetChaosTokenStatTracker()
else
local squidKing = "Nobody"
local maxSquid = 0
local foundAnyStats = false
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
for key, personalStats in pairs(tokenDrawingStats) do
local playerColor, playerName
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
if key == "Overall" then
playerColor = "White"
playerName = "Overall"
else
playerColor = playmatApi.getPlayerColor(MAT_GUID_TO_COLOR[key])
playerName = Player[playerColor].steam_name or playerColor
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
local playerSquidCount = personalStats["Auto-fail"]
if playerSquidCount > maxSquid then
squidKing = playerName
maxSquid = playerSquidCount
end
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- get the total count of drawn tokens for the player
local totalCount = 0
for tokenName, value in pairs(personalStats) do
totalCount = totalCount + value
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- only print the personal stats if any tokens were drawn
if totalCount > 0 then
foundAnyStats = true
printToAll("------------------------------")
printToAll(playerName .. " Stats", playerColor)
for tokenName, value in pairs(personalStats) do
if value ~= 0 then
printToAll(tokenName .. ': ' .. tostring(value))
end
end
printToAll('Total: ' .. tostring(totalCount))
end
end
-- detect if any player drew tokens
if foundAnyStats then
printToAll("------------------------------")
printToAll(squidKing .. " is an auto-fail magnet.", {255, 0, 0})
else
printToAll("No tokens have been drawn yet.", "Yellow")
end
2023-04-22 16:56:01 -04:00
end
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- resets the count for each token to 0
function resetChaosTokenStatTracker()
for key, _ in pairs(tokenDrawingStats) do
tokenDrawingStats[key] = {}
for _, token in pairs(ID_URL_MAP) do
tokenDrawingStats[key][token.name] = 0
end
2023-01-29 19:31:52 -05:00
end
2023-08-27 21:09:46 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- Difficulty selector script
---------------------------------------------------------
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- called for button creation on the difficulty selectors
---@param object object Usually "self"
---@param key string Name of the scenario
function createSetupButtons(args)
local data = getDataValue('modeData', args.key)
if data ~= nil then
local buttonParameters = {}
buttonParameters.function_owner = args.object
buttonParameters.position = {0, 0.1, -0.15}
buttonParameters.scale = {0.47, 1, 0.47}
buttonParameters.height = 200
buttonParameters.width = 1150
buttonParameters.color = {0.87, 0.8, 0.7}
if data.easy ~= nil then
buttonParameters.label = "Easy"
buttonParameters.click_function = "easyClick"
args.object.createButton(buttonParameters)
buttonParameters.position[3] = buttonParameters.position[3] + 0.20
end
if data.normal ~= nil then
buttonParameters.label = "Standard"
buttonParameters.click_function = "normalClick"
args.object.createButton(buttonParameters)
buttonParameters.position[3] = buttonParameters.position[3] + 0.20
end
if data.hard ~= nil then
buttonParameters.label = "Hard"
buttonParameters.click_function = "hardClick"
args.object.createButton(buttonParameters)
buttonParameters.position[3] = buttonParameters.position[3] + 0.20
end
if data.expert ~= nil then
buttonParameters.label = "Expert"
buttonParameters.click_function = "expertClick"
args.object.createButton(buttonParameters)
buttonParameters.position[3] = buttonParameters.position[3] + 0.20
end
if data.standalone ~= nil then
buttonParameters.label = "Standalone"
buttonParameters.click_function = "standaloneClick"
args.object.createButton(buttonParameters)
2023-08-27 21:09:46 -04:00
end
2023-01-29 19:31:52 -05:00
end
end
2024-01-06 21:32:07 -05:00
-- called for adding chaos tokens
---@param object object Usually "self"
---@param key string Name of the scenario
---@param mode string difficulty (e.g. "hard" or "expert")
function fillContainer(args)
local data = getDataValue('modeData', args.key)
if data == nil then return end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
local value = data[args.mode]
if value == nil or value.token == nil then return end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
local tokenList = {}
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
for _, tokenId in ipairs(value.token) do
table.insert(tokenList, tokenId)
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
if value.append ~= nil then
for _, tokenId in ipairs(value.append) do
table.insert(tokenList, tokenId)
end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- randomly choose tokens for specific Carcosa scenarios in standalone
if value.random then
local n = #value.random
if n > 0 then
for _, tokenId in ipairs(value.random[math.random(1, n)]) do
table.insert(tokenList, tokenId)
end
2023-01-29 19:31:52 -05:00
end
2023-08-27 21:09:46 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
setChaosBagState(tokenList)
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
if value.message then
broadcastToAll(value.message)
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
if value.warning then
broadcastToAll(value.warning, { 1, 0.5, 0.5 })
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function getDataValue(storage, key)
local data = getObjectFromGUID(DATA_HELPER_GUID).getTable(storage)
if data ~= nil then
local value = data[key]
if value ~= nil then
local res = {}
for m, v in pairs(value) do
res[m] = v
if res[m].parent ~= nil then
local parentData = getDataValue(storage, res[m].parent)
if parentData ~= nil and parentData[m] ~= nil and parentData[m].token ~= nil then
res[m].token = parentData[m].token
end
res[m].parent = nil
end
end
return res
end
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function createChaosTokenNameLookupTable()
local namesToIds = {}
for k, v in pairs(ID_URL_MAP) do
namesToIds[v.name] = k
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
return namesToIds
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- returns a Table List of chaos token ids in the current chaos bag
---@api chaosbag/ChaosBagApi
function getChaosBagState()
local tokens = {}
local invertedTable = createChaosTokenNameLookupTable()
local chaosbag = findChaosBag()
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
for _, v in ipairs(chaosbag.getObjects()) do
local id = invertedTable[v.name]
if id then
table.insert(tokens, id)
else
printToAll(v.name .. " token not recognized. Will not be recorded.", "Yellow")
end
2023-08-27 21:09:46 -04:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
return tokens
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
end
-- respawns the chaos bag with a new state of tokens
---@param tokenList Table List of chaos token ids
---@api chaosbag/ChaosBagApi
function setChaosBagState(tokenList)
if not canTouchChaosTokens() then return end
local chaosbag = findChaosBag()
local chaosbagData = chaosbag.getData()
local reserveData = getObjectFromGUID("106418").getData()
local tokenCache = {}
local containedObjects = {}
-- create a temporary copy of the data for each chaos token
for _, objData in ipairs(reserveData.ContainedObjects) do
tokenCache[objData.Nickname] = objData
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- iterate over tokenlist and insert specified tokens into new table
for _, tokenId in ipairs(tokenList) do
local tokenName = ID_URL_MAP[tokenId].name
table.insert(containedObjects, tokenCache[tokenName])
2023-04-22 16:56:01 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- overwrite chaos bag content and respawn it
chaosbagData.ContainedObjects = containedObjects
chaosbag.destruct()
spawnObjectData({data = chaosbagData})
-- remove tokens that are still in play
for _, token in pairs(chaosTokens) do
if token ~= nil then token.destruct() end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
chaosTokens = {}
chaosTokensLastMat = nil
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- reset bless / curse manager
blessCurseManagerApi.removeTakenTokensAndReset()
printToAll("Chaos bag set to chosen difficulty.", "Green")
end
-- spawns the specified chaos token and puts it into the chaos bag
---@param id String ID of the chaos token
function spawnChaosToken(id)
if not canTouchChaosTokens() then return end
id = id:lower()
local chaosbag = findChaosBag()
local url = ID_URL_MAP[id].url or ""
if url ~= "" then
return spawnObject({
type = 'Custom_Tile',
position = { 0.49, 3, 0 },
scale = { 0.81, 1.0, 0.81 },
rotation = {0, 270, 0},
callback_function = function(obj)
obj.setName(ID_URL_MAP[id].name)
chaosbag.putObject(obj)
tokenArrangerApi.layout()
end
}).setCustomObject({
type = 2,
image = url,
thickness = 0.1
})
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- removes the specified chaos token from the chaos bag
---@param id String ID of the chaos token
function removeChaosToken(id)
if not canTouchChaosTokens() then return end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
local tokens = {}
local chaosbag = findChaosBag()
local name = ID_URL_MAP[id].name
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == name then table.insert(tokens, v.guid) end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- error handling: no matching token found
if #tokens == 0 then
printToAll("No " .. name .. " tokens in the chaos bag.", "Yellow")
return
2023-04-22 16:56:01 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
chaosbag.takeObject({
guid = tokens[1],
smooth = false,
callback_function = function(obj)
obj.destruct()
tokenArrangerApi.layout()
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
})
printToAll("Removing " .. name .. " token (in bag: " .. #tokens - 1 .. ")", "White")
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- empty the chaos bag
function emptyChaosBag()
if not canTouchChaosTokens() then return end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
local chaosbag = findChaosBag()
for _, object in ipairs(chaosbag.getObjects()) do
chaosbag.takeObject({callback_function = function(item) item.destruct() end})
end
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- returns all sealed tokens on cards to the chaos bag
function releaseAllSealedTokens(playerColor)
local chaosbag = findChaosBag()
for _, obj in ipairs(getObjectsWithTag("CardThatSeals")) do
obj.call("releaseAllTokens", playerColor)
end
end
2020-12-06 09:42:32 -05:00
2023-08-27 21:09:46 -04:00
---------------------------------------------------------
2024-01-06 21:32:07 -05:00
-- Content Importing and XML functions
2023-08-27 21:09:46 -04:00
---------------------------------------------------------
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
function onClick_refreshList()
local request = WebRequest.get(SOURCE_REPO .. '/library.json', completed_list_update)
requestObj = request
startLuaCoroutine(Global, 'downloadCoroutine')
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function onClick_select(player, params)
params = JSON.decode(urldecode(params))
local url = SOURCE_REPO .. '/' .. params.url
local request = WebRequest.get(url, function (request) complete_obj_download(request, params) end )
requestObj = request
startLuaCoroutine(Global, 'downloadCoroutine')
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function onClick_load()
UI.show('progress_display')
UI.hide('load_button')
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
function onClick_toggleUi(player, title)
if title == "Navigation Overlay" then
navigationOverlayApi.cycleVisibility(player.color)
return
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
UI.hide('optionPanel')
UI.hide('load_ui')
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- when same button is clicked or close window button is pressed, don't open UI
if UI.getValue('title') ~= title and title ~= 'Hidden' then
UI.setValue('title', title)
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
if title == "Options" then
UI.show('optionPanel')
else
update_window_content(title)
UI.show('load_ui')
end
2023-08-27 21:09:46 -04:00
else
2024-01-06 21:32:07 -05:00
UI.setValue('title', "Hidden")
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
function downloadCoroutine()
while requestObj do
UI.setAttribute('download_progress', 'percentage', requestObj.download_progress * 100)
coroutine.yield(0)
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
return 1
end
function update_list(objects)
local ui = UI.getXmlTable()
local update_height = find_tag_with_id(ui, 'ui_update_height')
local update_children = find_tag_with_id(update_height.children, 'ui_update_point')
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
update_children.children = {}
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
for _, v in ipairs(objects) do
local s = JSON.encode(v);
table.insert(update_children.children,
{ tag = 'Text',
value = v.name,
attributes = { onClick = 'onClick_select(' .. urlencode(JSON.encode(v)) .. ')', alignment = 'MiddleLeft' }
})
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
update_height.attributes.height = #(update_children.children) * 24
UI.setXmlTable(ui)
end
2021-02-13 12:12:29 -05:00
2024-01-06 21:32:07 -05:00
function update_window_content(new_title)
if not library then return end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
if new_title == 'Campaigns' then
update_list(library.campaigns)
elseif new_title == 'Standalone Scenarios' then
update_list(library.scenarios)
elseif new_title == 'Investigators' then
update_list(library.investigators)
elseif new_title == 'Community Content' then
update_list(library.community)
elseif new_title == 'Extras' then
update_list(library.extras)
else
update_list({})
2020-12-06 09:42:32 -05:00
end
2023-08-27 21:09:46 -04:00
end
2022-12-13 14:02:30 -05:00
2024-01-06 21:32:07 -05:00
function complete_obj_download(request, params)
assert(request.is_done)
if request.is_error or request.response_code ~= 200 then
print('error: ' .. request.error)
else
if pcall(function()
local replaced_object
pcall(function()
if params.replace then
replaced_object = getObjectFromGUID(params.replace)
end
end)
local json = request.text
if replaced_object then
local pos = replaced_object.getPosition()
local rot = replaced_object.getRotation()
destroyObject(replaced_object)
Wait.frames(function()
spawnObjectJSON({json = json, position = pos, rotation = rot})
end, 1)
else
spawnObjectJSON({json = json})
end
end) then
print('Object loaded.')
else
print('Error loading object.')
end
2020-12-06 09:42:32 -05:00
end
2024-01-06 21:32:07 -05:00
requestObj = nil
UI.setAttribute('download_progress', 'percentage', 100)
2022-12-13 14:02:30 -05:00
end
2024-01-06 21:32:07 -05:00
-- the download button on the placeholder objects calls this to directly initiate a download
-- params is a table with url and guid of replacement object, which happens to match what onClick_select wants
function placeholder_download(params)
onClick_select(nil, JSON.encode(params))
2023-08-27 21:09:46 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
function completed_list_update(request)
assert(request.is_done)
if request.is_error or request.response_code ~= 200 then
print('error: ' .. request.error)
2023-08-27 21:09:46 -04:00
else
2024-01-06 21:32:07 -05:00
local json_response = nil
if pcall(function () json_response = JSON.decode(request.text) end) then
library = json_response
update_window_content(UI.getValue('title'))
else
print('error parsing downloaded library')
end
2023-08-27 21:09:46 -04:00
end
2022-12-13 14:02:30 -05:00
2024-01-06 21:32:07 -05:00
requestObj = nil
UI.setAttribute('download_progress', 'percentage', 100)
end
2022-12-13 14:02:30 -05:00
2024-01-06 21:32:07 -05:00
function find_tag_with_id(ui, id)
for _, obj in ipairs(ui) do
if obj.attributes and obj.attributes.id and obj.attributes.id == id then return obj end
if obj.children then
local result = find_tag_with_id(obj.children, id)
if result then return result end
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
end
2024-01-06 21:32:07 -05:00
return nil
end
function urlencode(str)
local str = string.gsub(str, "([^A-Za-z0-9-_.~])",
function (c) return string.format("%%%02X", string.byte(c)) end)
return str
end
function urldecode(str)
local str = string.gsub(str, "%%(%x%x)",
function (h) return string.char(tonumber(h, 16)) end)
return str
2020-12-06 09:42:32 -05:00
end
2022-12-13 14:02:30 -05:00
---------------------------------------------------------
2024-01-06 21:32:07 -05:00
-- Option Panel related functionality
2022-12-13 14:02:30 -05:00
---------------------------------------------------------
2024-01-06 21:32:07 -05:00
-- called by toggling an option
function onClick_toggleOption(_, id)
local state = self.UI.getAttribute(id, "isOn")
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- flip state (and handle stupid "False" value)
if state == "False" then
state = true
else
state = false
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
self.UI.setAttribute(id, "isOn", state)
applyOptionPanelChange(id, state)
end
-- called by the language selection dropdown
function languageSelected(_, selectedIndex, id)
optionPanel[id] = LANGUAGES[tonumber(selectedIndex) + 1].code
end
-- returns the ID (position in the table) for a provided language code
function returnLanguageId(code)
for index, tbl in ipairs(LANGUAGES) do
if tbl.code == code then
return index
2023-08-27 21:09:46 -04:00
end
end
2024-01-06 21:32:07 -05:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- called by the resource counter selection dropdown
function resourceCounterSelected(_, selectedIndex, id)
optionPanel[id] = RESOURCE_OPTIONS[tonumber(selectedIndex) + 1]
2023-08-27 21:09:46 -04:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- returns the ID for the provided option name
function returnResourceCounterId(name)
for index, optionName in ipairs(RESOURCE_OPTIONS) do
if optionName == name then
return index
end
2023-08-27 21:09:46 -04:00
end
2020-12-06 09:42:32 -05:00
end
2024-01-06 21:32:07 -05:00
-- sets the option panel to the correct state (corresponding to 'optionPanel')
function updateOptionPanelState()
for id, optionValue in pairs(optionPanel) do
if id == "cardLanguage" and type(optionValue) == "string" then
local dropdownId = returnLanguageId(optionValue) - 1
UI.setAttribute(id, "value", dropdownId)
elseif id == "useResourceCounters" and type(optionValue) == "string" then
local dropdownId = returnResourceCounterId(optionValue) - 1
UI.setAttribute(id, "value", dropdownId)
elseif (type(optionValue) == "boolean" and optionValue)
or (type(optionValue) == "string" and optionValue)
or (type(optionValue) == "table" and #optionValue ~= 0) then
UI.setAttribute(id, "isOn", true)
else
UI.setAttribute(id, "isOn", "False")
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
end
end
2024-01-06 21:32:07 -05:00
-- handles the applying of option selections and calls the respective functions based
---@param id String ID of the option that was selected or deselected
---@param state Boolean State of the option (true = enabled)
function applyOptionPanelChange(id, state)
-- option: Snap tags
if id == "useSnapTags" then
playmatApi.setLimitSnapsByType(state, "All")
optionPanel[id] = state
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Draw 1 button
elseif id == "showDrawButton" then
playmatApi.showDrawButton(state, "All")
optionPanel[id] = state
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Clickable clue counters
elseif id == "useClueClickers" then
playmatApi.clickableClues(state, "All")
optionPanel[id] = state
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- update master clue counter
getObjectFromGUID("4a3aa4").setVar("useClickableCounters", state)
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Play area snap tags
elseif id == "playAreaSnapTags" then
playAreaApi.setLimitSnapsByType(state)
optionPanel[id] = state
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Show Title on placing scenarios
elseif id == "showTitleSplash" then
optionPanel[id] = state
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Show clean up helper
elseif id == "showCleanUpHelper" then
optionPanel[id] = spawnOrRemoveHelper(state, "Clean Up Helper", {-66, 1.6, 46})
-- option: Show hand helper for each player
elseif id == "showHandHelper" then
for i, color in ipairs(MAT_COLORS) do
local pos = playmatApi.transformLocalPosition({0.05, 0, -1.182}, color)
local rot = playmatApi.returnRotation(color)
optionPanel[id][i] = spawnOrRemoveHelper(state, "Hand Helper", pos, rot)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Show search assistant for each player
elseif id == "showSearchAssistant" then
for i, color in ipairs(MAT_COLORS) do
local pos = playmatApi.transformLocalPosition({-0.3, 0, -1.182}, color)
local rot = playmatApi.returnRotation(color)
optionPanel[id][i] = spawnOrRemoveHelper(state, "Search Assistant", pos, rot)
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- option: Show attachment helper
elseif id == "showAttachmentHelper" then
optionPanel[id] = spawnOrRemoveHelper(state, "Attachment Helper", {-62, 1.4, 0})
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Show CYOA campaign guides
elseif id == "showCYOA" then
optionPanel[id] = spawnOrRemoveHelper(state, "CYOA Campaign Guides", {39, 1.3, -20})
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Show custom playmat images
elseif id == "showCustomPlaymatImages" then
optionPanel[id] = spawnOrRemoveHelper(state, "Custom Playmat Images", {67.5, 1.6, 37})
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- option: Show displacement tool
elseif id == "showDisplacementTool" then
optionPanel[id] = spawnOrRemoveHelper(state, "Displacement Tool", {-57, 1.6, 46})
end
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
-- handler for spawn / remove functions of helper objects
---@param state Boolean Contains the state of the option: true = spawn it, false = remove it
---@param name String Name of the helper object
---@param position Vector Position of the object (where it will spawn)
---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0})
---@return. GUID of the spawnedObj (or nil if object was removed)
function spawnOrRemoveHelper(state, name, position, rotation)
if (type(state) == "table" and #state == 0) then
return removeHelperObject(name)
elseif state then
Player.getPlayers()[1].pingTable(position)
return spawnHelperObject(name, position, rotation).getGUID()
2023-08-27 21:09:46 -04:00
else
2024-01-06 21:32:07 -05:00
return removeHelperObject(name)
end
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- copies the specified tool (by name) from the option panel source bag
---@param name String Name of the object that should be copied
---@param position Table Desired position of the object
function spawnHelperObject(name, position, rotation)
local sourceBag = getObjectFromGUID("830bd0")
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- error handling for missing sourceBag
if not sourceBag then
broadcastToAll("Option panel source bag could not be found!", "Red")
return
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
local spawnTable = {position = position}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- only overrride rotation if there is one provided (object's rotation used instead)
if rotation then
spawnTable.rotation = rotation
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
for _, obj in ipairs(sourceBag.getData().ContainedObjects) do
if obj["Nickname"] == name then
spawnTable.data = obj
spawnTable.callback_function = function(spawnedObj)
Wait.time(function() spawnedObj.setLock(true) end, 2)
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
return spawnObjectData(spawnTable)
2023-08-27 21:09:46 -04:00
end
2020-12-06 09:42:32 -05:00
end
end
2024-01-06 21:32:07 -05:00
-- removes the specified tool (by name)
---@param name String Object that should be removed
function removeHelperObject(name)
-- links objects name to the respective option name (to grab the GUID for removal)
local referenceTable = {
["Clean Up Helper"] = "showCleanUpHelper",
["Hand Helper"] = "showHandHelper",
["Search Assistant"] = "showSearchAssistant",
["Displacement Tool"] = "showDisplacementTool",
["Custom Playmat Images"] = "showCustomPlaymatImages",
["Attachment Helper"] = "showAttachmentHelper",
["CYOA Campaign Guides"] = "showCYOA"
}
local data = optionPanel[referenceTable[name]]
-- if there is a GUID stored, remove that object
if type(data) == "string" then
local obj = getObjectFromGUID(data)
if obj then obj.destruct() end
-- if it is a table (e.g. for the "Hand Helper", remove all of them)
elseif type(data) == "table" then
for _, guid in pairs(data) do
local obj = getObjectFromGUID(guid)
if obj then obj.destruct() end
2022-12-13 14:02:30 -05:00
end
2023-04-22 16:56:01 -04:00
end
2023-08-27 21:09:46 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- loads saved options
function loadSettings(newOptions)
optionPanel = newOptions
updateOptionPanelState()
for id, state in pairs(optionPanel) do
applyOptionPanelChange(id, state)
end
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- loads the default options
function onClick_defaultSettings()
for id, _ in pairs(optionPanel) do
local state = false
-- override for settings that are enabled by default
if id == "useSnapTags" or id == "showTitleSplash" then
state = true
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
applyOptionPanelChange(id, state)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- clean reset of variables
optionPanel = {
cardLanguage = "en",
playAreaSnapTags = true,
showAttachmentHelper = false,
showCleanUpHelper = false,
showCustomPlaymatImages = false,
showCYOA = false,
showDisplacementTool = false,
showDrawButton = false,
showHandHelper = {},
showSearchAssistant = {},
showTitleSplash = true,
useClueClickers = false,
useResourceCounters = "disabled",
useSnapTags = true
}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- update UI
updateOptionPanelState()
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- splash scenario title on setup
function titleSplash(scenarioName)
if optionPanel['showTitleSplash'] then
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- if there's any ongoing title being displayed, hide it and cancel the waiting function
if hideTitleSplashWaitFunctionId then
Wait.stop(hideTitleSplashWaitFunctionId)
hideTitleSplashWaitFunctionId = nil
UI.setAttribute('title_splash', 'active', false)
2023-08-27 21:09:46 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- display scenario name and set a 4 seconds (2 seconds animation and 2 seconds on screen)
-- wait timer to hide the scenario name
UI.setValue('title_splash_text', scenarioName)
UI.show('title_splash')
hideTitleSplashWaitFunctionId = Wait.time(function()
UI.hide('title_splash')
hideTitleSplashWaitFunctionId = nil
end, 4)
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
soundCubeApi.playSoundByName("Deep Bell")
end
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
---------------------------------------------------------
-- Update notification related functionality
---------------------------------------------------------
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- grabs the latest mod version and release notes from GitHub (called onLoad())
function getModVersion()
WebRequest.get(SOURCE_REPO .. '/modversion.json', compareVersion)
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- compares the modversion with GitHub and possibly shows the update notification
function compareVersion(request)
if request.is_error then
log(request.error)
return
2022-12-13 14:02:30 -05:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- global variable to make it accessible for other functions
modMeta = JSON.decode(request.text)
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- stop here if on latest version
if MOD_VERSION == modMeta["latestVersion"] then return end
-- stop here if "don't show again" was clicked for this version before
if acknowledgedUpgradeVersions[modMeta["latestVersion"]] then return end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
updateNotificationLoading()
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- delay to avoid lagging during onLoad()
Wait.time(function() UI.show("FinnIcon") end, 1)
2022-12-13 14:02:30 -05:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- updates the XML update notification based on the mod metadata
function updateNotificationLoading()
-- grab data
local highlights = modMeta["releaseHighlights"]
-- concatenate the release highlights
local highlightText = "• " .. highlights[1]
for i, entry in pairs(highlights) do
if i ~= 1 then
highlightText = highlightText .. "\n• " .. entry
2023-08-27 21:09:46 -04:00
end
end
2024-01-06 21:32:07 -05:00
-- update the XML UI
UI.setValue("notificationHeader", "New version available: ".. modMeta["latestVersion"])
UI.setValue("releaseHighlightText", highlightText)
UI.setAttribute("highlightRow", "preferredHeight", 20*#highlights)
UI.setAttribute("updateNotification", "height", 20*#highlights + 125)
2023-08-27 21:09:46 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- triggered by clicking on the Finn Icon
function onClick_FinnIcon()
if notificationVisible then
UI.hide("updateNotification")
notificationVisible = false
else
UI.show("updateNotification")
notificationVisible = true
2023-08-27 21:09:46 -04:00
end
end
2022-12-13 14:02:30 -05:00
2024-01-06 21:32:07 -05:00
-- close / don't show again buttons on the update notification
function onClick_notification(_, parameter)
if parameter == "dontShowAgain" then
-- this variable tracks if "don't show again" was pressed for a version
acknowledgedUpgradeVersions[modMeta["latestVersion"]] = true
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
UI.hide("FinnIcon")
UI.hide("updateNotification")
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end)
__bundle_register("accessories/TokenArrangerApi", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local TokenArrangerApi = {}
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- local function to call the token arranger, if it is on the table
---@param functionName String Name of the function to cal
---@param argument Variant Parameter to pass
local function callIfExistent(functionName, argument)
local tokenArranger = getObjectsWithTag("TokenArranger")[1]
if tokenArranger ~= nil then
tokenArranger.call(functionName, argument)
end
2022-12-13 14:02:30 -05:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- updates the token modifiers with the provided data
---@param tokenData Table Contains the chaos token metadata
TokenArrangerApi.onTokenDataChanged = function(fullData)
callIfExistent("onTokenDataChanged", fullData)
2023-08-27 21:09:46 -04:00
end
2023-04-22 16:56:01 -04:00
2024-01-06 21:32:07 -05:00
-- deletes already laid out tokens
TokenArrangerApi.deleteCopiedTokens = function()
callIfExistent("deleteCopiedTokens")
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- updates the laid out tokens
TokenArrangerApi.layout = function()
Wait.time(function() callIfExistent("layout") end, 0.1)
end
2022-12-13 14:02:30 -05:00
2024-01-06 21:32:07 -05:00
return TokenArrangerApi
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end)
__bundle_register("chaosbag/BlessCurseManagerApi", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local BlessCurseManagerApi = {}
local MANAGER_GUID = "5933fb"
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- removes all taken tokens and resets the counts
BlessCurseManagerApi.removeTakenTokensAndReset = function()
local BlessCurseManager = getObjectFromGUID(MANAGER_GUID)
Wait.time(function() BlessCurseManager.call("removeTakenTokens", "Bless") end, 0.05)
Wait.time(function() BlessCurseManager.call("removeTakenTokens", "Curse") end, 0.10)
Wait.time(function() BlessCurseManager.call("doReset", "White") end, 0.15)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- updates the internal count (called by cards that seal bless/curse tokens)
BlessCurseManagerApi.sealedToken = function(type, guid)
getObjectFromGUID(MANAGER_GUID).call("sealedToken", { type = type, guid = guid })
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- updates the internal count (called by cards that seal bless/curse tokens)
BlessCurseManagerApi.releasedToken = function(type, guid)
getObjectFromGUID(MANAGER_GUID).call("releasedToken", { type = type, guid = guid })
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
-- broadcasts the current status for bless/curse tokens
---@param playerColor String Color of the player to show the broadcast to
BlessCurseManagerApi.broadcastStatus = function(playerColor)
getObjectFromGUID(MANAGER_GUID).call("broadcastStatus", playerColor)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- removes all bless / curse tokens from the chaos bag and play
---@param playerColor String Color of the player to show the broadcast to
BlessCurseManagerApi.removeAll = function(playerColor)
getObjectFromGUID(MANAGER_GUID).call("doRemove", playerColor)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- adds Wendy's menu to the hovered card (allows sealing of tokens)
---@param color String Color of the player to show the broadcast to
BlessCurseManagerApi.addWendysMenu = function(playerColor, hoveredObject)
getObjectFromGUID(MANAGER_GUID).call("addMenuOptions", { playerColor = playerColor, hoveredObject = hoveredObject })
end
return BlessCurseManagerApi
end
end)
__bundle_register("core/NavigationOverlayApi", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local NavigationOverlayApi = {}
local HANDLER_GUID = "797ede"
-- Copies the visibility for the Navigation overlay
---@param startColor String Color of the player to copy from
---@param targetColor String Color of the targeted player
NavigationOverlayApi.copyVisibility = function(startColor, targetColor)
getObjectFromGUID(HANDLER_GUID).call("copyVisibility", {
startColor = startColor,
targetColor = targetColor
})
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
-- Changes the Navigation Overlay view ("Full View" --> "Play Areas" --> "Closed" etc.)
---@param playerColor String Color of the player to update the visibility for
NavigationOverlayApi.cycleVisibility = function(playerColor)
getObjectFromGUID(HANDLER_GUID).call("cycleVisibility", playerColor)
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
return NavigationOverlayApi
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end)
__bundle_register("core/token/TokenSpawnTrackerApi", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local TokenSpawnTracker = { }
local SPAWN_TRACKER_GUID = "e3ffc9"
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
TokenSpawnTracker.hasSpawnedTokens = function(cardGuid)
return getObjectFromGUID(SPAWN_TRACKER_GUID).call("hasSpawnedTokens", cardGuid)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
TokenSpawnTracker.markTokensSpawned = function(cardGuid)
return getObjectFromGUID(SPAWN_TRACKER_GUID).call("markTokensSpawned", cardGuid)
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
TokenSpawnTracker.resetTokensSpawned = function(cardGuid)
return getObjectFromGUID(SPAWN_TRACKER_GUID).call("resetTokensSpawned", cardGuid)
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
TokenSpawnTracker.resetAllAssetAndEvents = function()
return getObjectFromGUID(SPAWN_TRACKER_GUID).call("resetAllAssetAndEvents")
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
TokenSpawnTracker.resetAllLocations = function()
return getObjectFromGUID(SPAWN_TRACKER_GUID).call("resetAllLocations")
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
TokenSpawnTracker.resetAll = function()
return getObjectFromGUID(SPAWN_TRACKER_GUID).call("resetAll")
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
return TokenSpawnTracker
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end)
__bundle_register("core/MythosAreaApi", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local MythosAreaApi = {}
local MYTHOS_AREA_GUID = "9f334f"
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- returns the chaos token metadata (if provided through scenario reference card)
MythosAreaApi.returnTokenData = function()
return getObjectFromGUID(MYTHOS_AREA_GUID).call("returnTokenData")
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- draw an encounter card to the requested position/rotation
MythosAreaApi.drawEncounterCard = function(pos, rotY, alwaysFaceUp)
getObjectFromGUID(MYTHOS_AREA_GUID).call("drawEncounterCard", {
pos = pos,
rotY = rotY,
alwaysFaceUp = alwaysFaceUp
})
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
return MythosAreaApi
end
end)
__bundle_register("core/PlayAreaApi", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local PlayAreaApi = { }
local PLAY_AREA_GUID = "721ba2"
local INVESTIGATOR_COUNTER_GUID = "f182ee"
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- Returns the current value of the investigator counter from the playmat
---@return Integer. Number of investigators currently set on the counter
PlayAreaApi.getInvestigatorCount = function()
return getObjectFromGUID(INVESTIGATOR_COUNTER_GUID).getVar("val")
2023-08-27 21:09:46 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- Updates the current value of the investigator counter from the playmat
---@param count Number of investigators to set on the counter
PlayAreaApi.setInvestigatorCount = function(count)
return getObjectFromGUID(INVESTIGATOR_COUNTER_GUID).call("updateVal", count)
2023-08-27 21:09:46 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain
-- fixed objects will be ignored, as will anything the player has tagged with
-- 'displacement_excluded'
---@param playerColor Color of the player requesting the shift. Used solely to send an error
--- message in the unlikely case that the scripting zone has been deleted
PlayAreaApi.shiftContentsUp = function(playerColor)
return getObjectFromGUID(PLAY_AREA_GUID).call("shiftContentsUp", playerColor)
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
PlayAreaApi.shiftContentsDown = function(playerColor)
return getObjectFromGUID(PLAY_AREA_GUID).call("shiftContentsDown", playerColor)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
PlayAreaApi.shiftContentsLeft = function(playerColor)
return getObjectFromGUID(PLAY_AREA_GUID).call("shiftContentsLeft", playerColor)
2023-04-22 16:56:01 -04:00
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
PlayAreaApi.shiftContentsRight = function(playerColor)
return getObjectFromGUID(PLAY_AREA_GUID).call("shiftContentsRight", playerColor)
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- Reset the play area's tracking of which cards have had tokens spawned.
PlayAreaApi.resetSpawnedCards = function()
return getObjectFromGUID(PLAY_AREA_GUID).call("resetSpawnedCards")
end
2020-12-06 09:42:32 -05:00
2024-01-06 21:32:07 -05:00
-- Event to be called when the current scenario has changed.
---@param scenarioName Name of the new scenario
PlayAreaApi.onScenarioChanged = function(scenarioName)
getObjectFromGUID(PLAY_AREA_GUID).call("onScenarioChanged", scenarioName)
2022-12-13 14:02:30 -05:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Sets this playmat's snap points to limit snapping to locations or not.
-- If matchTypes is false, snap points will be reset to snap all cards.
---@param matchTypes Boolean Whether snap points should only snap for the matching card types.
PlayAreaApi.setLimitSnapsByType = function(matchCardTypes)
getObjectFromGUID(PLAY_AREA_GUID).call("setLimitSnapsByType", matchCardTypes)
2023-04-22 16:56:01 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Receiver for the Global tryObjectEnterContainer event. Used to clear vector lines from dragged
-- cards before they're destroyed by entering the container
PlayAreaApi.tryObjectEnterContainer = function(container, object)
getObjectFromGUID(PLAY_AREA_GUID).call("tryObjectEnterContainer",
{ container = container, object = object })
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- counts the VP on locations in the play area
PlayAreaApi.countVP = function()
return getObjectFromGUID(PLAY_AREA_GUID).call("countVP")
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- highlights all locations in the play area without metadata
---@param state Boolean True if highlighting should be enabled
PlayAreaApi.highlightMissingData = function(state)
return getObjectFromGUID(PLAY_AREA_GUID).call("highlightMissingData", state)
end
-- highlights all locations in the play area with VP
---@param state Boolean True if highlighting should be enabled
PlayAreaApi.highlightCountedVP = function(state)
return getObjectFromGUID(PLAY_AREA_GUID).call("highlightCountedVP", state)
end
-- Checks if an object is in the play area (returns true or false)
PlayAreaApi.isInPlayArea = function(object)
return getObjectFromGUID(PLAY_AREA_GUID).call("isInPlayArea", object)
2021-10-18 15:54:27 -04:00
end
2024-01-06 21:32:07 -05:00
PlayAreaApi.getSurface = function()
return getObjectFromGUID(PLAY_AREA_GUID).getCustomObject().image
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
PlayAreaApi.updateSurface = function(url)
return getObjectFromGUID(PLAY_AREA_GUID).call("updateSurface", url)
end
-- 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
PlayAreaApi.updateLocations = function(args)
getObjectFromGUID(PLAY_AREA_GUID).call("updateLocations", args)
2021-10-18 15:54:27 -04:00
end
2024-01-06 21:32:07 -05:00
PlayAreaApi.getCustomDataHelper = function()
return getObjectFromGUID(PLAY_AREA_GUID).getVar("customDataHelper")
end
2021-10-18 15:54:27 -04:00
2024-01-06 21:32:07 -05:00
return PlayAreaApi
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
end)
__bundle_register("core/token/TokenManager", function(require, _LOADED, __bundle_register, __bundle_modules)
do
local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi")
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
local PLAYER_CARD_TOKEN_OFFSETS = {
[1] = {
Vector(0, 3, -0.2)
},
[2] = {
Vector(0.4, 3, -0.2),
Vector(-0.4, 3, -0.2)
},
[3] = {
Vector(0, 3, -0.9),
Vector(0.4, 3, -0.2),
Vector(-0.4, 3, -0.2)
},
[4] = {
Vector(0.4, 3, -0.9),
Vector(-0.4, 3, -0.9),
Vector(0.4, 3, -0.2),
Vector(-0.4, 3, -0.2)
},
[5] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.4, 3, -0.2),
Vector(-0.4, 3, -0.2)
},
[6] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.7, 3, -0.2),
Vector(0, 3, -0.2),
Vector(-0.7, 3, -0.2)
},
[7] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.7, 3, -0.2),
Vector(0, 3, -0.2),
Vector(-0.7, 3, -0.2),
Vector(0, 3, 0.5)
},
[8] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.7, 3, -0.2),
Vector(0, 3, -0.2),
Vector(-0.7, 3, -0.2),
Vector(-0.35, 3, 0.5),
Vector(0.35, 3, 0.5)
},
[9] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.7, 3, -0.2),
Vector(0, 3, -0.2),
Vector(-0.7, 3, -0.2),
Vector(0.7, 3, 0.5),
Vector(0, 3, 0.5),
Vector(-0.7, 3, 0.5)
},
[10] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.7, 3, -0.2),
Vector(0, 3, -0.2),
Vector(-0.7, 3, -0.2),
Vector(0.7, 3, 0.5),
Vector(0, 3, 0.5),
Vector(-0.7, 3, 0.5),
Vector(0, 3, 1.2)
},
[11] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.7, 3, -0.2),
Vector(0, 3, -0.2),
Vector(-0.7, 3, -0.2),
Vector(0.7, 3, 0.5),
Vector(0, 3, 0.5),
Vector(-0.7, 3, 0.5),
Vector(-0.35, 3, 1.2),
Vector(0.35, 3, 1.2)
},
[12] = {
Vector(0.7, 3, -0.9),
Vector(0, 3, -0.9),
Vector(-0.7, 3, -0.9),
Vector(0.7, 3, -0.2),
Vector(0, 3, -0.2),
Vector(-0.7, 3, -0.2),
Vector(0.7, 3, 0.5),
Vector(0, 3, 0.5),
Vector(-0.7, 3, 0.5),
Vector(0.7, 3, 1.2),
Vector(0, 3, 1.2),
Vector(-0.7, 3, 1.2)
}
}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- stateIDs for the multi-stated resource tokens
local stateTable = {
["resource"] = 1,
["ammo"] = 2,
["bounty"] = 3,
["charge"] = 4,
["evidence"] = 5,
["secret"] = 6,
["supply"] = 7
}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- Source for tokens
local TOKEN_SOURCE_GUID = "124381"
2021-10-18 15:54:27 -04:00
2024-01-06 21:32:07 -05:00
-- Table of data extracted from the token source bag, keyed by the Memo on each token which
-- should match the token type keys ("resource", "clue", etc)
local tokenTemplates
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
local DATA_HELPER_GUID = "708279"
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
local playerCardData
local locationData
2021-10-18 15:54:27 -04:00
2024-01-06 21:32:07 -05:00
local TokenManager = { }
local internal = { }
-- Spawns tokens for the card. This function is built to just throw a card at it and let it do
-- the work once a card has hit an area where it might spawn tokens. It will check to see if
-- the card has already spawned, find appropriate data from either the uses metadata or the Data
-- Helper, and spawn the tokens.
---@param card Object Card to maybe spawn tokens for
---@param extraUses Table A table of <use type>=<count> which will modify the number of tokens
--- spawned for that type. e.g. Akachi's playmat should pass "Charge"=1
TokenManager.spawnForCard = function(card, extraUses)
if tokenSpawnTrackerApi.hasSpawnedTokens(card.getGUID()) then
return
end
local metadata = JSON.decode(card.getGMNotes())
if metadata ~= nil then
internal.spawnTokensFromUses(card, extraUses)
2021-10-18 15:54:27 -04:00
else
2024-01-06 21:32:07 -05:00
internal.spawnTokensFromDataHelper(card)
2021-10-18 15:54:27 -04:00
end
end
2024-01-06 21:32:07 -05:00
-- Spawns a set of tokens on the given card.
---@param card Object Card to spawn tokens on
---@param tokenType String Type of token to spawn, valid values are "damage", "horror",
-- "resource", "doom", or "clue"
---@param tokenCount Number How many tokens to spawn. For damage or horror this value will be set to the
-- spawned state object rather than spawning multiple tokens
---@param shiftDown Number An offset for the z-value of this group of tokens
---@param subType Number Subtype of token to spawn. This will only differ from the tokenName for resource tokens
TokenManager.spawnTokenGroup = function(card, tokenType, tokenCount, shiftDown, subType)
local optionPanel = optionPanelApi.getOptions()
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
if tokenType == "damage" or tokenType == "horror" then
TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown)
elseif tokenType == "resource" and optionPanel["useResourceCounters"] == "enabled" then
TokenManager.spawnResourceCounterToken(card, tokenCount)
elseif tokenType == "resource" and optionPanel["useResourceCounters"] == "custom" and tokenCount == 0 then
TokenManager.spawnResourceCounterToken(card, tokenCount)
else
TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown, subType)
end
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- Spawns a single counter token and sets the value to tokenValue. Used for damage and horror
-- tokens.
---@param card Object Card to spawn tokens on
---@param tokenType String type of token to spawn, valid values are "damage" and "horror". Other
-- types should use spawnMultipleTokens()
---@param tokenValue Number Value to set the damage/horror to
TokenManager.spawnCounterToken = function(card, tokenType, tokenValue, shiftDown)
if tokenValue < 1 or tokenValue > 50 then return end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
local pos = card.positionToWorld(PLAYER_CARD_TOKEN_OFFSETS[1][1] + Vector(0, 0, shiftDown))
local rot = card.getRotation()
TokenManager.spawnToken(pos, tokenType, rot, function(spawned) spawned.setState(tokenValue) end)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
TokenManager.spawnResourceCounterToken = function(card, tokenCount)
local pos = card.positionToWorld(card.positionToLocal(card.getPosition()) + Vector(0, 0.2, -0.5))
local rot = card.getRotation()
TokenManager.spawnToken(pos, "resourceCounter", rot, function(spawned)
spawned.call("updateVal", tokenCount)
end)
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- Spawns a number of tokens.
---@param tokenType String type of token to spawn, valid values are resource", "doom", or "clue".
-- Other types should use spawnCounterToken()
---@param tokenCount Number How many tokens to spawn
---@param shiftDown Number An offset for the z-value of this group of tokens
---@param subType Number Subtype of token to spawn. This will only differ from the tokenName for resource tokens
TokenManager.spawnMultipleTokens = function(card, tokenType, tokenCount, shiftDown, subType)
-- not checking the max at this point since clue offsets are calculated dynamically
if tokenCount < 1 then return end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
local offsets = {}
if tokenType == "clue" then
offsets = internal.buildClueOffsets(card, tokenCount)
else
-- only up to 12 offset tables defined
if tokenCount > 12 then return end
for i = 1, tokenCount do
offsets[i] = card.positionToWorld(PLAYER_CARD_TOKEN_OFFSETS[tokenCount][i])
-- Fix the y-position for the spawn, since positionToWorld considers rotation which can
-- have bad results for face up/down differences
offsets[i].y = card.getPosition().y + 0.15
end
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
if shiftDown ~= nil then
-- Copy the offsets to make sure we don't change the static values
local baseOffsets = offsets
offsets = { }
for i, baseOffset in ipairs(baseOffsets) do
offsets[i] = baseOffset
offsets[i][3] = offsets[i][3] + shiftDown
end
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
if offsets == nil then
error("couldn't find offsets for " .. tokenCount .. ' tokens')
return
2021-10-18 15:54:27 -04:00
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- handling for not provided subtype (for example when spawning from custom data helpers)
if subType == nil then
subType = ""
end
-- this is used to load the correct state for additional resource tokens (e.g. "Ammo")
local callback = nil
local stateID = stateTable[string.lower(subType)]
if tokenType == "resource" and stateID ~= nil and stateID ~= 1 then
callback = function(spawned) spawned.setState(stateID) end
2021-10-18 15:54:27 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
for i = 1, tokenCount do
TokenManager.spawnToken(offsets[i], tokenType, card.getRotation(), callback)
end
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Spawns a single token at the given global position by copying it from the template bag.
---@param position Global position to spawn the token
---@param tokenType String type of token to spawn, valid values are "damage", "horror",
-- "resource", "doom", or "clue"
---@param rotation Vector Rotation to be used for the new token. Only the y-value will be used,
-- x and z will use the default rotation from the source bag
---@param callback function A callback function triggered after the new token is spawned
TokenManager.spawnToken = function(position, tokenType, rotation, callback)
internal.initTokenTemplates()
local loadTokenType = tokenType
if tokenType == "clue" or tokenType == "doom" then
loadTokenType = "clueDoom"
end
if tokenTemplates[loadTokenType] == nil then
error("Unknown token type '" .. tokenType .. "'")
return
end
local tokenTemplate = tokenTemplates[loadTokenType]
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Take ONLY the Y-value for rotation, so we don't flip the token coming out of the bag
local rot = Vector(tokenTemplate.Transform.rotX,
270,
tokenTemplate.Transform.rotZ)
if rotation ~= nil then
rot.y = rotation.y
end
if tokenType == "doom" then
rot.z = 180
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
tokenTemplate.Nickname = ""
return spawnObjectData({
data = tokenTemplate,
position = position,
rotation = rot,
callback_function = callback
})
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- Checks a card for metadata to maybe replenish it
---@param card Object Card object to be replenished
---@param uses Table The already decoded metadata.uses (to avoid decoding again)
---@param mat Object The playmat the card is placed on (for rotation and casting)
TokenManager.maybeReplenishCard = function(card, uses, mat)
-- TODO: support for cards with multiple uses AND replenish (as of yet, no official card needs that)
if uses[1].count and uses[1].replenish then
internal.replenishTokens(card, uses, mat)
end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- Delegate function to the token spawn tracker. Exists to avoid circular dependencies in some
-- callers.
---@param card Object Card object to reset the tokens for
TokenManager.resetTokensSpawned = function(card)
tokenSpawnTrackerApi.resetTokensSpawned(card.getGUID())
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Pushes new player card data into the local copy of the Data Helper player data.
---@param dataTable Table Key/Value pairs following the DataHelper style
TokenManager.addPlayerCardData = function(dataTable)
internal.initDataHelperData()
for k, v in pairs(dataTable) do
playerCardData[k] = v
end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- Pushes new location data into the local copy of the Data Helper location data.
---@param dataTable Table Key/Value pairs following the DataHelper style
TokenManager.addLocationData = function(dataTable)
internal.initDataHelperData()
for k, v in pairs(dataTable) do
locationData[k] = v
end
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Checks to see if the given card has location data in the DataHelper
---@param card Object Card to check for data
---@return Boolean True if this card has data in the helper, false otherwise
TokenManager.hasLocationData = function(card)
internal.initDataHelperData()
return internal.getLocationData(card) ~= nil
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
internal.initTokenTemplates = function()
if tokenTemplates ~= nil then
return
end
tokenTemplates = { }
local tokenSource = getObjectFromGUID(TOKEN_SOURCE_GUID)
for _, tokenTemplate in ipairs(tokenSource.getData().ContainedObjects) do
local tokenName = tokenTemplate.Memo
tokenTemplates[tokenName] = tokenTemplate
2023-01-29 19:31:52 -05:00
end
end
2024-01-06 21:32:07 -05:00
-- Copies the data from the DataHelper. Will only happen once.
internal.initDataHelperData = function()
if playerCardData ~= nil then
return
end
local dataHelper = getObjectFromGUID(DATA_HELPER_GUID)
playerCardData = dataHelper.getTable('PLAYER_CARD_DATA')
locationData = dataHelper.getTable('LOCATIONS_DATA')
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Spawn tokens for a card based on the uses metadata. This will consider the face up/down state
-- of the card for both locations and standard cards.
---@param card Object Card to maybe spawn tokens for
---@param extraUses Table A table of <use type>=<count> which will modify the number of tokens
--- spawned for that type. e.g. Akachi's playmat should pass "Charge"=1
internal.spawnTokensFromUses = function(card, extraUses)
local uses = internal.getUses(card)
if uses == nil then return end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- go through tokens to spawn
local type, token, tokenCount
for i, useInfo in ipairs(uses) do
type = useInfo.type
token = useInfo.token
tokenCount = (useInfo.count or 0)
+ (useInfo.countPerInvestigator or 0) * playAreaApi.getInvestigatorCount()
if extraUses ~= nil and extraUses[type] ~= nil then
tokenCount = tokenCount + extraUses[type]
end
-- Shift each spawned group after the first down so they don't pile on each other
TokenManager.spawnTokenGroup(card, token, tokenCount, (i - 1) * 0.8, type)
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- Spawn tokens for a card based on the data helper data. This will consider the face up/down state
-- of the card for both locations and standard cards.
---@param card Object Card to maybe spawn tokens for
internal.spawnTokensFromDataHelper = function(card)
internal.initDataHelperData()
local playerData = internal.getPlayerCardData(card)
if playerData ~= nil then
internal.spawnPlayerCardTokensFromDataHelper(card, playerData)
end
local locationData = internal.getLocationData(card)
if locationData ~= nil then
internal.spawnLocationTokensFromDataHelper(card, locationData)
end
2023-04-22 16:56:01 -04:00
end
2024-01-06 21:32:07 -05:00
-- Spawn tokens for a player card using data retrieved from the Data Helper.
---@param card Object Card to maybe spawn tokens for
---@param playerData Table Player card data structure retrieved from the DataHelper. Should be
-- the right data for this card.
internal.spawnPlayerCardTokensFromDataHelper = function(card, playerData)
token = playerData.tokenType
tokenCount = playerData.tokenCount
--log("Spawning data helper tokens for "..card.getName()..'['..card.getDescription()..']: '..tokenCount.."x "..token)
TokenManager.spawnTokenGroup(card, token, tokenCount)
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
end
-- Spawn tokens for a location using data retrieved from the Data Helper.
---@param card Object Card to maybe spawn tokens for
---@param playerData Table Location data structure retrieved from the DataHelper. Should be
-- the right data for this card.
internal.spawnLocationTokensFromDataHelper = function(card, locationData)
local clueCount = internal.getClueCountFromData(card, locationData)
if clueCount > 0 then
TokenManager.spawnTokenGroup(card, "clue", clueCount)
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
2023-01-29 19:31:52 -05:00
end
end
2024-01-06 21:32:07 -05:00
internal.getPlayerCardData = function(card)
return playerCardData[card.getName() .. ':' .. card.getDescription()]
or playerCardData[card.getName()]
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
internal.getLocationData = function(card)
return locationData[card.getName() .. '_' .. card.getGUID()] or locationData[card.getName()]
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
internal.getClueCountFromData = function(card, locationData)
-- Return the number of clues to spawn on this location
if locationData == nil then
error('attempted to get clue for unexpected object: ' .. card.getName())
return 0
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
--log(card.getName() .. ' : ' .. locationData.type .. ' : ' .. locationData.value .. ' : ' .. locationData.clueSide)
if ((card.is_face_down and locationData.clueSide == 'back')
or (not card.is_face_down and locationData.clueSide == 'front')) then
if locationData.type == 'fixed' then
return locationData.value
elseif locationData.type == 'perPlayer' then
return locationData.value * playAreaApi.getInvestigatorCount()
end
error('unexpected location type: ' .. locationData.type)
2023-08-27 21:09:46 -04:00
end
2024-01-06 21:32:07 -05:00
return 0
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Gets the right uses structure for this card, based on metadata and face up/down state
---@param card Object Card to pull the uses from
internal.getUses = function(card)
local metadata = JSON.decode(card.getGMNotes()) or { }
if metadata.type == "Location" then
if card.is_face_down and metadata.locationBack ~= nil then
return metadata.locationBack.uses
elseif not card.is_face_down and metadata.locationFront ~= nil then
return metadata.locationFront.uses
end
elseif not card.is_face_down then
return metadata.uses
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
return nil
2023-04-22 16:56:01 -04:00
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- Dynamically create positions for clues on a card.
---@param card Object Card the clues will be placed on
---@param count Integer How many clues?
---@return Table Array of global positions to spawn the clues at
internal.buildClueOffsets = function(card, count)
local pos = card.getPosition()
local cluePositions = { }
for i = 1, count do
local row = math.floor(1 + (i - 1) / 4)
local column = (i - 1) % 4
table.insert(cluePositions, Vector(pos.x + 1.5 - 0.55 * row, pos.y + 0.15, pos.z - 0.825 + 0.55 * column))
end
return cluePositions
end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
---@param card Object Card object to be replenished
---@param uses Table The already decoded metadata.uses (to avoid decoding again)
---@param mat Object The playmat the card is placed on (for rotation and casting)
internal.replenishTokens = function(card, uses, mat)
local cardPos = card.getPosition()
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- don't continue for cards on the deck (Norman) or in the discard pile
if mat.positionToLocal(cardPos).x < -1 then return end
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
-- get current amount of resource tokens on the card
local search = internal.searchOnCard(cardPos, card.getRotation())
local clickableResourceCounter = nil
local foundTokens = 0
2023-01-29 19:31:52 -05:00
2024-01-06 21:32:07 -05:00
for _, obj in ipairs(search) do
local obj = obj.hit_object
local memo = obj.getMemo()
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
if (stateTable[memo] or 0) > 0 then
foundTokens = foundTokens + math.abs(obj.getQuantity())
obj.destruct()
elseif memo == "resourceCounter" then
foundTokens = obj.getVar("val")
clickableResourceCounter = obj
break
end
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- this is the theoretical new amount of uses (to be checked below)
local newCount = foundTokens + uses[1].replenish
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- if there are already more uses than the replenish amount, keep them
if foundTokens > uses[1].count then
newCount = foundTokens
-- only replenish up until the replenish amount
elseif newCount > uses[1].count then
newCount = uses[1].count
end
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- update the clickable counter or spawn a group of tokens
if clickableResourceCounter then
clickableResourceCounter.call("updateVal", newCount)
else
TokenManager.spawnTokenGroup(card, uses[1].token, newCount, _, uses[1].type)
2023-04-22 16:56:01 -04:00
end
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- searches on a card (standard size) and returns the result
---@param position Table Position of the card
---@param rotation Table Rotation of the card
internal.searchOnCard = function(position, rotation)
return Physics.cast({
origin = position,
direction = {0, 1, 0},
orientation = rotation,
type = 3,
size = { 2.5, 0.5, 3.5 },
max_distance = 1,
debug = false
})
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
return TokenManager
2023-08-27 21:09:46 -04:00
end
end)
2024-01-06 21:32:07 -05:00
__bundle_register("core/OptionPanelApi", function(require, _LOADED, __bundle_register, __bundle_modules)
2023-08-27 21:09:46 -04:00
do
2024-01-06 21:32:07 -05:00
local OptionPanelApi = {}
2023-08-27 21:09:46 -04:00
2024-01-06 21:32:07 -05:00
-- loads saved options
---@param options Table New options table
OptionPanelApi.loadSettings = function(options)
return Global.call("loadSettings", options)
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
-- returns option panel table
OptionPanelApi.getOptions = function()
return Global.getTable("optionPanel")
2023-01-29 19:31:52 -05:00
end
2024-01-06 21:32:07 -05:00
return OptionPanelApi
2023-01-29 19:31:52 -05:00
end
2022-12-13 14:02:30 -05:00
end)
return __bundle_require("__root")