Merge pull request #26 from argonui/blursemanager

updated bless/curse manager
This commit is contained in:
Chr1Z 2022-11-13 23:46:37 +01:00 committed by GitHub
commit a751259b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 427 additions and 387 deletions

View File

@ -198,7 +198,7 @@
"TheDream-Eaters.a34f34", "TheDream-Eaters.a34f34",
"ChaosBag.fea079", "ChaosBag.fea079",
"DataHelper.708279", "DataHelper.708279",
"BlessCurseTokenManager.5933fb", "BlessCurseManager.5933fb",
"Notecard.d8d357", "Notecard.d8d357",
"ArkhamDeckCutter.445115", "ArkhamDeckCutter.445115",
"ScriptingTrigger.a2f932", "ScriptingTrigger.a2f932",

View File

@ -19,10 +19,10 @@
}, },
"ImageScalar": 1, "ImageScalar": 1,
"ImageSecondaryURL": "", "ImageSecondaryURL": "",
"ImageURL": "http://cloud-3.steamusercontent.com/ugc/1557640258613050317/0CB60FE3464788DAE2A650900DD84734934E5020/", "ImageURL": "http://cloud-3.steamusercontent.com/ugc/1910115722577754046/64AF9853E51B79561BEAA3BEF13BBC694BBF9A34/",
"WidthScale": 0 "WidthScale": 0
}, },
"Description": "See Notebook for Instructions", "Description": "Left-Click: Add token\nRight-Click: Remove token\n\nContextmenu allows resetting the current state or removing all bless/curse tokens from play.\n\nSee Notebook for detailed instructions.",
"DragSelectable": true, "DragSelectable": true,
"GMNotes": "", "GMNotes": "",
"GUID": "5933fb", "GUID": "5933fb",
@ -33,27 +33,28 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": true, "Locked": true,
"LuaScriptState": "false",
"LuaScript": "require(\"tokens/BlessCurseManager\")", "LuaScript": "require(\"tokens/BlessCurseManager\")",
"LuaScriptState": "{\"Bless\":8,\"Curse\":0}",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Custom_Token", "Name": "Custom_Token",
"Nickname": "Bless/Curse Token Manager", "Nickname": "Bless/Curse Manager",
"Snap": true, "Snap": true,
"Sticky": true, "Sticky": true,
"Tags": [ "Tags": [
"CleanUpHelper_ignore",
"displacement_excluded" "displacement_excluded"
], ],
"Tooltip": true, "Tooltip": true,
"Transform": { "Transform": {
"posX": -47.62, "posX": -48.2,
"posY": 1.598, "posY": 1.531,
"posZ": 0, "posZ": 0,
"rotX": 0, "rotX": 0,
"rotY": 270, "rotY": 270,
"rotZ": 0, "rotZ": 0,
"scaleX": 0.6836529, "scaleX": 0.8,
"scaleY": 1, "scaleY": 1,
"scaleZ": 0.6836529 "scaleZ": 0.8
}, },
"Value": 0, "Value": 0,
"XmlUI": "" "XmlUI": ""

View File

@ -63,15 +63,15 @@
"Sticky": true, "Sticky": true,
"Tooltip": false, "Tooltip": false,
"Transform": { "Transform": {
"posX": -50.5, "posX": -50.9,
"posY": 1.581, "posY": 1.51,
"posZ": 0, "posZ": 0,
"rotX": 0, "rotX": 0,
"rotY": 270, "rotY": 270,
"rotZ": 0, "rotZ": 0,
"scaleX": 0.420461982, "scaleX": 0.4,
"scaleY": 0.008194907, "scaleY": 0.01,
"scaleZ": 0.367155 "scaleZ": 0.4
}, },
"Value": 0, "Value": 0,
"XmlUI": "" "XmlUI": ""

View File

