Merge pull request #725 from argonui/scroll-of-secrets
Updated Scroll of Secrets menu
This commit is contained in:
commit
df71f95383
@ -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()
|
||||
-- get class via metadata and proceed menu accordingly:
|
||||
-- lvl 0: draw 1 card from the bottom
|
||||
-- mystic lvl 3: draw 1 card from the bottom
|
||||
local buttonLabel = "Draw bottom card"
|
||||
local amount = 1
|
||||
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
|
||||
-- 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
|
||||
if notes.id == "05188" or notes.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)
|
||||
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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user