use require()

This commit is contained in:
Chr1Z93 2022-11-13 00:43:32 +01:00
parent 89545c6ee9
commit 6cc7efb9a4
3 changed files with 345 additions and 789 deletions

View File

@ -34,7 +34,7 @@
"LayoutGroupSortIndex": 0,
"Locked": true,
"LuaScriptState": "false",
"LuaScript_path": "BlessCurseManager.5933fb.ttslua",
"LuaScript": "require(\"tokens/BlessCurseManager\")",
"MeasureMovement": false,
"Name": "Custom_Token",
"Nickname": "Bless/Curse Manager",

View File

@ -1,475 +0,0 @@
-- Bless / Curse Manager
-- updated by: Chr1Z
-- made by: Tikatoy
-- description: helps with adding / removing and sealing of bless and curse tokens
information = {
version = "3.5",
last_updated = "12.11.2022"
}
local IMAGE_URL = {
Bless = "http://cloud-3.steamusercontent.com/ugc/1655601092778627699/339FB716CB25CA6025C338F13AFDFD9AC6FA8356/",
Curse = "http://cloud-3.steamusercontent.com/ugc/1655601092778636039/2A25BD38E8C44701D80DD96BF0121DA21843672E/"
}
-- common button parameters
local buttonParamaters = {}
buttonParamaters.function_owner = self
buttonParamaters.color = { 0, 0, 0, 0 }
buttonParamaters.width = 700
buttonParamaters.height = 700
local tokenarranger = getObjectFromGUID("022907")
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 = " "
---------------------------------------------------------
-- creating buttons and menus + initializing tables
---------------------------------------------------------
function onSave() return JSON.encode(TOGGLE) end
function onLoad(saved_state)
if saved_state ~= nil then
TOGGLE = JSON.decode(saved_state)
else
TOGGLE = false
end
-- index: 0 - bless
buttonParamaters.click_function = "clickBless"
buttonParamaters.position = { -1.03, 0.05, 0.46 }
self.createButton(buttonParamaters)
-- index: 1 - curse
buttonParamaters.click_function = "clickCurse"
buttonParamaters.position[1] = -buttonParamaters.position[1]
self.createButton(buttonParamaters)
-- index: 2 - alternative mode (take / return)
buttonParamaters.click_function = "enableAlt"
buttonParamaters.width = 900
buttonParamaters.height = 210
buttonParamaters.position = { -1.03, 0.05, -0.85 }
self.createButton(buttonParamaters)
-- index: 3 - default mode (add / remove)
buttonParamaters.click_function = "enableDefault"
buttonParamaters.position[1] = -buttonParamaters.position[1]
self.createButton(buttonParamaters)
-- load labels, tooltips and colors
updateButtons()
-- context menu
self.addContextMenuItem("Remove all", doRemove)
self.addContextMenuItem("Reset", doReset)
self.addContextMenuItem("More Information", function()
printToAll("------------------------------", "White")
printToAll("Bless / Curse Manager v" .. information["version"] .. " by Chr1Z", "Orange")
printToAll("last updated: " .. information["last_updated"], "White")
printToAll("original by Tikatoy", "White")
end)
-- hotkeys
addHotkey("Bless Curse Status", printStatus, false)
addHotkey("Wendy's Menu", addMenuOptions, false)
-- initializing tables
numInPlay = { Bless = 0, Curse = 0 }
tokensTaken = { Bless = {}, Curse = {} }
sealedTokens = {}
Wait.time(initializeState, 1)
-- feedback for token arranger
if tokenarranger then
print("Bless/Curse Manager will update the Token Arranger automatically.")
print("If you remove the Token Arranger, save and reload before continuing.")
end
end
function initializeState()
-- count tokens in the bag
local chaosbag = getChaosBag()
if chaosbag == nil then return end
local tokens = {}
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == "Bless" then
numInPlay.Bless = numInPlay.Bless + 1
elseif v.name == "Curse" then
numInPlay.Curse = numInPlay.Curse + 1
end
end
-- find tokens in the play area
for _, obj in ipairs(getObjects()) do
local pos = obj.getPosition()
if pos.x > -50 and pos.x < 50 and pos.z > 8 and pos.z < 50 then
if obj.getName() == "Bless" then
table.insert(tokensTaken.Bless, obj.getGUID())
numInPlay.Bless = numInPlay.Bless + 1
elseif obj.getName() == "Curse" then
table.insert(tokensTaken.Curse, obj.getGUID())
numInPlay.Curse = numInPlay.Curse + 1
end
end
end
print("Bless Tokens " .. getTokenCount("Bless"))
print("Curse Tokens " .. getTokenCount("Curse"))
end
function printStatus(color)
broadcastToColor("Curse Tokens " .. getTokenCount("Curse"), color, "White")
broadcastToColor("Bless Tokens " .. getTokenCount("Bless"), color, "White")
end
-- context menu function 1
function doRemove(color)
local chaosbag = getChaosBag()
if chaosbag == nil then
broadcastToAll("Chaos bag not found!", "Red")
return
end
-- remove tokens from chaos bag
local count = { Bless = 0, Curse = 0 }
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == "Bless" or v.name == "Curse" then
chaosbag.takeObject({
guid = v.guid,
position = { 0, 5, 0 },
callback_function = function(obj) obj.destruct() end
})
count[v.name] = count[v.name] + 1
end
end
broadcastToColor("Removed " .. count["Bless"] .. " Bless and " ..
count["Curse"] .. " Curse tokens from the chaos bag.", color, "White")
-- removing tokens that were 'taken'
local function removeType(type)
local count = 0
for _, guid in ipairs(tokensTaken[type]) do
local token = getObjectFromGUID(guid)
if token ~= nil then
token.destruct()
count = count + 1
end
end
return count
end
broadcastToColor("Removed " .. removeType("Bless") .. " Bless and " ..
removeType("Curse") .. " Curse tokens from play.", color, "White")
doReset(color)
end
-- context menu function 2
function doReset(color)
-- delete previously pulled out tokens by the token arranger
if tokenarranger then
for _, token in ipairs(getObjectsWithTag(tokenarranger.getVar("TO_DELETE_TAG"))) do
token.destruct()
end
end
playerColor = color
numInPlay = { Bless = 0, Curse = 0 }
tokensTaken = { Bless = {}, Curse = {} }
initializeState()
updateTokenArranger()
end
---------------------------------------------------------
-- click functions
---------------------------------------------------------
-- click function 1
function clickBless(_, color, isRightClick)
playerColor = color
callFunctions("Bless", isRightClick)
end
-- click function 2
function clickCurse(_, color, isRightClick)
playerColor = color
callFunctions("Curse", isRightClick)
end
-- click function 3
function enableAlt()
if TOGGLE then return end
TOGGLE = not TOGGLE
updateButtons()
end
-- click function 4
function enableDefault()
if not TOGGLE then return end
TOGGLE = not TOGGLE
updateButtons()
end
---------------------------------------------------------
-- called functions
---------------------------------------------------------
function updateButtons()
self.editButton({
index = 0,
tooltip = MODE[TOGGLE] .. " Bless"
})
self.editButton({
index = 1,
tooltip = MODE[TOGGLE] .. " Curse"
})
self.editButton({
index = 2,
label = whitespace .. MODE[true] .. (TOGGLE and " ✓" or whitespace) .. " ",
color = BUTTON_COLOR[not TOGGLE],
font_color = FONT_COLOR[not TOGGLE]
})
self.editButton({
index = 3,
label = whitespace .. MODE[false] .. (TOGGLE and whitespace or " ✓") .. " ",
color = BUTTON_COLOR[TOGGLE],
font_color = FONT_COLOR[TOGGLE]
})
end
-- function that is called by click_functions 1+2 and calls the other functions
function callFunctions(token, isRightClick)
local success
if not TOGGLE then
if isRightClick then
success = takeToken(token, true)
else
success = addToken(token)
end
else
if isRightClick then
success = returnToken(token)
else
success = takeToken(token, false)
end
end
if success ~= 0 then updateTokenArranger() end
end
UPDATING = false
function updateTokenArranger()
if tokenarranger and not UPDATING then
UPDATING = true
Wait.time(function()
UPDATING = false
tokenarranger.call("layout")
end, 1.5)
end
end
function getChaosBag()
local zone = getObjectFromGUID("83ef06")
if zone == nil then printToAll("Zone for chaosbag not found!", "Red") return end
local items = zone.getObjects()
local chaosbag = nil
for _, v in ipairs(items) do
if v.getDescription() == "Chaos Bag" then
chaosbag = getObjectFromGUID(v.getGUID())
break
end
end
if chaosbag == nil then printToColor("No chaos bag found", playerColor) end
return chaosbag
end
function getTokenCount(type)
if type == nil then type = mode end
return "(" .. (numInPlay[type] - #tokensTaken[type]) .. "/" .. #tokensTaken[type] .. ")"
end
---------------------------------------------------------
-- main functions: add, take and return
---------------------------------------------------------
function addToken(type)
if numInPlay[type] == 10 then
printToColor("10 tokens already in play, not adding any.", playerColor)
return 0
end
return spawnToken(type)
end
function spawnToken(type)
local chaosbag = getChaosBag()
if chaosbag == nil then
return 0
end
local pos = chaosbag.getPosition()
local obj = spawnObject({
type = 'Custom_Tile',
position = { pos.x, pos.y + 1, pos.z },
callback_function = function(obj)
obj.setName(type)
chaosbag.putObject(obj)
numInPlay[type] = numInPlay[type] + 1
printToAll("Adding " .. type .. " token " .. getTokenCount(type))
end
})
obj.setCustomObject({
type = 2,
image = IMAGE_URL[type],
thickness = 0.1,
})
obj.scale { 0.81, 1, 0.81 }
end
function takeToken(type, remove)
local chaosbag = getChaosBag()
if chaosbag == nil then
broadcastToAll("Chaos bag not found!", "Red")
return 0
end
if not remove and not SEAL_CARD_MESSAGE then
broadcastToColor("For sealing tokens on cards try right-clicking on the card for seal options.", playerColor)
SEAL_CARD_MESSAGE = true
end
local tokens = {}
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == type then
table.insert(tokens, v.guid)
end
end
if #tokens == 0 then
printToColor("No " .. type .. " tokens in the chaos bag.", playerColor)
return 0
end
local pos = self.getPosition() + Vector(-2, 0, 2.5)
if type == "Curse" then pos[3] = pos[3] - 5 end
chaosbag.takeObject({
guid = table.remove(tokens),
position = pos,
smooth = false,
callback_function = function(obj)
if remove then
numInPlay[type] = numInPlay[type] - 1
printToAll("Removing " .. type .. " token " .. getTokenCount(type))
obj.destruct()
else
table.insert(tokensTaken[type], obj.getGUID())
printToAll("Taking " .. type .. " token " .. getTokenCount(type))
end
end
})
end
function returnToken(type)
local guid = table.remove(tokensTaken[type])
if guid == nil then
printToColor("No " .. type .. " tokens to return", playerColor)
return 0
end
local token = getObjectFromGUID(guid)
if token == nil then
printToColor("Couldn't find token " .. guid .. ", not returning to bag", playerColor)
return 0
end
local chaosbag = getChaosBag()
if chaosbag == nil then
return 0
end
chaosbag.putObject(token)
printToAll("Returning " .. type .. " token " .. getTokenCount(type))
end
---------------------------------------------------------
-- Wendy Menu (context menu for cards on hotkey press)
---------------------------------------------------------
function addMenuOptions(playerColor, hoveredObject)
if hoveredObject == nil or hoveredObject.getVar("MENU_ADDED") == true then return end
if hoveredObject.tag ~= "Card" then
broadcastToColor("Right-click seal options can only be added to cards", playerColor)
return
end
hoveredObject.addContextMenuItem("Seal Bless", function(color)
sealToken("Bless", color, hoveredObject)
updateTokenArranger()
end, true)
hoveredObject.addContextMenuItem("Release Bless", function(color)
releaseToken("Bless", color, hoveredObject)
updateTokenArranger()
end, true)
hoveredObject.addContextMenuItem("Seal Curse", function(color)
sealToken("Curse", color, hoveredObject)
updateTokenArranger()
end, true)
hoveredObject.addContextMenuItem("Release Curse", function(color)
releaseToken("Curse", color, hoveredObject)
updateTokenArranger()
end, true)
broadcastToColor("Right-click seal options added to " .. hoveredObject.getName(), playerColor)
hoveredObject.setVar("MENU_ADDED", true)
sealedTokens[hoveredObject.getGUID()] = {}
end
function sealToken(type, color, enemy)
local chaosbag = getChaosBag()
if chaosbag == nil then return end
local pos = enemy.getPosition()
for i, token in ipairs(chaosbag.getObjects()) do
if token.name == type then
chaosbag.takeObject({
position = { pos.x, pos.y + 1, pos.z },
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 " .. getTokenCount(type), color)
end, 1)
end
})
return
end
end
printToColor(type .. " token not found in bag", color)
end
function releaseToken(type, color, enemy)
local chaosbag = getChaosBag()
if chaosbag == nil then return end
local tokens = sealedTokens[enemy.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)
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" .. getTokenCount(type), color)
return
end
end
end
end
printToColor(type .. " token not sealed on " .. enemy.getName(), color)
end

