Merge pull request #665 from argonui/mythos-area

Code maintenance for MythosArea
This commit is contained in:
BootleggerFinn 2024-05-03 00:52:01 -05:00 committed by GitHub
commit 4c62e93db8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,13 +8,13 @@ local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
local ENCOUNTER_DECK_AREA = {
upperLeft = { x = 0.9, z = 0.42 },
lowerRight = { x = 0.86, z = 0.38 },
lowerRight = { x = 0.86, z = 0.38 }
}
local ENCOUNTER_DISCARD_AREA = {
upperLeft = { x = 1.62, z = 0.42 },
lowerRight = { x = 1.58, z = 0.38 },
lowerRight = { x = 1.58, z = 0.38 }
}
local DRAWN_ENCOUNTER_CARD_OFFSET = {1.365, 0.5, -0.625}
local DRAWN_ENCOUNTER_CARD_OFFSET = { 1.365, 0.5, -0.625 }
-- global position of encounter deck and discard pile
local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 }
@ -153,39 +153,44 @@ end
-- 'params' contains the position, rotation and a boolean to force a faceup draw
function drawEncounterCard(params)
local encounterDeck = getEncounterDeck()
local reshuffledAlready
if encounterDeck then
reshuffledAlready = false
local card
if encounterDeck.type == "Deck" then
card = encounterDeck.takeObject()
actualEncounterCardDraw(encounterDeck.takeObject(), params)
else
card = encounterDeck
actualEncounterCardDraw(encounterDeck, params)
end
actualEncounterCardDraw(card, params)
else
-- nothing here, time to reshuffle
if reshuffledAlready == true then
reshuffledAlready = false
return
end
reshuffleEncounterDeck() -- if there is no discard pile either, reshuffleEncounterDeck will give an error message already
-- if there is no discard pile either, reshuffleEncounterDeck will give an error message already
reshuffleEncounterDeck()
reshuffledAlready = true
drawEncounterCard(params)
end
end
-- draw the provided card to the requesting playmat
function actualEncounterCardDraw(card, params)
local metadata = JSON.decode(card.getGMNotes()) or {}
-- draw hidden cards facedown
local faceUpRotation = 0
if metadata.hidden or DATA_HELPER.call('checkHiddenCard', card.getName()) then
faceUpRotation = 180
end
-- get position and rotation for the specific playmat
local pos = params.mat.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET)
local rot = { 0, params.mat.getRotation().y, faceUpRotation }
-- get first empty slot in threat area (right to left)
-- maybe override position with first empty slot in threat area (right to left)
if not params.stack then
local searchPos = Vector(-0.91, 0.5, -0.625)
for i = 1, 5 do
@ -200,7 +205,6 @@ function actualEncounterCardDraw(card, params)
end
end
local rot = { 0, params.mat.getRotation().y, faceUpRotation }
deckLib.placeOrMergeIntoDeck(card, pos, rot)
end
@ -208,21 +212,26 @@ function reshuffleEncounterDeck()
-- flag to avoid multiple calls
if isReshuffling then return end
isReshuffling = true
local encounterDeck = getEncounterDeck()
local discardPile = searchLib.atPosition(ENCOUNTER_DISCARD_POSITION, "isCardOrDeck")
if #discardPile > 0 then
local discardDeck = discardPile[1]
if not discardDeck.is_face_down then --flips discard pile
discardDeck.setRotation({0, -90, 180})
end
-- flips discard pile
if not discardDeck.is_face_down then
discardDeck.setRotation({ 0, -90, 180 })
end
-- make a new encounter deck
if encounterDeck == nil then
discardDeck.setPosition(Vector(ENCOUNTER_DECK_POS) + Vector({0, 1, 0}))
discardDeck.shuffle()
discardDeck.setPosition(Vector(ENCOUNTER_DECK_POS) + Vector({ 0, 1, 0 }))
encounterDeck = discardDeck
else
encounterDeck.putObject(discardDeck)
encounterDeck.shuffle()
end
encounterDeck.shuffle()
broadcastToAll("Shuffled encounter discard into deck.", "White")
else
broadcastToAll("Encounter discard pile is already empty.", "Red")
@ -231,6 +240,7 @@ function reshuffleEncounterDeck()
-- disable flag
Wait.time(function() isReshuffling = false end, 1)
end
---------------------------------------------------------
-- helper functions
---------------------------------------------------------