From f98cf3ca3932ce3b5a26c01fbace474af026432c Mon Sep 17 00:00:00 2001 From: dscarpac Date: Thu, 18 Apr 2024 05:13:44 -0500 Subject: [PATCH 1/6] version 1 --- .../KhakuNarukami.54eaa7.json | 2 +- src/playercards/cards/KhakuNarukami.ttslua | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/playercards/cards/KhakuNarukami.ttslua diff --git a/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json b/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json index 7c317a95..e73ac888 100644 --- a/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json +++ b/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "", + "LuaScript": "require(\"playercards/cards/KhakuNarukami\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", diff --git a/src/playercards/cards/KhakuNarukami.ttslua b/src/playercards/cards/KhakuNarukami.ttslua new file mode 100644 index 00000000..1c4acfde --- /dev/null +++ b/src/playercards/cards/KhakuNarukami.ttslua @@ -0,0 +1,64 @@ +function onSave() + return JSON.encode() +end + +function onLoad(savedData) + self.addContextMenuItem("Enable Helper", createButtons) + sigil = JSON.decode(savedData) + if sigil and sigil ~= nil then + makeXMLButton(sigil) + self.clearContextMenu() + self.addContextMenuItem("Clear Helper", deleteButtons) + end +end + +function makeXMLButton(chosenToken) + self.UI.setXmlTable({ + { + tag="Button", + attributes={ + height=450, + width=1400, + rotation="0 0 180", + scale="0.1 0.1 1", + position="0 -55 -22", + padding="50 50 50 50", + font="font_teutonic-arkham", + fontSize=300, + iconWidth=400, + iconAlignment="Right", + onClick="remove", + id=sigil, + icon=dataForToken[sigil].icon, + color=dataForToken[sigil].color, + textColor="White", + }, + value="Resolve", + } + } +) +end + +-- Create dialog window to choose sigil and create sigil-drawing button +function chooseSigil(playerColor) + self.clearContextMenu() + self.addContextMenuItem("Clear Helper", deleteButtons) + Player[playerColor].showOptionsDialog("Choose Sigil", tokenNames, 1, + function(chosenToken) + if chosenToken == "Custom Token" then + sigil = "" + else + sigil = chosenToken + end + makeXMLButton(sigil) + end + ) +end + +-- Delete button and remove sigil +function deleteButtons() + self.clearContextMenu() + self.addContextMenuItem("Enable Helper", chooseSigil) + self.UI.setXml("") + sigil = nil +end \ No newline at end of file From c27fcb5b2574c7f234a6fef4f96f22bf439eee88 Mon Sep 17 00:00:00 2001 From: dscarpac Date: Fri, 28 Jun 2024 11:41:19 -0500 Subject: [PATCH 2/6] first pass --- modsettings/CustomUIAssets.json | 5 + .../KhakuNarukami.54eaa7.json | 4 +- src/playercards/cards/KhakuNarukami.ttslua | 64 ---------- src/playercards/cards/KohakuNarukami.ttslua | 120 ++++++++++++++++++ src/playermat/Playermat.ttslua | 4 +- xml/playercards/KohakuNarukami.xml | 98 ++++++++++++++ 6 files changed, 228 insertions(+), 67 deletions(-) delete mode 100644 src/playercards/cards/KhakuNarukami.ttslua create mode 100644 src/playercards/cards/KohakuNarukami.ttslua create mode 100644 xml/playercards/KohakuNarukami.xml diff --git a/modsettings/CustomUIAssets.json b/modsettings/CustomUIAssets.json index 37fe7bd3..00501220 100644 --- a/modsettings/CustomUIAssets.json +++ b/modsettings/CustomUIAssets.json @@ -244,6 +244,11 @@ "Type": 0, "URL": "http://cloud-3.steamusercontent.com/ugc/2510267932886739653/CB7AA2D73777EF5938A6E6CD664B2ABA52B6E20A/" }, + { + "Name": "token-eldersign", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2540675016035917168/C0D6F531A85FD94C2F54825DFC50781B5B499A1D/" + }, { "Name": "token-custom-token", "Type": 0, diff --git a/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json b/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json index e73ac888..3cc17a73 100644 --- a/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json +++ b/objects/AllPlayerCards.15bb07/KhakuNarukami.54eaa7.json @@ -33,7 +33,7 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": false, - "LuaScript": "require(\"playercards/cards/KhakuNarukami\")", + "LuaScript": "require(\"playercards/cards/KohakuNarukami\")", "LuaScriptState": "", "MeasureMovement": false, "Name": "Card", @@ -58,5 +58,5 @@ "scaleZ": 1.15 }, "Value": 0, - "XmlUI": "" + "XmlUI": "\u003cInclude src=\"playercards/KohakuNarukami.xml\"/\u003e" } diff --git a/src/playercards/cards/KhakuNarukami.ttslua b/src/playercards/cards/KhakuNarukami.ttslua deleted file mode 100644 index 1c4acfde..00000000 --- a/src/playercards/cards/KhakuNarukami.ttslua +++ /dev/null @@ -1,64 +0,0 @@ -function onSave() - return JSON.encode() -end - -function onLoad(savedData) - self.addContextMenuItem("Enable Helper", createButtons) - sigil = JSON.decode(savedData) - if sigil and sigil ~= nil then - makeXMLButton(sigil) - self.clearContextMenu() - self.addContextMenuItem("Clear Helper", deleteButtons) - end -end - -function makeXMLButton(chosenToken) - self.UI.setXmlTable({ - { - tag="Button", - attributes={ - height=450, - width=1400, - rotation="0 0 180", - scale="0.1 0.1 1", - position="0 -55 -22", - padding="50 50 50 50", - font="font_teutonic-arkham", - fontSize=300, - iconWidth=400, - iconAlignment="Right", - onClick="remove", - id=sigil, - icon=dataForToken[sigil].icon, - color=dataForToken[sigil].color, - textColor="White", - }, - value="Resolve", - } - } -) -end - --- Create dialog window to choose sigil and create sigil-drawing button -function chooseSigil(playerColor) - self.clearContextMenu() - self.addContextMenuItem("Clear Helper", deleteButtons) - Player[playerColor].showOptionsDialog("Choose Sigil", tokenNames, 1, - function(chosenToken) - if chosenToken == "Custom Token" then - sigil = "" - else - sigil = chosenToken - end - makeXMLButton(sigil) - end - ) -end - --- Delete button and remove sigil -function deleteButtons() - self.clearContextMenu() - self.addContextMenuItem("Enable Helper", chooseSigil) - self.UI.setXml("") - sigil = nil -end \ No newline at end of file diff --git a/src/playercards/cards/KohakuNarukami.ttslua b/src/playercards/cards/KohakuNarukami.ttslua new file mode 100644 index 00000000..b8b8771e --- /dev/null +++ b/src/playercards/cards/KohakuNarukami.ttslua @@ -0,0 +1,120 @@ +require("playercards/CardsWithHelper") +local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") +local chaosBagApi = require("chaosbag/ChaosBagApi") +local guidReferenceApi = require("core/GUIDReferenceApi") +local playermatApi = require("playermat/PlayermatApi") +local tokenManager = require("core/token/TokenManager") + +function updateSave() + self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled }) +end + +function onLoad(savedData) + self.addTag("CardWithHelper") + if savedData and savedData ~= "" then + local loadedData = JSON.decode(savedData) + isHelperEnabled = loadedData.isHelperEnabled + end + checkOptionPanel() + updateDisplay() +end + +-- hide buttons and stop monitoring +function shutOff() + self.UI.hide("Helper") + Wait.stopAll() + updateSave() +end + +-- show buttons and begin monitoring chaos bag for curse and bless tokens +function initialize() + self.UI.show("Helper") + maybeUpdateButtonState() + Wait.time(maybeUpdateButtonState, 1, -1) + updateSave() +end + +function addTokenToBag(_, _, tokenType) + blessCurseManagerApi.addToken(tokenType) +end + +function removeAndExtraAction() + blessCurseManagerApi.removeToken("Bless") + blessCurseManagerApi.removeToken("Bless") + blessCurseManagerApi.removeToken("Curse") + blessCurseManagerApi.removeToken("Curse") + + local position = self.getPosition() + local matColor = playermatApi.getMatColorByPosition(position) + local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat") + local rotation = mat.getRotation() + + -- spawn extra action token in the middle of investigator card with Temporary tag + callback = function(spawned) spawned.call("updateClassAndSymbol", { class = "Mystic", symbol = "Mystic" }) spawned.addTag("Temporary") end + tokenManager.spawnToken(position + Vector(0, 0.2, 0), "universalActionAbility", rotation, callback) +end + +function elderSignAbility() + blessCurseManagerApi.addToken("Bless") + blessCurseManagerApi.addToken("Curse") +end + +-- count tokens in the bag and show appropriate buttons +function maybeUpdateButtonState() + local numInBag = getBlessCurseInBag() + local state = { Bless = false, Curse = false, Action = false, ElderSign = false } + + if numInBag.Bless <= numInBag.Curse and numInBag.Bless < 10 then + state.Bless = true + end + + if numInBag.Curse <= numInBag.Bless and numInBag.Curse < 10 then + state.Curse = true + end + + if numInBag.Curse >= 2 and numInBag.Bless >= 2 then + state.Action = true + end + + state.ElderSign = true + + setUiState(state) +end + +function getBlessCurseInBag() + local numInBag = { Bless = 0, Curse = 0 } + local chaosBag = chaosBagApi.findChaosBag() + + for _, v in ipairs(chaosBag.getObjects()) do + if v.name == "Bless" or v.name == "Curse" then + numInBag[v.name] = numInBag[v.name] + 1 + end + end + + return numInBag +end + +function setUiState(params) + for _, tokenName in ipairs({ "Bless", "Curse", "Action", "ElderSign" }) do + if params[tokenName] then + self.UI.show(tokenName) + self.UI.hide("inactive" .. tokenName) + else + self.UI.show("inactive" .. tokenName) + self.UI.hide(tokenName) + end + end +end + +function errorMessage(_, _, triggeringButton) + local numInBag = getBlessCurseInBag() + if triggeringButton == "inactiveAction" then + broadcastToAll("There are not enough Blesses and/or Curses in the chaos bag.", "Red") + elseif numInBag.Bless == 10 and numInBag.Curse == 10 then + broadcastToAll("No more tokens can be added to the chaos bag.", "Red") + elseif numInBag.Bless < numInBag.Curse then + broadcastToAll("There are more Bless tokens than Curse tokens in the chaos bag.", "Red") + else + broadcastToAll("There are more Curse tokens than Bless tokens in the chaos bag.", "Red") + end +end \ No newline at end of file diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index f4208b93..1021458c 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -314,7 +314,9 @@ function doUpkeep(_, clickedByColor, isRightClick) local forcedLearning = false local rot = self.getRotation() for _, obj in ipairs(searchAroundSelf()) do - if obj.hasTag("UniversalToken") == true and obj.is_face_down then + if obj.hasTag("Temporary") == true then + discardListOfObjects({obj}) + elseif obj.hasTag("UniversalToken") == true and obj.is_face_down then obj.flip() elseif obj.type == "Card" and not inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then local cardMetadata = JSON.decode(obj.getGMNotes()) or {} diff --git a/xml/playercards/KohakuNarukami.xml b/xml/playercards/KohakuNarukami.xml new file mode 100644 index 00000000..d39c467b --- /dev/null +++ b/xml/playercards/KohakuNarukami.xml @@ -0,0 +1,98 @@ + +