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:
commit
b843a86611
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/ScrollofSecrets\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
@ -127,20 +127,34 @@ end
|
||||
-- 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
|
||||
function drawEncounterCard(params)
|
||||
local card
|
||||
local items = searchArea(ENCOUNTER_DECK_POS, { 3, 1, 4 }, isCardOrDeck)
|
||||
if #items > 0 then
|
||||
for _, j in ipairs(items) do
|
||||
local v = j.hit_object
|
||||
if v.tag == 'Deck' then
|
||||
card = v.takeObject({ index = 0 })
|
||||
break
|
||||
end
|
||||
local deck = getEncounterDeck()
|
||||
|
||||
if deck then
|
||||
if deck.type == "Deck" then
|
||||
card = deck.takeObject()
|
||||
else
|
||||
card = deck
|
||||
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)
|
||||
else
|
||||
-- nothing here, time to reshuffle
|
||||
|
@ -11,6 +11,11 @@ do
|
||||
return getMythosArea().call("returnTokenData")
|
||||
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
|
||||
MythosAreaApi.drawEncounterCard = function(pos, rotY, alwaysFaceUp)
|
||||
getMythosArea().call("drawEncounterCard", {
|
||||
|
95
src/playercards/cards/ScrollofSecrets.ttslua
Normal file
95
src/playercards/cards/ScrollofSecrets.ttslua
Normal 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
|
Loading…
Reference in New Issue
Block a user