Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Fix #76 Move default player inventory to GameFiles #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions GameFiles/GameData/GameItems.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<GameItems>
<Weapons>
<Weapon ID="1001" Name="Pointy stick" Price="1" DamageDice="1d2"/>
<Weapon ID="1001" Name="Pointy stick" Price="1" DamageDice="1d2" StarterQuantity="1"/>
<Weapon ID="1002" Name="Rusty sword" Price="5" DamageDice="1d3"/>
<Weapon ID="1501" Name="Snake fang" Price="0" DamageDice="1d2"/>
<Weapon ID="1502" Name="Rat claw" Price="0" DamageDice="1d2"/>
<Weapon ID="1503" Name="Spider fang" Price="0" DamageDice="1d4"/>
</Weapons>
<HealingItems>
<HealingItem ID="2001" Name="Granola bar" Price="5" HitPointsToHeal="2"/>
<HealingItem ID="2001" Name="Granola bar" Price="5" HitPointsToHeal="2" StarterQuantity="1"/>
</HealingItems>
<MiscellaneousItems>
<MiscellaneousItem ID="3001" Name="Oats" Price="1"/>
<MiscellaneousItem ID="3002" Name="Honey" Price="2"/>
<MiscellaneousItem ID="3003" Name="Raisins" Price="2"/>
<MiscellaneousItem ID="3001" Name="Oats" Price="1" StarterQuantity="1"/>
<MiscellaneousItem ID="3002" Name="Honey" Price="2" StarterQuantity="1"/>
<MiscellaneousItem ID="3003" Name="Raisins" Price="2" StarterQuantity="1"/>
<MiscellaneousItem ID="9001" Name="Snake fang" Price="1"/>
<MiscellaneousItem ID="9002" Name="Snakeskin" Price="2"/>
<MiscellaneousItem ID="9003" Name="Rat tail" Price="1"/>
Expand Down
2 changes: 1 addition & 1 deletion GameFiles/GameData/Recipes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<Recipes>
<Recipe ID="1">
<Recipe ID="1" StarterQuantity="1">
<Name><![CDATA[Granola bar]]></Name>
<Ingredients>
<Item ID="3001" Quantity="1"/>
Expand Down
7 changes: 5 additions & 2 deletions SOSCSRPG.Models/GameItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ 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;
Name = name;
Price = price;
IsUnique = isUnique;
Action = action;
StarterQuantity = starterQuantity;
}

public void PerformAction(LivingEntity actor, LivingEntity target)
Expand All @@ -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);
}
}
}
5 changes: 4 additions & 1 deletion SOSCSRPG.Models/Recipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Recipe
[JsonIgnore] public List<ItemQuantity> Ingredients { get; }
[JsonIgnore]
public List<ItemQuantity> OutputItems { get; }
[JsonIgnore]
public int StarterQuantity { get; }

[JsonIgnore]
public string ToolTipContents =>
Expand All @@ -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<ItemQuantity> ingredients, List<ItemQuantity> outputItems)
public Recipe(int id, string name, List<ItemQuantity> ingredients, List<ItemQuantity> outputItems, int starterQuantity = 0)
{
ID = id;
Name = name;
Ingredients = ingredients;
OutputItems = outputItems;
StarterQuantity = starterQuantity;
}
}
}
7 changes: 7 additions & 0 deletions SOSCSRPG.Models/Shared/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
14 changes: 13 additions & 1 deletion SOSCSRPG.Services/Factories/ItemFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GameItem> StarterItems()
{
return _standardGameItems.Where(i => i.StarterQuantity > 0).ToList();
}

private static void LoadItemsFromNodes(XmlNodeList nodes)
{
if(nodes == null)
Expand All @@ -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)
{
Expand Down
9 changes: 8 additions & 1 deletion SOSCSRPG.Services/Factories/RecipeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -63,5 +65,10 @@ public static Recipe RecipeByID(int id)
{
return _recipes.FirstOrDefault(x => x.ID == id);
}

public static List<Recipe> StarterRecipes()
{
return _recipes.Where(r => r.StarterQuantity > 0).ToList();
}
}
}
15 changes: 9 additions & 6 deletions SOSCSRPG.ViewModels/CharacterCreationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down