From 3b26a6415bee6f74df8a437d2ae6a20c657f69be Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 09:23:01 +0000 Subject: [PATCH 1/8] Simplified game logic --- NetAF.Tests/Commands/Global/End_Tests.cs | 4 +- NetAF.Tests/Commands/Scene/Move_Tests.cs | 4 +- NetAF.Tests/Logic/Modes/AboutMode_Tests.cs | 21 +++--- .../Logic/Modes/CompletionMode_Tests.cs | 21 +++--- .../Logic/Modes/ConversationMode_Tests.cs | 21 +++--- NetAF.Tests/Logic/Modes/GameOverMode_Tests.cs | 21 +++--- NetAF.Tests/Logic/Modes/HelpMode_Tests.cs | 21 +++--- NetAF.Tests/Logic/Modes/ReactionMode_Tests.cs | 70 ++++--------------- .../Logic/Modes/RegionMapMode_Tests.cs | 21 +++--- NetAF.Tests/Logic/Modes/SceneMode_Tests.cs | 21 +++--- NetAF.Tests/Logic/Modes/TitleMode_Tests.cs | 21 +++--- NetAF/Commands/Global/End.cs | 11 +-- NetAF/Commands/RegionMap/Pan.cs | 11 +-- NetAF/Commands/Scene/Move.cs | 11 +-- NetAF/Logic/Game.cs | 58 ++++----------- NetAF/Logic/Modes/AboutMode.cs | 4 +- NetAF/Logic/Modes/CompletionMode.cs | 4 +- NetAF/Logic/Modes/ConversationMode.cs | 4 +- NetAF/Logic/Modes/GameOverMode.cs | 4 +- NetAF/Logic/Modes/HelpMode.cs | 4 +- NetAF/Logic/Modes/IGameMode.cs | 3 +- NetAF/Logic/Modes/ReactionMode.cs | 37 +--------- NetAF/Logic/Modes/RegionMapMode.cs | 4 +- NetAF/Logic/Modes/RenderState.cs | 17 ----- NetAF/Logic/Modes/SceneMode.cs | 4 +- NetAF/Logic/Modes/TitleMode.cs | 4 +- 26 files changed, 130 insertions(+), 296 deletions(-) delete mode 100644 NetAF/Logic/Modes/RenderState.cs diff --git a/NetAF.Tests/Commands/Global/End_Tests.cs b/NetAF.Tests/Commands/Global/End_Tests.cs index 715221bd..e91294a0 100644 --- a/NetAF.Tests/Commands/Global/End_Tests.cs +++ b/NetAF.Tests/Commands/Global/End_Tests.cs @@ -22,7 +22,7 @@ public void GivenNullGame_WhenInvoke_ThenError() } [TestMethod] - public void GivenValidGame_WhenInvoke_ThenInform() + public void GivenValidGame_WhenInvoke_ThenSilent() { RegionMaker regionMaker = new(string.Empty, string.Empty); Room room = new(string.Empty, string.Empty); @@ -33,7 +33,7 @@ public void GivenValidGame_WhenInvoke_ThenInform() var result = command.Invoke(game); - Assert.AreEqual(ReactionResult.Inform, result.Result); + Assert.AreEqual(ReactionResult.Silent, result.Result); } } } diff --git a/NetAF.Tests/Commands/Scene/Move_Tests.cs b/NetAF.Tests/Commands/Scene/Move_Tests.cs index e289b0fc..97b78d1b 100644 --- a/NetAF.Tests/Commands/Scene/Move_Tests.cs +++ b/NetAF.Tests/Commands/Scene/Move_Tests.cs @@ -27,7 +27,7 @@ public void GivenCantMove_WhenInvoke_ThenError() } [TestMethod] - public void GivenCanMove_WhenInvoke_ThenInform() + public void GivenCanMove_WhenInvoke_ThenSilent() { var region = new Region(Identifier.Empty, Description.Empty); region.AddRoom(new Room(Identifier.Empty, Description.Empty, [new Exit(Direction.North)]), 0, 0, 0); @@ -39,7 +39,7 @@ public void GivenCanMove_WhenInvoke_ThenInform() var result = command.Invoke(game); - Assert.AreEqual(ReactionResult.Inform, result.Result); + Assert.AreEqual(ReactionResult.Silent, result.Result); } } } diff --git a/NetAF.Tests/Logic/Modes/AboutMode_Tests.cs b/NetAF.Tests/Logic/Modes/AboutMode_Tests.cs index 3d6a77ad..9b928db1 100644 --- a/NetAF.Tests/Logic/Modes/AboutMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/AboutMode_Tests.cs @@ -11,18 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class AboutMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new AboutMode(); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new AboutMode(); - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } } } diff --git a/NetAF.Tests/Logic/Modes/CompletionMode_Tests.cs b/NetAF.Tests/Logic/Modes/CompletionMode_Tests.cs index 4262bcee..cb956971 100644 --- a/NetAF.Tests/Logic/Modes/CompletionMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/CompletionMode_Tests.cs @@ -11,18 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class CompletionMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new CompletionMode(string.Empty, string.Empty); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new CompletionMode(string.Empty, string.Empty); - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } } } diff --git a/NetAF.Tests/Logic/Modes/ConversationMode_Tests.cs b/NetAF.Tests/Logic/Modes/ConversationMode_Tests.cs index 9073d4db..313270ee 100644 --- a/NetAF.Tests/Logic/Modes/ConversationMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/ConversationMode_Tests.cs @@ -11,18 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class ConversationMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new ConversationMode(new NonPlayableCharacter(string.Empty, string.Empty)); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new ConversationMode(new NonPlayableCharacter(string.Empty, string.Empty)); - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } } } diff --git a/NetAF.Tests/Logic/Modes/GameOverMode_Tests.cs b/NetAF.Tests/Logic/Modes/GameOverMode_Tests.cs index bcddcab5..9218870e 100644 --- a/NetAF.Tests/Logic/Modes/GameOverMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/GameOverMode_Tests.cs @@ -11,18 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class GameOverMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new GameOverMode(string.Empty, string.Empty); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new GameOverMode(string.Empty, string.Empty); - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } } } diff --git a/NetAF.Tests/Logic/Modes/HelpMode_Tests.cs b/NetAF.Tests/Logic/Modes/HelpMode_Tests.cs index 785d54fd..add422e8 100644 --- a/NetAF.Tests/Logic/Modes/HelpMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/HelpMode_Tests.cs @@ -11,18 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class HelpMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new HelpMode([]); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new HelpMode([]); - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } } } diff --git a/NetAF.Tests/Logic/Modes/ReactionMode_Tests.cs b/NetAF.Tests/Logic/Modes/ReactionMode_Tests.cs index 11b07efe..7bc97fbb 100644 --- a/NetAF.Tests/Logic/Modes/ReactionMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/ReactionMode_Tests.cs @@ -4,8 +4,6 @@ using NetAF.Assets.Locations; using NetAF.Utilities; using NetAF.Logic.Modes; -using NetAF.Commands.Scene; -using NetAF.Commands.Global; namespace NetAF.Tests.Logic.Modes { @@ -13,63 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class ReactionMode_Tests { [TestMethod] - public void GivenNew_WhenRenderWithEmptyString_ThenReturnAborted() + public void GivenNew_WhenRenderWithNonEmptyString_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new ReactionMode(string.Empty, string.Empty); - - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Aborted, result); - } - - [TestMethod] - public void GivenNew_WhenRenderWithSuccessfulMove_ThenReturnAborted() - { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new ReactionMode(string.Empty, Move.SuccessfulMove); - - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Aborted, result); - } - - [TestMethod] - public void GivenNew_WhenRenderWithSuccessfulEnd_ThenReturnAborted() - { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new ReactionMode(string.Empty, End.SuccessfulEnd); - - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Aborted, result); - } - - [TestMethod] - public void GivenNew_WhenRenderWithNonEmptyString_ThenReturnCompleted() - { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new ReactionMode(string.Empty, "a"); - - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new ReactionMode(string.Empty, "a"); + + mode.Render(game); + }); } } } diff --git a/NetAF.Tests/Logic/Modes/RegionMapMode_Tests.cs b/NetAF.Tests/Logic/Modes/RegionMapMode_Tests.cs index e2e7f80f..6ee86fd3 100644 --- a/NetAF.Tests/Logic/Modes/RegionMapMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/RegionMapMode_Tests.cs @@ -12,18 +12,19 @@ namespace NetAF.Tests.Logic.Modes public class RegionMapMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new RegionMapMode(RegionMapMode.Player); - - var result = mode.Render(game); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new RegionMapMode(RegionMapMode.Player); - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } [TestMethod] diff --git a/NetAF.Tests/Logic/Modes/SceneMode_Tests.cs b/NetAF.Tests/Logic/Modes/SceneMode_Tests.cs index 1f092421..9ddbbc2e 100644 --- a/NetAF.Tests/Logic/Modes/SceneMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/SceneMode_Tests.cs @@ -11,18 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class SceneMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new SceneMode(); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new SceneMode(); - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } } } diff --git a/NetAF.Tests/Logic/Modes/TitleMode_Tests.cs b/NetAF.Tests/Logic/Modes/TitleMode_Tests.cs index f3716d6f..9076a877 100644 --- a/NetAF.Tests/Logic/Modes/TitleMode_Tests.cs +++ b/NetAF.Tests/Logic/Modes/TitleMode_Tests.cs @@ -11,18 +11,19 @@ namespace NetAF.Tests.Logic.Modes public class TitleMode_Tests { [TestMethod] - public void GivenNew_WhenRender_ThenReturnCompleted() + public void GivenNew_WhenRender_ThenNoExceptionThrown() { - RegionMaker regionMaker = new(string.Empty, string.Empty); - Room room = new(string.Empty, string.Empty); - regionMaker[0, 0, 0] = room; - OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); - var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); - var mode = new TitleMode(); + Assertions.NoExceptionThrown(() => + { + RegionMaker regionMaker = new(string.Empty, string.Empty); + Room room = new(string.Empty, string.Empty); + regionMaker[0, 0, 0] = room; + OverworldMaker overworldMaker = new(string.Empty, string.Empty, regionMaker); + var game = Game.Create(new(string.Empty, string.Empty, string.Empty), string.Empty, AssetGenerator.Retained(overworldMaker.Make(), new PlayableCharacter(string.Empty, string.Empty)), GameEndConditions.NoEnd, TestGameConfiguration.Default).Invoke(); + var mode = new TitleMode(); - var result = mode.Render(game); - - Assert.AreEqual(RenderState.Completed, result); + mode.Render(game); + }); } } } diff --git a/NetAF/Commands/Global/End.cs b/NetAF/Commands/Global/End.cs index b9a93552..7f8a8b66 100644 --- a/NetAF/Commands/Global/End.cs +++ b/NetAF/Commands/Global/End.cs @@ -8,15 +8,6 @@ namespace NetAF.Commands.Global /// public sealed class End : ICommand { - #region Constants - - /// - /// Get the string for successful ended. - /// - public const string SuccessfulEnd = "Ended."; - - #endregion - #region StaticProperties /// @@ -39,7 +30,7 @@ public Reaction Invoke(Logic.Game game) return new(ReactionResult.Error, "No game specified."); game.ChangeMode(new SceneMode()); - return new(ReactionResult.Inform, SuccessfulEnd); + return new(ReactionResult.Silent, "Ended."); } #endregion diff --git a/NetAF/Commands/RegionMap/Pan.cs b/NetAF/Commands/RegionMap/Pan.cs index eee6d675..bf73d845 100644 --- a/NetAF/Commands/RegionMap/Pan.cs +++ b/NetAF/Commands/RegionMap/Pan.cs @@ -11,15 +11,6 @@ namespace NetAF.Commands.RegionMap /// The direction to pan. public sealed class Pan(Direction direction) : ICommand { - #region Constants - - /// - /// Get the string for successful pan. - /// - public const string SuccessfulPan = "Panned."; - - #endregion - #region StaticProperties /// @@ -104,7 +95,7 @@ public Reaction Invoke(Logic.Game game) if (RegionMapMode.CanPanToPosition(game.Overworld.CurrentRegion, newPosition)) { regionMapMode.FocusPosition = newPosition; - return new(ReactionResult.Silent, SuccessfulPan); + return new(ReactionResult.Silent, $"Panned {direction}."); } else { diff --git a/NetAF/Commands/Scene/Move.cs b/NetAF/Commands/Scene/Move.cs index 4c92cf1a..8eedc348 100644 --- a/NetAF/Commands/Scene/Move.cs +++ b/NetAF/Commands/Scene/Move.cs @@ -9,15 +9,6 @@ namespace NetAF.Commands.Scene /// The direction to move. public sealed class Move(Direction direction) : ICommand { - #region Constants - - /// - /// Get the string for successful moves. - /// - public const string SuccessfulMove = "Moved."; - - #endregion - #region StaticProperties /// @@ -65,7 +56,7 @@ public Reaction Invoke(Logic.Game game) return new(ReactionResult.Error, "No game specified."); if (game.Overworld.CurrentRegion.Move(direction)) - return new(ReactionResult.Inform, SuccessfulMove); + return new(ReactionResult.Silent, $"Moved {direction}."); return new(ReactionResult.Error, $"Could not move {direction}."); } diff --git a/NetAF/Logic/Game.cs b/NetAF/Logic/Game.cs index 1a45fc09..ee3adb82 100644 --- a/NetAF/Logic/Game.cs +++ b/NetAF/Logic/Game.cs @@ -25,16 +25,12 @@ public sealed class Game : IRestoreFromObjectSerialization #region Fields private readonly List inactivePlayerLocations = []; + private GameState state; #endregion #region Properties - /// - /// Get or set the current state. - /// - private GameState State { get; set; } - /// /// Get the player. /// @@ -127,15 +123,15 @@ public PlayableCharacterLocation[] GetInactivePlayerLocations() internal void Execute() { // if the game is in an active state don't re-execute - switch (State) + switch (state) { case GameState.Active: case GameState.Finishing: return; } - // enter the game - Enter(); + // game is active + state = GameState.Active; // setup the adapter for this game Configuration.Adapter.Setup(this); @@ -149,7 +145,7 @@ internal void Execute() do { // always render the current mode - RenderCurrentMode(); + Mode.Render(this); // get the input var input = GetInput(); @@ -173,10 +169,10 @@ internal void Execute() if (CheckForGameEnd(EndConditions, out endMode)) End(); } - while (State != GameState.Finishing); + while (state != GameState.Finishing); // render the last mode - RenderCurrentMode(); + Mode.Render(this); // wait for acknowledge GetInput(); @@ -186,33 +182,14 @@ internal void Execute() { // set and render the end mode ChangeMode(endMode); - RenderCurrentMode(); + Mode.Render(this); // wait for acknowledge GetInput(); } // finished execution - State = GameState.Finished; - } - - /// - /// Render the current mode. - /// - private void RenderCurrentMode() - { - // perform the render - var result = Mode.Render(this); - - // if this was aborted by the mode - if (result == RenderState.Aborted) - { - // revert back to scene mode - ChangeMode(new SceneMode()); - - // render - Mode.Render(this); - } + state = GameState.Finished; } /// @@ -286,9 +263,8 @@ private string GetInput() // wait for acknowledge while (!Configuration.Adapter.WaitForAcknowledge()) { - // something other was entered, render again unless that was aborted - if (Mode.Render(this) != RenderState.Aborted) - break; + // something other was entered, render again + Mode.Render(this); } // acknowledge complete @@ -367,20 +343,12 @@ private void DisplayReaction(Reaction reaction) } } - /// - /// Enter the game. - /// - private void Enter() - { - State = GameState.Active; - } - /// /// End the game. /// - internal void End() + public void End() { - State = GameState.Finishing; + state = GameState.Finishing; } /// diff --git a/NetAF/Logic/Modes/AboutMode.cs b/NetAF/Logic/Modes/AboutMode.cs index a6b60937..500a1b22 100644 --- a/NetAF/Logic/Modes/AboutMode.cs +++ b/NetAF/Logic/Modes/AboutMode.cs @@ -23,12 +23,10 @@ public sealed class AboutMode : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { var frame = game.Configuration.FrameBuilders.AboutFrameBuilder.Build("About", game, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/CompletionMode.cs b/NetAF/Logic/Modes/CompletionMode.cs index 944aa4af..1781c2eb 100644 --- a/NetAF/Logic/Modes/CompletionMode.cs +++ b/NetAF/Logic/Modes/CompletionMode.cs @@ -25,12 +25,10 @@ public sealed class CompletionMode(string title, string message) : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { var frame = game.Configuration.FrameBuilders.CompletionFrameBuilder.Build(title, message, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/ConversationMode.cs b/NetAF/Logic/Modes/ConversationMode.cs index badf2ea7..c1385718 100644 --- a/NetAF/Logic/Modes/ConversationMode.cs +++ b/NetAF/Logic/Modes/ConversationMode.cs @@ -46,12 +46,10 @@ public ConversationMode(IConverser converser) /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { var frame = game.Configuration.FrameBuilders.ConversationFrameBuilder.Build($"Conversation with {Converser.Identifier.Name}", Converser, Interpreter.GetContextualCommandHelp(game), game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/GameOverMode.cs b/NetAF/Logic/Modes/GameOverMode.cs index f2362d30..60c7c71b 100644 --- a/NetAF/Logic/Modes/GameOverMode.cs +++ b/NetAF/Logic/Modes/GameOverMode.cs @@ -25,12 +25,10 @@ public sealed class GameOverMode(string title, string message) : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { var frame = game.Configuration.FrameBuilders.GameOverFrameBuilder.Build(title, message, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/HelpMode.cs b/NetAF/Logic/Modes/HelpMode.cs index 3e5c7b84..a58f851e 100644 --- a/NetAF/Logic/Modes/HelpMode.cs +++ b/NetAF/Logic/Modes/HelpMode.cs @@ -25,12 +25,10 @@ public sealed class HelpMode(CommandHelp[] commands) : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { var frame = game.Configuration.FrameBuilders.HelpFrameBuilder.Build("Help", string.Empty, commands, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/IGameMode.cs b/NetAF/Logic/Modes/IGameMode.cs index 20b49e85..0bbd7e6c 100644 --- a/NetAF/Logic/Modes/IGameMode.cs +++ b/NetAF/Logic/Modes/IGameMode.cs @@ -19,7 +19,6 @@ public interface IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - RenderState Render(Game game); + void Render(Game game); } } diff --git a/NetAF/Logic/Modes/ReactionMode.cs b/NetAF/Logic/Modes/ReactionMode.cs index ddf89ea7..6ab02638 100644 --- a/NetAF/Logic/Modes/ReactionMode.cs +++ b/NetAF/Logic/Modes/ReactionMode.cs @@ -12,30 +12,6 @@ namespace NetAF.Logic.Modes /// The message. public sealed class ReactionMode(string title, string message) : IGameMode { - #region Properties - - /// - /// Get or set if successful movement reactions are suppressed. - /// - public bool SuppressSuccessfulMovementReactions { get; set; } = true; - - /// - /// Get or set if ended reactions are suppressed. - /// - public bool SuppressEndedReactions { get; set; } = true; - - /// - /// Get if a reaction is a successful movement reaction. - /// - private bool IsSuccessfulMovementReaction => message.InsensitiveEquals(Move.SuccessfulMove); - - /// - /// Get if a reaction is a ended reaction. - /// - private bool IsEndedReaction => message.InsensitiveEquals(End.SuccessfulEnd); - - #endregion - #region Implementation of IGameMode /// @@ -52,21 +28,10 @@ public sealed class ReactionMode(string title, string message) : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { - if (SuppressSuccessfulMovementReactions && IsSuccessfulMovementReaction) - return RenderState.Aborted; - - if (SuppressEndedReactions && IsEndedReaction) - return RenderState.Aborted; - - if (string.IsNullOrEmpty(message)) - return RenderState.Aborted; - var frame = game.Configuration.FrameBuilders.ReactionModeFrameBuilder.Build(title, message, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/RegionMapMode.cs b/NetAF/Logic/Modes/RegionMapMode.cs index 84fc8abc..f2d377e2 100644 --- a/NetAF/Logic/Modes/RegionMapMode.cs +++ b/NetAF/Logic/Modes/RegionMapMode.cs @@ -44,8 +44,7 @@ public sealed class RegionMapMode(Point3D focusPosition) : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { // if focusing on the player, find their location if (FocusPosition.Equals(Player)) @@ -53,7 +52,6 @@ public RenderState Render(Game game) var frame = game.Configuration.FrameBuilders.RegionMapFrameBuilder.Build(game.Overworld.CurrentRegion, FocusPosition, Interpreter?.GetContextualCommandHelp(game) ?? [], game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/RenderState.cs b/NetAF/Logic/Modes/RenderState.cs deleted file mode 100644 index 26a02d89..00000000 --- a/NetAF/Logic/Modes/RenderState.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace NetAF.Logic.Modes -{ - /// - /// An enumeration of render states. - /// - public enum RenderState - { - /// - /// Render was aborted. - /// - Aborted, - /// - /// Render was completed. - /// - Completed - } -} diff --git a/NetAF/Logic/Modes/SceneMode.cs b/NetAF/Logic/Modes/SceneMode.cs index af52953b..d52a952c 100644 --- a/NetAF/Logic/Modes/SceneMode.cs +++ b/NetAF/Logic/Modes/SceneMode.cs @@ -26,8 +26,7 @@ public sealed class SceneMode : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { List commands = []; commands.AddRange(Interpreter.GetContextualCommandHelp(game)); @@ -35,7 +34,6 @@ public RenderState Render(Game game) var frame = game.Configuration.FrameBuilders.SceneFrameBuilder.Build(game.Overworld.CurrentRegion.CurrentRoom, ViewPoint.Create(game.Overworld.CurrentRegion), game.Player, game.Configuration.DisplayCommandListInSceneFrames ? [.. commands] : null, game.Configuration.SceneMapKeyType, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion diff --git a/NetAF/Logic/Modes/TitleMode.cs b/NetAF/Logic/Modes/TitleMode.cs index e9d7dc9a..f4f4a130 100644 --- a/NetAF/Logic/Modes/TitleMode.cs +++ b/NetAF/Logic/Modes/TitleMode.cs @@ -23,12 +23,10 @@ public sealed class TitleMode : IGameMode /// Render the current state of a game. /// /// The game. - /// The render state. - public RenderState Render(Game game) + public void Render(Game game) { var frame = game.Configuration.FrameBuilders.TitleFrameBuilder.Build(game.Info.Name, game.Introduction, game.Configuration.DisplaySize); game.Configuration.Adapter.RenderFrame(frame); - return RenderState.Completed; } #endregion From 76b1e3ba5cb26671147b105c9f6f0d4643aa286d Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 09:24:42 +0000 Subject: [PATCH 2/8] Moved reaction --- NetAF.Examples/Program.cs | 1 - NetAF.Tests/Assets/ExaminableObject_Tests.cs | 1 - NetAF.Tests/Commands/Conversation/Next_Tests.cs | 2 +- NetAF.Tests/Commands/Conversation/Respond_Tests.cs | 2 +- NetAF.Tests/Commands/Frame/CommandsOff_Tests.cs | 4 ++-- NetAF.Tests/Commands/Frame/CommandsOn_Tests.cs | 4 ++-- NetAF.Tests/Commands/Frame/KeyOff_Tests.cs | 4 ++-- NetAF.Tests/Commands/Frame/KeyOn_Tests.cs | 4 ++-- NetAF.Tests/Commands/Global/About_Tests.cs | 2 +- NetAF.Tests/Commands/Global/End_Tests.cs | 4 ++-- NetAF.Tests/Commands/Global/Exit_Tests.cs | 4 ++-- NetAF.Tests/Commands/Global/Help_Tests.cs | 2 +- NetAF.Tests/Commands/Global/Map_Tests.cs | 2 +- NetAF.Tests/Commands/Global/New_Tests.cs | 4 ++-- NetAF.Tests/Commands/Persistence/Load_Tests.cs | 4 ++-- NetAF.Tests/Commands/Persistence/Save_Tests.cs | 4 ++-- NetAF.Tests/Commands/RegionMap/PanReset_Tests.cs | 4 ++-- NetAF.Tests/Commands/RegionMap/Pan_Tests.cs | 4 ++-- NetAF.Tests/Commands/Scene/Drop_Tests.cs | 2 +- NetAF.Tests/Commands/Scene/Examine_Tests.cs | 2 +- NetAF.Tests/Commands/Scene/Move_Tests.cs | 2 +- NetAF.Tests/Commands/Scene/TakeAll_Tests.cs | 2 +- NetAF.Tests/Commands/Scene/Take_Tests.cs | 2 +- NetAF.Tests/Commands/Scene/Talk_Tests.cs | 2 +- NetAF.Tests/Commands/Scene/Unactionable_Tests.cs | 4 ++-- NetAF.Tests/Commands/Scene/UseOn_Tests.cs | 2 +- NetAF.Tests/Conversations/Conversation_Tests.cs | 2 +- NetAF.Tests/Interpretation/CustomCommandInterpreter_Tests.cs | 1 - .../Serialization/Assets/CustomCommandSerialization_Tests.cs | 1 - .../Serialization/Assets/ExaminableSerialization_Tests.cs | 1 - NetAF/Assets/ExaminationResult.cs | 4 +--- NetAF/Assets/{Interaction => }/Result.cs | 2 +- NetAF/Commands/Conversation/Next.cs | 3 +-- NetAF/Commands/Conversation/Respond.cs | 3 +-- NetAF/Commands/CustomCommand.cs | 1 - NetAF/Commands/CustomCommandCallback.cs | 4 +--- NetAF/Commands/Frame/CommandsOff.cs | 4 +--- NetAF/Commands/Frame/CommandsOn.cs | 4 +--- NetAF/Commands/Frame/KeyOff.cs | 3 +-- NetAF/Commands/Frame/KeyOn.cs | 3 +-- NetAF/Commands/Global/About.cs | 3 +-- NetAF/Commands/Global/End.cs | 3 +-- NetAF/Commands/Global/Exit.cs | 4 +--- NetAF/Commands/Global/Help.cs | 3 +-- NetAF/Commands/Global/Map.cs | 3 +-- NetAF/Commands/Global/New.cs | 4 +--- NetAF/Commands/ICommand.cs | 4 +--- NetAF/Commands/Persistence/Load.cs | 3 +-- NetAF/Commands/Persistence/Save.cs | 3 +-- NetAF/{Assets/Interaction => Commands}/Reaction.cs | 2 +- NetAF/{Assets/Interaction => Commands}/ReactionResult.cs | 2 +- NetAF/Commands/RegionMap/Pan.cs | 1 - NetAF/Commands/RegionMap/PanReset.cs | 3 +-- NetAF/Commands/Scene/Drop.cs | 1 - NetAF/Commands/Scene/Examine.cs | 1 - NetAF/Commands/Scene/Move.cs | 3 +-- NetAF/Commands/Scene/Take.cs | 1 - NetAF/Commands/Scene/TakeAll.cs | 1 - NetAF/Commands/Scene/Talk.cs | 1 - NetAF/Commands/Scene/Unactionable.cs | 4 +--- NetAF/Conversations/Conversation.cs | 2 +- NetAF/Logic/Game.cs | 1 + 62 files changed, 62 insertions(+), 101 deletions(-) rename NetAF/Assets/{Interaction => }/Result.cs (93%) rename NetAF/{Assets/Interaction => Commands}/Reaction.cs (95%) rename NetAF/{Assets/Interaction => Commands}/ReactionResult.cs (93%) diff --git a/NetAF.Examples/Program.cs b/NetAF.Examples/Program.cs index c2372e29..85ee30ea 100644 --- a/NetAF.Examples/Program.cs +++ b/NetAF.Examples/Program.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Commands; using NetAF.Commands.Persistence; diff --git a/NetAF.Tests/Assets/ExaminableObject_Tests.cs b/NetAF.Tests/Assets/ExaminableObject_Tests.cs index a4fe901f..12e9cb2a 100644 --- a/NetAF.Tests/Assets/ExaminableObject_Tests.cs +++ b/NetAF.Tests/Assets/ExaminableObject_Tests.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Commands; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/NetAF.Tests/Commands/Conversation/Next_Tests.cs b/NetAF.Tests/Commands/Conversation/Next_Tests.cs index 01afd151..59a8624e 100644 --- a/NetAF.Tests/Commands/Conversation/Next_Tests.cs +++ b/NetAF.Tests/Commands/Conversation/Next_Tests.cs @@ -1,5 +1,4 @@ using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Commands.Conversation; using NetAF.Conversations; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -7,6 +6,7 @@ using NetAF.Logic.Modes; using NetAF.Assets.Locations; using NetAF.Utilities; +using NetAF.Commands; namespace NetAF.Tests.Commands.Conversation { diff --git a/NetAF.Tests/Commands/Conversation/Respond_Tests.cs b/NetAF.Tests/Commands/Conversation/Respond_Tests.cs index 644ea5c3..57bf3788 100644 --- a/NetAF.Tests/Commands/Conversation/Respond_Tests.cs +++ b/NetAF.Tests/Commands/Conversation/Respond_Tests.cs @@ -1,5 +1,4 @@ using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Commands.Conversation; using NetAF.Conversations; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -7,6 +6,7 @@ using NetAF.Logic.Modes; using NetAF.Assets.Locations; using NetAF.Utilities; +using NetAF.Commands; namespace NetAF.Tests.Commands.Conversation { diff --git a/NetAF.Tests/Commands/Frame/CommandsOff_Tests.cs b/NetAF.Tests/Commands/Frame/CommandsOff_Tests.cs index becd4de2..5fc2028b 100644 --- a/NetAF.Tests/Commands/Frame/CommandsOff_Tests.cs +++ b/NetAF.Tests/Commands/Frame/CommandsOff_Tests.cs @@ -1,7 +1,7 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands.Frame; +using NetAF.Commands.Frame; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Frame { diff --git a/NetAF.Tests/Commands/Frame/CommandsOn_Tests.cs b/NetAF.Tests/Commands/Frame/CommandsOn_Tests.cs index 79b4431d..5b2196b0 100644 --- a/NetAF.Tests/Commands/Frame/CommandsOn_Tests.cs +++ b/NetAF.Tests/Commands/Frame/CommandsOn_Tests.cs @@ -1,7 +1,7 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands.Frame; +using NetAF.Commands.Frame; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Frame { diff --git a/NetAF.Tests/Commands/Frame/KeyOff_Tests.cs b/NetAF.Tests/Commands/Frame/KeyOff_Tests.cs index 641e235b..a25bca93 100644 --- a/NetAF.Tests/Commands/Frame/KeyOff_Tests.cs +++ b/NetAF.Tests/Commands/Frame/KeyOff_Tests.cs @@ -1,7 +1,7 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands.Frame; +using NetAF.Commands.Frame; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Frame { diff --git a/NetAF.Tests/Commands/Frame/KeyOn_Tests.cs b/NetAF.Tests/Commands/Frame/KeyOn_Tests.cs index d9416c43..5593880d 100644 --- a/NetAF.Tests/Commands/Frame/KeyOn_Tests.cs +++ b/NetAF.Tests/Commands/Frame/KeyOn_Tests.cs @@ -1,7 +1,7 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands.Frame; +using NetAF.Commands.Frame; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Frame { diff --git a/NetAF.Tests/Commands/Global/About_Tests.cs b/NetAF.Tests/Commands/Global/About_Tests.cs index d0d7b8b1..a7de5450 100644 --- a/NetAF.Tests/Commands/Global/About_Tests.cs +++ b/NetAF.Tests/Commands/Global/About_Tests.cs @@ -1,11 +1,11 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Commands.Global; using Microsoft.VisualStudio.TestTools.UnitTesting; using Exit = NetAF.Assets.Locations.Exit; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Global { diff --git a/NetAF.Tests/Commands/Global/End_Tests.cs b/NetAF.Tests/Commands/Global/End_Tests.cs index e91294a0..52dee0c1 100644 --- a/NetAF.Tests/Commands/Global/End_Tests.cs +++ b/NetAF.Tests/Commands/Global/End_Tests.cs @@ -1,10 +1,10 @@ -using NetAF.Assets.Interaction; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Global; using NetAF.Assets.Locations; using NetAF.Utilities; using NetAF.Assets.Characters; +using NetAF.Commands; namespace NetAF.Tests.Commands.Global { diff --git a/NetAF.Tests/Commands/Global/Exit_Tests.cs b/NetAF.Tests/Commands/Global/Exit_Tests.cs index 45bedb70..77f5930a 100644 --- a/NetAF.Tests/Commands/Global/Exit_Tests.cs +++ b/NetAF.Tests/Commands/Global/Exit_Tests.cs @@ -1,7 +1,7 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands.Global; +using NetAF.Commands.Global; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Global { diff --git a/NetAF.Tests/Commands/Global/Help_Tests.cs b/NetAF.Tests/Commands/Global/Help_Tests.cs index f7795759..363249e6 100644 --- a/NetAF.Tests/Commands/Global/Help_Tests.cs +++ b/NetAF.Tests/Commands/Global/Help_Tests.cs @@ -1,11 +1,11 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Commands.Global; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Logic.Modes; +using NetAF.Commands; namespace NetAF.Tests.Commands.Global { diff --git a/NetAF.Tests/Commands/Global/Map_Tests.cs b/NetAF.Tests/Commands/Global/Map_Tests.cs index 53917675..11642188 100644 --- a/NetAF.Tests/Commands/Global/Map_Tests.cs +++ b/NetAF.Tests/Commands/Global/Map_Tests.cs @@ -1,10 +1,10 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Commands.Global; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Global { diff --git a/NetAF.Tests/Commands/Global/New_Tests.cs b/NetAF.Tests/Commands/Global/New_Tests.cs index d8617f26..427f3d4a 100644 --- a/NetAF.Tests/Commands/Global/New_Tests.cs +++ b/NetAF.Tests/Commands/Global/New_Tests.cs @@ -1,7 +1,7 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands.Global; +using NetAF.Commands.Global; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; +using NetAF.Commands; namespace NetAF.Tests.Commands.Global { diff --git a/NetAF.Tests/Commands/Persistence/Load_Tests.cs b/NetAF.Tests/Commands/Persistence/Load_Tests.cs index 42bc4915..06fff802 100644 --- a/NetAF.Tests/Commands/Persistence/Load_Tests.cs +++ b/NetAF.Tests/Commands/Persistence/Load_Tests.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Assets.Characters; using NetAF.Assets.Locations; @@ -9,6 +8,7 @@ using NetAF.Commands.Persistence; using NetAF.Persistence; using NetAF.Persistence.Json; +using NetAF.Commands; namespace NetAF.Tests.Commands.Persistence { diff --git a/NetAF.Tests/Commands/Persistence/Save_Tests.cs b/NetAF.Tests/Commands/Persistence/Save_Tests.cs index a62dbf94..0c227d7c 100644 --- a/NetAF.Tests/Commands/Persistence/Save_Tests.cs +++ b/NetAF.Tests/Commands/Persistence/Save_Tests.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Assets.Characters; using NetAF.Assets.Locations; @@ -7,6 +6,7 @@ using NetAF.Utilities; using System.IO; using NetAF.Commands.Persistence; +using NetAF.Commands; namespace NetAF.Tests.Commands.Persistence { diff --git a/NetAF.Tests/Commands/RegionMap/PanReset_Tests.cs b/NetAF.Tests/Commands/RegionMap/PanReset_Tests.cs index 861f03ea..8416a9f0 100644 --- a/NetAF.Tests/Commands/RegionMap/PanReset_Tests.cs +++ b/NetAF.Tests/Commands/RegionMap/PanReset_Tests.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.RegionMap; using NetAF.Logic.Modes; @@ -7,6 +6,7 @@ using NetAF.Assets.Locations; using NetAF.Utilities; using NetAF.Assets; +using NetAF.Commands; namespace NetAF.Tests.Commands.RegionMap { diff --git a/NetAF.Tests/Commands/RegionMap/Pan_Tests.cs b/NetAF.Tests/Commands/RegionMap/Pan_Tests.cs index dcffddc1..a0795aff 100644 --- a/NetAF.Tests/Commands/RegionMap/Pan_Tests.cs +++ b/NetAF.Tests/Commands/RegionMap/Pan_Tests.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.RegionMap; using NetAF.Logic.Modes; @@ -7,6 +6,7 @@ using NetAF.Assets.Characters; using NetAF.Assets.Locations; using NetAF.Utilities; +using NetAF.Commands; namespace NetAF.Tests.Commands.RegionMap { diff --git a/NetAF.Tests/Commands/Scene/Drop_Tests.cs b/NetAF.Tests/Commands/Scene/Drop_Tests.cs index 1b297a2c..fc36d9da 100644 --- a/NetAF.Tests/Commands/Scene/Drop_Tests.cs +++ b/NetAF.Tests/Commands/Scene/Drop_Tests.cs @@ -1,10 +1,10 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Scene; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Commands/Scene/Examine_Tests.cs b/NetAF.Tests/Commands/Scene/Examine_Tests.cs index f8ef1005..56bc1fce 100644 --- a/NetAF.Tests/Commands/Scene/Examine_Tests.cs +++ b/NetAF.Tests/Commands/Scene/Examine_Tests.cs @@ -1,9 +1,9 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Scene; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Commands/Scene/Move_Tests.cs b/NetAF.Tests/Commands/Scene/Move_Tests.cs index 97b78d1b..649f77c0 100644 --- a/NetAF.Tests/Commands/Scene/Move_Tests.cs +++ b/NetAF.Tests/Commands/Scene/Move_Tests.cs @@ -1,9 +1,9 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Scene; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Commands/Scene/TakeAll_Tests.cs b/NetAF.Tests/Commands/Scene/TakeAll_Tests.cs index f264fe09..95a0614e 100644 --- a/NetAF.Tests/Commands/Scene/TakeAll_Tests.cs +++ b/NetAF.Tests/Commands/Scene/TakeAll_Tests.cs @@ -1,10 +1,10 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Scene; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Commands/Scene/Take_Tests.cs b/NetAF.Tests/Commands/Scene/Take_Tests.cs index e565eab6..41822eef 100644 --- a/NetAF.Tests/Commands/Scene/Take_Tests.cs +++ b/NetAF.Tests/Commands/Scene/Take_Tests.cs @@ -1,10 +1,10 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Scene; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Commands/Scene/Talk_Tests.cs b/NetAF.Tests/Commands/Scene/Talk_Tests.cs index 54d8c7fa..4d0a4f3f 100644 --- a/NetAF.Tests/Commands/Scene/Talk_Tests.cs +++ b/NetAF.Tests/Commands/Scene/Talk_Tests.cs @@ -1,11 +1,11 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Scene; using NetAF.Assets.Locations; using NetAF.Utilities; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Commands/Scene/Unactionable_Tests.cs b/NetAF.Tests/Commands/Scene/Unactionable_Tests.cs index 25ee9a70..e8b82732 100644 --- a/NetAF.Tests/Commands/Scene/Unactionable_Tests.cs +++ b/NetAF.Tests/Commands/Scene/Unactionable_Tests.cs @@ -1,6 +1,6 @@ -using NetAF.Assets.Interaction; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Commands.Scene; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs index 943ad30a..41644de5 100644 --- a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs +++ b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs @@ -1,11 +1,11 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Logic; using NetAF.Commands.Scene; +using NetAF.Commands; namespace NetAF.Tests.Commands.Scene { diff --git a/NetAF.Tests/Conversations/Conversation_Tests.cs b/NetAF.Tests/Conversations/Conversation_Tests.cs index 9eab8aef..5c7e06ed 100644 --- a/NetAF.Tests/Conversations/Conversation_Tests.cs +++ b/NetAF.Tests/Conversations/Conversation_Tests.cs @@ -1,5 +1,4 @@ using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Conversations; using NetAF.Conversations.Instructions; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -7,6 +6,7 @@ using NetAF.Logic.Modes; using NetAF.Assets.Locations; using NetAF.Utilities; +using NetAF.Commands; namespace NetAF.Tests.Conversations { diff --git a/NetAF.Tests/Interpretation/CustomCommandInterpreter_Tests.cs b/NetAF.Tests/Interpretation/CustomCommandInterpreter_Tests.cs index c4c4fdd2..d66e1938 100644 --- a/NetAF.Tests/Interpretation/CustomCommandInterpreter_Tests.cs +++ b/NetAF.Tests/Interpretation/CustomCommandInterpreter_Tests.cs @@ -1,6 +1,5 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Commands; using NetAF.Interpretation; diff --git a/NetAF.Tests/Serialization/Assets/CustomCommandSerialization_Tests.cs b/NetAF.Tests/Serialization/Assets/CustomCommandSerialization_Tests.cs index 7602a28f..eb362a73 100644 --- a/NetAF.Tests/Serialization/Assets/CustomCommandSerialization_Tests.cs +++ b/NetAF.Tests/Serialization/Assets/CustomCommandSerialization_Tests.cs @@ -1,5 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using NetAF.Assets.Interaction; using NetAF.Commands; using NetAF.Serialization; diff --git a/NetAF.Tests/Serialization/Assets/ExaminableSerialization_Tests.cs b/NetAF.Tests/Serialization/Assets/ExaminableSerialization_Tests.cs index e5233a79..36f86f05 100644 --- a/NetAF.Tests/Serialization/Assets/ExaminableSerialization_Tests.cs +++ b/NetAF.Tests/Serialization/Assets/ExaminableSerialization_Tests.cs @@ -1,7 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using NetAF.Assets; using NetAF.Assets.Attributes; -using NetAF.Assets.Interaction; using NetAF.Commands; using NetAF.Serialization.Assets; diff --git a/NetAF/Assets/ExaminationResult.cs b/NetAF/Assets/ExaminationResult.cs index 16a92465..03d6a074 100644 --- a/NetAF/Assets/ExaminationResult.cs +++ b/NetAF/Assets/ExaminationResult.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Assets +namespace NetAF.Assets { /// /// Represents the result of an examination. diff --git a/NetAF/Assets/Interaction/Result.cs b/NetAF/Assets/Result.cs similarity index 93% rename from NetAF/Assets/Interaction/Result.cs rename to NetAF/Assets/Result.cs index 34760a72..de5a1d3e 100644 --- a/NetAF/Assets/Interaction/Result.cs +++ b/NetAF/Assets/Result.cs @@ -1,4 +1,4 @@ -namespace NetAF.Assets.Interaction +namespace NetAF.Assets { /// /// Represents a result. diff --git a/NetAF/Commands/Conversation/Next.cs b/NetAF/Commands/Conversation/Next.cs index f66d61a3..32d57442 100644 --- a/NetAF/Commands/Conversation/Next.cs +++ b/NetAF/Commands/Conversation/Next.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Logic.Modes; +using NetAF.Logic.Modes; namespace NetAF.Commands.Conversation { diff --git a/NetAF/Commands/Conversation/Respond.cs b/NetAF/Commands/Conversation/Respond.cs index e6db14a4..ef0a0e7d 100644 --- a/NetAF/Commands/Conversation/Respond.cs +++ b/NetAF/Commands/Conversation/Respond.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Conversations; +using NetAF.Conversations; using NetAF.Logic.Modes; namespace NetAF.Commands.Conversation diff --git a/NetAF/Commands/CustomCommand.cs b/NetAF/Commands/CustomCommand.cs index a2b8846e..2d12dfd1 100644 --- a/NetAF/Commands/CustomCommand.cs +++ b/NetAF/Commands/CustomCommand.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Serialization; namespace NetAF.Commands diff --git a/NetAF/Commands/CustomCommandCallback.cs b/NetAF/Commands/CustomCommandCallback.cs index 404a3afe..aa017786 100644 --- a/NetAF/Commands/CustomCommandCallback.cs +++ b/NetAF/Commands/CustomCommandCallback.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Commands +namespace NetAF.Commands { /// /// Provides a callback for custom commands. diff --git a/NetAF/Commands/Frame/CommandsOff.cs b/NetAF/Commands/Frame/CommandsOff.cs index 02c679ca..597e51dc 100644 --- a/NetAF/Commands/Frame/CommandsOff.cs +++ b/NetAF/Commands/Frame/CommandsOff.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Commands.Frame +namespace NetAF.Commands.Frame { /// /// Represents the CommandsOff command. diff --git a/NetAF/Commands/Frame/CommandsOn.cs b/NetAF/Commands/Frame/CommandsOn.cs index e523d59d..f2ad2dc8 100644 --- a/NetAF/Commands/Frame/CommandsOn.cs +++ b/NetAF/Commands/Frame/CommandsOn.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Commands.Frame +namespace NetAF.Commands.Frame { /// /// Represents the CommandsOn command. diff --git a/NetAF/Commands/Frame/KeyOff.cs b/NetAF/Commands/Frame/KeyOff.cs index 207f3508..9987bce5 100644 --- a/NetAF/Commands/Frame/KeyOff.cs +++ b/NetAF/Commands/Frame/KeyOff.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Rendering; +using NetAF.Rendering; namespace NetAF.Commands.Frame { diff --git a/NetAF/Commands/Frame/KeyOn.cs b/NetAF/Commands/Frame/KeyOn.cs index 4326fe41..276ed175 100644 --- a/NetAF/Commands/Frame/KeyOn.cs +++ b/NetAF/Commands/Frame/KeyOn.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Rendering; +using NetAF.Rendering; namespace NetAF.Commands.Frame { diff --git a/NetAF/Commands/Global/About.cs b/NetAF/Commands/Global/About.cs index fc31be23..eaca5993 100644 --- a/NetAF/Commands/Global/About.cs +++ b/NetAF/Commands/Global/About.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Logic.Modes; +using NetAF.Logic.Modes; namespace NetAF.Commands.Global { diff --git a/NetAF/Commands/Global/End.cs b/NetAF/Commands/Global/End.cs index 7f8a8b66..f1e4ff5b 100644 --- a/NetAF/Commands/Global/End.cs +++ b/NetAF/Commands/Global/End.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Logic.Modes; +using NetAF.Logic.Modes; namespace NetAF.Commands.Global { diff --git a/NetAF/Commands/Global/Exit.cs b/NetAF/Commands/Global/Exit.cs index 0589d815..80413deb 100644 --- a/NetAF/Commands/Global/Exit.cs +++ b/NetAF/Commands/Global/Exit.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Commands.Global +namespace NetAF.Commands.Global { /// /// Represents the Exit command. diff --git a/NetAF/Commands/Global/Help.cs b/NetAF/Commands/Global/Help.cs index 865cae9c..96a961a5 100644 --- a/NetAF/Commands/Global/Help.cs +++ b/NetAF/Commands/Global/Help.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Logic.Modes; +using NetAF.Logic.Modes; using System.Collections.Generic; using System.Linq; diff --git a/NetAF/Commands/Global/Map.cs b/NetAF/Commands/Global/Map.cs index ee208394..050d62d9 100644 --- a/NetAF/Commands/Global/Map.cs +++ b/NetAF/Commands/Global/Map.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Logic; +using NetAF.Logic; using NetAF.Logic.Modes; namespace NetAF.Commands.Global diff --git a/NetAF/Commands/Global/New.cs b/NetAF/Commands/Global/New.cs index dfb07d50..29925f6c 100644 --- a/NetAF/Commands/Global/New.cs +++ b/NetAF/Commands/Global/New.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Commands.Global +namespace NetAF.Commands.Global { /// /// Represents the New command. diff --git a/NetAF/Commands/ICommand.cs b/NetAF/Commands/ICommand.cs index 96689b96..7745cd76 100644 --- a/NetAF/Commands/ICommand.cs +++ b/NetAF/Commands/ICommand.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Commands +namespace NetAF.Commands { /// /// Represents a command. diff --git a/NetAF/Commands/Persistence/Load.cs b/NetAF/Commands/Persistence/Load.cs index 5d1e6a09..374f4245 100644 --- a/NetAF/Commands/Persistence/Load.cs +++ b/NetAF/Commands/Persistence/Load.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Persistence.Json; +using NetAF.Persistence.Json; namespace NetAF.Commands.Persistence { diff --git a/NetAF/Commands/Persistence/Save.cs b/NetAF/Commands/Persistence/Save.cs index 457d28d4..a9660ca9 100644 --- a/NetAF/Commands/Persistence/Save.cs +++ b/NetAF/Commands/Persistence/Save.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using System.IO; +using System.IO; using NetAF.Persistence; using NetAF.Persistence.Json; diff --git a/NetAF/Assets/Interaction/Reaction.cs b/NetAF/Commands/Reaction.cs similarity index 95% rename from NetAF/Assets/Interaction/Reaction.cs rename to NetAF/Commands/Reaction.cs index 9d4634dd..6b841c11 100644 --- a/NetAF/Assets/Interaction/Reaction.cs +++ b/NetAF/Commands/Reaction.cs @@ -1,4 +1,4 @@ -namespace NetAF.Assets.Interaction +namespace NetAF.Commands { /// /// Represents a reaction. diff --git a/NetAF/Assets/Interaction/ReactionResult.cs b/NetAF/Commands/ReactionResult.cs similarity index 93% rename from NetAF/Assets/Interaction/ReactionResult.cs rename to NetAF/Commands/ReactionResult.cs index c8db0894..bec603b3 100644 --- a/NetAF/Assets/Interaction/ReactionResult.cs +++ b/NetAF/Commands/ReactionResult.cs @@ -1,4 +1,4 @@ -namespace NetAF.Assets.Interaction +namespace NetAF.Commands { /// /// Enumeration of reaction results. diff --git a/NetAF/Commands/RegionMap/Pan.cs b/NetAF/Commands/RegionMap/Pan.cs index bf73d845..373208d9 100644 --- a/NetAF/Commands/RegionMap/Pan.cs +++ b/NetAF/Commands/RegionMap/Pan.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Logic.Modes; diff --git a/NetAF/Commands/RegionMap/PanReset.cs b/NetAF/Commands/RegionMap/PanReset.cs index bfd9b06e..6624029a 100644 --- a/NetAF/Commands/RegionMap/PanReset.cs +++ b/NetAF/Commands/RegionMap/PanReset.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Logic.Modes; +using NetAF.Logic.Modes; namespace NetAF.Commands.RegionMap { diff --git a/NetAF/Commands/Scene/Drop.cs b/NetAF/Commands/Scene/Drop.cs index 8216eba7..fe9b3a12 100644 --- a/NetAF/Commands/Scene/Drop.cs +++ b/NetAF/Commands/Scene/Drop.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; namespace NetAF.Commands.Scene { diff --git a/NetAF/Commands/Scene/Examine.cs b/NetAF/Commands/Scene/Examine.cs index 0bb9b569..4b108118 100644 --- a/NetAF/Commands/Scene/Examine.cs +++ b/NetAF/Commands/Scene/Examine.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; namespace NetAF.Commands.Scene { diff --git a/NetAF/Commands/Scene/Move.cs b/NetAF/Commands/Scene/Move.cs index 8eedc348..4b3d0d6c 100644 --- a/NetAF/Commands/Scene/Move.cs +++ b/NetAF/Commands/Scene/Move.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Assets.Locations; +using NetAF.Assets.Locations; namespace NetAF.Commands.Scene { diff --git a/NetAF/Commands/Scene/Take.cs b/NetAF/Commands/Scene/Take.cs index 007a187a..1ad15c3e 100644 --- a/NetAF/Commands/Scene/Take.cs +++ b/NetAF/Commands/Scene/Take.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; namespace NetAF.Commands.Scene { diff --git a/NetAF/Commands/Scene/TakeAll.cs b/NetAF/Commands/Scene/TakeAll.cs index 4a15df23..5113c160 100644 --- a/NetAF/Commands/Scene/TakeAll.cs +++ b/NetAF/Commands/Scene/TakeAll.cs @@ -1,6 +1,5 @@ using System.Linq; using System.Text; -using NetAF.Assets.Interaction; namespace NetAF.Commands.Scene { diff --git a/NetAF/Commands/Scene/Talk.cs b/NetAF/Commands/Scene/Talk.cs index 789ede75..dfc4b1f6 100644 --- a/NetAF/Commands/Scene/Talk.cs +++ b/NetAF/Commands/Scene/Talk.cs @@ -1,5 +1,4 @@ using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Logic.Modes; namespace NetAF.Commands.Scene diff --git a/NetAF/Commands/Scene/Unactionable.cs b/NetAF/Commands/Scene/Unactionable.cs index 5366d67c..6645e826 100644 --- a/NetAF/Commands/Scene/Unactionable.cs +++ b/NetAF/Commands/Scene/Unactionable.cs @@ -1,6 +1,4 @@ -using NetAF.Assets.Interaction; - -namespace NetAF.Commands.Scene +namespace NetAF.Commands.Scene { /// /// Represents the Unactionable command. diff --git a/NetAF/Conversations/Conversation.cs b/NetAF/Conversations/Conversation.cs index c284b245..5a5e59da 100644 --- a/NetAF/Conversations/Conversation.cs +++ b/NetAF/Conversations/Conversation.cs @@ -1,9 +1,9 @@ using System.Linq; -using NetAF.Assets.Interaction; using NetAF.Extensions; using NetAF.Logic; using NetAF.Serialization.Assets; using NetAF.Serialization; +using NetAF.Commands; namespace NetAF.Conversations { diff --git a/NetAF/Logic/Game.cs b/NetAF/Logic/Game.cs index ee3adb82..32067eb7 100644 --- a/NetAF/Logic/Game.cs +++ b/NetAF/Logic/Game.cs @@ -5,6 +5,7 @@ using NetAF.Assets.Characters; using NetAF.Assets.Interaction; using NetAF.Assets.Locations; +using NetAF.Commands; using NetAF.Commands.Scene; using NetAF.Extensions; using NetAF.Interpretation; From 802d866166c27d2b6acd7d40710ee631ce092502 Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 16:26:57 +0000 Subject: [PATCH 3/8] Refactored interaction effect --- NetAF.Examples/Assets/Player/Player.cs | 10 +-- .../Regions/Everglades/Items/ConchShell.cs | 9 +-- .../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 | 11 ++- .../Regions/Zelda/Rooms/OutsideLinksHouse.cs | 6 +- .../Assets/Regions/Zelda/Rooms/Stream.cs | 5 +- .../Characters/PlayableCharacter_Tests.cs | 20 ----- .../Interaction/InteractionResult_Tests.cs | 34 +++----- NetAF.Tests/Assets/Item_Tests.cs | 4 +- .../Assets/Characters/NonPlayableCharacter.cs | 2 +- NetAF/Assets/Characters/PlayableCharacter.cs | 9 +-- NetAF/Assets/Interaction/InteractionEffect.cs | 20 ++--- NetAF/Assets/Interaction/InteractionResult.cs | 11 ++- NetAF/Assets/Item.cs | 2 +- NetAF/Assets/Locations/Exit.cs | 2 +- NetAF/Assets/Locations/Room.cs | 2 +- NetAF/Commands/Scene/UseOn.cs | 79 +++++++++++++++---- NetAF/Logic/Modes/ReactionMode.cs | 5 +- 23 files changed, 135 insertions(+), 134 deletions(-) diff --git a/NetAF.Examples/Assets/Player/Player.cs b/NetAF.Examples/Assets/Player/Player.cs index 5b687c62..45c9e2cb 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(InteractionEffect.NoEffect, null); + return new(InteractionEffect.NeitherItemOrTargetExpired, null); if (Knife.Name.EqualsExaminable(i)) - return new(InteractionEffect.FatalEffect, i, "You slash wildly at your own throat. You are dead."); + return new(InteractionEffect.TargetExpired, i, "You slash wildly at your own throat. You are dead."); if (CoffeeMug.Name.EqualsIdentifier(i.Identifier)) - return new(InteractionEffect.NoEffect, i, "If there was some coffee in the mug you could drink it."); + return new(InteractionEffect.NeitherItemOrTargetExpired, i, "If there was some coffee in the mug you could drink it."); if (Guitar.Name.EqualsIdentifier(i.Identifier)) - return new(InteractionEffect.NoEffect, i, "You bust out some Bad Religion. Cracking, shame the guitar isn't plugged in to an amplified though..."); + return new(InteractionEffect.NeitherItemOrTargetExpired, i, "You bust out some Bad Religion. Cracking, shame the guitar isn't plugged in to an amplified though..."); - return new(InteractionEffect.NoEffect, i); + return new(InteractionEffect.NeitherItemOrTargetExpired, i); }); return player; diff --git a/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs b/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs index efee028a..02b41752 100644 --- a/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs +++ b/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs @@ -24,11 +24,10 @@ public Item Instantiate() { var conchShell = new Item(Name, Description, true, interaction: item => { - return item.Identifier.IdentifiableName switch - { - Knife.Name => new(InteractionEffect.FatalEffect, item, "You slash at the conch shell and it shatters into tiny pieces. Without the conch shell you are well and truly in trouble."), - _ => new(InteractionEffect.NoEffect, item), - }; + if (item.Identifier.Equals(Knife.Name)) + return new(InteractionEffect.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(InteractionEffect.NeitherItemOrTargetExpired, item); }); return conchShell; diff --git a/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs b/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs index e1a270ac..4b6c563b 100644 --- a/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs +++ b/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs @@ -31,13 +31,13 @@ public Room Instantiate() if (item != null && ConchShell.Name.EqualsExaminable(item)) { room[Direction.North].Unlock(); - return new(InteractionEffect.ItemUsedUp, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces."); + return new(InteractionEffect.ItemExpired, 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(InteractionEffect.NoEffect, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); + return new(InteractionEffect.NeitherItemOrTargetExpired, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); - return new(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, 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 a0005b89..07d32f74 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(InteractionEffect.ItemUsedUp, item, "The lead fits snugly into the input socket on the amp."); + return new(InteractionEffect.ItemExpired, 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(InteractionEffect.NoEffect, 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(InteractionEffect.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(InteractionEffect.NoEffect, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); + return new(InteractionEffect.NeitherItemOrTargetExpired, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); } - return new(InteractionEffect.NoEffect, item, "You have no lead so you can't use the guitar with the amp..."); + return new(InteractionEffect.NeitherItemOrTargetExpired, item, "You have no lead so you can't use the guitar with the amp..."); } - return new(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, 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 d7e51969..b45ed0c4 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs @@ -26,10 +26,10 @@ public Item Instantiate() { if (Kettle.Name.EqualsIdentifier(item.Identifier)) { - return new(InteractionEffect.SelfContained, 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(InteractionEffect.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(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, item); }); } diff --git a/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs b/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs index 51e320ee..c40a8b93 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs @@ -25,9 +25,9 @@ public Item Instantiate() return new(Name, Description, interaction: item => { if (item != null && CoffeeMug.Name.EqualsIdentifier(item.Identifier)) - return new(InteractionEffect.SelfContained, 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(InteractionEffect.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(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, item); }); } diff --git a/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs b/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs index aedfd80c..ddd33a33 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(InteractionEffect.NoEffect, item, "Playing guitar in the kitchen is pretty stupid don't you think?"); + return new(InteractionEffect.NeitherItemOrTargetExpired, item, "Playing guitar in the kitchen is pretty stupid don't you think?"); - return new(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, 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 3eb02ca0..ffc2069a 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs @@ -37,23 +37,23 @@ public Room Instantiate() if (CoffeeMug.Name.EqualsIdentifier(item.Identifier)) { if (room.ContainsCharacter(Beth.Name)) - return new(InteractionEffect.ItemUsedUp, item, "Beth takes the cup of coffee and smiles. Brownie points to you!"); + return new(InteractionEffect.ItemExpired, item, "Beth takes the cup of coffee and smiles. Brownie points to you!"); - return new(InteractionEffect.SelfContained, 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(InteractionEffect.NeitherItemOrTargetExpired, 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(InteractionEffect.ItemUsedUp, item, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed."); + return new(InteractionEffect.ItemExpired, 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(InteractionEffect.NoEffect, 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(InteractionEffect.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(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, 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 e4acebd7..a88b71f2 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs @@ -59,13 +59,12 @@ public NonPlayableCharacter Instantiate() { saria.RemoveItem(key); room.AddItem(key); - item.IsPlayerVisible = false; - return new(InteractionEffect.SelfContained, item, $"{saria.Identifier.Name} looks excited! \"Thanks Link, here take the Tail Key!\" Saria put the Tail Key down, awesome!"); + return new(InteractionEffect.ItemExpired, 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(InteractionEffect.NoEffect, item, $"{saria.Identifier.Name} looks at your shield, but seems pretty unimpressed."); + return new(InteractionEffect.NeitherItemOrTargetExpired, item, $"{saria.Identifier.Name} looks at your shield, but seems pretty unimpressed."); } if (Sword.Name.EqualsIdentifier(item.Identifier) && saria.IsAlive) @@ -73,15 +72,15 @@ public NonPlayableCharacter Instantiate() saria.Kill(); if (!saria.HasItem(key)) - return new(InteractionEffect.SelfContained, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead."); + return new(InteractionEffect.NeitherItemOrTargetExpired, 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(InteractionEffect.SelfContained, 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(InteractionEffect.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(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, 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 19e48bad..b6fd4e47 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs @@ -36,13 +36,13 @@ public Room Instantiate() exit.Unlock(); room.RemoveItem(door); - return new(InteractionEffect.ItemUsedUp, item, "The Tail Key fits perfectly in the lock, you turn it and the door swings open, revealing a gaping cave mouth..."); + return new(InteractionEffect.ItemExpired, 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(InteractionEffect.NoEffect, item, "Clang clang!"); + return new(InteractionEffect.NeitherItemOrTargetExpired, item, "Clang clang!"); - return new(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, 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 119c807c..efde72d0 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs @@ -39,11 +39,10 @@ public Room Instantiate() if (Sword.Name.EqualsExaminable(item)) { rupee.IsPlayerVisible = true; - bush.IsPlayerVisible = false; - return new(InteractionEffect.SelfContained, 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(InteractionEffect.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(InteractionEffect.NoEffect, item); + return new(InteractionEffect.NeitherItemOrTargetExpired, item); }).Instantiate(); rupee.IsPlayerVisible = false; diff --git a/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs b/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs index 30fb6c4f..7f240d38 100644 --- a/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs +++ b/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs @@ -61,25 +61,5 @@ public void GivenAnItem_WhenRemoveItem_ThenHasItemIsFalse() Assert.IsFalse(result); } - - [TestMethod] - public void GivenUseItem_WhenFatalEffect_ThenIsAliveIsFalse() - { - var item = new Item("Test", string.Empty); - var pc = new PlayableCharacter(string.Empty, string.Empty, interaction: i => - { - if (i == null) - return new InteractionResult(InteractionEffect.NoEffect, null); - - if (i.Identifier.Name == "Test") - return new InteractionResult(InteractionEffect.FatalEffect, i, ""); - - return new InteractionResult(InteractionEffect.NoEffect, i); - }); - - pc.UseItem(item, pc); - - Assert.IsFalse(pc.IsAlive); - } } } diff --git a/NetAF.Tests/Assets/Interaction/InteractionResult_Tests.cs b/NetAF.Tests/Assets/Interaction/InteractionResult_Tests.cs index 3f0b5c94..35b1af80 100644 --- a/NetAF.Tests/Assets/Interaction/InteractionResult_Tests.cs +++ b/NetAF.Tests/Assets/Interaction/InteractionResult_Tests.cs @@ -9,61 +9,51 @@ public class InteractionResult_Tests [TestMethod] public void GivenConstructor_WhenExplicitDescription_ThenDescriptionIsAsSpecified() { - var instance = new InteractionResult(InteractionEffect.NoEffect, null, "A"); + var instance = new InteractionResult(InteractionEffect.NeitherItemOrTargetExpired, null, "A"); var result = instance.Description; Assert.AreEqual("A", result); } - [TestMethod] - public void GivenConstructor_WhenFatal_ThenGeneratedDescriptionIsCorrect() - { - var instance = new InteractionResult(InteractionEffect.FatalEffect, null); - - var result = instance.Description; - - Assert.AreEqual("There was a fatal effect.", result); - } - [TestMethod] public void GivenConstructor_WhenItemUsedUp_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.ItemUsedUp, null); + var instance = new InteractionResult(InteractionEffect.ItemExpired, null); var result = instance.Description; - Assert.AreEqual("The item was used up.", result); + Assert.AreEqual("The item expired.", result); } [TestMethod] - public void GivenConstructor_WhenNoEffect_ThenGeneratedDescriptionIsCorrect() + public void GivenConstructor_WhenItemAndTargetExpired_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.NoEffect, null); + var instance = new InteractionResult(InteractionEffect.ItemAndTargetExpired, null); var result = instance.Description; - Assert.AreEqual("There was no effect.", result); + Assert.AreEqual("Both the item and target expired.", result); } [TestMethod] - public void GivenConstructor_WhenSelfContained_ThenGeneratedDescriptionIsCorrect() + public void GivenConstructor_WhenNeitherItemOrTargetExpired_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.SelfContained, null); + var instance = new InteractionResult(InteractionEffect.NeitherItemOrTargetExpired, null); var result = instance.Description; - Assert.AreEqual("The effect was self contained.", result); + Assert.AreEqual("There was no effect.", result); } [TestMethod] - public void GivenConstructor_WhenTargetUsedUp_ThenGeneratedDescriptionIsCorrect() + public void GivenConstructor_WhenTargetExpired_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.TargetUsedUp, null); + var instance = new InteractionResult(InteractionEffect.TargetExpired, null); var result = instance.Description; - Assert.AreEqual("The target was used up.", result); + Assert.AreEqual("The target expired.", result); } } } \ No newline at end of file diff --git a/NetAF.Tests/Assets/Item_Tests.cs b/NetAF.Tests/Assets/Item_Tests.cs index 260cb16f..5181a1b1 100644 --- a/NetAF.Tests/Assets/Item_Tests.cs +++ b/NetAF.Tests/Assets/Item_Tests.cs @@ -8,14 +8,14 @@ namespace NetAF.Tests.Assets public class Item_Tests { [TestMethod] - public void Given2Items_WhenInteract_ThenNoEffect() + public void Given2Items_WhenInteract_ThenNeitherItemOrTargetExpired() { var item = new Item(string.Empty, string.Empty); var item2 = new Item(string.Empty, string.Empty); var result = item.Interact(item2); - Assert.AreEqual(InteractionEffect.NoEffect, result.Effect); + Assert.AreEqual(InteractionEffect.NeitherItemOrTargetExpired, result.Effect); } } } diff --git a/NetAF/Assets/Characters/NonPlayableCharacter.cs b/NetAF/Assets/Characters/NonPlayableCharacter.cs index f3c92055..d363c9cd 100644 --- a/NetAF/Assets/Characters/NonPlayableCharacter.cs +++ b/NetAF/Assets/Characters/NonPlayableCharacter.cs @@ -41,7 +41,7 @@ public NonPlayableCharacter(Identifier identifier, Description description, Conv Description = description; Conversation = conversation; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NoEffect, i)); + Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Characters/PlayableCharacter.cs b/NetAF/Assets/Characters/PlayableCharacter.cs index bc5350d9..2bcb6eb0 100644 --- a/NetAF/Assets/Characters/PlayableCharacter.cs +++ b/NetAF/Assets/Characters/PlayableCharacter.cs @@ -76,7 +76,7 @@ public PlayableCharacter(Identifier identifier, Description description, bool ca CanConverse = canConverse; Items = items ?? []; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NoEffect, i)); + Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; @@ -94,12 +94,7 @@ public PlayableCharacter(Identifier identifier, Description description, bool ca /// The result of the items usage. public InteractionResult UseItem(Item item, IInteractWithItem targetObject) { - var result = targetObject.Interact(item); - - if (result.Effect == InteractionEffect.FatalEffect) - IsAlive = false; - - return result; + return targetObject.Interact(item); } #endregion diff --git a/NetAF/Assets/Interaction/InteractionEffect.cs b/NetAF/Assets/Interaction/InteractionEffect.cs index 63b242f7..35b7abf6 100644 --- a/NetAF/Assets/Interaction/InteractionEffect.cs +++ b/NetAF/Assets/Interaction/InteractionEffect.cs @@ -6,24 +6,20 @@ public enum InteractionEffect { /// - /// No effect to the interaction on either the item or the target. + /// Neither the item or the target expired. /// - NoEffect = 0, + NeitherItemOrTargetExpired = 0, /// - /// Item was used up. + /// The item expired. /// - ItemUsedUp, + ItemExpired, /// - /// A fatal effect to the interaction. + /// The target expired. /// - FatalEffect, + TargetExpired, /// - /// The target was used up. + /// The item and the target expired. /// - TargetUsedUp, - /// - /// Any other self contained effect. - /// - SelfContained + ItemAndTargetExpired } } \ No newline at end of file diff --git a/NetAF/Assets/Interaction/InteractionResult.cs b/NetAF/Assets/Interaction/InteractionResult.cs index 3da8cb34..a06004e8 100644 --- a/NetAF/Assets/Interaction/InteractionResult.cs +++ b/NetAF/Assets/Interaction/InteractionResult.cs @@ -35,12 +35,11 @@ public InteractionResult(InteractionEffect effect, Item item) Description = effect switch { - InteractionEffect.FatalEffect => "There was a fatal effect.", - InteractionEffect.ItemUsedUp => "The item was used up.", - InteractionEffect.NoEffect => "There was no effect.", - InteractionEffect.SelfContained => "The effect was self contained.", - InteractionEffect.TargetUsedUp => "The target was used up.", - _ => throw new NotImplementedException(), + InteractionEffect.NeitherItemOrTargetExpired => "There was no effect.", + InteractionEffect.ItemExpired => "The item expired.", + InteractionEffect.TargetExpired => "The target expired.", + InteractionEffect.ItemAndTargetExpired => "Both the item and target expired.", + _ => throw new NotImplementedException($"No implementation for ${effect}."), }; } diff --git a/NetAF/Assets/Item.cs b/NetAF/Assets/Item.cs index 3b46c806..f43ca8cc 100644 --- a/NetAF/Assets/Item.cs +++ b/NetAF/Assets/Item.cs @@ -54,7 +54,7 @@ public Item(Identifier identifier, Description description, bool isTakeable = fa Description = description; IsTakeable = isTakeable; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NoEffect, i)); + Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Locations/Exit.cs b/NetAF/Assets/Locations/Exit.cs index 334d9535..d414db9b 100644 --- a/NetAF/Assets/Locations/Exit.cs +++ b/NetAF/Assets/Locations/Exit.cs @@ -48,7 +48,7 @@ public Exit(Direction direction, bool isLocked = false, Identifier identifier = Description = description ?? GenerateDescription(); IsLocked = isLocked; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NoEffect, i)); + Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Locations/Room.cs b/NetAF/Assets/Locations/Room.cs index aaafa89b..2aa64d77 100644 --- a/NetAF/Assets/Locations/Room.cs +++ b/NetAF/Assets/Locations/Room.cs @@ -90,7 +90,7 @@ public Room(Identifier identifier, Description description, Exit[] exits = null, Exits = exits ?? []; Items = items ?? []; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NoEffect, i)); + Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Commands/Scene/UseOn.cs b/NetAF/Commands/Scene/UseOn.cs index 81a60d7e..277f232a 100644 --- a/NetAF/Commands/Scene/UseOn.cs +++ b/NetAF/Commands/Scene/UseOn.cs @@ -1,6 +1,10 @@ using System; +using System.Collections.Generic; +using System.Linq; using NetAF.Assets; +using NetAF.Assets.Characters; using NetAF.Assets.Interaction; +using NetAF.Logic; namespace NetAF.Commands.Scene { @@ -25,6 +29,56 @@ public sealed class UseOn(Item item, IInteractWithItem target) : ICommand #endregion + #region StaticMethods + + /// + /// Handle an item expiring. + /// + /// The game. + /// The item that expired. + private static void ItemExpired(Game game, Item item) + { + List containers = []; + + containers.Add(game.Player); + containers.Add(game.Overworld.CurrentRegion.CurrentRoom); + containers.AddRange(game.Overworld.CurrentRegion.CurrentRoom.Characters ?? []); + + foreach (var container in containers) + { + if (container.Items.Contains(item)) + container.RemoveItem(item); + } + } + + /// + /// Handle a target expiring. + /// + /// The game. + /// The item that expired. + private static void TargetExpired(Game game, IInteractWithItem target) + { + if (target is IExaminable examinable && game.Overworld.CurrentRegion.CurrentRoom.ContainsInteractionTarget(examinable.Identifier.Name)) + game.Overworld.CurrentRegion.CurrentRoom.RemoveInteractionTarget(target); + + if (target is Item item) + { + foreach (var npc in game.Overworld.CurrentRegion.CurrentRoom.Characters ?? []) + { + if (npc.HasItem(item)) + npc.RemoveItem(item); + } + + if (game.Player.HasItem(item)) + game.Player.RemoveItem(item); + } + + if (target is Character character) + character.Kill(); + } + + #endregion + #region Implementation of ICommand /// @@ -50,24 +104,17 @@ public Reaction Invoke(Logic.Game game) switch (result.Effect) { - case InteractionEffect.ItemUsedUp: - - if (game.Overworld.CurrentRegion.CurrentRoom.ContainsItem(item)) - game.Overworld.CurrentRegion.CurrentRoom.RemoveItem(item); - else if (game.Player.HasItem(item)) - game.Player.RemoveItem(item); - + case InteractionEffect.NeitherItemOrTargetExpired: break; - - case InteractionEffect.TargetUsedUp: - - if (target is IExaminable examinable && game.Overworld.CurrentRegion.CurrentRoom.ContainsInteractionTarget(examinable.Identifier.Name)) - game.Overworld.CurrentRegion.CurrentRoom.RemoveInteractionTarget(target); - + case InteractionEffect.ItemExpired: + ItemExpired(game, item); break; - - case InteractionEffect.NoEffect: - case InteractionEffect.SelfContained: + case InteractionEffect.TargetExpired: + TargetExpired(game, target); + break; + case InteractionEffect.ItemAndTargetExpired: + ItemExpired(game, item); + TargetExpired(game, target); break; default: throw new NotImplementedException(); diff --git a/NetAF/Logic/Modes/ReactionMode.cs b/NetAF/Logic/Modes/ReactionMode.cs index 6ab02638..011e4f3c 100644 --- a/NetAF/Logic/Modes/ReactionMode.cs +++ b/NetAF/Logic/Modes/ReactionMode.cs @@ -1,7 +1,4 @@ -using NetAF.Commands.Global; -using NetAF.Commands.Scene; -using NetAF.Extensions; -using NetAF.Interpretation; +using NetAF.Interpretation; namespace NetAF.Logic.Modes { From 2f8f7793f07081626718352bf14070147ecb6f1c Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 16:40:23 +0000 Subject: [PATCH 4/8] Refactored interaction --- NetAF.Examples/Assets/Player/Player.cs | 14 ++--- .../Regions/Everglades/Items/ConchShell.cs | 5 +- .../Regions/Everglades/Rooms/InnerCave.cs | 7 +-- NetAF.Examples/Assets/Regions/Flat/Flat.cs | 12 ++-- .../Assets/Regions/Flat/Items/CoffeeMug.cs | 5 +- .../Assets/Regions/Flat/Items/Kettle.cs | 5 +- .../Assets/Regions/Flat/Rooms/Kitchen.cs | 6 +- .../Assets/Regions/Flat/Rooms/Lounge.cs | 11 ++-- .../Assets/Regions/Flat/Rooms/SpareBedroom.cs | 1 - .../Assets/Regions/Zelda/Items/Bush.cs | 1 - .../Assets/Regions/Zelda/Items/TailDoor.cs | 1 - .../Assets/Regions/Zelda/NPCs/Saria.cs | 14 ++--- .../Regions/Zelda/Rooms/OutsideLinksHouse.cs | 7 +-- .../Assets/Regions/Zelda/Rooms/Stream.cs | 5 +- .../Characters/PlayableCharacter_Tests.cs | 1 - ...onResult_Tests.cs => Interaction_Tests.cs} | 18 +++--- NetAF.Tests/Assets/Item_Tests.cs | 3 +- NetAF/Assets/Characters/Character.cs | 9 ++- .../Assets/Characters/NonPlayableCharacter.cs | 5 +- NetAF/Assets/Characters/PlayableCharacter.cs | 9 ++- .../{Interaction => }/IInteractWithItem.cs | 6 +- NetAF/Assets/Interaction.cs | 61 +++++++++++++++++++ .../Assets/Interaction/InteractionCallback.cs | 9 --- NetAF/Assets/Interaction/InteractionResult.cs | 61 ------------------- NetAF/Assets/InteractionCallback.cs | 9 +++ ...eractionEffect.cs => InteractionResult.cs} | 6 +- NetAF/Assets/Item.cs | 9 ++- NetAF/Assets/Locations/Exit.cs | 9 ++- NetAF/Assets/Locations/Room.cs | 11 ++-- NetAF/Commands/Scene/UseOn.cs | 11 ++-- .../Interpretation/SceneCommandInterpreter.cs | 1 - NetAF/Logic/Game.cs | 1 - NetAF/NetAF.csproj | 4 ++ 33 files changed, 160 insertions(+), 177 deletions(-) rename NetAF.Tests/Assets/{Interaction/InteractionResult_Tests.cs => Interaction_Tests.cs} (65%) rename NetAF/Assets/{Interaction => }/IInteractWithItem.cs (67%) create mode 100644 NetAF/Assets/Interaction.cs delete mode 100644 NetAF/Assets/Interaction/InteractionCallback.cs delete mode 100644 NetAF/Assets/Interaction/InteractionResult.cs create mode 100644 NetAF/Assets/InteractionCallback.cs rename NetAF/Assets/{Interaction/InteractionEffect.cs => InteractionResult.cs} (81%) diff --git a/NetAF.Examples/Assets/Player/Player.cs b/NetAF.Examples/Assets/Player/Player.cs index 45c9e2cb..a5d8022f 100644 --- a/NetAF.Examples/Assets/Player/Player.cs +++ b/NetAF.Examples/Assets/Player/Player.cs @@ -1,5 +1,5 @@ -using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; +using NetAF.Assets; +using NetAF.Assets.Characters; using NetAF.Examples.Assets.Items; using NetAF.Examples.Assets.Regions.Flat.Items; using NetAF.Extensions; @@ -27,18 +27,18 @@ public PlayableCharacter Instantiate() var player = new PlayableCharacter(Name, Description, [new Knife().Instantiate()], interaction: i => { if (i == null) - return new(InteractionEffect.NeitherItemOrTargetExpired, null); + return new(InteractionResult.NeitherItemOrTargetExpired, null); if (Knife.Name.EqualsExaminable(i)) - return new(InteractionEffect.TargetExpired, i, "You slash wildly at your own throat. You are dead."); + return new(InteractionResult.TargetExpired, i, "You slash wildly at your own throat. You are dead."); if (CoffeeMug.Name.EqualsIdentifier(i.Identifier)) - return new(InteractionEffect.NeitherItemOrTargetExpired, i, "If there was some coffee in the mug you could drink it."); + return new(InteractionResult.NeitherItemOrTargetExpired, i, "If there was some coffee in the mug you could drink it."); if (Guitar.Name.EqualsIdentifier(i.Identifier)) - return new(InteractionEffect.NeitherItemOrTargetExpired, i, "You bust out some Bad Religion. Cracking, shame the guitar isn't plugged in to an amplified though..."); + 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(InteractionEffect.NeitherItemOrTargetExpired, i); + return new(InteractionResult.NeitherItemOrTargetExpired, i); }); return player; diff --git a/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs b/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs index 02b41752..8954269e 100644 --- a/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs +++ b/NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Examples.Assets.Items; using NetAF.Utilities; @@ -25,9 +24,9 @@ public Item Instantiate() var conchShell = new Item(Name, Description, true, interaction: item => { if (item.Identifier.Equals(Knife.Name)) - return new(InteractionEffect.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.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(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, item); }); return conchShell; diff --git a/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs b/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs index 4b6c563b..7ea3d995 100644 --- a/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs +++ b/NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Examples.Assets.Items; using NetAF.Examples.Assets.Regions.Everglades.Items; @@ -31,13 +30,13 @@ public Room Instantiate() if (item != null && ConchShell.Name.EqualsExaminable(item)) { room[Direction.North].Unlock(); - return new(InteractionEffect.ItemExpired, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces."); + return new(InteractionResult.ItemExpired, 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(InteractionEffect.NeitherItemOrTargetExpired, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); + return new(InteractionResult.NeitherItemOrTargetExpired, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!"); - return new(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, 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 07d32f74..77345d03 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Flat.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Flat.cs @@ -1,4 +1,4 @@ -using NetAF.Assets.Interaction; +using NetAF.Assets; using NetAF.Assets.Locations; using NetAF.Examples.Assets.Regions.Flat.Items; using NetAF.Examples.Assets.Regions.Flat.NPCs; @@ -36,7 +36,7 @@ public Region Instantiate() if (Lead.Name.EqualsIdentifier(item.Identifier)) { spareBedroom.AddItem(new(item.Identifier, item.Description, true)); - return new(InteractionEffect.ItemExpired, item, "The lead fits snugly into the input socket on the amp."); + return new(InteractionResult.ItemExpired, 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(InteractionEffect.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.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(InteractionEffect.NeitherItemOrTargetExpired, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); + return new(InteractionResult.NeitherItemOrTargetExpired, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings."); } - return new(InteractionEffect.NeitherItemOrTargetExpired, item, "You have no lead so you can't use the guitar with the amp..."); + return new(InteractionResult.NeitherItemOrTargetExpired, item, "You have no lead so you can't use the guitar with the amp..."); } - return new(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, 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 b45ed0c4..a1759628 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Extensions; using NetAF.Utilities; @@ -26,10 +25,10 @@ public Item Instantiate() { if (Kettle.Name.EqualsIdentifier(item.Identifier)) { - return new(InteractionEffect.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.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(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, item); }); } diff --git a/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs b/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs index c40a8b93..132fb0df 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Extensions; using NetAF.Utilities; @@ -25,9 +24,9 @@ public Item Instantiate() return new(Name, Description, interaction: item => { if (item != null && CoffeeMug.Name.EqualsIdentifier(item.Identifier)) - return new(InteractionEffect.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.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(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, item); }); } diff --git a/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs b/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs index ddd33a33..1f225dc5 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs @@ -1,4 +1,4 @@ -using NetAF.Assets.Interaction; +using NetAF.Assets; using NetAF.Assets.Locations; using NetAF.Examples.Assets.Regions.Flat.Items; using NetAF.Extensions; @@ -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(InteractionEffect.NeitherItemOrTargetExpired, item, "Playing guitar in the kitchen is pretty stupid don't you think?"); + return new(InteractionResult.NeitherItemOrTargetExpired, item, "Playing guitar in the kitchen is pretty stupid don't you think?"); - return new(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, 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 ffc2069a..82d5bab9 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Examples.Assets.Regions.Flat.Items; using NetAF.Examples.Assets.Regions.Flat.NPCs; @@ -37,23 +36,23 @@ public Room Instantiate() if (CoffeeMug.Name.EqualsIdentifier(item.Identifier)) { if (room.ContainsCharacter(Beth.Name)) - return new(InteractionEffect.ItemExpired, item, "Beth takes the cup of coffee and smiles. Brownie points to you!"); + return new(InteractionResult.ItemExpired, item, "Beth takes the cup of coffee and smiles. Brownie points to you!"); - return new(InteractionEffect.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.NeitherItemOrTargetExpired, 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(InteractionEffect.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.ItemExpired, 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(InteractionEffect.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.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(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, item); }); room.AddCharacter(new Beth().Instantiate()); diff --git a/NetAF.Examples/Assets/Regions/Flat/Rooms/SpareBedroom.cs b/NetAF.Examples/Assets/Regions/Flat/Rooms/SpareBedroom.cs index 9441ca90..445c79f8 100644 --- a/NetAF.Examples/Assets/Regions/Flat/Rooms/SpareBedroom.cs +++ b/NetAF.Examples/Assets/Regions/Flat/Rooms/SpareBedroom.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Examples.Assets.Regions.Flat.Items; using NetAF.Utilities; diff --git a/NetAF.Examples/Assets/Regions/Zelda/Items/Bush.cs b/NetAF.Examples/Assets/Regions/Zelda/Items/Bush.cs index 996370d2..55291161 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Items/Bush.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Items/Bush.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Utilities; namespace NetAF.Examples.Assets.Regions.Zelda.Items diff --git a/NetAF.Examples/Assets/Regions/Zelda/Items/TailDoor.cs b/NetAF.Examples/Assets/Regions/Zelda/Items/TailDoor.cs index 6e413c40..40928346 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Items/TailDoor.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Items/TailDoor.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Utilities; namespace NetAF.Examples.Assets.Regions.Zelda.Items diff --git a/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs b/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs index a88b71f2..54b9ad80 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs @@ -1,5 +1,5 @@ -using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; +using NetAF.Assets; +using NetAF.Assets.Characters; using NetAF.Assets.Locations; using NetAF.Conversations; using NetAF.Conversations.Instructions; @@ -59,12 +59,12 @@ public NonPlayableCharacter Instantiate() { saria.RemoveItem(key); room.AddItem(key); - return new(InteractionEffect.ItemExpired, item, $"{saria.Identifier.Name} looks excited! \"Thanks Link, here take the Tail Key!\" Saria put the Tail Key down, awesome!"); + return new(InteractionResult.ItemExpired, 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(InteractionEffect.NeitherItemOrTargetExpired, item, $"{saria.Identifier.Name} looks at your shield, but seems pretty unimpressed."); + return new(InteractionResult.NeitherItemOrTargetExpired, 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(InteractionEffect.NeitherItemOrTargetExpired, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead."); + return new(InteractionResult.NeitherItemOrTargetExpired, 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(InteractionEffect.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.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(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, 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 b6fd4e47..c8deb68a 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Rooms/OutsideLinksHouse.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Examples.Assets.Regions.Zelda.Items; using NetAF.Examples.Assets.Regions.Zelda.NPCs; @@ -36,13 +35,13 @@ public Room Instantiate() exit.Unlock(); room.RemoveItem(door); - return new(InteractionEffect.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.ItemExpired, 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(InteractionEffect.NeitherItemOrTargetExpired, item, "Clang clang!"); + return new(InteractionResult.NeitherItemOrTargetExpired, item, "Clang clang!"); - return new(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, 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 efde72d0..8588d798 100644 --- a/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs +++ b/NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Examples.Assets.Regions.Zelda.Items; using NetAF.Extensions; @@ -39,10 +38,10 @@ public Room Instantiate() if (Sword.Name.EqualsExaminable(item)) { rupee.IsPlayerVisible = true; - return new(InteractionEffect.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.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(InteractionEffect.NeitherItemOrTargetExpired, item); + return new(InteractionResult.NeitherItemOrTargetExpired, item); }).Instantiate(); rupee.IsPlayerVisible = false; diff --git a/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs b/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs index 7f240d38..e6f03c28 100644 --- a/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs +++ b/NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs @@ -1,6 +1,5 @@ using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace NetAF.Tests.Assets.Characters diff --git a/NetAF.Tests/Assets/Interaction/InteractionResult_Tests.cs b/NetAF.Tests/Assets/Interaction_Tests.cs similarity index 65% rename from NetAF.Tests/Assets/Interaction/InteractionResult_Tests.cs rename to NetAF.Tests/Assets/Interaction_Tests.cs index 35b1af80..862b670b 100644 --- a/NetAF.Tests/Assets/Interaction/InteractionResult_Tests.cs +++ b/NetAF.Tests/Assets/Interaction_Tests.cs @@ -1,15 +1,15 @@ -using NetAF.Assets.Interaction; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NetAF.Assets; -namespace NetAF.Tests.Assets.Interaction +namespace NetAF.Tests.Assets { [TestClass] - public class InteractionResult_Tests + public class Interaction_Tests { [TestMethod] public void GivenConstructor_WhenExplicitDescription_ThenDescriptionIsAsSpecified() { - var instance = new InteractionResult(InteractionEffect.NeitherItemOrTargetExpired, null, "A"); + Interaction instance = new(InteractionResult.NeitherItemOrTargetExpired, null, "A"); var result = instance.Description; @@ -19,7 +19,7 @@ public void GivenConstructor_WhenExplicitDescription_ThenDescriptionIsAsSpecifie [TestMethod] public void GivenConstructor_WhenItemUsedUp_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.ItemExpired, null); + Interaction instance = new(InteractionResult.ItemExpired, null); var result = instance.Description; @@ -29,7 +29,7 @@ public void GivenConstructor_WhenItemUsedUp_ThenGeneratedDescriptionIsCorrect() [TestMethod] public void GivenConstructor_WhenItemAndTargetExpired_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.ItemAndTargetExpired, null); + Interaction instance = new(InteractionResult.ItemAndTargetExpired, null); var result = instance.Description; @@ -39,7 +39,7 @@ public void GivenConstructor_WhenItemAndTargetExpired_ThenGeneratedDescriptionIs [TestMethod] public void GivenConstructor_WhenNeitherItemOrTargetExpired_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.NeitherItemOrTargetExpired, null); + Interaction instance = new(InteractionResult.NeitherItemOrTargetExpired, null); var result = instance.Description; @@ -49,7 +49,7 @@ public void GivenConstructor_WhenNeitherItemOrTargetExpired_ThenGeneratedDescrip [TestMethod] public void GivenConstructor_WhenTargetExpired_ThenGeneratedDescriptionIsCorrect() { - var instance = new InteractionResult(InteractionEffect.TargetExpired, null); + Interaction instance = new(InteractionResult.TargetExpired, null); var result = instance.Description; diff --git a/NetAF.Tests/Assets/Item_Tests.cs b/NetAF.Tests/Assets/Item_Tests.cs index 5181a1b1..94c0b055 100644 --- a/NetAF.Tests/Assets/Item_Tests.cs +++ b/NetAF.Tests/Assets/Item_Tests.cs @@ -1,5 +1,4 @@ using NetAF.Assets; -using NetAF.Assets.Interaction; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace NetAF.Tests.Assets @@ -15,7 +14,7 @@ public void Given2Items_WhenInteract_ThenNeitherItemOrTargetExpired() var result = item.Interact(item2); - Assert.AreEqual(InteractionEffect.NeitherItemOrTargetExpired, result.Effect); + Assert.AreEqual(InteractionResult.NeitherItemOrTargetExpired, result.Result); } } } diff --git a/NetAF/Assets/Characters/Character.cs b/NetAF/Assets/Characters/Character.cs index c989bac4..43b44004 100644 --- a/NetAF/Assets/Characters/Character.cs +++ b/NetAF/Assets/Characters/Character.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using NetAF.Assets.Interaction; using NetAF.Extensions; using NetAF.Serialization; using NetAF.Serialization.Assets; @@ -32,8 +31,8 @@ public abstract class Character : ExaminableObject, IInteractWithItem, IItemCont /// Interact with a specified item. /// /// The item to interact with. - /// The result of the interaction. - protected virtual InteractionResult InteractWithItem(Item item) + /// The interaction. + protected virtual Interaction InteractWithItem(Item item) { return Interaction.Invoke(item); } @@ -103,8 +102,8 @@ public virtual bool Give(Item item, Character character) /// Interact with an item. /// /// The item to interact with. - /// The result of the interaction. - public InteractionResult Interact(Item item) + /// The interaction. + public Interaction Interact(Item item) { return InteractWithItem(item); } diff --git a/NetAF/Assets/Characters/NonPlayableCharacter.cs b/NetAF/Assets/Characters/NonPlayableCharacter.cs index d363c9cd..af8971ee 100644 --- a/NetAF/Assets/Characters/NonPlayableCharacter.cs +++ b/NetAF/Assets/Characters/NonPlayableCharacter.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands; +using NetAF.Commands; using NetAF.Conversations; using NetAF.Serialization; using NetAF.Serialization.Assets; @@ -41,7 +40,7 @@ public NonPlayableCharacter(Identifier identifier, Description description, Conv Description = description; Conversation = conversation; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; diff --git a/NetAF/Assets/Characters/PlayableCharacter.cs b/NetAF/Assets/Characters/PlayableCharacter.cs index 2bcb6eb0..e7319d15 100644 --- a/NetAF/Assets/Characters/PlayableCharacter.cs +++ b/NetAF/Assets/Characters/PlayableCharacter.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands; +using NetAF.Commands; namespace NetAF.Assets.Characters { @@ -76,7 +75,7 @@ public PlayableCharacter(Identifier identifier, Description description, bool ca CanConverse = canConverse; Items = items ?? []; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; @@ -91,8 +90,8 @@ public PlayableCharacter(Identifier identifier, Description description, bool ca /// /// The item to use. /// A target object to use the item on. - /// The result of the items usage. - public InteractionResult UseItem(Item item, IInteractWithItem targetObject) + /// The interaction. + public Interaction UseItem(Item item, IInteractWithItem targetObject) { return targetObject.Interact(item); } diff --git a/NetAF/Assets/Interaction/IInteractWithItem.cs b/NetAF/Assets/IInteractWithItem.cs similarity index 67% rename from NetAF/Assets/Interaction/IInteractWithItem.cs rename to NetAF/Assets/IInteractWithItem.cs index 80cb6af0..48199a99 100644 --- a/NetAF/Assets/Interaction/IInteractWithItem.cs +++ b/NetAF/Assets/IInteractWithItem.cs @@ -1,4 +1,4 @@ -namespace NetAF.Assets.Interaction +namespace NetAF.Assets { /// /// Represents any object that can interact with an item. @@ -9,7 +9,7 @@ public interface IInteractWithItem /// Interact with an item. /// /// The item to interact with. - /// The result of the interaction. - InteractionResult Interact(Item item); + /// The interaction. + Interaction Interact(Item item); } } \ No newline at end of file diff --git a/NetAF/Assets/Interaction.cs b/NetAF/Assets/Interaction.cs new file mode 100644 index 00000000..e51e3b68 --- /dev/null +++ b/NetAF/Assets/Interaction.cs @@ -0,0 +1,61 @@ +using System; + +namespace NetAF.Assets +{ + /// + /// Represents an interaction. + /// + public sealed class Interaction : Result + { + #region Properties + + /// + /// Get the result. + /// + public InteractionResult Result { get; } + + /// + /// Get the item used in the interaction. + /// + public Item Item { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the Interaction class. + /// + /// The result of the interaction. + /// The item used in the interaction. + public Interaction(InteractionResult result, Item item) + { + Result = 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.", + _ => throw new NotImplementedException($"No implementation for ${result}."), + }; + } + + /// + /// Initializes a new instance of the Interaction class. + /// + /// The result of the interaction. + /// The item used in the interaction. + /// A description of the effect. + public Interaction(InteractionResult result, Item item, string descriptionOfEffect) + { + Result = result; + Item = item; + Description = descriptionOfEffect; + } + + #endregion + } +} \ No newline at end of file diff --git a/NetAF/Assets/Interaction/InteractionCallback.cs b/NetAF/Assets/Interaction/InteractionCallback.cs deleted file mode 100644 index b3b09dce..00000000 --- a/NetAF/Assets/Interaction/InteractionCallback.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace NetAF.Assets.Interaction -{ - /// - /// Represents the callback for interacting with objects. - /// - /// The item to interact with. - /// The result of the interaction. - public delegate InteractionResult InteractionCallback(Item item); -} \ No newline at end of file diff --git a/NetAF/Assets/Interaction/InteractionResult.cs b/NetAF/Assets/Interaction/InteractionResult.cs deleted file mode 100644 index a06004e8..00000000 --- a/NetAF/Assets/Interaction/InteractionResult.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; - -namespace NetAF.Assets.Interaction -{ - /// - /// Represents a result of an interaction. - /// - public sealed class InteractionResult : Result - { - #region Properties - - /// - /// Get the effect. - /// - public InteractionEffect Effect { get; } - - /// - /// Get the item used in the interaction. - /// - public Item Item { get; } - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the InteractionResult class. - /// - /// The effect of this interaction. - /// The item used in this interaction. - public InteractionResult(InteractionEffect effect, Item item) - { - Effect = effect; - Item = item; - - Description = effect switch - { - InteractionEffect.NeitherItemOrTargetExpired => "There was no effect.", - InteractionEffect.ItemExpired => "The item expired.", - InteractionEffect.TargetExpired => "The target expired.", - InteractionEffect.ItemAndTargetExpired => "Both the item and target expired.", - _ => throw new NotImplementedException($"No implementation for ${effect}."), - }; - } - - /// - /// Initializes a new instance of the InteractionResult class. - /// - /// The effect of this interaction. - /// The item used in this interaction. - /// A description of the effect. - public InteractionResult(InteractionEffect effect, Item item, string descriptionOfEffect) - { - Effect = effect; - Item = item; - Description = descriptionOfEffect; - } - - #endregion - } -} \ No newline at end of file diff --git a/NetAF/Assets/InteractionCallback.cs b/NetAF/Assets/InteractionCallback.cs new file mode 100644 index 00000000..0a100d10 --- /dev/null +++ b/NetAF/Assets/InteractionCallback.cs @@ -0,0 +1,9 @@ +namespace NetAF.Assets +{ + /// + /// Represents the callback for interacting with objects. + /// + /// The item to interact with. + /// The interaction. + public delegate Interaction InteractionCallback(Item item); +} \ No newline at end of file diff --git a/NetAF/Assets/Interaction/InteractionEffect.cs b/NetAF/Assets/InteractionResult.cs similarity index 81% rename from NetAF/Assets/Interaction/InteractionEffect.cs rename to NetAF/Assets/InteractionResult.cs index 35b7abf6..87f94d1e 100644 --- a/NetAF/Assets/Interaction/InteractionEffect.cs +++ b/NetAF/Assets/InteractionResult.cs @@ -1,9 +1,9 @@ -namespace NetAF.Assets.Interaction +namespace NetAF.Assets { /// - /// Enumeration of interaction effects. + /// Enumeration of interaction results. /// - public enum InteractionEffect + public enum InteractionResult { /// /// Neither the item or the target expired. diff --git a/NetAF/Assets/Item.cs b/NetAF/Assets/Item.cs index f43ca8cc..f5fa55d5 100644 --- a/NetAF/Assets/Item.cs +++ b/NetAF/Assets/Item.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands; +using NetAF.Commands; using NetAF.Serialization; using NetAF.Serialization.Assets; @@ -54,7 +53,7 @@ public Item(Identifier identifier, Description description, bool isTakeable = fa Description = description; IsTakeable = isTakeable; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; @@ -68,8 +67,8 @@ public Item(Identifier identifier, Description description, bool isTakeable = fa /// Interact with an item. /// /// The item to interact with. - /// The result of the interaction. - public InteractionResult Interact(Item item) + /// The interaction. + public Interaction Interact(Item item) { return Interaction.Invoke(item); } diff --git a/NetAF/Assets/Locations/Exit.cs b/NetAF/Assets/Locations/Exit.cs index d414db9b..97a7ae21 100644 --- a/NetAF/Assets/Locations/Exit.cs +++ b/NetAF/Assets/Locations/Exit.cs @@ -1,5 +1,4 @@ -using NetAF.Assets.Interaction; -using NetAF.Commands; +using NetAF.Commands; using NetAF.Serialization; using NetAF.Serialization.Assets; @@ -48,7 +47,7 @@ public Exit(Direction direction, bool isLocked = false, Identifier identifier = Description = description ?? GenerateDescription(); IsLocked = isLocked; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; @@ -91,8 +90,8 @@ public void Lock() /// Interact with an item. /// /// The item to interact with. - /// The result of the interaction. - public InteractionResult Interact(Item item) + /// The interaction. + public Interaction Interact(Item item) { return Interaction.Invoke(item); } diff --git a/NetAF/Assets/Locations/Room.cs b/NetAF/Assets/Locations/Room.cs index 2aa64d77..3959b1de 100644 --- a/NetAF/Assets/Locations/Room.cs +++ b/NetAF/Assets/Locations/Room.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Commands; using NetAF.Extensions; using NetAF.Serialization; @@ -90,7 +89,7 @@ public Room(Identifier identifier, Description description, Exit[] exits = null, Exits = exits ?? []; Items = items ?? []; Commands = commands ?? []; - Interaction = interaction ?? (i => new(InteractionEffect.NeitherItemOrTargetExpired, i)); + Interaction = interaction ?? (i => new(InteractionResult.NeitherItemOrTargetExpired, i)); if (examination != null) Examination = examination; @@ -163,8 +162,8 @@ public bool CanMove(Direction direction) /// Interact with a specified item. /// /// The item to interact with. - /// The result of the interaction. - private InteractionResult InteractWithItem(Item item) + /// The interaction. + private Interaction InteractWithItem(Item item) { return Interaction.Invoke(item); } @@ -431,8 +430,8 @@ public void MovedInto(Direction? fromDirection) /// Interact with an item. /// /// The item to interact with. - /// The result of the interaction. - public InteractionResult Interact(Item item) + /// The interaction. + public Interaction Interact(Item item) { return InteractWithItem(item); } diff --git a/NetAF/Commands/Scene/UseOn.cs b/NetAF/Commands/Scene/UseOn.cs index 277f232a..7e75c503 100644 --- a/NetAF/Commands/Scene/UseOn.cs +++ b/NetAF/Commands/Scene/UseOn.cs @@ -3,7 +3,6 @@ using System.Linq; using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Logic; namespace NetAF.Commands.Scene @@ -102,17 +101,17 @@ public Reaction Invoke(Logic.Game game) var result = target.Interact(item); - switch (result.Effect) + switch (result.Result) { - case InteractionEffect.NeitherItemOrTargetExpired: + case InteractionResult.NeitherItemOrTargetExpired: break; - case InteractionEffect.ItemExpired: + case InteractionResult.ItemExpired: ItemExpired(game, item); break; - case InteractionEffect.TargetExpired: + case InteractionResult.TargetExpired: TargetExpired(game, target); break; - case InteractionEffect.ItemAndTargetExpired: + case InteractionResult.ItemAndTargetExpired: ItemExpired(game, item); TargetExpired(game, target); break; diff --git a/NetAF/Interpretation/SceneCommandInterpreter.cs b/NetAF/Interpretation/SceneCommandInterpreter.cs index 4012ee05..2d721d21 100644 --- a/NetAF/Interpretation/SceneCommandInterpreter.cs +++ b/NetAF/Interpretation/SceneCommandInterpreter.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using NetAF.Assets; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Commands; using NetAF.Commands.Scene; diff --git a/NetAF/Logic/Game.cs b/NetAF/Logic/Game.cs index 32067eb7..cb6786a1 100644 --- a/NetAF/Logic/Game.cs +++ b/NetAF/Logic/Game.cs @@ -3,7 +3,6 @@ using System.Linq; using NetAF.Assets; using NetAF.Assets.Characters; -using NetAF.Assets.Interaction; using NetAF.Assets.Locations; using NetAF.Commands; using NetAF.Commands.Scene; diff --git a/NetAF/NetAF.csproj b/NetAF/NetAF.csproj index e53cc6e8..31e4c6be 100644 --- a/NetAF/NetAF.csproj +++ b/NetAF/NetAF.csproj @@ -44,4 +44,8 @@ + + + + From d24b3d7bc20f3ca0e6f34c3960fa45274bfef7c6 Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 16:43:48 +0000 Subject: [PATCH 5/8] Updated docs --- docs/docfx/docs/items.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docfx/docs/items.md b/docs/docfx/docs/items.md index 1ee6aea0..0674c0a9 100644 --- a/docs/docfx/docs/items.md +++ b/docs/docfx/docs/items.md @@ -33,7 +33,7 @@ Item bomb = new("Bomb", "A bomb", commands: ## Interaction -Interactions can be set up between different assets in the game. The **InteractionResult** contains the result of the interaction, and allows the game to react to the interaction. +Interactions can be set up between different assets in the game. The **Interaction** contains the result of the interaction, and allows the game to react to the interaction. ```csharp var dartsBoard = new Item("Darts board", "A darts board."); @@ -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 InteractionResult(InteractionEffect.SelfContained, item, "The dart stuck in the darts board."); + return new Interaction(InteractionResult.NeitherItemOrTargetExpired, item, "The dart stuck in the darts board."); - return new InteractionResult(InteractionEffect.NoEffect, item); + return new Interaction(InteractionResult.NeitherItemOrTargetExpired, item); }); ``` \ No newline at end of file From ff0d2c4af7f37c322935df4223a454d9c667af98 Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 16:49:44 +0000 Subject: [PATCH 6/8] Fixed sonar suggestions --- NetAF/Assets/Characters/PlayableCharacter.cs | 15 --------------- NetAF/Commands/Scene/UseOn.cs | 16 +++++----------- NetAF/NetAF.csproj | 10 ++++++---- docs/docfx/docs/playable-character.md | 8 -------- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/NetAF/Assets/Characters/PlayableCharacter.cs b/NetAF/Assets/Characters/PlayableCharacter.cs index e7319d15..cd028611 100644 --- a/NetAF/Assets/Characters/PlayableCharacter.cs +++ b/NetAF/Assets/Characters/PlayableCharacter.cs @@ -82,20 +82,5 @@ public PlayableCharacter(Identifier identifier, Description description, bool ca } #endregion - - #region Methods - - /// - /// Use an item. - /// - /// The item to use. - /// A target object to use the item on. - /// The interaction. - public Interaction UseItem(Item item, IInteractWithItem targetObject) - { - return targetObject.Interact(item); - } - - #endregion } } \ No newline at end of file diff --git a/NetAF/Commands/Scene/UseOn.cs b/NetAF/Commands/Scene/UseOn.cs index 7e75c503..fa7696f7 100644 --- a/NetAF/Commands/Scene/UseOn.cs +++ b/NetAF/Commands/Scene/UseOn.cs @@ -42,12 +42,9 @@ private static void ItemExpired(Game game, Item item) containers.Add(game.Player); containers.Add(game.Overworld.CurrentRegion.CurrentRoom); containers.AddRange(game.Overworld.CurrentRegion.CurrentRoom.Characters ?? []); - - foreach (var container in containers) - { - if (container.Items.Contains(item)) - container.RemoveItem(item); - } + + foreach (var container in from IItemContainer container in containers where container.Items.Contains(item) select container) + container.RemoveItem(item); } /// @@ -62,11 +59,8 @@ private static void TargetExpired(Game game, IInteractWithItem target) if (target is Item item) { - foreach (var npc in game.Overworld.CurrentRegion.CurrentRoom.Characters ?? []) - { - if (npc.HasItem(item)) - npc.RemoveItem(item); - } + foreach (var npc in from NonPlayableCharacter npc in game.Overworld.CurrentRegion.CurrentRoom.Characters ?? [] where npc.HasItem(item) select npc) + npc.RemoveItem(item); if (game.Player.HasItem(item)) game.Player.RemoveItem(item); diff --git a/NetAF/NetAF.csproj b/NetAF/NetAF.csproj index 31e4c6be..767af950 100644 --- a/NetAF/NetAF.csproj +++ b/NetAF/NetAF.csproj @@ -23,6 +23,12 @@ 12.0 + + + + + + <_Parameter1>NetAF.Tests @@ -44,8 +50,4 @@ - - - - diff --git a/docs/docfx/docs/playable-character.md b/docs/docfx/docs/playable-character.md index b51aa109..dd0240ec 100644 --- a/docs/docfx/docs/playable-character.md +++ b/docs/docfx/docs/playable-character.md @@ -34,14 +34,6 @@ A PlayableCharacter can lose an item with the **RemoveItem** method. player.RemoveItem(mallet); ``` -A PlayableCharacter can use an item on another asset: - -```csharp -var trapDoor = new Exit(Direction.Down); -var mallet = new Item("Mallet", "A large mallet."); -player.UseItem(mallet, trapDoor); -``` - A PlayableCharacter can give an item to a non-playable character. ```csharp From cdc0fea99cd2b9a966290085af920eb01e7dc7eb Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 17:02:44 +0000 Subject: [PATCH 7/8] Improved coverage --- NetAF.Tests/Commands/Scene/UseOn_Tests.cs | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs index 41644de5..1637f798 100644 --- a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs +++ b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs @@ -102,5 +102,73 @@ public void GivenTargetIsRoom_WhenInvoke_ThenInform() Assert.AreEqual(ReactionResult.Inform, result.Result); } + + [TestMethod] + public void GivenItemOnRoomInteractionCausesItemExpire_WhenInvoke_ThenItemRemovedFromRoom() + { + 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); + }); + 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, room); + command.Invoke(game); + + var result = room.ContainsItem(item); + + Assert.IsFalse(result); + } + + [TestMethod] + public void GivenItemOnPlayerInteractionCausesTargetExpire_WhenInvoke_ThenPlayerNotAlive() + { + var item = new Item(Identifier.Empty, Description.Empty, true); + var room = new Room(Identifier.Empty, Description.Empty, items: [item]); + 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, interaction: (i) => + { + return new Interaction(InteractionResult.TargetExpired, 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); + command.Invoke(game); + + var result = player.IsAlive; + + Assert.IsFalse(result); + } + + [TestMethod] + public void GivenItemOnPlayerInteractionCausesItemAndTargetExpire_WhenInvoke_ThenPlayerNotAliveAndItemNotInRoom() + { + var item = new Item(Identifier.Empty, Description.Empty, true); + var room = new Room(Identifier.Empty, Description.Empty, items: [item]); + 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, interaction: (i) => + { + return new Interaction(InteractionResult.ItemAndTargetExpired, 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); + command.Invoke(game); + + var result1 = player.IsAlive; + var result2 = room.ContainsItem(item); + + Assert.IsFalse(result1); + Assert.IsFalse(result2); + } } } From cc748fb7c238e4b07f477a8329cf4d992d5f46a5 Mon Sep 17 00:00:00 2001 From: ben_singer Date: Sun, 17 Nov 2024 17:17:04 +0000 Subject: [PATCH 8/8] Inproved coverage --- NetAF.Tests/Commands/Scene/UseOn_Tests.cs | 47 +++++++++++++++++++++++ NetAF/Commands/Scene/UseOn.cs | 20 ++++++---- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs index 1637f798..e5bb3e19 100644 --- a/NetAF.Tests/Commands/Scene/UseOn_Tests.cs +++ b/NetAF.Tests/Commands/Scene/UseOn_Tests.cs @@ -170,5 +170,52 @@ public void GivenItemOnPlayerInteractionCausesItemAndTargetExpire_WhenInvoke_The Assert.IsFalse(result1); Assert.IsFalse(result2); } + + [TestMethod] + public void GivenItemOnPlayerInteractionCausesItemExpire_WhenInvoke_ThenPlayerDoesNotHaveItem() + { + var item = new Item(Identifier.Empty, Description.Empty, true); + var room = new Room(Identifier.Empty, Description.Empty); + 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, items: [item], interaction: (i) => + { + return new Interaction(InteractionResult.ItemExpired, 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); + command.Invoke(game); + + var result = player.HasItem(item); + + Assert.IsFalse(result); + } + + [TestMethod] + public void GivenItemOnNonPlayableCharacterInteractionCausesItemExpire_WhenInvoke_ThenNonPlayableCharacterDoesNotHaveItem() + { + 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); + }); + 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 = npc.HasItem(item); + + Assert.IsFalse(result); + } } } diff --git a/NetAF/Commands/Scene/UseOn.cs b/NetAF/Commands/Scene/UseOn.cs index fa7696f7..8e9ce4f3 100644 --- a/NetAF/Commands/Scene/UseOn.cs +++ b/NetAF/Commands/Scene/UseOn.cs @@ -35,7 +35,8 @@ public sealed class UseOn(Item item, IInteractWithItem target) : ICommand /// /// The game. /// The item that expired. - private static void ItemExpired(Game game, Item item) + /// The target that the item was used on. + private static void ItemExpired(Game game, Item item, IInteractWithItem target) { List containers = []; @@ -43,7 +44,10 @@ private static void ItemExpired(Game game, Item item) containers.Add(game.Overworld.CurrentRegion.CurrentRoom); containers.AddRange(game.Overworld.CurrentRegion.CurrentRoom.Characters ?? []); - foreach (var container in from IItemContainer container in containers where container.Items.Contains(item) select container) + if (target is IItemContainer targetContainer) + containers.Add(targetContainer); + + foreach (var container in from IItemContainer container in containers.Distinct() where container.Items.Contains(item) select container) container.RemoveItem(item); } @@ -51,7 +55,7 @@ private static void ItemExpired(Game game, Item item) /// Handle a target expiring. /// /// The game. - /// The item that expired. + /// The target that expired. private static void TargetExpired(Game game, IInteractWithItem target) { if (target is IExaminable examinable && game.Overworld.CurrentRegion.CurrentRoom.ContainsInteractionTarget(examinable.Identifier.Name)) @@ -93,27 +97,27 @@ public Reaction Invoke(Logic.Game game) if (game.Player == null) return new(ReactionResult.Error, "You must specify the character that is using this item."); - var result = target.Interact(item); + var interaction = target.Interact(item); - switch (result.Result) + switch (interaction.Result) { case InteractionResult.NeitherItemOrTargetExpired: break; case InteractionResult.ItemExpired: - ItemExpired(game, item); + ItemExpired(game, item, target); break; case InteractionResult.TargetExpired: TargetExpired(game, target); break; case InteractionResult.ItemAndTargetExpired: - ItemExpired(game, item); + ItemExpired(game, item, target); TargetExpired(game, target); break; default: throw new NotImplementedException(); } - return new(ReactionResult.Inform, result.Description); + return new(ReactionResult.Inform, interaction.Description); } #endregion