Merge pull request #701 from argonui/gamekeyhandler
Updated GameKeyHandler code
This commit is contained in:
commit
fab05202bc
@ -71,16 +71,15 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
||||
|
||||
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
|
||||
@ -89,17 +88,15 @@ function takeCardIntoThreatArea(playerColor, hoveredObject)
|
||||
local originalMatColor = guidReferenceApi.getOwnerOfObject(hoveredObject)
|
||||
|
||||
-- determine modifiers for the playmats
|
||||
local modifierY
|
||||
local modifierY = 0
|
||||
if originalMatColor == "Red" then
|
||||
modifierY = 90
|
||||
elseif originalMatColor == "Green" then
|
||||
modifierY = -90
|
||||
else
|
||||
modifierY = 0
|
||||
end
|
||||
|
||||
-- store local positions of objects
|
||||
local localPositions = {}
|
||||
|
||||
for i, obj in ipairs(moveTheseObjects) do
|
||||
local localPos = hoveredObject.positionToLocal(obj.getPosition())
|
||||
localPositions[i] = localPos
|
||||
@ -136,15 +133,17 @@ function discardObject(playerColor, hoveredObject)
|
||||
end
|
||||
|
||||
-- These should probably not be discarded normally. Ask player for confirmation.
|
||||
if (hoveredObject.type == "Deck") or hoveredObject.hasTag("Location") then
|
||||
if hoveredObject.type == "Deck" or hoveredObject.hasTag("Location") then
|
||||
local suspect = (hoveredObject.type == "Deck") and "Deck" or "Location"
|
||||
Player[playerColor].showConfirmDialog("Discard " .. suspect .. "?", function () performDiscard(playerColor, hoveredObject) end)
|
||||
Player[playerColor].showConfirmDialog("Discard " .. suspect .. "?",
|
||||
function() performDiscard(playerColor, hoveredObject) end)
|
||||
return
|
||||
end
|
||||
|
||||
performDiscard(playerColor, hoveredObject)
|
||||
end
|
||||
|
||||
-- actually performs the discarding of the object and tokens / tiles on it
|
||||
function performDiscard(playerColor, hoveredObject)
|
||||
-- initialize list of objects to discard
|
||||
local discardTheseObjects = { hoveredObject }
|
||||
@ -169,10 +168,11 @@ function discardTopDeck(playerColor, hoveredObject)
|
||||
broadcastToColor("Hover a deck/card and try again.", playerColor, "Yellow")
|
||||
return
|
||||
end
|
||||
|
||||
-- take top card from deck (unless it is already a single card)
|
||||
local takenCard = hoveredObject
|
||||
if hoveredObject.type == "Deck" then
|
||||
takenCard = hoveredObject.takeObject({ index = 0 })
|
||||
else
|
||||
takenCard = hoveredObject
|
||||
end
|
||||
Wait.frames(function() performDiscard(playerColor, takenCard) end, 1)
|
||||
end
|
||||
@ -194,15 +194,21 @@ function getColorToDiscardFor(hoveredObject, playerColor)
|
||||
areaNearPlaymat.minZ = bounds.center.z - bounds.size.z / 2 - bufferAroundPlaymat
|
||||
areaNearPlaymat.maxZ = bounds.center.z + bounds.size.z / 2 + bufferAroundPlaymat
|
||||
|
||||
-- discard to closest mat if near it, use triggering playmat if not
|
||||
local discardForMatColor
|
||||
-- discard to closest mat if near it
|
||||
if inArea(pos, areaNearPlaymat) then
|
||||
return closestMatColor
|
||||
elseif pos.y > (Player[playerColor].getHandTransform().position.y - (Player[playerColor].getHandTransform().scale.y / 2)) then -- discard to closest mat if card is in a hand
|
||||
return closestMatColor
|
||||
else
|
||||
return playmatApi.getMatColor(playerColor)
|
||||
end
|
||||
|
||||
-- discard to closest mat if card is in a hand
|
||||
local handZone = guidReferenceApi.getObjectByOwnerAndType(closestMatColor, "HandZone")
|
||||
for _, zone in ipairs(hoveredObject.getZones()) do
|
||||
if zone == handZone then
|
||||
return closestMatColor
|
||||
end
|
||||
end
|
||||
|
||||
-- discard to triggering mat if previous conditions weren't met
|
||||
return playmatApi.getMatColor(playerColor)
|
||||
end
|
||||
|
||||
-- moves the hovered card to the victory display
|
||||
|
Loading…
x
Reference in New Issue
Block a user