Merge pull request #841 from argonui/mythos-area

Added position check to scenario reference detection
This commit is contained in:
dscarpac 2024-08-25 09:40:42 -05:00 committed by GitHub
commit d6d9e7a019
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,6 +16,10 @@ local ENCOUNTER_DISCARD_AREA = {
upperLeft = { x = 1.77, z = 0.15 }, upperLeft = { x = 1.77, z = 0.15 },
lowerRight = { x = 1.42, z = 0.59 } 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 -- global position of encounter deck and discard pile
local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 } local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 }
@ -48,23 +52,30 @@ function onLoad(savedData)
end end
function copyScenarioReferenceCard() 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() 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 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") local searchResult = searchLib.atPosition(cardPosition, "isCardOrDeck")
if #searchResult == 0 then if #searchResult == 0 then
scenarioCard.clone({position = cardPosition, snap_to_grid = true}) scenarioCard.clone({ position = cardPosition, snap_to_grid = true })
elseif #searchResult == 1 then elseif #searchResult == 1 then
local obj = searchResult[1] local obj = searchResult[1]
local md = JSON.decode(obj.getGMNotes()) or {} local md = JSON.decode(obj.getGMNotes()) or {}
if md.type == "ScenarioReference" then if md.type == "ScenarioReference" then
local trash = guidReferenceApi.getObjectByOwnerAndType(color, "Trash") local trash = guidReferenceApi.getObjectByOwnerAndType(color, "Trash")
trash.putObject(obj) trash.putObject(obj)
scenarioCard.clone({position = cardPosition, snap_to_grid = true}) scenarioCard.clone({ position = cardPosition, snap_to_grid = true })
end end
end end
end end
@ -80,27 +91,25 @@ function onCollisionEnter(collisionInfo)
local object = collisionInfo.collision_object local object = collisionInfo.collision_object
-- early exit for better performance (but should exclude Tiles again in 4.0) -- early exit for better performance
if object.type ~= "Card" and object.type ~= "Tile" then return end 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()) local localPos = self.positionToLocal(object.getPosition())
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then 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) Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1)
removeTokensFromObject(object) removeTokensFromObject(object)
return
end
-- get metadata elseif inArea(localPos, SCENARIO_REFERENCE_AREA) then
local md = JSON.decode(object.getGMNotes()) or {} -- 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 if cardName == "Scenario" or md.type == "ScenarioReference" then
local cardName = object.getName() getDataFromReferenceCard(object, cardName, md)
if object.getName() == "Scenario" or md.type == "ScenarioReference" then scenarioCard = object
getDataFromReferenceCard(object, cardName, md) scenarioCard.setPosition({ -3.85, 1.60, -10.39 })
scenarioCard = object
if scenarioCard.type == "Card" then
scenarioCard.setPosition{-3.85, 1.60, -10.39}
end end
end end
end end