added right-click function to specify a trait

This commit is contained in:
Chr1Z93 2024-06-27 12:12:55 +02:00
parent 8ac0c7a48a
commit fd9e7e6c86
3 changed files with 51 additions and 12 deletions

View File

@ -380,8 +380,9 @@ end
-- Constructs a list of available basic weaknesses by starting with the full pool of basic
-- weaknesses then removing any which are currently in the play or deck construction areas
---@param trait? string Trait to use as filter
---@return table: Array of weakness IDs which are valid to choose from
function buildAvailableWeaknesses()
function buildAvailableWeaknesses(trait)
local weaknessesInPlay = {}
local allObjects = getAllObjects()
for _, object in ipairs(allObjects) do
@ -399,7 +400,15 @@ function buildAvailableWeaknesses()
if (weaknessesInPlay[weaknessId] ~= nil and weaknessesInPlay[weaknessId] > 0) then
weaknessesInPlay[weaknessId] = weaknessesInPlay[weaknessId] - 1
else
table.insert(availableWeaknesses, weaknessId)
if trait then
-- make sure the trait is present on the weakness
local card = cardIdIndex[weaknessId]
if string.contains(string.lower(card.metadata.traits), string.lower(trait)) then
table.insert(availableWeaknesses, weaknessId)
end
else
table.insert(availableWeaknesses, weaknessId)
end
end
end
return availableWeaknesses

View File

@ -25,7 +25,7 @@ do
return getAllCardsBag().call("getCardById", { id = id })
end
-- Gets a random basic weakness from the bag. Once a given ID has been returned it
-- 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.
---@return string: ID of the selected weakness
@ -80,6 +80,14 @@ do
return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", { cycle = cycle, sortByMetadata = sortByMetadata }))
end
-- Constructs a list of available basic weaknesses by starting with the full pool of basic
-- weaknesses then removing any which are currently in the play or deck construction areas
---@param trait? string Trait to use as filter
---@return table: Array of weakness IDs which are valid to choose from
AllCardsBagApi.buildAvailableWeaknesses = function(trait)
return returnCopyOfList(getAllCardsBag().call("buildAvailableWeaknesses", trait))
end
AllCardsBagApi.getUniqueWeaknesses = function()
return returnCopyOfList(getAllCardsBag().call("getUniqueWeaknesses"))
end

View File

@ -5,6 +5,8 @@ local allCardsBagApi = require("playercards/AllCardsBagApi")
local arkhamDb = require("arkhamdb/ArkhamDb")
local spawnBag = require("playercards/SpawnBag")
local lastWeaknessTrait = "Madness"
-- Size and position information for the three rows of class buttons
local CIRCLE_BUTTON_SIZE = 250
local CLASS_BUTTONS_X_OFFSET = 0.1325
@ -224,9 +226,10 @@ function createWeaknessButtons()
weaknessButtonParams.tooltip = "All Weaknesses"
weaknessButtonParams.position = buttonPos
self.createButton(weaknessButtonParams)
buttonPos.x = buttonPos.x + MISC_BUTTONS_X_OFFSET
weaknessButtonParams.click_function = "spawnRandomWeakness"
weaknessButtonParams.tooltip = "Random Basic Weakness"
weaknessButtonParams.tooltip = "Random Basic Weakness\nRight-click to specify a trait"
weaknessButtonParams.position = buttonPos
self.createButton(weaknessButtonParams)
end
@ -361,9 +364,9 @@ function createXML(showOtherCardsButton)
alignment = "MiddleLeft",
horizontalOverflow = "wrap",
text = "• Select a group to place cards\n" ..
"• Copy the cards you want for your deck\n" ..
"• Select a new group to clear the placed cards and see new ones\n" ..
"• Clear to remove all cards"
"• Copy the cards you want for your deck\n" ..
"• Select a new group to clear the placed cards and see new ones\n" ..
"• Clear to remove all cards"
}
}
}
@ -775,13 +778,32 @@ function spawnWeaknesses()
})
end
function spawnRandomWeakness()
function spawnRandomWeakness(_, playerColor, isRightClick)
prepareToPlaceCards()
local weaknessId = allCardsBagApi.getRandomWeaknessId()
if (weaknessId == nil) then
broadcastToAll("All basic weaknesses are in play!", { 0.9, 0.2, 0.2 })
return
if not isRightClick then
local weaknessId = allCardsBagApi.getRandomWeaknessId()
if weaknessId == nil then
broadcastToAll("All basic weaknesses are in play!", { 0.9, 0.2, 0.2 })
else
spawnSingleWeakness(weaknessId)
end
else
Player[playerColor].showInputDialog("Specify a trait for the weakness:", lastWeaknessTrait,
function(text)
lastWeaknessTrait = text
local availableWeaknesses = allCardsBagApi.buildAvailableWeaknesses(text)
if #availableWeaknesses > 0 then
spawnSingleWeakness(availableWeaknesses[math.random(#availableWeaknesses)])
else
broadcastToAll("No matching weakness available!", { 0.9, 0.2, 0.2 })
end
end)
end
end
-- spawn the random weakness
function spawnSingleWeakness(weaknessId)
spawnBag.spawn({
name = "randomWeakness",
cards = { weaknessId },