2023-08-08 12:49:31 -04:00
|
|
|
do
|
|
|
|
local AllCardsBagApi = {}
|
2023-10-18 20:55:38 +02:00
|
|
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
2023-10-02 02:05:00 +02:00
|
|
|
|
2023-10-02 13:51:10 +02:00
|
|
|
local function getAllCardsBag()
|
2023-10-18 20:55:38 +02:00
|
|
|
return guidReferenceApi.getObjectByOwnerAndType("Mythos", "AllCardsBag")
|
2023-10-02 02:05:00 +02:00
|
|
|
end
|
2023-08-08 12:49:31 -04:00
|
|
|
|
2023-08-09 12:37:45 -04:00
|
|
|
-- Returns a specific card from the bag, based on ArkhamDB ID
|
2023-09-29 13:41:43 +02:00
|
|
|
---@param id table String ID of the card to retrieve
|
|
|
|
---@return table table
|
|
|
|
-- If the indexes are still being constructed, an empty table is
|
|
|
|
-- returned. Otherwise, a single table with the following fields
|
|
|
|
-- cardData: TTS object data, suitable for spawning the card
|
|
|
|
-- cardMetadata: Table of parsed metadata
|
2023-08-24 20:04:14 -04:00
|
|
|
AllCardsBagApi.getCardById = function(id)
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("getCardById", {id = id})
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Gets a random basic weakness from the bag. Once a given ID has been returned
|
|
|
|
-- it will be removed from the list and cannot be selected again until a reload
|
|
|
|
-- occurs or the indexes are rebuilt, which will refresh the list to include all
|
|
|
|
-- weaknesses.
|
2023-09-29 13:41:43 +02:00
|
|
|
---@return id String ID of the selected weakness.
|
2023-08-09 12:37:45 -04:00
|
|
|
AllCardsBagApi.getRandomWeaknessId = function()
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("getRandomWeaknessId")
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
AllCardsBagApi.isIndexReady = function()
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("isIndexReady")
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Called by Hotfix bags when they load. If we are still loading indexes, then
|
|
|
|
-- the all cards and hotfix bags are being loaded together, and we can ignore
|
|
|
|
-- this call as the hotfix will be included in the initial indexing. If it is
|
|
|
|
-- called once indexing is complete it means the hotfix bag has been added
|
|
|
|
-- later, and we should rebuild the index to integrate the hotfix bag.
|
|
|
|
AllCardsBagApi.rebuildIndexForHotfix = function()
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("rebuildIndexForHotfix")
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Searches the bag for cards which match the given name and returns a list. Note that this is
|
|
|
|
-- an O(n) search without index support. It may be slow.
|
2023-09-29 13:41:43 +02:00
|
|
|
---@param name String or string fragment to search for names
|
|
|
|
---@param exact Boolean Whether the name match should be exact
|
2023-08-24 20:04:14 -04:00
|
|
|
AllCardsBagApi.getCardsByName = function(name, exact)
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("getCardsByName", {name = name, exact = exact})
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
AllCardsBagApi.isBagPresent = function()
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag() and true
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Returns a list of cards from the bag matching a class and level (0 or upgraded)
|
2023-09-29 13:41:43 +02:00
|
|
|
---@param class String class to retrieve ("Guardian", "Seeker", etc)
|
|
|
|
---@param upgraded Boolean true for upgraded cards (Level 1-5), false for Level 0
|
|
|
|
---@return: If the indexes are still being constructed, returns an empty table.
|
2023-08-09 12:37:45 -04:00
|
|
|
-- Otherwise, a list of tables, each with the following fields
|
|
|
|
-- cardData: TTS object data, suitable for spawning the card
|
|
|
|
-- cardMetadata: Table of parsed metadata
|
2023-08-24 20:04:14 -04:00
|
|
|
AllCardsBagApi.getCardsByClassAndLevel = function(class, upgraded)
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("getCardsByClassAndLevel", {class = class, upgraded = upgraded})
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
AllCardsBagApi.getCardsByCycle = function(cycle)
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("getCardsByCycle", cycle)
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
AllCardsBagApi.getUniqueWeaknesses = function()
|
2023-10-02 13:51:10 +02:00
|
|
|
return getAllCardsBag().call("getUniqueWeaknesses")
|
2023-08-09 12:37:45 -04:00
|
|
|
end
|
2023-08-08 12:49:31 -04:00
|
|
|
|
|
|
|
return AllCardsBagApi
|
|
|
|
end
|