Updated "Take into Threat Area" Game Key

This commit is contained in:
Chr1Z93 2024-10-16 11:51:43 +02:00
parent e29c8cb198
commit b096007b10

View File

@ -68,9 +68,9 @@ end
-- move the hovered object to the nearest empty slot on the playermat -- move the hovered object to the nearest empty slot on the playermat
function takeCardIntoThreatArea(playerColor, hoveredObject) function takeCardIntoThreatArea(playerColor, hoveredObject)
-- only continue if an unlocked card -- only continue if an unlocked, non-location card is hovered
if hoveredObject == nil if hoveredObject == nil
or hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck" or (hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck")
or hoveredObject.hasTag("Location") or hoveredObject.hasTag("Location")
or hoveredObject.locked then or hoveredObject.locked then
broadcastToColor("Hover a non-location card and try again.", playerColor, "Yellow") broadcastToColor("Hover a non-location card and try again.", playerColor, "Yellow")
@ -78,7 +78,7 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
end end
local matColor = playermatApi.getMatColor(playerColor) local matColor = playermatApi.getMatColor(playerColor)
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat") local cardRot = hoveredObject.getRotation()
-- do not continue if the threat area is already full -- do not continue if the threat area is already full
local threatAreaPos = playermatApi.getEncounterCardDrawPosition(matColor, false) local threatAreaPos = playermatApi.getEncounterCardDrawPosition(matColor, false)
@ -87,37 +87,29 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
return return
end end
-- initialize list of objects to move (and store local positions) -- initialize list of objects to move (and store local position + rotation)
local additionalObjects = {} local additionalObjects = {}
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
local data = {} if not obj.locked then
data.object = obj local data = {
data.localPos = hoveredObject.positionToLocal(obj.getPosition()) object = obj,
localPos = hoveredObject.positionToLocal(obj.getPosition()),
localRotY = cardRot.y - obj.getRotation().y
}
table.insert(additionalObjects, data) table.insert(additionalObjects, data)
end end
-- find out if the original card is on the green or red playermats
local originalMatColor = guidReferenceApi.getOwnerOfObject(hoveredObject)
-- determine modifiers for the playermats
local modifierY = 0
if originalMatColor == "Red" then
modifierY = 90
elseif originalMatColor == "Green" then
modifierY = -90
end end
-- contruct feedback message -- get the rotation of the owning playermat (or Mythos)
local cardName = hoveredObject.getName() local cardOwner = guidReferenceApi.getOwnerOfObject(hoveredObject)
if cardName == "" then cardName = "a card" end local ownerRotation = Vector(0, 270, 0)
local playerName = GlobalApi.getColoredName(playerColor) if cardOwner ~= "Mythos" then
broadcastToAll("Moved " .. cardName .. " to " .. playerName .. "'s threat area.", "White") ownerRotation = playermatApi.returnRotation(cardOwner)
end
-- get new rotation (rounded) -- work out the new rotation
local cardRot = hoveredObject.getRotation() local matRotation = playermatApi.returnRotation(matColor)
local roundedRotY = roundToMultiple(cardRot.y, 45) local newCardRot = cardRot:setAt("y", matRotation.y + ownerRotation.y - cardRot.y)
local deltaRotY = 270 - mat.getRotation().y - modifierY
local newCardRot = cardRot:setAt("y", roundedRotY - deltaRotY)
-- move the main card to threat area -- move the main card to threat area
hoveredObject.setRotation(newCardRot) hoveredObject.setRotation(newCardRot)
@ -125,11 +117,18 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
-- move tokens/tiles (to new global position) -- move tokens/tiles (to new global position)
for _, data in ipairs(additionalObjects) do for _, data in ipairs(additionalObjects) do
if not data.object.locked then
data.object.setPosition(hoveredObject.positionToWorld(data.localPos)) data.object.setPosition(hoveredObject.positionToWorld(data.localPos))
data.object.setRotation(data.object.getRotation() - Vector(0, deltaRotY, 0)) data.object.setRotation(newCardRot.y + data.localRotY)
end end
-- contruct feedback message (hide name when face-down + enabled setting)
local cardName = hoveredObject.getName()
if cardName == "" or (hoveredObject.is_face_down and hoveredObject.hide_when_face_down) then
cardName = "a card"
end end
local playerName = GlobalApi.getColoredName(playerColor)
broadcastToAll("Moved " .. cardName .. " to " .. playerName .. "'s threat area.", "White")
end end
-- discard the hovered or selected objects to the respective trashcan and discard tokens on it if it was a card -- discard the hovered or selected objects to the respective trashcan and discard tokens on it if it was a card
@ -577,7 +576,3 @@ function getFirstSeatedPlayer()
return color return color
end end
end end
function roundToMultiple(num, mult)
return math.floor((num + mult / 2) / mult) * mult
end