2023-04-04 12:03:38 +02:00
|
|
|
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
2023-10-18 20:55:38 +02:00
|
|
|
local guidReferenceApi = require("core/GUIDReferenceApi")
|
2023-09-26 16:14:37 +02:00
|
|
|
local optionPanelApi = require("core/OptionPanelApi")
|
2023-04-04 12:03:38 +02:00
|
|
|
local playmatApi = require("playermat/PlaymatApi")
|
2023-12-11 18:11:04 +01:00
|
|
|
local searchLib = require("util/SearchLib")
|
2023-06-14 22:17:55 +02:00
|
|
|
local victoryDisplayApi = require("core/VictoryDisplayApi")
|
2023-04-04 12:03:38 +02:00
|
|
|
|
|
|
|
function onLoad()
|
|
|
|
addHotkey("Add Doom to Agenda", addDoomToAgenda)
|
|
|
|
addHotkey("Bless/Curse Status", showBlessCurseStatus)
|
2023-10-22 00:12:11 +02:00
|
|
|
addHotkey("Discard Object", discardObject)
|
2023-12-07 18:26:13 -06:00
|
|
|
addHotkey("Discard top card", discardTopDeck)
|
2023-05-12 13:02:33 +02:00
|
|
|
addHotkey("Move card to Victory Display", moveCardToVictoryDisplay)
|
2023-11-05 10:38:31 +01:00
|
|
|
addHotkey("Remove a use", removeOneUse)
|
2023-05-12 13:02:33 +02:00
|
|
|
addHotkey("Take clue from location", takeClueFromLocation)
|
|
|
|
addHotkey("Upkeep", triggerUpkeep)
|
|
|
|
addHotkey("Upkeep (Multi-handed)", triggerUpkeepMultihanded)
|
2023-04-04 12:03:38 +02:00
|
|
|
addHotkey("Wendy's Menu", addWendysMenu)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- triggers the "Upkeep" function of the calling player's playmat
|
|
|
|
function triggerUpkeep(playerColor)
|
|
|
|
if playerColor == "Black" then
|
|
|
|
broadcastToColor("Triggering 'Upkeep (Multihanded)' instead", playerColor, "Yellow")
|
|
|
|
triggerUpkeepMultihanded(playerColor)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local matColor = playmatApi.getMatColor(playerColor)
|
|
|
|
playmatApi.doUpkeepFromHotkey(matColor, playerColor)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- triggers the "Upkeep" function of the calling player's playmat AND
|
|
|
|
-- for all playmats that don't have a seated player, but a investigator card
|
|
|
|
function triggerUpkeepMultihanded(playerColor)
|
|
|
|
if playerColor ~= "Black" then
|
|
|
|
triggerUpkeep(playerColor)
|
|
|
|
end
|
|
|
|
local colors = Player.getAvailableColors()
|
|
|
|
for _, handColor in ipairs(colors) do
|
|
|
|
local matColor = playmatApi.getMatColor(handColor)
|
|
|
|
if playmatApi.returnInvestigatorId(matColor) ~= "00000" and Player[handColor].seated == false then
|
|
|
|
playmatApi.doUpkeepFromHotkey(matColor, playerColor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- adds 1 doom to the agenda
|
|
|
|
function addDoomToAgenda()
|
2023-10-18 20:55:38 +02:00
|
|
|
local doomCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomCounter")
|
2023-10-02 13:51:10 +02:00
|
|
|
doomCounter.call("addVal", 1)
|
2023-04-04 12:03:38 +02:00
|
|
|
end
|
|
|
|
|
2023-10-23 11:25:17 +02:00
|
|
|
-- discard the hovered object to the respective trashcan and discard tokens on it if it was a card
|
2023-10-22 00:12:11 +02:00
|
|
|
function discardObject(playerColor, hoveredObject)
|
2023-11-04 12:25:12 +01:00
|
|
|
-- only continue if an unlocked card, deck or tile was hovered
|
|
|
|
if hoveredObject == nil
|
2023-11-05 10:38:31 +01:00
|
|
|
or (hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck" and hoveredObject.type ~= "Tile")
|
|
|
|
or hoveredObject.locked then
|
2023-10-23 11:25:17 +02:00
|
|
|
broadcastToColor("Hover a token/tile or a card/deck and try again.", playerColor, "Yellow")
|
|
|
|
return
|
|
|
|
end
|
2023-10-22 00:12:11 +02:00
|
|
|
|
2023-11-04 12:25:12 +01:00
|
|
|
-- warning for locations since these are usually not meant to be discarded
|
|
|
|
if hoveredObject.hasTag("Location") then
|
|
|
|
broadcastToAll("Watch out: A location was discarded.", "Yellow")
|
2023-10-22 00:12:11 +02:00
|
|
|
end
|
|
|
|
|
2023-11-04 12:25:12 +01:00
|
|
|
-- initialize list of objects to discard
|
|
|
|
local discardTheseObjects = { hoveredObject }
|
2023-10-23 11:25:17 +02:00
|
|
|
|
2023-11-04 12:25:12 +01:00
|
|
|
-- discard tokens / tiles on cards / decks
|
|
|
|
if hoveredObject.type ~= "Tile" then
|
2023-12-31 13:41:53 +01:00
|
|
|
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
|
2023-12-11 18:11:04 +01:00
|
|
|
table.insert(discardTheseObjects, obj)
|
2023-10-23 11:25:17 +02:00
|
|
|
end
|
2023-11-04 12:25:12 +01:00
|
|
|
end
|
2023-10-23 11:25:17 +02:00
|
|
|
|
2023-11-05 10:38:31 +01:00
|
|
|
local discardForMatColor = getColorToDiscardFor(hoveredObject, playerColor)
|
|
|
|
playmatApi.discardListOfObjects(discardForMatColor, discardTheseObjects)
|
|
|
|
end
|
|
|
|
|
2023-12-07 18:26:13 -06:00
|
|
|
-- discard the top card of hovered deck, calling discardObject function
|
|
|
|
function discardTopDeck(playerColor, hoveredObject)
|
|
|
|
-- only continue if an unlocked card or deck was hovered
|
|
|
|
if hoveredObject == nil
|
|
|
|
or (hoveredObject.type ~= "Card" and hoveredObject.type ~= "Deck")
|
|
|
|
or hoveredObject.locked then
|
|
|
|
broadcastToColor("Hover a deck/card and try again.", playerColor, "Yellow")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if hoveredObject.type == "Deck" then
|
|
|
|
takenCard = hoveredObject.takeObject({index = 0})
|
|
|
|
else
|
|
|
|
takenCard = hoveredObject
|
|
|
|
end
|
|
|
|
Wait.frames(function() discardObject(playerColor, takenCard) end, 1)
|
|
|
|
end
|
|
|
|
|
2023-11-05 10:38:31 +01:00
|
|
|
-- helper function to get the player to trigger the discard function for
|
|
|
|
function getColorToDiscardFor(hoveredObject, playerColor)
|
2023-11-04 12:25:12 +01:00
|
|
|
local pos = hoveredObject.getPosition()
|
|
|
|
local closestMatColor = playmatApi.getMatColorByPosition(pos)
|
|
|
|
|
|
|
|
-- check if actually on the closest playmat
|
|
|
|
local closestMat = guidReferenceApi.getObjectByOwnerAndType(closestMatColor, "Playermat")
|
|
|
|
local bounds = closestMat.getBounds()
|
|
|
|
|
|
|
|
-- define the area "near" the playmat
|
|
|
|
local bufferAroundPlaymat = 2
|
|
|
|
local areaNearPlaymat = {}
|
|
|
|
areaNearPlaymat.minX = bounds.center.x - bounds.size.x / 2 - bufferAroundPlaymat
|
|
|
|
areaNearPlaymat.maxX = bounds.center.x + bounds.size.x / 2 + bufferAroundPlaymat
|
|
|
|
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
|
|
|
|
if inArea(pos, areaNearPlaymat) then
|
2023-11-05 10:38:31 +01:00
|
|
|
return closestMatColor
|
2023-11-04 12:25:12 +01:00
|
|
|
else
|
2023-11-05 10:38:31 +01:00
|
|
|
return playmatApi.getMatColor(playerColor)
|
2023-10-23 11:25:17 +02:00
|
|
|
end
|
2023-10-22 00:12:11 +02:00
|
|
|
end
|
|
|
|
|
2023-04-04 12:03:38 +02:00
|
|
|
-- moves the hovered card to the victory display
|
2023-06-15 23:18:17 +02:00
|
|
|
function moveCardToVictoryDisplay(_, hoveredObject)
|
|
|
|
victoryDisplayApi.placeCard(hoveredObject)
|
2023-04-04 12:03:38 +02:00
|
|
|
end
|
|
|
|
|
2023-11-05 10:38:31 +01:00
|
|
|
-- 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
|
|
|
|
|
2023-12-11 18:11:04 +01:00
|
|
|
for _, obj in ipairs(searchLib.onObject(hoveredObject), "isTileOrToken") do
|
|
|
|
if not obj.locked and obj.memo ~= "resourceCounter" then
|
2023-11-05 10:38:31 +01:00
|
|
|
-- 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
|
|
|
|
|
2023-11-05 17:17:28 +01:00
|
|
|
-- handling for stacked tokens
|
|
|
|
if targetObject.getQuantity() > 1 then
|
|
|
|
targetObject = targetObject.takeObject()
|
|
|
|
end
|
|
|
|
|
2023-11-05 10:38:31 +01:00
|
|
|
-- feedback message
|
|
|
|
local tokenName = targetObject.getName()
|
|
|
|
if tokenName == "" then
|
|
|
|
if targetObject.memo ~= "" then
|
2023-11-05 17:17:28 +01:00
|
|
|
-- name handling for clue / doom
|
|
|
|
if targetObject.memo == "clueDoom" then
|
|
|
|
if targetObject.is_face_down then
|
|
|
|
tokenName = "Doom"
|
|
|
|
else
|
|
|
|
tokenName = "Clue"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
tokenName = titleCase(targetObject.memo)
|
|
|
|
end
|
2023-11-05 10:38:31 +01:00
|
|
|
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
|
|
|
|
|
2023-05-12 13:02:33 +02:00
|
|
|
-- takes a clue from a location, player needs to hover the clue directly or the location
|
|
|
|
function takeClueFromLocation(playerColor, hoveredObject)
|
|
|
|
local cardName, clue
|
|
|
|
|
|
|
|
if hoveredObject == nil then
|
|
|
|
broadcastToColor("Hover a clue or card with clues and try again.", playerColor, "Yellow")
|
|
|
|
return
|
2023-10-22 00:12:11 +02:00
|
|
|
elseif hoveredObject.type == "Card" then
|
2023-05-12 13:02:33 +02:00
|
|
|
cardName = hoveredObject.getName()
|
2023-12-14 09:51:33 +01:00
|
|
|
local searchResult = searchLib.onObject(hoveredObject, "isClue")
|
2023-05-12 13:02:33 +02:00
|
|
|
|
2023-12-14 09:51:33 +01:00
|
|
|
if #searchResult == 0 then
|
2023-05-12 13:02:33 +02:00
|
|
|
broadcastToColor("This card does not have any clues on it.", playerColor, "Yellow")
|
|
|
|
return
|
2023-12-14 09:51:33 +01:00
|
|
|
else
|
|
|
|
clue = searchResult[1]
|
2023-05-12 13:02:33 +02:00
|
|
|
end
|
|
|
|
elseif hoveredObject.memo == "clueDoom" then
|
|
|
|
if hoveredObject.is_face_down then
|
|
|
|
broadcastToColor("This is a doom token and not a clue.", playerColor, "Yellow")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-12-14 09:51:33 +01:00
|
|
|
local searchResult = searchLib.belowPosition(hoveredObject.getPosition(), "isCard")
|
|
|
|
|
|
|
|
if #searchResult ~= 0 then
|
|
|
|
cardName = searchResult[1].getName()
|
2023-05-12 13:02:33 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
broadcastToColor("Hover a clue or card with clues and try again.", playerColor, "Yellow")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-08-08 16:32:58 -04:00
|
|
|
local clickableClues = optionPanelApi.getOptions()["useClueClickers"]
|
2023-05-12 13:02:33 +02:00
|
|
|
local playerName = Player[playerColor].steam_name
|
2023-08-08 16:32:58 -04:00
|
|
|
local matColor = playmatApi.getMatColor(playerColor)
|
|
|
|
local pos = nil
|
|
|
|
if clickableClues then
|
|
|
|
pos = {x = 0.49, y = 2.66, z = 0.00}
|
2023-09-30 00:10:06 +02:00
|
|
|
playmatApi.updateCounter(matColor, "ClickableClueCounter", _, 1)
|
2023-08-08 16:32:58 -04:00
|
|
|
else
|
|
|
|
pos = playmatApi.transformLocalPosition({x = -1.12, y = 0.05, z = 0.7}, matColor)
|
2023-05-12 13:02:33 +02:00
|
|
|
end
|
2023-08-08 16:32:58 -04:00
|
|
|
|
|
|
|
local rot = playmatApi.returnRotation(matColor)
|
2023-05-12 13:02:33 +02:00
|
|
|
|
2023-05-16 10:13:13 +02:00
|
|
|
-- check if found clue is a stack or single token
|
|
|
|
if clue.getQuantity() > 1 then
|
|
|
|
clue.takeObject({position = pos, rotation = rot})
|
|
|
|
else
|
|
|
|
clue.setPositionSmooth(pos)
|
|
|
|
clue.setRotation(rot)
|
|
|
|
end
|
2023-05-12 13:02:33 +02:00
|
|
|
|
|
|
|
if cardName then
|
|
|
|
broadcastToAll(playerName .. " took one clue from " .. cardName .. ".", playerColor)
|
|
|
|
else
|
|
|
|
broadcastToAll(playerName .. " took one clue.", "Green")
|
|
|
|
end
|
2023-06-14 22:17:55 +02:00
|
|
|
|
|
|
|
victoryDisplayApi.update()
|
2023-05-12 13:02:33 +02:00
|
|
|
end
|
|
|
|
|
2023-04-04 12:03:38 +02:00
|
|
|
-- broadcasts the bless/curse status to the calling player
|
|
|
|
function showBlessCurseStatus(playerColor)
|
|
|
|
blessCurseManagerApi.broadcastStatus(playerColor)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- adds Wendy's menu to the hovered card
|
|
|
|
function addWendysMenu(playerColor, hoveredObject)
|
|
|
|
blessCurseManagerApi.addWendysMenu(playerColor, hoveredObject)
|
|
|
|
end
|
2023-05-12 13:02:33 +02:00
|
|
|
|
2023-11-04 12:25:12 +01:00
|
|
|
-- Simple method to check if the given point is in a specified area
|
|
|
|
---@param point Vector Point to check, only x and z values are relevant
|
|
|
|
---@param bounds Table Defined area to see if the point is within
|
|
|
|
function inArea(point, bounds)
|
|
|
|
return (point.x > bounds.minX
|
|
|
|
and point.x < bounds.maxX
|
|
|
|
and point.z > bounds.minZ
|
|
|
|
and point.z < bounds.maxZ)
|
2023-11-05 10:38:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- capitalizes the first letter
|
|
|
|
function titleCase(str)
|
|
|
|
local first = str:sub(1, 1)
|
|
|
|
local rest = str:sub(2)
|
|
|
|
return first:upper() .. rest:lower()
|
2023-12-11 18:11:04 +01:00
|
|
|
end
|