From 9943cc035ec93383eb2e0b9ddfb1c696ed157d0e Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 18 Aug 2024 12:13:51 +0200 Subject: [PATCH] Added position check to scenario reference detection --- src/core/MythosArea.ttslua | 51 ++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 9e529f1e..6bd770b7 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -16,6 +16,10 @@ local ENCOUNTER_DISCARD_AREA = { upperLeft = { x = 1.77, z = 0.15 }, lowerRight = { x = 1.42, z = 0.59 } } +local SCENARIO_REFERENCE_AREA = { + upperLeft = { x = -1.45, z = 0.15 }, + lowerRight = { x = -1.75, z = 0.59 } +} -- global position of encounter deck and discard pile local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 } @@ -48,23 +52,30 @@ function onLoad(savedData) end function copyScenarioReferenceCard() - if scenarioCard == nil then broadcastToAll("No scenario reference card found.", "Red") return end - + if scenarioCard == nil then + broadcastToAll("No scenario reference card found.", "Red") + return + end + local usedColors = playermatApi.getUsedMatColors() - if #usedColors == 0 then broadcastToAll("No investigators placed.", "Red") return end + if #usedColors == 0 then + broadcastToAll("No investigators placed.", "Red") + return + end + for _, color in ipairs(usedColors) do - local cardPosition = playermatApi.transformLocalPosition({-1.365, 0.1, -0.625}, color) + local cardPosition = playermatApi.transformLocalPosition({ -1.365, 0.1, -0.625 }, color) local searchResult = searchLib.atPosition(cardPosition, "isCardOrDeck") if #searchResult == 0 then - scenarioCard.clone({position = cardPosition, snap_to_grid = true}) + scenarioCard.clone({ position = cardPosition, snap_to_grid = true }) elseif #searchResult == 1 then local obj = searchResult[1] local md = JSON.decode(obj.getGMNotes()) or {} - + if md.type == "ScenarioReference" then local trash = guidReferenceApi.getObjectByOwnerAndType(color, "Trash") trash.putObject(obj) - scenarioCard.clone({position = cardPosition, snap_to_grid = true}) + scenarioCard.clone({ position = cardPosition, snap_to_grid = true }) end end end @@ -80,27 +91,25 @@ function onCollisionEnter(collisionInfo) local object = collisionInfo.collision_object - -- early exit for better performance (but should exclude Tiles again in 4.0) - if object.type ~= "Card" and object.type ~= "Tile" then return end + -- early exit for better performance + if object.type ~= "Card" then return end - -- reset spawned tokens and remove tokens from cards in encounter deck / discard area local localPos = self.positionToLocal(object.getPosition()) + if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then + -- reset spawned tokens and remove tokens from cards in encounter deck / discard area Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1) removeTokensFromObject(object) - return - end - -- get metadata - local md = JSON.decode(object.getGMNotes()) or {} + elseif inArea(localPos, SCENARIO_REFERENCE_AREA) then + -- detect scenario reference card and attempt to load data from it + local md = JSON.decode(object.getGMNotes()) or {} + local cardName = object.getName() - -- get scenario name and maybe fire followup event - local cardName = object.getName() - if object.getName() == "Scenario" or md.type == "ScenarioReference" then - getDataFromReferenceCard(object, cardName, md) - scenarioCard = object - if scenarioCard.type == "Card" then - scenarioCard.setPosition{-3.85, 1.60, -10.39} + if cardName == "Scenario" or md.type == "ScenarioReference" then + getDataFromReferenceCard(object, cardName, md) + scenarioCard = object + scenarioCard.setPosition({ -3.85, 1.60, -10.39 }) end end end