Refactor upgrade sheet handling in the deck loader

- Split upgrade sheets to follow the slots/data pattern
- Factor out methods to set selections on upgrade sheets
- Factor out method to add Summoned Servitor minicard
- Add type 'UpgradeSheet' to appropriate cards
- Remove handleStartsInPlay() method and detect it as a default zone
This commit is contained in:
Buhallin 2022-11-17 01:03:58 -08:00
parent 90ed79ee96
commit d19d35a310
No known key found for this signature in database
GPG Key ID: DB3C362823852294
34 changed files with 224 additions and 89 deletions

View File

@ -0,0 +1,7 @@
{
"id": "09040-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09040-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/AlchemicalDistillationUpgradeSheet.156166.gmnotes",
"GUID": "156166",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09023-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09023-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/CustomModificationsUpgradeSheet.4104bf.gmnotes",
"GUID": "4104bf",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09059-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09059-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/DamningTestimonyUpgradeSheet.dc4a62.gmnotes",
"GUID": "dc4a62",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09041-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09041-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/EmpiricalHypothesisUpgradeSheet.0c46a7.gmnotes",
"GUID": "0c46a7",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09060-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09060-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/FriendsinLowPlacesUpgradeSheet.9fb3b9.gmnotes",
"GUID": "9fb3b9",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09101-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09101-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/GrizzledUpgradeSheet.ef8f08.gmnotes",
"GUID": "ef8f08",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09061-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09061-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/HonedInstinctUpgradeSheet.ba0e34.gmnotes",
"GUID": "ba0e34",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09021-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09021-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/HuntersArmorUpgradeSheet.d2d01b.gmnotes",
"GUID": "d2d01b",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09119-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09119-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/HyperphysicalShotcasterUpgradeSheet.a4eec2.gmnotes",
"GUID": "a4eec2",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09079-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09079-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/LivingLinkUpgradeSheet.19a05b.gmnotes",
"GUID": "19a05b",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09100-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09100-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/MakeshiftTrapUpgradeSheet.64dfce.gmnotes",
"GUID": "64dfce",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09099-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09099-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/PocketMultiToolUpgradeSheet.d706e7.gmnotes",
"GUID": "d706e7",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09081-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09081-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/PowerWordUpgradeSheet.0d9481.gmnotes",
"GUID": "0d9481",
"Grid": true,
"GridProjection": false,

View File

@ -24,7 +24,6 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"01501-m\",\n \"type\": \"Minicard\",\n \"traits\": \"\"\n}",
"GMNotes_path": "AllPlayerCards.15bb07/RolandBanks.f8cea5.gmnotes",
"GUID": "f8cea5",
"Grid": true,

View File

@ -0,0 +1,7 @@
{
"id": "09022-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09022-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/RunicAxeUpgradeSheet.be427d.gmnotes",
"GUID": "be427d",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09080-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09080-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/SummonedServitorUpgradeSheet.5397a6.gmnotes",
"GUID": "5397a6",
"Grid": true,
"GridProjection": false,

View File

@ -0,0 +1,7 @@
{
"id": "09042-c",
"type": "UpgradeSheet",
"traits": "",
"permanent": false,
"weakness": false
}

View File

@ -24,7 +24,7 @@
},
"Description": "",
"DragSelectable": true,
"GMNotes": "{\n \"id\": \"09042-c\",\n \"traits\": \"\",\n \"permanent\": false,\n \"weakness\": false\n}",
"GMNotes_path": "AllPlayerCards.15bb07/TheRavenQuillUpgradeSheet.23b96a.gmnotes",
"GUID": "23b96a",
"Grid": true,
"GridProjection": false,

View File

@ -147,6 +147,8 @@ local function onDeckResult(deck, playerColor, configuration)
local slots = deck.slots
maybeDrawRandomWeakness(slots, playerColor, configuration)
maybeAddInvestigatorCards(deck, slots)
maybeAddCustomizeUpgradeSheets(slots, configuration)
maybeAddSummonedServitor(slots)
extractBondedCards(slots, configuration)
checkTaboos(deck.taboo_id, slots, playerColor, configuration)
@ -171,8 +173,8 @@ local function onDeckResult(deck, playerColor, configuration)
local customizations = {}
if meta then customizations = JSON.decode(deck.meta) end
loadCards(slots, deck.investigator_code, playerColor, commandManager,
configuration, results.configuration, customizations)
loadCards(slots, deck.investigator_code, customizations, playerColor, commandManager,
configuration, results.configuration)
end
-- Checks to see if the slot list includes the random weakness ID. If it does,
@ -224,6 +226,27 @@ function maybeAddInvestigatorCards(deck, slots)
end
end
function maybeAddCustomizeUpgradeSheets(slots, configuration)
local allCardsBag = getObjectFromGUID(configuration.card_bag_guid)
for cardId, _ in pairs(slots) do
-- upgrade sheets for customizable cards
local upgradesheet = allCardsBag.call("getCardById", { id = cardId .. "-c" })
if upgradesheet ~= nil then
slots[cardId.."-c"] = 1
end
end
end
function maybeAddSummonedServitor(slots)
for cardId, cardCount in pairs(slots) do
-- spawn additional minicard for 'Summoned Servitor'
if cardId == "09080" then
slots["09080-m"] = cardCount
return
end
end
end
-- Process the slot list and looks for any cards which are bonded to those in the deck. Adds those cards to the slot list.
---@param slots: The slot list for cards in this deck. Table key is the cardId, value is the number of those cards which will be spawned
---@param configuration: The API configuration object
@ -276,10 +299,14 @@ end
---@param cardMetadata: Table of card metadata. Metadata fields type and permanent are required; all others are optional.
---@return: Zone name such as "Deck", "SetAside1", etc. See Zones object documentation for a list of valid zones.
function getDefaultCardZone(cardMetadata)
if cardMetadata.type == "Investigator" then
if (cardMetadata.id == "09080-m") then
return "SetAside6"
elseif cardMetadata.type == "Investigator" then
return "Investigator"
elseif cardMetadata.type == "Minicard" then
return "Minicard"
elseif cardMetadata.type == "UpgradeSheet" then
return "SetAside4"
elseif cardMetadata.permanent then
return "SetAside1"
elseif bondedList[cardMetadata.id] then
@ -300,10 +327,10 @@ end
-- Investigator cards should already be added to the slots list if they
-- should be spawned, but this value is separate to check for special
-- handling for certain investigators
---@param customizations: ArkhamDB data for customizations on customizable cards
---@param playerColor String Color name of the player mat to place this deck on (e.g. "Red")
---@param configuration: Loader configuration object
---@param customizations: ArkhamDB data for customizations on customizable cards
function loadCards(slots, investigatorId, playerColor, commandManager, configuration, command_config, customizations)
function loadCards(slots, investigatorId, customizations, playerColor, commandManager, configuration, command_config)
function coinside()
local allCardsBag = getObjectFromGUID(configuration.card_bag_guid)
local yPos = {}
@ -316,73 +343,6 @@ function loadCards(slots, investigatorId, playerColor, commandManager, configura
table.insert(cardsToSpawn, { data = card.data, metadata = card.metadata, zone = cardZone })
end
-- upgrade sheets for customizable cards
local upgradesheet = allCardsBag.call("getCardById", { id = cardId .. "-c" })
if upgradesheet ~= nil then
-- update metadata for spawned upgrade sheets
local upgrades = customizations["cus_" .. cardId]
if upgrades ~= nil then
-- initialize tables
-- markedBoxes: contains the amount of markedBoxes (left to right) per row (starting at row 1)
-- inputValues: contains the amount of inputValues per row (starting at row 0)
local markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
local inputValues = {}
local index_xp = {}
-- get the index and xp values (looks like this: X|X,X|X, ..)
for str in string.gmatch(customizations["cus_" .. cardId], "([^,]+)") do
table.insert(index_xp, str)
end
-- split each pair and assign it to the proper position in markedBoxes
if (customizationRowsWithFields[cardId] ~= nil) then
for i = 1, customizationRowsWithFields[cardId].inputCount do
table.insert(inputValues, "")
end
end
local inputCount = 0
for _, entry in ipairs(index_xp) do
local counter = 0
local index = 0
-- if found number is 0, then only get inputvalue
for str in string.gmatch(entry, "([^|]+)") do
counter = counter + 1
if counter == 1 then
index = tonumber(str) + 1
elseif counter == 2 then
markedBoxes[index] = tonumber(str)
elseif counter == 3 and str ~= "" then
if (cardId == "09042") then
inputValues[customizationRowsWithFields[cardId].inputMap[index]] =
convertRavenQuillSelections(str)
else
inputValues[customizationRowsWithFields[cardId].inputMap[index]] = str
end
end
end
end
-- remove first entry in markedBoxes if row 0 has textbox
if customizationRowsWithFields[cardId] ~= nil
and customizationRowsWithFields[cardId].inputCount > 0 then
table.remove(markedBoxes, 1)
end
-- write the loaded values to the save_data of the sheets
upgradesheet.data["LuaScriptState"] = JSON.encode({ markedBoxes, inputValues })
table.insert(cardsToSpawn, { data = upgradesheet.data, metadata = upgradesheet.metadata, zone = "SetAside4" })
end
end
-- spawn additional minicard for 'Summoned Servitor'
if cardId == "09080" then
local servitor = allCardsBag.call("getCardById", { id = "09080-m" })
table.insert(cardsToSpawn, { data = servitor.data, metadata = servitor.metadata, zone = "SetAside6" })
end
slots[cardId] = 0
end
end
@ -397,6 +357,7 @@ function loadCards(slots, investigatorId, playerColor, commandManager, configura
handleAncestralKnowledge(cardsToSpawn)
handleUnderworldMarket(cardsToSpawn, playerColor)
handleHunchDeck(investigatorId, cardsToSpawn, playerColor)
handleCustomizableUpgrades(cardsToSpawn, customizations)
-- Split the card list into separate lists for each zone
local zoneDecks = buildZoneLists(cardsToSpawn)
@ -650,6 +611,69 @@ function handleHunchDeck(investigatorId, cardList, playerColor)
end
end
function handleCustomizableUpgrades(cardList, customizations)
for _, card in ipairs(cardList) do
if card.metadata.type == "UpgradeSheet" then
local baseId = string.sub(card.metadata.id, 1, 5)
local upgrades = customizations["cus_" .. baseId]
log(upgrades)
log(baseId)
if upgrades ~= nil then
-- initialize tables
-- markedBoxes: contains the amount of markedBoxes (left to right) per row (starting at row 1)
-- inputValues: contains the amount of inputValues per row (starting at row 0)
local markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
local inputValues = {}
local index_xp = {}
-- get the index and xp values (looks like this: X|X,X|X, ..)
for str in string.gmatch(customizations["cus_" .. baseId], "([^,]+)") do
table.insert(index_xp, str)
end
-- split each pair and assign it to the proper position in markedBoxes
if (customizationRowsWithFields[baseId] ~= nil) then
for i = 1, customizationRowsWithFields[baseId].inputCount do
table.insert(inputValues, "")
end
end
local inputCount = 0
for _, entry in ipairs(index_xp) do
local counter = 0
local index = 0
-- if found number is 0, then only get inputvalue
for str in string.gmatch(entry, "([^|]+)") do
counter = counter + 1
if counter == 1 then
index = tonumber(str) + 1
elseif counter == 2 then
markedBoxes[index] = tonumber(str)
elseif counter == 3 and str ~= "" then
if (baseId == "09042") then
inputValues[customizationRowsWithFields[baseId].inputMap[index]] =
convertRavenQuillSelections(str)
else
inputValues[customizationRowsWithFields[baseId].inputMap[index]] = str
end
end
end
end
-- remove first entry in markedBoxes if row 0 has textbox
if customizationRowsWithFields[baseId] ~= nil
and customizationRowsWithFields[baseId].inputCount > 0 then
table.remove(markedBoxes, 1)
end
-- write the loaded values to the save_data of the sheets
card.data["LuaScriptState"] = JSON.encode({ markedBoxes, inputValues })
end
end
end
end
-- Test method. Loads all decks which were submitted to ArkhamDB on a given date window.
function testLoadLotsOfDecks()
local configuration = getConfiguration()