Skip to content

Commit

Permalink
More refactoring of Interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ben_singer committed Nov 17, 2024
1 parent 15e7491 commit 50bab1b
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 83 deletions.
10 changes: 5 additions & 5 deletions NetAF.Examples/Assets/Player/Player.cs
Original file line number Diff line number Diff line change
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(InteractionResult.NeitherItemOrTargetExpired, null);
return new(InteractionResult.NoChange, null);

if (Knife.Name.EqualsExaminable(i))
return new(InteractionResult.TargetExpired, i, "You slash wildly at your own throat. You are dead.");
return new(InteractionResult.TargetExpires, i, "You slash wildly at your own throat. You are dead.");

if (CoffeeMug.Name.EqualsIdentifier(i.Identifier))
return new(InteractionResult.NeitherItemOrTargetExpired, i, "If there was some coffee in the mug you could drink it.");
return new(InteractionResult.NoChange, i, "If there was some coffee in the mug you could drink it.");

if (Guitar.Name.EqualsIdentifier(i.Identifier))
return new(InteractionResult.NeitherItemOrTargetExpired, i, "You bust out some Bad Religion. Cracking, shame the guitar isn't plugged in to an amplified though...");
return new(InteractionResult.NoChange, i, "You bust out some Bad Religion. Cracking, shame the guitar isn't plugged in to an amplified though...");

return new(InteractionResult.NeitherItemOrTargetExpired, i);
return new(InteractionResult.NoChange, i);
});

return player;
Expand Down
4 changes: 2 additions & 2 deletions NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public Item Instantiate()
var conchShell = new Item(Name, Description, true, interaction: item =>
{
if (item.Identifier.Equals(Knife.Name))
return new(InteractionResult.TargetExpired, item, "You slash at the conch shell and it shatters into tiny pieces. Without the conch shell you are well and truly in trouble.");
return new(InteractionResult.TargetExpires, item, "You slash at the conch shell and it shatters into tiny pieces. Without the conch shell you are well and truly in trouble.");

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
});

return conchShell;
Expand Down
6 changes: 3 additions & 3 deletions NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public Room Instantiate()
if (item != null && ConchShell.Name.EqualsExaminable(item))
{
room[Direction.North].Unlock();
return new(InteractionResult.ItemExpired, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces.");
return new(InteractionResult.ItemExpires, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces.");
}

if (item != null && Knife.Name.EqualsExaminable(item))
return new(InteractionResult.NeitherItemOrTargetExpired, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!");
return new(InteractionResult.NoChange, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!");

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
});

room.SpecifyConditionalDescription(new ConditionalDescription("With the bats gone there is daylight to the north. To the west is the cave entrance", "As you enter the inner cave the screeching gets louder, and in the gloom you can make out what looks like a million sets of eyes looking back at you. Bats! You can just make out a few rays of light coming from the north, but the bats are blocking your way.", () => !room[Direction.North].IsLocked));
Expand Down
10 changes: 5 additions & 5 deletions NetAF.Examples/Assets/Regions/Flat/Flat.cs
Original file line number Diff line number Diff line change
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(InteractionResult.ItemExpired, item, "The lead fits snugly into the input socket on the amp.");
return new(InteractionResult.ItemExpires, item, "The lead fits snugly into the input socket on the amp.");
}

if (Guitar.Name.EqualsIdentifier(item.Identifier))
Expand All @@ -48,16 +48,16 @@ public Region Instantiate()
if (lounge.FindCharacter(Beth.Name, out var b))
{
lounge.RemoveCharacter(b);
return new(InteractionResult.NeitherItemOrTargetExpired, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings. Beth's had enough! She bolts for the front door leaving it wide open! You are free to leave the flat! You unplug the guitar.");
return new(InteractionResult.NoChange, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings. Beth's had enough! She bolts for the front door leaving it wide open! You are free to leave the flat! You unplug the guitar.");
}

return new(InteractionResult.NeitherItemOrTargetExpired, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings.");
return new(InteractionResult.NoChange, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings.");
}

return new(InteractionResult.NeitherItemOrTargetExpired, item, "You have no lead so you can't use the guitar with the amp...");
return new(InteractionResult.NoChange, item, "You have no lead so you can't use the guitar with the amp...");
}

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
}).Instantiate();

var regionMaker = new RegionMaker(Name, Description)
Expand Down
4 changes: 2 additions & 2 deletions NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public Item Instantiate()
{
if (Kettle.Name.EqualsIdentifier(item.Identifier))
{
return new(InteractionResult.NeitherItemOrTargetExpired, item, "You put some instant coffee graduals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!");
return new(InteractionResult.NoChange, item, "You put some instant coffee graduals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!");
}

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
});
}

