diff --git a/objects/AllPlayerCards.15bb07/ScrollofSecrets.230835.json b/objects/AllPlayerCards.15bb07/ScrollofSecrets.230835.json index 57e5ec32..bdec7352 100644 --- a/objects/AllPlayerCards.15bb07/ScrollofSecrets.230835.json +++ b/objects/AllPlayerCards.15bb07/ScrollofSecrets.230835.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "", + "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", diff --git a/objects/AllPlayerCards.15bb07/ScrollofSecrets3.0b12ac.json b/objects/AllPlayerCards.15bb07/ScrollofSecrets3.0b12ac.json index 58b80881..44ded60c 100644 --- a/objects/AllPlayerCards.15bb07/ScrollofSecrets3.0b12ac.json +++ b/objects/AllPlayerCards.15bb07/ScrollofSecrets3.0b12ac.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "", + "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", diff --git a/objects/AllPlayerCards.15bb07/ScrollofSecrets3.194d88.json b/objects/AllPlayerCards.15bb07/ScrollofSecrets3.194d88.json index 99f1862c..d2dd906d 100644 --- a/objects/AllPlayerCards.15bb07/ScrollofSecrets3.194d88.json +++ b/objects/AllPlayerCards.15bb07/ScrollofSecrets3.194d88.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "", + "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", diff --git a/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.84a7df.json b/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.84a7df.json index 7ea28028..705b77c2 100644 --- a/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.84a7df.json +++ b/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.84a7df.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "", + "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", diff --git a/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.c127f1.json b/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.c127f1.json index e5143b65..f2640ffc 100644 --- a/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.c127f1.json +++ b/objects/AllPlayerCards.15bb07/ScrollofSecrets3Taboo.c127f1.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "", + "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", diff --git a/objects/AllPlayerCards.15bb07/ScrollofSecretsTaboo.b383b8.json b/objects/AllPlayerCards.15bb07/ScrollofSecretsTaboo.b383b8.json index 2b56a0dc..0d62fb10 100644 --- a/objects/AllPlayerCards.15bb07/ScrollofSecretsTaboo.b383b8.json +++ b/objects/AllPlayerCards.15bb07/ScrollofSecretsTaboo.b383b8.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "", + "LuaScript": "require(\"playercards/cards/ScrollofSecrets\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index fada0072..4245df02 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -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 diff --git a/src/core/MythosAreaApi.ttslua b/src/core/MythosAreaApi.ttslua index 08caeb1d..e2dc44ec 100644 --- a/src/core/MythosAreaApi.ttslua +++ b/src/core/MythosAreaApi.ttslua @@ -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", { diff --git a/src/playercards/cards/ScrollofSecrets.ttslua b/src/playercards/cards/ScrollofSecrets.ttslua new file mode 100644 index 00000000..964912bd --- /dev/null +++ b/src/playercards/cards/ScrollofSecrets.ttslua @@ -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