Skip to content

Commit

Permalink
Merge pull request #91 from benpollarduk/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
benpollarduk authored Nov 3, 2024
2 parents 6cc4680 + 9f1c4c6 commit 6cfd6bd
Show file tree
Hide file tree
Showing 92 changed files with 702 additions and 563 deletions.
25 changes: 11 additions & 14 deletions NetAF.Examples/Assets/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,22 @@ public class Player : IAssetTemplate<PlayableCharacter>
/// <returns>The asset.</returns>
public PlayableCharacter Instantiate()
{
var player = new PlayableCharacter(Name, Description, new Knife().Instantiate())
var player = new PlayableCharacter(Name, Description, [new Knife().Instantiate()], interaction: i =>
{
Interaction = i =>
{
if (i == null)
return new(InteractionEffect.NoEffect, null);
if (i == null)
return new(InteractionEffect.NoEffect, null);

if (Knife.Name.EqualsExaminable(i))
return new(InteractionEffect.FatalEffect, i, "You slash wildly at your own throat. You are dead.");
if (Knife.Name.EqualsExaminable(i))
return new(InteractionEffect.FatalEffect, 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.");
if (CoffeeMug.Name.EqualsIdentifier(i.Identifier))
return new(InteractionEffect.NoEffect, 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...");
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.NoEffect, i);
}
};
return new(InteractionEffect.NoEffect, i);
});

return player;
}
Expand Down
17 changes: 6 additions & 11 deletions NetAF.Examples/Assets/Regions/Everglades/Items/ConchShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ public class ConchShell : IAssetTemplate<Item>
/// <returns>The item.</returns>
public Item Instantiate()
{
var conchShell = new Item(Name, Description, true)
var conchShell = new Item(Name, Description, true, interaction: item =>
{
Interaction = item =>
return item.Identifier.IdentifiableName switch
{
switch (item.Identifier.IdentifiableName)
{
case Knife.Name:
return 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.");
default:
return new(InteractionEffect.NoEffect, item);
}
}
};
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),
};
});

return conchShell;
}
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Examples/Assets/Regions/Everglades/Rooms/Cave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class Cave : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
return new(Name, Description, new Exit(Direction.East), new Exit(Direction.South));
return new(Name, Description, [new Exit(Direction.East), new Exit(Direction.South)]);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class CaveMouth : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
return new(Name, Description, new Exit(Direction.North), new Exit(Direction.South), new Exit(Direction.West));
return new(Name, Description, [new Exit(Direction.North), new Exit(Direction.South), new Exit(Direction.West)]);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ForestEntrance : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
return new(Name, Description, new Exit(Direction.North));
return new(Name, Description, [new Exit(Direction.North)]);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ForestFloor : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
return new(Name, Description, new Exit(Direction.North), new Exit(Direction.South));
return new(Name, Description, [new Exit(Direction.North), new Exit(Direction.South)]);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class GreatWesternOcean : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, Description, new Exit(Direction.East));
var room = new Room(Name, Description, [new Exit(Direction.East)]);
room.AddItem(new ConchShell().Instantiate());
return room;
}
Expand Down
9 changes: 4 additions & 5 deletions NetAF.Examples/Assets/Regions/Everglades/Rooms/InnerCave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ internal class InnerCave : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, string.Empty, new Exit(Direction.West), new Exit(Direction.North, true));
Room room = null;

InteractionResult innerCaveInteraction(Item item)
room = new Room(Name, string.Empty, [new Exit(Direction.West), new Exit(Direction.North, true)], interaction: item =>
{
if (item != null && ConchShell.Name.EqualsExaminable(item))
{
Expand All @@ -38,15 +38,14 @@ InteractionResult innerCaveInteraction(Item item)
return new(InteractionEffect.NoEffect, item, "You slash wildly at the bats, but there are too many. Don't aggravate them!");

return new(InteractionEffect.NoEffect, item);
}
});

room.Interaction = innerCaveInteraction;
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));

return room;

}

#endregion
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class Outskirts : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
return new(Name, Description, new Exit(Direction.South));
return new(Name, Description, [new Exit(Direction.South)]);
}

