added function to get owner of an object

This commit is contained in:
Chr1Z93 2024-05-10 13:39:18 +02:00
parent 7e14a51ffa
commit c1d600f6f4
3 changed files with 51 additions and 24 deletions

View File

@ -5,6 +5,7 @@ do
return getObjectFromGUID("123456")
end
-- Returns the matching object
---@param owner string Parent object for this search
---@param type string Type of object to search for
---@return any: Object reference to the matching object
@ -12,21 +13,21 @@ do
return getGuidHandler().call("getObjectByOwnerAndType", { owner = owner, type = type })
end
-- returns all matching objects as a table with references
-- Returns all matching objects as a table with references
---@param type string Type of object to search for
---@return table: List of object references to matching objects
GUIDReferenceApi.getObjectsByType = function(type)
return getGuidHandler().call("getObjectsByType", type)
end
-- returns all matching objects as a table with references
-- Returns all matching objects as a table with references
---@param owner string Parent object for this search
---@return table: List of object references to matching objects
GUIDReferenceApi.getObjectsByOwner = function(owner)
return getGuidHandler().call("getObjectsByOwner", owner)
end
-- sends new information to the reference handler to edit the main index
-- Sends new information to the reference handler to edit the main index
---@param owner string Parent of the object
---@param type string Type of the object
---@param guid string GUID of the object
@ -38,5 +39,12 @@ do
})
end
-- Returns the owner of an object or the object it's located on
---@param object tts__GameObject Object for this search
---@return string: Parent of the object or object it's located on
GUIDReferenceApi.getOwnerOfObject = function(object)
return getGuidHandler().call("getOwnerOfObject", object)
end
return GUIDReferenceApi
end

View File

@ -1,3 +1,5 @@
local searchLib = require("util/SearchLib")
local GuidReferences = {
White = {
ClueCounter = "d86b7c",
@ -156,3 +158,37 @@ function editIndex(params)
editsToIndex[params.owner][params.type] = params.guid
updateMainIndex()
end
-- Returns the owner of the provided object (either the matColor or "Mythos")
---@param object tts__GameObject Object to check
function getOwnerOfObject(object)
if object == nil then return end
-- use GUID to check owners instead of obtaining each as reference
local objectGuid = object.getGUID()
-- check if object is directly owned
for owner, subtable in pairs(GuidReferences) do
for type, guid in pairs(subtable) do
if guid == objectGuid then
return owner
end
end
end
-- check if it is on an owned object
local result = searchLib.belowPosition(object.getPosition())
for owner, subtable in pairs(GuidReferences) do
for type, guid in pairs(subtable) do
for _, searchObj in ipairs(result) do
if guid == searchObj.getGUID() then
return owner
end
end
end
end
-- default to "Mythos"
return "Mythos"
end

View File

@ -280,7 +280,7 @@ end
-- This method will broadcast a message to all players if the bag is being searched.
---@return boolean: True if the bag is manipulated, false if it should be blocked.
function canTouchChaosTokens()
for color, searching in pairs(bagSearchers) do
for _, searching in pairs(bagSearchers) do
if searching then
broadcastToAll("Someone is searching the chaos bag, can't touch the tokens.", "Red")
return false
@ -331,7 +331,6 @@ function drawChaosToken(params)
local takeParameters = {}
-- add the token to the list, compute new position based on list length
if params.returnedToken then
trackChaosToken(params.returnedToken.getName(), matGUID, true)
indexOfReturnedToken = getTokenIndex(params.returnedToken)
@ -349,9 +348,8 @@ function drawChaosToken(params)
end
local token
-- resolve a sealed token from a card
if params.guidToBeResolved then
-- resolve a sealed token from a card
token = getObjectFromGUID(params.guidToBeResolved)
token.setPositionSmooth(takeParameters.position)
local guid = token.getGUID()
@ -360,10 +358,8 @@ function drawChaosToken(params)
blessCurseManagerApi.releasedToken(tokenType, guid)
end
tokenArrangerApi.layout()
-- take a token from the bag, either specified or random
else
-- take a token from the bag, either specified or random
if params.tokenType then
for i, lookedForToken in ipairs(chaosBag.getObjects()) do
if lookedForToken.nickname == params.tokenType then
@ -371,19 +367,16 @@ function drawChaosToken(params)
end
end
end
token = chaosBag.takeObject(takeParameters)
end
-- get data for token description
local name = token.getName()
local tokenData = mythosAreaApi.returnTokenData().tokenData or {}
local specificData = tokenData[name] or {}
token.setDescription(specificData.description or "")
-- track the chaos token (for stat tracker and future returning)
trackChaosToken(name, matGUID)
if params.returnedToken then
chaosTokens[indexOfReturnedToken] = token
else
@ -750,16 +743,6 @@ function removeChaosToken(id)
printToAll("Removing " .. name .. " token (in bag: " .. #tokens - 1 .. ")", "White")
end
-- empty the chaos bag
function emptyChaosBag()
if not canTouchChaosTokens() then return end
local chaosBag = findChaosBag()
for _, object in ipairs(chaosBag.getObjects()) do
chaosBag.takeObject({ callback_function = function(item) item.destruct() end })
end
end
-- returns all sealed tokens on cards to the chaos bag
function releaseAllSealedTokens(playerColor)
for _, obj in ipairs(getObjectsWithTag("CardThatSeals")) do