Merge branch 'norman-withers-qol' into scroll-of-secrets

This commit is contained in:
Chr1Z93 2023-11-04 23:08:49 +01:00
commit f1cbc28768
4 changed files with 127 additions and 80 deletions

View File

@ -1,7 +1,7 @@
local playmatApi = require("playermat/PlaymatApi") local playmatApi = require("playermat/PlaymatApi")
-- forward declaration of variables that are used across functions -- forward declaration of variables that are used across functions
local matColor, handColor, setAsidePosition, setAsideRotation, drawDeckPosition local matColor, handColor, setAsidePosition, setAsideRotation, drawDeckPosition, topCardDetected
local quickParameters = {} local quickParameters = {}
quickParameters.function_owner = self quickParameters.function_owner = self
@ -101,15 +101,18 @@ end
function startSearch(messageColor, number) function startSearch(messageColor, number)
matColor = playmatApi.getMatColorByPosition(self.getPosition()) matColor = playmatApi.getMatColorByPosition(self.getPosition())
handColor = playmatApi.getPlayerColor(matColor) handColor = playmatApi.getPlayerColor(matColor)
topCardDetected = false
-- get draw deck -- get draw deck
local drawDeck = playmatApi.getDrawDeck(matColor) local deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
if drawDeck == nil then if deckAreaObjects.draw == nil then
printToColor(matColor .. " draw deck could not be found!", messageColor, "Red") printToColor(matColor .. " draw deck could not be found!", messageColor, "Red")
return return
end end
drawDeckPosition = drawDeck.getPosition() -- get bounds to know the height of the deck
local bounds = deckAreaObjects.draw.getBounds()
drawDeckPosition = bounds.center + Vector(0, bounds.size.y / 2 + 0.2, 0)
printToColor("Place target(s) of search on set aside hand.", messageColor, "Green") printToColor("Place target(s) of search on set aside hand.", messageColor, "Green")
-- get playmat orientation -- get playmat orientation
@ -124,23 +127,26 @@ function startSearch(messageColor, number)
setAsidePosition = handData.position + offset * handData.right setAsidePosition = handData.position + offset * handData.right
setAsideRotation = { handData.rotation.x, handData.rotation.y + 180, 180 } setAsideRotation = { handData.rotation.x, handData.rotation.y + 180, 180 }
-- set y-value
setAsidePosition.y = 1.5
for i = #handCards, 1, -1 do for i = #handCards, 1, -1 do
handCards[i].setPosition(setAsidePosition - Vector(0, i * 0.3, 0)) handCards[i].setPosition(setAsidePosition + Vector(0, (#handCards - i) * 0.1, 0))
handCards[i].setRotation(setAsideRotation) handCards[i].setRotation(setAsideRotation)
end end
-- handling for Norman Withers -- handling for Norman Withers
for _, v in ipairs(searchArea(drawDeckPosition)) do if deckAreaObjects.topCard then
local object = v.hit_object deckAreaObjects.topCard.flip()
if object.tag == "Card" and not object.is_face_down then topCardDetected = true
object.flip()
Wait.time(function() drawDeck = playmatApi.getDrawDeck(matColor) end, 1)
break
end
end end
Wait.time(function() drawDeck.deal(number, handColor) end, 1)
searchView() searchView()
Wait.time(function()
deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
deckAreaObjects.draw.deal(number, handColor)
end, 1)
end end
-- place handCards back into deck and optionally shuffle -- place handCards back into deck and optionally shuffle
@ -148,28 +154,19 @@ function endSearch(_, _, isRightClick)
local handCards = Player[handColor].getHandObjects() local handCards = Player[handColor].getHandObjects()
for i = #handCards, 1, -1 do for i = #handCards, 1, -1 do
handCards[i].setPosition(drawDeckPosition + Vector(0, 6 - i * 0.3, 0)) handCards[i].setPosition(drawDeckPosition + Vector(0, (#handCards - i) * 0.1, 0))
handCards[i].setRotation(setAsideRotation) handCards[i].setRotation(setAsideRotation)
end end
if not isRightClick then
Wait.time(function()
local deck = playmatApi.getDrawDeck(matColor)
if deck ~= nil then
deck.shuffle()
end
end, 2)
end
-- draw set aside cards (from the ground!) -- draw set aside cards (from the ground!)
for _, v in ipairs(searchArea(setAsidePosition - Vector(0, 5, 0))) do for _, v in ipairs(searchArea(setAsidePosition)) do
local obj = v.hit_object local obj = v.hit_object
if obj.tag == "Deck" then if obj.type == "Deck" then
Wait.time(function() Wait.time(function()
obj.deal(#obj.getObjects(), handColor) obj.deal(#obj.getObjects(), handColor)
end, 1) end, 1)
break break
elseif obj.tag == "Card" then elseif obj.type == "Card" then
obj.setPosition(Player[handColor].getHandTransform().position) obj.setPosition(Player[handColor].getHandTransform().position)
obj.flip() obj.flip()
break break
@ -177,6 +174,21 @@ function endSearch(_, _, isRightClick)
end end
normalView() normalView()
-- delay is to wait for cards to enter deck
if not isRightClick then
Wait.time(function()
local deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
if deckAreaObjects.draw then
deckAreaObjects.draw.shuffle()
end
end, #handCards * 0.1)
end
-- Norman Withers handling
if topCardDetected then
Wait.time(function() playmatApi.flipTopCardFromDeck(matColor) end, #handCards * 0.1)
end
end end
-- utility function -- utility function

View File

@ -9,7 +9,8 @@ function shortSupply(color)
local matColor = playmatApi.getMatColorByPosition(self.getPosition()) local matColor = playmatApi.getMatColorByPosition(self.getPosition())
-- get draw deck and discard position -- get draw deck and discard position
local drawDeck = playmatApi.getDrawDeck(matColor) local deckAreaObjects = playmatApi.getDeckAreaObjects(matColor)
local drawDeck = deckAreaObjects.draw
local discardPos = playmatApi.getDiscardPosition(matColor) local discardPos = playmatApi.getDiscardPosition(matColor)
-- error handling -- error handling

View File

@ -62,19 +62,19 @@ local DECK_DISCARD_AREA = {
}, },
center = { center = {
x = -1.82, x = -1.82,
y = 0.1, y = 0.5,
z = 0.305 z = 0.305
}, },
size = { size = {
x = 0.4, x = 0.4,
y = 1, y = 3,
z = 1.1 z = 1.1
} }
} }
-- local position of draw and discard pile -- local position of draw and discard pile
local DRAW_DECK_POSITION = { x = -1.82, y = 0, z = 0 } local DRAW_DECK_POSITION = { x = -1.82, y = 0.1, z = 0 }
local DISCARD_PILE_POSITION = { x = -1.82, y = 0, z = 0.61 } local DISCARD_PILE_POSITION = { x = -1.82, y = 0.1, z = 0.61 }
-- global position of encounter discard pile -- global position of encounter discard pile
local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1.5, z = 10.38} local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1.5, z = 10.38}
@ -418,81 +418,108 @@ end
-- draw X cards (shuffle discards if necessary) -- draw X cards (shuffle discards if necessary)
function drawCardsWithReshuffle(numCards) function drawCardsWithReshuffle(numCards)
getDrawDiscardDecks() local deckAreaObjects = getDeckAreaObjects()
-- Norman Withers handling -- Norman Withers handling
if string.match(activeInvestigatorId, "%d%d%d%d%d") == "08004" then local harbinger = false
local harbinger = false if deckAreaObjects.topCard and deckAreaObjects.topCard.getName() == "The Harbinger" then
if topCard ~= nil and topCard.getName() == "The Harbinger" then harbinger = true
elseif deckAreaObjects.draw and not deckAreaObjects.draw.is_face_down then
local cards = deckAreaObjects.draw.getObjects()
if cards[#cards].name == "The Harbinger" then
harbinger = true harbinger = true
elseif drawDeck ~= nil and not drawDeck.is_face_down then
local cards = drawDeck.getObjects()
if cards[#cards].name == "The Harbinger" then
harbinger = true
end
end end
end
if harbinger then if harbinger then
printToColor("The Harbinger is on top of your deck, not drawing cards", messageColor) 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 return
end end
if topCard ~= nil then
topCard.deal(numCards, playerColor)
numCards = numCards - 1
if numCards == 0 then return end
end
end end
local deckSize = 1 local deckSize = 1
if drawDeck == nil then if deckAreaObjects.draw == nil then
deckSize = 0 deckSize = 0
elseif drawDeck.tag == "Deck" then elseif deckAreaObjects.draw.type == "Deck" then
deckSize = #drawDeck.getObjects() deckSize = #deckAreaObjects.draw.getObjects()
end end
if deckSize >= numCards then if deckSize >= numCards then
drawCards(numCards) drawCards(numCards)
return if topCardDetected then flipTopCardFromDeck() end
else
drawCards(deckSize)
if deckAreaObjects.discard ~= nil then
shuffleDiscardIntoDeck()
Wait.time(function()
drawCards(numCards - deckSize)
if topCardDetected then flipTopCardFromDeck() end
end, 1)
end
printToColor("Take 1 horror (drawing card from empty deck)", messageColor)
end end
drawCards(deckSize)
if discardPile ~= nil then
shuffleDiscardIntoDeck()
Wait.time(|| drawCards(numCards - deckSize), 1)
end
printToColor("Take 1 horror (drawing card from empty deck)", messageColor)
end end
-- get the draw deck and discard pile objects -- get the draw deck and discard pile objects and returns the references
function getDrawDiscardDecks() function getDeckAreaObjects()
drawDeck = nil local deckAreaObjects = {}
discardPile = nil
topCard = nil
for _, object in ipairs(searchDeckAndDiscardArea(isCardOrDeck)) do for _, object in ipairs(searchDeckAndDiscardArea(isCardOrDeck)) do
if self.positionToLocal(object.getPosition()).z > 0.5 then if self.positionToLocal(object.getPosition()).z > 0.5 then
discardPile = object deckAreaObjects.discard = object
-- Norman Withers handling -- Norman Withers handling
elseif string.match(activeInvestigatorId, "%d%d%d%d%d") == "08004" and not object.is_face_down then elseif object.type == "Card" and not object.is_face_down then
topCard = object deckAreaObjects.topCard = object
else else
drawDeck = object deckAreaObjects.draw = object
end end
end end
return deckAreaObjects
end end
function drawCards(numCards) function drawCards(numCards)
if drawDeck == nil then return end local deckAreaObjects = getDeckAreaObjects()
drawDeck.deal(numCards, playerColor) if deckAreaObjects.draw then
deckAreaObjects.draw.deal(numCards, playerColor)
end
end end
function shuffleDiscardIntoDeck() function shuffleDiscardIntoDeck()
if not discardPile.is_face_down then discardPile.flip() end local deckAreaObjects = getDeckAreaObjects()
discardPile.shuffle() if not deckAreaObjects.discard.is_face_down then
discardPile.setPositionSmooth(self.positionToWorld(DRAW_DECK_POSITION), false, false) deckAreaObjects.discard.flip()
drawDeck = discardPile end
discardPile = nil deckAreaObjects.discard.shuffle()
deckAreaObjects.discard.setPositionSmooth(self.positionToWorld(DRAW_DECK_POSITION), false, false)
end
-- utility function for Norman Withers to flip the top card to the revealed side
function flipTopCardFromDeck()
log("called")
Wait.time(function()
local deckAreaObjects = getDeckAreaObjects()
if deckAreaObjects.topCard then
return
elseif deckAreaObjects.draw then
if deckAreaObjects.draw.type == "Card" then
deckAreaObjects.draw.flip()
else
-- get bounds to know the height of the deck
local bounds = deckAreaObjects.draw.getBounds()
local pos = bounds.center + Vector(0, bounds.size.y / 2 + 0.2, 0)
deckAreaObjects.draw.takeObject({ position = pos, flip = true })
end
end
end, 0.1)
end end
-- discard a random non-hidden card from hand -- discard a random non-hidden card from hand

View File

@ -54,12 +54,19 @@ do
end end
end end
-- Returns the draw deck of the requested playmat -- Performs a search of the deck area of the requested playmat and returns the result as table
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.getDrawDeck = function(matColor) PlaymatApi.getDeckAreaObjects = function(matColor)
for _, mat in pairs(getMatForColor(matColor)) do for _, mat in pairs(getMatForColor(matColor)) do
mat.call("getDrawDiscardDecks") return mat.call("getDeckAreaObjects")
return mat.getVar("drawDeck") end
end
-- Flips the top card of the deck (useful after deck manipulation for Norman Withers)
---@param matColor String Color of the playmat - White, Orange, Green or Red (does not support "All")
PlaymatApi.flipTopCardFromDeck = function(matColor)
for _, mat in pairs(getMatForColor(matColor)) do
return mat.call("flipTopCardFromDeck")
end end
end end