Merge pull request #224 from argonui/revised-investigator-bugfix

Deckimporter: Updated handling for parallel, revised and promo investigators
This commit is contained in:
Chr1Z 2023-04-07 20:30:11 +02:00 committed by GitHub
commit aa9632e7d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 19 deletions

View File

@ -77,7 +77,7 @@ do
return false, "Deck not found!" return false, "Deck not found!"
end end
return true, JSON.decode(status.text) return true, json
end) end)
deck:with(internal.onDeckResult, playerColor, loadNewest, loadInvestigators, callback) deck:with(internal.onDeckResult, playerColor, loadNewest, loadInvestigators, callback)
@ -139,8 +139,9 @@ do
-- investigator may have bonded cards or taboo entries, and should be present -- investigator may have bonded cards or taboo entries, and should be present
local slots = deck.slots local slots = deck.slots
internal.maybeDrawRandomWeakness(slots, playerColor) internal.maybeDrawRandomWeakness(slots, playerColor)
local loadAltInvestigator = "normal"
if loadInvestigators then if loadInvestigators then
internal.addInvestigatorCards(deck, slots) loadAltInvestigator = internal.addInvestigatorCards(deck, slots)
end end
internal.maybeAddCustomizeUpgradeSheets(slots) internal.maybeAddCustomizeUpgradeSheets(slots)
internal.maybeAddSummonedServitor(slots) internal.maybeAddSummonedServitor(slots)
@ -149,13 +150,12 @@ do
internal.checkTaboos(deck.taboo_id, slots, playerColor) internal.checkTaboos(deck.taboo_id, slots, playerColor)
-- get upgrades for customizable cards -- get upgrades for customizable cards
local meta = deck.meta
local customizations = {} local customizations = {}
if meta then if deck.meta then
customizations = JSON.decode(meta) customizations = JSON.decode(deck.meta)
end end
callback(slots, deck.investigator_code, bondList, customizations, playerColor) callback(slots, deck.investigator_code, bondList, customizations, playerColor, loadAltInvestigator)
end end
-- Checks to see if the slot list includes the random weakness ID. If it does, -- Checks to see if the slot list includes the random weakness ID. If it does,
@ -186,25 +186,54 @@ do
---@param deck Table The processed ArkhamDB deck response ---@param deck Table The processed ArkhamDB deck response
---@param slots Table The slot list for cards in this deck. Table key is the cardId, value is the ---@param slots Table The slot list for cards in this deck. Table key is the cardId, value is the
--- number of those cards which will be spawned --- number of those cards which will be spawned
---@return string: Contains the name of the art that should be loaded ("normal", "promo" or "revised")
internal.addInvestigatorCards = function(deck, slots) internal.addInvestigatorCards = function(deck, slots)
local investigatorId = deck.investigator_code local investigatorId = deck.investigator_code
slots[investigatorId .. "-m"] = 1 slots[investigatorId .. "-m"] = 1
local deckMeta = JSON.decode(deck.meta) local deckMeta = JSON.decode(deck.meta)
local parallelFront = deckMeta ~= nil and deckMeta.alternate_front ~= nil and deckMeta.alternate_front ~= "" -- handling alternative investigator art and parallel investigators
local parallelBack = deckMeta ~= nil and deckMeta.alternate_back ~= nil and deckMeta.alternate_back ~= "" local loadAltInvestigator = "normal"
if parallelFront and parallelBack then if deckMeta ~= nil then
investigatorId = investigatorId .. "-p" local altFrontId = tonumber(deckMeta.alternate_front) or 0
elseif parallelFront then local altBackId = tonumber(deckMeta.alternate_back) or 0
local alternateNum = tonumber(deckMeta.alternate_front) local altArt = { front = "normal", back = "normal" }
if alternateNum >= 01501 and alternateNum <= 01506 then
investigatorId = investigatorId .. "-r" -- translating front ID
else if altFrontId > 90000 and altFrontId < 90006 then
investigatorId = investigatorId .. "-pf" altArt.front = "parallel"
elseif altFrontId > 01500 and altFrontId < 01506 then
altArt.front = "revised"
elseif altFrontId > 98000 then
altArt.front = "promo"
end
-- translating back ID
if altBackId > 90000 and altBackId < 90006 then
altArt.back = "parallel"
elseif altBackId > 01500 and altBackId < 01506 then
altArt.back = "revised"
elseif altBackId > 98000 then
altArt.back = "promo"
end
-- updating investigatorID based on alt investigator selection
-- precedence: parallel > promo > revised
if altArt.front == "parallel" then
if altArt.back == "parallel" then
investigatorId = investigatorId .. "-p"
else
investigatorId = investigatorId .. "-pf"
end
elseif altArt.back == "parallel" then
investigatorId = investigatorId .. "-pb"
elseif altArt.front == "promo" or altArt.back == "promo" then
loadAltInvestigator = "promo"
elseif altArt.front == "revised" or altArt.back == "revised" then
loadAltInvestigator = "revised"
end end
elseif parallelBack then
investigatorId = investigatorId .. "-pb"
end end
slots[investigatorId] = 1 slots[investigatorId] = 1
return loadAltInvestigator
end end
-- Process the card list looking for the customizable cards, and add their upgrade sheets if needed -- Process the card list looking for the customizable cards, and add their upgrade sheets if needed

