This commit is contained in:
dscarpac 2024-10-05 07:52:34 -05:00
parent 7cb143bfda
commit 49b0c7bc52
7 changed files with 217 additions and 48 deletions

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "",
"LuaScript": "require(\"playercards/cards/TheRedClock\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Card",
@ -58,5 +58,5 @@
"scaleZ": 1
},
"Value": 0,
"XmlUI": ""
"XmlUI": "\u003cInclude src=\"playercards/TheRedClock.xml\"/\u003e"
}

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "",
"LuaScript": "require(\"playercards/cards/TheRedClock\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Card",
@ -58,5 +58,5 @@
"scaleZ": 1
},
"Value": 0,
"XmlUI": ""
"XmlUI": "\u003cInclude src=\"playercards/TheRedClock.xml\"/\u003e"
}

View File

@ -2478,6 +2478,51 @@ function TokenManager.replenishTokens(card, useInfo)
end
end
-- adds a use to a card
---@param card tts__Object Card that should get a use added
---@param useType string Type of uses to be added
function TokenManager.addUseToCard(params)
log(params.useType)
local card = params.card
local useType = params.useType
local metadata = JSON.decode(card.getGMNotes()) or {}
-- get correct data for location
if metadata.type == "Location" then
if not card.is_face_down and metadata.locationFront ~= nil then
metadata = metadata.locationFront
elseif metadata.locationBack ~= nil then
metadata = metadata.locationBack
end
-- if there are no uses at all, add "empty" uses for fake replenishing (only for clues)
if metadata.uses == nil then
metadata.uses = { { token = "clue" } }
end
end
local match = false
for _, useInfo in ipairs(metadata.uses or {}) do
if useInfo.token == useType then
-- artificially create replenish data to re-use that existing functionality
useInfo.count = 999
useInfo.replenish = 1
match = true
else
-- artificially disable other uses from replenishing
useInfo.replenish = nil
end
end
-- if matching uses were found, perform the "fake" replenish
if match then
TokenManager.maybeReplenishCard({ card = card, uses = metadata.uses })
return true
else
return false
end
end
---------------------------------------------------------
-- Callback functions for token spawning
---------------------------------------------------------

View File

@ -96,5 +96,19 @@ do
})
end
-- adds a use to a card
---@param card tts__Object Card that should get a use added
---@param useType string Type of uses to be added
function TokenManagerApi.addUseToCard(card, useType)
local result = Global.call("callTable", {
{ "TokenManager", "addUseToCard" },
{
card = card,
useType = useType
}
})
return result
end
return TokenManagerApi
end

View File

@ -0,0 +1,119 @@
require("playercards/CardsWithHelper")
local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
local tokenManagerApi = require("core/token/TokenManagerApi")
-- intentionally global
hasXML = true
isHelperEnabled = false
function onLoad(savedData)
-- get level via metadata and proceed accordingly:
-- lvl 2: one action
-- lvl 5: two actions
notes = JSON.decode(self.getGMNotes())
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
end
syncDisplayWithOptionPanel()
end
function updateSave()
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled
})
end
function addCharge(player)
tokenManagerApi.addUseToCard(self, "resource")
Wait.time(function() searchSelf() end, 5)
log(foundTokens)
if foundTokens == 3 then
addAction(player)
end
end
function searchSelf(destroy)
clickableResourceCounter = nil
foundTokens = 0
for _, obj in ipairs(searchLib.onObject(self, "isTileOrToken")) do
local image = obj.getCustomObject().image
if image == "https://steamusercontent-a.akamaihd.net/ugc/2028355744161230179/E3A30A2D661A12205D98D4D0E374591586C5C486/" then
foundTokens = foundTokens + math.abs(obj.getQuantity())
if destroy then obj.destruct() end
return foundTokens
elseif obj.getMemo() == "resourceCounter" then
foundTokens = obj.getVar("val")
clickableResourceCounter = obj
return foundTokens
end
end
end
function takeAll(player)
local destroy = true
searchSelf(destroy)
local matColor = playermatApi.getMatColorByPosition(self.getPosition())
playermatApi.updateCounter(matColor, "ResourceCounter", _, foundTokens)
if clickableResourceCounter then
clickableResourceCounter.call("updateVal", 0)
end
if notes.id == "08058" then
Wait.frames(function() addCharge(player) end, 2)
broadcastToColor("Moved " .. foundTokens .. " resource(s) to " .. matColor .. "'s resource pool and placed one charge.", player.color)
else
broadcastToColor("Moved " .. foundTokens .. " resource(s) to " .. matColor .. "'s resource pool.", player.color)
end
end
function addAction(player)
if notes.id == "08058" then
spawnActionToken(2)
broadcastToColor("Spawning two temporary action tokens.", player.color)
else
spawnActionToken(1)
broadcastToColor("Spawning one temporary action token.", player.color)
end
end
function spawnActionToken(numTokens)
local position = self.getPosition()
local matColor = playermatApi.getMatColorByPosition(position)
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
local rotation = mat.getRotation()
-- find empty action token slots by checking snap points
local snaps = mat.getSnapPoints()
-- get empty slots
local emptyPositions = {}
for i, snap in ipairs(snaps) do
if i > 1 then
if snap.tags[1] == "UniversalToken" then
local snapPos = mat.positionToWorld(snap.position)
local searchResult = searchLib.atPosition(snapPos, "isUniversalToken")
if #searchResult == 0 then
table.insert(emptyPositions, snapPos)
end
end
end
end
local activeInvestigatorData = playermatApi.getActiveInvestigatorData(matColor)
local callbackParams = { class = activeInvestigatorData.class, symbol = activeInvestigatorData.class, addTag = "Temporary" }
local callbackName = "updateUniversalActionAbilityToken"
for i = 1, numTokens do
if emptyPositions[i] ~= nil then
tokenManagerApi.spawnToken(emptyPositions[i] + Vector(0, 0.7, 0), "universalActionAbility", rotation, callbackName, callbackParams)
else
tokenManagerApi.spawnToken(position + Vector(0, 0.7, 0), "universalActionAbility", rotation, callbackName, callbackParams)
end
end
end

