From 7e26a25d7d22113ca8f380aa5e8a21626c229475 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 18 Nov 2024 23:41:19 +0100 Subject: [PATCH 1/6] Unified token discarding --- src/core/Global.ttslua | 34 ++++++++++++++++++++++++++++------ src/core/GlobalApi.ttslua | 7 +++++++ src/core/MythosArea.ttslua | 18 ++---------------- src/playermat/Playermat.ttslua | 27 ++------------------------- 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index d39e95fb..cd502aea 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2869,11 +2869,7 @@ function handleTokenAttaching(params) end Wait.condition( - function() - if card ~= nil then - handleTokenDetaching({ card = card }) - end - end, + function() handleTokenDetaching({ card = card }) end, function() if card ~= nil and player ~= nil and player.seated then return card.resting and not tableContains(player.getHoldingObjects(), card) @@ -2886,7 +2882,7 @@ end function handleTokenDetaching(params) local card = params.card - if next(card.getAttachments()) == nil then return end + if card == nil or next(card.getAttachments()) == nil then return end -- restore card settings if cardSetting[card] ~= nil then @@ -2912,3 +2908,29 @@ function handleTokenDetaching(params) end end end + +-- removes tokens from the provided card/deck +function removeTokensFromObject(params) + local object = params.object + local trash = guidReferenceApi.getObjectByOwnerAndType(params.owner, "Trash") + + if object.hasTag("CardThatSeals") then + local func = object.getVar("resetSealedTokens") -- check if function exists (it won't for older custom content) + if func ~= nil then + object.call("resetSealedTokens") + end + end + + for _, obj in ipairs(searchLib.onObject(object)) do + if tokenChecker.isChaosToken(obj) then + returnChaosTokenToBag( { token = obj, fromBag = false } ) + elseif obj.getGUID() ~= "4ee1f2" and -- table + obj ~= self and + obj.type ~= "Deck" and + obj.type ~= "Card" and + obj.memo ~= nil and + obj.getLock() == false then + trash.putObject(obj) + end + end +end diff --git a/src/core/GlobalApi.ttslua b/src/core/GlobalApi.ttslua index 887463de..8a26fd62 100644 --- a/src/core/GlobalApi.ttslua +++ b/src/core/GlobalApi.ttslua @@ -59,6 +59,13 @@ do Global.call("handleTokenDetaching", { card = card }) end + -- discards tokens from an object + ---@param object tts__Object Object that should get tokens removed + ---@param owner string Owner of this object (for discarding) + function GlobalApi.removeTokensFromObject(object, owner) + Global.call("removeTokensFromObject", { object = object, owner = owner }) + end + -- loads saved options ---@param options table Set a new state for the option table function GlobalApi.loadOptionPanelSettings(options) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index d580acc5..3c0a1c0a 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -106,7 +106,7 @@ function onCollisionEnter(collisionInfo) -- reset spawned tokens and remove tokens from cards in encounter deck / discard area Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1) GlobalApi.handleTokenDetaching(object) - removeTokensFromObject(object) + GlobalApi.removeTokensFromObject(object, "Mythos") elseif inArea(localPos, SCENARIO_REFERENCE_AREA) then -- detect scenario reference card and attempt to load data from it @@ -167,7 +167,7 @@ function onObjectEnterContainer(container, object) local localPos = self.positionToLocal(container.getPosition()) if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then tokenSpawnTrackerApi.resetTokensSpawned(object) - removeTokensFromObject(object) + GlobalApi.removeTokensFromObject(object, "Mythos") end end @@ -313,17 +313,3 @@ function inArea(point, bounds) and point.z > bounds.upperLeft.z and point.z < bounds.lowerRight.z) end - --- removes tokens from the provided card/deck -function removeTokensFromObject(object) - local TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash") - for _, obj in ipairs(searchLib.onObject(object, "isTileOrToken")) do - if obj.getGUID() ~= "4ee1f2" and -- table - obj ~= self and - obj.memo ~= nil and - obj.getLock() == false and - not tokenChecker.isChaosToken(obj) then - TRASH.putObject(obj) - end - end -end diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index cffb6107..e7619a1e 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -1300,7 +1300,7 @@ function onCollisionEnter(collisionInfo) elseif inArea(localCardPos, DECK_DISCARD_AREA) then GlobalApi.handleTokenDetaching(object) tokenSpawnTrackerApi.resetTokensSpawned(object) - removeTokensFromObject(object) + GlobalApi.removeTokensFromObject(object, matColor) elseif object.is_face_down == false then -- main uses spawning @@ -1341,30 +1341,7 @@ function onObjectEnterContainer(container, object) local localCardPos = self.positionToLocal(object.getPosition()) if inArea(localCardPos, DECK_DISCARD_AREA) then tokenSpawnTrackerApi.resetTokensSpawned(object) - removeTokensFromObject(object) - end -end - --- removes tokens from the provided card/deck -function removeTokensFromObject(object) - if object.hasTag("CardThatSeals") then - local func = object.getVar("resetSealedTokens") -- check if function exists (it won't for older custom content) - if func ~= nil then - object.call("resetSealedTokens") - end - end - - for _, obj in ipairs(searchLib.onObject(object)) do - if tokenChecker.isChaosToken(obj) then - chaosBagApi.returnChaosTokenToBag(obj, false) - elseif obj.getGUID() ~= "4ee1f2" and -- table - obj ~= self and - obj.type ~= "Deck" and - obj.type ~= "Card" and - obj.memo ~= nil and - obj.getLock() == false then - ownedObjects.Trash.putObject(obj) - end + GlobalApi.removeTokensFromObject(object, matColor) end end From b58f9923c2c125e6acac22e1d27b5f99ffed948d Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 19 Nov 2024 00:04:57 +0100 Subject: [PATCH 2/6] updated search --- src/core/Global.ttslua | 4 +--- src/util/SearchLib.ttslua | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index cd502aea..42b9d2a0 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2921,13 +2921,11 @@ function removeTokensFromObject(params) end end - for _, obj in ipairs(searchLib.onObject(object)) do + for _, obj in ipairs(searchLib.onObject(object, "isTileOrToken")) do if tokenChecker.isChaosToken(obj) then returnChaosTokenToBag( { token = obj, fromBag = false } ) elseif obj.getGUID() ~= "4ee1f2" and -- table obj ~= self and - obj.type ~= "Deck" and - obj.type ~= "Card" and obj.memo ~= nil and obj.getLock() == false then trash.putObject(obj) diff --git a/src/util/SearchLib.ttslua b/src/util/SearchLib.ttslua index 97531916..40800f4d 100644 --- a/src/util/SearchLib.ttslua +++ b/src/util/SearchLib.ttslua @@ -6,7 +6,7 @@ do isCardOrDeck = function(x) return x.type == "Card" or x.type == "Deck" end, isClue = function(x) return x.memo == "clueDoom" and x.is_face_down == false end, isDoom = function(x) return x.memo == "clueDoom" and x.is_face_down == true end, - isTileOrToken = function(x) return x.type == "Tile" end, + isTileOrToken = function(x) return x.type == "Tile" or x.type == "Generic" end, isUniversalToken = function(x) return x.getMemo() == "universalActionAbility" end, } From ac80962c9c0b5874360c1c1e02bac60da42300a5 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 19 Nov 2024 00:18:00 +0100 Subject: [PATCH 3/6] some nil handling --- src/core/MythosArea.ttslua | 2 +- src/playercards/CardsThatSealTokens.ttslua | 11 ++++++++--- src/playermat/Playermat.ttslua | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 3c0a1c0a..36d38d5c 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -163,7 +163,7 @@ end -- Listens for cards entering the encounter deck or encounter discard, discards tokens on them, -- and resets the spawn state for the cards when they do. -function onObjectEnterContainer(container, object) +function tryObjectEnterContainer(container, object) local localPos = self.positionToLocal(container.getPosition()) if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then tokenSpawnTrackerApi.resetTokensSpawned(object) diff --git a/src/playercards/CardsThatSealTokens.ttslua b/src/playercards/CardsThatSealTokens.ttslua index c92801e5..74eaf35b 100644 --- a/src/playercards/CardsThatSealTokens.ttslua +++ b/src/playercards/CardsThatSealTokens.ttslua @@ -360,11 +360,15 @@ function resolveSealed(playerColor) broadcastToAll("No tokens sealed.", "Red") return end + local closestMatColor = playermatApi.getMatColorByPosition(self.getPosition()) local mat = guidReferenceApi.getObjectByOwnerAndType(closestMatColor, "Playermat") local guidToBeResolved = table.remove(sealedTokens) local resolvedToken = getObjectFromGUID(guidToBeResolved) - resolvedToken.UI.setXml("") + if resolvedToken ~= nil then + resolvedToken.UI.setXml("") + end + updateStackSize() updateSave() chaosBagApi.drawChaosToken(mat, true, _, guidToBeResolved) @@ -374,9 +378,10 @@ end function updateStackSize() if MAX_SEALED == 1 then return end if #sealedTokens == 0 then return end + -- get topmost sealed token local topToken = getObjectFromGUID(sealedTokens[#sealedTokens]) - local name = topToken.getName() + if topToken == nil then return end topToken.UI.setXmlTable({ { @@ -387,7 +392,7 @@ function updateStackSize() rotation = "0 0 180", scale = "0.2 0.2 1", position = "0 0 -12", - color = tokenColor[name] or "#77674DE6" + color = tokenColor[topToken.getName()] or "#77674DE6" }, children = { tag = "Text", diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index e7619a1e..da8b350d 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -1335,7 +1335,7 @@ function spawnTokensOrShowHelper(card) end end -function onObjectEnterContainer(container, object) +function tryObjectEnterContainer(container, object) if object.type ~= "Card" then return end local localCardPos = self.positionToLocal(object.getPosition()) From ae2c5259d27b1b743b1b3f80454a1b907456af22 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 19 Nov 2024 09:26:19 +0100 Subject: [PATCH 4/6] changed event --- src/core/MythosArea.ttslua | 2 +- src/playermat/Playermat.ttslua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 36d38d5c..3c0a1c0a 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -163,7 +163,7 @@ end -- Listens for cards entering the encounter deck or encounter discard, discards tokens on them, -- and resets the spawn state for the cards when they do. -function tryObjectEnterContainer(container, object) +function onObjectEnterContainer(container, object) local localPos = self.positionToLocal(container.getPosition()) if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then tokenSpawnTrackerApi.resetTokensSpawned(object) diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index da8b350d..e7619a1e 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -1335,7 +1335,7 @@ function spawnTokensOrShowHelper(card) end end -function tryObjectEnterContainer(container, object) +function onObjectEnterContainer(container, object) if object.type ~= "Card" then return end local localCardPos = self.positionToLocal(object.getPosition()) From 2e27fec64612c0cb6a482f5a0bc5ee61dd1a15e5 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 19 Nov 2024 09:27:04 +0100 Subject: [PATCH 5/6] Updated patch notes date --- objects/PatchNotes.f47225.luascriptstate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objects/PatchNotes.f47225.luascriptstate b/objects/PatchNotes.f47225.luascriptstate index 0855930f..6c2ec597 100644 --- a/objects/PatchNotes.f47225.luascriptstate +++ b/objects/PatchNotes.f47225.luascriptstate @@ -85,7 +85,7 @@ }, "tooltip": "None", "value": [ - "Arkham Horror LCG SCE 4.0.1 - 11/18/2024" + "Arkham Horror LCG SCE 4.0.1 - 11/19/2024" ] }, { From 65285d3cc3a3af8ed60665956b8725c245cca9da Mon Sep 17 00:00:00 2001 From: Chr1Z <97286811+Chr1Z93@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:38:25 +0100 Subject: [PATCH 6/6] updated date --- objects/PatchNotes.f47225.luascriptstate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objects/PatchNotes.f47225.luascriptstate b/objects/PatchNotes.f47225.luascriptstate index 6c2ec597..005602f9 100644 --- a/objects/PatchNotes.f47225.luascriptstate +++ b/objects/PatchNotes.f47225.luascriptstate @@ -85,7 +85,7 @@ }, "tooltip": "None", "value": [ - "Arkham Horror LCG SCE 4.0.1 - 11/19/2024" + "Arkham Horror LCG SCE 4.0.1 - 11/20/2024" ] }, {