added remove a use hotkey
This commit is contained in:
parent
15660689cd
commit
93e26b6b73
@ -9,6 +9,7 @@ function onLoad()
|
|||||||
addHotkey("Bless/Curse Status", showBlessCurseStatus)
|
addHotkey("Bless/Curse Status", showBlessCurseStatus)
|
||||||
addHotkey("Discard Object", discardObject)
|
addHotkey("Discard Object", discardObject)
|
||||||
addHotkey("Move card to Victory Display", moveCardToVictoryDisplay)
|
addHotkey("Move card to Victory Display", moveCardToVictoryDisplay)
|
||||||
|
addHotkey("Remove a use", removeOneUse)
|
||||||
addHotkey("Take clue from location", takeClueFromLocation)
|
addHotkey("Take clue from location", takeClueFromLocation)
|
||||||
addHotkey("Upkeep", triggerUpkeep)
|
addHotkey("Upkeep", triggerUpkeep)
|
||||||
addHotkey("Upkeep (Multi-handed)", triggerUpkeepMultihanded)
|
addHotkey("Upkeep (Multi-handed)", triggerUpkeepMultihanded)
|
||||||
@ -51,10 +52,8 @@ end
|
|||||||
function discardObject(playerColor, hoveredObject)
|
function discardObject(playerColor, hoveredObject)
|
||||||
-- only continue if an unlocked card, deck or tile was hovered
|
-- only continue if an unlocked card, deck or tile was hovered
|
||||||
if hoveredObject == nil
|
if hoveredObject == nil
|
||||||
or hoveredObject.type ~= "Card"
|
or (hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck" and hoveredObject.type ~= "Tile")
|
||||||
and hoveredObject.type ~= "Deck"
|
or hoveredObject.locked then
|
||||||
and hoveredObject.type ~= "Tile"
|
|
||||||
and not hoveredObject.locked then
|
|
||||||
broadcastToColor("Hover a token/tile or a card/deck and try again.", playerColor, "Yellow")
|
broadcastToColor("Hover a token/tile or a card/deck and try again.", playerColor, "Yellow")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -76,6 +75,12 @@ function discardObject(playerColor, hoveredObject)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local discardForMatColor = getColorToDiscardFor(hoveredObject, playerColor)
|
||||||
|
playmatApi.discardListOfObjects(discardForMatColor, discardTheseObjects)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- helper function to get the player to trigger the discard function for
|
||||||
|
function getColorToDiscardFor(hoveredObject, playerColor)
|
||||||
local pos = hoveredObject.getPosition()
|
local pos = hoveredObject.getPosition()
|
||||||
local closestMatColor = playmatApi.getMatColorByPosition(pos)
|
local closestMatColor = playmatApi.getMatColorByPosition(pos)
|
||||||
|
|
||||||
@ -94,11 +99,10 @@ function discardObject(playerColor, hoveredObject)
|
|||||||
-- discard to closest mat if near it, use triggering playmat if not
|
-- discard to closest mat if near it, use triggering playmat if not
|
||||||
local discardForMatColor
|
local discardForMatColor
|
||||||
if inArea(pos, areaNearPlaymat) then
|
if inArea(pos, areaNearPlaymat) then
|
||||||
discardForMatColor = closestMatColor
|
return closestMatColor
|
||||||
else
|
else
|
||||||
discardForMatColor = playmatApi.getMatColor(playerColor)
|
return playmatApi.getMatColor(playerColor)
|
||||||
end
|
end
|
||||||
playmatApi.discardListOfObjects(discardForMatColor, discardTheseObjects)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- moves the hovered card to the victory display
|
-- moves the hovered card to the victory display
|
||||||
@ -106,6 +110,66 @@ function moveCardToVictoryDisplay(_, hoveredObject)
|
|||||||
victoryDisplayApi.placeCard(hoveredObject)
|
victoryDisplayApi.placeCard(hoveredObject)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- removes a use from a card (or a token if hovered)
|
||||||
|
function removeOneUse(playerColor, hoveredObject)
|
||||||
|
-- only continue if an unlocked card or tile was hovered
|
||||||
|
if hoveredObject == nil
|
||||||
|
or (hoveredObject.type ~= "Card" and hoveredObject.type ~= "Tile")
|
||||||
|
or hoveredObject.locked then
|
||||||
|
broadcastToColor("Hover a token/tile or a card and try again.", playerColor, "Yellow")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local targetObject = nil
|
||||||
|
|
||||||
|
-- discard hovered token / tile
|
||||||
|
if hoveredObject.type == "Tile" then
|
||||||
|
targetObject = hoveredObject
|
||||||
|
elseif hoveredObject.type == "Card" then
|
||||||
|
-- grab the first use type from the metadata (or nil)
|
||||||
|
local notes = JSON.decode(hoveredObject.getGMNotes()) or {}
|
||||||
|
local usesData = notes.uses or {}
|
||||||
|
local useInfo = usesData[1] or {}
|
||||||
|
local searchForType = useInfo.type
|
||||||
|
if searchForType then searchForType = searchForType:lower() end
|
||||||
|
|
||||||
|
for _, v in ipairs(searchOnObj(hoveredObject)) do
|
||||||
|
local obj = v.hit_object
|
||||||
|
if obj.type == "Tile" and not obj.locked then
|
||||||
|
-- check for matching object, otherwise use the first hit
|
||||||
|
if obj.memo == searchForType then
|
||||||
|
targetObject = obj
|
||||||
|
break
|
||||||
|
elseif not targetObject then
|
||||||
|
targetObject = obj
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- error handling
|
||||||
|
if not targetObject then
|
||||||
|
broadcastToColor("No tokens found!", playerColor, "Yellow")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- feedback message
|
||||||
|
local tokenName = targetObject.getName()
|
||||||
|
if tokenName == "" then
|
||||||
|
if targetObject.memo ~= "" then
|
||||||
|
tokenName = titleCase(targetObject.memo)
|
||||||
|
else
|
||||||
|
tokenName = "Unknown"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local playerName = Player[playerColor].steam_name
|
||||||
|
broadcastToAll(playerName .. " removed a token: " .. tokenName, playerColor)
|
||||||
|
|
||||||
|
local discardForMatColor = getColorToDiscardFor(hoveredObject, playerColor)
|
||||||
|
playmatApi.discardListOfObjects(discardForMatColor, { targetObject })
|
||||||
|
end
|
||||||
|
|
||||||
-- takes a clue from a location, player needs to hover the clue directly or the location
|
-- takes a clue from a location, player needs to hover the clue directly or the location
|
||||||
function takeClueFromLocation(playerColor, hoveredObject)
|
function takeClueFromLocation(playerColor, hoveredObject)
|
||||||
local cardName, clue
|
local cardName, clue
|
||||||
@ -217,3 +281,10 @@ function inArea(point, bounds)
|
|||||||
and point.z > bounds.minZ
|
and point.z > bounds.minZ
|
||||||
and point.z < bounds.maxZ)
|
and point.z < bounds.maxZ)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- capitalizes the first letter
|
||||||
|
function titleCase(str)
|
||||||
|
local first = str:sub(1, 1)
|
||||||
|
local rest = str:sub(2)
|
||||||
|
return first:upper() .. rest:lower()
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user