added right-click function to specify a trait
This commit is contained in:
parent
8ac0c7a48a
commit
fd9e7e6c86
@ -380,8 +380,9 @@ end
|
|||||||
|
|
||||||
-- Constructs a list of available basic weaknesses by starting with the full pool of basic
|
-- 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
|
-- 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
|
---@return table: Array of weakness IDs which are valid to choose from
|
||||||
function buildAvailableWeaknesses()
|
function buildAvailableWeaknesses(trait)
|
||||||
local weaknessesInPlay = {}
|
local weaknessesInPlay = {}
|
||||||
local allObjects = getAllObjects()
|
local allObjects = getAllObjects()
|
||||||
for _, object in ipairs(allObjects) do
|
for _, object in ipairs(allObjects) do
|
||||||
@ -399,7 +400,15 @@ function buildAvailableWeaknesses()
|
|||||||
if (weaknessesInPlay[weaknessId] ~= nil and weaknessesInPlay[weaknessId] > 0) then
|
if (weaknessesInPlay[weaknessId] ~= nil and weaknessesInPlay[weaknessId] > 0) then
|
||||||
weaknessesInPlay[weaknessId] = weaknessesInPlay[weaknessId] - 1
|
weaknessesInPlay[weaknessId] = weaknessesInPlay[weaknessId] - 1
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
return availableWeaknesses
|
return availableWeaknesses
|
||||||
|
@ -25,7 +25,7 @@ do
|
|||||||
return getAllCardsBag().call("getCardById", { id = id })
|
return getAllCardsBag().call("getCardById", { id = id })
|
||||||
end
|
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
|
-- 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.
|
-- or the indexes are rebuilt, which will refresh the list to include all weaknesses.
|
||||||
---@return string: ID of the selected weakness
|
---@return string: ID of the selected weakness
|
||||||
@ -80,6 +80,14 @@ do
|
|||||||
return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", { cycle = cycle, sortByMetadata = sortByMetadata }))
|
return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", { cycle = cycle, sortByMetadata = sortByMetadata }))
|
||||||
end
|
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()
|
AllCardsBagApi.getUniqueWeaknesses = function()
|
||||||
return returnCopyOfList(getAllCardsBag().call("getUniqueWeaknesses"))
|
return returnCopyOfList(getAllCardsBag().call("getUniqueWeaknesses"))
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,8 @@ local allCardsBagApi = require("playercards/AllCardsBagApi")
|
|||||||
local arkhamDb = require("arkhamdb/ArkhamDb")
|
local arkhamDb = require("arkhamdb/ArkhamDb")
|
||||||
local spawnBag = require("playercards/SpawnBag")
|
local spawnBag = require("playercards/SpawnBag")
|
||||||
|
|
||||||
|
local lastWeaknessTrait = "Madness"
|
||||||
|
|
||||||
-- Size and position information for the three rows of class buttons
|
-- Size and position information for the three rows of class buttons
|
||||||
local CIRCLE_BUTTON_SIZE = 250
|
local CIRCLE_BUTTON_SIZE = 250
|
||||||
local CLASS_BUTTONS_X_OFFSET = 0.1325
|
local CLASS_BUTTONS_X_OFFSET = 0.1325
|
||||||
@ -224,9 +226,10 @@ function createWeaknessButtons()
|
|||||||
weaknessButtonParams.tooltip = "All Weaknesses"
|
weaknessButtonParams.tooltip = "All Weaknesses"
|
||||||
weaknessButtonParams.position = buttonPos
|
weaknessButtonParams.position = buttonPos
|
||||||
self.createButton(weaknessButtonParams)
|
self.createButton(weaknessButtonParams)
|
||||||
|
|
||||||
buttonPos.x = buttonPos.x + MISC_BUTTONS_X_OFFSET
|
buttonPos.x = buttonPos.x + MISC_BUTTONS_X_OFFSET
|
||||||
weaknessButtonParams.click_function = "spawnRandomWeakness"
|
weaknessButtonParams.click_function = "spawnRandomWeakness"
|
||||||
weaknessButtonParams.tooltip = "Random Basic Weakness"
|
weaknessButtonParams.tooltip = "Random Basic Weakness\nRight-click to specify a trait"
|
||||||
weaknessButtonParams.position = buttonPos
|
weaknessButtonParams.position = buttonPos
|
||||||
self.createButton(weaknessButtonParams)
|
self.createButton(weaknessButtonParams)
|
||||||
end
|
end
|
||||||
@ -361,9 +364,9 @@ function createXML(showOtherCardsButton)
|
|||||||
alignment = "MiddleLeft",
|
alignment = "MiddleLeft",
|
||||||
horizontalOverflow = "wrap",
|
horizontalOverflow = "wrap",
|
||||||
text = "• Select a group to place cards\n" ..
|
text = "• Select a group to place cards\n" ..
|
||||||
"• Copy the cards you want for your deck\n" ..
|
"• Copy the cards you want for your deck\n" ..
|
||||||
"• Select a new group to clear the placed cards and see new ones\n" ..
|
"• Select a new group to clear the placed cards and see new ones\n" ..
|
||||||
"• Clear to remove all cards"
|
"• Clear to remove all cards"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -775,13 +778,32 @@ function spawnWeaknesses()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function spawnRandomWeakness()
|
function spawnRandomWeakness(_, playerColor, isRightClick)
|
||||||
prepareToPlaceCards()
|
prepareToPlaceCards()
|
||||||
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
|
||||||
if (weaknessId == nil) then
|
if not isRightClick then
|
||||||
broadcastToAll("All basic weaknesses are in play!", { 0.9, 0.2, 0.2 })
|
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
||||||
return
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
-- spawn the random weakness
|
||||||
|
function spawnSingleWeakness(weaknessId)
|
||||||
spawnBag.spawn({
|
spawnBag.spawn({
|
||||||
name = "randomWeakness",
|
name = "randomWeakness",
|
||||||
cards = { weaknessId },
|
cards = { weaknessId },
|
||||||
|
Loading…
Reference in New Issue
Block a user