Bug Fixes & Improvements

Added support for Additional Player Cards bag (still needs latency improvements), custom trauma getting, importing on collision, and fixed the tour bug
This commit is contained in:
Entrox-Licher 2024-01-08 17:29:24 -05:00
parent 8dcbce1542
commit f53f7fdba0
2 changed files with 87 additions and 68 deletions

View File

@ -53,5 +53,14 @@
"scaleZ": 3.38
},
"Value": 0,
"XmlUI": ""
"XmlUI": "",
"AttachedSnapPoints": [
{
"Position": {
"x": -0.95,
"y": 0.2,
"z": 0.01
}
}
]
}

View File

@ -47,23 +47,12 @@ local campaignTokenData = {
local COLORS = { "White", "Orange", "Green", "Red" }
function onLoad()
self.createButton({
click_function = "findCampaignFromToken",
function_owner = self,
label = "Import",
tooltip = "Load in a campaign save from a token!\n\n(Token can be anywhere on the table, but ensure there is only 1!)",
position = { x = -1, y = 0.2, z = 0 },
font_size = 400,
width = 1400,
height = 600,
scale = { 0.5, 1, 0.5 },
})
self.createButton({
click_function = "createCampaignToken",
function_owner = self,
label = "Export",
tooltip = "Create a campaign save token!\n\n(Ensure all chaos tokens have been unsealed!)",
position = { x = 1, y = 0.2, z = 0 },
tooltip = "Create a campaign save token!",
position = { x = -1, y = 0.2, z = 0 },
font_size = 400,
width = 1400,
height = 600,
@ -75,20 +64,20 @@ end
-- main import functions (split up to allow for Wait conditions)
---------------------------------------------------------
function onCollisionEnter(info)
local objectData = info.collision_object.getData()
if info.collision_object.hasTag("ImporterToken") then
findCampaignFromToken(info.collision_object)
end
end
-- Identifies import token, determines campaign box and downloads it (if needed)
function findCampaignFromToken(_, _, _)
local coin = nil
local coinObjects = getObjectsWithTag("ImporterToken")
if #coinObjects == 0 then
broadcastToAll("Could not find importer token", Color.Red)
elseif #coinObjects > 1 then
broadcastToAll("More than 1 importer token found. Please delete all but 1 importer token", Color.Yellow)
else
coin = coinObjects[1]
function findCampaignFromToken(coin)
broadcastToAll("Campaign Import Initiated")
local importData = JSON.decode(coin.getGMNotes())
campaignBoxGUID = importData["box"]
coin.destruct()
campaignBoxGUID = importData["box"]
local campaignBox = getObjectFromGUID(campaignBoxGUID)
if campaignBox.type == "Generic" then
campaignBox.call("buttonClick_download")
@ -112,7 +101,6 @@ function findCampaignFromToken(_, _, _)
2,
function() broadcastToAll("Error loading campaign box") end
)
end
end
-- After box has been downloaded, places content on table
@ -132,6 +120,11 @@ function createCampaignFromToken(importData)
findUniqueObjectWithTag("CampaignLog").destruct()
spawnObjectData({ data = importData["log"] })
if importData["additionalIndex"] then
findUniqueObjectWithTag("AllCardsHotfix").destruct()
spawnObjectData({data = importData["additionalIndex"]})
end
chaosBagApi.setChaosBagState(importData["bag"])
-- populate trauma values
@ -155,7 +148,7 @@ function createCampaignFromToken(importData)
-- Condition function that is called continiously until returs true or timeout is reached
function() return guide.Book.setPage(importData["guide"]) end,
-- Amount of time in seconds until the Wait times out
1,
2,
-- Called if the Wait times out
function() log("Campaign Guide import failed!") end
)
@ -165,7 +158,9 @@ function createCampaignFromToken(importData)
-- destroy Tour Starter token
local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter")
if tourStarter then
tourStarter.destruct()
end
-- restore PlayArea image
playAreaApi.updateSurface(importData["playmat"])
@ -175,9 +170,6 @@ end
-- Creates a campaign token with save data encoded into GM Notes based on the current state of the table
function createCampaignToken(_, playerColor, _)
-- clean up chaos tokens
blessCurseApi.removeAll(playerColor)
chaosBagApi.releaseAllSealedTokens(playerColor)
-- find active campaign
local campaignBox
@ -202,20 +194,20 @@ function createCampaignToken(_, playerColor, _)
return
end
local traumaValues = {
0, 0, 0, 0,
0, 0, 0, 0
}
local counterData = campaignLog.getVar("ref_buttonData")
if counterData ~= nil then
local additionalIndex = findUniqueObjectWithTag("AllCardsHotfix")
local traumaValues = { }
local trauma = campaignLog.getVar("returnTrauma")
if trauma ~= nil then
printToAll("Trauma values found in campaign log!", "Green")
for i = 1, 10, 3 do
traumaValues[1 + (i - 1) / 3] = counterData.counter[i].value
traumaValues[5 + (i - 1) / 3] = counterData.counter[i + 1].value
trauma = campaignLog.call("returnTrauma")
for _, val in ipairs(trauma) do
table.insert(traumaValues, val)
end
else
printToAll("Trauma values could not be found in campaign log!", "Yellow")
printToAll("Default values for health and sanity loaded.", "Yellow")
return
end
local campaignGuide = findUniqueObjectWithTag("CampaignGuide")
@ -224,6 +216,10 @@ function createCampaignToken(_, playerColor, _)
return
end
-- clean up chaos tokens
blessCurseApi.removeAll(playerColor)
chaosBagApi.releaseAllSealedTokens(playerColor)
local campaignData = {
box = campaignBox.getGUID(),
log = campaignLog.getData(),
@ -231,9 +227,10 @@ function createCampaignToken(_, playerColor, _)
trauma = traumaValues,
decks = deckImporterApi.getUiState(),
clueCount = playAreaApi.getInvestigatorCount(),
guide = campaignGuide.Book.getPage(),
playmat = playAreaApi.getSurface(),
options = optionPanelApi.getOptions(),
playmat = playAreaApi.getSurface()
guide = campaignGuide.Book.getPage(),
additionalIndex = additionalIndex.getData()
}
campaignTokenData.GMNotes = JSON.encode(campaignData)
campaignTokenData.Nickname = os.date("%b %d ") .. campaignBox.getName() .. " Save"
@ -263,3 +260,16 @@ function setTrauma(trauma)
playmatApi.updateCounter(COLORS[i], "HorrorCounter", trauma[i + 4])
end
end
-- gets data from campaign log if possible
function loadTrauma(campaignLog)
local trauma = campaignLog.getVar("returnTrauma")
if trauma ~= nil then
printToAll("Trauma values found in campaign log!", "Green")
trauma = campaignLog.call("returnTrauma")
return trauma
else
return nil
end
end