Merge pull request #726 from argonui/weakness-by-trait
Added right-click function to specify a trait for RBW button
This commit is contained in:
commit
07263d9d9d
@ -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 traits? string Trait(s) to use as filter
|
||||
---@return table: Array of weakness IDs which are valid to choose from
|
||||
function buildAvailableWeaknesses()
|
||||
function buildAvailableWeaknesses(traits)
|
||||
local weaknessesInPlay = {}
|
||||
local allObjects = getAllObjects()
|
||||
for _, object in ipairs(allObjects) do
|
||||
@ -399,7 +400,32 @@ function buildAvailableWeaknesses()
|
||||
if (weaknessesInPlay[weaknessId] ~= nil and weaknessesInPlay[weaknessId] > 0) then
|
||||
weaknessesInPlay[weaknessId] = weaknessesInPlay[weaknessId] - 1
|
||||
else
|
||||
if traits then
|
||||
-- split the string into separate traits (separated by "|")
|
||||
local allowedTraits = {}
|
||||
for str in traits:gmatch("([^|]+)") do
|
||||
-- remove dots
|
||||
str = str:gsub("[%.]", "")
|
||||
|
||||
-- remove leading and trailing whitespace
|
||||
str = str:match("^%s*(.-)%s*$")
|
||||
|
||||
-- make sure string ends with a dot
|
||||
str = string.lower(str .. ".")
|
||||
table.insert(allowedTraits, str)
|
||||
end
|
||||
|
||||
-- make sure the trait is present on the weakness
|
||||
local card = cardIdIndex[weaknessId]
|
||||
for _, allowedTrait in ipairs(allowedTraits) do
|
||||
if string.contains(string.lower(card.metadata.traits), allowedTrait) then
|
||||
table.insert(availableWeaknesses, weaknessId)
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
table.insert(availableWeaknesses, weaknessId)
|
||||
end
|
||||
end
|
||||
end
|
||||
return availableWeaknesses
|
||||
|
@ -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 traits? string Trait(s) to use as filter
|
||||
---@return table: Array of weakness IDs which are valid to choose from
|
||||
AllCardsBagApi.buildAvailableWeaknesses = function(traits)
|
||||
return returnCopyOfList(getAllCardsBag().call("buildAvailableWeaknesses", traits))
|
||||
end
|
||||
|
||||
AllCardsBagApi.getUniqueWeaknesses = function()
|
||||
return returnCopyOfList(getAllCardsBag().call("getUniqueWeaknesses"))
|
||||
end
|
||||
|
@ -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
|
||||
@ -775,13 +778,32 @@ function spawnWeaknesses()
|
||||
})
|
||||
end
|
||||
|
||||
function spawnRandomWeakness()
|
||||
function spawnRandomWeakness(_, playerColor, isRightClick)
|
||||
prepareToPlaceCards()
|
||||
|
||||
if not isRightClick then
|
||||
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
||||
if (weaknessId == nil) then
|
||||
if weaknessId == nil then
|
||||
broadcastToAll("All basic weaknesses are in play!", { 0.9, 0.2, 0.2 })
|
||||
return
|
||||
else
|
||||
spawnSingleWeakness(weaknessId)
|
||||
end
|
||||
else
|
||||
Player[playerColor].showInputDialog("Specify a trait for the weakness (split multiple eligible traits with '|'):", 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 },
|
||||
|
Loading…
Reference in New Issue
Block a user