added functionality for viewing Doom Thresholds
This commit is contained in:
parent
cec1a7b4d9
commit
8e90a898a8
@ -1,4 +1,5 @@
|
||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||
local playAreaApi = require("core/PlayAreaApi")
|
||||
|
||||
local optionsVisible = false
|
||||
local options = {
|
||||
@ -51,14 +52,32 @@ function addVal(number)
|
||||
number = tonumber(number) or 0
|
||||
val = val + number
|
||||
self.editButton({ index = 0, label = tostring(val) })
|
||||
printToAll("Doom on agenda set to: " .. val)
|
||||
broadcastDoom(val)
|
||||
end
|
||||
|
||||
-- sets the current count to the provided number
|
||||
function updateVal(number)
|
||||
val = number or 0
|
||||
self.editButton({ index = 0, label = tostring(val) })
|
||||
printToAll("Doom on agenda set to: " .. val)
|
||||
broadcastDoom(val)
|
||||
end
|
||||
|
||||
--called by updateVal and addVal to broadcast total doom in play, including doom threshold
|
||||
function broadcastDoom(val)
|
||||
|
||||
if val ~= 0 then
|
||||
local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter")
|
||||
otherDoom = doomInPlayCounter.call("countDoom")
|
||||
totalDoomThreshold = getDoomThreshold()
|
||||
|
||||
if totalDoomThreshold ~= nil then
|
||||
broadcastToAll(val .. " doom on the agenda (" .. otherDoom + val .. "/" .. totalDoomThreshold .. " in play)", "White")
|
||||
else
|
||||
broadcastToAll(val .. " doom on the agenda (" .. otherDoom + val .. " in play)", "White")
|
||||
end
|
||||
else
|
||||
broadcastToAll("Doom on agenda set to " .. val, "White")
|
||||
end
|
||||
end
|
||||
|
||||
-- called by "Reset" button to remove doom
|
||||
@ -72,6 +91,57 @@ function startReset()
|
||||
end
|
||||
end
|
||||
|
||||
-- get Doom Threshold from top card of Agenda deck
|
||||
function getDoomThreshold()
|
||||
|
||||
local origin = { -2.72, 1.6, 0.37 } -- this needs to be edited to the actual coordinates of the agenda deck
|
||||
local size = { 0.1, 0.1, 0.1 } -- very slim area, basically a single raycast
|
||||
local searchResult = searchArea(origin, size, isCardOrDeck)
|
||||
|
||||
local metadata = {}
|
||||
if #searchResult == 0 then
|
||||
-- handle no agenda found
|
||||
return nil
|
||||
elseif #searchResult == 1 then
|
||||
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
|
||||
-- handle agenda deck
|
||||
|
||||
local cardData = searchResult[1].getData().ContainedObjects
|
||||
local topCardData = cardData[#cardData]
|
||||
metadata = JSON.decode(topCardData.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
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
-- handle multiple cards / decks found
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
-- XML UI functions
|
||||
function optionClick(_, optionName)
|
||||
options[optionName] = not options[optionName]
|
||||
@ -87,3 +157,28 @@ function toggleOptions()
|
||||
self.UI.hide("Options")
|
||||
end
|
||||
end
|
||||
|
||||
-- searches an area and optionally filters the result
|
||||
function searchArea(origin, size, filter)
|
||||
local searchResult = Physics.cast({
|
||||
origin = origin,
|
||||
direction = { 0, 1, 0 },
|
||||
orientation = self.getRotation(),
|
||||
type = 3,
|
||||
size = size,
|
||||
max_distance = 0
|
||||
})
|
||||
|
||||
local objList = {}
|
||||
for _, v in ipairs(searchResult) do
|
||||
if not filter or (filter and filter(v.hit_object)) then
|
||||
table.insert(objList, v.hit_object)
|
||||
end
|
||||
end
|
||||
return objList
|
||||
end
|
||||
|
||||
-- filter functions for searchArea()
|
||||
function isCard(x) return x.type == 'Card' end
|
||||
function isDeck(x) return x.type == 'Deck' end
|
||||
function isCardOrDeck(x) return x.type == 'Card' or x.type == 'Deck' end
|
||||
|
@ -45,6 +45,7 @@ function countDoom()
|
||||
end
|
||||
|
||||
self.editButton({ index = 0, label = tostring(count) })
|
||||
return count
|
||||
end
|
||||
|
||||
-- gets quantity (for stacks) of doom
|
||||
@ -64,12 +65,16 @@ function removeDoom(options)
|
||||
|
||||
if options.Playermats then
|
||||
count = removeDoomFromList(playmatApi.searchAroundPlaymat("All"))
|
||||
broadcastToAll(count .. " doom removed from Playermats.", "White")
|
||||
if count > 0 then
|
||||
broadcastToAll(count .. " doom removed from Playermats.", "White")
|
||||
end
|
||||
end
|
||||
|
||||
if options.Playarea then
|
||||
count = removeDoomFromList(ZONE.getObjects())
|
||||
broadcastToAll(count .. " doom removed from Playerarea.", "White")
|
||||
if count > 0 then
|
||||
broadcastToAll(count .. " doom removed from Playerarea.", "White")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user