summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop.Tests')
-rw-r--r--src/LivingVillage.Desktop.Tests/PrototypeTests.fs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs
index 77d2530..af34802 100644
--- a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs
+++ b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs
@@ -595,6 +595,41 @@ type PrototypeTests () =
Assert.IsTrue(M5Interaction.resolveAction blockedWorld Outside |> Option.isNone)
[<TestMethod>]
+ member _.TargetSelectionUsesPureDistancePriorityWithIdTiebreak () =
+ let doorPixel : PixelPosition =
+ { X = float32 (31 * Sim.tilePixels + Sim.tilePixels / 2)
+ Y = float32 (23 * Sim.tilePixels + Sim.tilePixels / 2) }
+ let avatar : Vec2 = { X = doorPixel.X - 32.0f; Y = doorPixel.Y }
+ let world = Sim.initialWorldN 42UL 2
+
+ // Door nearer than the villager: door wins by pure distance (no kind privilege).
+ let doorNearer =
+ { world with
+ Avatar = { world.Avatar with Pos = avatar }
+ Npcs = [| { world.Npcs.[0] with Pos = { X = avatar.X + 40.0f; Y = avatar.Y } } |] }
+ Assert.AreEqual<InteractionAction option>(Some(EnterHome(HomeId 1)), InteractionResolver.resolve doorNearer Outside |> Option.map (fun candidate -> candidate.Action))
+
+ // NPC nearer than the door: villager wins.
+ let npcNearerWorld = { doorNearer with Npcs = [| { world.Npcs.[0] with Pos = { X = avatar.X + 4.0f; Y = avatar.Y } } |] }
+ Assert.AreEqual<InteractionAction option>(Some(TalkTo(NpcId 0)), InteractionResolver.resolve npcNearerWorld Outside |> Option.map (fun candidate -> candidate.Action))
+
+ // Exact distance tie between two villagers: lower entity id wins deterministically.
+ let tieAvatar : Vec2 = { X = 1600.0f; Y = 800.0f }
+ let tieWorld =
+ { world with
+ Avatar = { world.Avatar with Pos = tieAvatar }
+ Npcs = [| { world.Npcs.[0] with Pos = { X = tieAvatar.X + 64.0f; Y = tieAvatar.Y } }
+ { world.Npcs.[1] with Pos = { X = tieAvatar.X - 64.0f; Y = tieAvatar.Y } } |] }
+ Assert.AreEqual<InteractionAction option>(Some(TalkTo(NpcId 0)), InteractionResolver.resolve tieWorld Outside |> Option.map (fun candidate -> candidate.Action))
+
+ // Array snapshot immutability: neither resolve nor refreshPrompt may mutate Npcs.
+ let snapshot = Array.copy tieWorld.Npcs
+ let resolvedIgnore = InteractionResolver.resolve tieWorld Outside
+ CollectionAssert.AreEqual(snapshot, tieWorld.Npcs)
+ let view = M5Interaction.refreshPrompt tieWorld M5Interaction.initial
+ CollectionAssert.AreEqual(snapshot, tieWorld.Npcs)
+
+ [<TestMethod>]
member _.WorldPanelDoesNotRenderA永久KeyList () =
let world = Sim.initialWorldN 42UL 0
let lines = M5Interaction.panelLines world M5Interaction.initial