updated decklib
This commit is contained in:
parent
77c2fdafa7
commit
b13e0a75b4
@ -124,22 +124,17 @@ function startSearch(messageColor, number)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- get position and rotation for set aside cards
|
-- get position and rotation for set aside cards
|
||||||
local handData = Player[handColor].getHandTransform()
|
local handData = Player[handColor].getHandTransform()
|
||||||
local handCards = Player[handColor].getHandObjects()
|
local handCards = Player[handColor].getHandObjects()
|
||||||
setAsidePosition = handData.position + offset * handData.right
|
setAsidePosition = (handData.position + offset * handData.right):setAt("y", 1.5)
|
||||||
setAsideRotation = { handData.rotation.x, handData.rotation.y + 180, 180 }
|
setAsideRotation = { handData.rotation.x, handData.rotation.y + 180, 180 }
|
||||||
|
|
||||||
-- set y-value
|
-- place hand cards set aside
|
||||||
setAsidePosition.y = 1.5
|
deckLib.placeOrMergeIntoDeck(handCards, setAsidePosition, setAsideRotation)
|
||||||
|
|
||||||
for i = #handCards, 1, -1 do
|
|
||||||
handCards[i].setPosition(setAsidePosition + Vector(0, (#handCards - i) * 0.1, 0))
|
|
||||||
handCards[i].setRotation(setAsideRotation)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- handling for Norman Withers
|
-- handling for Norman Withers
|
||||||
if deckAreaObjects.topCard then
|
if deckAreaObjects.topCard then
|
||||||
deckAreaObjects.topCard.flip()
|
deckAreaObjects.topCard.setRotation(setAsideRotation)
|
||||||
topCardDetected = true
|
topCardDetected = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -155,35 +150,36 @@ end
|
|||||||
function endSearch(_, _, isRightClick)
|
function endSearch(_, _, isRightClick)
|
||||||
local handCards = Player[handColor].getHandObjects()
|
local handCards = Player[handColor].getHandObjects()
|
||||||
|
|
||||||
local handCount = #handCards
|
-- place cards on deck
|
||||||
for i = handCount, 1, -1 do
|
deckLib.placeOrMergeIntoDeck(handCards, drawDeckPosition, setAsideRotation)
|
||||||
Wait.time(function() deckLib.placeOrMergeIntoDeck(handCards[i], drawDeckPosition, setAsideRotation) end,
|
|
||||||
(handCount - i + 1) * 0.1)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- draw set aside cards (from the ground!)
|
-- draw set aside cards (from the ground!)
|
||||||
|
Wait.time(drawSetAsideCards, 0.5 + #handCards * 0.1)
|
||||||
|
|
||||||
|
normalView()
|
||||||
|
|
||||||
|
Wait.time(function()
|
||||||
|
-- maybe shuffle deck
|
||||||
|
if not isRightClick then
|
||||||
|
local deckAreaObjects = playermatApi.getDeckAreaObjects(matColor)
|
||||||
|
if deckAreaObjects.draw then
|
||||||
|
deckAreaObjects.draw.shuffle()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Norman Withers handling
|
||||||
|
if topCardDetected then
|
||||||
|
playermatApi.flipTopCardFromDeck(matColor)
|
||||||
|
end
|
||||||
|
end, 1 + #handCards * 0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function drawSetAsideCards()
|
||||||
for _, obj in ipairs(searchLib.atPosition(setAsidePosition, "isCardOrDeck")) do
|
for _, obj in ipairs(searchLib.atPosition(setAsidePosition, "isCardOrDeck")) do
|
||||||
local count = 1
|
local count = 1
|
||||||
if obj.type == "Deck" then
|
if obj.type == "Deck" then
|
||||||
count = #obj.getObjects()
|
count = #obj.getObjects()
|
||||||
end
|
end
|
||||||
Wait.time(function() obj.deal(count, handColor) end, 1)
|
obj.deal(count, handColor)
|
||||||
end
|
|
||||||
|
|
||||||
normalView()
|
|
||||||
|
|
||||||
-- delay is to wait for cards to enter deck
|
|
||||||
if not isRightClick then
|
|
||||||
Wait.time(function()
|
|
||||||
local deckAreaObjects = playermatApi.getDeckAreaObjects(matColor)
|
|
||||||
if deckAreaObjects.draw then
|
|
||||||
deckAreaObjects.draw.shuffle()
|
|
||||||
end
|
|
||||||
end, #handCards * 0.3 + 0.5)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Norman Withers handling
|
|
||||||
if topCardDetected then
|
|
||||||
Wait.time(function() playermatApi.flipTopCardFromDeck(matColor) end, #handCards * 0.3 + 0.75)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
local searchLib = require("util/SearchLib")
|
|
||||||
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
||||||
|
local deckLib = require("util/DeckLib")
|
||||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||||
local playAreaApi = require("core/PlayAreaApi")
|
local playAreaApi = require("core/PlayAreaApi")
|
||||||
|
local searchLib = require("util/SearchLib")
|
||||||
local tokenChecker = require("core/token/TokenChecker")
|
local tokenChecker = require("core/token/TokenChecker")
|
||||||
|
|
||||||
local pendingCall = false
|
local pendingCall = false
|
||||||
@ -234,6 +235,8 @@ end
|
|||||||
|
|
||||||
-- places the provided card in the first empty spot
|
-- places the provided card in the first empty spot
|
||||||
function placeCard(card)
|
function placeCard(card)
|
||||||
|
local name = card.getName() or "Unnamed card"
|
||||||
|
|
||||||
-- get sorted list of snap points to check slots
|
-- get sorted list of snap points to check slots
|
||||||
local snaps = self.getSnapPoints()
|
local snaps = self.getSnapPoints()
|
||||||
table.sort(snaps, function(a, b) return a.position.x > b.position.x end)
|
table.sort(snaps, function(a, b) return a.position.x > b.position.x end)
|
||||||
@ -263,15 +266,15 @@ function placeCard(card)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- place the card
|
-- use the first snap position in case all slots are full
|
||||||
card.setRotation({ 0, 270, card.getRotation().z })
|
local pos = emptyPos or self.positionToWorld(snaps[1].position)
|
||||||
local name = card.getName() or "Unnamed card"
|
local rot = card.getRotation():setAt("x", 0):setAt("y", 270)
|
||||||
|
deckLib.placeOrMergeIntoDeck(card, pos, rot)
|
||||||
|
|
||||||
|
-- give a feedback message
|
||||||
if emptyPos then
|
if emptyPos then
|
||||||
card.setPositionSmooth(emptyPos, false, true)
|
|
||||||
broadcastToAll("Victory Display: " .. name .. " placed into slot " .. emptyIndex .. ".", "Green")
|
broadcastToAll("Victory Display: " .. name .. " placed into slot " .. emptyIndex .. ".", "Green")
|
||||||
else
|
else
|
||||||
-- use the first snap position in case all slots are full
|
|
||||||
card.setPositionSmooth(self.positionToWorld(snaps[1].position), false, true)
|
|
||||||
broadcastToAll("Victory Display is full! " .. name .. " placed into slot 1.", "Orange")
|
broadcastToAll("Victory Display is full! " .. name .. " placed into slot 1.", "Orange")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -92,6 +92,8 @@ end
|
|||||||
function elderSignAbility()
|
function elderSignAbility()
|
||||||
blessCurseManagerApi.addToken("Bless")
|
blessCurseManagerApi.addToken("Bless")
|
||||||
blessCurseManagerApi.addToken("Curse")
|
blessCurseManagerApi.addToken("Curse")
|
||||||
|
updated = false
|
||||||
|
Wait.frames(maybeUpdateButtonState, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- count tokens in the bag and show appropriate buttons
|
-- count tokens in the bag and show appropriate buttons
|
||||||
@ -118,7 +120,7 @@ function maybeUpdateButtonState()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function setUiState(params)
|
function setUiState(params)
|
||||||
for buttonId, state in ipairs(params) do
|
for buttonId, state in pairs(params) do
|
||||||
if state then
|
if state then
|
||||||
self.UI.setAttribute(buttonId, "color", xmlData[buttonId].color)
|
self.UI.setAttribute(buttonId, "color", xmlData[buttonId].color)
|
||||||
self.UI.setAttribute(buttonId, "onClick", xmlData[buttonId].onClick)
|
self.UI.setAttribute(buttonId, "onClick", xmlData[buttonId].onClick)
|
||||||
|
@ -314,7 +314,7 @@ function doUpkeep(_, clickedByColor, isRightClick)
|
|||||||
local rot = self.getRotation()
|
local rot = self.getRotation()
|
||||||
for _, obj in ipairs(searchAroundSelf()) do
|
for _, obj in ipairs(searchAroundSelf()) do
|
||||||
if obj.hasTag("Temporary") == true then
|
if obj.hasTag("Temporary") == true then
|
||||||
discardListOfObjects({obj})
|
discardListOfObjects({ obj })
|
||||||
elseif obj.hasTag("UniversalToken") == true and obj.is_face_down then
|
elseif obj.hasTag("UniversalToken") == true and obj.is_face_down then
|
||||||
obj.flip()
|
obj.flip()
|
||||||
elseif obj.type == "Card" and not inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then
|
elseif obj.type == "Card" and not inArea(self.positionToLocal(obj.getPosition()), INVESTIGATOR_AREA) then
|
||||||
@ -389,35 +389,32 @@ function doUpkeep(_, clickedByColor, isRightClick)
|
|||||||
local handCards = Player[playerColor].getHandObjects()
|
local handCards = Player[playerColor].getHandObjects()
|
||||||
local cardsToDiscard = {}
|
local cardsToDiscard = {}
|
||||||
|
|
||||||
for i = 1, #handCards do
|
for _, card in ipairs(handCards) do
|
||||||
local md = JSON.decode(handCards[i].getGMNotes())
|
local md = JSON.decode(card.getGMNotes())
|
||||||
if md ~= nil and (not md.weakness and not md.hidden and md.type ~= "Enemy") then
|
if md ~= nil and (not md.weakness and not md.hidden and md.type ~= "Enemy") then
|
||||||
table.insert(cardsToDiscard, handCards[i])
|
table.insert(cardsToDiscard, card)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- perform discarding 1 by 1
|
-- perform discarding 1 by 1
|
||||||
local pos = returnGlobalDiscardPosition()
|
local pos = returnGlobalDiscardPosition()
|
||||||
local count = #cardsToDiscard
|
deckLib.placeOrMergeIntoDeck(cardsToDiscard, pos, rot)
|
||||||
for i = count, 1, -1 do
|
|
||||||
Wait.time(function() deckLib.placeOrMergeIntoDeck(cardsToDiscard[i], pos, rot) end,
|
|
||||||
(count - i + 1) * 0.1)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- add some time if there are any cards to discard, if not, draw up to 5 immediately
|
-- add some time if there are any cards to discard
|
||||||
local k = 0
|
local k = 0
|
||||||
if count > 0 then
|
if #cardsToDiscard > 0 then
|
||||||
k = 0.5 + (count * 0.1)
|
k = 1 + (#cardsToDiscard * 0.1)
|
||||||
end
|
end
|
||||||
|
|
||||||
Wait.time(function()
|
-- draw up to 5 cards
|
||||||
local handSize = #Player[playerColor].getHandObjects()
|
Wait.time(
|
||||||
if handSize < 5 then
|
function()
|
||||||
local cardsToDraw = 5 - handSize
|
local cardsToDraw = 5 - #handCards + #cardsToDiscard
|
||||||
printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", messageColor)
|
if cardsToDraw > 0 then
|
||||||
drawCardsWithReshuffle(cardsToDraw)
|
printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", messageColor)
|
||||||
end
|
drawCardsWithReshuffle(cardsToDraw)
|
||||||
end, k)
|
end
|
||||||
|
end, k)
|
||||||
end
|
end
|
||||||
elseif forcedLearning then
|
elseif forcedLearning then
|
||||||
printToColor("Drawing 2 cards, discard 1 (Forced Learning)", messageColor)
|
printToColor("Drawing 2 cards, discard 1 (Forced Learning)", messageColor)
|
||||||
|
@ -3,12 +3,20 @@ do
|
|||||||
local searchLib = require("util/SearchLib")
|
local searchLib = require("util/SearchLib")
|
||||||
|
|
||||||
-- places a card/deck at a position or merges into an existing deck below
|
-- places a card/deck at a position or merges into an existing deck below
|
||||||
---@param obj tts__Object Object to move
|
---@param objOrTable tts__Object|table Object or table of objects to move
|
||||||
---@param pos table New position for the object
|
---@param pos table New position for the object
|
||||||
---@param rot? table New rotation for the object
|
---@param rot? table New rotation for the object
|
||||||
---@param below? boolean Should the object be placed below an existing deck?
|
---@param below? boolean Should the object be placed below an existing deck?
|
||||||
DeckLib.placeOrMergeIntoDeck = function(obj, pos, rot, below)
|
DeckLib.placeOrMergeIntoDeck = function(objOrTable, pos, rot, below)
|
||||||
if obj == nil or obj.isDestroyed() or pos == nil then return end
|
if objOrTable == nil or pos == nil then return end
|
||||||
|
|
||||||
|
-- handle 'objOrTable' parameter
|
||||||
|
local objects = {}
|
||||||
|
if type(objOrTable) == "table" then
|
||||||
|
objects = objOrTable
|
||||||
|
else
|
||||||
|
table.insert(objects, objOrTable)
|
||||||
|
end
|
||||||
|
|
||||||
-- search the new position for existing card/deck
|
-- search the new position for existing card/deck
|
||||||
local searchResult = searchLib.atPosition(pos, "isCardOrDeck")
|
local searchResult = searchLib.atPosition(pos, "isCardOrDeck")
|
||||||
@ -28,26 +36,39 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- allow moving the objects smoothly out of the hand and temporarily lock it
|
-- process objects in reverse order
|
||||||
obj.setLock(true)
|
for i = #objects, 1, -1 do
|
||||||
obj.use_hands = false
|
local obj = objects[i]
|
||||||
|
-- add a 0.1 delay for each object (for animation purposes)
|
||||||
|
Wait.time(function()
|
||||||
|
-- allow moving smoothly out of hand and temporarily lock it
|
||||||
|
obj.setLock(true)
|
||||||
|
obj.use_hands = false
|
||||||
|
|
||||||
if rot then
|
if rot then
|
||||||
obj.setRotationSmooth(rot, false, true)
|
obj.setRotationSmooth(rot, false, true)
|
||||||
end
|
|
||||||
obj.setPositionSmooth(newPos, false, true)
|
|
||||||
|
|
||||||
-- use putObject if the card stops smooth moving to avoid a TTS bug that merges unrelated cards that are not resting
|
|
||||||
-- pcall avoids errors (physics is sometimes too fast so the object doesn't exist for the put)
|
|
||||||
Wait.condition(
|
|
||||||
pcall(function()
|
|
||||||
obj.setLock(false)
|
|
||||||
obj.use_hands = true
|
|
||||||
if #searchResult == 1 and targetObj ~= obj then
|
|
||||||
targetObj.putObject(obj)
|
|
||||||
end
|
end
|
||||||
end),
|
obj.setPositionSmooth(newPos, false, true)
|
||||||
function() return not obj.isSmoothMoving() end, 3)
|
|
||||||
|
-- wait for object to finish movement (or 2 seconds)
|
||||||
|
Wait.condition(
|
||||||
|
function()
|
||||||
|
-- revert toggles
|
||||||
|
obj.setLock(false)
|
||||||
|
obj.use_hands = true
|
||||||
|
|
||||||
|
-- use putObject to avoid a TTS bug that merges unrelated cards that are not resting
|
||||||
|
if #searchResult == 1 and targetObj ~= obj and not targetObj.isDestroyed() and not obj.isDestroyed() then
|
||||||
|
targetObj = targetObj.putObject(obj)
|
||||||
|
else
|
||||||
|
targetObj = obj
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
-- check state of the object (make sure it's not moving)
|
||||||
|
function() return obj.isDestroyed() or not obj.isSmoothMoving() end,
|
||||||
|
2)
|
||||||
|
end, (#objects- i) * 0.1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return DeckLib
|
return DeckLib
|
||||||
|
Loading…
x
Reference in New Issue
Block a user