SCED/src/core/GameKeyHandler.ttslua

153 lines
4.8 KiB
Plaintext
Raw Normal View History

2023-04-04 12:03:38 +02:00
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local playmatApi = require("playermat/PlaymatApi")
2023-06-14 22:17:55 +02:00
local victoryDisplayApi = require("core/VictoryDisplayApi")
local optionPanelApi = require("core/OptionPanelApi")
2023-04-04 12:03:38 +02:00
function onLoad()
addHotkey("Add Doom to Agenda", addDoomToAgenda)
addHotkey("Bless/Curse Status", showBlessCurseStatus)
2023-05-12 13:02:33 +02:00
addHotkey("Move card to Victory Display", moveCardToVictoryDisplay)
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()
getObjectFromGUID("85c4c6").call("addVal", 1)
end
-- 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-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
elseif hoveredObject.tag == "Card" then
cardName = hoveredObject.getName()
for _, v in ipairs(searchOnObj(hoveredObject)) do
local obj = v.hit_object
if obj.memo == "clueDoom" and obj.is_face_down == false then
clue = obj
break
end
end
if clue == nil then
broadcastToColor("This card does not have any clues on it.", playerColor, "Yellow")
return
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
clue = hoveredObject
local search = Physics.cast({
direction = { 0, -1, 0 },
max_distance = 0.1,
type = 3,
size = { 0.1, 0.1, 0.1 },
origin = clue.getPosition()
})
for _, v in ipairs(search) do
local obj = v.hit_object
if obj.tag == "Card" then
cardName = obj.getName()
break
end
end
else
broadcastToColor("Hover a clue or card with clues and try again.", playerColor, "Yellow")
return
end
local clickableClues = optionPanelApi.getOptions()["useClueClickers"]
2023-05-12 13:02:33 +02:00
local playerName = Player[playerColor].steam_name
local matColor = playmatApi.getMatColor(playerColor)
local pos = nil
if clickableClues then
pos = {x = 0.49, y = 2.66, z = 0.00}
playmatApi.updateClueClicker(playerColor, playmatApi.getClueCount(clickableClues, playerColor) + 1)
else
pos = playmatApi.transformLocalPosition({x = -1.12, y = 0.05, z = 0.7}, matColor)
2023-05-12 13:02:33 +02:00
end
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
-- searches on an object (by using its bounds)
---@param obj Object Object to search on
function searchOnObj(obj)
return Physics.cast({
direction = { 0, 1, 0 },
max_distance = 0.5,
type = 3,
size = obj.getBounds().size,
origin = obj.getPosition()
})
2023-05-16 10:13:13 +02:00
end