Merge branch 'kohaku' of https://github.com/dscarpac/SCED into kohaku

This commit is contained in:
dscarpac 2024-06-28 11:41:28 -05:00
commit c001dbd755
6 changed files with 48 additions and 39 deletions

View File

@ -7,5 +7,12 @@
"level": 0, "level": 0,
"traits": "Item. Illicit.", "traits": "Item. Illicit.",
"intellectIcons": 1, "intellectIcons": 1,
"uses": [
{
"count": 0,
"type": "Suspicion",
"token": "resource"
}
],
"cycle": "The Feast of Hemlock Vale" "cycle": "The Feast of Hemlock Vale"
} }

View File

@ -8,5 +8,12 @@
"traits": "Item. Illicit.", "traits": "Item. Illicit.",
"intellectIcons": 1, "intellectIcons": 1,
"agilityIcons": 1, "agilityIcons": 1,
"uses": [
{
"count": 0,
"type": "Suspicion",
"token": "resource"
}
],
"cycle": "The Feast of Hemlock Vale" "cycle": "The Feast of Hemlock Vale"
} }

View File

@ -211,8 +211,11 @@ do
if tokenType == "clue" then if tokenType == "clue" then
offsets = internal.buildClueOffsets(card, tokenCount) offsets = internal.buildClueOffsets(card, tokenCount)
else else
-- only up to 12 offset tables defined -- only up to 12 offset tables defined (TODO: stack more than 12 tokens and generate offsets dynamically)
if tokenCount > 12 then return end if tokenCount > 12 then
printToAll("Spawning maximum of 12 tokens.")
tokenCount = 12
end
for i = 1, tokenCount do for i = 1, tokenCount do
offsets[i] = card.positionToWorld(PLAYER_CARD_TOKEN_OFFSETS[tokenCount][i]) offsets[i] = card.positionToWorld(PLAYER_CARD_TOKEN_OFFSETS[tokenCount][i])
-- Fix the y-position for the spawn, since positionToWorld considers rotation which can -- Fix the y-position for the spawn, since positionToWorld considers rotation which can
@ -302,8 +305,7 @@ do
end end
end end
-- Delegate function to the token spawn tracker. Exists to avoid circular dependencies in some -- Delegate function to the token spawn tracker. Exists to avoid circular dependencies in some callers
-- callers.
---@param card tts__Object Card object to reset the tokens for ---@param card tts__Object Card object to reset the tokens for
TokenManager.resetTokensSpawned = function(card) TokenManager.resetTokensSpawned = function(card)
tokenSpawnTrackerApi.resetTokensSpawned(card.getGUID()) tokenSpawnTrackerApi.resetTokensSpawned(card.getGUID())
@ -483,11 +485,6 @@ do
---@param uses table The already decoded metadata.uses (to avoid decoding again) ---@param uses table The already decoded metadata.uses (to avoid decoding again)
---@param mat tts__Object The playermat the card is placed on (for rotation and casting) ---@param mat tts__Object The playermat the card is placed on (for rotation and casting)
internal.replenishTokens = function(card, uses, mat) internal.replenishTokens = function(card, uses, mat)
local cardPos = card.getPosition()
-- don't continue for cards on the deck (Norman) or in the discard pile
if mat.positionToLocal(cardPos).x < -1 then return end
-- get current amount of resource tokens on the card -- get current amount of resource tokens on the card
local clickableResourceCounter = nil local clickableResourceCounter = nil
local foundTokens = 0 local foundTokens = 0
@ -511,7 +508,7 @@ do
-- if there are already more uses than the replenish amount, keep them -- if there are already more uses than the replenish amount, keep them
if foundTokens > uses[1].count then if foundTokens > uses[1].count then
newCount = foundTokens newCount = foundTokens
-- only replenish up until the replenish amount -- only replenish up until the replenish amount
elseif newCount > uses[1].count then elseif newCount > uses[1].count then
newCount = uses[1].count newCount = uses[1].count
end end

View File

