Fixed card drawing with reshuffle
This commit is contained in:
parent
5621ed2270
commit
fc95bbde56
@ -225,7 +225,11 @@ function onObjectEnterZone(zone, object)
|
|||||||
elseif zone.type == "Hand" and object.type == "Card" then
|
elseif zone.type == "Hand" and object.type == "Card" then
|
||||||
-- make sure the card is face-up
|
-- make sure the card is face-up
|
||||||
if object.is_face_down then
|
if object.is_face_down then
|
||||||
object.flip()
|
if object.held_by_color then
|
||||||
|
object.held_flip_index = 0
|
||||||
|
else
|
||||||
|
object.flip()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- maybe reset data about sealed tokens (if that function exists)
|
-- maybe reset data about sealed tokens (if that function exists)
|
||||||
|
@ -54,22 +54,22 @@ local SEARCH_AROUND_SELF_Z_BUFFER = 1.75
|
|||||||
|
|
||||||
-- defined areas for object searching
|
-- defined areas for object searching
|
||||||
local MAIN_PLAY_AREA = {
|
local MAIN_PLAY_AREA = {
|
||||||
upperLeft = { x = 1.98, z = 0.736 },
|
upperLeft = { x = 1.98, z = 0.736 },
|
||||||
lowerRight = { x = -0.79, z = -0.39 }
|
lowerRight = { x = -0.79, z = -0.39 }
|
||||||
}
|
}
|
||||||
local INVESTIGATOR_AREA = {
|
local INVESTIGATOR_AREA = {
|
||||||
upperLeft = { x = -1.084, z = 0.06517 },
|
upperLeft = { x = -1.084, z = 0.06517 },
|
||||||
lowerRight = { x = -1.258, z = -0.0805 }
|
lowerRight = { x = -1.258, z = -0.0805 }
|
||||||
}
|
}
|
||||||
local THREAT_AREA = {
|
local THREAT_AREA = {
|
||||||
upperLeft = { x = 1.53, z = -0.34 },
|
upperLeft = { x = 1.53, z = -0.34 },
|
||||||
lowerRight = { x = -1.13, z = -0.92 }
|
lowerRight = { x = -1.13, z = -0.92 }
|
||||||
}
|
}
|
||||||
local DECK_DISCARD_AREA = {
|
local DECK_DISCARD_AREA = {
|
||||||
upperLeft = { x = -1.62, z = 0.855 },
|
upperLeft = { x = -1.62, z = 0.855 },
|
||||||
lowerRight = { x = -2.02, z = -0.245 },
|
lowerRight = { x = -2.02, z = -0.245 },
|
||||||
center = { x = -1.82, y = 0.5, z = 0.305 },
|
center = { x = -1.82, y = 0.5, z = 0.305 },
|
||||||
size = { x = 0.4, y = 3, z = 1.1 }
|
size = Vector(0.4, 3, 1.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- local positions
|
-- local positions
|
||||||
@ -252,13 +252,7 @@ end
|
|||||||
-- searches the area around the draw deck and discard pile
|
-- searches the area around the draw deck and discard pile
|
||||||
function searchDeckAndDiscardArea(filter)
|
function searchDeckAndDiscardArea(filter)
|
||||||
local pos = self.positionToWorld(DECK_DISCARD_AREA.center)
|
local pos = self.positionToWorld(DECK_DISCARD_AREA.center)
|
||||||
local scale = self.getScale()
|
return searchArea(pos, DECK_DISCARD_AREA.size * self.getScale(), filter)
|
||||||
local size = {
|
|
||||||
x = DECK_DISCARD_AREA.size.x * scale.x,
|
|
||||||
y = DECK_DISCARD_AREA.size.y,
|
|
||||||
z = DECK_DISCARD_AREA.size.z * scale.z
|
|
||||||
}
|
|
||||||
return searchArea(pos, size, filter)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- rounds a number to the specified amount of decimal places
|
-- rounds a number to the specified amount of decimal places
|
||||||
@ -518,58 +512,73 @@ end
|
|||||||
-- draws the specified amount of cards (and shuffles the discard if necessary)
|
-- draws the specified amount of cards (and shuffles the discard if necessary)
|
||||||
---@param numCards number Number of cards to draw
|
---@param numCards number Number of cards to draw
|
||||||
function drawCardsWithReshuffle(numCards)
|
function drawCardsWithReshuffle(numCards)
|
||||||
local deckAreaObjects = getDeckAreaObjects()
|
function drawCardsCoroutine()
|
||||||
|
local deckAreaObjects = getDeckAreaObjects()
|
||||||
|
|
||||||
-- Norman Withers handling
|
-- Norman Withers handling
|
||||||
local harbinger
|
local harbinger
|
||||||
if deckAreaObjects.topCard then
|
if deckAreaObjects.topCard then
|
||||||
harbinger = isHarbinger(deckAreaObjects.topCard.getGMNotes())
|
harbinger = isHarbinger(deckAreaObjects.topCard.getGMNotes())
|
||||||
elseif deckAreaObjects.draw and not deckAreaObjects.draw.is_face_down then
|
elseif deckAreaObjects.draw and not deckAreaObjects.draw.is_face_down then
|
||||||
local cards = deckAreaObjects.draw.getObjects()
|
local cards = deckAreaObjects.draw.getObjects()
|
||||||
harbinger = isHarbinger(cards[#cards].gm_notes)
|
harbinger = isHarbinger(cards[#cards].gm_notes)
|
||||||
end
|
|
||||||
|
|
||||||
if harbinger then
|
|
||||||
printToColor("The Harbinger is on top of your deck, not drawing cards", messageColor)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local topCardDetected = false
|
|
||||||
if deckAreaObjects.topCard ~= nil then
|
|
||||||
deckAreaObjects.topCard.deal(1, playerColor)
|
|
||||||
topCardDetected = true
|
|
||||||
numCards = numCards - 1
|
|
||||||
if numCards == 0 then
|
|
||||||
flipTopCardFromDeck()
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local deckSize = 1
|
if harbinger then
|
||||||
if deckAreaObjects.draw == nil then
|
printToColor("The Harbinger is on top of your deck, not drawing cards", messageColor)
|
||||||
deckSize = 0
|
return 1
|
||||||
elseif deckAreaObjects.draw.type == "Deck" then
|
|
||||||
deckSize = #deckAreaObjects.draw.getObjects()
|
|
||||||
end
|
|
||||||
|
|
||||||
if deckSize >= numCards then
|
|
||||||
drawCards(numCards)
|
|
||||||
if topCardDetected then
|
|
||||||
flipTopCardFromDeck()
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
drawCards(deckSize)
|
-- draw the top card if possible
|
||||||
|
local topCardDetected = false
|
||||||
|
if deckAreaObjects.topCard ~= nil then
|
||||||
|
deckAreaObjects.topCard.deal(1, playerColor)
|
||||||
|
topCardDetected = true
|
||||||
|
numCards = numCards - 1
|
||||||
|
if numCards == 0 then
|
||||||
|
flipTopCardFromDeck()
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- determine deck size
|
||||||
|
local deckSize = 1
|
||||||
|
if deckAreaObjects.draw == nil then
|
||||||
|
deckSize = 0
|
||||||
|
elseif deckAreaObjects.draw.type == "Deck" then
|
||||||
|
deckSize = #deckAreaObjects.draw.getObjects()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- draw additional cards from existing deck
|
||||||
|
if deckSize >= numCards then
|
||||||
|
drawCards(deckAreaObjects.draw, numCards)
|
||||||
|
if topCardDetected then
|
||||||
|
flipTopCardFromDeck()
|
||||||
|
end
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- draw the full deck, form a new deck and draw the remaining cards
|
||||||
|
drawCards(deckAreaObjects.draw, deckSize)
|
||||||
if deckAreaObjects.discard ~= nil then
|
if deckAreaObjects.discard ~= nil then
|
||||||
|
coWaitFrames(30)
|
||||||
shuffleDiscardIntoDeck()
|
shuffleDiscardIntoDeck()
|
||||||
Wait.time(function()
|
if deckAreaObjects.discard.type == "Card" then
|
||||||
drawCards(numCards - deckSize)
|
coWaitSeconds(1 * 0.1 + 0.25)
|
||||||
if topCardDetected then
|
else
|
||||||
flipTopCardFromDeck()
|
coWaitSeconds(#deckAreaObjects.discard.getObjects() * 0.1 + 0.25)
|
||||||
end
|
end
|
||||||
end, 1)
|
local shuffledObjects = getDeckAreaObjects()
|
||||||
|
drawCards(shuffledObjects.draw, numCards - deckSize)
|
||||||
|
if topCardDetected then
|
||||||
|
flipTopCardFromDeck()
|
||||||
|
end
|
||||||
|
printToColor("Take 1 horror (drawing card from empty deck)", messageColor)
|
||||||
end
|
end
|
||||||
printToColor("Take 1 horror (drawing card from empty deck)", messageColor)
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
startLuaCoroutine(self, "drawCardsCoroutine")
|
||||||
end
|
end
|
||||||
|
|
||||||
function isHarbinger(notes)
|
function isHarbinger(notes)
|
||||||
@ -595,11 +604,11 @@ function getDeckAreaObjects()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- draws the specified number of cards (reshuffling of discard pile is handled separately)
|
-- draws the specified number of cards (reshuffling of discard pile is handled separately)
|
||||||
|
---@param cardOrDeck tts__Object Card/Deck to draw from
|
||||||
---@param numCards number Number of cards to draw
|
---@param numCards number Number of cards to draw
|
||||||
function drawCards(numCards)
|
function drawCards(cardOrDeck, numCards)
|
||||||
local deckAreaObjects = getDeckAreaObjects()
|
if cardOrDeck ~= nil then
|
||||||
if deckAreaObjects.draw then
|
cardOrDeck.deal(numCards, playerColor)
|
||||||
deckAreaObjects.draw.deal(numCards, playerColor)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -639,7 +648,11 @@ function shuffleDiscardIntoDeck(player, _, elementId)
|
|||||||
table.insert(objectsToShuffle, deckAreaObjects.topCard)
|
table.insert(objectsToShuffle, deckAreaObjects.topCard)
|
||||||
|
|
||||||
-- this will be executed after the deck merging + shuffling
|
-- this will be executed after the deck merging + shuffling
|
||||||
Wait.time(flipTopCardFromDeck, 1)
|
if deckAreaObjects.discard.type == "Card" then
|
||||||
|
Wait.time(flipTopCardFromDeck, 1 * 0.1 + 0.5)
|
||||||
|
else
|
||||||
|
Wait.time(flipTopCardFromDeck, #deckAreaObjects.discard.getObjects() * 0.1 + 0.5)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(objectsToShuffle, deckAreaObjects.discard)
|
table.insert(objectsToShuffle, deckAreaObjects.discard)
|
||||||
@ -651,8 +664,9 @@ end
|
|||||||
function flipTopCardFromDeck()
|
function flipTopCardFromDeck()
|
||||||
Wait.time(function()
|
Wait.time(function()
|
||||||
local deckAreaObjects = getDeckAreaObjects()
|
local deckAreaObjects = getDeckAreaObjects()
|
||||||
if deckAreaObjects.topCard then
|
if deckAreaObjects.topCard ~= nil then return end
|
||||||
elseif deckAreaObjects.draw then
|
|
||||||
|
if deckAreaObjects.draw ~= nil then
|
||||||
if deckAreaObjects.draw.type == "Card" then
|
if deckAreaObjects.draw.type == "Card" then
|
||||||
deckAreaObjects.draw.flip()
|
deckAreaObjects.draw.flip()
|
||||||
else
|
else
|
||||||
@ -1711,3 +1725,18 @@ end
|
|||||||
function getActiveInvestigatorData() return activeInvestigatorData end
|
function getActiveInvestigatorData() return activeInvestigatorData end
|
||||||
|
|
||||||
function setActiveInvestigatorData(newData) activeInvestigatorData = newData end
|
function setActiveInvestigatorData(newData) activeInvestigatorData = newData end
|
||||||
|
|
||||||
|
-- pauses the current coroutine for 'frameCount' frames
|
||||||
|
function coWaitFrames(frameCount)
|
||||||
|
for k = 1, frameCount do
|
||||||
|
coroutine.yield(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- pauses the current coroutine for 'seconds' seconds
|
||||||
|
function coWaitSeconds(seconds)
|
||||||
|
local startTime = os.clock()
|
||||||
|
while os.clock() - startTime < seconds do
|
||||||
|
coroutine.yield(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user