Merge pull request #65 from argonui/uses-fixes
Fix multiple bugs with uses
This commit is contained in:
commit
26d5ce4c57
@ -194,25 +194,35 @@ function doUpkeep(_, color, alt_click)
|
||||
-- unexhaust cards in play zone, flip action tokens and find forcedLearning
|
||||
for _, v in ipairs(searchArea(PLAY_ZONE_POSITION, PLAY_ZONE_SCALE)) do
|
||||
local obj = v.hit_object
|
||||
if obj.tag == "Card" and not obj.is_face_down and not doNotReady(obj) then
|
||||
local notes = JSON.decode(obj.getGMNotes()) or {}
|
||||
if notes.id == "08031" then
|
||||
forcedLearning = true
|
||||
elseif notes.type ~= "Investigator" then
|
||||
if obj.getDescription() == "Action Token" and obj.is_face_down then
|
||||
obj.flip()
|
||||
elseif obj.tag == "Card" and not obj.is_face_down then
|
||||
local cardMetadata = JSON.decode(obj.getGMNotes()) or {}
|
||||
if not doNotReady(obj) and cardMetadata.type ~= "Investigator" then
|
||||
obj.setRotation(PLAY_ZONE_ROTATION)
|
||||
|
||||
end
|
||||
if cardMetadata.id == "08031" then
|
||||
forcedLearning = true
|
||||
end
|
||||
if cardMetadata.uses ~= nil then
|
||||
-- check for cards with 'replenish' in their metadata
|
||||
if notes.uses ~= nil then
|
||||
local count = notes.uses[1].count
|
||||
local replenish = notes.uses[1].replenish
|
||||
local count
|
||||
local replenish
|
||||
-- Uses structure underwent a breaking change in 2.4.0, have to check to see if this is
|
||||
-- a single entry or an array. TODO: Clean this up when 2.4.0 has been out long
|
||||
-- enough that saved decks don't have old data
|
||||
if cardMetadata.uses.count ~= nil then
|
||||
count = cardMetadata.uses.count
|
||||
replenish = cardMetadata.uses.replenish
|
||||
else
|
||||
count = cardMetadata.uses[1].count
|
||||
replenish = cardMetadata.uses[1].replenish
|
||||
end
|
||||
if count and replenish then
|
||||
replenishTokens(obj, count, replenish)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif obj.getDescription() == "Action Token" and obj.is_face_down then
|
||||
obj.flip()
|
||||
end
|
||||
end
|
||||
|
||||
-- flip investigator mini-card if found
|
||||
@ -350,10 +360,26 @@ function spawnTokenOn(object, offsets, tokenType)
|
||||
spawnToken(tokenPosition, tokenType)
|
||||
end
|
||||
|
||||
-- spawn a group of tokens of the given type on the object
|
||||
function spawnTokenGroup(object, tokenType, tokenCount)
|
||||
-- Spawn a group of tokens of the given type on the object
|
||||
-- @param object Object to spawn the tokens on
|
||||
-- @param tokenType Type of token to be spawned
|
||||
-- @param tokenCount Number of tokens to spawn
|
||||
-- @param shiftDown Amount to shift this group down to avoid spawning multiple token groups on
|
||||
-- top of each other. Negative values are allowed, and will move the group up instead. This is
|
||||
-- a static value and is unaware of how many tokens were spawned previously; callers should
|
||||
-- ensure the proper shift.
|
||||
function spawnTokenGroup(object, tokenType, tokenCount, shiftDown)
|
||||
if (tokenCount < 1 or tokenCount > 12) then return end
|
||||
local offsets = PLAYER_CARD_TOKEN_OFFSETS[tokenCount]
|
||||
if shiftDown ~= nil then
|
||||
-- Copy the offsets to make sure we don't change the static values
|
||||
local baseOffsets = offsets
|
||||
offsets = { }
|
||||
for i, baseOffset in ipairs(baseOffsets) do
|
||||
offsets[i] = baseOffset
|
||||
offsets[i][3] = offsets[i][3] + shiftDown
|
||||
end
|
||||
end
|
||||
if offsets == nil then error("couldn't find offsets for " .. tokenCount .. ' tokens') end
|
||||
|
||||
for i = 1, tokenCount do
|
||||
@ -435,11 +461,23 @@ function spawnTokensFor(object)
|
||||
local token = nil
|
||||
local tokenCount = 0
|
||||
if cardMetadata.uses ~= nil then
|
||||
for _, useInfo in ipairs(cardMetadata.uses) do
|
||||
-- Uses structure underwent a breaking change in 2.4.0, have to check to see if this is
|
||||
-- a single entry or an array. This is ugly and duplicated, but impossible to replicate the
|
||||
-- multi-spawn vs. single spawn otherwise. TODO: Clean this up when 2.4.0 has been out long
|
||||
-- enough that saved decks don't have old data
|
||||
if cardMetadata.uses.count != nil then
|
||||
type = cardMetadata.uses.type
|
||||
token = cardMetadata.uses.token
|
||||
tokenCount = cardMetadata.uses.count
|
||||
if activeInvestigatorId == "03004" and type == "Charge" then tokenCount = tokenCount + 1 end
|
||||
|
||||
log("Spawning tokens for "..object.getName()..'['..object.getDescription()..']: '..tokenCount.."x "..token)
|
||||
spawnTokenGroup(object, token, tokenCount)
|
||||
else
|
||||
for i, useInfo in ipairs(cardMetadata.uses) do
|
||||
type = useInfo.type
|
||||
token = useInfo.token
|
||||
tokenCount = useInfo.count
|
||||
end
|
||||
|
||||
-- additional uses for certain customizable cards (by checking the upgradesheets)
|
||||
if customizationsTable[cardMetadata.id] ~= nil then
|
||||
@ -461,7 +499,10 @@ function spawnTokensFor(object)
|
||||
if activeInvestigatorId == "03004" and type == "Charge" then tokenCount = tokenCount + 1 end
|
||||
|
||||
log("Spawning tokens for "..object.getName()..'['..object.getDescription()..']: '..tokenCount.."x "..token)
|
||||
spawnTokenGroup(object, token, tokenCount)
|
||||
-- Shift each spawned group after the first down so they don't pile on each other
|
||||
spawnTokenGroup(object, token, tokenCount, (i - 1) * 0.6)
|
||||
end
|
||||
end
|
||||
else
|
||||
local data = getPlayerCardData(object)
|
||||
token = data['tokenType']
|
||||
|
Loading…
x
Reference in New Issue
Block a user