Skip to content

Commit

Permalink
Merge pull request #97 from benpollarduk/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
benpollarduk authored Nov 17, 2024
2 parents ccc59d0 + cc748fb commit 15e7491
Show file tree
Hide file tree
Showing 118 changed files with 605 additions and 734 deletions.
14 changes: 7 additions & 7 deletions NetAF.Examples/Assets/Player/Player.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(InteractionResult.NeitherItemOrTargetExpired, null);
if (Knife.Name.EqualsExaminable(i))
return new(InteractionEffect.FatalEffect, 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.NoEffect, 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.NoEffect, 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.NoEffect, i);
return new(InteractionResult.NeitherItemOrTargetExpired, i);
});

return player;
Expand Down
10 changes: 4 additions & 6 deletions NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NetAF.Assets;
using NetAF.Assets.Interaction;
using NetAF.Examples.Assets.Items;
using NetAF.Utilities;

Expand All @@ -24,11 +23,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(InteractionResult.TargetExpired, item, "You slash at the conch shell and it shatters into tiny pieces. Without the conch shell you are well and truly in trouble.");
return new(InteractionResult.NeitherItemOrTargetExpired, item);
});

return conchShell;
Expand Down
7 changes: 3 additions & 4 deletions NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,13 +30,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(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.NoEffect, 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.NoEffect, 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));
Expand Down
12 changes: 6 additions & 6 deletions NetAF.Examples/Assets/Regions/Flat/Flat.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(InteractionResult.ItemExpired, item, "The lead fits snugly into the input socket on the amp.");
}
if (Guitar.Name.EqualsIdentifier(item.Identifier))
Expand All @@ -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(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.NoEffect, 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.NoEffect, 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.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
}).Instantiate();

var regionMaker = new RegionMaker(Name, Description)
Expand Down
5 changes: 2 additions & 3 deletions NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NetAF.Assets;
using NetAF.Assets.Interaction;
using NetAF.Extensions;
using NetAF.Utilities;

Expand All @@ -26,10 +25,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(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.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
});
}

Expand Down
5 changes: 2 additions & 3 deletions NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NetAF.Assets;
using NetAF.Assets.Interaction;
using NetAF.Extensions;
using NetAF.Utilities;

Expand All @@ -25,9 +24,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(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.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
});
}

Expand Down
6 changes: 3 additions & 3 deletions NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(InteractionResult.NeitherItemOrTargetExpired, item, "Playing guitar in the kitchen is pretty stupid don't you think?");
return new(InteractionEffect.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
});

room.AddItem(new HamsterCage().Instantiate());
Expand Down
11 changes: 5 additions & 6 deletions NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,23 +36,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(InteractionResult.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(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.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(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.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(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.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
});

room.AddCharacter(new Beth().Instantiate());
Expand Down
1 change: 0 additions & 1 deletion NetAF.Examples/Assets/Regions/Flat/Rooms/SpareBedroom.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion NetAF.Examples/Assets/Regions/Zelda/Items/Bush.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NetAF.Assets;
using NetAF.Assets.Interaction;
using NetAF.Utilities;

namespace NetAF.Examples.Assets.Regions.Zelda.Items
Expand Down
1 change: 0 additions & 1 deletion NetAF.Examples/Assets/Regions/Zelda/Items/TailDoor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NetAF.Assets;
using NetAF.Assets.Interaction;
using NetAF.Utilities;

namespace NetAF.Examples.Assets.Regions.Zelda.Items
Expand Down
15 changes: 7 additions & 8 deletions NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,29 +59,28 @@ 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(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.NoEffect, 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)
{
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(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.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(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.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
});

saria.AddItem(new TailKey().Instantiate());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,13 +35,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(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.NoEffect, item, "Clang clang!");
return new(InteractionResult.NeitherItemOrTargetExpired, item, "Clang clang!");
return new(InteractionEffect.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
}).Instantiate();

room.AddItem(door);
Expand Down
6 changes: 2 additions & 4 deletions NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,11 +38,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(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.NoEffect, item);
return new(InteractionResult.NeitherItemOrTargetExpired, item);
}).Instantiate();

rupee.IsPlayerVisible = false;
Expand Down
1 change: 0 additions & 1 deletion NetAF.Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
21 changes: 0 additions & 21 deletions NetAF.Tests/Assets/Characters/PlayableCharacter_Tests.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -61,25 +60,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);
}
}
}
1 change: 0 additions & 1 deletion NetAF.Tests/Assets/ExaminableObject_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NetAF.Assets;
using NetAF.Assets.Interaction;
using NetAF.Commands;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down
Loading

0 comments on commit 15e7491

Please sign in to comment.