mythos area code clean up
This commit is contained in:
parent
cdce59db2f
commit
de2b6ab22e
@ -1,6 +1,6 @@
|
|||||||
local searchLib = require("util/SearchLib")
|
|
||||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||||
local playAreaApi = require("core/PlayAreaApi")
|
local playAreaApi = require("core/PlayAreaApi")
|
||||||
|
local searchLib = require("util/SearchLib")
|
||||||
|
|
||||||
local optionsVisible = false
|
local optionsVisible = false
|
||||||
local options = {
|
local options = {
|
||||||
@ -50,10 +50,8 @@ end
|
|||||||
|
|
||||||
-- adds the provided number to the current count
|
-- adds the provided number to the current count
|
||||||
function addVal(number)
|
function addVal(number)
|
||||||
number = tonumber(number) or 0
|
|
||||||
val = val + number
|
val = val + number
|
||||||
self.editButton({ index = 0, label = tostring(val) })
|
updateVal(val)
|
||||||
broadcastDoom(val)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- sets the current count to the provided number
|
-- sets the current count to the provided number
|
||||||
@ -65,18 +63,14 @@ end
|
|||||||
|
|
||||||
-- called by updateVal and addVal to broadcast total doom in play, including doom threshold
|
-- called by updateVal and addVal to broadcast total doom in play, including doom threshold
|
||||||
function broadcastDoom(val)
|
function broadcastDoom(val)
|
||||||
if val ~= 0 then
|
|
||||||
local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter")
|
local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter")
|
||||||
local otherDoom = doomInPlayCounter.call("countDoom")
|
local doomInPlay = doomInPlayCounter.call("countDoomInPlay") + val
|
||||||
local totalDoomThreshold = getDoomThreshold()
|
local doomThreshold = getDoomThreshold()
|
||||||
|
|
||||||
if totalDoomThreshold ~= nil then
|
if doomThreshold then
|
||||||
broadcastToAll(val .. " doom on the agenda (" .. otherDoom + val .. "/" .. totalDoomThreshold .. " in play)", "White")
|
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. "/" .. doomThreshold .. " in play)", "White")
|
||||||
else
|
else
|
||||||
broadcastToAll(val .. " doom on the agenda (" .. otherDoom + val .. " in play)", "White")
|
broadcastToAll(val .. " doom on the agenda (" .. doomInPlay .. " in play)", "White")
|
||||||
end
|
|
||||||
else
|
|
||||||
broadcastToAll("Doom on agenda set to " .. val, "White")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -95,43 +89,29 @@ end
|
|||||||
function getDoomThreshold()
|
function getDoomThreshold()
|
||||||
local agendaPos = { -2.72, 1.6, 0.37 }
|
local agendaPos = { -2.72, 1.6, 0.37 }
|
||||||
local searchResult = searchLib.atPosition(agendaPos, "isCardOrDeck")
|
local searchResult = searchLib.atPosition(agendaPos, "isCardOrDeck")
|
||||||
local metadata = {}
|
|
||||||
if #searchResult == 0 then
|
if #searchResult == 1 then
|
||||||
-- handle no agenda found
|
local obj = searchResult[1]
|
||||||
return nil
|
if obj.type == "Card" then
|
||||||
elseif #searchResult == 1 then
|
return getDoomThresholdFromGMNotes(obj.getGMNotes())
|
||||||
if searchResult[1].type == "Card" then
|
|
||||||
-- handle single agenda card
|
|
||||||
local cardData = searchResult[1].getData()
|
|
||||||
metadata = JSON.decode(cardData.GMNotes)
|
|
||||||
if metadata == nil then
|
|
||||||
return nil
|
|
||||||
else
|
|
||||||
if metadata.doomThresholdPerInvestigator then
|
|
||||||
return metadata.doomThresholdPerInvestigator*playAreaApi.getInvestigatorCount() + metadata.doomThreshold
|
|
||||||
else
|
|
||||||
return metadata.doomThreshold
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
-- handle agenda deck
|
-- handle agenda deck
|
||||||
local cardData = searchResult[1].getData().ContainedObjects
|
local containedObjects = obj.getData().ContainedObjects
|
||||||
local topCardData = cardData[#cardData]
|
local topCardData = containedObjects[#containedObjects]
|
||||||
metadata = JSON.decode(topCardData.GMNotes)
|
return getDoomThresholdFromGMNotes(topCardData.GMNotes)
|
||||||
if metadata == nil then
|
end
|
||||||
|
end
|
||||||
return nil
|
return nil
|
||||||
else
|
end
|
||||||
|
|
||||||
|
-- decodes the gm notes and return the doom treshhold
|
||||||
|
function getDoomThresholdFromGMNotes(notes)
|
||||||
|
local metadata = JSON.decode(notes) or {}
|
||||||
if metadata.doomThresholdPerInvestigator then
|
if metadata.doomThresholdPerInvestigator then
|
||||||
return metadata.doomThresholdPerInvestigator*playAreaApi.getInvestigatorCount() + metadata.doomThreshold
|
return metadata.doomThresholdPerInvestigator * playAreaApi.getInvestigatorCount() + metadata.doomThreshold
|
||||||
else
|
else
|
||||||
return metadata.doomThreshold
|
return metadata.doomThreshold
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- handle multiple cards / decks found
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- XML UI functions
|
-- XML UI functions
|
||||||
|
@ -32,19 +32,23 @@ function onLoad()
|
|||||||
|
|
||||||
TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
|
TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
|
||||||
ZONE = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone")
|
ZONE = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone")
|
||||||
loopID = Wait.time(countDoom, 2, -1)
|
loopID = Wait.time(updateCounter, 2, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- main function
|
-- main function
|
||||||
function countDoom()
|
function updateCounter()
|
||||||
|
local count = countDoomInPlay()
|
||||||
|
self.editButton({ index = 0, label = tostring(count) })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get doom in play
|
||||||
|
function countDoomInPlay()
|
||||||
local count = 0
|
local count = 0
|
||||||
|
|
||||||
-- get doom in play
|
|
||||||
for _, obj in ipairs(getObjects()) do
|
for _, obj in ipairs(getObjects()) do
|
||||||
count = count + getDoomAmount(obj)
|
count = count + getDoomAmount(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.editButton({ index = 0, label = tostring(count) })
|
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,19 +65,17 @@ end
|
|||||||
|
|
||||||
-- removes doom from playermats / playarea
|
-- removes doom from playermats / playarea
|
||||||
function removeDoom(options)
|
function removeDoom(options)
|
||||||
local count = 0
|
|
||||||
|
|
||||||
if options.Playermats then
|
if options.Playermats then
|
||||||
count = removeDoomFromList(playmatApi.searchAroundPlaymat("All"))
|
local count = removeDoomFromList(playmatApi.searchAroundPlaymat("All"))
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
broadcastToAll(count .. " doom removed from Playermats.", "White")
|
broadcastToAll(count .. " doom removed from playermats.", "White")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if options.Playarea then
|
if options.Playarea then
|
||||||
count = removeDoomFromList(ZONE.getObjects())
|
local count = removeDoomFromList(ZONE.getObjects())
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
broadcastToAll(count .. " doom removed from Playerarea.", "White")
|
broadcastToAll(count .. " doom removed from play area.", "White")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -91,6 +93,7 @@ function removeDoomFromList(objList)
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- helper function to check if a position is inside an area
|
||||||
function inArea(point, bounds)
|
function inArea(point, bounds)
|
||||||
return (point.x < bounds.upperLeft.x
|
return (point.x < bounds.upperLeft.x
|
||||||
and point.x > bounds.lowerRight.x
|
and point.x > bounds.lowerRight.x
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
local searchLib = require("util/SearchLib")
|
|
||||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||||
local playAreaApi = require("core/PlayAreaApi")
|
local playAreaApi = require("core/PlayAreaApi")
|
||||||
|
local searchLib = require("util/SearchLib")
|
||||||
local tokenArrangerApi = require("accessories/TokenArrangerApi")
|
local tokenArrangerApi = require("accessories/TokenArrangerApi")
|
||||||
local tokenChecker = require("core/token/TokenChecker")
|
local tokenChecker = require("core/token/TokenChecker")
|
||||||
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
|
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
|
||||||
@ -18,16 +18,9 @@ local ENCOUNTER_DISCARD_AREA = {
|
|||||||
local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 }
|
local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 }
|
||||||
local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1, z = 10.38 }
|
local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1, z = 10.38 }
|
||||||
local isReshuffling = false
|
local isReshuffling = false
|
||||||
|
|
||||||
-- scenario metadata
|
|
||||||
local currentScenario, useFrontData, tokenData
|
local currentScenario, useFrontData, tokenData
|
||||||
|
|
||||||
-- object references
|
|
||||||
local TRASH, DATA_HELPER
|
local TRASH, DATA_HELPER
|
||||||
|
|
||||||
-- we use this to turn off collision handling until onLoad() is complete
|
|
||||||
local collisionEnabled = false
|
|
||||||
|
|
||||||
function onLoad(saveState)
|
function onLoad(saveState)
|
||||||
if saveState ~= nil then
|
if saveState ~= nil then
|
||||||
local loadedState = JSON.decode(saveState) or {}
|
local loadedState = JSON.decode(saveState) or {}
|
||||||
@ -37,7 +30,6 @@ function onLoad(saveState)
|
|||||||
end
|
end
|
||||||
TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
|
TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
|
||||||
DATA_HELPER = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper")
|
DATA_HELPER = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper")
|
||||||
collisionEnabled = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function onSave()
|
function onSave()
|
||||||
@ -48,9 +40,12 @@ function onSave()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---------------------------------------------------------
|
||||||
|
-- collison and container event handling
|
||||||
|
---------------------------------------------------------
|
||||||
|
|
||||||
-- TTS event handler. Handles scenario name event triggering and encounter card token resets.
|
-- TTS event handler. Handles scenario name event triggering and encounter card token resets.
|
||||||
function onCollisionEnter(collisionInfo)
|
function onCollisionEnter(collisionInfo)
|
||||||
if not collisionEnabled then return end
|
|
||||||
local object = collisionInfo.collision_object
|
local object = collisionInfo.collision_object
|
||||||
|
|
||||||
if object.getName() == "Scenario" then
|
if object.getName() == "Scenario" then
|
||||||
@ -83,7 +78,6 @@ end
|
|||||||
|
|
||||||
-- TTS event handler. Handles scenario name event triggering
|
-- TTS event handler. Handles scenario name event triggering
|
||||||
function onCollisionExit(collisionInfo)
|
function onCollisionExit(collisionInfo)
|
||||||
if not collisionEnabled then return end
|
|
||||||
local object = collisionInfo.collision_object
|
local object = collisionInfo.collision_object
|
||||||
|
|
||||||
-- reset token metadata if scenario reference card is removed
|
-- reset token metadata if scenario reference card is removed
|
||||||
@ -153,14 +147,14 @@ end
|
|||||||
|
|
||||||
-- 'params' contains the position, rotation and a boolean to force a faceup draw
|
-- 'params' contains the position, rotation and a boolean to force a faceup draw
|
||||||
function drawEncounterCard(params)
|
function drawEncounterCard(params)
|
||||||
local card
|
local encounterDeck = getEncounterDeck()
|
||||||
local deck = getEncounterDeck()
|
|
||||||
|
|
||||||
if deck then
|
if encounterDeck then
|
||||||
if deck.type == "Deck" then
|
local card
|
||||||
card = deck.takeObject()
|
if encounterDeck.type == "Deck" then
|
||||||
|
card = encounterDeck.takeObject()
|
||||||
else
|
else
|
||||||
card = deck
|
card = encounterDeck
|
||||||
end
|
end
|
||||||
actualEncounterCardDraw(card, params)
|
actualEncounterCardDraw(card, params)
|
||||||
else
|
else
|
||||||
@ -206,11 +200,10 @@ end
|
|||||||
-- helper functions
|
-- helper functions
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
-- Simple method to check if the given point is in a specified area. Local use only,
|
-- Simple method to check if the given point is in a specified area
|
||||||
---@param point Vector. Point to check, only x and z values are relevant
|
---@param point Vector Point to check, only x and z values are relevant
|
||||||
---@param bounds Table. Defined area to see if the point is within. See MAIN_PLAY_AREA for sample
|
---@param bounds Table Defined area to see if the point is within
|
||||||
-- bounds definition.
|
---@return Boolean: True if the point is in the area defined by bounds
|
||||||
---@return Boolean. True if the point is in the area defined by bounds
|
|
||||||
function inArea(point, bounds)
|
function inArea(point, bounds)
|
||||||
return (point.x < bounds.upperLeft.x
|
return (point.x < bounds.upperLeft.x
|
||||||
and point.x > bounds.lowerRight.x
|
and point.x > bounds.lowerRight.x
|
||||||
|
Loading…
Reference in New Issue
Block a user