Skip to content

Commit

Permalink
Merge branch 'docs-update' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ben_pollard committed Jan 26, 2024
2 parents d03ed66 + 66207fd commit 9bb4499
Show file tree
Hide file tree
Showing 25 changed files with 413 additions and 125 deletions.
2 changes: 1 addition & 1 deletion BP.AdventureFramework.Examples/Assets/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PlayableCharacter Instantiate()
{
var player = new PlayableCharacter(Name, Description, new Knife().Instantiate())
{
Interaction = (i, _) =>
Interaction = i =>
{
if (i == null)
return new InteractionResult(InteractionEffect.NoEffect, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Item Instantiate()
{
var conchShell = new Item(Name, Description, true)
{
Interaction = (item, _) =>
Interaction = item =>
{
switch (item.Identifier.IdentifiableName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ public Room Instantiate()
{
var room = new Room(Name, string.Empty, new Exit(Direction.West), new Exit(Direction.North, true));

InteractionCallback innerCaveInteraction = (i, _) =>
InteractionCallback innerCaveInteraction = item =>
{
if (i != null && ConchShell.Name.EqualsExaminable(i))
if (item != null && ConchShell.Name.EqualsExaminable(item))
{
room[Direction.North].Unlock();
return new InteractionResult(InteractionEffect.ItemUsedUp, i, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces.");
return new InteractionResult(InteractionEffect.ItemUsedUp, item, "You blow into the Conch Shell. The Conch Shell howls, the bats leave! Conch shell crumbles to pieces.");
}

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

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

room.Interaction = innerCaveInteraction;
Expand Down
37 changes: 15 additions & 22 deletions BP.AdventureFramework.Examples/Assets/Regions/Flat/Flat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,33 @@ public Region Instantiate()
"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 = (i, target) =>
spareBedroom.Interaction = item =>
{
var obj = target as Room;
if (Lead.Name.EqualsIdentifier(item.Identifier))
{
spareBedroom.AddItem(new Item(item.Identifier, item.Description, true));
return new InteractionResult(InteractionEffect.ItemUsedUp, item, "The lead fits snugly into the input socket on the amp.");
}

if (obj != null)
if (Guitar.Name.EqualsIdentifier(item.Identifier))
{
if (Lead.Name.EqualsIdentifier(i.Identifier))
if (spareBedroom.ContainsItem(Lead.Name))
{
obj.AddItem(new Item(i.Identifier, i.Description, true));
return new InteractionResult(InteractionEffect.ItemUsedUp, i, "The lead fits snugly into the input socket on the amp.");
}
easternHallway[Direction.East].Unlock();

if (Guitar.Name.EqualsIdentifier(i.Identifier))
{
if (obj.ContainsItem(Lead.Name))
if (lounge.FindCharacter(Beth.Name, out var b))
{
easternHallway[Direction.East].Unlock();

if (lounge.FindCharacter(Beth.Name, out var b))
{
lounge.RemoveCharacter(b);
return new InteractionResult(InteractionEffect.NoEffect, i, "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(InteractionEffect.NoEffect, i, "The guitar plugs in with a satisfying click. You play some punk and the amp sings.");
lounge.RemoveCharacter(b);
return new InteractionResult(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(InteractionEffect.NoEffect, i, "You have no lead so you can't use the guitar with the amp...");
return new InteractionResult(InteractionEffect.NoEffect, item, "The guitar plugs in with a satisfying click. You play some punk and the amp sings.");
}

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

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

var regionMaker = new RegionMaker(Name, Description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ public Item Instantiate()
{
return new Item(Name, Description, true)
{
Interaction = (i, target) =>
Interaction = item =>
{
if (Kettle.Name.EqualsIdentifier(i.Identifier))
if (Kettle.Name.EqualsIdentifier(item.Identifier))
{
var item = target as Item;
item?.Morph(new MugOfCoffee().Instantiate());
return new InteractionResult(InteractionEffect.ItemMorphed, i, "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(InteractionEffect.ItemMorphed, 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(InteractionEffect.NoEffect, i);
return new InteractionResult(InteractionEffect.NoEffect, item);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ public Item Instantiate()
{
return new Item(Name, Description)
{
Interaction = (i, target) =>
Interaction = item =>
{
var obj = target as Item;

if (obj != null)
if (item != null)
{
if (EmptyCoffeeMug.Name.EqualsIdentifier(i.Identifier))
if (EmptyCoffeeMug.Name.EqualsIdentifier(item.Identifier))
{
i.Morph(new MugOfCoffee().Instantiate());
return new InteractionResult(InteractionEffect.ItemMorphed, i, "You put some instant coffee granuals into the mug and add some freshly boiled water from the Kettle. The coffee smells amazing!");
item.Morph(new MugOfCoffee().Instantiate());
return new InteractionResult(InteractionEffect.ItemMorphed, 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(InteractionEffect.NoEffect, i);
return new InteractionResult(InteractionEffect.NoEffect, item);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ public Room Instantiate()
room.AddItem(new HamsterCage().Instantiate());
room.AddItem(new Kettle().Instantiate());

room.Interaction = (i, target) =>
room.Interaction = (item) =>
{
var obj = target as Room;
if (Guitar.Name.EqualsIdentifier(item.Identifier))
return new InteractionResult(InteractionEffect.NoEffect, item, "Playing guitar in the kitchen is pretty stupid don't you think?");

if (obj != null)
{
if (Guitar.Name.EqualsIdentifier(i.Identifier))
return new InteractionResult(InteractionEffect.NoEffect, i, "Playing guitar in the kitchen is pretty stupid don't you think?");
}

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

return room;
Expand Down
30 changes: 13 additions & 17 deletions BP.AdventureFramework.Examples/Assets/Regions/Flat/Rooms/Lounge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,31 @@ public Room Instantiate()
room.AddItem(new LoungeTV().Instantiate());
room.AddItem(new Lead().Instantiate());

room.Interaction = (i, target) =>
room.Interaction = item =>
{
var obj = target as Room;

if (obj != null)
if (item != null)
{
if (MugOfCoffee.Name.EqualsIdentifier(i.Identifier))
if (MugOfCoffee.Name.EqualsIdentifier(item.Identifier))
{
if (obj.ContainsCharacter(Beth.Name))
return new InteractionResult(InteractionEffect.ItemUsedUp, i, "Beth takes the cup of coffee and smiles. Brownie points to you!");
if (room.ContainsCharacter(Beth.Name))
return new InteractionResult(InteractionEffect.ItemUsedUp, item, "Beth takes the cup of coffee and smiles. Brownie points to you!");

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

}

if (EmptyCoffeeMug.Name.EqualsIdentifier(i.Identifier))
if (EmptyCoffeeMug.Name.EqualsIdentifier(item.Identifier))
{
obj.AddItem(i);
return new InteractionResult(InteractionEffect.ItemUsedUp, i, "You put the mug down on the coffee table, sick of carrying the bloody thing around. Beth is none too impressed.");
room.AddItem(item);
return new InteractionResult(InteractionEffect.ItemUsedUp, 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(i.Identifier))
return new InteractionResult(InteractionEffect.NoEffect, i, "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(InteractionEffect.NoEffect, i);
if (Guitar.Name.EqualsIdentifier(item.Identifier))
return new InteractionResult(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(InteractionEffect.NoEffect, i);
return new InteractionResult(InteractionEffect.NoEffect, item);
};

return room;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Item Instantiate()
{
var stump = new Item(Name, Description);

stump.Interaction = (item, _) =>
stump.Interaction = item =>
{
if (Shield.Name.EqualsExaminable(item))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Room Instantiate()
var room = new Room(Name, Description, new Exit(Direction.South), new Exit(Direction.North), new Exit(Direction.East, true));
var door = new TailDoor().Instantiate();

door.Interaction = (item, _) =>
door.Interaction = item =>
{
if (TailKey.Name.EqualsExaminable(item))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Room Instantiate()
var bush = new Bush().Instantiate();
var rupee = new Rupee().Instantiate();

bush.Interaction = (item, _) =>
bush.Interaction = item =>
{
if (Sword.Name.EqualsExaminable(item))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Region Instantiate()
new Paragraph("OK Link your annoying me now, I'm just going to ignore you.", 0)
);

saria.Interaction = (item, _) =>
saria.Interaction = item =>
{
saria.FindItem(TailKey.Name, out var key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void GivenUseItem_WhenFatalEffect_ThenIsAliveIsFalse()
var item = new Item("Test", string.Empty);
var pc = new PlayableCharacter(string.Empty, string.Empty)
{
Interaction = (i, _) =>
Interaction = i =>
{
if (i == null)
return new InteractionResult(InteractionEffect.NoEffect, null);
Expand All @@ -80,7 +80,7 @@ public void GivenUseItem_WhenFatalEffect_ThenIsAliveIsFalse()
}
};

var result = pc.UseItem(pc, item);
pc.UseItem(pc, item);

Assert.IsFalse(pc.IsAlive);
}
Expand Down
4 changes: 2 additions & 2 deletions BP.AdventureFramework.Tests/Assets/Item_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace BP.AdventureFramework.Tests.Assets
public class Item_Tests
{
[TestMethod]
public void Given2Items_WhenUse_ThenNoEffect()
public void Given2Items_WhenInteract_ThenNoEffect()
{
var item = new Item(string.Empty, string.Empty);
var item2 = new Item(string.Empty, string.Empty);

var result = item.Use(item2);
var result = item.Interact(item2);

Assert.AreEqual(InteractionEffect.NoEffect, result.Effect);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using BP.AdventureFramework.Assets;
using BP.AdventureFramework.Assets.Interaction;
using BP.AdventureFramework.Rendering.FrameBuilders;
using BP.AdventureFramework.Rendering.FrameBuilders.Color;
using BP.AdventureFramework.Rendering.Frames;
Expand Down
4 changes: 2 additions & 2 deletions BP.AdventureFramework/Assets/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class Character : ExaminableObject, IInteractWithItem
/// <summary>
/// Get or set the interaction.
/// </summary>
public InteractionCallback Interaction { get; set; } = (i, target) => new InteractionResult(InteractionEffect.NoEffect, i);
public InteractionCallback Interaction { get; set; } = i => new InteractionResult(InteractionEffect.NoEffect, i);

/// <summary>
/// Get the items this Character holds.
Expand All @@ -38,7 +38,7 @@ public abstract class Character : ExaminableObject, IInteractWithItem
/// <returns>The result of the interaction.</returns>
protected virtual InteractionResult InteractWithItem(Item item)
{
return Interaction.Invoke(item, this);
return Interaction.Invoke(item);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/// Represents the callback for interacting with objects.
/// </summary>
/// <param name="item">The item to interact with.</param>
/// <param name="target">The target interaction element.</param>
/// <returns>The result of the interaction.</returns>
public delegate InteractionResult InteractionCallback(Item item, IInteractWithItem target);
public delegate InteractionResult InteractionCallback(Item item);
}
14 changes: 2 additions & 12 deletions BP.AdventureFramework/Assets/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class Item : ExaminableObject, IInteractWithItem
/// <summary>
/// Get or set the interaction.
/// </summary>
public InteractionCallback Interaction { get; set; } = (i, target) => new InteractionResult(InteractionEffect.NoEffect, i);
public InteractionCallback Interaction { get; set; } = i => new InteractionResult(InteractionEffect.NoEffect, i);

#endregion

Expand Down Expand Up @@ -62,16 +62,6 @@ public void Morph(Item item)
IsTakeable = item.IsTakeable;
}

/// <summary>
/// Use this item on a target.
/// </summary>
/// <param name="target">The target to use the item on.</param>
/// <retunrs>The result of the interaction.</retunrs>
public InteractionResult Use(IInteractWithItem target)
{
return target.Interact(this);
}

#endregion

#region IInteractWithItem Members
Expand All @@ -83,7 +73,7 @@ public InteractionResult Use(IInteractWithItem target)
/// <returns>The result of the interaction.</returns>
public InteractionResult Interact(Item item)
{
return Interaction.Invoke(item, this);
return Interaction.Invoke(item);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions BP.AdventureFramework/Assets/Locations/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public sealed class Room : ExaminableObject, IInteractWithItem
/// <summary>
/// Get or set the interaction.
/// </summary>
public InteractionCallback Interaction { get; set; } = (i, target) => new InteractionResult(InteractionEffect.NoEffect, i);
public InteractionCallback Interaction { get; set; } = i => new InteractionResult(InteractionEffect.NoEffect, i);

/// <summary>
/// Get an exit.
Expand Down Expand Up @@ -203,7 +203,7 @@ public bool CanMove(Direction direction)
/// <returns>The result of the interaction.</returns>
private InteractionResult InteractWithItem(Item item)
{
return Interaction.Invoke(item, this);
return Interaction.Invoke(item);
}

/// <summary>
Expand Down
Loading

0 comments on commit 9bb4499

Please sign in to comment.