View File

@ -28,7 +28,7 @@ function onScriptingButtonDown(index, playerColor)
local card = getTargetCard(playerColor, position)
if card and not card.is_face_down then
local status = addUseToCard(card, tokenType)
local status = tokenManagerApi.addUseToCard(card, tokenType)
if status == true then return end
end
@ -37,7 +37,7 @@ function onScriptingButtonDown(index, playerColor)
local card = getTargetCard(playerColor, position)
if card and (not card.is_face_down or card.hasTag("Location")) then
local status = addUseToCard(card, tokenType)
local status = tokenManagerApi.addUseToCard(card, tokenType)
if status == true then return end
end
@ -85,45 +85,3 @@ function getTargetCard(playerColor, position)
end
end
end
-- adds a use to a card (TODO: probably move this to the TokenManager?)
---@param card tts__Object Card that should get a use added
---@param useType string Type of uses to be added
function addUseToCard(card, useType)
local metadata = JSON.decode(card.getGMNotes()) or {}
-- get correct data for location
if metadata.type == "Location" then
if not card.is_face_down and metadata.locationFront ~= nil then
metadata = metadata.locationFront
elseif metadata.locationBack ~= nil then
metadata = metadata.locationBack
end
-- if there are no uses at all, add "empty" uses for fake replenishing (only for clues)
if metadata.uses == nil then
metadata.uses = { { token = "clue" } }
end
end
local match = false
for _, useInfo in ipairs(metadata.uses or {}) do
if useInfo.token == useType then
-- artificially create replenish data to re-use that existing functionality
useInfo.count = 999
useInfo.replenish = 1
match = true
else
-- artificially disable other uses from replenishing
useInfo.replenish = nil
end
end
-- if matching uses were found, perform the "fake" replenish
if match then
tokenManagerApi.maybeReplenishCard(card, metadata.uses)
return true
else
return false
end
end

View File

@ -0,0 +1,33 @@
<Defaults>
<Button padding="50 50 50 50"
font="font_teutonic-arkham"
fontSize="200"
textColor="White"
iconWidth="300"
iconAlignment="Right"/>
<TableLayout position="0 125 -22"
rotation="0 0 180"
height="350"
width="1400"
scale="0.1 0.1 1"
cellSpacing="80"
cellBackgroundColor="rgba(1,1,1,0)"/>
</Defaults>
<TableLayout id="Helper"
active="false">
<Row>
<Cell>
<Button id="Resources"
onClick="takeAll"
color="#173B0BE6"
text="Take"/>
</Cell>
<Cell>
<Button id="Charges"
onClick="addCharge"
color="#77674DE6"
text="Place"/>
</Cell>
</Row>
</TableLayout>