Merge pull request #887 from argonui/investigator-callback

Added an investigator placing callback
This commit is contained in:
dscarpac 2024-10-02 07:45:27 -05:00 committed by GitHub
commit 5d226574f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 175 additions and 46 deletions

View File

@ -19,7 +19,6 @@
"LuckyPenny.2ab443",
"SecretObjectivesUltimatums.b2077d",
"UnderworldMarketHelper.3650ea",
"Subject5U-21Helper.1335e8",
"Auto-failCounter.a9a321",
"ElderSignCounter.e62cb5",
"AdditionalVictoryPoints.958bc0"

View File

@ -17,6 +17,7 @@
"CYOACampaignGuides.e87ea2",
"AttachmentHelper.7f4976",
"SearchAssistant.17aed0",
"Subject5U-21Helper.1335e8",
"HandHelper.450688",
"DisplacementTool.0f1374",
"CleanUpHelper.26cf4b"

View File

@ -2478,6 +2478,54 @@ function TokenManager.replenishTokens(card, useInfo)
end
end
-- generates the data to spawn an infinite bag of a specific type of resources
function TokenManager.getDataForInfiniteBag(params)
-- re-assign parameters for convenience
local tokenType = params.tokenType
local position = params.position
local rotation = params.rotation
-- make sure the token templates are initialized
TokenManager.initTokenTemplates()
-- create a copy of the resource token (to not modify the source)
local template = deepCopy(tokenTemplates["resource"])
local subTypeStateId = stateTable[tokenType]
local subTypeData = template["States"][subTypeStateId]
-- add states to data
subTypeData["States"] = template["States"]
-- add "1" state and remove the current state
subTypeData["States"][1] = template
subTypeData["States"][1]["States"] = nil
subTypeData["States"][subTypeStateId] = nil
-- update rotation of the main state
subTypeData["Transform"].rotX = 0
subTypeData["Transform"].rotY = 0
subTypeData["Transform"].rotZ = 0
-- generate and return data for the infinite bag
local properTypeName = tokenType:gsub("^%l", string.upper)
return {
Name = "Infinite_Bag",
Nickname = properTypeName .. " Bag",
ContainedObjects = { subTypeData },
Transform = {
posX = position.x,
posY = position.y,
posZ = position.z,
rotX = rotation.x,
rotY = rotation.y,
rotZ = rotation.z,
scaleX = 1,
scaleY = 1,
scaleZ = 1
}
}
end
---------------------------------------------------------
-- Callback functions for token spawning
---------------------------------------------------------
@ -2547,3 +2595,17 @@ function getColoredName(playerColor)
-- add bb-code
return "[" .. Color.fromString(playerColor):toHex() .. "]" .. displayName .. "[-]"
end
-- creates a deep copy of a table
function deepCopy(data)
if type(data) ~= "table" then return data end
local copiedList = {}
for key, value in pairs(data) do
if type(value) == "table" then
copiedList[key] = deepCopy(value)
else
copiedList[key] = value
end
end
return copiedList
end

View File

@ -50,7 +50,7 @@ do
---@param playerColor string Color of the player that needs the visibility toggled
---@param handColor string Color of the hand to toggle the visibility for
function GlobalApi.handVisibilityToggle(playerColor, handColor)
Global.call("handVisibilityToggle", { playerColor = playerColor, handColor = handColor})
Global.call("handVisibilityToggle", { playerColor = playerColor, handColor = handColor })
end
-- loads saved options

View File

@ -89,9 +89,18 @@ do
function TokenManagerApi.maybeReplenishCard(card, uses)
Global.call("callTable", {
{ "TokenManager", "maybeReplenishCard" },
{ card = card, uses = uses }
})
end
-- Generates the data to spawn an infinite bag of a specific type of resources
function TokenManagerApi.getDataForInfiniteBag(tokenType, position, rotation)
return Global.call("callTable", {
{ "TokenManager", "getDataForInfiniteBag" },
{
card = card,
uses = uses
tokenType = tokenType,
position = position,
rotation = rotation
}
})
end

View File

