From 1ab71a1c60e0ff6c2476034cfaa127f8389d359a Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 4 Dec 2024 16:44:26 +0100 Subject: [PATCH] Updated Chef's Selection --- src/core/Global.ttslua | 52 ++++++++++++++++++++----------- src/tokens/TokenManagerApi.ttslua | 29 ++++++++--------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 8bb6ac042..9a9a3068f 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2184,24 +2184,37 @@ end -- Spawns a set of tokens on the given card. function TokenManager.spawnTokenGroup(params) - local card = params.card - local tokenType = params.tokenType + local card = params.card + local tokenType = params.tokenType local tokenCount = params.tokenCount - local shiftDown = params.shiftDown - local subType = params.subType - local temporary = params.temporary + local replenish = params.replenish + local shiftDown = params.shiftDown + local subType = params.subType + local temporary = params.temporary if tokenType == "damage" or tokenType == "horror" then TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown) - elseif tokenType == "resource" and optionPanel["useResourceCounters"] == "enabled" then - TokenManager.spawnResourceCounterToken(card, tokenCount) - elseif tokenType == "resource" and optionPanel["useResourceCounters"] == "custom" and tokenCount == 0 then + elseif shouldSpawnResourceCounter(tokenType, tokenCount, replenish) then TokenManager.spawnResourceCounterToken(card, tokenCount) else TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown, subType, temporary) end end +function shouldSpawnResourceCounter(tokenType, tokenCount, replenish) + if tokenType == "resource" then + if optionPanel["useResourceCounters"] == "enabled" then + return true + elseif optionPanel["useResourceCounters"] == "custom" then + -- spawn a resource counter for cards with "0 uses" or small amount of replenshing tokens + if tokenCount == 0 or (replenish and tokenCount < 3) then + return true + end + end + end + return false +end + -- Spawns a single counter token and sets the value to tokenValue. Used for damage and horror tokens. ---@param card tts__Object Card to spawn tokens on ---@param tokenType string Type of token to spawn (template needs to be in source bag) @@ -2434,11 +2447,12 @@ function TokenManager.spawnTokensFromUses(card, extraUses) end -- Shift each spawned group after the first down so they don't pile on each other TokenManager.spawnTokenGroup({ - card = card, - tokenType = useInfo.token, + card = card, + tokenType = useInfo.token, tokenCount = tokenCount, - shiftDown = (i - 1) * 0.8, - subType = useInfo.type + replenish = useInfo.replenish, + shiftDown = (i - 1) * 0.8, + subType = useInfo.type }) end @@ -2466,8 +2480,8 @@ end -- the right data for this card. function TokenManager.spawnPlayerCardTokensFromDataHelper(card, playerData) TokenManager.spawnTokenGroup({ - card = card, - tokenType = playerData.tokenType, + card = card, + tokenType = playerData.tokenType, tokenCount = playerData.tokenCount }) tokenSpawnTrackerApi.markTokensSpawned(card.getGUID()) @@ -2481,8 +2495,8 @@ function TokenManager.spawnLocationTokensFromDataHelper(card, locationData) local clueCount = TokenManager.getClueCountFromData(card, locationData) if clueCount > 0 then TokenManager.spawnTokenGroup({ - card = card, - tokenType = "clue", + card = card, + tokenType = "clue", tokenCount = clueCount }) tokenSpawnTrackerApi.markTokensSpawned(card.getGUID()) @@ -2627,10 +2641,10 @@ function TokenManager.replenishTokens(card, useInfo) -- spawn new token group TokenManager.spawnTokenGroup({ - card = card, - tokenType = useInfo.token, + card = card, + tokenType = useInfo.token, tokenCount = newCount, - subType = useInfo.type + subType = useInfo.type }) end end diff --git a/src/tokens/TokenManagerApi.ttslua b/src/tokens/TokenManagerApi.ttslua index 3a4a7b575..c9c161c13 100644 --- a/src/tokens/TokenManagerApi.ttslua +++ b/src/tokens/TokenManagerApi.ttslua @@ -55,12 +55,12 @@ do Global.call("callTable", { { "TokenManager", "spawnToken" }, { - position = position, - rotation = rotation, - tokenType = tokenType, - callbackName = callbackName, + position = position, + rotation = rotation, + tokenType = tokenType, + callbackName = callbackName, callbackParams = callbackParams, - scriptstate = scriptstate + scriptstate = scriptstate } }) end @@ -77,12 +77,12 @@ do Global.call("callTable", { { "TokenManager", "spawnTokenGroup" }, { - card = card, - tokenType = tokenType, + card = card, + tokenType = tokenType, tokenCount = tokenCount, - shiftDown = shiftDown, - subType = subType, - temporary = temporary + shiftDown = shiftDown, + subType = subType, + temporary = temporary } }) end @@ -103,8 +103,8 @@ do { "TokenManager", "getDataForInfiniteBag" }, { tokenType = tokenType, - position = position, - rotation = rotation + position = position, + rotation = rotation } }) end @@ -115,10 +115,7 @@ do function TokenManagerApi.addUseToCard(card, useType) local result = Global.call("callTable", { { "TokenManager", "addUseToCard" }, - { - card = card, - useType = useType - } + { card = card, useType = useType } }) return result end