2021-01-02 22:49:38 -05:00
|
|
|
function onload()
|
2021-02-13 12:12:29 -05:00
|
|
|
mode = "Bless"
|
2021-01-02 22:49:38 -05:00
|
|
|
chaosbag = getChaosBag()
|
2021-02-13 12:12:29 -05:00
|
|
|
manager = getObjectFromGUID("5933fb")
|
2021-01-02 22:49:38 -05:00
|
|
|
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()
|
2021-02-13 12:12:29 -05:00
|
|
|
self.addContextMenuItem("Release Token", releaseTokens, true)
|
2021-01-02 22:49:38 -05:00
|
|
|
for url,name in pairs(IMAGE_TOKEN_MAP) do
|
2021-02-13 12:12:29 -05:00
|
|
|
if name == mode then
|
2021-04-25 09:57:58 -04:00
|
|
|
self.addContextMenuItem("Seal 2 " .. mode, function(playerColor) sealToken(url, playerColor) end, true)
|
2021-01-02 22:49:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function sealToken(url, playerColor)
|
|
|
|
local pos = self.getPosition()
|
|
|
|
|
|
|
|
local name = IMAGE_TOKEN_MAP[url]
|
2021-04-25 09:57:58 -04:00
|
|
|
local indexes = {}
|
|
|
|
|
2021-01-02 22:49:38 -05:00
|
|
|
for i,obj in ipairs(chaosbag.getObjects()) do
|
|
|
|
if obj.name == name then
|
2021-04-25 09:57:58 -04:00
|
|
|
table.insert(indexes, obj.index)
|
2021-01-02 22:49:38 -05:00
|
|
|
end
|
|
|
|
end
|
2021-04-25 09:57:58 -04:00
|
|
|
if #indexes < 2 then
|
|
|
|
printToColor("Fewer than 2 " .. name .. " tokens in bag", playerColor)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
table.sort(indexes)
|
|
|
|
chaosbag.takeObject({
|
|
|
|
position={ pos.x, pos.y + 1, pos.z },
|
|
|
|
index=indexes[#indexes],
|
|
|
|
smooth=false,
|
|
|
|
callback_function=_sealToken
|
|
|
|
})
|
|
|
|
chaosbag.takeObject({
|
|
|
|
position={ pos.x, pos.y + 2, pos.z },
|
|
|
|
index=indexes[#indexes-1],
|
|
|
|
smooth=false,
|
|
|
|
callback_function=_sealToken
|
|
|
|
})
|
2021-01-02 22:49:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function _sealToken(obj)
|
|
|
|
table.insert(sealedTokens, obj)
|
2021-02-13 12:12:29 -05:00
|
|
|
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"))
|
2021-01-02 22:49:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function releaseTokens(playerColor)
|
2021-02-13 12:12:29 -05:00
|
|
|
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"))
|
2021-01-02 22:49:38 -05:00
|
|
|
end
|
2021-02-13 12:12:29 -05:00
|
|
|
|
|
|
|
table.remove(sealedTokens)
|
2021-01-02 22:49:38 -05:00
|
|
|
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
|