Merge pull request #681 from dscarpac/grab-card-hotkey

New hotkey to take cards into threat area
This commit is contained in:
Chr1Z 2024-05-12 13:06:50 +02:00 committed by GitHub
commit 7108c2a15c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,7 @@ function onLoad()
addHotkey("Discard top card", discardTopDeck)
addHotkey("Display Bless/Curse status", showBlessCurseStatus)
addHotkey("Move card to Victory Display", moveCardToVictoryDisplay)
addHotkey("Place card into threat area", takeCardIntoThreatArea)
addHotkey("Remove a use", removeOneUse)
addHotkey("Switch seat clockwise", switchSeatClockwise)
addHotkey("Switch seat counter-clockwise", switchSeatCounterClockwise)
@ -57,6 +58,73 @@ function addDoomToAgenda()
doomCounter.call("addVal", 1)
end
-- move the hovered object to the nearest empty slot on the playermat
function takeCardIntoThreatArea(playerColor, hoveredObject)
-- only continue if an unlocked card
if hoveredObject == nil
or hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck"
or hoveredObject.hasTag("Location")
or hoveredObject.locked then
broadcastToColor("Hover a non-location card and try again.", playerColor, "Yellow")
return
end
local matColor = playmatApi.getMatColor(playerColor)
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
-- do not continue if the threat area is already full
if playmatApi.getEncounterCardDrawPosition(matColor, false) == playmatApi.getEncounterCardDrawPosition(matColor, true) then
broadcastToColor("Threat area is full.", playerColor,"Yellow")
return
end
-- initialize list of objects to move
local moveTheseObjects = {}
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
table.insert(moveTheseObjects, obj)
end
-- find out if the original card is on the green or red playmats
local originalMatColor = guidReferenceApi.getOwnerOfObject(hoveredObject)
-- determine modifiers for the playmats
local modifierY
if originalMatColor == "Red" then
modifierY = 90
elseif originalMatColor == "Green" then
modifierY = -90
else
modifierY = 0
end
local localPositions = {}
for i, obj in ipairs(moveTheseObjects) do
local localPos = hoveredObject.positionToLocal(obj.getPosition())
localPositions[i] = localPos
end
-- move the main card
local pos = playmatApi.getEncounterCardDrawPosition(matColor, false)
hoveredObject.setPosition(pos)
hoveredObject.setRotation(hoveredObject.getRotation() - Vector(0, 270-mat.getRotation().y-modifierY, 0))
local cardName = hoveredObject.getName()
if cardName == nil or cardName == "" then
cardName = "card(s)"
end
broadcastToAll("Placed " .. cardName .. " into threat area.", "White")
for i, obj in ipairs(moveTheseObjects) do
if not obj.locked then
local globalPos = hoveredObject.positionToWorld(localPositions[i])
obj.setPosition(globalPos)
obj.setRotation(obj.getRotation() - Vector(0, 270-mat.getRotation().y-modifierY, 0))
end
end
end
-- discard the hovered object to the respective trashcan and discard tokens on it if it was a card
function discardObject(playerColor, hoveredObject)
-- only continue if an unlocked card, deck or tile was hovered