added releasing on discarding

This commit is contained in:
Chr1Z93 2024-01-16 00:06:55 +01:00
parent f90257e03c
commit 1d74a84851
7 changed files with 81 additions and 53 deletions

View File

@ -40,7 +40,7 @@
"Decoration-Coin.180a23",
"Panel.463022",
"TentacleStand.7bff34",
"ScriptingTrigger.83ef06",
"ChaosBagZone.83ef06",
"Cluetokens.11e0cf",
"Doomtokens.b015d8",
"DoomCounter.85c4c6",

View File

@ -26,19 +26,19 @@
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "ScriptingTrigger",
"Nickname": "",
"Nickname": "ChaosBagZone",
"Snap": true,
"Sticky": true,
"Tooltip": true,
"Transform": {
"posX": 1.4,
"posY": 2.866,
"posZ": -13.4,
"posX": 1.6,
"posY": 4.5,
"posZ": -13.75,
"rotX": 0,
"rotY": 90,
"rotY": 0,
"rotZ": 0,
"scaleX": 6,
"scaleY": 2,
"scaleY": 7,
"scaleZ": 6
},
"Value": 0,

View File

@ -62,9 +62,9 @@ function initializeState()
resetTables()
-- count tokens in the bag
local chaosbag = chaosBagApi.findChaosBag()
local chaosBag = chaosBagApi.findChaosBag()
local tokens = {}
for _, v in ipairs(chaosbag.getObjects()) do
for _, v in ipairs(chaosBag.getObjects()) do
if v.name == "Bless" then
numInPlay.Bless = numInPlay.Bless + 1
elseif v.name == "Curse" then
@ -113,8 +113,14 @@ end
function onObjectDrop(_, object)
if not isBlurseToken(object) then return end
trackBagChange = true
Wait.time(function() trackBagChange = false end, 1)
-- check if object was dropped in chaos bag area
for _, zone in ipairs(object.getZones()) do
if zone.getName() == "ChaosBagZone" then
trackBagChange = true
Wait.time(function() trackBagChange = false end, 1)
return
end
end
end
-- handle manual returning of bless / curse tokens
@ -140,13 +146,13 @@ end
---------------------------------------------------------
function doRemove(color)
local chaosbag = chaosBagApi.findChaosBag()
local chaosBag = chaosBagApi.findChaosBag()
-- remove tokens from chaos bag
local count = { Bless = 0, Curse = 0 }
for _, v in ipairs(chaosbag.getObjects()) do
for _, v in ipairs(chaosBag.getObjects()) do
if v.name == "Bless" or v.name == "Curse" then
chaosbag.takeObject({
chaosBag.takeObject({
guid = v.guid,
position = { 0, 5, 0 },
callback_function = function(obj) obj.destruct() end
@ -228,14 +234,7 @@ function releasedToken(param)
break
end
end
if not updating then
updating = true
Wait.frames(function()
broadcastCount(param.type)
updateButtonLabels()
updating = false
end, 1)
end
updateDisplayAndBroadcast(param.type)
end
-- removes a token (called by cards that seal bless/curse tokens)
@ -248,13 +247,17 @@ function returnedToken(param)
break
end
end
updateDisplayAndBroadcast(param.type)
end
function updateDisplayAndBroadcast(type)
if not updating then
updating = true
Wait.frames(function()
broadcastCount(param.type)
broadcastCount(type)
updateButtonLabels()
updating = false
end, 1)
end, 5)
end
end
@ -274,10 +277,10 @@ function addToken(type)
end
function removeToken(type)
local chaosbag = chaosBagApi.findChaosBag()
local chaosBag = chaosBagApi.findChaosBag()
local tokens = {}
for _, v in ipairs(chaosbag.getObjects()) do
for _, v in ipairs(chaosBag.getObjects()) do
if v.name == type then
table.insert(tokens, v.guid)
end
@ -288,7 +291,7 @@ function removeToken(type)
return
end
chaosbag.takeObject({
chaosBag.takeObject({
guid = table.remove(tokens),
smooth = false,
callback_function = function(obj)
@ -353,52 +356,48 @@ function addMenuOptions(parameters)
sealedTokens[hoveredObject.getGUID()] = {}
end
function sealToken(type, playerColor, enemy)
local chaosbag = chaosBagApi.findChaosBag()
if chaosbag == nil then return end
local pos = enemy.getPosition()
function sealToken(type, playerColor, hoveredObject)
local chaosBag = chaosBagApi.findChaosBag()
for i, token in ipairs(chaosbag.getObjects()) do
for i, token in ipairs(chaosBag.getObjects()) do
if token.name == type then
chaosbag.takeObject({
position = { pos.x, pos.y + 1, pos.z },
return chaosBag.takeObject({
position = hoveredObject.getPosition() + Vector(0, 1, 0),
index = i - 1,
smooth = false,
callback_function = function(obj)
Wait.frames(function()
table.insert(sealedTokens[enemy.getGUID()], obj)
table.insert(tokensTaken[type], obj.getGUID())
printToColor("Sealing " .. type .. " token " .. formatTokenCount(type), playerColor)
end, 1)
table.insert(sealedTokens[hoveredObject.getGUID()], obj)
table.insert(tokensTaken[type], obj.getGUID())
tokenArrangerApi.layout()
updateDisplayAndBroadcast(type)
end
})
return
end
end
printToColor(type .. " token not found in bag", playerColor)
end
function releaseToken(type, playerColor, enemy)
local chaosbag = chaosBagApi.findChaosBag()
if chaosbag == nil then return end
local tokens = sealedTokens[enemy.getGUID()]
function releaseToken(type, playerColor, hoveredObject)
local chaosBag = chaosBagApi.findChaosBag()
local tokens = sealedTokens[hoveredObject.getGUID()]
if tokens == nil or #tokens == 0 then return end
for i, token in ipairs(tokens) do
if token ~= nil and token.getName() == type then
local guid = token.getGUID()
chaosbag.putObject(token)
chaosBag.putObject(token)
for j, v in ipairs(tokensTaken[type]) do
if v == guid then
table.remove(tokensTaken[type], j)
table.remove(tokens, i)
printToColor("Releasing " .. type .. " token" .. formatTokenCount(type), playerColor)
tokenArrangerApi.layout()
updateDisplayAndBroadcast(type)
return
end
end
end
end
printToColor(type .. " token not sealed on " .. enemy.getName(), playerColor)
printToColor(type .. " token not sealed on " .. hoveredObject.getName(), playerColor)
end
function none() end

View File

@ -44,6 +44,12 @@ do
return Global.call("removeChaosToken", id)
end
-- returns a chaos token to the bag and calls all relevant functions
---@param token TTSObject Chaos Token to return
ChaosBagApi.returnChaosTokenToBag = function(token)
return Global.call("returnChaosTokenToBag", token)
end
-- spawns the specified chaos token and puts it into the chaos bag
---@param id String ID of the chaos token
ChaosBagApi.spawnChaosToken = function(id)

View File

@ -252,6 +252,18 @@ function returnChaosTokens()
chaosTokens = {}
end
-- returns a single chaos token to the bag and calls respective functions
function returnChaosTokenToBag(token)
local name = token.getName()
local guid = token.getGUID()
local chaosBag = findChaosBag()
chaosBag.putObject(token)
tokenArrangerApi.layout()
if name == "Bless" or name == "Curse" then
blessCurseManagerApi.releasedToken(name, guid)
end
end
-- Checks to see if the chaos bag can be manipulated. If a player is searching the bag when tokens
-- are drawn or replaced a TTS bug can cause those tokens to vanish. Any functions which change the
-- contents of the bag should check this method before doing so.

View File

@ -149,6 +149,10 @@ function readBag()
end
end
function resetSealedTokens()
sealedTokens = {}
end
-- native event from TTS - used to update the context menu for cards like "Unrelenting"
function onHover()
if UPDATE_ON_HOVER then

View File

@ -213,8 +213,7 @@ function discardListOfObjects(objList)
end
-- put chaos tokens back into bag (e.g. Unrelenting)
elseif tokenChecker.isChaosToken(obj) then
local chaosBag = chaosBagApi.findChaosBag()
chaosBag.putObject(obj)
chaosBagApi.returnChaosTokenToBag(obj)
-- don't touch locked objects (like the table etc.)
elseif not obj.getLock() then
ownedObjects.Trash.putObject(obj)
@ -660,15 +659,23 @@ 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 obj.getGUID() ~= "4ee1f2" and -- table
if tokenChecker.isChaosToken(obj) then
chaosBagApi.returnChaosTokenToBag(obj)
elseif obj.getGUID() ~= "4ee1f2" and -- table
obj ~= self and
obj.type ~= "Deck" and
obj.type ~= "Card" and
obj.memo ~= nil and
obj.getLock() == false and
obj.getDescription() ~= "Action Token" and
not tokenChecker.isChaosToken(obj) then
obj.getDescription() ~= "Action Token" then
ownedObjects.Trash.putObject(obj)
end
end