Merge branch 'argonui:main' into kohaku

This commit is contained in:
dscarpac 2024-06-28 16:29:50 -05:00 committed by GitHub
commit e8e68de98a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 130 additions and 52 deletions

View File

@ -89,12 +89,12 @@
],
"Tooltip": true,
"Transform": {
"posX": 40.7253036,
"posY": 1.29860592,
"posZ": 66.7765656,
"rotX": 1.697304e-7,
"rotY": 270.0102,
"rotZ": 2.00479718e-7,
"posX": 40,
"posY": 1.3,
"posZ": 66,
"rotX": 0,
"rotY": 270,
"rotZ": 0,
"scaleX": 0.6,
"scaleY": 1,
"scaleZ": 0.6

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 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

View File

@ -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

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
@ -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 },

View File

@ -28,6 +28,9 @@ Spawner.spawnCards = function(cardList, pos, rot, sort, callback)
if card.metadata.type == "Investigator" then
table.insert(investigatorCards, card)
elseif card.metadata.type == "Minicard" then
-- set proper scale for minicards
card.data.Transform.scaleX = 0.6
card.data.Transform.scaleZ = 0.6
table.insert(miniCards, card)
else
table.insert(standardCards, card)

View File

@ -1,32 +1,31 @@
-- this script is shared between the lvl 0 and lvl 3 versions of Scroll of Secrets
local mythosAreaApi = require("core/MythosAreaApi")
local playermatApi = require("playermat/PlayermatApi")
-- get class via metadata and create context menu accordingly
function onLoad()
local notes = JSON.decode(self.getGMNotes())
if notes then
createContextMenu(notes.id)
else
print("Missing metadata for Scroll of Secrets!")
end
end
function createContextMenu(id)
if id == "05116" or id == "05116-t" then
-- get class via metadata and proceed menu accordingly:
-- lvl 0: draw 1 card from the bottom
self.addContextMenuItem("Draw bottom card", function(playerColor) contextFunc(playerColor, 1) end)
elseif id == "05188" or id == "05188-t" then
-- seeker lvl 3: draw 3 cards from the bottom
self.addContextMenuItem("Draw bottom card(s)", function(playerColor) contextFunc(playerColor, 3) end)
elseif id == "05189" or id == "05189-t" then
-- mystic lvl 3: draw 1 card from the bottom
self.addContextMenuItem("Draw bottom card", function(playerColor) contextFunc(playerColor, 1) end)
local buttonLabel = "Draw bottom card"
local amount = 1
local notes = JSON.decode(self.getGMNotes())
if notes.id == "05188" or notes.id == "05188-t" then
-- seeker lvl 3: draw 3 cards from the bottom
buttonLabel = buttonLabel .. "(s)"
amount = 3
end
self.addContextMenuItem(buttonLabel, function(playerColor) contextFunc(playerColor, amount) end)
end
function contextFunc(playerColor, amount)
local options = { "Encounter Deck" }
deckData = {}
local options = {}
-- check for encounter deck
local encounterDeck = mythosAreaApi.getEncounterDeck()
if encounterDeck then
table.insert(options, "Encounter Deck")
deckData["Encounter Deck"] = { draw = encounterDeck }
end
-- check for players with a deck and only display them as option
for _, color in ipairs(Player.getAvailableColors()) do
@ -34,28 +33,35 @@ function contextFunc(playerColor, amount)
local deckAreaObjects = playermatApi.getDeckAreaObjects(matColor)
if deckAreaObjects.draw or deckAreaObjects.topCard then
table.insert(options, color)
local playerName = Player[color].steam_name
local invName = playermatApi.getInvestigatorName(matColor)
-- figure out a proper display name for the drop down menu
local displayName = color .. " (color)"
if playerName then
displayName = playerName
elseif invName ~= "" then
displayName = invName .. " (inv)"
end
-- recreate table in this script to have access
deckData[displayName] = {
draw = deckAreaObjects.draw,
topCard = deckAreaObjects.topCard
}
table.insert(options, displayName)
end
end
-- show the target selection dialog
Player[playerColor].showOptionsDialog("Select target deck", options, _, function(owner) drawCardsFromBottom(playerColor, owner, amount) end)
Player[playerColor].showOptionsDialog("Select target deck", options, _,
function(owner) drawCardsFromBottom(playerColor, owner, amount) end)
end
function drawCardsFromBottom(playerColor, owner, amount)
-- variable initialization
local deck = nil
local deckAreaObjects = deckData[owner]
local deck = deckAreaObjects.draw
local deckSize = 1
local deckAreaObjects = {}
-- get the respective deck
if owner == "Encounter Deck" then
deck = mythosAreaApi.getEncounterDeck()
else
local matColor = playermatApi.getMatColor(owner)
deckAreaObjects = playermatApi.getDeckAreaObjects(matColor)
deck = deckAreaObjects.draw
end
-- error handling
if not deck then

View File

@ -2,6 +2,7 @@ do
local PlayermatApi = {}
local guidReferenceApi = require("core/GUIDReferenceApi")
local searchLib = require("util/SearchLib")
local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 }
-- Convenience function to look up a mat's object by color, or get all mats.
---@param matColor string Color of the playermat - White, Orange, Green, Red or All
@ -283,7 +284,6 @@ do
-- Returns a list of mat colors that have an investigator placed
PlayermatApi.getUsedMatColors = function()
local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 }
local usedColors = {}
for matColor, mat in pairs(getMatForColor("All")) do
local searchPos = mat.positionToWorld(localInvestigatorPosition)
@ -295,6 +295,19 @@ do
return usedColors
end
-- Returns investigator name
---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
PlayermatApi.getInvestigatorName = function(matColor)
for _, mat in pairs(getMatForColor(matColor)) do
local searchPos = mat.positionToWorld(localInvestigatorPosition)
local searchResult = searchLib.atPosition(searchPos, "isCardOrDeck")
if #searchResult == 1 then
return searchResult[1].getName()
end
end
return ""
end
-- Resets the specified skill tracker to "1, 1, 1, 1"
---@param matColor string Color of the playermat - White, Orange, Green, Red or All
PlayermatApi.resetSkillTracker = function(matColor)