Merge pull request #1001 from argonui/unified-token-discarding
Unified token discarding
This commit is contained in:
commit
bb1c6e85a0
@ -2869,11 +2869,7 @@ function handleTokenAttaching(params)
|
||||
end
|
||||
|
||||
Wait.condition(
|
||||
function()
|
||||
if card ~= nil then
|
||||
handleTokenDetaching({ card = card })
|
||||
end
|
||||
end,
|
||||
function() handleTokenDetaching({ card = card }) end,
|
||||
function()
|
||||
if card ~= nil and player ~= nil and player.seated then
|
||||
return card.resting and not tableContains(player.getHoldingObjects(), card)
|
||||
@ -2886,7 +2882,7 @@ end
|
||||
|
||||
function handleTokenDetaching(params)
|
||||
local card = params.card
|
||||
if next(card.getAttachments()) == nil then return end
|
||||
if card == nil or next(card.getAttachments()) == nil then return end
|
||||
|
||||
-- restore card settings
|
||||
if cardSetting[card] ~= nil then
|
||||
@ -2912,3 +2908,27 @@ function handleTokenDetaching(params)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- removes tokens from the provided card/deck
|
||||
function removeTokensFromObject(params)
|
||||
local object = params.object
|
||||
local trash = guidReferenceApi.getObjectByOwnerAndType(params.owner, "Trash")
|
||||
|
||||
if object.hasTag("CardThatSeals") then
|
||||
local func = object.getVar("resetSealedTokens") -- check if function exists (it won't for older custom content)
|
||||
if func ~= nil then
|
||||
object.call("resetSealedTokens")
|
||||
end
|
||||
end
|
||||
|
||||
for _, obj in ipairs(searchLib.onObject(object, "isTileOrToken")) do
|
||||
if tokenChecker.isChaosToken(obj) then
|
||||
returnChaosTokenToBag( { token = obj, fromBag = false } )
|
||||
elseif obj.getGUID() ~= "4ee1f2" and -- table
|
||||
obj ~= self and
|
||||
obj.memo ~= nil and
|
||||
obj.getLock() == false then
|
||||
trash.putObject(obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -59,6 +59,13 @@ do
|
||||
Global.call("handleTokenDetaching", { card = card })
|
||||
end
|
||||
|
||||
-- discards tokens from an object
|
||||
---@param object tts__Object Object that should get tokens removed
|
||||
---@param owner string Owner of this object (for discarding)
|
||||
function GlobalApi.removeTokensFromObject(object, owner)
|
||||
Global.call("removeTokensFromObject", { object = object, owner = owner })
|
||||
end
|
||||
|
||||
-- loads saved options
|
||||
---@param options table Set a new state for the option table
|
||||
function GlobalApi.loadOptionPanelSettings(options)
|
||||
|
@ -106,7 +106,7 @@ function onCollisionEnter(collisionInfo)
|
||||
-- reset spawned tokens and remove tokens from cards in encounter deck / discard area
|
||||
Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1)
|
||||
GlobalApi.handleTokenDetaching(object)
|
||||
removeTokensFromObject(object)
|
||||
GlobalApi.removeTokensFromObject(object, "Mythos")
|
||||
|
||||
elseif inArea(localPos, SCENARIO_REFERENCE_AREA) then
|
||||
-- detect scenario reference card and attempt to load data from it
|
||||
@ -167,7 +167,7 @@ function onObjectEnterContainer(container, object)
|
||||
local localPos = self.positionToLocal(container.getPosition())
|
||||
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then
|
||||
tokenSpawnTrackerApi.resetTokensSpawned(object)
|
||||
removeTokensFromObject(object)
|
||||
GlobalApi.removeTokensFromObject(object, "Mythos")
|
||||
end
|
||||
end
|
||||
|
||||
@ -313,17 +313,3 @@ function inArea(point, bounds)
|
||||
and point.z > bounds.upperLeft.z
|
||||
and point.z < bounds.lowerRight.z)
|
||||
end
|
||||
|
||||
-- removes tokens from the provided card/deck
|
||||
function removeTokensFromObject(object)
|
||||
local TRASH = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
|
||||
for _, obj in ipairs(searchLib.onObject(object, "isTileOrToken")) do
|
||||
if obj.getGUID() ~= "4ee1f2" and -- table
|
||||
obj ~= self and
|
||||
obj.memo ~= nil and
|
||||
obj.getLock() == false and
|
||||
not tokenChecker.isChaosToken(obj) then
|
||||
TRASH.putObject(obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -360,11 +360,15 @@ function resolveSealed(playerColor)
|
||||
broadcastToAll("No tokens sealed.", "Red")
|
||||
return
|
||||
end
|
||||
|
||||
local closestMatColor = playermatApi.getMatColorByPosition(self.getPosition())
|
||||
local mat = guidReferenceApi.getObjectByOwnerAndType(closestMatColor, "Playermat")
|
||||
local guidToBeResolved = table.remove(sealedTokens)
|
||||
local resolvedToken = getObjectFromGUID(guidToBeResolved)
|
||||
resolvedToken.UI.setXml("")
|
||||
if resolvedToken ~= nil then
|
||||
resolvedToken.UI.setXml("")
|
||||
end
|
||||
|
||||
updateStackSize()
|
||||
updateSave()
|
||||
chaosBagApi.drawChaosToken(mat, true, _, guidToBeResolved)
|
||||
@ -374,9 +378,10 @@ end
|
||||
function updateStackSize()
|
||||
if MAX_SEALED == 1 then return end
|
||||
if #sealedTokens == 0 then return end
|
||||
|
||||
-- get topmost sealed token
|
||||
local topToken = getObjectFromGUID(sealedTokens[#sealedTokens])
|
||||
local name = topToken.getName()
|
||||
if topToken == nil then return end
|
||||
|
||||
topToken.UI.setXmlTable({
|
||||
{
|
||||
@ -387,7 +392,7 @@ function updateStackSize()
|
||||
rotation = "0 0 180",
|
||||
scale = "0.2 0.2 1",
|
||||
position = "0 0 -12",
|
||||
color = tokenColor[name] or "#77674DE6"
|
||||
color = tokenColor[topToken.getName()] or "#77674DE6"
|
||||
},
|
||||
children = {
|
||||
tag = "Text",
|
||||
|
@ -1300,7 +1300,7 @@ function onCollisionEnter(collisionInfo)
|
||||
elseif inArea(localCardPos, DECK_DISCARD_AREA) then
|
||||
GlobalApi.handleTokenDetaching(object)
|
||||
tokenSpawnTrackerApi.resetTokensSpawned(object)
|
||||
removeTokensFromObject(object)
|
||||
GlobalApi.removeTokensFromObject(object, matColor)
|
||||
|
||||
elseif object.is_face_down == false then
|
||||
-- main uses spawning
|
||||
@ -1341,30 +1341,7 @@ function onObjectEnterContainer(container, object)
|
||||
local localCardPos = self.positionToLocal(object.getPosition())
|
||||
if inArea(localCardPos, DECK_DISCARD_AREA) then
|
||||
tokenSpawnTrackerApi.resetTokensSpawned(object)
|
||||
removeTokensFromObject(object)
|
||||
end
|
||||
end
|
||||
|
||||
-- removes tokens from the provided card/deck
|
||||
function removeTokensFromObject(object)
|
||||
if object.hasTag("CardThatSeals") then
|
||||
local func = object.getVar("resetSealedTokens") -- check if function exists (it won't for older custom content)
|
||||
if func ~= nil then
|
||||
object.call("resetSealedTokens")
|
||||
end
|
||||
end
|
||||
|
||||
for _, obj in ipairs(searchLib.onObject(object)) do
|
||||
if tokenChecker.isChaosToken(obj) then
|
||||
chaosBagApi.returnChaosTokenToBag(obj, false)
|
||||
elseif obj.getGUID() ~= "4ee1f2" and -- table
|
||||
obj ~= self and
|
||||
obj.type ~= "Deck" and
|
||||
obj.type ~= "Card" and
|
||||
obj.memo ~= nil and
|
||||
obj.getLock() == false then
|
||||
ownedObjects.Trash.putObject(obj)
|
||||
end
|
||||
GlobalApi.removeTokensFromObject(object, matColor)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -6,7 +6,7 @@ do
|
||||
isCardOrDeck = function(x) return x.type == "Card" or x.type == "Deck" end,
|
||||
isClue = function(x) return x.memo == "clueDoom" and x.is_face_down == false end,
|
||||
isDoom = function(x) return x.memo == "clueDoom" and x.is_face_down == true end,
|
||||
isTileOrToken = function(x) return x.type == "Tile" end,
|
||||
isTileOrToken = function(x) return x.type == "Tile" or x.type == "Generic" end,
|
||||
isUniversalToken = function(x) return x.getMemo() == "universalActionAbility" end,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user