@ -3,12 +3,12 @@
-- original by: Whimsical -- original by: Whimsical
-- description: displays the content of the chaos bag -- description: displays the content of the chaos bag
information = { information = {
version = "1.6", version = "1.7",
last_updated = "10.10.2022" last_updated = "13.11.2022"
} }
-- names of tokens in order -- names of tokens in order
token_names = { local token_names = {
"Elder Sign", "Elder Sign",
"Skull", "Skull",
"Cultist", "Cultist",
@ -21,85 +21,82 @@ token_names = {
"" ""
} }
-- common parameters -- token modifiers for sorting (and order for same modifier)
local BUTTON_PARAMETERS = {} -- order starts at 2 because there is a "+1" token
BUTTON_PARAMETERS.function_owner = self local token_precedence = {
BUTTON_PARAMETERS.label = "" ["Elder Sign"] = { 100, 2 },
BUTTON_PARAMETERS.tooltip = "Add / Remove" ["Skull"] = { -1, 3 },
BUTTON_PARAMETERS.color = { 0, 0, 0, 0 } ["Cultist"] = { -2, 4 },
BUTTON_PARAMETERS.width = 325 ["Tablet"] = { -3, 5 },
BUTTON_PARAMETERS.height = 325 ["Elder Thing"] = { -4, 6 },
["Auto-fail"] = { -100, 7 },
["Bless"] = { 101, 8 },
["Curse"] = { -101, 9 },
["Frost"] = { -99, 10 },
[""] = { 0, 11 }
}
local INPUT_PARAMETERS = {} -- common parameters
INPUT_PARAMETERS.function_owner = self local buttonParameters = {}
INPUT_PARAMETERS.font_size = 100 buttonParameters.function_owner = self
INPUT_PARAMETERS.width = 250 buttonParameters.label = ""
INPUT_PARAMETERS.height = INPUT_PARAMETERS.font_size + 23 buttonParameters.tooltip = "Add / Remove"
INPUT_PARAMETERS.alignment = 3 buttonParameters.color = { 0, 0, 0, 0 }
INPUT_PARAMETERS.validation = 2 buttonParameters.width = 325
INPUT_PARAMETERS.tab = 2 buttonParameters.height = 325
local inputParameters = {}
inputParameters.function_owner = self
inputParameters.font_size = 100
inputParameters.width = 250
inputParameters.height = inputParameters.font_size + 23
inputParameters.alignment = 3
inputParameters.validation = 2
inputParameters.tab = 2
-- tag for cloned tokens -- tag for cloned tokens
TO_DELETE_TAG = "to_be_deleted" TO_DELETE_TAG = "to_be_deleted"
updating = false
function onSave() return JSON.encode(token_precedence) end function onSave() return JSON.encode(token_precedence) end
function onload(save_state) function onLoad(save_state)
if save_state ~= nil then if save_state ~= nil then
token_precedence = JSON.decode(save_state) token_precedence = JSON.decode(save_state)
else
-- token modifiers for sorting (and order for same modifier)
-- order starts at 2 because there is a "+1" token
token_precedence = {
["Elder Sign"] = { 100, 2 },
["Skull"] = { -1, 3 },
["Cultist"] = { -2, 4 },
["Tablet"] = { -3, 5 },
["Elder Thing"] = { -4, 6 },
["Auto-fail"] = { -100, 7 },
["Bless"] = { 101, 8 },
["Curse"] = { -101, 9 },
["Frost"] = { -99, 10 },
[""] = { 0, 11 }
}
end end
updating = false
-- create UI -- create UI
local offset = 0.725 local offset = 0.725
local pos = { local pos = { x = { -1.067, 0.377 }, z = -2.175 }
x = { -1.067, 0.377 },
z = -2.175
}
-- button and inputs index 1-10 -- button and inputs index 1-10
for i = 1, 10 do for i = 1, 10 do
if i < 6 then if i < 6 then
BUTTON_PARAMETERS.position = { pos.x[1], 0, pos.z + i * offset } buttonParameters.position = { pos.x[1], 0, pos.z + i * offset }
INPUT_PARAMETERS.position = { pos.x[1] + offset, 0.1, pos.z + i * offset } inputParameters.position = { pos.x[1] + offset, 0.1, pos.z + i * offset }
else else
BUTTON_PARAMETERS.position = { pos.x[2], 0, pos.z + (i - 5) * offset } buttonParameters.position = { pos.x[2], 0, pos.z + (i - 5) * offset }
INPUT_PARAMETERS.position = { pos.x[2] + offset, 0.1, pos.z + (i - 5) * offset } inputParameters.position = { pos.x[2] + offset, 0.1, pos.z + (i - 5) * offset }
end end
BUTTON_PARAMETERS.click_function = attachIndex("tokenClick", i) buttonParameters.click_function = attachIndex("tokenClick", i)
INPUT_PARAMETERS.input_function = attachIndex2("tokenInput", i) inputParameters.input_function = attachIndex2("tokenInput", i)
INPUT_PARAMETERS.value = token_precedence[token_names[i]][1] inputParameters.value = token_precedence[token_names[i]][1]
self.createButton(BUTTON_PARAMETERS) self.createButton(buttonParameters)
self.createInput(INPUT_PARAMETERS) self.createInput(inputParameters)
end end
-- index 11: "Update / Hide" button -- index 11: "Update / Hide" button
BUTTON_PARAMETERS.label = "Update / Hide" buttonParameters.label = "Update / Hide"
BUTTON_PARAMETERS.click_function = "layout" buttonParameters.click_function = "layout"
BUTTON_PARAMETERS.tooltip = "Left-Click: Update!\nRight-Click: Hide Tokens!" buttonParameters.tooltip = "Left-Click: Update!\nRight-Click: Hide Tokens!"
BUTTON_PARAMETERS.position = { 0.725, 0.1, 2.025 } buttonParameters.position = { 0.725, 0.1, 2.025 }
BUTTON_PARAMETERS.color = { 1, 1, 1 } buttonParameters.color = { 1, 1, 1 }
BUTTON_PARAMETERS.width = 675 buttonParameters.width = 675
BUTTON_PARAMETERS.height = 175 buttonParameters.height = 175
self.createButton(BUTTON_PARAMETERS) self.createButton(buttonParameters)
self.addContextMenuItem("More Information", function() self.addContextMenuItem("More Information", function()
printToAll("------------------------------", "White") printToAll("------------------------------", "White")
@ -107,6 +104,16 @@ function onload(save_state)
printToAll("last updated: " .. information["last_updated"], "White") printToAll("last updated: " .. information["last_updated"], "White")
printToAll("original concept by Whimsical", "White") printToAll("original concept by Whimsical", "White")
end) end)
-- send object reference to bless/curse manager
Wait.time(function()
getObjectFromGUID("5933fb").setVar("tokenArranger", self)
end, 1)
end
function onDestroy()
-- remove object reference from bless/curse manager
getObjectFromGUID("5933fb").setVar("tokenArranger", nil)
end end
-- helper functions to carry index -- helper functions to carry index
@ -221,7 +228,7 @@ function do_position()
-- create table with tokens -- create table with tokens
for i, token in ipairs(getObjectsWithTag(TO_DELETE_TAG)) do for i, token in ipairs(getObjectsWithTag(TO_DELETE_TAG)) do
local name = token.getName() local name = token.getName() or ""
local value = tonumber(name) local value = tonumber(name)
local precedence = token_precedence[name] local precedence = token_precedence[name]

View File

@ -1,139 +1,96 @@
BLESS_COLOR = { r = 0.3, g = 0.25, b = 0.09 } -- Bless / Curse Manager
CURSE_COLOR = { r = 0.2, g = 0.08, b = 0.24 } -- updated by: Chr1Z
MIN_VALUE = 1 -- made by: Tikatoy
MAX_VALUE = 10 -- description: helps with adding / removing and sealing of bless and curse tokens
IMAGE_URL = { information = {
version = "3.5",
last_updated = "12.11.2022"
}
local IMAGE_URL = {
Bless = "http://cloud-3.steamusercontent.com/ugc/1655601092778627699/339FB716CB25CA6025C338F13AFDFD9AC6FA8356/", Bless = "http://cloud-3.steamusercontent.com/ugc/1655601092778627699/339FB716CB25CA6025C338F13AFDFD9AC6FA8356/",
Curse = "http://cloud-3.steamusercontent.com/ugc/1655601092778636039/2A25BD38E8C44701D80DD96BF0121DA21843672E/" Curse = "http://cloud-3.steamusercontent.com/ugc/1655601092778636039/2A25BD38E8C44701D80DD96BF0121DA21843672E/"
} }
function onload() -- common button parameters
self.createButton({ local buttonParamaters = {}
label = "Add", buttonParamaters.function_owner = self
click_function = "addBlessToken", buttonParamaters.color = { 0, 0, 0, 0 }
function_owner = self, buttonParamaters.width = 700
position = { -2.3, 0.1, -0.5 }, buttonParamaters.height = 700
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
})
self.createButton({ local altState = false
label = "Remove", local MODE = { [false] = "Add / Remove", [true] = "Take / Return" }
click_function = "removeBlessToken", local BUTTON_COLOR = { [false] = { 0.4, 0.4, 0.4 }, [true] = { 0.9, 0.9, 0.9 } }
function_owner = self, local FONT_COLOR = { [false] = { 1, 1, 1 }, [true] = { 0, 0, 0 } }
position = { -0.9, 0.1, -0.5 }, local whitespace = " "
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
})
self.createButton({ -- variable will be set by outside call
label = "Take", tokenArranger = nil
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
})
self.createButton({ ---------------------------------------------------------
label = "Return", -- creating buttons and menus + initializing tables
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
})
self.createButton({ function onSave() return JSON.encode(altState) end
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
})
self.createButton({ function onLoad(saved_state)
label = "Remove", if saved_state ~= nil then
click_function = "removeCurseToken", altState = JSON.decode(saved_state)
function_owner = self, end
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
})
self.createButton({ -- index: 0 - bless
label = "Take", buttonParamaters.click_function = "clickBless"
click_function = "takeCurseToken", buttonParamaters.position = { -1.03, 0.05, 0.46 }
function_owner = self, self.createButton(buttonParamaters)
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
})
self.createButton({ -- index: 1 - curse
label = "Return", buttonParamaters.click_function = "clickCurse"
click_function = "returnCurseToken", buttonParamaters.position[1] = -buttonParamaters.position[1]
function_owner = self, self.createButton(buttonParamaters)
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
})
self.createButton({ -- index: 2 - alternative mode (take / return)
label = "Reset", click_function = "doReset", function_owner = self, buttonParamaters.click_function = "enableAlt"
position = { 0, 0, 1.8 }, rotation = { 0, 0, 0 }, height = 350, width = 800, buttonParamaters.width = 900
font_size = 250, color = { 0, 0, 0 }, font_color = { 1, 1, 1 } 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 } numInPlay = { Bless = 0, Curse = 0 }
tokensTaken = { Bless = {}, Curse = {} } tokensTaken = { Bless = {}, Curse = {} }
sealedTokens = {} sealedTokens = {}
Wait.time(initializeState, 1) Wait.time(initializeState, 1)
addHotkey("Bless Curse Status", printStatus, false)
addHotkey("Wendy's Menu", addMenuOptions, false)
end end
function initializeState() function initializeState()
playerColor = "White"
-- count tokens in the bag -- count tokens in the bag
local chaosbag = getChaosBag() local chaosbag = getChaosBag()
if chaosbag == nil then return end if chaosbag == nil then return end
local tokens = {} local tokens = {}
for i, v in ipairs(chaosbag.getObjects()) do for _, v in ipairs(chaosbag.getObjects()) do
if v.name == "Bless" then if v.name == "Bless" then
numInPlay.Bless = numInPlay.Bless + 1 numInPlay.Bless = numInPlay.Bless + 1
elseif v.name == "Curse" then elseif v.name == "Curse" then
@ -142,10 +99,9 @@ function initializeState()
end end
-- find tokens in the play area -- find tokens in the play area
local objs = getObjects() for _, obj in ipairs(getObjects()) do
for i, obj in ipairs(objs) do
local pos = obj.getPosition() 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 if obj.getName() == "Bless" then
table.insert(tokensTaken.Bless, obj.getGUID()) table.insert(tokensTaken.Bless, obj.getGUID())
numInPlay.Bless = numInPlay.Bless + 1 numInPlay.Bless = numInPlay.Bless + 1
@ -156,172 +112,177 @@ function initializeState()
end end
end end
mode = "Bless" broadcastCount("Curse")
print("Bless Tokens " .. getTokenCount()) broadcastCount("Bless")
mode = "Curse"
print("Curse Tokens " .. getTokenCount())
end end
function printStatus(player_color, hovered_object, world_position, key_down_up) function broadcastCount(token)
mode = "Curse" local count = getTokenCount(token)
broadcastToColor("Curse Tokens " .. getTokenCount(), player_color) if count == "(0/0)" then return end
mode = "Bless" broadcastToAll(token .. " Tokens " .. count, "White")
broadcastToColor("Bless Tokens " .. getTokenCount(), player_color)
end end
function doReset(_obj, _color, alt_click) function printStatus(color)
playerColor = _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 } numInPlay = { Bless = 0, Curse = 0 }
tokensTaken = { Bless = {}, Curse = {} } tokensTaken = { Bless = {}, Curse = {} }
initializeState() initializeState()
updateTokenArranger()
end 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 end
function addCurseToken(_obj, _color, alt_click) -- click function 2
addToken("Curse", _color) function clickCurse(_, color, isRightClick)
playerColor = color
callFunctions("Curse", isRightClick)
end end
function addToken(type, _color) -- click function 3
if numInPlay[type] == MAX_VALUE then function enableAlt()
printToColor(MAX_VALUE .. " tokens already in play, not adding any", _color) if altState then return end
altState = not altState
updateButtons()
end
-- click function 4
function enableDefault()
if not altState then return end
altState = not altState
updateButtons()
end
---------------------------------------------------------
-- called functions
---------------------------------------------------------
function updateButtons()
self.editButton({
index = 0,
tooltip = MODE[altState] .. " Bless"
})
self.editButton({
index = 1,
tooltip = MODE[altState] .. " Curse"
})
self.editButton({
index = 2,
label = whitespace .. MODE[true] .. (altState and " ✓" or whitespace) .. " ",
color = BUTTON_COLOR[not altState],
font_color = FONT_COLOR[not altState]
})
self.editButton({
index = 3,
label = whitespace .. MODE[false] .. (altState and whitespace or " ✓") .. " ",
color = BUTTON_COLOR[altState],
font_color = FONT_COLOR[altState]
})
end
-- function that is called by click_functions 1+2 and calls the other functions
function callFunctions(token, isRightClick)
local success
if not altState then
if isRightClick then
success = takeToken(token, true)
else
success = addToken(token)
end
else else
mode = type if isRightClick then
spawnToken() success = returnToken(token)
end else
end success = takeToken(token, false)
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)
end end
end end
if #tokens == 0 then if success ~= 0 then updateTokenArranger() end
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
})
end end
function remove_callback(obj) UPDATING = false
take_callback(obj, true) function updateTokenArranger()
end if tokenArranger and not UPDATING then
UPDATING = true
function take_callback(obj, remove) Wait.time(function()
local guid = obj.getGUID() UPDATING = false
if remove then tokenArranger.call("layout")
numInPlay[mode] = numInPlay[mode] - 1 end, 1.5)
printToAll("Removing " .. mode .. " token " .. getTokenCount())
obj.destruct()
else
table.insert(tokensTaken[mode], guid)
printToAll("Taking " .. mode .. " token " .. getTokenCount())
end end
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() 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 local chaosbag = nil
for i, v in ipairs(items) do for _, v in ipairs(items) do
if v.getDescription() == "Chaos Bag" then if v.getDescription() == "Chaos Bag" then
chaosbag = getObjectFromGUID(v.getGUID()) chaosbag = getObjectFromGUID(v.getGUID())
break break
@ -331,114 +292,185 @@ function getChaosBag()
return chaosbag return chaosbag
end 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() local chaosbag = getChaosBag()
if chaosbag == nil then return nil end if chaosbag == nil then
return chaosbag.getPosition() 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 end
function getTokenCount() function takeToken(type, remove)
return "(" .. (numInPlay[mode] - #tokensTaken[mode]) .. "/" .. local chaosbag = getChaosBag()
#tokensTaken[mode] .. ")" 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.25, 0, 0.85)
if type == "Curse" then pos[3] = pos[3] - 1.7 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 end
function addMenuOptions(playerColor, hoveredObject, pointerPosition, isKeyUp) function returnToken(type)
local manager = self 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 == nil or hoveredObject.getVar("MENU_ADDED") == true then return end
if hoveredObject.tag ~= "Card" then if hoveredObject.tag ~= "Card" then
broadcastToColor("Right-click seal options can only be added to cards", playerColor) broadcastToColor("Right-click seal options can only be added to cards", playerColor)
return return
end end
hoveredObject.addContextMenuItem("Seal Bless", function(color) hoveredObject.addContextMenuItem("Seal Bless", function(color)
manager.call("sealToken", { sealToken("Bless", color, hoveredObject)
type = "Bless", updateTokenArranger()
playerColor = color,
enemy = hoveredObject
})
end, true) end, true)
hoveredObject.addContextMenuItem("Release Bless", function(color) hoveredObject.addContextMenuItem("Release Bless", function(color)
manager.call("releaseToken", { releaseToken("Bless", color, hoveredObject)
type = "Bless", updateTokenArranger()
playerColor = color,
enemy = hoveredObject
})
end, true) end, true)
hoveredObject.addContextMenuItem("Seal Curse", function(color) hoveredObject.addContextMenuItem("Seal Curse", function(color)
manager.call("sealToken", { sealToken("Curse", color, hoveredObject)
type = "Curse", updateTokenArranger()
playerColor = color,
enemy = hoveredObject
})
end, true) end, true)
hoveredObject.addContextMenuItem("Release Curse", function(color) hoveredObject.addContextMenuItem("Release Curse", function(color)
manager.call("releaseToken", { releaseToken("Curse", color, hoveredObject)
type = "Curse", updateTokenArranger()
playerColor = color,
enemy = hoveredObject
})
end, true) end, true)
broadcastToColor("Right-click seal options added to " .. hoveredObject.getName(), playerColor) broadcastToColor("Right-click seal options added to " .. hoveredObject.getName(), playerColor)
hoveredObject.setVar("MENU_ADDED", true) hoveredObject.setVar("MENU_ADDED", true)
sealedTokens[hoveredObject.getGUID()] = {} sealedTokens[hoveredObject.getGUID()] = {}
end end
function sealToken(params) function sealToken(type, playerColor, enemy)
playerColor = params.playerColor
local chaosbag = getChaosBag() local chaosbag = getChaosBag()
if chaosbag == nil then return end if chaosbag == nil then return end
local pos = params.enemy.getPosition() local pos = enemy.getPosition()
local manager = self
for i, token in ipairs(chaosbag.getObjects()) do for i, token in ipairs(chaosbag.getObjects()) do
if token.name == params.type then if token.name == type then
chaosbag.takeObject({ chaosbag.takeObject({
position = { pos.x, pos.y + 1, pos.z }, position = { pos.x, pos.y + 1, pos.z },
index = i - 1, index = i - 1,
smooth = false, smooth = false,
callback_function = function(obj) callback_function = function(obj)
Wait.frames(function() Wait.frames(function()
local mSealedTokens = manager.getVar("sealedTokens") table.insert(sealedTokens[enemy.getGUID()], obj)
local tokens = mSealedTokens[params.enemy.getGUID()] table.insert(tokensTaken[type], obj.getGUID())
table.insert(tokens, obj) printToColor("Sealing " .. type .. " token " .. getTokenCount(type), playerColor)
manager.setVar("sealedTokens", mSealedTokens) end, 1)
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)
end end
}) })
return return
end end
end end
printToColor(params.type .. " token not found in bag", playerColor) printToColor(type .. " token not found in bag", playerColor)
end end
function releaseToken(params) function releaseToken(type, playerColor, enemy)
playerColor = params.playerColor
local chaosbag = getChaosBag() local chaosbag = getChaosBag()
if chaosbag == nil then return end 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 if tokens == nil or #tokens == 0 then return end
mode = params.type
for i, token in ipairs(tokens) do 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() local guid = token.getGUID()
chaosbag.putObject(token) chaosbag.putObject(token)
for j, v in ipairs(tokensTaken[mode]) do for j, v in ipairs(tokensTaken[type]) do
if v == guid then if v == guid then
table.remove(tokensTaken[mode], j) table.remove(tokensTaken[type], j)
table.remove(tokens, i) table.remove(tokens, i)
printToColor("Releasing " .. mode .. " token" .. getTokenCount(), params.playerColor) printToColor("Releasing " .. type .. " token" .. getTokenCount(type), playerColor)
return return
end end
end end
end end
end end
printToColor(params.type .. " token not sealed on " .. params.enemy.getName(), params.playerColor) printToColor(type .. " token not sealed on " .. enemy.getName(), playerColor)
end end