diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-14 20:02:34 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-14 20:02:34 +0300 |
| commit | 68f18f228ef27e46eaf3623481977c54972f9d01 (patch) | |
| tree | e30ca1bfc98c1f72082e4589b85c1769466072f5 | |
| parent | 97bb830a57e8eb2458e74710d91670493f629dd0 (diff) | |
| download | Mundus-68f18f228ef27e46eaf3623481977c54972f9d01.tar Mundus-68f18f228ef27e46eaf3623481977c54972f9d01.tar.gz Mundus-68f18f228ef27e46eaf3623481977c54972f9d01.zip | |
Did Service/Tiles/Crafting refactorization and documentation.
| -rw-r--r-- | Mundus/Service/Tiles/Crafting/CraftingController.cs | 66 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Crafting/CraftingRecipe.cs | 194 |
2 files changed, 142 insertions, 118 deletions
diff --git a/Mundus/Service/Tiles/Crafting/CraftingController.cs b/Mundus/Service/Tiles/Crafting/CraftingController.cs index 64cdc27..4fe0279 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingController.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingController.cs @@ -1,48 +1,45 @@ -using System.Collections.Generic; -using System.Linq; -using Mundus.Data.Crafting; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Service.Tiles.Mobs; -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Items.Presets; -using Mundus.Data; - -namespace Mundus.Service.Tiles.Crafting { - public static class CraftingController { - /// <summary> - /// Returns all recipes that can be executed with the current items in the player inventory (Inventory.Items) - /// </summary> - /// <returns>All avalable recipies.</returns> - public static CraftingRecipe[] GetAvalableRecipes() { - return DataBaseContexts.CTContext.GetAvalableRecipes(); - } +namespace Mundus.Service.Tiles.Crafting +{ + using System.Linq; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Service.Tiles.Items; + using Mundus.Service.Tiles.Items.Presets; + using Mundus.Service.Tiles.Mobs; + public static class CraftingController + { /// <summary> - /// Removes items, used for crafting and adds the result item to the inventory + /// Removes items and adds the result item to the inventory /// </summary> - /// <param name="itemRecipe">CraftingRecipie of the item that will be crafted</param> - public static void CraftItem(CraftingRecipe itemRecipe, MobTile mob) { - //Removes all items that are used to craft the result item + public static void CraftItem(CraftingRecipe itemRecipe, MobTile mob) + { + // Removes all items that are used to craft the result item var reqItems = itemRecipe.GetAllRequiredItems(); var reqCounts = itemRecipe.GetAllCounts(); - var inventoryItems = mob.Inventory.Items.Where(i => i != null).ToArray(); + + var allInventoryItems = mob.Inventory.Items.Where(i => i != null).ToArray(); for (int item = 0; item < reqItems.Length; item++) { - for (int i = 0, removed = 0; i < inventoryItems.Length && removed < reqCounts[item]; i++) + for (int i = 0, removed = 0; i < allInventoryItems.Length && removed < reqCounts[item]; i++) { - if (inventoryItems[i].stock_id == reqItems[item]) { + if (allInventoryItems[i].stock_id == reqItems[item]) + { mob.Inventory.DeleteFromItems(i); removed++; } } } - ItemTile tmp = ToolPresets.GetFromStock(itemRecipe.ResultItem); - if (tmp == null) { - tmp = StructurePresets.GetFromStock(itemRecipe.ResultItem); + ItemTile result = ToolPresets.GetFromStock(itemRecipe.ResultItem); + + if (result == null) + { + result = StructurePresets.GetFromStock(itemRecipe.ResultItem); } - MI.Player.Inventory.AppendToItems(tmp); + + MI.Player.Inventory.AppendToItems(result); Data.Windows.WI.SelWin.PrintInventory(); } @@ -51,8 +48,17 @@ namespace Mundus.Service.Tiles.Crafting { /// Does CraftItem method for the player /// </summary> /// <param name="itemRecipe">CraftingRecipie of the item that will be crafted</param> - public static void CraftItemPlayer(CraftingRecipe itemRecipe) { + public static void CraftItemPlayer(CraftingRecipe itemRecipe) + { CraftItem(itemRecipe, MI.Player); } + + /// <summary> + /// Returns all recipes that can be executed with the current items in the player inventory (Inventory.Items) + /// </summary> + public static CraftingRecipe[] GetAvalableRecipes() + { + return DataBaseContexts.CTContext.GetAvalableRecipes(); + } } }
\ No newline at end of file diff --git a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs index 148e76b..3d495a3 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs @@ -1,137 +1,155 @@ -using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using Mundus.Service.Tiles.Items; - -namespace Mundus.Service.Tiles.Crafting {
- [Table("CraftingRecipes", Schema = "Mundus")] - public class CraftingRecipe {
- [Key]
- public int ID { get; set; }
- /// <summary>
- /// Item that will be added to the inventory after crafting
- /// </summary>
- /// <value>The result item.</value> - public string ResultItem { get; private set; } -
- /// <summary>
- /// Required amount of the first item
- /// </summary> - public int Count1 { get; private set; }
- /// <summary>
- /// Required first item
- /// </summary> - public string ReqItem1 { get; private set; } -
- /// <summary>
- /// Required amount of the second item
- /// </summary> - public int Count2 { get; private set; }
- /// <summary>
- /// Required second item
- /// </summary> - public string ReqItem2 { get; private set; } -
- /// <summary>
- /// Required amount of the third item
- /// </summary> - public int Count3 { get; private set; }
- /// <summary>
- /// Required third item
- /// </summary> - public string ReqItem3 { get; private set; } +namespace Mundus.Service.Tiles.Crafting +{ + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Linq; + using Mundus.Service.Tiles.Items; - /// <summary>
- /// Required amount of the fourth item
- /// </summary> - public int Count4 { get; private set; }
- /// <summary>
- /// Required fourth item
- /// </summary> - public string ReqItem4 { get; private set; } -
- /// <summary>
- /// Required amount of the fifth item
- /// </summary> - public int Count5 { get; private set; }
+ [Table("CraftingRecipes", Schema = "Mundus")] + public class CraftingRecipe + { /// <summary>
/// Required fifth item
/// </summary> public string ReqItem5 { get; private set; } - public CraftingRecipe(string resultItem, int count1, string reqItem1) :this(resultItem, count1, reqItem1, 0, null, 0, null, 0, null, 0, null) - { } + public CraftingRecipe(string resultItem, int count1, string reqItem1) : this(resultItem, count1, reqItem1, 0, null, 0, null, 0, null, 0, null) + { + } public CraftingRecipe(string resultItem, int count1, string reqItem1, int count2, string reqItem2) : this(resultItem, count1, reqItem1, count2, reqItem2, 0, null, 0, null, 0, null) - { } + { + } public CraftingRecipe(string resultItem, int count1, string reqItem1, int count2, string reqItem2, int count3, string reqItem3) : this(resultItem, count1, reqItem1, count2, reqItem2, count3, reqItem3, 0, null, 0, null) - { } + { + } public CraftingRecipe(string resultItem, int count1, string reqItem1, int count2, string reqItem2, int count3, string reqItem3, int count4, string reqItem4) : this(resultItem, count1, reqItem1, count2, reqItem2, count3, reqItem3, count4, reqItem4, 0, null) - { } + { + } - public CraftingRecipe(string resultItem, int count1, string reqItem1, int count2, string reqItem2, int count3, string reqItem3, int count4, string reqItem4, int count5, string reqItem5) { + public CraftingRecipe(string resultItem, int count1, string reqItem1, int count2, string reqItem2, int count3, string reqItem3, int count4, string reqItem4, int count5, string reqItem5) + { this.ResultItem = resultItem; this.Count1 = count1; this.ReqItem1 = reqItem1; this.Count2 = count2; - this.ReqItem2 = reqItem2; //reqItem2.stock_id; + this.ReqItem2 = reqItem2; this.Count3 = count3; - this.ReqItem3 = reqItem3; //reqItem3.stock_id; + this.ReqItem3 = reqItem3; this.Count4 = count4; - this.ReqItem4 = reqItem4; //reqItem4.stock_id; + this.ReqItem4 = reqItem4; this.Count5 = count5; - this.ReqItem5 = reqItem5; //reqItem5.stock_id; + this.ReqItem5 = reqItem5; } + + [Key] + public int ID { get; set; } + + /// <summary> + /// Item that will be added to the inventory after crafting + /// </summary> + /// <value>The result item.</value> + public string ResultItem { get; private set; } + + /// <summary> + /// Required amount of the first item + /// </summary> + public int Count1 { get; private set; } + + /// <summary> + /// Required first item + /// </summary> + public string ReqItem1 { get; private set; } + + /// <summary> + /// Required amount of the second item + /// </summary> + public int Count2 { get; private set; } + + /// <summary> + /// Required second item + /// </summary> + public string ReqItem2 { get; private set; } + + /// <summary> + /// Required amount of the third item + /// </summary> + public int Count3 { get; private set; } + + /// <summary> + /// Required third item + /// </summary> + public string ReqItem3 { get; private set; } + + /// <summary> + /// Required amount of the fourth item + /// </summary> + public int Count4 { get; private set; } + + /// <summary> + /// Required fourth item + /// </summary> + public string ReqItem4 { get; private set; } + + /// <summary> + /// Required amount of the fifth item + /// </summary> + public int Count5 { get; private set; } - //ugly af, but will rewrite when I imntegrade data bases
/// <summary>
- /// Checks if the parameter has enough of every requried item
+ /// Checks if the given array of items has enough of every requried item
/// </summary>
/// <returns><c>true</c>If has enough<c>false</c>otherwise</returns>
- /// <param name="items">Player items inventory (Inventory.Items)</param>
- public bool HasEnoughItems(ItemTile[] items) {
+ public bool HasEnoughItems(ItemTile[] items) + {
bool hasEnough = false;
- if (items.Any(r => r != null)) { - var allItems = items.Where(x => x != null).Select(x => x.stock_id).ToArray(); + if (items.Any(item => item != null)) + { + var allItemStocks = items.Where(x => x != null).Select(x => x.stock_id).ToArray(); - hasEnough = allItems.Contains(ReqItem1) && - allItems.Count(i => i == ReqItem1) >= Count1; + hasEnough = allItemStocks.Contains(ReqItem1) && + allItemStocks.Count(i => i == ReqItem1) >= Count1; - if (ReqItem2 != null && hasEnough) { - hasEnough = allItems.Contains(ReqItem2) && - allItems.Count(i => i == ReqItem2) >= Count2; + if (ReqItem2 != null && hasEnough) + { + hasEnough = allItemStocks.Contains(ReqItem2) && + allItemStocks.Count(i => i == ReqItem2) >= Count2; } - if (ReqItem3 != null && hasEnough) { - hasEnough = allItems.Contains(ReqItem3) && - allItems.Count(i => i == ReqItem3) >= Count3; + if (ReqItem3 != null && hasEnough) + { + hasEnough = allItemStocks.Contains(ReqItem3) && + allItemStocks.Count(i => i == ReqItem3) >= Count3; } - if (ReqItem4 != null && hasEnough) { - hasEnough = allItems.Contains(ReqItem4) && - allItems.Count(i => i == ReqItem4) >= Count4; + if (ReqItem4 != null && hasEnough) + { + hasEnough = allItemStocks.Contains(ReqItem4) && + allItemStocks.Count(i => i == ReqItem4) >= Count4; } - if (ReqItem5 != null && hasEnough) { - hasEnough = allItems.Contains(ReqItem5) && - allItems.Count(i => i == ReqItem5) >= Count5; + if (ReqItem5 != null && hasEnough) + { + hasEnough = allItemStocks.Contains(ReqItem5) && + allItemStocks.Count(i => i == ReqItem5) >= Count5; } }
return hasEnough; }
- public string[] GetAllRequiredItems() { + public string[] GetAllRequiredItems() + { return new string[] { ReqItem1, ReqItem2, ReqItem3, ReqItem4, ReqItem5}; }
- public int[] GetAllCounts() { + public int[] GetAllCounts() + { return new int[] { Count1, Count2, Count3, Count4, Count5}; } } |
