diff options
| -rw-r--r-- | Mundus/App.config | 12 | ||||
| -rw-r--r-- | Mundus/Data/Crafting/CraftingTableContext.cs | 52 | ||||
| -rw-r--r-- | Mundus/Data/Crafting/RI.cs | 41 | ||||
| -rw-r--r-- | Mundus/Data/Windows/WI.cs | 2 | ||||
| -rw-r--r-- | Mundus/Mundus.csproj | 142 | ||||
| -rw-r--r-- | Mundus/Program.cs | 9 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Crafting/CraftingController.cs | 62 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Crafting/CraftingRecipe.cs | 125 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Items/Presets/StructurePresets.cs | 7 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Items/Presets/ToolPresets.cs | 16 | ||||
| -rw-r--r-- | Mundus/Views/Windows/CraftingWindow.cs | 18 | ||||
| -rw-r--r-- | Mundus/packages.config | 39 |
12 files changed, 348 insertions, 177 deletions
diff --git a/Mundus/App.config b/Mundus/App.config new file mode 100644 index 0000000..d9ec5bd --- /dev/null +++ b/Mundus/App.config @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <configSections> + + <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> + </configSections> + <entityFramework> + <providers> + <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> + </providers> + </entityFramework> +</configuration>
\ No newline at end of file diff --git a/Mundus/Data/Crafting/CraftingTableContext.cs b/Mundus/Data/Crafting/CraftingTableContext.cs new file mode 100644 index 0000000..0a8c6c1 --- /dev/null +++ b/Mundus/Data/Crafting/CraftingTableContext.cs @@ -0,0 +1,52 @@ +using System.Linq;
+using Microsoft.EntityFrameworkCore; +using Mundus.Data.Superlayers.Mobs; +using Mundus.Service.Tiles.Crafting; +using Mundus.Service.Tiles.Items.Presets; + +namespace Mundus.Data.Crafting { + public class CraftingTableContext : DbContext {
+ public DbSet<CraftingRecipe> CraftingRecipes { get; set; }
+ + public CraftingTableContext() : base()
+ { }
+
+ + public void AddRecipes() { + ResetTable(); + + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenShovel().stock_id, 5, MaterialPresets.GetALandStick().stock_id)); + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenPickaxe().stock_id, 4, MaterialPresets.GetALandStick().stock_id)); + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenAxe().stock_id, 3, MaterialPresets.GetALandStick().stock_id)); + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenLongsword().stock_id, 4, MaterialPresets.GetALandStick().stock_id)); + + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockShovel().stock_id, 4, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockPickaxe().stock_id, 4, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockAxe().stock_id, 3, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); + CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockLongsword().stock_id, 5, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); + + CraftingRecipes.Add(new CraftingRecipe(StructurePresets.GetAWoodenLadder().inventory_stock_id, 6, MaterialPresets.GetALandStick().stock_id)); + + this.SaveChanges(); + } + + private void ResetTable() { + CraftingRecipes.RemoveRange(CraftingRecipes); + } + + public CraftingRecipe[] GetAvalableRecipes() {
+ var recipes = CraftingRecipes.ToArray(); + return recipes.Where(cr => cr.HasEnoughItems(MI.Player.Inventory.Items)).ToArray(); + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + optionsBuilder.UseMySQL( + "server=localhost;" + + "port=3306;" + + "user id=root; " + + "password=password; " + + "database=Mundus; " + + "SslMode=none"); + } + } +} diff --git a/Mundus/Data/Crafting/RI.cs b/Mundus/Data/Crafting/RI.cs deleted file mode 100644 index fd06dc4..0000000 --- a/Mundus/Data/Crafting/RI.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Collections.Generic; -using Mundus.Service.Tiles.Crafting; -using Mundus.Service.Tiles.Items.Presets; - -namespace Mundus.Data.Crafting { - public static class RI { //short for Recipe Instances - public static List<CraftingRecipe> AllRecipies { get; private set; } - - public static CraftingRecipe WoodenShovel { get; private set; } - public static CraftingRecipe WoodenPickaxe { get; private set; } - public static CraftingRecipe WoodenAxe { get; private set; } - public static CraftingRecipe WoodenLongsword { get; private set; } - - public static CraftingRecipe RockShovel { get; private set; } - public static CraftingRecipe RockPickaxe { get; private set; } - public static CraftingRecipe RockAxe { get; private set; } - public static CraftingRecipe RockLongsword { get; private set; } - - public static CraftingRecipe WoodenLadder { get; private set; } - - public static void CreateInstances() { - WoodenShovel = new CraftingRecipe(ToolPresets.GetAWoodenShovel(), 5, MaterialPresets.GetALandStick()); - WoodenPickaxe = new CraftingRecipe(ToolPresets.GetAWoodenPickaxe(), 4, MaterialPresets.GetALandStick()); - WoodenAxe = new CraftingRecipe(ToolPresets.GetAWoodenAxe(), 3, MaterialPresets.GetALandStick()); - WoodenLongsword = new CraftingRecipe(ToolPresets.GetAWoodenLongsword(), 4, MaterialPresets.GetALandStick()); - - RockShovel = new CraftingRecipe(ToolPresets.GetARockShovel(), 4, MaterialPresets.GetALandRock(), 2, MaterialPresets.GetALandStick()); - RockPickaxe = new CraftingRecipe(ToolPresets.GetARockPickaxe(), 4, MaterialPresets.GetALandRock(), 2, MaterialPresets.GetALandStick()); - RockAxe = new CraftingRecipe(ToolPresets.GetARockAxe(), 3, MaterialPresets.GetALandRock(), 2, MaterialPresets.GetALandStick()); - RockLongsword = new CraftingRecipe(ToolPresets.GetARockLongsword(), 5, MaterialPresets.GetALandRock(), 2, MaterialPresets.GetALandStick()); - - WoodenLadder = new CraftingRecipe(StructurePresets.GetAWoodenLadder(), 6, MaterialPresets.GetALandStick()); - - AllRecipies = new List<CraftingRecipe> { - WoodenShovel, WoodenPickaxe, WoodenAxe, WoodenLongsword, - RockShovel, RockPickaxe, RockAxe, RockLongsword, - WoodenLadder - }; - } - } -} diff --git a/Mundus/Data/Windows/WI.cs b/Mundus/Data/Windows/WI.cs index 70cb2bd..dbba9a8 100644 --- a/Mundus/Data/Windows/WI.cs +++ b/Mundus/Data/Windows/WI.cs @@ -2,7 +2,7 @@ namespace Mundus.Data.Windows { public static class WI { //stands for Window Instances - public const string BuildName = "Build 01-05-2020 No3"; + public const string BuildName = "Requirements Build"; public static IGameWindow SelWin { get; set; } diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index 206e1a9..1a23716 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -32,6 +32,144 @@ <Reference Include="gdk-sharp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="glib-sharp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="atk-sharp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+ <Reference Include="System.Data.SqlClient">
+ <HintPath>..\packages\System.Data.SqlClient.4.8.1\lib\net461\System.Data.SqlClient.dll</HintPath>
+ </Reference>
+ <Reference Include="mscorlib" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="Mono.Data.Sqlite" />
+ <Reference Include="BouncyCastle.Crypto">
+ <HintPath>..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll</HintPath>
+ </Reference>
+ <Reference Include="Google.Protobuf">
+ <HintPath>..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll</HintPath>
+ </Reference>
+ <Reference Include="Renci.SshNet">
+ <HintPath>..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Buffers">
+ <HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Numerics.Vectors">
+ <HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Numerics" />
+ <Reference Include="System.Runtime.CompilerServices.Unsafe">
+ <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Memory">
+ <HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
+ </Reference>
+ <Reference Include="K4os.Compression.LZ4">
+ <HintPath>..\packages\K4os.Compression.LZ4.1.1.11\lib\net46\K4os.Compression.LZ4.dll</HintPath>
+ </Reference>
+ <Reference Include="K4os.Hash.xxHash">
+ <HintPath>..\packages\K4os.Hash.xxHash.1.0.6\lib\net46\K4os.Hash.xxHash.dll</HintPath>
+ </Reference>
+ <Reference Include="K4os.Compression.LZ4.Streams">
+ <HintPath>..\packages\K4os.Compression.LZ4.Streams.1.1.11\lib\net46\K4os.Compression.LZ4.Streams.dll</HintPath>
+ </Reference>
+ <Reference Include="MySql.Data">
+ <HintPath>..\packages\MySql.Data.8.0.20\lib\net452\MySql.Data.dll</HintPath>
+ </Reference>
+ <Reference Include="Ubiety.Dns.Core">
+ <HintPath>..\packages\MySql.Data.8.0.20\lib\net452\Ubiety.Dns.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Zstandard.Net">
+ <HintPath>..\packages\MySql.Data.8.0.20\lib\net452\Zstandard.Net.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.ComponentModel" />
+ <Reference Include="System.ComponentModel.DataAnnotations" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Configuration.Install" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Drawing.Design" />
+ <Reference Include="System.Management" />
+ <Reference Include="System.Transactions" />
+ <Reference Include="Microsoft.Bcl.HashCode">
+ <HintPath>..\packages\Microsoft.Bcl.HashCode.1.1.0\lib\net461\Microsoft.Bcl.HashCode.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
+ <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.3.1.3\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Logging.Abstractions">
+ <HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
+ </Reference>
+ <Reference Include="System.ComponentModel.Annotations">
+ <HintPath>..\packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Primitives">
+ <HintPath>..\packages\Microsoft.Extensions.Primitives.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Caching.Abstractions">
+ <HintPath>..\packages\Microsoft.Extensions.Caching.Abstractions.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Caching.Abstractions.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Configuration.Abstractions">
+ <HintPath>..\packages\Microsoft.Extensions.Configuration.Abstractions.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Configuration">
+ <HintPath>..\packages\Microsoft.Extensions.Configuration.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Configuration.Binder">
+ <HintPath>..\packages\Microsoft.Extensions.Configuration.Binder.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Options">
+ <HintPath>..\packages\Microsoft.Extensions.Options.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Options.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Caching.Memory">
+ <HintPath>..\packages\Microsoft.Extensions.Caching.Memory.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Collections.Immutable">
+ <HintPath>..\packages\System.Collections.Immutable.1.7.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Diagnostics.DiagnosticSource">
+ <HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.7.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Threading.Tasks.Extensions">
+ <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Bcl.AsyncInterfaces">
+ <HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.DependencyInjection">
+ <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.3.1.3\lib\net461\Microsoft.Extensions.DependencyInjection.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Extensions.Logging">
+ <HintPath>..\packages\Microsoft.Extensions.Logging.3.1.3\lib\netstandard2.0\Microsoft.Extensions.Logging.dll</HintPath>
+ </Reference>
+ <Reference Include="Mono.Posix" />
+ <Reference Include="Microsoft.EntityFrameworkCore.Abstractions">
+ <HintPath>..\packages\Microsoft.EntityFrameworkCore.Abstractions.3.1.3\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Abstractions.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.EntityFrameworkCore">
+ <HintPath>..\packages\Microsoft.EntityFrameworkCore.3.1.3\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Identity.Client">
+ <HintPath>..\packages\Microsoft.Identity.Client.3.0.8\lib\net45\Microsoft.Identity.Client.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Core" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.IdentityModel" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.Common">
+ <HintPath>..\packages\System.Data.Common.4.3.0\lib\net451\System.Data.Common.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.SqlClient">
+ <HintPath>..\packages\Microsoft.Data.SqlClient.1.0.19269.1\lib\net46\Microsoft.Data.SqlClient.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.EntityFrameworkCore.Relational">
+ <HintPath>..\packages\Microsoft.EntityFrameworkCore.Relational.3.1.3\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Relational.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.EntityFrameworkCore.SqlServer">
+ <HintPath>..\packages\Microsoft.EntityFrameworkCore.SqlServer.3.1.3\lib\netstandard2.0\Microsoft.EntityFrameworkCore.SqlServer.dll</HintPath>
+ </Reference>
+ <Reference Include="MySql.Data.EntityFrameworkCore">
+ <HintPath>..\packages\MySql.Data.EntityFrameworkCore.8.0.20\lib\netstandard2.0\MySql.Data.EntityFrameworkCore.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic">
@@ -121,7 +259,6 @@ <Compile Include="Data\Tiles\ToolTypes.cs" />
<Compile Include="Service\Tiles\Items\Material.cs" />
<Compile Include="Service\Tiles\Items\Gear.cs" />
- <Compile Include="Data\Crafting\RI.cs" />
<Compile Include="Data\SuperLayers\Underground.cs" />
<Compile Include="Service\SuperLayers\Generators\LandSuperLayerGenerator.cs" />
<Compile Include="Service\SuperLayers\Generators\UndergroundSuperLayerGenerator.cs" />
@@ -155,6 +292,7 @@ <Compile Include="Views\Windows\GameWindows\LargeGameWindow.cs" />
<Compile Include="Views\Windows\GameWindows\MediumGameWindow.cs" />
<Compile Include="Views\Windows\GameWindows\SmallGameWindow.cs" />
+ <Compile Include="Data\Crafting\CraftingTableContext.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Service\" />
@@ -183,6 +321,8 @@ </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
+ <None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Project="..\packages\Microsoft.Data.SqlClient.SNI.1.0.19235.1\build\net46\Microsoft.Data.SqlClient.SNI.targets" Condition="Exists('..\packages\Microsoft.Data.SqlClient.SNI.1.0.19235.1\build\net46\Microsoft.Data.SqlClient.SNI.targets')" />
</Project>
\ No newline at end of file diff --git a/Mundus/Program.cs b/Mundus/Program.cs index 7ca908c..48992b5 100644 --- a/Mundus/Program.cs +++ b/Mundus/Program.cs @@ -6,19 +6,26 @@ using Mundus.Data.SuperLayers; using Mundus.Data.Windows; using Mundus.Data; using Mundus.Service; +using Mundus.Service.Tiles.Crafting; +using Mundus.Service.Tiles.Items.Presets; namespace Mundus { public static class MainClass { public static bool runGame = true; + public static CraftingTableContext CTController { get; private set; } public static void Main(string[] args) { + //DBController = new DatabaseController(); + //Data.Crafting.CraftingTableContext.CreateRecipes(); + CTController = new CraftingTableContext(); + CTController.AddRecipes(); + Application.Init(); //All windows and dialogues that are used by user (instances) are saved and created in WindowInstances.cs LogController.Initialize(); WI.CreateInstances(); DI.CreateInstances(); LI.CreateInstances(); - RI.CreateInstances(); WI.WMain.Show(); Application.Run(); diff --git a/Mundus/Service/Tiles/Crafting/CraftingController.cs b/Mundus/Service/Tiles/Crafting/CraftingController.cs index 61bc897..aedaa3a 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingController.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingController.cs @@ -4,38 +4,16 @@ 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; namespace Mundus.Service.Tiles.Crafting { public static class CraftingController { - private static Dictionary<ItemTile, int> avalableItems; - /// <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() { - FindAvalableItems(); - - List<CraftingRecipe> recipes = new List<CraftingRecipe>(); - - foreach (var recipe in RI.AllRecipies) { - if (recipe.HasEnoughItems(avalableItems)) { - recipes.Add(recipe); - } - } - - return recipes.ToArray(); - } - - // Sets avalableItems to all items in the player inventory (Inventory.Items) - private static void FindAvalableItems() { - avalableItems = MI.Player.Inventory.Items.Where(x => x != null) - //Can't use distinct on non primative types, beause they also hold their memory location info (I think). - //This is my way of getting only the "unique" item tiles. - .Select(x => x.stock_id).Distinct().Select(x => MI.Player.Inventory.Items.Where(y => y != null).First(y => y.stock_id == x)) - //For each "unique" item tile (key), get how many there are of it in the player inventory (value) - .Select(x => new KeyValuePair<ItemTile, int>(x, MI.Player.Inventory.Items.Where(y => y != null).Count(i => i.stock_id == x.stock_id))) - .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + return MainClass.CTController.GetAvalableRecipes(); } /// <summary> @@ -43,31 +21,25 @@ namespace Mundus.Service.Tiles.Crafting { /// </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 - foreach (var itemAndCount in itemRecipe.GetRequiredItemsAndCounts()) { - for(int i = 0, removedItems = 0; i < mob.Inventory.Items.Length && removedItems < itemAndCount.Value; i++) { - if (MI.Player.Inventory.Items[i] != null) { - if (MI.Player.Inventory.Items[i].stock_id == itemAndCount.Key.stock_id) { - MI.Player.Inventory.Items[i] = null; - removedItems++; - } + //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(); + + for (int item = 0; item < reqItems.Length; item++) + { + for (int i = 0, removed = 0; i < inventoryItems.Length && removed < reqCounts[item]; i++) + { + if (inventoryItems[i].stock_id == reqItems[item]) { + mob.Inventory.DeleteFromItems(i); + removed++; } } } - ItemTile tmp = null; - // Adds the result item to the inventory (in the correct data type) - if (itemRecipe.ResultItem.GetType() == typeof(Material)) { - tmp = new Material((Material)itemRecipe.ResultItem); - } - if (itemRecipe.ResultItem.GetType() == typeof(Tool)) { - tmp = new Tool((Tool)itemRecipe.ResultItem); - } - if (itemRecipe.ResultItem.GetType() == typeof(Gear)) { - tmp = new Gear((Gear)itemRecipe.ResultItem); - } - if (itemRecipe.ResultItem.GetType() == typeof(Structure)) { - tmp = new Structure((Structure)itemRecipe.ResultItem); + ItemTile tmp = ToolPresets.GetFromStock(itemRecipe.ResultItem); + if (tmp == null) { + tmp = StructurePresets.GetFromStock(itemRecipe.ResultItem); } MI.Player.Inventory.AppendToItems(tmp); diff --git a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs index af7ec7e..85833e2 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs @@ -1,14 +1,19 @@ 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 { +namespace Mundus.Service.Tiles.Crafting {
+ [Table("Recipes", 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 ItemTile ResultItem { get; private set; } + public string ResultItem { get; private set; } /// <summary>
/// Required amount of the first item
@@ -17,7 +22,7 @@ namespace Mundus.Service.Tiles.Crafting { /// <summary>
/// Required first item
/// </summary> - public ItemTile ReqItem1 { get; private set; } + public string ReqItem1 { get; private set; } /// <summary>
/// Required amount of the second item
@@ -26,7 +31,7 @@ namespace Mundus.Service.Tiles.Crafting { /// <summary>
/// Required second item
/// </summary> - public ItemTile ReqItem2 { get; private set; } + public string ReqItem2 { get; private set; } /// <summary>
/// Required amount of the third item
@@ -35,7 +40,7 @@ namespace Mundus.Service.Tiles.Crafting { /// <summary>
/// Required third item
/// </summary> - public ItemTile ReqItem3 { get; private set; } + public string ReqItem3 { get; private set; } /// <summary>
/// Required amount of the fourth item
@@ -44,7 +49,7 @@ namespace Mundus.Service.Tiles.Crafting { /// <summary>
/// Required fourth item
/// </summary> - public ItemTile ReqItem4 { get; private set; } + public string ReqItem4 { get; private set; } /// <summary>
/// Required amount of the fifth item
@@ -53,37 +58,37 @@ namespace Mundus.Service.Tiles.Crafting { /// <summary>
/// Required fifth item
/// </summary> - public ItemTile ReqItem5 { get; private set; } + public string ReqItem5 { get; private set; } - public CraftingRecipe(ItemTile resultItem, int count1, ItemTile 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(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile 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) : this(resultItem, count1, reqItem1, count2, reqItem2, 0, null, 0, null, 0, null) { } - public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile reqItem2, int count3, ItemTile 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) : this(resultItem, count1, reqItem1, count2, reqItem2, count3, reqItem3, 0, null, 0, null) { } - public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile reqItem2, int count3, ItemTile reqItem3, int count4, ItemTile 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) : this(resultItem, count1, reqItem1, count2, reqItem2, count3, reqItem3, count4, reqItem4, 0, null) { } - public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1, int count2, ItemTile reqItem2, int count3, ItemTile reqItem3, int count4, ItemTile reqItem4, int count5, ItemTile 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; + this.ReqItem2 = reqItem2; //reqItem2.stock_id; this.Count3 = count3; - this.ReqItem3 = reqItem3; + this.ReqItem3 = reqItem3; //reqItem3.stock_id; this.Count4 = count4; - this.ReqItem4 = reqItem4; + this.ReqItem4 = reqItem4; //reqItem4.stock_id; this.Count5 = count5; - this.ReqItem5 = reqItem5; + this.ReqItem5 = reqItem5; //reqItem5.stock_id; } //ugly af, but will rewrite when I imntegrade data bases
@@ -91,73 +96,43 @@ namespace Mundus.Service.Tiles.Crafting { /// Checks if the parameter has enough of every requried item
/// </summary>
/// <returns><c>true</c>If has enough<c>false</c>otherwise</returns>
- /// <param name="itemsAndCounts">Dictionary that has the items and their respective amounts (that will be checked)</param>
- public bool HasEnoughItems(Dictionary<ItemTile, int> itemsAndCounts) { - bool hasEnough = true;
+ /// <param name="items">Player items inventory (Inventory.Items)</param>
+ public bool HasEnoughItems(ItemTile[] items) {
+ bool hasEnough = false;
- if (ReqItem1 != null && hasEnough) {
- if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem1.stock_id)) {
- hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem1.stock_id).Value >= Count1;
- }
- else hasEnough = false;
- }
-
- if (ReqItem2 != null && hasEnough) {
- if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem2.stock_id)) { - hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem2.stock_id).Value >= Count2;
+ if (items.Any(r => r != null)) { + var allItems = items.Where(x => x != null).Select(x => x.stock_id).ToArray(); + + hasEnough = allItems.Contains(ReqItem1) && + allItems.Count(i => i == ReqItem1) >= Count1; + + if (ReqItem2 != null && hasEnough) { + hasEnough = allItems.Contains(ReqItem2) && + allItems.Count(i => i == ReqItem2) >= Count2; + } + if (ReqItem3 != null && hasEnough) { + hasEnough = allItems.Contains(ReqItem3) && + allItems.Count(i => i == ReqItem3) >= Count3; + } + if (ReqItem4 != null && hasEnough) { + hasEnough = allItems.Contains(ReqItem4) && + allItems.Count(i => i == ReqItem4) >= Count4; + } + if (ReqItem5 != null && hasEnough) { + hasEnough = allItems.Contains(ReqItem5) && + allItems.Count(i => i == ReqItem5) >= Count5; } - else hasEnough = false; - }
-
- if (ReqItem3 != null && hasEnough) {
- if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem3.stock_id)) {
- hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem3.stock_id).Value >= Count3;
- }
- else hasEnough = false;
- }
-
- if (ReqItem4 != null && hasEnough) {
- if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem4.stock_id)) {
- hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem4.stock_id).Value >= Count4;
- }
- else hasEnough = false;
- }
-
- if (ReqItem5 != null && hasEnough) {
- if (itemsAndCounts.Keys.Any(k => k.stock_id == ReqItem5.stock_id)) {
- hasEnough = itemsAndCounts.First(x => x.Key.stock_id == ReqItem5.stock_id).Value >= Count5;
- }
- else hasEnough = false;
}
return hasEnough; }
- /// <summary>
- /// Checks if the given item (and amount) is enough for the recipe
- /// </summary> - public bool HasEnoughOfItem(ItemTile item, int count) { - if (ReqItem1.stock_id == item.stock_id) return count >= Count1; - if (ReqItem2.stock_id == item.stock_id) return count >= Count2; - if (ReqItem3.stock_id == item.stock_id) return count >= Count3; - if (ReqItem4.stock_id == item.stock_id) return count >= Count4; - if (ReqItem5.stock_id == item.stock_id) return count >= Count5; - return false; - } -
- /// <summary>
- /// Returns a dictionary of every required item and their respective amount
- /// </summary> - public Dictionary<ItemTile, int> GetRequiredItemsAndCounts() { - Dictionary<ItemTile, int> req = new Dictionary<ItemTile, int>();
-
- req.Add(ReqItem1, Count1);
- if (ReqItem2 != null) req.Add(ReqItem2, Count2);
- if (ReqItem3 != null) req.Add(ReqItem3, Count3);
- if (ReqItem4 != null) req.Add(ReqItem4, Count4);
- if (ReqItem5 != null) req.Add(ReqItem5, Count5);
+ public string[] GetAllRequiredItems() { + return new string[] { ReqItem1, ReqItem2, ReqItem3, ReqItem4, ReqItem5}; + }
- return req; + public int[] GetAllCounts() { + return new int[] { Count1, Count2, Count3, Count4, Count5}; } } } diff --git a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs b/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs index 1834de4..e71111a 100644 --- a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs @@ -26,5 +26,12 @@ namespace Mundus.Service.Tiles.Items.Presets { public static Structure GetAWoodenLadder() { return new Structure("L_wooden_ladder", "L_wooden_ladder_inventory", 1, ToolTypes.Axe, 1, true, true); } + + public static Structure GetFromStock(string stock_id) { + switch(stock_id) { + case "L_wooden_ladder": return GetAWoodenLadder(); + default: return null; + } + } } } diff --git a/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs b/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs index d18f089..a52e027 100644 --- a/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs @@ -25,7 +25,7 @@ namespace Mundus.Service.Tiles.Items.Presets { public static Tool GetARockAxe() { return new Tool("rock_axe", ToolTypes.Axe, 2); } - + public static Tool GetARockShovel() { return new Tool("rock_shovel", ToolTypes.Shovel, 2); } @@ -33,5 +33,19 @@ namespace Mundus.Service.Tiles.Items.Presets { public static Tool GetARockLongsword() { return new Tool("rock_longsword", ToolTypes.Sword, 4); } + + public static Tool GetFromStock(string stock_id) { + switch(stock_id) { + case "wooden_pickaxe": return GetAWoodenPickaxe(); + case "wooden_axe": return GetAWoodenAxe(); + case "wooden_shovel": return GetAWoodenShovel(); + case "wooden_longsword": return GetAWoodenLongsword(); + case "rock_pickaxe": return GetARockPickaxe(); + case "rock_axe": return GetARockAxe(); + case "rock_shovel": return GetARockShovel(); + case "rock_longsword": return GetARockLongsword(); + default: return null; + } + } } } diff --git a/Mundus/Views/Windows/CraftingWindow.cs b/Mundus/Views/Windows/CraftingWindow.cs index 56d9549..43ba6ff 100644 --- a/Mundus/Views/Windows/CraftingWindow.cs +++ b/Mundus/Views/Windows/CraftingWindow.cs @@ -37,36 +37,30 @@ namespace Mundus.Views.Windows { CraftingRecipe recipe = Recipes[recipeIndex]; btnCraft.Sensitive = true; - if (recipe.ResultItem.GetType() == typeof(Structure)) { - Structure tmp = (Structure)recipe.ResultItem; - imgItem.SetFromStock(tmp.inventory_stock_id, IconSize.Dnd); - } - else { - imgItem.SetFromStock(recipe.ResultItem.stock_id, IconSize.Dnd); - } + imgItem.SetFromStock(recipe.ResultItem, IconSize.Dnd); lblInfo.Text = recipe.ResultItem.ToString(); lblC1.Text = recipe.Count1 + ""; - imgI1.SetFromStock(recipe.ReqItem1.stock_id, IconSize.Dnd); + imgI1.SetFromStock(recipe.ReqItem1, IconSize.Dnd); if (recipe.ReqItem2 != null) { lblC2.Text = recipe.Count2 + ""; - imgI2.SetFromStock(recipe.ReqItem2.stock_id, IconSize.Dnd); + imgI2.SetFromStock(recipe.ReqItem2, IconSize.Dnd); } if (recipe.ReqItem3 != null) { lblC3.Text = recipe.Count3 + ""; - imgI3.SetFromStock(recipe.ReqItem3.stock_id, IconSize.Dnd); + imgI3.SetFromStock(recipe.ReqItem3, IconSize.Dnd); } if (recipe.ReqItem4 != null) { lblC4.Text = recipe.Count4 + ""; - imgI4.SetFromStock(recipe.ReqItem4.stock_id, IconSize.Dnd); + imgI4.SetFromStock(recipe.ReqItem4, IconSize.Dnd); } if (recipe.ReqItem5 != null) { lblC5.Text = recipe.Count5 + ""; - imgI5.SetFromStock(recipe.ReqItem5.stock_id, IconSize.Dnd); + imgI5.SetFromStock(recipe.ReqItem5, IconSize.Dnd); } } } diff --git a/Mundus/packages.config b/Mundus/packages.config index cc1fbe7..cc8415d 100644 --- a/Mundus/packages.config +++ b/Mundus/packages.config @@ -1,4 +1,43 @@ <?xml version="1.0" encoding="utf-8"?> <packages> + <package id="BouncyCastle" version="1.8.3.1" targetFramework="net47" /> + <package id="Google.Protobuf" version="3.6.1" targetFramework="net47" /> + <package id="K4os.Compression.LZ4" version="1.1.11" targetFramework="net47" /> + <package id="K4os.Compression.LZ4.Streams" version="1.1.11" targetFramework="net47" /> + <package id="K4os.Hash.xxHash" version="1.0.6" targetFramework="net47" /> + <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net47" /> + <package id="Microsoft.Bcl.HashCode" version="1.1.0" targetFramework="net47" /> + <package id="Microsoft.Data.SqlClient" version="1.0.19269.1" targetFramework="net47" /> + <package id="Microsoft.Data.SqlClient.SNI" version="1.0.19235.1" targetFramework="net47" /> + <package id="Microsoft.EntityFrameworkCore" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.EntityFrameworkCore.Abstractions" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.EntityFrameworkCore.Analyzers" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.EntityFrameworkCore.Relational" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.EntityFrameworkCore.SqlServer" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Caching.Abstractions" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Caching.Memory" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Configuration" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Configuration.Abstractions" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Configuration.Binder" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.DependencyInjection" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Logging" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Logging.Abstractions" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Options" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Extensions.Primitives" version="3.1.3" targetFramework="net47" /> + <package id="Microsoft.Identity.Client" version="3.0.8" targetFramework="net47" /> + <package id="MySql.Data" version="8.0.20" targetFramework="net47" /> + <package id="MySql.Data.EntityFrameworkCore" version="8.0.20" targetFramework="net47" /> + <package id="SSH.NET" version="2016.1.0" targetFramework="net47" /> <package id="StyleCop.Analyzers" version="1.1.118" targetFramework="net47" developmentDependency="true" /> + <package id="System.Buffers" version="4.5.0" targetFramework="net47" /> + <package id="System.Collections.Immutable" version="1.7.0" targetFramework="net47" /> + <package id="System.ComponentModel.Annotations" version="4.7.0" targetFramework="net47" /> + <package id="System.Data.Common" version="4.3.0" targetFramework="net47" /> + <package id="System.Data.SqlClient" version="4.8.1" targetFramework="net47" /> + <package id="System.Diagnostics.DiagnosticSource" version="4.7.0" targetFramework="net47" /> + <package id="System.Memory" version="4.5.3" targetFramework="net47" /> + <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net47" /> + <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net47" /> + <package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net47" /> </packages>
\ No newline at end of file |