Expand Down
4 changes: 2 additions & 2 deletions NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public Item Instantiate()
return new(Name, Description, interaction: item =>
{
if (item != null && CoffeeMug.Name.EqualsIdentifier(item.Identifier))
return new(InteractionResult.NeitherItemOrTargetExpired, item, "You put some instant coffee granuals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!");
return new(InteractionResult.NoChange, item, "You put some instant coffee granuals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!");

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
});
}

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

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
});

room.AddItem(new HamsterCage().Instantiate());
Expand Down
10 changes: 5 additions & 5 deletions NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ public Room Instantiate()
if (CoffeeMug.Name.EqualsIdentifier(item.Identifier))
{
if (room.ContainsCharacter(Beth.Name))
return new(InteractionResult.ItemExpired, item, "Beth takes the cup of coffee and smiles. Brownie points to you!");
return new(InteractionResult.ItemExpires, item, "Beth takes the cup of coffee and smiles. Brownie points to you!");

return new(InteractionResult.NeitherItemOrTargetExpired, item, "As no one is about you decide to drink the coffee yourself. Your nose wasn't lying, it is bitter but delicious.");
return new(InteractionResult.NoChange, item, "As no one is about you decide to drink the coffee yourself. Your nose wasn't lying, it is bitter but delicious.");

}

if (CoffeeMug.Name.EqualsIdentifier(item.Identifier))
{
room.AddItem(item);
return new(InteractionResult.ItemExpired, item, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed.");
return new(InteractionResult.ItemExpires, item, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed.");
}

if (Guitar.Name.EqualsIdentifier(item.Identifier))
return new(InteractionResult.NeitherItemOrTargetExpired, item, "You strum the guitar frantically trying to impress Beth, she smiles but looks at you like you are a fool. The guitar just isn't loud enough when it is not plugged in...");
return new(InteractionResult.NoChange, item, "You strum the guitar frantically trying to impress Beth, she smiles but looks at you like you are a fool. The guitar just isn't loud enough when it is not plugged in...");
}

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
});

room.AddCharacter(new Beth().Instantiate());
Expand Down
10 changes: 5 additions & 5 deletions NetAF.Examples/Assets/Regions/Zelda/NPCs/Saria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ public NonPlayableCharacter Instantiate()
{
saria.RemoveItem(key);
room.AddItem(key);
return new(InteractionResult.ItemExpired, item, $"{saria.Identifier.Name} looks excited! \"Thanks Link, here take the Tail Key!\" Saria put the Tail Key down, awesome!");
return new(InteractionResult.ItemExpires, item, $"{saria.Identifier.Name} looks excited! \"Thanks Link, here take the Tail Key!\" Saria put the Tail Key down, awesome!");
}

if (Shield.Name.EqualsIdentifier(item.Identifier))
{
return new(InteractionResult.NeitherItemOrTargetExpired, item, $"{saria.Identifier.Name} looks at your shield, but seems pretty unimpressed.");
return new(InteractionResult.NoChange, item, $"{saria.Identifier.Name} looks at your shield, but seems pretty unimpressed.");
}

if (Sword.Name.EqualsIdentifier(item.Identifier) && saria.IsAlive)
{
saria.Kill();

if (!saria.HasItem(key))
return new(InteractionResult.NeitherItemOrTargetExpired, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead.");
return new(InteractionResult.NoChange, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead.");

saria.RemoveItem(key);
room.AddItem(key);

return new(InteractionResult.NeitherItemOrTargetExpired, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead. When she fell you saw something drop to out of her hand, it looked like a key...");
return new(InteractionResult.NoChange, item, $"You strike {saria.Identifier.Name} in the face with the sword and she falls down dead. When she fell you saw something drop to out of her hand, it looked like a key...");
}

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
});

saria.AddItem(new TailKey().Instantiate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public Room Instantiate()
exit.Unlock();

room.RemoveItem(door);
return new(InteractionResult.ItemExpired, item, "The Tail Key fits perfectly in the lock, you turn it and the door swings open, revealing a gaping cave mouth...");
return new(InteractionResult.ItemExpires, item, "The Tail Key fits perfectly in the lock, you turn it and the door swings open, revealing a gaping cave mouth...");
}

if (Sword.Name.EqualsExaminable(item))
return new(InteractionResult.NeitherItemOrTargetExpired, item, "Clang clang!");
return new(InteractionResult.NoChange, item, "Clang clang!");

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
}).Instantiate();

