diff --git a/config.json b/config.json index 58c64c6b..4c048c32 100644 --- a/config.json +++ b/config.json @@ -40,7 +40,7 @@ "Decoration-Coin.180a23", "Panel.463022", "TentacleStand.7bff34", - "ScriptingTrigger.83ef06", + "ChaosBagZone.83ef06", "Cluetokens.11e0cf", "Doomtokens.b015d8", "DoomCounter.85c4c6", diff --git a/objects/ScriptingTrigger.83ef06.json b/objects/ChaosBagZone.83ef06.json similarity index 85% rename from objects/ScriptingTrigger.83ef06.json rename to objects/ChaosBagZone.83ef06.json index 6e1865dd..1d1673bd 100644 --- a/objects/ScriptingTrigger.83ef06.json +++ b/objects/ChaosBagZone.83ef06.json @@ -26,21 +26,21 @@ "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, "XmlUI": "" -} +} \ No newline at end of file diff --git a/src/chaosbag/BlessCurseManager.ttslua b/src/chaosbag/BlessCurseManager.ttslua index 3c12c9b1..6c1c8260 100644 --- a/src/chaosbag/BlessCurseManager.ttslua +++ b/src/chaosbag/BlessCurseManager.ttslua @@ -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 diff --git a/src/chaosbag/ChaosBagApi.ttslua b/src/chaosbag/ChaosBagApi.ttslua index 2b3c95f9..58ebdf9e 100644 --- a/src/chaosbag/ChaosBagApi.ttslua +++ b/src/chaosbag/ChaosBagApi.ttslua @@ -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) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 8ee04751..5ac7c717 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -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. diff --git a/src/playercards/CardsThatSealTokens.ttslua b/src/playercards/CardsThatSealTokens.ttslua index f0485fe5..2eb338dd 100644 --- a/src/playercards/CardsThatSealTokens.ttslua +++ b/src/playercards/CardsThatSealTokens.ttslua @@ -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 diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index aa104201..2187ed20 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -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