@ -345,8 +345,8 @@ function doUpkeep(_, clickedByColor, isRightClick)
forcedLearning = true forcedLearning = true
end end
-- maybe replenish uses on certain cards -- maybe replenish uses on certain cards (don't continue for cards on the deck (Norman) or in the discard pile)
if cardMetadata.uses ~= nil then if cardMetadata.uses ~= nil and self.positionToLocal(obj.getPosition()).x < -1 then
tokenManager.maybeReplenishCard(obj, cardMetadata.uses, self) tokenManager.maybeReplenishCard(obj, cardMetadata.uses, self)
end end
elseif obj.type == "Deck" and forcedLearning == false then elseif obj.type == "Deck" and forcedLearning == false then

View File

@ -60,6 +60,7 @@ do
-- searches below the specified position (downwards until y = 0) -- searches below the specified position (downwards until y = 0)
SearchLib.belowPosition = function(pos, filter) SearchLib.belowPosition = function(pos, filter)
size = { 0.1, 2, 0.1 }
direction = { 0, -1, 0 } direction = { 0, -1, 0 }
maxDistance = pos.y maxDistance = pos.y
return returnSearchResult(pos, _, size, filter, direction, maxDistance) return returnSearchResult(pos, _, size, filter, direction, maxDistance)

View File

@ -1,3 +1,4 @@
local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
local tokenManager = require("core/token/TokenManager") local tokenManager = require("core/token/TokenManager")
@ -12,17 +13,6 @@ TOKEN_INDEX[7] = "doom"
TOKEN_INDEX[8] = "clue" TOKEN_INDEX[8] = "clue"
TOKEN_INDEX[9] = "resource" TOKEN_INDEX[9] = "resource"
local stateTable = {
["resource"] = 1,
["ammo"] = 2,
["bounty"] = 3,
["charge"] = 4,
["evidence"] = 5,
["secret"] = 6,
["supply"] = 7,
["offering"] = 8
}
---@param index number Index of the pressed key ---@param index number Index of the pressed key
---@param playerColor string Color of the triggering player ---@param playerColor string Color of the triggering player
function onScriptingButtonDown(index, playerColor) function onScriptingButtonDown(index, playerColor)
@ -31,29 +21,36 @@ function onScriptingButtonDown(index, playerColor)
local rotation = { x = 0, y = Player[playerColor].getPointerRotation(), z = 0 } local rotation = { x = 0, y = Player[playerColor].getPointerRotation(), z = 0 }
local position = Player[playerColor].getPointerPosition() + Vector(0, 0.2, 0) local position = Player[playerColor].getPointerPosition() + Vector(0, 0.2, 0)
local subType = ""
local callback = nil
-- check for subtype of resource based on card below -- check for subtype of resource based on card below
if tokenType == "resource" then if tokenType == "resource" then
for _, obj in ipairs(searchLib.belowPosition(position, "isCard")) do local card
if not obj.is_face_down then local hoverObj = Player[playerColor].getHoverObject()
local metadata = JSON.decode(obj.getGMNotes()) or {} if hoverObj and hoverObj.type == "Card" then
local uses = metadata.uses or {} card = hoverObj
for _, useInfo in ipairs(uses) do elseif hoverObj then
if useInfo.token == "resource" then -- use the first card below the hovered object if it's not a card1
subType = useInfo.type for _, obj in ipairs(searchLib.belowPosition(position, "isCard")) do
break card = obj
end
end
break break
end end
end end
-- this is used to load the correct state for additional resource tokens (e.g. "Ammo") -- get the metadata from the card and maybe replenish a use
local stateID = stateTable[string.lower(subType)] if card and not card.is_face_down then
if stateID ~= nil and stateID ~= 1 then local metadata = JSON.decode(card.getGMNotes()) or {}
callback = function(spawned) spawned.setState(stateID) end local uses = metadata.uses or {}
for _, useInfo in ipairs(uses) do
if useInfo.token == "resource" then
-- artifically create replenish data to re-use that existing functionality
uses[1].count = 999
uses[1].replenish = 1
local matColor = playermatApi.getMatColorByPosition(position)
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
tokenManager.maybeReplenishCard(card, uses, mat)
return
end
end
end end
-- check hovered object for "resourceCounter" tokens and increase them instead -- check hovered object for "resourceCounter" tokens and increase them instead
elseif tokenType == "resourceCounter" then elseif tokenType == "resourceCounter" then