View File

@ -1,139 +1,101 @@
BLESS_COLOR = { r = 0.3, g = 0.25, b = 0.09 }
CURSE_COLOR = { r = 0.2, g = 0.08, b = 0.24 }
MIN_VALUE = 1
MAX_VALUE = 10
IMAGE_URL = {
-- Bless / Curse Manager
-- updated by: Chr1Z
-- made by: Tikatoy
-- description: helps with adding / removing and sealing of bless and curse tokens
information = {
version = "3.5",
last_updated = "12.11.2022"
}
local IMAGE_URL = {
Bless = "http://cloud-3.steamusercontent.com/ugc/1655601092778627699/339FB716CB25CA6025C338F13AFDFD9AC6FA8356/",
Curse = "http://cloud-3.steamusercontent.com/ugc/1655601092778636039/2A25BD38E8C44701D80DD96BF0121DA21843672E/"
}
function onload()
self.createButton({
label = "Add",
click_function = "addBlessToken",
function_owner = self,
position = { -2.3, 0.1, -0.5 },
height = 150,
width = 300,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = BLESS_COLOR
})
-- common button parameters
local buttonParamaters = {}
buttonParamaters.function_owner = self
buttonParamaters.color = { 0, 0, 0, 0 }
buttonParamaters.width = 700
buttonParamaters.height = 700
self.createButton({
label = "Remove",
click_function = "removeBlessToken",
function_owner = self,
position = { -0.9, 0.1, -0.5 },
height = 150,
width = 450,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = BLESS_COLOR
})
local tokenarranger = getObjectFromGUID("022907")
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 = " "
self.createButton({
label = "Take",
click_function = "takeBlessToken",
function_owner = self,
position = { 0.7, 0.1, -0.5 },
height = 150,
width = 350,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = BLESS_COLOR
})
---------------------------------------------------------
-- creating buttons and menus + initializing tables
---------------------------------------------------------
self.createButton({
label = "Return",
click_function = "returnBlessToken",
function_owner = self,
position = { 2.1, 0.1, -0.5 },
height = 150,
width = 400,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = BLESS_COLOR
})
function onSave() return JSON.encode(TOGGLE) end
self.createButton({
label = "Add",
click_function = "addCurseToken",
function_owner = self,
position = { -2.3, 0.1, 0.5 },
height = 150,
width = 300,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = CURSE_COLOR
})
function onLoad(saved_state)
if saved_state ~= nil then
TOGGLE = JSON.decode(saved_state)
else
TOGGLE = false
end
self.createButton({
label = "Remove",
click_function = "removeCurseToken",
function_owner = self,
position = { -0.9, 0.1, 0.5 },
height = 150,
width = 450,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = CURSE_COLOR
})
-- index: 0 - bless
buttonParamaters.click_function = "clickBless"
buttonParamaters.position = { -1.03, 0.05, 0.46 }
self.createButton(buttonParamaters)
self.createButton({
label = "Take",
click_function = "takeCurseToken",
function_owner = self,
position = { 0.7, 0.1, 0.5 },
height = 150,
width = 350,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = CURSE_COLOR
})
-- index: 1 - curse
buttonParamaters.click_function = "clickCurse"
buttonParamaters.position[1] = -buttonParamaters.position[1]
self.createButton(buttonParamaters)
self.createButton({
label = "Return",
click_function = "returnCurseToken",
function_owner = self,
position = { 2.1, 0.1, 0.5 },
height = 150,
width = 400,
scale = { x = 1.75, y = 1.75, z = 1.75 },
font_size = 100,
font_color = { r = 1, g = 1, b = 1 },
color = CURSE_COLOR
})
-- index: 2 - alternative mode (take / return)
buttonParamaters.click_function = "enableAlt"
buttonParamaters.width = 900
buttonParamaters.height = 210
buttonParamaters.position = { -1.03, 0.05, -0.85 }
self.createButton(buttonParamaters)
self.createButton({
label = "Reset", click_function = "doReset", function_owner = self,
position = { 0, 0, 1.8 }, rotation = { 0, 0, 0 }, height = 350, width = 800,
font_size = 250, color = { 0, 0, 0 }, font_color = { 1, 1, 1 }
})
-- index: 3 - default mode (add / remove)
buttonParamaters.click_function = "enableDefault"
buttonParamaters.position[1] = -buttonParamaters.position[1]
self.createButton(buttonParamaters)
-- load labels, tooltips and colors
updateButtons()
-- context menu
self.addContextMenuItem("Remove all", doRemove)
self.addContextMenuItem("Reset", doReset)
self.addContextMenuItem("More Information", function()
printToAll("------------------------------", "White")
printToAll("Bless / Curse Manager v" .. information["version"] .. " by Chr1Z", "Orange")
printToAll("last updated: " .. information["last_updated"], "White")
printToAll("original by Tikatoy", "White")
end)
-- hotkeys
addHotkey("Bless Curse Status", printStatus, false)
addHotkey("Wendy's Menu", addMenuOptions, false)
-- initializing tables
numInPlay = { Bless = 0, Curse = 0 }
tokensTaken = { Bless = {}, Curse = {} }
sealedTokens = {}
Wait.time(initializeState, 1)
addHotkey("Bless Curse Status", printStatus, false)
addHotkey("Wendy's Menu", addMenuOptions, false)
-- feedback for token arranger
if tokenarranger then
print("Bless/Curse Manager will update the Token Arranger automatically.")
print("If you remove the Token Arranger, save and reload before continuing.")
end
end
function initializeState()
playerColor = "White"
-- count tokens in the bag
local chaosbag = getChaosBag()
if chaosbag == nil then return end
local tokens = {}
for i, 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
@ -142,10 +104,9 @@ function initializeState()
end
-- find tokens in the play area
local objs = getObjects()
for i, obj in ipairs(objs) do
for _, obj in ipairs(getObjects()) do
local pos = obj.getPosition()
if (pos.x > -110 and pos.x < 44 and pos.z > -77 and pos.z < 77) then
if pos.x > -50 and pos.x < 50 and pos.z > 8 and pos.z < 50 then
if obj.getName() == "Bless" then
table.insert(tokensTaken.Bless, obj.getGUID())
numInPlay.Bless = numInPlay.Bless + 1
@ -156,172 +117,171 @@ function initializeState()
end
end
mode = "Bless"
print("Bless Tokens " .. getTokenCount())
mode = "Curse"
print("Curse Tokens " .. getTokenCount())
print("Bless Tokens " .. getTokenCount("Bless"))
print("Curse Tokens " .. getTokenCount("Curse"))
end
function printStatus(player_color, hovered_object, world_position, key_down_up)
mode = "Curse"
broadcastToColor("Curse Tokens " .. getTokenCount(), player_color)
mode = "Bless"
broadcastToColor("Bless Tokens " .. getTokenCount(), player_color)
function printStatus(color)
broadcastToColor("Curse Tokens " .. getTokenCount("Curse"), color, "White")
broadcastToColor("Bless Tokens " .. getTokenCount("Bless"), color, "White")
end
function doReset(_obj, _color, alt_click)
playerColor = _color
-- context menu function 1
function doRemove(color)
local chaosbag = getChaosBag()
if chaosbag == nil then
broadcastToAll("Chaos bag not found!", "Red")
return
end
-- remove tokens from chaos bag
local count = { Bless = 0, Curse = 0 }
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == "Bless" or v.name == "Curse" then
chaosbag.takeObject({
guid = v.guid,
position = { 0, 5, 0 },
callback_function = function(obj) obj.destruct() end
})
count[v.name] = count[v.name] + 1
end
end
broadcastToColor("Removed " .. count["Bless"] .. " Bless and " ..
count["Curse"] .. " Curse tokens from the chaos bag.", color, "White")
-- removing tokens that were 'taken'
local function removeType(type)
local count = 0
for _, guid in ipairs(tokensTaken[type]) do
local token = getObjectFromGUID(guid)
if token ~= nil then
token.destruct()
count = count + 1
end
end
return count
end
broadcastToColor("Removed " .. removeType("Bless") .. " Bless and " ..
removeType("Curse") .. " Curse tokens from play.", color, "White")
doReset(color)
end
-- context menu function 2
function doReset(color)
-- delete previously pulled out tokens by the token arranger
if tokenarranger then
for _, token in ipairs(getObjectsWithTag(tokenarranger.getVar("TO_DELETE_TAG"))) do
token.destruct()
end
end
playerColor = color
numInPlay = { Bless = 0, Curse = 0 }
tokensTaken = { Bless = {}, Curse = {} }
initializeState()
updateTokenArranger()
end
function addBlessToken(_obj, _color, alt_click)
addToken("Bless", _color)
---------------------------------------------------------
-- click functions
---------------------------------------------------------
-- click function 1
function clickBless(_, color, isRightClick)
playerColor = color
callFunctions("Bless", isRightClick)
end
function addCurseToken(_obj, _color, alt_click)
addToken("Curse", _color)
-- click function 2
function clickCurse(_, color, isRightClick)
playerColor = color
callFunctions("Curse", isRightClick)
end
function addToken(type, _color)
if numInPlay[type] == MAX_VALUE then
printToColor(MAX_VALUE .. " tokens already in play, not adding any", _color)
-- click function 3
function enableAlt()
if TOGGLE then return end
TOGGLE = not TOGGLE
updateButtons()
end
-- click function 4
function enableDefault()
if not TOGGLE then return end
TOGGLE = not TOGGLE
updateButtons()
end
---------------------------------------------------------
-- called functions
---------------------------------------------------------
function updateButtons()
self.editButton({
index = 0,
tooltip = MODE[TOGGLE] .. " Bless"
})
self.editButton({
index = 1,
tooltip = MODE[TOGGLE] .. " Curse"
})
self.editButton({
index = 2,
label = whitespace .. MODE[true] .. (TOGGLE and " ✓" or whitespace) .. " ",
color = BUTTON_COLOR[not TOGGLE],
font_color = FONT_COLOR[not TOGGLE]
})
self.editButton({
index = 3,
label = whitespace .. MODE[false] .. (TOGGLE and whitespace or " ✓") .. " ",
color = BUTTON_COLOR[TOGGLE],
font_color = FONT_COLOR[TOGGLE]
})
end
-- function that is called by click_functions 1+2 and calls the other functions
function callFunctions(token, isRightClick)
local success
if not TOGGLE then
if isRightClick then
success = takeToken(token, true)
else
success = addToken(token)
end
else
mode = type
spawnToken()
end
end
function spawnToken()
local pos = getChaosBagPosition()
if pos == nil then return end
local url = IMAGE_URL[mode]
local obj = spawnObject({
type = 'Custom_Tile',
position = { pos.x, pos.y + 3, pos.z },
rotation = { x = 0, y = 260, z = 0 },
callback_function = spawn_callback
})
obj.setCustomObject({
type = 2,
image = url,
thickness = 0.10,
})
obj.scale { 0.81, 1, 0.81 }
return obj
end
function spawn_callback(obj)
obj.setName(mode)
local guid = obj.getGUID()
numInPlay[mode] = numInPlay[mode] + 1
printToAll("Adding " .. mode .. " token " .. getTokenCount())
end
function removeBlessToken(_obj, _color, alt_click)
takeToken("Bless", _color, true)
end
function removeCurseToken(_obj, _color, alt_click)
takeToken("Curse", _color, true)
end
function takeBlessToken(_obj, _color, alt_click)
takeToken("Bless", _color, false)
end
function takeCurseToken(_obj, _color, alt_click)
takeToken("Curse", _color, false)
end
function takeToken(type, _color, remove)
playerColor = _color
local chaosbag = getChaosBag()
if chaosbag == nil then return end
if not remove and not SEAL_CARD_MESSAGE then
broadcastToColor("Are you trying to seal a token on a card? Return " ..
"this one, then try right-clicking on the card for seal options.",
_color)
SEAL_CARD_MESSAGE = true
end
local tokens = {}
for i, v in ipairs(chaosbag.getObjects()) do
if v.name == type then
table.insert(tokens, v.guid)
if isRightClick then
success = returnToken(token)
else
success = takeToken(token, false)
end
end
if #tokens == 0 then
printToColor("No " .. type .. " tokens in the chaos bag", _color)
return
end
local pos = self.getPosition()
local callback = take_callback
if remove then
callback = remove_callback
num = removeNum
end
local guid = table.remove(tokens)
mode = type
local position = Vector({ pos.x - 2, pos.y, pos.z + 2.5 })
if type == "Curse" then
position = position + Vector({ 0, 0, -5 })
end
chaosbag.takeObject({
guid = guid,
position = position,
smooth = false,
callback_function = callback
})
if success ~= 0 then updateTokenArranger() end
end
function remove_callback(obj)
take_callback(obj, true)
end
function take_callback(obj, remove)
local guid = obj.getGUID()
if remove then
numInPlay[mode] = numInPlay[mode] - 1
printToAll("Removing " .. mode .. " token " .. getTokenCount())
obj.destruct()
else
table.insert(tokensTaken[mode], guid)
printToAll("Taking " .. mode .. " token " .. getTokenCount())
UPDATING = false
function updateTokenArranger()
if tokenarranger and not UPDATING then
UPDATING = true
Wait.time(function()
UPDATING = false
tokenarranger.call("layout")
end, 1.5)
end
end
function returnBlessToken(_obj, _color, alt_click)
returnToken("Bless", _color)
end
function returnCurseToken(_obj, _color, alt_click)
returnToken("Curse", _color)
end
function returnToken(type, _color)
mode = type
local guid = table.remove(tokensTaken[type])
if guid == nil then
printToColor("No " .. mode .. " tokens to return", _color)
return
end
local token = getObjectFromGUID(guid)
if token == nil then
printToColor("Couldn't find token " .. guid .. ", not returning to bag", _color)
return
end
playerColor = _color
local chaosbag = getChaosBag()
if chaosbag == nil then return end
chaosbag.putObject(token)
printToAll("Returning " .. type .. " token " .. getTokenCount())
end
function getChaosBag()
local items = getObjectFromGUID("83ef06").getObjects()
local zone = getObjectFromGUID("83ef06")
if zone == nil then printToAll("Zone for chaosbag not found!", "Red") return end
local items = zone.getObjects()
local chaosbag = nil
for i, v in ipairs(items) do
for _, v in ipairs(items) do
if v.getDescription() == "Chaos Bag" then
chaosbag = getObjectFromGUID(v.getGUID())
break
@ -331,114 +291,185 @@ function getChaosBag()
return chaosbag
end
function getChaosBagPosition()
function getTokenCount(type)
if type == nil then type = mode end
return "(" .. (numInPlay[type] - #tokensTaken[type]) .. "/" .. #tokensTaken[type] .. ")"
end
---------------------------------------------------------
-- main functions: add, take and return
---------------------------------------------------------
function addToken(type)
if numInPlay[type] == 10 then
printToColor("10 tokens already in play, not adding any.", playerColor)
return 0
end
return spawnToken(type)
end
function spawnToken(type)
local chaosbag = getChaosBag()
if chaosbag == nil then return nil end
return chaosbag.getPosition()
if chaosbag == nil then
return 0
end
local pos = chaosbag.getPosition()
local obj = spawnObject({
type = 'Custom_Tile',
position = { pos.x, pos.y + 1, pos.z },
callback_function = function(obj)
obj.setName(type)
chaosbag.putObject(obj)
numInPlay[type] = numInPlay[type] + 1
printToAll("Adding " .. type .. " token " .. getTokenCount(type))
end
})
obj.setCustomObject({
type = 2,
image = IMAGE_URL[type],
thickness = 0.1,
})
obj.scale { 0.81, 1, 0.81 }
end
function getTokenCount()
return "(" .. (numInPlay[mode] - #tokensTaken[mode]) .. "/" ..
#tokensTaken[mode] .. ")"
function takeToken(type, remove)
local chaosbag = getChaosBag()
if chaosbag == nil then
broadcastToAll("Chaos bag not found!", "Red")
return 0
end
if not remove and not SEAL_CARD_MESSAGE then
broadcastToColor("For sealing tokens on cards try right-clicking on the card for seal options.", playerColor)
SEAL_CARD_MESSAGE = true
end
local tokens = {}
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == type then
table.insert(tokens, v.guid)
end
end
if #tokens == 0 then
printToColor("No " .. type .. " tokens in the chaos bag.", playerColor)
return 0
end
local pos = self.getPosition() + Vector(-2, 0, 2.5)
if type == "Curse" then pos[3] = pos[3] - 5 end
chaosbag.takeObject({
guid = table.remove(tokens),
position = pos,
smooth = false,
callback_function = function(obj)
if remove then
numInPlay[type] = numInPlay[type] - 1
printToAll("Removing " .. type .. " token " .. getTokenCount(type))
obj.destruct()
else
table.insert(tokensTaken[type], obj.getGUID())
printToAll("Taking " .. type .. " token " .. getTokenCount(type))
end
end
})
end
function addMenuOptions(playerColor, hoveredObject, pointerPosition, isKeyUp)
local manager = self
function returnToken(type)
local guid = table.remove(tokensTaken[type])
if guid == nil then
printToColor("No " .. type .. " tokens to return", playerColor)
return 0
end
local token = getObjectFromGUID(guid)
if token == nil then
printToColor("Couldn't find token " .. guid .. ", not returning to bag", playerColor)
return 0
end
local chaosbag = getChaosBag()
if chaosbag == nil then
return 0
end
chaosbag.putObject(token)
printToAll("Returning " .. type .. " token " .. getTokenCount(type))
end
---------------------------------------------------------
-- Wendy Menu (context menu for cards on hotkey press)
---------------------------------------------------------
function addMenuOptions(playerColor, hoveredObject)
if hoveredObject == nil or hoveredObject.getVar("MENU_ADDED") == true then return end
if hoveredObject.tag ~= "Card" then
broadcastToColor("Right-click seal options can only be added to cards", playerColor)
return
end
hoveredObject.addContextMenuItem("Seal Bless", function(color)
manager.call("sealToken", {
type = "Bless",
playerColor = color,
enemy = hoveredObject
})
sealToken("Bless", color, hoveredObject)
updateTokenArranger()
end, true)
hoveredObject.addContextMenuItem("Release Bless", function(color)
manager.call("releaseToken", {
type = "Bless",
playerColor = color,
enemy = hoveredObject
})
releaseToken("Bless", color, hoveredObject)
updateTokenArranger()
end, true)
hoveredObject.addContextMenuItem("Seal Curse", function(color)
manager.call("sealToken", {
type = "Curse",
playerColor = color,
enemy = hoveredObject
})
sealToken("Curse", color, hoveredObject)
updateTokenArranger()
end, true)
hoveredObject.addContextMenuItem("Release Curse", function(color)
manager.call("releaseToken", {
type = "Curse",
playerColor = color,
enemy = hoveredObject
})
releaseToken("Curse", color, hoveredObject)
updateTokenArranger()
end, true)
broadcastToColor("Right-click seal options added to " .. hoveredObject.getName(), playerColor)
hoveredObject.setVar("MENU_ADDED", true)
sealedTokens[hoveredObject.getGUID()] = {}
end
function sealToken(params)
playerColor = params.playerColor
function sealToken(type, color, enemy)
local chaosbag = getChaosBag()
if chaosbag == nil then return end
local pos = params.enemy.getPosition()
local manager = self
local pos = enemy.getPosition()
for i, token in ipairs(chaosbag.getObjects()) do
if token.name == params.type then
if token.name == type then
chaosbag.takeObject({
position = { pos.x, pos.y + 1, pos.z },
index = i - 1,
smooth = false,
callback_function = function(obj)
Wait.frames(function()
local mSealedTokens = manager.getVar("sealedTokens")
local tokens = mSealedTokens[params.enemy.getGUID()]
table.insert(tokens, obj)
manager.setVar("sealedTokens", mSealedTokens)
local guid = obj.getGUID()
local tokensTaken = manager.getVar("tokensTaken")
table.insert(tokensTaken[params.type], guid)
manager.setVar("tokensTaken", tokensTaken)
manager.setVar("mode", params.type)
printToColor("Sealing " .. params.type .. " token " .. manager.call("getTokenCount"),
params.playerColor)
end
, 1)
table.insert(sealedTokens[enemy.getGUID()], obj)
table.insert(tokensTaken[type], obj.getGUID())
printToColor("Sealing " .. type .. " token " .. getTokenCount(type), color)
end, 1)
end
})
return
end
end
printToColor(params.type .. " token not found in bag", playerColor)
printToColor(type .. " token not found in bag", color)
end
function releaseToken(params)
playerColor = params.playerColor
function releaseToken(type, color, enemy)
local chaosbag = getChaosBag()
if chaosbag == nil then return end
local tokens = sealedTokens[params.enemy.getGUID()]
local tokens = sealedTokens[enemy.getGUID()]
if tokens == nil or #tokens == 0 then return end
mode = params.type
for i, token in ipairs(tokens) do
if token ~= nil and token.getName() == params.type then
if token ~= nil and token.getName() == type then
local guid = token.getGUID()
chaosbag.putObject(token)
for j, v in ipairs(tokensTaken[mode]) do
for j, v in ipairs(tokensTaken[type]) do
if v == guid then
table.remove(tokensTaken[mode], j)
table.remove(tokensTaken[type], j)
table.remove(tokens, i)
printToColor("Releasing " .. mode .. " token" .. getTokenCount(), params.playerColor)
printToColor("Releasing " .. type .. " token" .. getTokenCount(type), color)
return
end
end
end
end
printToColor(params.type .. " token not sealed on " .. params.enemy.getName(), params.playerColor)
printToColor(type .. " token not sealed on " .. enemy.getName(), color)
end