Implemented proper replenishing for resource spawning hotkey
This commit is contained in:
parent
8ac0c7a48a
commit
34ab661f7f
@ -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
|
||||||
|
@ -343,8 +343,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
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
local card
|
||||||
|
local hoverObj = Player[playerColor].getHoverObject()
|
||||||
|
if hoverObj and hoverObj.type == "Card" then
|
||||||
|
card = hoverObj
|
||||||
|
elseif hoverObj then
|
||||||
|
-- use the first card below the hovered object if it's not a card1
|
||||||
for _, obj in ipairs(searchLib.belowPosition(position, "isCard")) do
|
for _, obj in ipairs(searchLib.belowPosition(position, "isCard")) do
|
||||||
if not obj.is_face_down then
|
card = obj
|
||||||
local metadata = JSON.decode(obj.getGMNotes()) or {}
|
|
||||||
local uses = metadata.uses or {}
|
|
||||||
for _, useInfo in ipairs(uses) do
|
|
||||||
if useInfo.token == "resource" then
|
|
||||||
subType = useInfo.type
|
|
||||||
break
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user