View File

@ -104,7 +104,8 @@ end
-- from a parent bonded card. -- from a parent bonded card.
---@param customizations String ArkhamDB data for customizations on customizable cards ---@param customizations String 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 playerColor String Color name of the player mat to place this deck on (e.g. "Red")
function loadCards(slots, investigatorId, bondedList, customizations, playerColor) ---@param loadAltInvestigator String Contains the name of alternative art for the investigator ("normal", "revised" or "promo")
function loadCards(slots, investigatorId, bondedList, customizations, playerColor, loadAltInvestigator)
function coinside() function coinside()
local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID) local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID)
local yPos = {} local yPos = {}
@ -148,6 +149,8 @@ function loadCards(slots, investigatorId, bondedList, customizations, playerColo
callback = function(deck) deck.spread(spreadDistance) end callback = function(deck) deck.spread(spreadDistance) end
elseif zone == "Deck" then elseif zone == "Deck" then
callback = function(deck) deckSpawned(deck, playerColor) end callback = function(deck) deckSpawned(deck, playerColor) end
elseif zone == "Investigator" or zone == "Minicard" then
callback = function(card) loadAltArt(card, loadAltInvestigator) end
end end
Spawner.spawnCards( Spawner.spawnCards(
zoneCards, zoneCards,
@ -419,6 +422,51 @@ function handleCustomizableUpgrades(cardList, customizations)
end end
end end
-- Callback function for investigator cards and minicards to set the correct state for alt art
---@param card Object Card which needs to be set the state for
---@param loadAltInvestigator String Contains the name of alternative art for the investigator ("normal", "revised" or "promo")
function loadAltArt(card, loadAltInvestigator)
if loadAltInvestigator == "normal" then return end
-- lookup correct stateId for investigator and alt art state
local baseId = string.gsub(JSON.decode(card.getGMNotes()).id, "-m", "")
local stateIdTable = {}
-- Roland Banks
stateIdTable["01001"] = {}
stateIdTable["01001"]["revised"] = 2
stateIdTable["01001"]["promo"] = 3
-- Daisy Walker
stateIdTable["01002"] = {}
stateIdTable["01002"]["revised"] = 2
-- "Skids" O'Toole
stateIdTable["01003"] = {}
stateIdTable["01003"]["revised"] = 2
-- Agnes Baker
stateIdTable["01004"] = {}
stateIdTable["01004"]["revised"] = 2
-- Wendy Adams
stateIdTable["01005"] = {}
stateIdTable["01005"]["revised"] = 2
-- Jenny Barnes
stateIdTable["02003"] = {}
stateIdTable["02003"]["promo"] = 2
-- Carolyn Fern
stateIdTable["05001"] = {}
stateIdTable["05001"]["promo"] = 2
-- Dexter Drake
stateIdTable["07004"] = {}
stateIdTable["07004"]["promo"] = 2
-- Silas Marsh
stateIdTable["07005"] = {}
stateIdTable["07005"]["promo"] = 2
-- Norman Withers
stateIdTable["08004"] = {}
stateIdTable["08004"]["promo"] = 2
card.setState(stateIdTable[baseId][loadAltInvestigator])
end
function log(message) function log(message)
if DEBUG then print(message) end if DEBUG then print(message) end
end end