From 50bab1bd2b95fc75b4c379a5770d4af38bfd3ed2 Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 19:37:15 +0000 Subject: [PATCH] More refactoring of Interaction --- NetAF.Examples/Assets/Player/Player.cs | 10 +++--- .../Regions/Everglades/Items/ConchShell.cs | 4 +-- .../Regions/Everglades/Rooms/InnerCave.cs | 6 ++-- NetAF.Examples/Assets/Regions/Flat/Flat.cs | 10 +++--- .../Assets/Regions/Flat/Items/CoffeeMug.cs | 4 +-- .../Assets/Regions/Flat/Items/Kettle.cs | 4 +-- .../Assets/Regions/Flat/Rooms/Kitchen.cs | 4 +-- .../Assets/Regions/Flat/Rooms/Lounge.cs | 10 +++--- .../Assets/Regions/Zelda/NPCs/Saria.cs | 10 +++--- .../Regions/Zelda/Rooms/OutsideLinksHouse.cs | 6 ++-- .../Assets/Regions/Zelda/Rooms/Stream.cs | 4 +-- NetAF.Tests/Assets/Interaction_Tests.cs | 32 +++++++++++------ NetAF.Tests/Assets/Item_Tests.cs | 4 +-- NetAF.Tests/Commands/Scene/UseOn_Tests.cs | 35 ++++++++++++++++--- .../Assets/Characters/NonPlayableCharacter.cs | 2 +- NetAF/Assets/Characters/PlayableCharacter.cs | 2 +- NetAF/Assets/Interaction.cs | 9 ++--- NetAF/Assets/InteractionResult.cs | 20 ++++++----- NetAF/Assets/Item.cs | 2 +- NetAF/Assets/Locations/Exit.cs | 2 +- NetAF/Assets/Locations/Room.cs | 2 +- NetAF/Commands/Scene/UseOn.cs | 23 ++++++------ docs/docfx/docs/items.md | 4 +-- 23 files changed, 126 insertions(+), 83 deletions(-) diff --git a/NetAF.Examples/Assets/Player/Player.cs b/NetAF.Examples/Assets/Player/Player.cs index a5d8022f..c565f7c6 100644 --- a/NetAF.Examples/Assets/Player/Player.cs +++ b/NetAF.Examples/Assets/Player/Player.cs @@ -27,18 +27,18 @@ public PlayableCharacter Instantiate() var player = new PlayableCharacter(Name, Description, [new Knife().Instantiate()], interaction: i => { if (i == null) - return new(InteractionResult.NeitherItemOrTargetExpired, null); + return new(InteractionResult.NoChange, null); if (Knife.Name.EqualsExaminable(i)) - return new(InteractionResult.TargetExpired, i, "You slash wildly at your own throat. You are dead."); + return new(InteractionResult.TargetExpires, i, "You slash wildly at your own throat. You are dead."); if (CoffeeMug.Name.EqualsIdentifier(i.Identifier)) - return new(InteractionResult.NeitherItemOrTargetExpired, i, "If there was some coffee in the mug you could drink it."); + return new(InteractionResult.NoChange, i, "If there was some coffee in the mug you could drink it."); if (Guitar.Name.EqualsIdentifier(i.Identifier)) - return new(InteractionResult.NeitherItemOrTargetExpired, i, "You bust out some Bad Religion. Cracking, shame the guitar isn't plugged in to an amplified though..."); + return new(InteractionResult.NoChange, i, "You bust out some Bad Religion. Cracking, shame the guitar isn't plugged in to an amplified though..."); - return new(InteractionResult.NeitherItemOrTargetExpired, i); + return new(InteractionResult.NoChange, i); }); return player; diff --git a/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs b/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs index 8954269e..8eb29b1f 100644 --- a/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs +++ b/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs @@ -24,9 +24,9 @@ public Item Instantiate() var conchShell = new Item(Name, Description, true, interaction: item => { if (item.Identifier.Equals(Knife.Name)) - return new(InteractionResult.TargetExpired, item, "You slash at the conch shell and it shatters into tiny pieces. Without the conch shell you are well and truly in trouble."); + return new(InteractionResult.TargetExpires, item, "You slash at the conch shell and it shatters into tiny pieces. Without the conch shell you are well and truly in trouble."); - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }); return conchShell; diff --git a/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs b/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs index 7ea3d995..32d02aa5 100644 --- a/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs +++ b/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs @@ -30,13 +30,13 @@ public Room Instantiate() if (item != null && ConchShell.Name.EqualsExaminable(item)) { room[Direction.North].Unlock(); - return new(InteractionResult.ItemExpired, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces."); + return new(InteractionResult.ItemExpires, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces."); } if (item != null && Knife.Name.EqualsExaminable(item)) - return new(InteractionResult.NeitherItemOrTargetExpired, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); + return new(InteractionResult.NoChange, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }); room.SpecifyConditionalDescription(new ConditionalDescription("With the bats gone there is daylight to the north. To the west is the cave entrance", "As you enter the inner cave the screeching gets louder, and in the gloom you can make out what looks like a million sets of eyes looking back at you. Bats! You can just make out a few rays of light coming from the north, but the bats are blocking your way.", () => !room[Direction.North].IsLocked)); diff --git a/NetAF.Examples/Assets/Regions/Flat/Flat.cs b/NetAF.Examples/Assets/Regions/Flat/Flat.cs index 77345d03..f6eca28f 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Flat.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Flat.cs @@ -36,7 +36,7 @@ public Region Instantiate() if (Lead.Name.EqualsIdentifier(item.Identifier)) { spareBedroom.AddItem(new(item.Identifier, item.Description, true)); - return new(InteractionResult.ItemExpired, item, "The lead fits snugly into the input socket on the amp."); + return new(InteractionResult.ItemExpires, item, "The lead fits snugly into the input socket on the amp."); } if (Guitar.Name.EqualsIdentifier(item.Identifier)) @@ -48,16 +48,16 @@ public Region Instantiate() if (lounge.FindCharacter(Beth.Name, out var b)) { lounge.RemoveCharacter(b); - return new(InteractionResult.NeitherItemOrTargetExpired, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings. Beth's had enough! She bolts for the front door leaving it wide open! You are free to leave the flat! You unplug the guitar."); + return new(InteractionResult.NoChange, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings. Beth's had enough! She bolts for the front door leaving it wide open! You are free to leave the flat! You unplug the guitar."); } - return new(InteractionResult.NeitherItemOrTargetExpired, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); + return new(InteractionResult.NoChange, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); } - return new(InteractionResult.NeitherItemOrTargetExpired, item, "You have no lead so you can't use the guitar with the amp..."); + return new(InteractionResult.NoChange, item, "You have no lead so you can't use the guitar with the amp..."); } - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }).Instantiate(); var regionMaker = new RegionMaker(Name, Description) diff --git a/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs b/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs index a1759628..ef5a1e1a 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs @@ -25,10 +25,10 @@ public Item Instantiate() { if (Kettle.Name.EqualsIdentifier(item.Identifier)) { - return new(InteractionResult.NeitherItemOrTargetExpired, item, "You put some instant coffee graduals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); + return new(InteractionResult.NoChange, item, "You put some instant coffee graduals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); } - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }); } diff --git a/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs b/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs index 132fb0df..11353907 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs @@ -24,9 +24,9 @@ public Item Instantiate() return new(Name, Description, interaction: item => { if (item != null && CoffeeMug.Name.EqualsIdentifier(item.Identifier)) - return new(InteractionResult.NeitherItemOrTargetExpired, item, "You put some instant coffee granuals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); + return new(InteractionResult.NoChange, item, "You put some instant coffee granuals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!"); - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }); } diff --git a/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs b/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs index 1f225dc5..537e461f 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs @@ -26,9 +26,9 @@ public Room Instantiate() var room = new Room(Name, Description, [new Exit(Direction.South), new Exit(Direction.East)], interaction: item => { if (Guitar.Name.EqualsIdentifier(item.Identifier)) - return new(InteractionResult.NeitherItemOrTargetExpired, item, "Playing guitar in the kitchen is pretty stupid don't you think?"); + return new(InteractionResult.NoChange, item, "Playing guitar in the kitchen is pretty stupid don't you think?"); - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }); room.AddItem(new HamsterCage().Instantiate()); diff --git a/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs b/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs index 82d5bab9..23e6bba9 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs @@ -36,23 +36,23 @@ public Room Instantiate() if (CoffeeMug.Name.EqualsIdentifier(item.Identifier)) { if (room.ContainsCharacter(Beth.Name)) - return new(InteractionResult.ItemExpired, item, "Beth takes the cup of coffee and smiles. Brownie points to you!"); + return new(InteractionResult.ItemExpires, item, "Beth takes the cup of coffee and smiles. Brownie points to you!"); - return new(InteractionResult.NeitherItemOrTargetExpired, item, "As no one is about you decide to drink the coffee yourself. Your nose wasn't lying, it is bitter but delicious."); + return new(InteractionResult.NoChange, item, "As no one is about you decide to drink the coffee yourself. Your nose wasn't lying, it is bitter but delicious."); } if (CoffeeMug.Name.EqualsIdentifier(item.Identifier)) { room.AddItem(item); - return new(InteractionResult.ItemExpired, item, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed."); + return new(InteractionResult.ItemExpires, item, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed."); } if (Guitar.Name.EqualsIdentifier(item.Identifier)) - return new(InteractionResult.NeitherItemOrTargetExpired, item, "You strum the guitar frantically trying to impress Beth, she smiles but looks at you like you are a fool. The guitar just isn't loud enough when it is not plugged in..."); + return new(InteractionResult.NoChange, item, "You strum the guitar frantically trying to impress Beth, she smiles but looks at you like you are a fool. The guitar just isn't loud enough when it is not plugged in..."); } - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }); room.AddCharacter(new Beth().Instantiate()); diff --git a/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs b/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs index 54b9ad80..1d615221 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs @@ -59,12 +59,12 @@ public NonPlayableCharacter Instantiate() { saria.RemoveItem(key); room.AddItem(key); - return new(InteractionResult.ItemExpired, item, $"{saria.Identifier.Name} looks excited! \"Thanks Link, here take the Tail Key!\" Saria put the Tail Key down, awesome!"); + return new(InteractionResult.ItemExpires, item, $"{saria.Identifier.Name} looks excited! \"Thanks Link, here take the Tail Key!\" Saria put the Tail Key down, awesome!"); } if (Shield.Name.EqualsIdentifier(item.Identifier)) { - return new(InteractionResult.NeitherItemOrTargetExpired, item, $"{saria.Identifier.Name} looks at your shield, but seems pretty unimpressed."); + return new(InteractionResult.NoChange, item, $"{saria.Identifier.Name} looks at your shield, but seems pretty unimpressed."); } if (Sword.Name.EqualsIdentifier(item.Identifier) && saria.IsAlive) @@ -72,15 +72,15 @@ public NonPlayableCharacter Instantiate() saria.Kill(); if (!saria.HasItem(key)) - return new(InteractionResult.NeitherItemOrTargetExpired, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead."); + return new(InteractionResult.NoChange, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead."); saria.RemoveItem(key); room.AddItem(key); - return new(InteractionResult.NeitherItemOrTargetExpired, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead. When she fell you saw something drop to out of her hand, it looked like a key..."); + return new(InteractionResult.NoChange, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead. When she fell you saw something drop to out of her hand, it looked like a key..."); } - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }); saria.AddItem(new TailKey().Instantiate()); diff --git a/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs b/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs index c8deb68a..776b4eb1 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs @@ -35,13 +35,13 @@ public Room Instantiate() exit.Unlock(); room.RemoveItem(door); - return new(InteractionResult.ItemExpired, item, "The Tail Key fits perfectly in the lock, you turn it and the door swings open, revealing a gaping cave mouth..."); + return new(InteractionResult.ItemExpires, item, "The Tail Key fits perfectly in the lock, you turn it and the door swings open, revealing a gaping cave mouth..."); } if (Sword.Name.EqualsExaminable(item)) - return new(InteractionResult.NeitherItemOrTargetExpired, item, "Clang clang!"); + return new(InteractionResult.NoChange, item, "Clang clang!"); - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }).Instantiate(); room.AddItem(door); diff --git a/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs b/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs index 8588d798..aa54cdff 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs @@ -38,10 +38,10 @@ public Room Instantiate() if (Sword.Name.EqualsExaminable(item)) { rupee.IsPlayerVisible = true; - return new(InteractionResult.TargetExpired, item, "You slash wildly at the bush and reduce it to a stump. This exposes a red rupee, that must have been what was glinting from within the bush..."); + return new(InteractionResult.TargetExpires, item, "You slash wildly at the bush and reduce it to a stump. This exposes a red rupee, that must have been what was glinting from within the bush..."); } - return new(InteractionResult.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NoChange, item); }).Instantiate(); rupee.IsPlayerVisible = false; diff --git a/NetAF.Tests/Assets/Interaction_Tests.cs b/NetAF.Tests/Assets/Interaction_Tests.cs index 862b670b..df0c1800 100644 --- a/NetAF.Tests/Assets/Interaction_Tests.cs +++ b/NetAF.Tests/Assets/Interaction_Tests.cs @@ -9,7 +9,7 @@ public class Interaction_Tests [TestMethod] public void GivenConstructor_WhenExplicitDescription_ThenDescriptionIsAsSpecified() { - Interaction instance = new(InteractionResult.NeitherItemOrTargetExpired, null, "A"); + Interaction instance = new(InteractionResult.NoChange, null, "A"); var result = instance.Description; @@ -19,27 +19,27 @@ public void GivenConstructor_WhenExplicitDescription_ThenDescriptionIsAsSpecifie [TestMethod] public void GivenConstructor_WhenItemUsedUp_ThenGeneratedDescriptionIsCorrect() { - Interaction instance = new(InteractionResult.ItemExpired, null); + Interaction instance = new(InteractionResult.ItemExpires, null); var result = instance.Description; - Assert.AreEqual("The item expired.", result); + Assert.AreEqual("The item expires.", result); } [TestMethod] - public void GivenConstructor_WhenItemAndTargetExpired_ThenGeneratedDescriptionIsCorrect() + public void GivenConstructor_WhenItemAndTargetExpires_ThenGeneratedDescriptionIsCorrect() { - Interaction instance = new(InteractionResult.ItemAndTargetExpired, null); + Interaction instance = new(InteractionResult.ItemAndTargetExpires, null); var result = instance.Description; - Assert.AreEqual("Both the item and target expired.", result); + Assert.AreEqual("Both the item and target expires.", result); } [TestMethod] - public void GivenConstructor_WhenNeitherItemOrTargetExpired_ThenGeneratedDescriptionIsCorrect() + public void GivenConstructor_WhenNoChange_ThenGeneratedDescriptionIsCorrect() { - Interaction instance = new(InteractionResult.NeitherItemOrTargetExpired, null); + Interaction instance = new(InteractionResult.NoChange, null); var result = instance.Description; @@ -47,13 +47,23 @@ public void GivenConstructor_WhenNeitherItemOrTargetExpired_ThenGeneratedDescrip } [TestMethod] - public void GivenConstructor_WhenTargetExpired_ThenGeneratedDescriptionIsCorrect() + public void GivenConstructor_WhenTargetExpires_ThenGeneratedDescriptionIsCorrect() { - Interaction instance = new(InteractionResult.TargetExpired, null); + Interaction instance = new(InteractionResult.TargetExpires, null); var result = instance.Description; - Assert.AreEqual("The target expired.", result); + Assert.AreEqual("The target expires.", result); + } + + [TestMethod] + public void GivenConstructor_WhenPlayerDies_ThenGeneratedDescriptionIsCorrect() + { + Interaction instance = new(InteractionResult.PlayerDies, null); + + var result = instance.Description; + + Assert.AreEqual("The player dies.", result); } } } \ No newline at end of file diff --git a/NetAF.Tests/Assets/Item_Tests.cs b/NetAF.Tests/Assets/Item_Tests.cs index 94c0b055..a4df887e 100644 --- a/NetAF.Tests/Assets/Item_Tests.cs +++ b/NetAF.Tests/Assets/Item_Tests.cs @@ -7,14 +7,14 @@ namespace NetAF.Tests.Assets public class Item_Tests { [TestMethod] - public void Given2Items_WhenInteract_ThenNeitherItemOrTargetExpired() + public void Given2Items_WhenInteract_ThenNoChange() { var item = new Item(string.Empty, string.Empty); var item2 = new Item(string.Empty, string.Empty); var result = item.Interact(item2); - Assert.AreEqual(InteractionResult.NeitherItemOrTargetExpired, result.Result); + Assert.AreEqual(InteractionResult.NoChange, result.Result); } } } diff --git a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs index e5bb3e19..d63a3136 100644 --- a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs +++ b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs @@ -109,7 +109,7 @@ public void GivenItemOnRoomInteractionCausesItemExpire_WhenInvoke_ThenItemRemove var item = new Item(Identifier.Empty, Description.Empty, true); var room = new Room(Identifier.Empty, Description.Empty, items: [item], interaction: (i) => { - return new Interaction(InteractionResult.ItemExpired, i); + return new Interaction(InteractionResult.ItemExpires, i); }); var region = new Region(string.Empty, string.Empty); region.AddRoom(room, 0, 0, 0); @@ -136,7 +136,7 @@ public void GivenItemOnPlayerInteractionCausesTargetExpire_WhenInvoke_ThenPlayer overworld.AddRegion(region); var player = new PlayableCharacter(Identifier.Empty, Description.Empty, interaction: (i) => { - return new Interaction(InteractionResult.TargetExpired, i); + return new Interaction(InteractionResult.TargetExpires, i); }); var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); var command = new UseOn(item, player); @@ -158,7 +158,7 @@ public void GivenItemOnPlayerInteractionCausesItemAndTargetExpire_WhenInvoke_The overworld.AddRegion(region); var player = new PlayableCharacter(Identifier.Empty, Description.Empty, interaction: (i) => { - return new Interaction(InteractionResult.ItemAndTargetExpired, i); + return new Interaction(InteractionResult.ItemAndTargetExpires, i); }); var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); var command = new UseOn(item, player); @@ -182,7 +182,7 @@ public void GivenItemOnPlayerInteractionCausesItemExpire_WhenInvoke_ThenPlayerDo overworld.AddRegion(region); var player = new PlayableCharacter(Identifier.Empty, Description.Empty, items: [item], interaction: (i) => { - return new Interaction(InteractionResult.ItemExpired, i); + return new Interaction(InteractionResult.ItemExpires, i); }); var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); var command = new UseOn(item, player); @@ -199,7 +199,7 @@ public void GivenItemOnNonPlayableCharacterInteractionCausesItemExpire_WhenInvok var item = new Item(Identifier.Empty, Description.Empty, true); var npc = new NonPlayableCharacter(Identifier.Empty, Description.Empty, interaction: (i) => { - return new Interaction(InteractionResult.ItemExpired, i); + return new Interaction(InteractionResult.ItemExpires, i); }); npc.AddItem(item); var room = new Room(Identifier.Empty, Description.Empty); @@ -217,5 +217,30 @@ public void GivenItemOnNonPlayableCharacterInteractionCausesItemExpire_WhenInvok Assert.IsFalse(result); } + + [TestMethod] + public void GivenItemOnNonPlayableCharacterInteractionCausesPlayerDies_WhenInvoke_ThenPlayerIsNotAlive() + { + var item = new Item(Identifier.Empty, Description.Empty, true); + var npc = new NonPlayableCharacter(Identifier.Empty, Description.Empty, interaction: (i) => + { + return new Interaction(InteractionResult.PlayerDies, i); + }); + npc.AddItem(item); + var room = new Room(Identifier.Empty, Description.Empty); + room.AddCharacter(npc); + var region = new Region(string.Empty, string.Empty); + region.AddRoom(room, 0, 0, 0); + var overworld = new Overworld(string.Empty, string.Empty); + overworld.AddRegion(region); + var player = new PlayableCharacter(Identifier.Empty, Description.Empty); + var game = Game.Create(new GameInfo(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworld, player), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var command = new UseOn(item, npc); + command.Invoke(game); + + var result = player.IsAlive; + + Assert.IsFalse(result); + } } } diff --git a/NetAF/Assets/Characters/NonPlayableCharacter.cs b/NetAF/Assets/Characters/NonPlayableCharacter.cs index af8971ee..fde88785 100644 --- a/NetAF/Assets/Characters/NonPlayableCharacter.cs +++ b/NetAF/Assets/Characters/NonPlayableCharacter.cs @@ -40,7 +40,7 @@ public NonPlayableCharacter(Identifier identifier, Description description, Conv Description = description; Conversation = conversation; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NoChange, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Characters/PlayableCharacter.cs b/NetAF/Assets/Characters/PlayableCharacter.cs index cd028611..1e0b441d 100644 --- a/NetAF/Assets/Characters/PlayableCharacter.cs +++ b/NetAF/Assets/Characters/PlayableCharacter.cs @@ -75,7 +75,7 @@ public PlayableCharacter(Identifier identifier, Description description, bool ca CanConverse = canConverse; Items = items ?? []; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NoChange, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Interaction.cs b/NetAF/Assets/Interaction.cs index e51e3b68..79374db0 100644 --- a/NetAF/Assets/Interaction.cs +++ b/NetAF/Assets/Interaction.cs @@ -35,10 +35,11 @@ public Interaction(InteractionResult result, Item item) Description = result switch { - InteractionResult.NeitherItemOrTargetExpired => "There was no effect.", - InteractionResult.ItemExpired => "The item expired.", - InteractionResult.TargetExpired => "The target expired.", - InteractionResult.ItemAndTargetExpired => "Both the item and target expired.", + InteractionResult.NoChange => "There was no effect.", + InteractionResult.ItemExpires => "The item expires.", + InteractionResult.TargetExpires => "The target expires.", + InteractionResult.ItemAndTargetExpires => "Both the item and target expires.", + InteractionResult.PlayerDies => "The player dies.", _ => throw new NotImplementedException($"No implementation for ${result}."), }; } diff --git a/NetAF/Assets/InteractionResult.cs b/NetAF/Assets/InteractionResult.cs index 87f94d1e..25c38f7f 100644 --- a/NetAF/Assets/InteractionResult.cs +++ b/NetAF/Assets/InteractionResult.cs @@ -6,20 +6,24 @@ public enum InteractionResult { /// - /// Neither the item or the target expired. + /// No change. /// - NeitherItemOrTargetExpired = 0, + NoChange = 0, /// - /// The item expired. + /// The item expires. /// - ItemExpired, + ItemExpires, /// - /// The target expired. + /// The target expires. /// - TargetExpired, + TargetExpires, /// - /// The item and the target expired. + /// The item and the target expires. /// - ItemAndTargetExpired + ItemAndTargetExpires, + /// + /// The player dies. + /// + PlayerDies } } \ No newline at end of file diff --git a/NetAF/Assets/Item.cs b/NetAF/Assets/Item.cs index f5fa55d5..99d41934 100644 --- a/NetAF/Assets/Item.cs +++ b/NetAF/Assets/Item.cs @@ -53,7 +53,7 @@ public Item(Identifier identifier, Description description, bool isTakeable = fa Description = description; IsTakeable = isTakeable; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NoChange, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Locations/Exit.cs b/NetAF/Assets/Locations/Exit.cs index 97a7ae21..f47c1964 100644 --- a/NetAF/Assets/Locations/Exit.cs +++ b/NetAF/Assets/Locations/Exit.cs @@ -47,7 +47,7 @@ public Exit(Direction direction, bool isLocked = false, Identifier identifier = Description = description ?? GenerateDescription(); IsLocked = isLocked; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NoChange, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Locations/Room.cs b/NetAF/Assets/Locations/Room.cs index 3959b1de..3a0da8ed 100644 --- a/NetAF/Assets/Locations/Room.cs +++ b/NetAF/Assets/Locations/Room.cs @@ -89,7 +89,7 @@ public Room(Identifier identifier, Description description, Exit[] exits = null, Exits = exits ?? []; Items = items ?? []; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NoChange, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Commands/Scene/UseOn.cs b/NetAF/Commands/Scene/UseOn.cs index 8e9ce4f3..4af74898 100644 --- a/NetAF/Commands/Scene/UseOn.cs +++ b/NetAF/Commands/Scene/UseOn.cs @@ -36,7 +36,7 @@ public sealed class UseOn(Item item, IInteractWithItem target) : ICommand /// The game. /// The item that expired. /// The target that the item was used on. - private static void ItemExpired(Game game, Item item, IInteractWithItem target) + private static void ItemExpires(Game game, Item item, IInteractWithItem target) { List containers = []; @@ -56,7 +56,7 @@ private static void ItemExpired(Game game, Item item, IInteractWithItem target) /// /// The game. /// The target that expired. - private static void TargetExpired(Game game, IInteractWithItem target) + private static void TargetExpires(Game game, IInteractWithItem target) { if (target is IExaminable examinable && game.Overworld.CurrentRegion.CurrentRoom.ContainsInteractionTarget(examinable.Identifier.Name)) game.Overworld.CurrentRegion.CurrentRoom.RemoveInteractionTarget(target); @@ -101,17 +101,20 @@ public Reaction Invoke(Logic.Game game) switch (interaction.Result) { - case InteractionResult.NeitherItemOrTargetExpired: + case InteractionResult.NoChange: break; - case InteractionResult.ItemExpired: - ItemExpired(game, item, target); + case InteractionResult.ItemExpires: + ItemExpires(game, item, target); break; - case InteractionResult.TargetExpired: - TargetExpired(game, target); + case InteractionResult.TargetExpires: + TargetExpires(game, target); break; - case InteractionResult.ItemAndTargetExpired: - ItemExpired(game, item, target); - TargetExpired(game, target); + case InteractionResult.ItemAndTargetExpires: + ItemExpires(game, item, target); + TargetExpires(game, target); + break; + case InteractionResult.PlayerDies: + game.Player.Kill(); break; default: throw new NotImplementedException(); diff --git a/docs/docfx/docs/items.md b/docs/docfx/docs/items.md index 0674c0a9..82bd9337 100644 --- a/docs/docfx/docs/items.md +++ b/docs/docfx/docs/items.md @@ -41,8 +41,8 @@ var dartsBoard = new Item("Darts board", "A darts board."); var dart = new Item("Dart", "A dart", interaction: item => { if (item == dartsBoard) - return new Interaction(InteractionResult.NeitherItemOrTargetExpired, item, "The dart stuck in the darts board."); + return new Interaction(InteractionResult.NoChange, item, "The dart stuck in the darts board."); - return new Interaction(InteractionResult.NeitherItemOrTargetExpired, item); + return new Interaction(InteractionResult.NoChange, item); }); ``` \ No newline at end of file