#endregion
Expand Down
14 changes: 5 additions & 9 deletions NetAF.Examples/Assets/Regions/Flat/Flat.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.Interaction;
using NetAF.Assets.Locations;
using NetAF.Examples.Assets.Regions.Flat.Items;
using NetAF.Examples.Assets.Regions.Flat.NPCs;
Expand Down Expand Up @@ -28,14 +27,11 @@ public Region Instantiate()
{
var roof = new Roof().Instantiate();
var easternHallway = new EasternHallway().Instantiate();
var spareBedroom = new SpareBedroom().Instantiate();
var lounge = new Lounge().Instantiate();

lounge.Description = new ConditionalDescription("Your in a large sitting room. Theres a huge map hanging on the eastern wall. On the southern wall there is a canvas. Theres a large coffee table in the center of the room. Beth is sat on a green sofa watching the TV. There is what appears to be a lead of some sort poking out from underneath the sofa. The kitchen is to the north.",
"Your in a large sitting room. Theres a huge map hanging on the eastern wall. On the southern wall there is a canvas. Theres a large coffee table in the center of the room. Beth is sat on a green sofa watching the TV. The kitchen is to the north.",
() => roof.ContainsItem(Lead.Name));

spareBedroom.Interaction = item =>
Room spareBedroom = null;

spareBedroom = new SpareBedroom(item =>
{
if (Lead.Name.EqualsIdentifier(item.Identifier))
{
Expand All @@ -62,7 +58,7 @@ public Region Instantiate()
}

return new(InteractionEffect.NoEffect, item);
};
}).Instantiate();

var regionMaker = new RegionMaker(Name, Description)
{
Expand Down
15 changes: 6 additions & 9 deletions NetAF.Examples/Assets/Regions/Flat/Items/CoffeeMug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ public class CoffeeMug : IAssetTemplate<Item>
/// <returns>The item.</returns>
public Item Instantiate()
{
return new(Name, Description, true)
return new(Name, Description, true, interaction: item =>
{
Interaction = item =>
if (Kettle.Name.EqualsIdentifier(item.Identifier))
{
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.NoEffect, item);
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.NoEffect, item);
});
}

#endregion
Expand Down
15 changes: 5 additions & 10 deletions NetAF.Examples/Assets/Regions/Flat/Items/Kettle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ public class Kettle : IAssetTemplate<Item>
/// <returns>The item.</returns>
public Item Instantiate()
{
return new(Name, Description)
return new(Name, Description, interaction: item =>
{
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!");
}
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.NoEffect, item);
}
};
return new(InteractionEffect.NoEffect, item);
});
}

#endregion
Expand Down
5 changes: 1 addition & 4 deletions NetAF.Examples/Assets/Regions/Flat/NPCs/Beth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ internal class Beth : IAssetTemplate<NonPlayableCharacter>
/// <returns>The asset.</returns>
public NonPlayableCharacter Instantiate()
{
return new(Name, Description)
{
Conversation = new(new("Hello Ben."), new("How are you?", null, new First()))
};
return new(Name, Description, conversation: new(new("Hello Ben."), new("How are you?", null, new First())));
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Examples/Assets/Regions/Flat/Rooms/Attic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class Attic : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
return new(Name, Description, new Exit(Direction.Down));
return new(Name, Description, [new Exit(Direction.Down)]);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Examples/Assets/Regions/Flat/Rooms/Bathroom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class Bathroom : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, Description, new Exit(Direction.North), new Exit(Direction.South));
var room = new Room(Name, Description, [new Exit(Direction.North), new Exit(Direction.South)]);

room.AddItem(new Bath().Instantiate());
room.AddItem(new Toilet().Instantiate());
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Examples/Assets/Regions/Flat/Rooms/Bedroom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class Bedroom : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, Description, new Exit(Direction.North), new Exit(Direction.Up));
var room = new Room(Name, Description, [new Exit(Direction.North), new Exit(Direction.Up)]);

room.AddItem(new Bed().Instantiate());
room.AddItem(new Picture().Instantiate());
Expand Down
2 changes: 1 addition & 1 deletion NetAF.Examples/Assets/Regions/Flat/Rooms/EasternHallway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class EasternHallway : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, Description, new Exit(Direction.East, true), new Exit(Direction.West));
var room = new Room(Name, Description, [new Exit(Direction.East, true), new Exit(Direction.West)]);

