Merge pull request #731 from dscarpac/kohaku

Added helper to Kohaku
This commit is contained in:
Chr1Z 2024-07-03 10:13:56 +02:00 committed by GitHub
commit c1f3746ae6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 268 additions and 18 deletions

View File

@ -234,6 +234,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,

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "",
"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"
}

View File

@ -266,6 +266,19 @@ function updateDisplayAndBroadcast(type)
end
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
---------------------------------------------------------
-- main functions: add and remove
---------------------------------------------------------

View File

@ -67,5 +67,9 @@ do
getManager().call("removeToken", type)
end
BlessCurseManagerApi.getBlessCurseInBag = function()
return getManager().call("getBlessCurseInBag", {})
end
return BlessCurseManagerApi
end

View File

@ -1,9 +1,11 @@
require("playercards/CardsWithHelper")
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local chaosBagApi = require("chaosbag/ChaosBagApi")
local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi")
local isHelperEnabled = false
local updated
function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
@ -34,6 +36,7 @@ function initialize()
end
function resolveToken(player, _, tokenType)
if not updated then return end
local matColor
if player.color == "Black" then
matColor = playermatApi.getMatColorByPosition(self.getPosition())
@ -43,11 +46,13 @@ function resolveToken(player, _, tokenType)
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
chaosBagApi.drawChaosToken(mat, true, tokenType)
updated = false
Wait.frames(maybeUpdateButtonState, 2)
end
-- count tokens in the bag and show appropriate buttons
function maybeUpdateButtonState()
local numInBag = getBlessCurseInBag()
local numInBag = blessCurseManagerApi.getBlessCurseInBag()
local state = { Bless = false, Curse = false }
if numInBag.Bless >= numInBag.Curse and numInBag.Bless > 0 then
@ -59,19 +64,7 @@ function maybeUpdateButtonState()
end
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
updated = true
end
function setUiState(params)
@ -87,7 +80,7 @@ function setUiState(params)
end
function errorMessage()
local numInBag = getBlessCurseInBag()
local numInBag = blessCurseManagerApi.getBlessCurseInBag()
if numInBag.Bless == 0 and numInBag.Curse == 0 then
broadcastToAll("There are no Bless or Curse tokens in the chaos bag.", "Red")

View File

@ -0,0 +1,139 @@
require("playercards/CardsWithHelper")
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
local tokenManager = require("core/token/TokenManager")
local isHelperEnabled = false
local updated
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()
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)
if not updated then return end
blessCurseManagerApi.addToken(tokenType)
updated = false
Wait.frames(maybeUpdateButtonState, 2)
end
function removeAndExtraAction()
if not updated then return end
blessCurseManagerApi.removeToken("Bless")
blessCurseManagerApi.removeToken("Bless")
blessCurseManagerApi.removeToken("Curse")
blessCurseManagerApi.removeToken("Curse")
updated = false
Wait.frames(maybeUpdateButtonState, 2)
local position = self.getPosition()
local matColor = playermatApi.getMatColorByPosition(position)
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
local rotation = mat.getRotation()
-- find empty action token slots
-- check snap point states
local snaps = mat.getSnapPoints()
-- get first empty slot
local fullSlots = {}
local positions = {}
for _, snap in ipairs(snaps) do
if snap.tags[1] == "UniversalToken" then
table.insert(positions, mat.positionToWorld(snap.position))
local searchResult = searchLib.atPosition(positions[#positions], "isUniversalToken")
table.insert(fullSlots, #searchResult > 0)
end
end
for i = 2, 6 do -- look at all 5 slots above investigator card
if fullSlots[i] ~= true then
callback = function(spawned) spawned.call("updateClassAndSymbol", { class = "Mystic", symbol = "Mystic" }) spawned.addTag("Temporary") end
tokenManager.spawnToken(positions[i] + Vector(0, 0.7, 0), "universalActionAbility", rotation, callback)
return
end
end
-- if all slots are full
callback = function(spawned) spawned.call("updateClassAndSymbol", { class = "Mystic", symbol = "Mystic" }) spawned.addTag("Temporary") end
tokenManager.spawnToken(position + Vector(0, 0.7, 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 = blessCurseManagerApi.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)
updated = true
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 = blessCurseManagerApi.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

View File

@ -313,7 +313,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 {}

View File

@ -0,0 +1,94 @@
<Defaults>
<Button padding="50 50 50 50"
font="font_teutonic-arkham"
fontSize="200"
iconWidth="300"
iconAlignment="Right"/>
<Button class="inactive"
onClick="errorMessage"
color="#353535E6"
textColor="#A0A0A0"/>
<Button class="active"
onClick="addTokenToBag"
textColor="white"
active="false"/>
<TableLayout position="0 188 -22"
rotation="0 0 90"
height="1800"
width="700"
scale="0.1 0.1 1"
cellSpacing="80"
cellBackgroundColor="rgba(1,1,1,0)"/>
</Defaults>
<Panel id="Helper"
active="false">
<TableLayout>
<Row>
<Cell>
<Button id="Bless"
icon="token-bless"
color="#9D702CE6"
class="active"/>
</Cell>
</Row>
<Row>
<Cell>
<Button id="Curse"
icon="token-curse"
color="#633A84E6"
class="active"/>
</Cell>
</Row>
<Row>
<Cell>
<Button id="Action"
text="Remove tokens"
color="#6D202CE6"
class="active"
onClick="removeAndExtraAction"/>
</Cell>
</Row>
<Row>
<Cell>
<Button id="ElderSign"
icon="token-eldersign"
color="#50A8CEE6"
class="active"
onClick="elderSignAbility"/>
</Cell>
</Row>
</TableLayout>
<TableLayout>
<Row>
<Cell>
<Button id="inactiveBless"
icon="token-bless"
class="inactive"/>
</Cell>
</Row>
<Row>
<Cell>
<Button id="inactiveCurse"
icon="token-curse"
class="inactive"/>
</Cell>
</Row>
<Row>
<Cell>
<Button id="inactiveAction"
text="Remove tokens"
class="inactive"/>
</Cell>
</Row>
<Row>
<Cell>
<Button id="inactiveElderSign"
text="Elder Sign"
icon="token-eldersign"
class="inactive"
onClick="elderSignAbility"/>
</Cell>
</Row>
</TableLayout>
</Panel>