From 767ed4cb47b714631209cc9e906dc4b40ac9b37d Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Tue, 13 Oct 2026 19:21:01 -0400 Subject: [PATCH] Use physical Ctrl state for stack dropping, not toggle sprint --- crates/horizon-client/src/game.rs | 6 ++- crates/horizon-client/src/game/agent.rs | 9 +--- tests/test_drop_modifier_policy.py | 55 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 tests/test_drop_modifier_policy.py diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 594eb9325..5156e685c 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4170,7 +4170,8 @@ impl Game<'_> { (Some(n), _) => self.menu_click(Some(slot), n as i32, Input::Swap), (None, KeyCode::KeyF) => self.menu_click(Some(slot), 40, Input::Swap), (None, KeyCode::KeyQ) => { - let all = self.keys.contains(&KeyCode::ControlLeft); + let all = self.physical_keys.contains(&KeyCode::ControlLeft) + || self.physical_keys.contains(&KeyCode::ControlRight); self.menu_click(Some(slot), i32::from(all), Input::Throw) } _ => false, @@ -8001,7 +8002,8 @@ impl Game<'_> { self.using = None; } KeyCode::KeyQ if self.screen == Screen::Playing => { - let all = self.keys.contains(&KeyCode::ControlLeft); + let all = self.physical_keys.contains(&KeyCode::ControlLeft) + || self.physical_keys.contains(&KeyCode::ControlRight); self.drop_held(all); } KeyCode::Digit1 diff --git a/crates/horizon-client/src/game/agent.rs b/crates/horizon-client/src/game/agent.rs index 2de1f4c74..8b1b8071e 100644 --- a/crates/horizon-client/src/game/agent.rs +++ b/crates/horizon-client/src/game/agent.rs @@ -1232,14 +1232,7 @@ impl Game<'_> { self.playing()?; let all = a.pos.first() == Some(&"all"); let before = self.held().map(|s| self.stack_value(s)); - if all { - self.keys.insert(KeyCode::ControlLeft); - } - let result = self.key_pressed(KeyCode::KeyQ); - if all { - self.keys.remove(&KeyCode::ControlLeft); - } - result?; + self.drop_held(all); ok( json!({ "ok": true, "dropped_from": before, "held": self.held().map(|s| self.stack_value(s)) }), ) diff --git a/tests/test_drop_modifier_policy.py b/tests/test_drop_modifier_policy.py new file mode 100644 index 000000000..76415f876 --- /dev/null +++ b/tests/test_drop_modifier_policy.py @@ -0,0 +1,55 @@ +"""Drop modifiers must come from physical Ctrl, not the sprint key mapping.""" +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] + + +class DropModifierPolicyTests(unittest.TestCase): + @unittest.skipUnless(shutil.which("rustc"), "rustc is needed for the drop-policy probe") + def test_playing_and_inventory_drop_ignore_latched_sprint(self): + source = (ROOT / "crates/horizon-client/src/game.rs").read_text() + inventory = source.split("fn inventory_hotkey(", 1)[1] + playing = source.split("KeyCode::KeyQ if self.screen == Screen::Playing =>", 1)[1] + expressions = [section.split("let all = ", 1)[1].split(";", 1)[0] + for section in (inventory, playing)] + program = """ +use std::collections::HashSet; +#[derive(PartialEq, Eq, Hash)] enum KeyCode { ControlLeft, ControlRight } +struct Game { keys: HashSet, physical_keys: HashSet } +impl Game { + fn inventory_drop_all(&self) -> bool { INVENTORY } + fn playing_drop_all(&self) -> bool { PLAYING } +} +#[test] +fn sprint_and_control_are_independent() { + for sprint in [false, true] { + for held in 0..4 { + let ctrl = held != 0; + let mut game = Game { keys: HashSet::new(), physical_keys: HashSet::new() }; + if held & 1 != 0 { game.physical_keys.insert(KeyCode::ControlLeft); } + if held & 2 != 0 { game.physical_keys.insert(KeyCode::ControlRight); } + if sprint { game.keys.insert(KeyCode::ControlLeft); } + assert_eq!(game.inventory_drop_all(), ctrl, "inventory: sprint={sprint}, ctrl={ctrl}"); + assert_eq!(game.playing_drop_all(), ctrl, "playing: sprint={sprint}, ctrl={ctrl}"); + } + } +} +""".replace("INVENTORY", expressions[0]).replace("PLAYING", expressions[1]) + with tempfile.TemporaryDirectory(prefix="horizon-drop-policy-") as directory: + path = Path(directory) + (path / "probe.rs").write_text(program) + compiled = subprocess.run( + ["rustc", "--edition=2024", "--test", str(path / "probe.rs"), "-o", str(path / "probe")], + capture_output=True, text=True, check=False, + ) + self.assertEqual(compiled.returncode, 0, compiled.stderr) + result = subprocess.run([str(path / "probe")], capture_output=True, text=True, check=False) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + + +if __name__ == "__main__": + unittest.main()