ui/client thread race condition: moved lava/waterfall state machine logic into the client thread

so it's synced with the client thread.
This commit is contained in:
Louis Hong
2024-11-09 09:33:43 -08:00
parent 74d8f531d6
commit f58e5ad868

View File

@@ -279,59 +279,62 @@ public class EasyGiantsFoundryPlugin extends Plugin
@Subscribe @Subscribe
public void onMenuOptionClicked(MenuOptionClicked event) public void onMenuOptionClicked(MenuOptionClicked event)
{ {
clientThread.invokeAtTickEnd(() ->
if (!(event.getMenuAction() == MenuAction.GAME_OBJECT_FIRST_OPTION
|| event.getMenuAction() == MenuAction.GAME_OBJECT_SECOND_OPTION
|| event.getMenuAction() == MenuAction.GAME_OBJECT_THIRD_OPTION
|| event.getMenuAction() == MenuAction.GAME_OBJECT_FOURTH_OPTION
|| event.getMenuAction() == MenuAction.GAME_OBJECT_FIFTH_OPTION
|| event.getMenuAction() == MenuAction.WIDGET_TARGET_ON_GAME_OBJECT
|| event.getMenuAction() == MenuAction.WALK))
{ {
return; if (!(event.getMenuAction() == MenuAction.GAME_OBJECT_FIRST_OPTION
} || event.getMenuAction() == MenuAction.GAME_OBJECT_SECOND_OPTION
|| event.getMenuAction() == MenuAction.GAME_OBJECT_THIRD_OPTION
if (!state.isEnabled()) return; || event.getMenuAction() == MenuAction.GAME_OBJECT_FOURTH_OPTION
|| event.getMenuAction() == MenuAction.GAME_OBJECT_FIFTH_OPTION
if (event.getMenuTarget().contains("Crucible ")) || event.getMenuAction() == MenuAction.WIDGET_TARGET_ON_GAME_OBJECT
{ || event.getMenuAction() == MenuAction.WALK))
if (event.getMenuOption().equals("Pour"))
{ {
if (client.getVarbitValue(VARBIT_GAME_STAGE) == 1) return;
{
state.setLastKnownCrucibleScore((int) state.getCrucibleScore());
}
// add persistent game message of the alloy value so user can reference later.
client.addChatMessage(ChatMessageType.GAMEMESSAGE, "", "The score of the preform is <col=00FFFF>" + ((int) state.getCrucibleScore() + state.getMouldScore()), null);
} }
}
// Could not find a varbit to capture, so capture the menu-option directly. if (!state.isEnabled()) return;
// start the HeatActionStateMachine when varbit begins to update in onVarbitChanged()
if (event.getMenuOption().startsWith("Heat-preform")) if (event.getMenuTarget().contains("Crucible "))
{ {
state.heatActionStateMachine.stop(); if (event.getMenuOption().equals("Pour"))
state.heatActionStateMachine.setup(false, true, "heats"); {
} if (client.getVarbitValue(VARBIT_GAME_STAGE) == 1)
else if (event.getMenuOption().startsWith("Dunk-preform")) {
{ state.setLastKnownCrucibleScore((int) state.getCrucibleScore());
state.heatActionStateMachine.stop(); }
state.heatActionStateMachine.setup(true, true, "dunks"); // add persistent game message of the alloy value so user can reference later.
} client.addChatMessage(ChatMessageType.GAMEMESSAGE, "", "The score of the preform is <col=00FFFF>" + ((int) state.getCrucibleScore() + state.getMouldScore()), null);
else if (event.getMenuOption().startsWith("Cool-preform")) }
{ }
state.heatActionStateMachine.stop();
state.heatActionStateMachine.setup(false, false, "cools"); // Could not find a varbit to capture, so capture the menu-option directly.
} // start the HeatActionStateMachine when varbit begins to update in onVarbitChanged()
else if (event.getMenuOption().startsWith("Quench-preform")) if (event.getMenuOption().startsWith("Heat-preform"))
{ {
state.heatActionStateMachine.stop(); state.heatActionStateMachine.stop();
state.heatActionStateMachine.setup(true, false, "quenches"); state.heatActionStateMachine.setup(false, true, "heats");
} }
else if (!state.heatActionStateMachine.isIdle()) // canceled heating/cooling, stop the heating state-machine else if (event.getMenuOption().startsWith("Dunk-preform"))
{ {
state.heatActionStateMachine.stop(); state.heatActionStateMachine.stop();
} state.heatActionStateMachine.setup(true, true, "dunks");
}
else if (event.getMenuOption().startsWith("Cool-preform"))
{
state.heatActionStateMachine.stop();
state.heatActionStateMachine.setup(false, false, "cools");
}
else if (event.getMenuOption().startsWith("Quench-preform"))
{
state.heatActionStateMachine.stop();
state.heatActionStateMachine.setup(true, false, "quenches");
}
else if (!state.heatActionStateMachine.isIdle()) // canceled heating/cooling, stop the heating state-machine
{
state.heatActionStateMachine.stop();
}
});
} }
@Subscribe @Subscribe