room.AddItem(new Telephone().Instantiate());

Expand Down
12 changes: 5 additions & 7 deletions NetAF.Examples/Assets/Regions/Flat/Rooms/Kitchen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ internal class Kitchen : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, Description, new Exit(Direction.South), new Exit(Direction.East));

room.AddItem(new HamsterCage().Instantiate());
room.AddItem(new Kettle().Instantiate());

room.Interaction = (item) =>
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.NoEffect, item);
};
});

room.AddItem(new HamsterCage().Instantiate());
room.AddItem(new Kettle().Instantiate());

return room;
}
Expand Down
25 changes: 15 additions & 10 deletions NetAF.Examples/Assets/Regions/Flat/Rooms/Lounge.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NetAF.Assets.Interaction;
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 All @@ -23,16 +24,13 @@ internal class Lounge : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, string.Empty, new Exit(Direction.North));
Room room = null;

room.AddCharacter(new Beth().Instantiate());
room.AddItem(new Map().Instantiate());
room.AddItem(new Canvas().Instantiate());
room.AddItem(new Table().Instantiate());
room.AddItem(new LoungeTV().Instantiate());
room.AddItem(new Lead().Instantiate());
ConditionalDescription description = new("You're in a large sitting room. Theres a huge map hanging on the eastern wall. On the southern wall there is a canvas. Theres a large coffee table in the center of the room. Beth is sat on a green sofa watching the TV. There is what appears to be a lead of some sort poking out from underneath the sofa. The kitchen is to the north.",
"You're in a large sitting room. Theres a huge map hanging on the eastern wall. On the southern wall there is a canvas. Theres a large coffee table in the center of the room. Beth is sat on a green sofa watching the TV. The kitchen is to the north.",
() => room.ContainsItem(Lead.Name));

room.Interaction = item =>
room = new(new Identifier(Name), description, [new Exit(Direction.North)], interaction: item =>
{
if (item != null)
{
Expand All @@ -56,7 +54,14 @@ public Room Instantiate()
}

return new(InteractionEffect.NoEffect, item);
};
});

room.AddCharacter(new Beth().Instantiate());
room.AddItem(new Map().Instantiate());
room.AddItem(new Canvas().Instantiate());
room.AddItem(new Table().Instantiate());
room.AddItem(new LoungeTV().Instantiate());
room.AddItem(new Lead().Instantiate());

return room;
}
Expand Down
11 changes: 6 additions & 5 deletions NetAF.Examples/Assets/Regions/Flat/Rooms/Roof.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ internal class Roof : IAssetTemplate<Room>
/// <returns>The asset.</returns>
public Room Instantiate()
{
var room = new Room(Name, string.Empty, new Exit(Direction.South));
Room room = null;
ConditionalDescription description = new("The roof is small and gravely, and it hurts your shoe-less feet to stand on it. There is a large skylight in the center of the roof, and a coffee mug sits to the side, indicating someone has been here recently. The window behind you south leads back into the bathroom.",
"The roof is small and gravely, and it hurts your shoe-less feet to stand on it. There is a large skylight in the center of the roof. The window behind you south leads back into the bathroom.",
() => room.ContainsItem(CoffeeMug.Name));

room = new(new Identifier(Name), description, [new Exit(Direction.South)]);

room.AddItem(new Skylight().Instantiate());
room.AddItem(new CoffeeMug().Instantiate());

room.Description = new ConditionalDescription("The roof is small and gravely, and it hurts your shoe-less feet to stand on it. There is a large skylight in the center of the roof, and a coffee mug sits to the side, indicating someone has been here recently. The window behind you south leads back into the bathroom.",
"The roof is small and gravely, and it hurts your shoe-less feet to stand on it. There is a large skylight in the center of the roof. The window behind you south leads back into the bathroom.",
() => room.ContainsItem(CoffeeMug.Name));

return room;
}

Expand Down
Loading

0 comments on commit 6cfd6bd

Please sign in to comment.