room.AddItem(door);
Expand Down
4 changes: 2 additions & 2 deletions NetAF.Examples/Assets/Regions/Zelda/Rooms/Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public Room Instantiate()
if (Sword.Name.EqualsExaminable(item))
{
rupee.IsPlayerVisible = true;
return new(InteractionResult.TargetExpired, item, "You slash wildly at the bush and reduce it to a stump. This exposes a red rupee, that must have been what was glinting from within the bush...");
return new(InteractionResult.TargetExpires, item, "You slash wildly at the bush and reduce it to a stump. This exposes a red rupee, that must have been what was glinting from within the bush...");
}

return new(InteractionResult.NeitherItemOrTargetExpired, item);
return new(InteractionResult.NoChange, item);
}).Instantiate();

rupee.IsPlayerVisible = false;
Expand Down
32 changes: 21 additions & 11 deletions NetAF.Tests/Assets/Interaction_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Interaction_Tests
[TestMethod]
public void GivenConstructor_WhenExplicitDescription_ThenDescriptionIsAsSpecified()
{
Interaction instance = new(InteractionResult.NeitherItemOrTargetExpired, null, "A");
Interaction instance = new(InteractionResult.NoChange, null, "A");

var result = instance.Description;

Expand All @@ -19,41 +19,51 @@ public void GivenConstructor_WhenExplicitDescription_ThenDescriptionIsAsSpecifie
[TestMethod]
public void GivenConstructor_WhenItemUsedUp_ThenGeneratedDescriptionIsCorrect()
{
Interaction instance = new(InteractionResult.ItemExpired, null);
Interaction instance = new(InteractionResult.ItemExpires, null);

var result = instance.Description;

Assert.AreEqual("The item expired.", result);
Assert.AreEqual("The item expires.", result);
}

[TestMethod]
public void GivenConstructor_WhenItemAndTargetExpired_ThenGeneratedDescriptionIsCorrect()
public void GivenConstructor_WhenItemAndTargetExpires_ThenGeneratedDescriptionIsCorrect()
{
Interaction instance = new(InteractionResult.ItemAndTargetExpired, null);
Interaction instance = new(InteractionResult.ItemAndTargetExpires, null);

var result = instance.Description;

Assert.AreEqual("Both the item and target expired.", result);
Assert.AreEqual("Both the item and target expires.", result);
}

[TestMethod]
public void GivenConstructor_WhenNeitherItemOrTargetExpired_ThenGeneratedDescriptionIsCorrect()
public void GivenConstructor_WhenNoChange_ThenGeneratedDescriptionIsCorrect()
{
Interaction instance = new(InteractionResult.NeitherItemOrTargetExpired, null);
Interaction instance = new(InteractionResult.NoChange, null);

var result = instance.Description;

Assert.AreEqual("There was no effect.", result);
}

[TestMethod]
public void GivenConstructor_WhenTargetExpired_ThenGeneratedDescriptionIsCorrect()
public void GivenConstructor_WhenTargetExpires_ThenGeneratedDescriptionIsCorrect()
{
Interaction instance = new(InteractionResult.TargetExpired, null);
Interaction instance = new(InteractionResult.TargetExpires, null);

var result = instance.Description;

Assert.AreEqual("The target expired.", result);
Assert.AreEqual("The target expires.", result);
}

[TestMethod]
public void GivenConstructor_WhenPlayerDies_ThenGeneratedDescriptionIsCorrect()
{
Interaction instance = new(InteractionResult.PlayerDies, null);

var result = instance.Description;

Assert.AreEqual("The player dies.", result);
}
}
}
4 changes: 2 additions & 2 deletions NetAF.Tests/Assets/Item_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace NetAF.Tests.Assets
public class Item_Tests
{
[TestMethod]
public void Given2Items_WhenInteract_ThenNeitherItemOrTargetExpired()
public void Given2Items_WhenInteract_ThenNoChange()
{
var item = new Item(string.Empty, string.Empty);
var item2 = new Item(string.Empty, string.Empty);

var result = item.Interact(item2);

Assert.AreEqual(InteractionResult.NeitherItemOrTargetExpired, result.Result);
Assert.AreEqual(InteractionResult.NoChange, result.Result);
}
}
}
Loading

0 comments on commit 50bab1b

Please sign in to comment.