fixed decklib error

This commit is contained in:
Chr1Z93 2024-07-02 18:43:49 +02:00
parent 199fa6b77c
commit f77f7dace1
3 changed files with 14 additions and 14 deletions

View File

@ -155,10 +155,10 @@ end
function endSearch(_, _, isRightClick) function endSearch(_, _, isRightClick)
local handCards = Player[handColor].getHandObjects() local handCards = Player[handColor].getHandObjects()
local j = 0 local handCount = #handCards
for i = #handCards, 1, -1 do for i = handCount, 1, -1 do
j = j + 1 Wait.time(function() deckLib.placeOrMergeIntoDeck(handCards[i], drawDeckPosition, setAsideRotation) end,
Wait.time(function() deckLib.placeOrMergeIntoDeck(handCards[i], drawDeckPosition, setAsideRotation) end, j * 0.1) (handCount - i + 1) * 0.1)
end end
-- draw set aside cards (from the ground!) -- draw set aside cards (from the ground!)

View File

@ -256,13 +256,11 @@ function discardListOfObjects(objList)
else else
deckLib.placeOrMergeIntoDeck(obj, ENCOUNTER_DISCARD_POSITION, { x = 0, y = -90, z = 0 }) deckLib.placeOrMergeIntoDeck(obj, ENCOUNTER_DISCARD_POSITION, { x = 0, y = -90, z = 0 })
end end
-- put chaos tokens back into bag (e.g. Unrelenting)
elseif tokenChecker.isChaosToken(obj) then elseif tokenChecker.isChaosToken(obj) then
-- put chaos tokens back into bag (e.g. Unrelenting)
chaosBagApi.returnChaosTokenToBag(obj) chaosBagApi.returnChaosTokenToBag(obj)
-- don't touch locked objects (like the table etc.) or specific objects (like key tokens)
elseif not obj.getLock() and not obj.hasTag("DontDiscard") then elseif not obj.getLock() and not obj.hasTag("DontDiscard") then
-- don't touch locked objects (like the table etc.) or specific objects (like key tokens)
ownedObjects.Trash.putObject(obj) ownedObjects.Trash.putObject(obj)
end end
end end
@ -390,8 +388,8 @@ function doUpkeep(_, clickedByColor, isRightClick)
local cardsToDiscard = {} local cardsToDiscard = {}
for i = 1, #handCards do for i = 1, #handCards do
local metadata = JSON.decode(handCards[i].getGMNotes()) local md = JSON.decode(handCards[i].getGMNotes())
if metadata ~= nil and (not metadata.weakness and not metadata.hidden) then if md ~= nil and (not md.weakness and not md.hidden and md.type ~= "Enemy") then
table.insert(cardsToDiscard, handCards[i]) table.insert(cardsToDiscard, handCards[i])
end end
end end
@ -400,13 +398,14 @@ function doUpkeep(_, clickedByColor, isRightClick)
local pos = returnGlobalDiscardPosition() local pos = returnGlobalDiscardPosition()
local count = #cardsToDiscard local count = #cardsToDiscard
for i = count, 1, -1 do for i = count, 1, -1 do
Wait.time(function() deckLib.placeOrMergeIntoDeck(cardsToDiscard[i], pos, rot) end, (count - i + 1) * 0.1) Wait.time(function() deckLib.placeOrMergeIntoDeck(cardsToDiscard[i], pos, rot) end,
(count - i + 1) * 0.1)
end end
-- add some time if there are any cards to discard, if not, draw up to 5 immediately -- add some time if there are any cards to discard, if not, draw up to 5 immediately
local k = 0 local k = 0
if count > 0 then if count > 0 then
k = 1 + (count * 0.1) k = 0.5 + (count * 0.1)
end end
Wait.time(function() Wait.time(function()
@ -575,7 +574,8 @@ function doDiscardOne()
-- get a random non-hidden card (from the "choices" table) -- get a random non-hidden card (from the "choices" table)
local num = math.random(1, #choices) local num = math.random(1, #choices)
deckLib.placeOrMergeIntoDeck(hand[choices[num]], returnGlobalDiscardPosition(), self.getRotation()) deckLib.placeOrMergeIntoDeck(hand[choices[num]], returnGlobalDiscardPosition(), self.getRotation())
broadcastToAll(getColoredName(playerColor) .. " randomly discarded card " .. choices[num] .. "/" .. #hand .. ".", "White") broadcastToAll(getColoredName(playerColor) .. " randomly discarded card "
.. choices[num] .. "/" .. #hand .. ".", "White")
end end
end end

View File

@ -39,7 +39,7 @@ do
function() function()
obj.use_hands = true obj.use_hands = true
-- this avoids a TTS bug that merges unrelated cards that are not resting -- this avoids a TTS bug that merges unrelated cards that are not resting
if #searchResult == 1 and searchResult[1] ~= obj then if #searchResult == 1 and searchResult[1] ~= obj and searchResult[1] ~= nil then
-- call this with avoiding errors (physics is sometimes too fast so the object doesn't exist for the put) -- call this with avoiding errors (physics is sometimes too fast so the object doesn't exist for the put)
pcall(function() searchResult[1].putObject(obj) end) pcall(function() searchResult[1].putObject(obj) end)
end end