Merge pull request #665 from argonui/mythos-area
Code maintenance for MythosArea
This commit is contained in:
commit
4c62e93db8
@ -8,13 +8,13 @@ local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
|
|||||||
|
|
||||||
local ENCOUNTER_DECK_AREA = {
|
local ENCOUNTER_DECK_AREA = {
|
||||||
upperLeft = { x = 0.9, z = 0.42 },
|
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 = {
|
local ENCOUNTER_DISCARD_AREA = {
|
||||||
upperLeft = { x = 1.62, z = 0.42 },
|
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
|
-- global position of encounter deck and discard pile
|
||||||
local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 }
|
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
|
-- 'params' contains the position, rotation and a boolean to force a faceup draw
|
||||||
function drawEncounterCard(params)
|
function drawEncounterCard(params)
|
||||||
local encounterDeck = getEncounterDeck()
|
local encounterDeck = getEncounterDeck()
|
||||||
|
local reshuffledAlready
|
||||||
|
|
||||||
if encounterDeck then
|
if encounterDeck then
|
||||||
reshuffledAlready = false
|
reshuffledAlready = false
|
||||||
local card
|
|
||||||
if encounterDeck.type == "Deck" then
|
if encounterDeck.type == "Deck" then
|
||||||
card = encounterDeck.takeObject()
|
actualEncounterCardDraw(encounterDeck.takeObject(), params)
|
||||||
else
|
else
|
||||||
card = encounterDeck
|
actualEncounterCardDraw(encounterDeck, params)
|
||||||
end
|
end
|
||||||
actualEncounterCardDraw(card, params)
|
|
||||||
else
|
else
|
||||||
-- nothing here, time to reshuffle
|
-- nothing here, time to reshuffle
|
||||||
if reshuffledAlready == true then
|
if reshuffledAlready == true then
|
||||||
reshuffledAlready = false
|
reshuffledAlready = false
|
||||||
return
|
return
|
||||||
end
|
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
|
reshuffledAlready = true
|
||||||
drawEncounterCard(params)
|
drawEncounterCard(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- draw the provided card to the requesting playmat
|
||||||
function actualEncounterCardDraw(card, params)
|
function actualEncounterCardDraw(card, params)
|
||||||
local metadata = JSON.decode(card.getGMNotes()) or {}
|
local metadata = JSON.decode(card.getGMNotes()) or {}
|
||||||
|
|
||||||
|
-- draw hidden cards facedown
|
||||||
local faceUpRotation = 0
|
local faceUpRotation = 0
|
||||||
if metadata.hidden or DATA_HELPER.call('checkHiddenCard', card.getName()) then
|
if metadata.hidden or DATA_HELPER.call('checkHiddenCard', card.getName()) then
|
||||||
faceUpRotation = 180
|
faceUpRotation = 180
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get position and rotation for the specific playmat
|
||||||
local pos = params.mat.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET)
|
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
|
if not params.stack then
|
||||||
local searchPos = Vector(-0.91, 0.5, -0.625)
|
local searchPos = Vector(-0.91, 0.5, -0.625)
|
||||||
for i = 1, 5 do
|
for i = 1, 5 do
|
||||||
@ -200,7 +205,6 @@ function actualEncounterCardDraw(card, params)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local rot = { 0, params.mat.getRotation().y, faceUpRotation }
|
|
||||||
deckLib.placeOrMergeIntoDeck(card, pos, rot)
|
deckLib.placeOrMergeIntoDeck(card, pos, rot)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -208,21 +212,26 @@ function reshuffleEncounterDeck()
|
|||||||
-- flag to avoid multiple calls
|
-- flag to avoid multiple calls
|
||||||
if isReshuffling then return end
|
if isReshuffling then return end
|
||||||
isReshuffling = true
|
isReshuffling = true
|
||||||
|
|
||||||
local encounterDeck = getEncounterDeck()
|
local encounterDeck = getEncounterDeck()
|
||||||
local discardPile = searchLib.atPosition(ENCOUNTER_DISCARD_POSITION, "isCardOrDeck")
|
local discardPile = searchLib.atPosition(ENCOUNTER_DISCARD_POSITION, "isCardOrDeck")
|
||||||
|
|
||||||
if #discardPile > 0 then
|
if #discardPile > 0 then
|
||||||
local discardDeck = discardPile[1]
|
local discardDeck = discardPile[1]
|
||||||
if not discardDeck.is_face_down then --flips discard pile
|
|
||||||
discardDeck.setRotation({0, -90, 180})
|
-- flips discard pile
|
||||||
end
|
if not discardDeck.is_face_down then
|
||||||
|
discardDeck.setRotation({ 0, -90, 180 })
|
||||||
|
end
|
||||||
|
|
||||||
|
-- make a new encounter deck
|
||||||
if encounterDeck == nil then
|
if encounterDeck == nil then
|
||||||
discardDeck.setPosition(Vector(ENCOUNTER_DECK_POS) + Vector({0, 1, 0}))
|
discardDeck.setPosition(Vector(ENCOUNTER_DECK_POS) + Vector({ 0, 1, 0 }))
|
||||||
discardDeck.shuffle()
|
encounterDeck = discardDeck
|
||||||
else
|
else
|
||||||
encounterDeck.putObject(discardDeck)
|
encounterDeck.putObject(discardDeck)
|
||||||
encounterDeck.shuffle()
|
|
||||||
end
|
end
|
||||||
|
encounterDeck.shuffle()
|
||||||
broadcastToAll("Shuffled encounter discard into deck.", "White")
|
broadcastToAll("Shuffled encounter discard into deck.", "White")
|
||||||
else
|
else
|
||||||
broadcastToAll("Encounter discard pile is already empty.", "Red")
|
broadcastToAll("Encounter discard pile is already empty.", "Red")
|
||||||
@ -231,6 +240,7 @@ function reshuffleEncounterDeck()
|
|||||||
-- disable flag
|
-- disable flag
|
||||||
Wait.time(function() isReshuffling = false end, 1)
|
Wait.time(function() isReshuffling = false end, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- helper functions
|
-- helper functions
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user