Merge pull request #458 from argonui/scroll-of-secrets

Added scripting to Scroll of Secrets to draw bottom cards of a deck
This commit is contained in:
BootleggerFinn 2023-11-18 17:59:47 -06:00 committed by GitHub
commit b843a86611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 130 additions and 16 deletions

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -127,20 +127,34 @@ end
-- encounter card drawing -- encounter card drawing
--------------------------------------------------------- ---------------------------------------------------------
-- gets the encounter deck (for internal functions and Api calls)
function getEncounterDeck()
local search = searchArea(ENCOUNTER_DECK_POS, { 3, 1, 4 }, isCardOrDeck)
for _, v in ipairs(search) do
local obj = v.hit_object
if obj.type == 'Deck' then
return obj
end
end
-- if no deck was found, return the first hit (a card)
if #search > 0 then
return search[1].hit_object
end
end
-- 'params' contains the position, rotation and a boolean to force a faceup draw -- 'params' contains the position, rotation and a boolean to force a faceup draw
function drawEncounterCard(params) function drawEncounterCard(params)
local card local card
local items = searchArea(ENCOUNTER_DECK_POS, { 3, 1, 4 }, isCardOrDeck) local deck = getEncounterDeck()
if #items > 0 then
for _, j in ipairs(items) do if deck then
local v = j.hit_object if deck.type == "Deck" then
if v.tag == 'Deck' then card = deck.takeObject()
card = v.takeObject({ index = 0 }) else
break card = deck
end
end end
-- we didn't find the deck so just pull the first thing we did find
if card == nil then card = items[1].hit_object end
actualEncounterCardDraw(card, params) actualEncounterCardDraw(card, params)
else else
-- nothing here, time to reshuffle -- nothing here, time to reshuffle

View File

@ -11,6 +11,11 @@ do
return getMythosArea().call("returnTokenData") return getMythosArea().call("returnTokenData")
end end
-- returns an object reference to the encounter deck
MythosAreaApi.getEncounterDeck = function()
return getMythosArea().call("getEncounterDeck")
end
-- draw an encounter card to the requested position/rotation -- draw an encounter card to the requested position/rotation
MythosAreaApi.drawEncounterCard = function(pos, rotY, alwaysFaceUp) MythosAreaApi.drawEncounterCard = function(pos, rotY, alwaysFaceUp)
getMythosArea().call("drawEncounterCard", { getMythosArea().call("drawEncounterCard", {

View File

@ -0,0 +1,95 @@
-- this script is shared between the lvl 0 and lvl 3 versions of Scroll of Secrets
local mythosAreaApi = require("core/MythosAreaApi")
local playmatApi = require("playermat/PlaymatApi")
-- 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
-- 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)
end
end
function contextFunc(playerColor, amount)
local options = { "Encounter Deck" }
-- check for players with a deck and only display them as option
for _, color in ipairs(Player.getAvailableColors()) do
local matColor = playmatApi.getMatColor(color)
local deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
if deckAreaObjects.draw or deckAreaObjects.topCard then
table.insert(options, color)
end
end
-- show the target selection dialog
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 deckSize = 1
local deckAreaObjects = {}
-- get the respective deck
if owner == "Encounter Deck" then
deck = mythosAreaApi.getEncounterDeck()
else
local matColor = playmatApi.getMatColor(owner)
deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
deck = deckAreaObjects.draw
end
-- error handling
if not deck then
printToColor("Couldn't find deck!", playerColor)
return
end
-- set deck size if there is actually a deck and not just a card
if deck.type == "Deck" then
deckSize = #deck.getObjects()
end
-- proceed according to deck size
if deckSize > amount then
for i = 1, amount do
local card = deck.takeObject({ top = false, flip = true })
card.deal(1, playerColor)
end
else
-- deal the whole deck
deck.deal(amount, playerColor)
if deckSize < amount then
-- Norman Withers handling
if deckAreaObjects.topCard then
deckAreaObjects.topCard.deal(1, playerColor)
deckSize = deckSize + 1
end
-- warning message for player
if deckSize < amount then
printToColor("Deck didn't contain enough cards.", playerColor)
end
end
end
printToColor("Handle the drawn cards according to the ability text on 'Scroll of Secrets'.", playerColor)
end