Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions src/accessories/AttachmentHelper.ttslua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local searchLib = require("util/SearchLib")
local fontColor
local BACKGROUNDS = {
{
Expand Down Expand Up @@ -112,25 +113,11 @@ end
-- attempt to load image from below card when dropped
function onDrop(playerColor)
local pos = self.getPosition():setAt("y", 2)
local search = Physics.cast({
direction = { 0, -1, 0 },
max_distance = 2,
type = 3,
size = { 0.1, 0.1, 0.1 },
origin = pos
})

local syncName
for _, v in ipairs(search) do
if v.hit_object.tag == "Card" then
syncName = v.hit_object.getName()
break
end
end

if not syncName then return end
local searchResult = searchLib.belowPosition(pos, "isCard")
if #searchResult == 0 then return end
local syncName = searchResult[1].getName()

-- remove level information fron syncName
-- remove level information from syncName
syncName = syncName:gsub("%s%(%d%)", "")

-- loop through background table
Expand Down Expand Up @@ -170,9 +157,9 @@ end
-- only allow cards to enter, split decks and reject other objects
function onObjectEnterContainer(container, object)
if container ~= self then return end
if object.tag == "Deck" then
if object.type == "Deck" then
takeDeckOut(object.getGUID(), self.getPosition() + Vector(0, 0.1, 0))
elseif object.tag ~= "Card" then
elseif object.type ~= "Card" then
broadcastToAll("The 'Attachment Helper' is meant to be used for cards.", "White")
else
findCard(object.getGUID(), object.getName(), object.getGMNotes())
Expand Down
26 changes: 2 additions & 24 deletions src/accessories/CleanUpHelper.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local chaosBagApi = require("chaosbag/ChaosBagApi")
local guidReferenceApi = require("core/GUIDReferenceApi")
local playAreaApi = require("core/PlayAreaApi")
local playmatApi = require("playermat/PlaymatApi")
local searchLib = require("util/SearchLib")
local soundCubeApi = require("core/SoundCubeApi")
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")

Expand Down Expand Up @@ -284,7 +285,7 @@ function tidyPlayerMatCoroutine()
if i < 5 then
objList = playmatApi.searchAroundPlaymat(COLORS[i])
else
objList = searchMythosArea()
objList = searchLib.inArea({ -2, 2, 10 }, { 0, 270, 0 }, { 55, 1, 13.5 })
end

for _, obj in ipairs(objList) do
Expand Down Expand Up @@ -321,26 +322,3 @@ function tidyPlayerMatCoroutine()
printToAll("Clean up completed!", "Green")
return 1
end

---------------------------------------------------------
-- helper functions
---------------------------------------------------------

-- find objects in the mythos area
function searchMythosArea()
local searchResult = Physics.cast({
direction = { 0, 1, 0 },
max_distance = 1,
type = 3,
size = { 55, 1, 13.5 },
origin = { -2, 2, 10 },
orientation = { 0, 270, 0 },
debug = false
})

local objList = {}
for _, v in ipairs(searchResult) do
table.insert(objList, v.hit_object)
end
return objList
end
27 changes: 3 additions & 24 deletions src/accessories/PlayermatHider.ttslua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local guidReferenceApi = require("core/GUIDReferenceApi")
local objects
local playmatApi = require("playermat/PlaymatApi")

function onClick_hideShow(player, matColor)
objects = guidReferenceApi.getObjectsByOwner(matColor)
local actionTokens = searchMat(objects.Playermat.positionToWorld({-1.1, 0.05, -0.27}), {4, 1, 1}, isActionToken)
local objects = guidReferenceApi.getObjectsByOwner(matColor)
local actionTokens = playmatApi.searchAroundPlaymat(matColor, "isActionToken")
local pos = objects.Playermat.getPosition()
local mod = (pos.y > 0) and -2 or 2

Expand All @@ -18,24 +18,3 @@ function onClick_hideShow(player, matColor)
obj.setPosition(obj.getPosition() + Vector(0, mod, 0))
end
end

function isActionToken(x) return x.getDescription() == 'Action Token' end

function searchMat(origin, size, filter)
local searchResult = Physics.cast({
origin = origin,
direction = { 0, 1, 0 },
orientation = objects.Playermat.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
21 changes: 3 additions & 18 deletions src/accessories/SearchAssistant.ttslua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local searchLib = require("util/SearchLib")
local playmatApi = require("playermat/PlaymatApi")

-- forward declaration of variables that are used across functions
Expand Down Expand Up @@ -159,17 +160,12 @@ function endSearch(_, _, isRightClick)
end

-- draw set aside cards (from the ground!)
for _, v in ipairs(searchArea(setAsidePosition)) do
local obj = v.hit_object
for _, obj in ipairs(searchLib.atPosition(setAsidePosition), "isCardOrDeck") do
if obj.type == "Deck" then
Wait.time(function()
obj.deal(#obj.getObjects(), handColor)
end, 1)
break
Wait.time(function() obj.deal(#obj.getObjects(), handColor) end, 1)
elseif obj.type == "Card" then
obj.setPosition(Player[handColor].getHandTransform().position)
obj.flip()
break
end
end

Expand All @@ -190,14 +186,3 @@ function endSearch(_, _, isRightClick)
Wait.time(function() playmatApi.flipTopCardFromDeck(matColor) end, #handCards * 0.1)
end
end

-- utility function
function searchArea(position)
return Physics.cast({
origin = position,
direction = { 0, 1, 0 },
type = 3,
size = { 2, 2, 2 },
max_distance = 0
})
end
13 changes: 3 additions & 10 deletions src/accessories/Subject5U-21Helper.ttslua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local searchLib = require("util/SearchLib")

local classOrder = {
"Guardian",
"Seeker",
Expand Down Expand Up @@ -75,17 +77,8 @@ function updateDisplayButtons(_, playerColor)
end

function getNotesFromCardsAndContainers()
local search = Physics.cast({
direction = { 0, 1, 0 },
max_distance = 0,
type = 3,
size = self.getBounds().size:setAt("y", 1),
origin = self.getPosition() + Vector(0, 0.5, 0),
})

local notesList = {}
for _, hit in ipairs(search) do
local obj = hit.hit_object
for _, obj in ipairs(searchLib.onObject(self)) do
local notes = {}
if obj.type == "Card" then
notes = JSON.decode(obj.getGMNotes()) or {}
Expand Down
15 changes: 4 additions & 11 deletions src/accessories/UnderworldMarketHelper.ttslua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local searchLib = require("util/SearchLib")

function onload(saved_data)
revealCardPositions = {
Vector(3.5, 0.25, 0),
Expand Down Expand Up @@ -176,17 +178,8 @@ function getRevealedCards()
local revealedCards = {}

for _, pos in ipairs(revealCardPositions) do
local hitList = Physics.cast({
origin = self.positionToWorld(pos) + Vector(0, 0.25, 0),
direction = {0,-1,0},
type = 1,
max_distance = 2
})

for _, hit in ipairs(hitList) do
if hit.hit_object != self and hit.hit_object.tag == "Card" then
table.insert(revealedCards, hit.hit_object.getGUID())
end
for _, obj in ipairs(searchLib.atPosition(self.positionToWorld(pos), "isCard")) do
table.insert(revealedCards, obj.getGUID())
end
end

Expand Down
53 changes: 10 additions & 43 deletions src/core/DoomCounter.ttslua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local searchLib = require("util/SearchLib")
local guidReferenceApi = require("core/GUIDReferenceApi")
local playAreaApi = require("core/PlayAreaApi")

Expand Down Expand Up @@ -62,13 +63,12 @@ function updateVal(number)
broadcastDoom(val)
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)

if val ~= 0 then
local doomInPlayCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomInPlayCounter")
otherDoom = doomInPlayCounter.call("countDoom")
totalDoomThreshold = getDoomThreshold()
local otherDoom = doomInPlayCounter.call("countDoom")
local totalDoomThreshold = getDoomThreshold()

if totalDoomThreshold ~= nil then
broadcastToAll(val .. " doom on the agenda (" .. otherDoom + val .. "/" .. totalDoomThreshold .. " in play)", "White")
Expand All @@ -91,13 +91,10 @@ function startReset()
end
end

-- get Doom Threshold from top card of Agenda deck
-- 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 agendaPos = { -2.72, 1.6, 0.37 }
local searchResult = searchLib.atPosition(agendaPos, "isCardOrDeck")
local metadata = {}
if #searchResult == 0 then
-- handle no agenda found
Expand All @@ -110,32 +107,27 @@ function getDoomThreshold()
if metadata == nil then
return nil
else
if(metadata.doomThresholdPerInvestigator) then

if metadata.doomThresholdPerInvestigator then
return metadata.doomThresholdPerInvestigator*playAreaApi.getInvestigatorCount() + metadata.doomThreshold
else
return metadata.doomThreshold
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
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
Expand All @@ -157,28 +149,3 @@ 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
Loading