diff --git a/GameFiles/GameData/GameItems.xml b/GameFiles/GameData/GameItems.xml index f6930fa..f0ad796 100644 --- a/GameFiles/GameData/GameItems.xml +++ b/GameFiles/GameData/GameItems.xml @@ -1,19 +1,19 @@  - + - + - - - + + + diff --git a/GameFiles/GameData/Recipes.xml b/GameFiles/GameData/Recipes.xml index 8600296..4c707dd 100644 --- a/GameFiles/GameData/Recipes.xml +++ b/GameFiles/GameData/Recipes.xml @@ -1,6 +1,6 @@  - + diff --git a/SOSCSRPG.Models/GameItem.cs b/SOSCSRPG.Models/GameItem.cs index ae5eea5..ebf98cf 100644 --- a/SOSCSRPG.Models/GameItem.cs +++ b/SOSCSRPG.Models/GameItem.cs @@ -23,9 +23,11 @@ public enum ItemCategory public bool IsUnique { get; } [JsonIgnore] public IAction Action { get; set; } + [JsonIgnore] + public int StarterQuantity { get; } public GameItem(ItemCategory category, int itemTypeID, string name, int price, - bool isUnique = false, IAction action = null) + bool isUnique = false, IAction action = null, int starterQuantity = 0) { Category = category; ItemTypeID = itemTypeID; @@ -33,6 +35,7 @@ public GameItem(ItemCategory category, int itemTypeID, string name, int price, Price = price; IsUnique = isUnique; Action = action; + StarterQuantity = starterQuantity; } public void PerformAction(LivingEntity actor, LivingEntity target) @@ -42,7 +45,7 @@ public void PerformAction(LivingEntity actor, LivingEntity target) public GameItem Clone() { - return new GameItem(Category, ItemTypeID, Name, Price, IsUnique, Action); + return new GameItem(Category, ItemTypeID, Name, Price, IsUnique, Action, StarterQuantity); } } } \ No newline at end of file diff --git a/SOSCSRPG.Models/Recipe.cs b/SOSCSRPG.Models/Recipe.cs index 1978a37..d427a08 100644 --- a/SOSCSRPG.Models/Recipe.cs +++ b/SOSCSRPG.Models/Recipe.cs @@ -14,6 +14,8 @@ public class Recipe [JsonIgnore] public List Ingredients { get; } [JsonIgnore] public List OutputItems { get; } + [JsonIgnore] + public int StarterQuantity { get; } [JsonIgnore] public string ToolTipContents => @@ -25,12 +27,13 @@ public class Recipe "===========" + Environment.NewLine + string.Join(Environment.NewLine, OutputItems.Select(i => i.QuantityItemDescription)); - public Recipe(int id, string name, List ingredients, List outputItems) + public Recipe(int id, string name, List ingredients, List outputItems, int starterQuantity = 0) { ID = id; Name = name; Ingredients = ingredients; OutputItems = outputItems; + StarterQuantity = starterQuantity; } } } \ No newline at end of file diff --git a/SOSCSRPG.Models/Shared/ExtensionMethods.cs b/SOSCSRPG.Models/Shared/ExtensionMethods.cs index 92c0475..433678a 100644 --- a/SOSCSRPG.Models/Shared/ExtensionMethods.cs +++ b/SOSCSRPG.Models/Shared/ExtensionMethods.cs @@ -14,6 +14,13 @@ public static int AttributeAsInt(this XmlNode node, string attributeName) return Convert.ToInt32(node.AttributeAsString(attributeName)); } + public static int OptionalAttributeAsInt(this XmlNode node, string attributeName) + { + XmlAttribute attribute = node.Attributes?[attributeName]; + + return attribute == null ? 0 : Convert.ToInt32(node.AttributeAsString(attributeName)); + } + public static string AttributeAsString(this XmlNode node, string attributeName) { XmlAttribute attribute = node.Attributes?[attributeName]; diff --git a/SOSCSRPG.Services/Factories/ItemFactory.cs b/SOSCSRPG.Services/Factories/ItemFactory.cs index 986c1dd..7d3e23e 100644 --- a/SOSCSRPG.Services/Factories/ItemFactory.cs +++ b/SOSCSRPG.Services/Factories/ItemFactory.cs @@ -37,6 +37,16 @@ public static GameItem CreateGameItem(int itemTypeID) return _standardGameItems.FirstOrDefault(item => item.ItemTypeID == itemTypeID)?.Clone(); } + public static GameItem ItemById(int id) + { + return _standardGameItems.FirstOrDefault(i => i.ItemTypeID == id); + } + + public static List StarterItems() + { + return _standardGameItems.Where(i => i.StarterQuantity > 0).ToList(); + } + private static void LoadItemsFromNodes(XmlNodeList nodes) { if(nodes == null) @@ -53,7 +63,9 @@ private static void LoadItemsFromNodes(XmlNodeList nodes) node.AttributeAsInt("ID"), node.AttributeAsString("Name"), node.AttributeAsInt("Price"), - itemCategory == GameItem.ItemCategory.Weapon); + itemCategory == GameItem.ItemCategory.Weapon, + null, + node.OptionalAttributeAsInt("StarterQuantity")); if(itemCategory == GameItem.ItemCategory.Weapon) { diff --git a/SOSCSRPG.Services/Factories/RecipeFactory.cs b/SOSCSRPG.Services/Factories/RecipeFactory.cs index 2a704c9..6813367 100644 --- a/SOSCSRPG.Services/Factories/RecipeFactory.cs +++ b/SOSCSRPG.Services/Factories/RecipeFactory.cs @@ -53,7 +53,9 @@ private static void LoadRecipesFromNodes(XmlNodeList nodes) Recipe recipe = new Recipe(node.AttributeAsInt("ID"), node.SelectSingleNode("./Name")?.InnerText ?? "", - ingredients, outputItems); + ingredients, + outputItems, + node.OptionalAttributeAsInt("StarterQuantity")); _recipes.Add(recipe); } @@ -63,5 +65,10 @@ public static Recipe RecipeByID(int id) { return _recipes.FirstOrDefault(x => x.ID == id); } + + public static List StarterRecipes() + { + return _recipes.Where(r => r.StarterQuantity > 0).ToList(); + } } } \ No newline at end of file diff --git a/SOSCSRPG.ViewModels/CharacterCreationViewModel.cs b/SOSCSRPG.ViewModels/CharacterCreationViewModel.cs index ac2c7ce..ff68981 100644 --- a/SOSCSRPG.ViewModels/CharacterCreationViewModel.cs +++ b/SOSCSRPG.ViewModels/CharacterCreationViewModel.cs @@ -66,12 +66,15 @@ public Player GetPlayer() Player player = new Player(Name, 0, 10, 10, PlayerAttributes, 10); // Give player default inventory items, weapons, recipes, etc. - player.AddItemToInventory(ItemFactory.CreateGameItem(1001)); - player.AddItemToInventory(ItemFactory.CreateGameItem(2001)); - player.LearnRecipe(RecipeFactory.RecipeByID(1)); - player.AddItemToInventory(ItemFactory.CreateGameItem(3001)); - player.AddItemToInventory(ItemFactory.CreateGameItem(3002)); - player.AddItemToInventory(ItemFactory.CreateGameItem(3003)); + foreach (GameItem item in ItemFactory.StarterItems()) + { + player.AddItemToInventory(ItemFactory.ItemById(item.ItemTypeID)); + } + + foreach (Recipe recipe in RecipeFactory.StarterRecipes()) + { + player.LearnRecipe(RecipeFactory.RecipeByID(recipe.ID)); + } return player; }