From 194670a3a0015dcf4c7268e73112f5b31f9b5285 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 4 Nov 2023 15:03:53 +0100 Subject: [PATCH 1/5] initial commit --- .../ScrollofSecrets.230835.json | 2 +- .../ScrollofSecrets3.0b12ac.json | 2 +- .../ScrollofSecrets3.194d88.json | 2 +- .../ScrollofSecrets3Taboo.84a7df.json | 2 +- .../ScrollofSecrets3Taboo.c127f1.json | 2 +- .../ScrollofSecretsTaboo.b383b8.json | 2 +- src/playercards/cards/ScrollofSecrets.ttslua | 32 +++++++++++++++++++ 7 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/playercards/cards/ScrollofSecrets.ttslua 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/playercards/cards/ScrollofSecrets.ttslua b/src/playercards/cards/ScrollofSecrets.ttslua new file mode 100644 index 00000000..1cb68c7b --- /dev/null +++ b/src/playercards/cards/ScrollofSecrets.ttslua @@ -0,0 +1,32 @@ + + +function onLoad() + -- select mode via metadata and create context menu accordingly + local notes = JSON.decode(self.getGMNotes()) + if notes then + createContextMenu(notes.class) + else + print("Missing metadata for Scroll of Secrets!") + end +end + + +function createContextMenu(mode) + if mode == "Seeker|Mystic" then + + elseif mode == "Seeker" then + + elseif mode == "Mystic" then + + end +end + + +function drawCardsFromBottom(owner, amount) + +end + + +function actualCardDrawing(deck, amount) + +end \ No newline at end of file From 33334b405816bfb32ee685324cee6b22564bfe74 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 5 Nov 2023 00:18:16 +0100 Subject: [PATCH 2/5] added scripting to scroll of secrets --- src/core/MythosArea.ttslua | 34 +++++--- src/core/MythosAreaApi.ttslua | 5 ++ src/playercards/cards/ScrollofSecrets.ttslua | 84 ++++++++++++++++---- 3 files changed, 99 insertions(+), 24 deletions(-) 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 index 1cb68c7b..c37cc45e 100644 --- a/src/playercards/cards/ScrollofSecrets.ttslua +++ b/src/playercards/cards/ScrollofSecrets.ttslua @@ -1,7 +1,9 @@ +-- 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() - -- select mode via metadata and create context menu accordingly local notes = JSON.decode(self.getGMNotes()) if notes then createContextMenu(notes.class) @@ -10,23 +12,77 @@ function onLoad() end end +function createContextMenu(class) + local colorList = Player.getAvailableColors() -function createContextMenu(mode) - if mode == "Seeker|Mystic" then - - elseif mode == "Seeker" then - - elseif mode == "Mystic" then - + if class == "Seeker|Mystic" then + -- draw 1 card from the bottom + self.addContextMenuItem("Draw bottom card", function(playerColor) contextFunc(playerColor, 1) end) + elseif class == "Seeker" then + -- draw 3 cards from the bottom + self.addContextMenuItem("Draw bottom card(s)", function(playerColor) contextFunc(playerColor, 3) end) + elseif class == "Mystic" then + -- draw 1 card from the bottom + self.addContextMenuItem("Draw bottom card", function(playerColor) contextFunc(playerColor, 1) end) end end - -function drawCardsFromBottom(owner, amount) - +function contextFunc(playerColor, amount) + local options = Player.getAvailableColors() + table.insert(options, "Encounter") + 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 = {} -function actualCardDrawing(deck, amount) + -- get the respective deck + if owner == "Encounter" then + deck = mythosAreaApi.getEncounterDeck() + else + deckAreaObjects = playmatApi.getDeckAreaObjects(owner) + deck = deckAreaObjects.draw + end -end \ No newline at end of file + -- 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 +end From 762756430a6f0fffa7e6890fd2e32e8e11457e10 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 5 Nov 2023 00:32:19 +0100 Subject: [PATCH 3/5] added different color handling --- src/playercards/cards/ScrollofSecrets.ttslua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/playercards/cards/ScrollofSecrets.ttslua b/src/playercards/cards/ScrollofSecrets.ttslua index c37cc45e..33b78779 100644 --- a/src/playercards/cards/ScrollofSecrets.ttslua +++ b/src/playercards/cards/ScrollofSecrets.ttslua @@ -29,7 +29,9 @@ end function contextFunc(playerColor, amount) local options = Player.getAvailableColors() - table.insert(options, "Encounter") + table.insert(options, "Encounter Deck") + + -- show the target selection dialog Player[playerColor].showOptionsDialog("Select target deck", options, _, function(owner) drawCardsFromBottom(playerColor, owner, amount) @@ -44,10 +46,11 @@ function drawCardsFromBottom(playerColor, owner, amount) local deckAreaObjects = {} -- get the respective deck - if owner == "Encounter" then + if owner == "Encounter Deck" then deck = mythosAreaApi.getEncounterDeck() else - deckAreaObjects = playmatApi.getDeckAreaObjects(owner) + local matColor = playmatApi.getMatColor(owner) + deckAreaObjects = playmatApi.getDeckAreaObjects(matColor) deck = deckAreaObjects.draw end From ad3b943c339454664e1cde28a03be30a89ca7578 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 5 Nov 2023 18:06:17 +0100 Subject: [PATCH 4/5] added note --- src/playercards/cards/ScrollofSecrets.ttslua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/playercards/cards/ScrollofSecrets.ttslua b/src/playercards/cards/ScrollofSecrets.ttslua index 33b78779..48c8cb3a 100644 --- a/src/playercards/cards/ScrollofSecrets.ttslua +++ b/src/playercards/cards/ScrollofSecrets.ttslua @@ -28,6 +28,7 @@ function createContextMenu(class) end function contextFunc(playerColor, amount) + -- TODO: only show colors that have a deck local options = Player.getAvailableColors() table.insert(options, "Encounter Deck") From f0ead2f41569e5366defe48a648f9718f5030d29 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 18 Nov 2023 10:03:37 +0100 Subject: [PATCH 5/5] resolved review comments --- src/playercards/cards/ScrollofSecrets.ttslua | 39 +++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/playercards/cards/ScrollofSecrets.ttslua b/src/playercards/cards/ScrollofSecrets.ttslua index 48c8cb3a..964912bd 100644 --- a/src/playercards/cards/ScrollofSecrets.ttslua +++ b/src/playercards/cards/ScrollofSecrets.ttslua @@ -6,38 +6,40 @@ local playmatApi = require("playermat/PlaymatApi") function onLoad() local notes = JSON.decode(self.getGMNotes()) if notes then - createContextMenu(notes.class) + createContextMenu(notes.id) else print("Missing metadata for Scroll of Secrets!") end end -function createContextMenu(class) - local colorList = Player.getAvailableColors() - - if class == "Seeker|Mystic" then - -- draw 1 card from the bottom +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 class == "Seeker" then - -- draw 3 cards from the bottom + 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 class == "Mystic" then - -- draw 1 card from the bottom + 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) - -- TODO: only show colors that have a deck - local options = Player.getAvailableColors() - table.insert(options, "Encounter Deck") + 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 - ) + Player[playerColor].showOptionsDialog("Select target deck", options, _, function(owner) drawCardsFromBottom(playerColor, owner, amount) end) end function drawCardsFromBottom(playerColor, owner, amount) @@ -89,4 +91,5 @@ function drawCardsFromBottom(playerColor, owner, amount) end end end + printToColor("Handle the drawn cards according to the ability text on 'Scroll of Secrets'.", playerColor) end