Added rounding and hand zone support
This commit is contained in:
parent
5c53ca9c9c
commit
95cd42064e
@ -176,6 +176,17 @@ function getOwnerOfObject(object)
|
|||||||
end
|
end
|
||||||
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
|
-- check if it is on an owned object
|
||||||
local result = searchLib.belowPosition(object.getPosition())
|
local result = searchLib.belowPosition(object.getPosition())
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
||||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||||
local mythosAreaApi = require("core/MythosAreaApi")
|
local mythosAreaApi = require("core/MythosAreaApi")
|
||||||
local navigationOverlayApi = require("core/NavigationOverlayApi")
|
local navigationOverlayApi = require("core/NavigationOverlayApi")
|
||||||
local optionPanelApi = require("core/OptionPanelApi")
|
local optionPanelApi = require("core/OptionPanelApi")
|
||||||
local playermatApi = require("playermat/PlayermatApi")
|
local playermatApi = require("playermat/PlayermatApi")
|
||||||
local searchLib = require("util/SearchLib")
|
local searchLib = require("util/SearchLib")
|
||||||
local victoryDisplayApi = require("core/VictoryDisplayApi")
|
local victoryDisplayApi = require("core/VictoryDisplayApi")
|
||||||
|
|
||||||
function onLoad()
|
function onLoad()
|
||||||
addHotkey("Add doom to agenda", addDoomToAgenda)
|
addHotkey("Add doom to agenda", addDoomToAgenda)
|
||||||
@ -75,15 +75,19 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
|||||||
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
|
local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat")
|
||||||
|
|
||||||
-- do not continue if the threat area is already full
|
-- 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")
|
broadcastToColor("Threat area is full.", playerColor, "Yellow")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- initialize list of objects to move
|
-- initialize list of objects to move (and store local positions)
|
||||||
local moveTheseObjects = {}
|
local additionalObjects = {}
|
||||||
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
|
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
|
end
|
||||||
|
|
||||||
-- find out if the original card is on the green or red playermats
|
-- find out if the original card is on the green or red playermats
|
||||||
@ -97,29 +101,25 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
|||||||
modifierY = -90
|
modifierY = -90
|
||||||
end
|
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()
|
local cardName = hoveredObject.getName()
|
||||||
if cardName == nil or cardName == "" then
|
if cardName == "" then cardName = "card" end
|
||||||
cardName = "card(s)"
|
broadcastToAll("Moved " .. cardName .. " to " .. getColoredName(playerColor) .. "'s threat area.", "White")
|
||||||
end
|
|
||||||
broadcastToAll("Placed " .. cardName .. " into threat area.", "White")
|
|
||||||
|
|
||||||
for i, obj in ipairs(moveTheseObjects) do
|
-- get new rotation (rounded)
|
||||||
if not obj.locked then
|
local cardRot = hoveredObject.getRotation()
|
||||||
local globalPos = hoveredObject.positionToWorld(localPositions[i])
|
local roundedRotY = roundToMultiple(cardRot.y, 45)
|
||||||
obj.setPosition(globalPos)
|
local deltaRotY = 270 - mat.getRotation().y - modifierY
|
||||||
obj.setRotation(obj.getRotation() - Vector(0, 270 - mat.getRotation().y - modifierY, 0))
|
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
|
end
|
||||||
end
|
end
|
||||||
@ -131,7 +131,7 @@ function discardObject(playerColor, hoveredObject)
|
|||||||
if #selectedObjects > 0 then
|
if #selectedObjects > 0 then
|
||||||
discardGroup(playerColor, selectedObjects)
|
discardGroup(playerColor, selectedObjects)
|
||||||
return
|
return
|
||||||
-- only continue if an unlocked card, deck or tile was hovered
|
-- only continue if an unlocked card, deck or tile was hovered
|
||||||
elseif hoveredObject == nil
|
elseif hoveredObject == nil
|
||||||
or (hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck" and hoveredObject.type ~= "Tile")
|
or (hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck" and hoveredObject.type ~= "Tile")
|
||||||
or hoveredObject.locked then
|
or hoveredObject.locked then
|
||||||
@ -174,11 +174,11 @@ function discardGroup(playerColor, selectedObjects)
|
|||||||
local count = #selectedObjects
|
local count = #selectedObjects
|
||||||
-- discarding one at a time avoids an error with cards in the discard pile losing the 'hands' toggle and uses multiple mats
|
-- discarding one at a time avoids an error with cards in the discard pile losing the 'hands' toggle and uses multiple mats
|
||||||
for i = count, 1, -1 do
|
for i = count, 1, -1 do
|
||||||
Wait.time(function()
|
Wait.time(function()
|
||||||
if (selectedObjects[i].type == "Card" or selectedObjects[i].type ~= "Deck" or selectedObjects[i].type == "Tile") then
|
if (selectedObjects[i].type == "Card" or selectedObjects[i].type ~= "Deck" or selectedObjects[i].type == "Tile") then
|
||||||
performDiscard(playerColor, selectedObjects[i])
|
performDiscard(playerColor, selectedObjects[i])
|
||||||
end
|
end
|
||||||
end, (count - i + 1) * 0.1)
|
end, (count - i + 1) * 0.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -503,3 +503,7 @@ function getColoredName(playerColor)
|
|||||||
-- add bb-code
|
-- add bb-code
|
||||||
return "[" .. Color.fromString(playerColor):toHex() .. "]" .. displayName .. "[-]"
|
return "[" .. Color.fromString(playerColor):toHex() .. "]" .. displayName .. "[-]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function roundToMultiple(num, mult)
|
||||||
|
return math.floor((num + mult / 2) / mult) * mult
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user