diff --git a/Engine/Engine.csproj b/Engine/Engine.csproj
index ba947ec..fd6a797 100644
--- a/Engine/Engine.csproj
+++ b/Engine/Engine.csproj
@@ -44,6 +44,7 @@
+
@@ -54,6 +55,7 @@
+
diff --git a/Engine/Factories/TraderFactory.cs b/Engine/Factories/TraderFactory.cs
new file mode 100644
index 0000000..0e1c6a1
--- /dev/null
+++ b/Engine/Factories/TraderFactory.cs
@@ -0,0 +1,45 @@
+using Engine.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Engine.Factories
+{
+ public static class TraderFactory
+ {
+ private static readonly List _traders = new List();
+
+ static TraderFactory()
+ {
+ Trader susan = new Trader("Susan");
+ susan.AddItemToInventory(ItemFactory.CreateGameItem(1001));
+
+ Trader farmerTed = new Trader("Framer Ted");
+ farmerTed.AddItemToInventory(ItemFactory.CreateGameItem(1001));
+
+ Trader peteTheHerbalist = new Trader("Pete the Herbalist");
+ peteTheHerbalist.AddItemToInventory(ItemFactory.CreateGameItem(1001));
+
+ AddTraderToList(susan);
+ AddTraderToList(farmerTed);
+ AddTraderToList(peteTheHerbalist);
+ }
+
+ public static Trader GetTraderByName(string name)
+ {
+ return _traders.FirstOrDefault(t => t.Name == name);
+ }
+
+ private static void AddTraderToList(Trader trader)
+ {
+ if(_traders.Any(t => t.Name == trader.Name)) // ensures only one of each trader gets added
+ {
+ throw new ArgumentException($"Trader '{trader.Name}' already exists");
+ }
+
+ _traders.Add(trader);
+ }
+ }
+}
diff --git a/Engine/Factories/WorldFactory.cs b/Engine/Factories/WorldFactory.cs
index 817716b..01224ae 100644
--- a/Engine/Factories/WorldFactory.cs
+++ b/Engine/Factories/WorldFactory.cs
@@ -13,6 +13,7 @@ internal static World CreateWorld()
{
World newWorld = new World();
+ //TODO find a way to link names to location coords.
newWorld.AddLocation(-2, -1, "Farmer's Field",
"There are rows of corn growing here, with giant rats hiding between them.",
"FarmFields.png");
@@ -23,12 +24,14 @@ internal static World CreateWorld()
newWorld.AddLocation(-1, -1, "Farmer's House",
"This is the house of your neighbor, Farmer Ted.",
"Farmhouse.png");
+ newWorld.LocationAt(-1, -1).TraderHere = TraderFactory.GetTraderByName("Farmer Ted");
newWorld.AddLocation(0, -1, "Home", "This is your home", "Home.png");
newWorld.AddLocation(-1, 0, "Trading Shop",
"The shop of Susan, the trader.",
"Trader.png");
+ newWorld.LocationAt(-1, 0).TraderHere = TraderFactory.GetTraderByName("Susan");
newWorld.AddLocation(0, 0, "Town square",
"You see a fountain here.",
@@ -47,6 +50,7 @@ internal static World CreateWorld()
newWorld.AddLocation(0, 1, "Herbalist's hut",
"You see a small hut, with plants drying from the roof.",
"HerbalistsHut.png");
+ newWorld.LocationAt(0, 1).TraderHere = TraderFactory.GetTraderByName("Pete the Herbalist");
newWorld.LocationAt(0, 1).QuestAvailableHere.Add(QuestFactory.GetQuestByID(1));// this makes it so you don't need a temp variable to hold the location
diff --git a/Engine/Models/Location.cs b/Engine/Models/Location.cs
index e99e667..bf157aa 100644
--- a/Engine/Models/Location.cs
+++ b/Engine/Models/Location.cs
@@ -18,6 +18,8 @@ public class Location
public List MonstersHere { get; set; } = new List();
+ public Trader TraderHere { get; set; }
+
public void AddMonster(int monsterID, int chanceOfEncountering)
{
if(MonstersHere.Exists(m => m.MonsterID == monsterID))
diff --git a/Engine/Models/Trader.cs b/Engine/Models/Trader.cs
new file mode 100644
index 0000000..06cc4ed
--- /dev/null
+++ b/Engine/Models/Trader.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Engine.Models
+{
+ public class Trader : BaseNotificationClass
+ {
+ public string Name { get; set; }
+
+ public ObservableCollection Inventory { get; set; }
+
+ public Trader(string name)
+ {
+ Name = name;
+ Inventory = new ObservableCollection();
+ }
+
+ public void AddItemToInventory(GameItem item)
+ {
+ Inventory.Add(item);
+ }
+ public void RemoveItemToInventory(GameItem item)
+ {
+ Inventory.Remove(item);
+ }
+ }
+}
diff --git a/Engine/ViewModels/GameSession.cs b/Engine/ViewModels/GameSession.cs
index 5b39f5e..cadc0a2 100644
--- a/Engine/ViewModels/GameSession.cs
+++ b/Engine/ViewModels/GameSession.cs
@@ -17,6 +17,7 @@ public class GameSession : BaseNotificationClass
#region Properties
private Location _currentLocation;
private Monster _currentMonster;
+ private Trader _currentTrader;
public World CurrentWorld { get; set; }
public Player CurrentPlayer { get; set; }
@@ -35,6 +36,8 @@ public Location CurrentLocation
CompleteQuestsAtLocation();
GivePlayerQuestsAtLocation();
GetMonsterAtLocation(); //TODO maybe at a timer so even if a player stays in the same area monsters will respawn.
+
+ _currentTrader = CurrentLocation.TraderHere;
}
}
@@ -57,7 +60,16 @@ public Monster CurrentMonster
}
}
-
+ public Trader CurrentTrader
+ {
+ get { return _currentTrader; }
+ set
+ {
+ _currentTrader = value;
+ OnPropertyChanged(nameof(CurrentTrader));
+ OnPropertyChanged(nameof(HasTrader));
+ }
+ }
//TODO might be away to simplify this..
public bool HasLocationToNorth =>
@@ -75,6 +87,8 @@ public Monster CurrentMonster
public bool HasMonster => CurrentMonster != null;
+ public bool HasTrader => CurrentTrader != null;
+
#endregion
public GameSession()
diff --git a/UI/MainWindow.xaml b/UI/MainWindow.xaml
index 7db2ddf..cbc408b 100644
--- a/UI/MainWindow.xaml
+++ b/UI/MainWindow.xaml
@@ -216,6 +216,10 @@
Width="65" Margin="10" Click="OnClick_MoveWest"
Visibility="{Binding HasLocationToWest, Converter={StaticResource BooleanToVisibility}}"
Content="West" />
+