Merge pull request #544 from dscarpac/encounter-discard-reshuffle
added button to reshuffle encounter discard pile into deck
This commit is contained in:
commit
6d876f27d2
@ -82,5 +82,5 @@
|
||||
"scaleZ": 6.5
|
||||
},
|
||||
"Value": 0,
|
||||
"XmlUI": ""
|
||||
"XmlUI": "\u003cInclude src=\"MythosArea.xml\"/\u003e"
|
||||
}
|
||||
|
@ -134,13 +134,6 @@ end
|
||||
function getEncounterDeck()
|
||||
local searchResult = searchLib.atPosition(ENCOUNTER_DECK_POS, "isCardOrDeck")
|
||||
|
||||
for _, obj in ipairs(searchResult) do
|
||||
if obj.type == 'Deck' then
|
||||
return obj
|
||||
end
|
||||
end
|
||||
|
||||
-- if no deck was found, return the first hit (a card)
|
||||
if #searchResult > 0 then
|
||||
return searchResult[1]
|
||||
end
|
||||
@ -151,6 +144,7 @@ function drawEncounterCard(params)
|
||||
local encounterDeck = getEncounterDeck()
|
||||
|
||||
if encounterDeck then
|
||||
reshuffledAlready = false
|
||||
local card
|
||||
if encounterDeck.type == "Deck" then
|
||||
card = encounterDeck.takeObject()
|
||||
@ -160,7 +154,13 @@ function drawEncounterCard(params)
|
||||
actualEncounterCardDraw(card, params)
|
||||
else
|
||||
-- nothing here, time to reshuffle
|
||||
reshuffleEncounterDeck(params)
|
||||
if reshuffledAlready == true then
|
||||
reshuffledAlready = false
|
||||
return
|
||||
end
|
||||
reshuffleEncounterDeck() -- if there is no discard pile either, reshuffleEncounterDeck will give an error message already
|
||||
reshuffledAlready = true
|
||||
drawEncounterCard(params)
|
||||
end
|
||||
end
|
||||
|
||||
@ -180,27 +180,33 @@ function actualEncounterCardDraw(card, params)
|
||||
deckLib.placeOrMergeIntoDeck(card, pos, { 0, rotY, faceUpRotation })
|
||||
end
|
||||
|
||||
function reshuffleEncounterDeck(params)
|
||||
function reshuffleEncounterDeck()
|
||||
-- flag to avoid multiple calls
|
||||
if isReshuffling then return end
|
||||
isReshuffling = true
|
||||
|
||||
-- shuffle and flip deck, draw card after completion
|
||||
local searchResult = searchLib.atPosition(ENCOUNTER_DISCARD_POSITION, "isCardOrDeck")
|
||||
if #searchResult > 0 then
|
||||
local deck = searchResult[1]
|
||||
if not deck.is_face_down then deck.flip() end
|
||||
deck.shuffle()
|
||||
deck.setPositionSmooth(Vector(ENCOUNTER_DECK_POS) + Vector(0, 2, 0), false, true)
|
||||
Wait.time(function() actualEncounterCardDraw(deck.takeObject({ index = 0 }), params) end, 0.5)
|
||||
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
|
||||
if encounterDeck == nil then
|
||||
discardDeck.setPosition(Vector(ENCOUNTER_DECK_POS) + Vector({0, 1, 0}))
|
||||
discardDeck.shuffle()
|
||||
else
|
||||
encounterDeck.putObject(discardDeck)
|
||||
encounterDeck.shuffle()
|
||||
end
|
||||
broadcastToAll("Shuffled encounter discard into deck.", "White")
|
||||
else
|
||||
printToAll("Couldn't find encounter discard pile to reshuffle.", { 1, 0, 0 })
|
||||
broadcastToAll("Encounter discard pile is already empty.", "Red")
|
||||
end
|
||||
|
||||
-- disable flag
|
||||
Wait.time(function() isReshuffling = false end, 1)
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
-- helper functions
|
||||
---------------------------------------------------------
|
||||
|
3
xml/MythosArea.xml
Normal file
3
xml/MythosArea.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<Panel position="160 70 -13" rotation="0 0 180" height="74" width="315">
|
||||
<Button scale="0.1 0.1 1" color="#ffffff00" textColors="#ffffff|#88e3cf|#4f8478" font="font_teutonic-arkham" fontSize="62" onClick="reshuffleEncounterDeck">Reshuffle ➡</Button>
|
||||
</Panel>
|
Loading…
Reference in New Issue
Block a user