@ -8,6 +8,7 @@ local searchLib = require("util/SearchLib")
local tokenChecker = require("core/token/TokenChecker")
local tokenManagerApi = require("core/token/TokenManagerApi")
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
local zones = require("playermat/Zones")
-- option panel data
local availableOptions = {
@ -271,9 +272,15 @@ function round(num, numDecimalPlaces)
end
-- updates the internal "messageColor" which is used for print/broadcast statements if no player is seated
---@param clickedByColor string Colorstring of player who clicked a button
---@param clickedByColor? string Colorstring of player who clicked a button
function updateMessageColor(clickedByColor)
messageColor = Player[playerColor].seated and playerColor or clickedByColor
if Player[playerColor].seated then
messageColor = playerColor
elseif clickedByColor and Player[clickedByColor].seated then
messageColor = clickedByColor
else
messageColor = Player.getPlayers()[1].color
end
end
---------------------------------------------------------
@ -341,19 +348,19 @@ function doUpkeep(_, clickedByColor, isRightClick)
local forcedLearning = false
local rot = self.getRotation()
for _, obj in ipairs(searchAroundSelf()) do
if obj.hasTag("Temporary") == true then
if obj.hasTag("Temporary") then
discardListOfObjects({ obj })
elseif obj.hasTag("UniversalToken") == true and obj.is_face_down then
elseif obj.hasTag("UniversalToken") and obj.is_face_down then
obj.flip()
elseif obj.type == "Card" then
if obj.hasTag("DoInUpkeep") then
obj.call("doInUpkeep")
end
-- do not rotate, replenish, etc. on cards in investigator card area
if inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then
break
end
-- call the 'doInUpkeep' function for face-up objects with the respective tag
if obj.hasTag("DoInUpkeep") and not obj.is_face_down then
obj.call("doInUpkeep")
end
if obj.type == "Card" and not inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then
-- do not continue for cards in investigator card area
local cardMetadata = JSON.decode(obj.getGMNotes()) or {}
if not (obj.getVar("do_not_ready") or obj.hasTag("DoNotReady")) then
@ -384,8 +391,8 @@ function doUpkeep(_, clickedByColor, isRightClick)
if cardMetadata.uses ~= nil and self.positionToLocal(obj.getPosition()).x > -1 and not obj.is_face_down then
tokenManagerApi.maybeReplenishCard(obj, cardMetadata.uses, self)
end
elseif obj.type == "Deck" and forcedLearning == false then
-- check decks for forced learning
elseif obj.type == "Deck" and not obj.is_face_down and not forcedLearning then
-- check face up decks for forced learning
for _, deepObj in ipairs(obj.getObjects()) do
local cardMetadata = JSON.decode(deepObj.gm_notes) or {}
if cardMetadata.id == "08031" then
@ -1265,20 +1272,25 @@ end
-- investigator ID grabbing and skill tracker
---------------------------------------------------------
-- updates the internal investigator id and action tokens if an investigator card is detected
-- updates the internal investigator data and performs additional operations if an investigator card is detected
---@param card tts__Object Card that might be an investigator
function maybeUpdateActiveInvestigator(card)
-- don't continue if this card is not in the investigator area
if not inArea(self.positionToLocal(card.getPosition()), INVESTIGATOR_AREA) then return end
local notes = JSON.decode(card.getGMNotes())
local extraToken
-- get metadata
local notes = JSON.decode(card.getGMNotes()) or {}
if notes ~= nil and notes.type == "Investigator" and notes.id ~= nil then
-- don't continue for cards without proper metadata
if notes.type ~= "Investigator" or notes.id == nil then return end
-- don't continue if this is already the active investigator
if notes.id == activeInvestigatorData.id then return end
-- extract relevant data from the metadata
activeInvestigatorData.class = notes.class
activeInvestigatorData.id = notes.id
activeInvestigatorData.miniId = getMiniId(notes.id)
extraToken = notes.extraToken
ownedObjects.InvestigatorSkillTracker.call("updateStats", {
notes.willpowerIcons,
notes.intellectIcons,
@ -1286,15 +1298,8 @@ function maybeUpdateActiveInvestigator(card)
notes.agilityIcons
})
updateTexture()
elseif activeInvestigatorData.id ~= "00000" then
activeInvestigatorData.class = "Neutral"
activeInvestigatorData.id = "00000"
activeInvestigatorData.miniId = "00000-m"
ownedObjects.InvestigatorSkillTracker.call("updateStats", { 1, 1, 1, 1 })
updateTexture()
else
return
end
newInvestigatorCallback(notes.id)
-- set proper scale for investigators
local cardData = card.getData()
@ -1322,10 +1327,10 @@ function maybeUpdateActiveInvestigator(card)
end
-- spawn additional token (maybe specific for investigator)
if extraToken and extraToken ~= "None" then
if notes.extraToken and notes.extraToken ~= "None" then
-- spawn tokens (split string by "|")
local count = { action = 0, ability = 0 }
for str in string.gmatch(extraToken, "([^|]+)") do
for str in string.gmatch(notes.extraToken, "([^|]+)") do
local type = "action"
if str == "FreeTrigger" or str == "Reaction" then
type = "ability"
@ -1344,6 +1349,55 @@ function maybeUpdateActiveInvestigator(card)
end
end
-- does something for specific investigators when they are loaded
function newInvestigatorCallback(newId)
updateMessageColor()
-- get position/rotation for maybe spawned object
local pos = zones.getZonePosition(playerColor, "SetAside7")
local rot = self.getRotation()
-- remove existing object that was placed for a specific investigator
local obj = guidReferenceApi.getObjectByOwnerAndType(playerColor, "InvestigatorSpecifics")
if obj ~= nil then
obj.destruct()
guidReferenceApi.editIndex(playerColor, "InvestigatorSpecifics")
end
if newId == "01005-p" or newId == "01005-pf" then
-- parallel Wendy Adams
printToColor("Wendy Adams: There's a Game Key to add sealing options to any card:" ..
" Top menu bar > Options > Game Keys", messageColor)
elseif newId == "06003" then
-- Tony Morgan
local spawnedObj = spawnObjectData({ data = tokenManagerApi.getDataForInfiniteBag("bounty", pos, rot) })
guidReferenceApi.editIndex(playerColor, "InvestigatorSpecifics", spawnedObj.getGUID())
printToColor("Tony Morgan: Spawned an infinite bag of bounty tokens near your playermat.", messageColor)
elseif newId == "08004" then
-- Norman Withers
printToColor("At the start of the game flip the top card of your deck manually " ..
"and then the mod should keep it flipped throughout the game.", messageColor)
elseif newId == "09015" then
-- Darrell Simmons
local spawnedObj = spawnObjectData({ data = tokenManagerApi.getDataForInfiniteBag("evidence", pos, rot) })
guidReferenceApi.editIndex(playerColor, "InvestigatorSpecifics", spawnedObj.getGUID())
printToColor("Darrell Simons: Spawned an infinite bag of evidence tokens near your playermat.", messageColor)
elseif newId == "89001" then
-- Subject 5U-21
local sourceBag = guidReferenceApi.getObjectByOwnerAndType("Mythos", "OptionPanelSource")
for _, objData in ipairs(sourceBag.getData().ContainedObjects) do
if objData["Nickname"] == "Subject 5U-21 Helper" then
objData["Locked"] = true
local spawnedObj = spawnObjectData({ data = objData, position = pos, rotation = rot })
guidReferenceApi.editIndex(playerColor, "InvestigatorSpecifics", spawnedObj.getGUID())
break
end
end
printToColor("Subject 5U-21: Spawned a helper to track the classes of devoured cards near your playermat. " ..
"Note that this and 'Ravenous' will work with the Attachment Helper from the option panel.", messageColor)
end
end
-- returns the mini ID for the currently placed investigator
function getMiniId(baseId)
if #baseId < 16 then

View File

@ -19,6 +19,8 @@
-- SetAside4: Upgrade sheets for customizable cards
-- SetAside5: Hunch Deck for Joe Diamond
-- SetAside6: currently unused
-- SetAside7: Investigator specific object
do
local playermatApi = require("playermat/PlayermatApi")
local Zones = { }
@ -78,6 +80,7 @@ do
zoneData["White"]["SetAside5"] = { 2.78, 0, 0.042 }
zoneData["White"]["SetAside6"] = { 2.78, 0, 0.605 }
zoneData["White"]["UnderSetAside6"] = { 2.93, 0, 0.805 }
zoneData["White"]["SetAside7"] = { 2.85, 0, 1.650 }
zoneData["Orange"] = {}
zoneData["Orange"]["Investigator"] = commonZones["Investigator"]
@ -110,6 +113,7 @@ do
zoneData["Orange"]["SetAside5"] = { -2.78, 0, 0.042 }
zoneData["Orange"]["SetAside6"] = { -2.78, 0, 0.605 }
zoneData["Orange"]["UnderSetAside6"] = { -2.93, 0, 0.805 }
zoneData["Orange"]["SetAside7"] = { -2.85, 0, 1.650 }
-- Green positions are the same as White and Red the same as Orange
zoneData["Red"] = zoneData["Orange"]