From 52e5ec01f425b38724c55ee56b45e39b107df8b4 Mon Sep 17 00:00:00 2001 From: Zerino Date: Wed, 13 Nov 2024 21:08:52 -0300 Subject: [PATCH 1/2] updated upkeep hotkey, removed upkeep (multihanded) hotkey --- src/core/GameKeyHandler.ttslua | 39 ++++++++++++++-------------------- src/core/PlayArea.ttslua | 7 +++++- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index c045c928..d94f7635 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -9,6 +9,8 @@ local searchLib = require("util/SearchLib") local tokenChecker = require("core/token/TokenChecker") local victoryDisplayApi = require("core/VictoryDisplayApi") +local sentMessage = false + function onLoad() addHotkey("Add doom to agenda", addDoomToAgenda) addHotkey("Add Bless/Curse context menu", addBlurseSealingMenu) @@ -27,39 +29,30 @@ function onLoad() addHotkey("Take clue from location (Green)", takeClueFromLocationGreen) addHotkey("Take clue from location (Red)", takeClueFromLocationRed) addHotkey("Upkeep", triggerUpkeep) - addHotkey("Upkeep (Multi-handed)", triggerUpkeepMultihanded) end -- triggers the "Upkeep" function of the calling player's playermat function triggerUpkeep(playerColor) - if playerColor == "Black" then - broadcastToColor("Triggering 'Upkeep (Multihanded)' instead", playerColor, "Yellow") - triggerUpkeepMultihanded(playerColor) + if playerColor == "Black" and not sentMessage then + broadcastToColor("It is recommended to sit on a player mat", playerColor, "Yellow") + sentMessage = true + end + if #Player.getPlayers() == 1 then + local colors = Player.getAvailableColors() + for _, handColor in ipairs(colors) do + local matColor = playermatApi.getMatColor(handColor) + local data = playermatApi.getActiveInvestigatorData(matColor) + if data.id ~= "00000" then + playermatApi.doUpkeepFromHotkey(matColor, playerColor) + end + end + playAreaApi.readyCards() return end local matColor = playermatApi.getMatColor(playerColor) playermatApi.doUpkeepFromHotkey(matColor, playerColor) end --- triggers the "Upkeep" function of the calling player's playermat AND --- for all playermats that don't have a seated player, but an investigator card -function triggerUpkeepMultihanded(playerColor) - if playerColor ~= "Black" then - triggerUpkeep(playerColor) - end - local colors = Player.getAvailableColors() - for _, handColor in ipairs(colors) do - local matColor = playermatApi.getMatColor(handColor) - local data = playermatApi.getActiveInvestigatorData(matColor) - if data.id ~= "00000" and Player[handColor].seated == false then - playermatApi.doUpkeepFromHotkey(matColor, playerColor) - end - end - - -- also trigger the PlayArea's "Ready Cards" function - playAreaApi.readyCards() -end - -- adds 1 doom to the agenda function addDoomToAgenda() local doomCounter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DoomCounter") diff --git a/src/core/PlayArea.ttslua b/src/core/PlayArea.ttslua index e80fceac..567ff802 100644 --- a/src/core/PlayArea.ttslua +++ b/src/core/PlayArea.ttslua @@ -514,7 +514,12 @@ end -- Readies all cards in the main playarea (both player cards, treacheries and enemies) function readyCards(player, clickType) - local playerColor = player.color + if player ~= nil then + local playerColor = player.color + else + local existingPlayer = Player.getPlayers()[1] + playerColor = existingPlayer.color + end -- when right-clicked if clickType == "-2" then From 77f320e18885a43b21d960170aefb804e31a516d Mon Sep 17 00:00:00 2001 From: Zerino Date: Wed, 13 Nov 2024 21:42:27 -0300 Subject: [PATCH 2/2] fixed a local, made code even smaller --- src/core/GameKeyHandler.ttslua | 10 +++------- src/core/PlayArea.ttslua | 3 ++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index d94f7635..761d86ed 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -38,13 +38,9 @@ function triggerUpkeep(playerColor) sentMessage = true end if #Player.getPlayers() == 1 then - local colors = Player.getAvailableColors() - for _, handColor in ipairs(colors) do - local matColor = playermatApi.getMatColor(handColor) - local data = playermatApi.getActiveInvestigatorData(matColor) - if data.id ~= "00000" then - playermatApi.doUpkeepFromHotkey(matColor, playerColor) - end + local usedMats = playermatApi.getUsedMatColors() + for _, matColor in ipairs(usedMats) do + playermatApi.doUpkeepFromHotkey(matColor, playerColor) end playAreaApi.readyCards() return diff --git a/src/core/PlayArea.ttslua b/src/core/PlayArea.ttslua index 567ff802..34f2778f 100644 --- a/src/core/PlayArea.ttslua +++ b/src/core/PlayArea.ttslua @@ -514,8 +514,9 @@ end -- Readies all cards in the main playarea (both player cards, treacheries and enemies) function readyCards(player, clickType) + local playerColor if player ~= nil then - local playerColor = player.color + playerColor = player.color else local existingPlayer = Player.getPlayers()[1] playerColor = existingPlayer.color