Added rounding and hand zone support
This commit is contained in:
parent
5c53ca9c9c
commit
95cd42064e
@ -176,6 +176,17 @@ function getOwnerOfObject(object)
|
||||
end
|
||||
end
|
||||
|
||||
-- check if the object is in a handzone
|
||||
for owner, subtable in pairs(GuidReferences) do
|
||||
for type, guid in pairs(subtable) do
|
||||
for _, zone in ipairs(object.getZones()) do
|
||||
if guid == zone.getGUID() then
|
||||
return owner
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- check if it is on an owned object
|
||||
local result = searchLib.belowPosition(object.getPosition())
|
||||
|
||||
|
@ -75,15 +75,19 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
||||
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
|
||||
|
||||
-- do not continue if the threat area is already full
|
||||
if playermatApi.getEncounterCardDrawPosition(matColor, false) == playermatApi.getEncounterCardDrawPosition(matColor, true) then
|
||||
local threatAreaPos = playermatApi.getEncounterCardDrawPosition(matColor, false)
|
||||
if threatAreaPos == playermatApi.getEncounterCardDrawPosition(matColor, true) then
|
||||
broadcastToColor("Threat area is full.", playerColor, "Yellow")
|
||||
return
|
||||
end
|
||||
|
||||
-- initialize list of objects to move
|
||||
local moveTheseObjects = {}
|
||||
-- initialize list of objects to move (and store local positions)
|
||||
local additionalObjects = {}
|
||||
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
|
||||
table.insert(moveTheseObjects, obj)
|
||||
local data = {}
|
||||
data.object = obj
|
||||
data.localPos = hoveredObject.positionToLocal(obj.getPosition())
|
||||
table.insert(additionalObjects, data)
|
||||
end
|
||||
|
||||
-- find out if the original card is on the green or red playermats
|
||||
@ -97,29 +101,25 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
||||
modifierY = -90
|
||||
end
|
||||
|
||||
-- store local positions of objects
|
||||
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 = playermatApi.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")
|
||||
if cardName == "" then cardName = "card" end
|
||||
broadcastToAll("Moved " .. cardName .. " to " .. getColoredName(playerColor) .. "'s 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))
|
||||
-- get new rotation (rounded)
|
||||
local cardRot = hoveredObject.getRotation()
|
||||
local roundedRotY = roundToMultiple(cardRot.y, 45)
|
||||
local deltaRotY = 270 - mat.getRotation().y - modifierY
|
||||
local newCardRot = cardRot:setAt("y", roundedRotY - deltaRotY)
|
||||
|
||||
-- move the main card to threat area
|
||||
hoveredObject.setRotation(newCardRot)
|
||||
hoveredObject.setPosition(threatAreaPos)
|
||||
|
||||
-- move tokens/tiles (to new global position)
|
||||
for _, data in ipairs(additionalObjects) do
|
||||
if not data.object.locked then
|
||||
data.object.setPosition(hoveredObject.positionToWorld(data.localPos))
|
||||
data.object.setRotation(data.object.getRotation() - Vector(0, deltaRotY, 0))
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -503,3 +503,7 @@ function getColoredName(playerColor)
|
||||
-- add bb-code
|
||||
return "[" .. Color.fromString(playerColor):toHex() .. "]" .. displayName .. "[-]"
|
||||
end
|
||||
|
||||
function roundToMultiple(num, mult)
|
||||
return math.floor((num + mult / 2) / mult) * mult
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user