From ca214f7ecdab7a8a1e31549c5b94c05eb5f1d2f6 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 4 Mar 2023 13:54:10 +0100 Subject: [PATCH] first batch of player cards updates --- src/chaosbag/BlessCurseManager.ttslua | 36 ++++++-- src/chaosbag/BlessCurseManagerApi.ttslua | 14 ++- src/core/Global.ttslua | 2 +- src/playercards/CardsThatSealTokens.ttslua | 88 +++++++++++++++++++ .../cards/CrystallineElderSign3.ttslua | 65 +------------- src/playercards/cards/DarkRitual.ttslua | 84 +----------------- src/playercards/cards/DayofReckoning.ttslua | 63 +------------ src/playercards/cards/FavoroftheMoon1.ttslua | 84 ++---------------- src/playercards/cards/FavoroftheSun1.ttslua | 84 ++---------------- .../cards/FluteoftheOuterGods4.ttslua | 84 ++---------------- src/playercards/cards/Nephthys4.ttslua | 84 ++---------------- src/playercards/cards/RadiantSmite1.ttslua | 84 +----------------- .../cards/RiteofSanctification.ttslua | 84 ++---------------- .../cards/SealoftheSeventhSign5.ttslua | 63 +------------ src/playercards/cards/SerpentsofYig.ttslua | 63 +------------ src/playercards/cards/ShardsoftheVoid3.ttslua | 48 ++-------- src/playercards/cards/ShieldofFaith2.ttslua | 84 ++---------------- .../cards/TheChthonianStone.ttslua | 69 ++------------- .../cards/TheChthonianStone3.ttslua | 69 ++------------- src/playercards/cards/TheCodexofAges.ttslua | 63 +------------ 20 files changed, 204 insertions(+), 1111 deletions(-) create mode 100644 src/playercards/CardsThatSealTokens.ttslua diff --git a/src/chaosbag/BlessCurseManager.ttslua b/src/chaosbag/BlessCurseManager.ttslua index c4a176d7..49257167 100644 --- a/src/chaosbag/BlessCurseManager.ttslua +++ b/src/chaosbag/BlessCurseManager.ttslua @@ -8,10 +8,11 @@ buttonParamaters.width = 700 buttonParamaters.height = 700 local altState = false -local MODE = { [false] = "Add / Remove", [true] = "Take / Return" } -local BUTTON_COLOR = { [false] = { 0.4, 0.4, 0.4 }, [true] = { 0.9, 0.9, 0.9 } } -local FONT_COLOR = { [false] = { 1, 1, 1 }, [true] = { 0, 0, 0 } } +local MODE = { [false] = "Add / Remove",[true] = "Take / Return" } +local BUTTON_COLOR = { [false] = { 0.4, 0.4, 0.4 },[true] = { 0.9, 0.9, 0.9 } } +local FONT_COLOR = { [false] = { 1, 1, 1 },[true] = { 0, 0, 0 } } local whitespace = " " +local updating --------------------------------------------------------- -- creating buttons and menus + initializing tables @@ -122,8 +123,8 @@ function doRemove(color) end end - broadcastToColor("Removed " .. count["Bless"] .. " Bless and " .. - count["Curse"] .. " Curse tokens from the chaos bag.", color, "White") + broadcastToColor("Removed " .. count.Bless .. " Bless and " .. + count.Curse .. " Curse tokens from the chaos bag.", color, "White") broadcastToColor("Removed " .. removeType("Bless") .. " Bless and " .. removeType("Curse") .. " Curse tokens from play.", color, "White") @@ -239,6 +240,31 @@ function getTokenCount(type) return "(" .. (numInPlay[type] - #tokensTaken[type]) .. "/" .. #tokensTaken[type] .. ")" end +-- called by cards that seal bless/curse tokens +---@param param Table This contains the type and guid of the sealed token +function sealedToken(param) + table.insert(tokensTaken[param.type], param.guid) + broadcastCount(param.type) +end + +-- called by cards that seal bless/curse tokens +---@param param Table This contains the type and guid of the released token +function releasedToken(param) + for i, v in ipairs(tokensTaken[param.type]) do + if v == param.guid then + table.remove(tokensTaken[param.type], i) + break + end + end + if not updating then + updating = true + Wait.time(function() + broadcastCount(param.type) + updating = false + end, 0.1) + end +end + --------------------------------------------------------- -- main functions: add, take and return --------------------------------------------------------- diff --git a/src/chaosbag/BlessCurseManagerApi.ttslua b/src/chaosbag/BlessCurseManagerApi.ttslua index 1f27cec3..0e535b6d 100644 --- a/src/chaosbag/BlessCurseManagerApi.ttslua +++ b/src/chaosbag/BlessCurseManagerApi.ttslua @@ -1,14 +1,24 @@ do local BlessCurseManagerApi = {} - local GUID = "5933fb" + local MANAGER_GUID = "5933fb" -- removes all taken tokens and resets the counts BlessCurseManagerApi.removeTakenTokensAndReset = function() - local BlessCurseManager = getObjectFromGUID(GUID) + local BlessCurseManager = getObjectFromGUID(MANAGER_GUID) Wait.time(function() BlessCurseManager.call("removeType", "Bless") end, 0.05) Wait.time(function() BlessCurseManager.call("removeType", "Curse") end, 0.10) Wait.time(function() BlessCurseManager.call("doReset", "White") end, 0.15) end + -- updates the internal count (called by cards that seal bless/curse tokens) + BlessCurseManagerApi.sealedToken = function(type, guid) + getObjectFromGUID(MANAGER_GUID).call("sealedToken", { type = type, guid = guid }) + end + + -- updates the internal count (called by cards that seal bless/curse tokens) + BlessCurseManagerApi.releasedToken = function(type, guid) + getObjectFromGUID(MANAGER_GUID).call("releasedToken", { type = type, guid = guid }) + end + return BlessCurseManagerApi end diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 869d72ad..1bb55cfa 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -232,7 +232,7 @@ end -- chaos token drawing --------------------------------------------------------- --- checks scripting zone for chaos bag +-- checks scripting zone for chaos bag (also called by a lot of objects!) function findChaosBag() local chaosbag_zone = getObjectFromGUID("83ef06") diff --git a/src/playercards/CardsThatSealTokens.ttslua b/src/playercards/CardsThatSealTokens.ttslua new file mode 100644 index 00000000..dd994cfd --- /dev/null +++ b/src/playercards/CardsThatSealTokens.ttslua @@ -0,0 +1,88 @@ +local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") + +function onSave() return JSON.encode(sealedTokens) end + +function onLoad(savedData) + sealedTokens = JSON.decode(savedData) or {} + ID_URL_MAP = Global.getTable("ID_URL_MAP") + + -- add menu items + if SHOW_SINGLE_RELEASE then + self.addContextMenuItem("Release token", releaseOneToken) + elseif SHOW_MULTI_RELEASE then + self.addContextMenuItem("Release " .. SHOW_MULTI_RELEASE .. " token(s)", function(playerColor) + for i = 1, SHOW_MULTI_RELEASE do + releaseOneToken(playerColor) + end + end) + else + self.addContextMenuItem("Release token(s)", releaseTokens) + end + + for _, map in pairs(ID_URL_MAP) do + if VALID_TOKENS[map.name] ~= nil then + self.addContextMenuItem("Seal " .. map.name, function(playerColor) sealToken(map.name, playerColor) end) + end + end +end + +-- seals the named token on this card +function sealToken(name, playerColor) + local chaosbag = Global.call("findChaosBag") + for i, obj in ipairs(chaosbag.getObjects()) do + if obj.name == name then + chaosbag.takeObject({ + position = self.getPosition() + Vector(0, 0.5 + 0.1 * #sealedTokens, 0), + rotation = self.getRotation(), + index = i - 1, + smooth = false, + callback_function = function(token) + local guid = token.getGUID() + table.insert(sealedTokens, guid) + + if name == "Bless" or name == "Curse" then + blessCurseManagerApi.sealedToken(name, guid) + end + end + }) + return + end + end + printToColor(name .. " token not found in chaos bag", playerColor) +end + +-- release the last sealed token +function releaseOneToken(playerColor) + if sealedTokens == {} then + printToColor("No sealed token(s) found", playerColor) + else + printToColor("Releasing token", playerColor) + local chaosbag = Global.call("findChaosBag") + local guid = table.remove(sealedTokens) + local token = getObjectFromGUID(guid) + local name = token.getName() + chaosbag.putObject(token) + if name == "Bless" or name == "Curse" then + blessCurseManagerApi.releasedToken(name, guid) + end + end +end + +-- releases all sealed tokens +function releaseTokens(playerColor) + if #sealedTokens == 0 then + printToColor("No sealed token(s) found", playerColor) + else + printToColor("Releasing token(s)", playerColor) + local chaosbag = Global.call("findChaosBag") + for _, guid in ipairs(sealedTokens) do + local token = getObjectFromGUID(guid) + local name = token.getName() + chaosbag.putObject(token) + if name == "Bless" or name == "Curse" then + blessCurseManagerApi.releasedToken(name, guid) + end + end + sealedTokens = {} + end +end diff --git a/src/playercards/cards/CrystallineElderSign3.ttslua b/src/playercards/cards/CrystallineElderSign3.ttslua index ee47beff..f0652701 100644 --- a/src/playercards/cards/CrystallineElderSign3.ttslua +++ b/src/playercards/cards/CrystallineElderSign3.ttslua @@ -1,65 +1,6 @@ VALID_TOKENS = { - ["+1"]=true, - ["Elder Sign"]=true + ["+1"] = true, + ["Elder Sign"] = true } -function onload() - chaosbag = getChaosBag() - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end - - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if VALID_TOKENS[name] ~= nil then - self.addContextMenuItem("Seal " .. name, function(playerColor) sealToken(url, playerColor) end) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) -end - -function releaseTokens(playerColor) - printToColor("Releasing token", playerColor) - for i,obj in ipairs(sealedTokens) do - chaosbag.putObject(obj) - end - sealedTokens = { } -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/DarkRitual.ttslua b/src/playercards/cards/DarkRitual.ttslua index 000cd744..6cec94f7 100644 --- a/src/playercards/cards/DarkRitual.ttslua +++ b/src/playercards/cards/DarkRitual.ttslua @@ -1,81 +1,5 @@ -function onload() - mode = "Curse" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Curse"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/DayofReckoning.ttslua b/src/playercards/cards/DayofReckoning.ttslua index 447d6743..46cdab93 100644 --- a/src/playercards/cards/DayofReckoning.ttslua +++ b/src/playercards/cards/DayofReckoning.ttslua @@ -1,60 +1,5 @@ -function onload() - chaosbag = getChaosBag() - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Elder Sign"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == "Elder Sign" then - self.addContextMenuItem("Seal Elder Sign", function(playerColor) sealToken(url, playerColor) end) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) -end - -function releaseTokens(playerColor) - printToColor("Releasing token", playerColor) - for i,obj in ipairs(sealedTokens) do - chaosbag.putObject(obj) - end - sealedTokens = { } -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/FavoroftheMoon1.ttslua b/src/playercards/cards/FavoroftheMoon1.ttslua index 000cd744..1413142b 100644 --- a/src/playercards/cards/FavoroftheMoon1.ttslua +++ b/src/playercards/cards/FavoroftheMoon1.ttslua @@ -1,81 +1,7 @@ -function onload() - mode = "Curse" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Curse"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end +SHOW_SINGLE_RELEASE = true -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/FavoroftheSun1.ttslua b/src/playercards/cards/FavoroftheSun1.ttslua index ab3fe3f1..8c91d129 100644 --- a/src/playercards/cards/FavoroftheSun1.ttslua +++ b/src/playercards/cards/FavoroftheSun1.ttslua @@ -1,81 +1,7 @@ -function onload() - mode = "Bless" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Bless"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end +SHOW_SINGLE_RELEASE = true -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/FluteoftheOuterGods4.ttslua b/src/playercards/cards/FluteoftheOuterGods4.ttslua index 000cd744..1413142b 100644 --- a/src/playercards/cards/FluteoftheOuterGods4.ttslua +++ b/src/playercards/cards/FluteoftheOuterGods4.ttslua @@ -1,81 +1,7 @@ -function onload() - mode = "Curse" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Curse"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end +SHOW_SINGLE_RELEASE = true -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/Nephthys4.ttslua b/src/playercards/cards/Nephthys4.ttslua index ab3fe3f1..b0550977 100644 --- a/src/playercards/cards/Nephthys4.ttslua +++ b/src/playercards/cards/Nephthys4.ttslua @@ -1,81 +1,7 @@ -function onload() - mode = "Bless" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Bless"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end +SHOW_MULTI_RELEASE = 3 -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/RadiantSmite1.ttslua b/src/playercards/cards/RadiantSmite1.ttslua index ab3fe3f1..f4f0ed6d 100644 --- a/src/playercards/cards/RadiantSmite1.ttslua +++ b/src/playercards/cards/RadiantSmite1.ttslua @@ -1,81 +1,5 @@ -function onload() - mode = "Bless" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Bless"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/RiteofSanctification.ttslua b/src/playercards/cards/RiteofSanctification.ttslua index ab3fe3f1..8c91d129 100644 --- a/src/playercards/cards/RiteofSanctification.ttslua +++ b/src/playercards/cards/RiteofSanctification.ttslua @@ -1,81 +1,7 @@ -function onload() - mode = "Bless" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Bless"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end +SHOW_SINGLE_RELEASE = true -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/SealoftheSeventhSign5.ttslua b/src/playercards/cards/SealoftheSeventhSign5.ttslua index b24b7903..5cf8e709 100644 --- a/src/playercards/cards/SealoftheSeventhSign5.ttslua +++ b/src/playercards/cards/SealoftheSeventhSign5.ttslua @@ -1,60 +1,5 @@ -function onload() - chaosbag = getChaosBag() - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Auto-fail"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == "Auto-fail" then - self.addContextMenuItem("Seal Auto-fail", function(playerColor) sealToken(url, playerColor) end) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) -end - -function releaseTokens(playerColor) - printToColor("Releasing token", playerColor) - for i,obj in ipairs(sealedTokens) do - chaosbag.putObject(obj) - end - sealedTokens = { } -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/SerpentsofYig.ttslua b/src/playercards/cards/SerpentsofYig.ttslua index 447d6743..46cdab93 100644 --- a/src/playercards/cards/SerpentsofYig.ttslua +++ b/src/playercards/cards/SerpentsofYig.ttslua @@ -1,60 +1,5 @@ -function onload() - chaosbag = getChaosBag() - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Elder Sign"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == "Elder Sign" then - self.addContextMenuItem("Seal Elder Sign", function(playerColor) sealToken(url, playerColor) end) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) -end - -function releaseTokens(playerColor) - printToColor("Releasing token", playerColor) - for i,obj in ipairs(sealedTokens) do - chaosbag.putObject(obj) - end - sealedTokens = { } -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/ShardsoftheVoid3.ttslua b/src/playercards/cards/ShardsoftheVoid3.ttslua index c935705c..00808f9f 100644 --- a/src/playercards/cards/ShardsoftheVoid3.ttslua +++ b/src/playercards/cards/ShardsoftheVoid3.ttslua @@ -1,45 +1,7 @@ -function onload() - chaosbag = getChaosBag() - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["0"] = true +} - -- add menu items - self.clearContextMenu() - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == "0" then - self.addContextMenuItem("Seal 0", function(playerColor) sealToken(url, playerColor) end) - end - end -end +SHOW_SINGLE_RELEASE = true -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/ShieldofFaith2.ttslua b/src/playercards/cards/ShieldofFaith2.ttslua index ab3fe3f1..8c91d129 100644 --- a/src/playercards/cards/ShieldofFaith2.ttslua +++ b/src/playercards/cards/ShieldofFaith2.ttslua @@ -1,81 +1,7 @@ -function onload() - mode = "Bless" - chaosbag = getChaosBag() - manager = getObjectFromGUID("5933fb") - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Bless"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens, true) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == mode then - self.addContextMenuItem("Seal " .. mode, function(playerColor) sealToken(url, playerColor) end, true) - end - end -end +SHOW_SINGLE_RELEASE = true -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) - local guid = obj.getGUID() - local tokensTaken = manager.getVar("tokensTaken") - table.insert(tokensTaken[mode], guid) - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Sealing " .. mode .. " token " .. manager.call("getTokenCount")) -end - -function releaseTokens(playerColor) - if #sealedTokens == 0 then return end - local token = sealedTokens[#sealedTokens] - if token ~= nil then - local guid = token.getGUID() - chaosbag.putObject(token) - local tokensTaken = manager.getVar("tokensTaken") - for i,v in ipairs(tokensTaken[mode]) do - if v == guid then - table.remove(tokensTaken[mode], i) - break - end - end - manager.setVar("tokensTaken", tokensTaken) - manager.setVar("mode", mode) - printToAll("Releasing " .. mode .. " token" .. manager.call("getTokenCount")) - end - - table.remove(sealedTokens) -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/TheChthonianStone.ttslua b/src/playercards/cards/TheChthonianStone.ttslua index b7aabf11..6898ac09 100644 --- a/src/playercards/cards/TheChthonianStone.ttslua +++ b/src/playercards/cards/TheChthonianStone.ttslua @@ -1,67 +1,8 @@ VALID_TOKENS = { - Skull=true, - Cultist=true, - Tablet=true, - ["Elder Thing"]=true + ["Skull"] = true, + ["Cultist"] = true, + ["Tablet"] = true, + ["Elder Thing"] = true, } -function onload() - chaosbag = getChaosBag() - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end - - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if VALID_TOKENS[name] ~= nil then - self.addContextMenuItem("Seal " .. name, function(playerColor) sealToken(url, playerColor) end) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) -end - -function releaseTokens(playerColor) - printToColor("Releasing token", playerColor) - for i,obj in ipairs(sealedTokens) do - chaosbag.putObject(obj) - end - sealedTokens = { } -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/TheChthonianStone3.ttslua b/src/playercards/cards/TheChthonianStone3.ttslua index b7aabf11..6898ac09 100644 --- a/src/playercards/cards/TheChthonianStone3.ttslua +++ b/src/playercards/cards/TheChthonianStone3.ttslua @@ -1,67 +1,8 @@ VALID_TOKENS = { - Skull=true, - Cultist=true, - Tablet=true, - ["Elder Thing"]=true + ["Skull"] = true, + ["Cultist"] = true, + ["Tablet"] = true, + ["Elder Thing"] = true, } -function onload() - chaosbag = getChaosBag() - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end - - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if VALID_TOKENS[name] ~= nil then - self.addContextMenuItem("Seal " .. name, function(playerColor) sealToken(url, playerColor) end) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) -end - -function releaseTokens(playerColor) - printToColor("Releasing token", playerColor) - for i,obj in ipairs(sealedTokens) do - chaosbag.putObject(obj) - end - sealedTokens = { } -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens") diff --git a/src/playercards/cards/TheCodexofAges.ttslua b/src/playercards/cards/TheCodexofAges.ttslua index 447d6743..46cdab93 100644 --- a/src/playercards/cards/TheCodexofAges.ttslua +++ b/src/playercards/cards/TheCodexofAges.ttslua @@ -1,60 +1,5 @@ -function onload() - chaosbag = getChaosBag() - sealedTokens = { } - IMAGE_TOKEN_MAP = { } - for i,v in pairs(Global.getVar("IMAGE_TOKEN_MAP")) do - IMAGE_TOKEN_MAP[i] = v - end +VALID_TOKENS = { + ["Elder Sign"] = true +} - -- add menu items - self.clearContextMenu() - self.addContextMenuItem("Release Token", releaseTokens) - for url,name in pairs(IMAGE_TOKEN_MAP) do - if name == "Elder Sign" then - self.addContextMenuItem("Seal Elder Sign", function(playerColor) sealToken(url, playerColor) end) - end - end -end - -function sealToken(url, playerColor) - local pos = self.getPosition() - - local name = IMAGE_TOKEN_MAP[url] - for i,obj in ipairs(chaosbag.getObjects()) do - if obj.name == name then - chaosbag.takeObject({ - position={ pos.x, pos.y + 1, pos.z }, - index=i-1, - smooth=false, - callback_function=_sealToken - }) - return - end - end - printToColor(name .. " token not found in bag", playerColor) -end - -function _sealToken(obj) - table.insert(sealedTokens, obj) -end - -function releaseTokens(playerColor) - printToColor("Releasing token", playerColor) - for i,obj in ipairs(sealedTokens) do - chaosbag.putObject(obj) - end - sealedTokens = { } -end - -function getChaosBag() - local items = getObjectFromGUID("83ef06").getObjects() - local chaosbag = nil - for i,v in ipairs(items) do - if v.getDescription() == "Chaos Bag" then - chaosbag = getObjectFromGUID(v.getGUID()) - break - end - end - if chaosbag == nil then printToAll("No chaos bag found") end - return chaosbag -end +require("playercards/CardsThatSealTokens")