From 39cba7ccdfc9e71e8bff5df2f1a6ff28a2ae3556 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 12 May 2020 12:37:53 +0300 Subject: Finished refactoring of data layer. Found a wierd bug with mob fighting (some are shown but you cant interract, after killing one the drops from the same mob are broken). --- CREATE MySQL queries.sql | 2 +- Mundus/Data/Crafting/CraftingTableContext.cs | 90 +++++++---- Mundus/Data/DataBaseContexts.cs | 47 +++++- Mundus/Data/Dialogues/DI.cs | 33 +++- Mundus/Data/GameEventLog.cs | 16 -- Mundus/Data/GameEventLogContext.cs | 37 ----- Mundus/Data/GameEventLogs/GameEventLog.cs | 28 ++++ Mundus/Data/GameEventLogs/GameEventLogContext.cs | 64 ++++++++ Mundus/Data/SuperLayers/DBTables/LGPlacedTile.cs | 15 +- Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs | 23 ++- Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs | 22 ++- Mundus/Data/SuperLayers/DBTables/PlacedTile.cs | 37 ++++- Mundus/Data/SuperLayers/DBTables/SGPlacedTile.cs | 15 +- Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs | 22 ++- Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs | 22 ++- Mundus/Data/SuperLayers/DBTables/UGPlacedTile.cs | 15 +- Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs | 22 ++- Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs | 22 ++- Mundus/Data/SuperLayers/ISuperLayerContext.cs | 64 +++++++- Mundus/Data/SuperLayers/LandContext.cs | 188 ++++++++++++++++------- Mundus/Data/SuperLayers/Mobs/MI.cs | 22 ++- Mundus/Data/SuperLayers/SkyContext.cs | 187 +++++++++++++++------- Mundus/Data/SuperLayers/UndergroundContext.cs | 187 +++++++++++++++------- Mundus/Data/Values.cs | 49 ++++-- Mundus/Data/Windows/WI.cs | 74 ++++++++- Mundus/Mundus.csproj | 13 +- Mundus/Service/Tiles/Crafting/CraftingRecipe.cs | 2 +- 27 files changed, 945 insertions(+), 373 deletions(-) delete mode 100644 Mundus/Data/GameEventLog.cs delete mode 100644 Mundus/Data/GameEventLogContext.cs create mode 100644 Mundus/Data/GameEventLogs/GameEventLog.cs create mode 100644 Mundus/Data/GameEventLogs/GameEventLogContext.cs diff --git a/CREATE MySQL queries.sql b/CREATE MySQL queries.sql index 399eff9..8f0edc7 100644 --- a/CREATE MySQL queries.sql +++ b/CREATE MySQL queries.sql @@ -6,7 +6,7 @@ CREATE TABLE GameEventLogs ( message VARCHAR(100) NOT NULL ); -CREATE TABLE Recipes ( +CREATE TABLE CraftingRecipes ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, resultitem VARCHAR(45) NOT NULL, count1 INT NOT NULL, diff --git a/Mundus/Data/Crafting/CraftingTableContext.cs b/Mundus/Data/Crafting/CraftingTableContext.cs index 6f7c6bb..284573f 100644 --- a/Mundus/Data/Crafting/CraftingTableContext.cs +++ b/Mundus/Data/Crafting/CraftingTableContext.cs @@ -1,45 +1,73 @@ -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 CraftingRecipes { get; private set; } +namespace Mundus.Data.Crafting +{ + using System.Linq; + using Microsoft.EntityFrameworkCore; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Service.Tiles.Crafting; + using Mundus.Service.Tiles.Items.Presets; + /// + /// Context for getting the crafting recipes + /// + public class CraftingTableContext : DbContext + { + /// + /// Initializes a new instance of the class and adds all the recipes to the table + /// public CraftingTableContext() : base() - { } + { + this.AddRecipes(); + } - public void AddRecipes() { - ResetTable(); + /// + /// Gets DBSet of the CraftingRecipes table + /// + /// The crafting recipes. + public DbSet CraftingRecipes { get; private set; } - 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)); + /// + /// Returns an array with all the recipes that can be crafted with the items the player has + /// + public CraftingRecipe[] GetAvalableRecipes() + { + var recipes = this.CraftingRecipes.ToArray(); + return recipes.Where(cr => cr.HasEnoughItems(MI.Player.Inventory.Items)).ToArray(); + } - 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)); + // Used to set the connection string + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); + } - CraftingRecipes.Add(new CraftingRecipe(StructurePresets.GetAWoodenLadder().inventory_stock_id, 6, MaterialPresets.GetALandStick().stock_id)); + /// + /// Truncates CraftingRecipes table and adds the crafting recipes (and saves changes) + /// + private void AddRecipes() + { + this.TruncateTable(); - this.SaveChanges(); - } + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenShovel().stock_id, 5, MaterialPresets.GetALandStick().stock_id)); + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenPickaxe().stock_id, 4, MaterialPresets.GetALandStick().stock_id)); + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenAxe().stock_id, 3, MaterialPresets.GetALandStick().stock_id)); + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetAWoodenLongsword().stock_id, 4, MaterialPresets.GetALandStick().stock_id)); - private void ResetTable() { - CraftingRecipes.RemoveRange(CraftingRecipes); - } + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockShovel().stock_id, 4, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockPickaxe().stock_id, 4, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockAxe().stock_id, 3, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); + this.CraftingRecipes.Add(new CraftingRecipe(ToolPresets.GetARockLongsword().stock_id, 5, MaterialPresets.GetALandRock().stock_id, 2, MaterialPresets.GetALandStick().stock_id)); - public CraftingRecipe[] GetAvalableRecipes() { - var recipes = CraftingRecipes.ToArray(); - return recipes.Where(cr => cr.HasEnoughItems(MI.Player.Inventory.Items)).ToArray(); + this.CraftingRecipes.Add(new CraftingRecipe(StructurePresets.GetAWoodenLadder().inventory_stock_id, 6, MaterialPresets.GetALandStick().stock_id)); + + this.SaveChanges(); } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); + /// + /// Truncates the table CraftingRecipes (doesn't save the changes) + /// + private void TruncateTable() + { + this.Database.ExecuteSqlRaw("TRUNCATE TABLE CraftingRecipes"); } } } diff --git a/Mundus/Data/DataBaseContexts.cs b/Mundus/Data/DataBaseContexts.cs index 77425c2..44cad65 100644 --- a/Mundus/Data/DataBaseContexts.cs +++ b/Mundus/Data/DataBaseContexts.cs @@ -1,9 +1,17 @@ -using System; -using Mundus.Data.Crafting; -using Mundus.Data.SuperLayers; +namespace Mundus.Data +{ + using Mundus.Data.Crafting; + using Mundus.Data.GameEventLogs; + using Mundus.Data.SuperLayers; -namespace Mundus.Data { - public static class DataBaseContexts { + /// + /// Used to store all the contexts that correspond to the database tables + /// + public static class DataBaseContexts + { + /// + /// The connection string for MySQL + /// public const string ConnectionStringMySQL = "server=localhost;" + "port=3306;" + "user id=root; " + @@ -11,17 +19,42 @@ namespace Mundus.Data { "database=Mundus; " + "SslMode=none"; + /// + /// Gets the crafting table context instance + /// public static CraftingTableContext CTContext { get; private set; } + + /// + /// Gets the game event log table context instance + /// public static GameEventLogContext GELContext { get; private set; } + /// + /// Gets the sky superlayer context instance + /// public static SkyContext SContext { get; private set; } + + /// + /// Gets the land superlayer context instance + /// public static LandContext LContext { get; private set; } + + /// + /// Gets the underground superlayer context instance + /// public static UndergroundContext UContext { get; private set; } + + /// + /// Gets the an array of all superlayer context instances + /// public static ISuperLayerContext[] SuperLayerContexts { get; private set; } - public static void CreateInstances() { + /// + /// Creates all instances of the contexts + /// + public static void CreateInstances() + { CTContext = new CraftingTableContext(); - CTContext.AddRecipes(); GELContext = new GameEventLogContext(); SContext = new SkyContext(); diff --git a/Mundus/Data/Dialogues/DI.cs b/Mundus/Data/Dialogues/DI.cs index 2f5bd3d..94f9ae7 100644 --- a/Mundus/Data/Dialogues/DI.cs +++ b/Mundus/Data/Dialogues/DI.cs @@ -1,19 +1,36 @@ -using Mundus.Views.Dialogs; -using Gtk; +namespace Mundus.Data.Dialogues +{ + using Mundus.Views.Dialogs; -namespace Mundus.Data.Dialogues { - public static class DI { //stands for Dialogue Instances + /// + /// Dialog Instances + /// Stores and creates all needed dialogs + /// + public static class DI + { + /// + /// Gets the exit dialoge + /// public static ExitDialog DExit { get; private set; } - public static void CreateInstances() { + /// + /// Creates all dialog instances + /// + public static void CreateInstances() + { DExit = new ExitDialog(); HideAll(); } - //Gtk opens all dialog (window) instances in the project automatically, unless they are hidden - private static void HideAll() { + /// + /// Hides all dialogs + /// Gtk opens all dialog (window) instances in the project automatically, + /// so you need to manually hide them + /// + private static void HideAll() + { DExit.Hide(); } } -} +} \ No newline at end of file diff --git a/Mundus/Data/GameEventLog.cs b/Mundus/Data/GameEventLog.cs deleted file mode 100644 index eee5b54..0000000 --- a/Mundus/Data/GameEventLog.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Mundus.Data { - [Table("GameEventLogs", Schema = "Mundus")] - public class GameEventLog { - [Key] - public int ID { get; private set; } - public string Message { get; private set; } - - public GameEventLog(string message) { - this.Message = message; - } - } -} diff --git a/Mundus/Data/GameEventLogContext.cs b/Mundus/Data/GameEventLogContext.cs deleted file mode 100644 index eda4ffe..0000000 --- a/Mundus/Data/GameEventLogContext.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using Mundus.Service; - -namespace Mundus.Data { - public class GameEventLogContext : DbContext { - public DbSet GameEventLogs { get; private set; } - - public GameEventLogContext() :base() - { - ResetTable(); - } - - private void ResetTable() { - Database.ExecuteSqlRaw("TRUNCATE TABLE GameEventLogs;"); - SaveChanges(); - } - - public void AddMessage(string message) { - GameEventLogs.Add(new GameEventLog(message)); - this.SaveChanges(); - } - - public string GetMessage(int id) { - return GameEventLogs.Single(x => x.ID == id).Message; - } - - public int GetCount() { - return GameEventLogs.Count(); - } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); - } - } -} diff --git a/Mundus/Data/GameEventLogs/GameEventLog.cs b/Mundus/Data/GameEventLogs/GameEventLog.cs new file mode 100644 index 0000000..61b38b4 --- /dev/null +++ b/Mundus/Data/GameEventLogs/GameEventLog.cs @@ -0,0 +1,28 @@ +namespace Mundus.Data.GameEventLogs +{ + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + + /// + /// Data type for the DBSet of GameEventLogs table + /// + [Table("GameEventLogs", Schema = "Mundus")] + public class GameEventLog + { + public GameEventLog(string message) + { + this.Message = message; + } + + /// + /// Gets the unique identifier (primary key ; only used in the tables by MySQL) + /// + [Key] + public int ID { get; private set; } + + /// + /// Gets the message of the log + /// + public string Message { get; private set; } + } +} \ No newline at end of file diff --git a/Mundus/Data/GameEventLogs/GameEventLogContext.cs b/Mundus/Data/GameEventLogs/GameEventLogContext.cs new file mode 100644 index 0000000..5440bd8 --- /dev/null +++ b/Mundus/Data/GameEventLogs/GameEventLogContext.cs @@ -0,0 +1,64 @@ +namespace Mundus.Data.GameEventLogs +{ + using System.Linq; + using Microsoft.EntityFrameworkCore; + + /// + /// Add and get log messages from the GameEventLogs table + /// + public class GameEventLogContext : DbContext + { + /// + /// Initializes a new instance of the class and truncates the table + /// + public GameEventLogContext() : base() + { + this.ResetTable(); + } + + /// + /// Gets DbSet of the game event logs table + /// + public DbSet GameEventLogs { get; private set; } + + /// + /// Adds a message to the GameEventLogs table + /// + public void AddMessage(string message) + { + this.GameEventLogs.Add(new GameEventLog(message)); + this.SaveChanges(); + } + + /// + /// Gets a message from the GameEventLogs table that has the specified id + /// + public string GetMessage(int id) + { + return this.GameEventLogs.Single(x => x.ID == id).Message; + } + + /// + /// Gets count of game event logs + /// + public int GetCount() + { + return this.GameEventLogs.Count(); + } + + // Used to set the connection string + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); + } + + /// + /// Truncates the GameEventLogs table (saves the change) + /// + private void ResetTable() + { + this.Database.ExecuteSqlRaw("TRUNCATE TABLE GameEventLogs;"); + this.SaveChanges(); + } + } +} \ No newline at end of file diff --git a/Mundus/Data/SuperLayers/DBTables/LGPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/LGPlacedTile.cs index 44a0db3..e7ef095 100644 --- a/Mundus/Data/SuperLayers/DBTables/LGPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/LGPlacedTile.cs @@ -1,10 +1,15 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Land) LGroundLayer table + /// [Table("LGroundLayer", Schema = "Mundus")] - public class LGPlacedTile : PlacedTile { - public LGPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class LGPlacedTile : PlacedTile + { + public LGPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) + { } } } diff --git a/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs index a61c39c..a009ef6 100644 --- a/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs @@ -1,14 +1,21 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; -using Mundus.Data.Windows; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Land) LMobLayer table + /// [Table("LMobLayer", Schema = "Mundus")] - public class LMPlacedTile : PlacedTile { - public int Health { get; set; } - - public LMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class LMPlacedTile : PlacedTile + { + public LMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) + { this.Health = health; } + + /// + /// Gets or sets the health of the mob + /// + public int Health { get; set; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs index a4ab6e3..44d095b 100644 --- a/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs @@ -1,13 +1,21 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Land) LStructureLayer table + /// [Table("LStructureLayer", Schema = "Mundus")] - public class LSPlacedTile : PlacedTile { - public int Health { get; set; } - - public LSPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class LSPlacedTile : PlacedTile + { + public LSPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) + { this.Health = health; } + + /// + /// Gets or sets the health of the structure + /// + public int Health { get; set; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/PlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/PlacedTile.cs index 31bd1bb..53c7dd2 100644 --- a/Mundus/Data/SuperLayers/DBTables/PlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/PlacedTile.cs @@ -1,14 +1,35 @@ -namespace Mundus.Data.SuperLayers.DBTables { - public abstract class PlacedTile { - public int ID { get; private set; } - public int XPos { get; private set; } - public int YPos { get; private set; } - public string stock_id { get; set; } - - public PlacedTile(string stock_id, int yPos, int xPos) { +namespace Mundus.Data.SuperLayers.DBTables +{ + /// + /// Abstract class that is used for the classes that correspond to DBSets + /// + public abstract class PlacedTile + { + public PlacedTile(string stock_id, int yPos, int xPos) + { this.YPos = yPos; this.XPos = xPos; this.stock_id = stock_id; } + + /// + /// Gets the unique identifier (primary key ; only used in the tables by MySQL) + /// + public int ID { get; private set; } + + /// + /// Gets the position on the horizontal (x) axis of the tile in it's layer + /// + public int XPos { get; private set; } + + /// + /// Gets the position on the vertical (y) axis of the tile in it's layer + /// + public int YPos { get; private set; } + + /// + /// Gets or sets the stock _id of the tile + /// + public string stock_id { get; set; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/SGPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/SGPlacedTile.cs index 0791cc4..74a41a4 100644 --- a/Mundus/Data/SuperLayers/DBTables/SGPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/SGPlacedTile.cs @@ -1,10 +1,15 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Sky) SGroundLayer table + /// [Table("SGroundLayer", Schema = "Mundus")] - public class SGPlacedTile : PlacedTile { - public SGPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class SGPlacedTile : PlacedTile + { + public SGPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) + { } } } diff --git a/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs index 36bc5bf..ad2fd23 100644 --- a/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs @@ -1,13 +1,21 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Sky) SMobLayer table + /// [Table("SMobLayer", Schema = "Mundus")] - public class SMPlacedTile : PlacedTile { - public int Health { get; set; } - - public SMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class SMPlacedTile : PlacedTile + { + public SMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) + { this.Health = health; } + + /// + /// Gets or sets the health of the mob + /// + public int Health { get; set; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs index 251a568..f70eee4 100644 --- a/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs @@ -1,13 +1,21 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Sky) SStructureLayer table + /// [Table("SStructureLayer", Schema = "Mundus")] - public class SSPlacedTile : PlacedTile { - public int Health { get; set; } - - public SSPlacedTile(string stock_id, int health, int yPos, int xPos):base(stock_id, yPos, xPos) { + public class SSPlacedTile : PlacedTile + { + public SSPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) + { this.Health = health; } + + /// + /// Gets or sets the health of the structure + /// + public int Health { get; set; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/UGPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/UGPlacedTile.cs index 762af7e..8c1240a 100644 --- a/Mundus/Data/SuperLayers/DBTables/UGPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/UGPlacedTile.cs @@ -1,10 +1,15 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Undergound) UGroundLayer table + /// [Table("UGroundLayer", Schema = "Mundus")] - public class UGPlacedTile : PlacedTile { - public UGPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class UGPlacedTile : PlacedTile + { + public UGPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) + { } } } diff --git a/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs index 0f2fdbc..fb60068 100644 --- a/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs @@ -1,13 +1,21 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Undergound) UMobLayer table + /// [Table("UMobLayer", Schema = "Mundus")] - public class UMPlacedTile : PlacedTile { - public int Health { get; set; } - - public UMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class UMPlacedTile : PlacedTile + { + public UMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) + { this.Health = health; } + + /// + /// Gets or sets the health of the mob + /// + public int Health { get; set; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs index d536640..90478e4 100644 --- a/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs @@ -1,13 +1,21 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +namespace Mundus.Data.SuperLayers.DBTables +{ + using System.ComponentModel.DataAnnotations.Schema; -namespace Mundus.Data.SuperLayers.DBTables { + /// + /// Data type for the DBSet of (Undergound) UStructureLayer table + /// [Table("UStructureLayer", Schema = "Mundus")] - public class USPlacedTile : PlacedTile { - public int Health { get; set; } - - public USPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public class USPlacedTile : PlacedTile + { + public USPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) + { this.Health = health; } + + /// + /// Gets or sets the health of the structure + /// + public int Health { get; set; } } } diff --git a/Mundus/Data/SuperLayers/ISuperLayerContext.cs b/Mundus/Data/SuperLayers/ISuperLayerContext.cs index 20a5551..e6884ad 100644 --- a/Mundus/Data/SuperLayers/ISuperLayerContext.cs +++ b/Mundus/Data/SuperLayers/ISuperLayerContext.cs @@ -1,22 +1,80 @@ -using System; -namespace Mundus.Data.SuperLayers { - public interface ISuperLayerContext { +namespace Mundus.Data.SuperLayers +{ + /// + /// Add, remove and change values in the different superlayers (database tables) + /// + public interface ISuperLayerContext + { + /// + /// Returns the stock_id of the mob at the specified positoin + /// string GetMobLayerStock(int yPos, int xPos); + + /// + /// Returns the stock_id of the structure at the specified positoin + /// string GetStructureLayerStock(int yPos, int xPos); + + /// + /// Returns the stock_id of the ground (tile) at the specified positoin + /// string GetGroundLayerStock(int yPos, int xPos); + /// + /// Adds a mob's stock_id, it's health and the specified position in the mob layer table + /// void AddMobAtPosition(string stock_id, int health, int yPos, int xPos); + + /// + /// Sets the mob's stock_id and health for the specified position of the mob layer table + /// void SetMobAtPosition(string stock_id, int health, int yPos, int xPos); + + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the mob layer table + /// void RemoveMobFromPosition(int yPos, int xPos); + + /// + /// Removes health from the mob on the specified position in the mob layer table + /// + /// trueIf the mob can still be damaged (alive)false otherwise. bool TakeDamageMobAtPosition(int yPos, int xPos, int damage); + /// + /// Adds a structure's stock_id, it's health and the specified position in the structure layer table + /// void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos); + + /// + /// Sets the structure's stock_id and health for the specified position of the structure layer table + /// void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos); + + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the structure layer table + /// void RemoveStructureFromPosition(int yPos, int xPos); + + /// + /// Removes health from the structure on the specified position in the structure layer table + /// + /// trueIf the structure can still be damaged false otherwise. bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage); + /// + /// Adds a ground (tile)'s stock_id and the specified position in the ground (tile) layer table + /// void AddGroundAtPosition(string stock_id, int yPos, int xPos); + + /// + /// Sets the ground (tile)'s stock_id and health for the specified position of the ground (tile) layer table + /// void SetGroundAtPosition(string stock_id, int yPos, int xPos); + + /// + /// Sets invalid values for stock_id (null) for the specified position of the ground (tile) layer table + /// void RemoveGroundFromPosition(int yPos, int xPos); } } diff --git a/Mundus/Data/SuperLayers/LandContext.cs b/Mundus/Data/SuperLayers/LandContext.cs index 26f6f41..7e23498 100644 --- a/Mundus/Data/SuperLayers/LandContext.cs +++ b/Mundus/Data/SuperLayers/LandContext.cs @@ -1,92 +1,166 @@ -using System; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using Mundus.Data.SuperLayers.DBTables; -using Mundus.Service.SuperLayers; -using Mundus.Service.Tiles.Mobs.LandMobs; - -namespace Mundus.Data.SuperLayers { - public class LandContext : DbContext, ISuperLayerContext { +namespace Mundus.Data.SuperLayers +{ + using System.Linq; + using Microsoft.EntityFrameworkCore; + using Mundus.Data.SuperLayers.DBTables; + + /// + /// Add, remove and change values in the land superlayer + /// + public class LandContext : DbContext, ISuperLayerContext + { + /// + /// Initializes a new instance of the LandContext class and truncates all related tables + /// + public LandContext() : base() + { + this.Database.ExecuteSqlRaw("TRUNCATE TABLE LMobLayer"); + this.Database.ExecuteSqlRaw("TRUNCATE TABLE LStructureLayer"); + this.Database.ExecuteSqlRaw("TRUNCATE TABLE LGroundLayer"); + + this.SaveChanges(); + } + + /// + /// Gets DBSet of the land mob layer table + /// public DbSet LMobLayer { get; private set; } + + /// + /// Gets DBSet of the land structure layer table + /// public DbSet LStructureLayer { get; private set; } + + /// + /// Gets DBSet of the land ground (tile) layer table + /// public DbSet LGroundLayer { get; private set; } - public LandContext() : base() { - Database.ExecuteSqlRaw("TRUNCATE TABLE LMobLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE LStructureLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE LGroundLayer"); - SaveChanges(); + /// + /// Returns the stock_id of the mob at the specified positoin + /// + public string GetMobLayerStock(int yPos, int xPos) + { + return this.LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public string GetMobLayerStock(int yPos, int xPos) { - return LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; + /// + /// Returns the stock_id of the structure at the specified positoin + /// + public string GetStructureLayerStock(int yPos, int xPos) + { + return this.LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public string GetStructureLayerStock(int yPos, int xPos) { - return LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; - } - public string GetGroundLayerStock(int yPos, int xPos) { - return LGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; + + /// + /// Returns the stock_id of the ground (tile) at the specified positoin + /// + public string GetGroundLayerStock(int yPos, int xPos) + { + return this.LGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) { - LMobLayer.Add(new LMPlacedTile(stock_id, health, yPos, xPos)); - + /// + /// Adds a mob's stock_id, it's health and the specified position in the mob layer table + /// + public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.LMobLayer.Add(new LMPlacedTile(stock_id, health, yPos, xPos)); } - public void SetMobAtPosition(string stock_id, int health, int yPos, int xPos) { - LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; + /// + /// Sets the mob's stock_id and health for the specified position of the mob layer table + /// + public void SetMobAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; + this.LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; } - public void RemoveMobFromPosition(int yPos, int xPos) { - LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; + + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the mob layer table + /// + public void RemoveMobFromPosition(int yPos, int xPos) + { + this.LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; + this.LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; } - public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) { - var mob = LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); + + /// + /// Removes health from the mob on the specified position in the mob layer table + /// + /// trueIf the mob can still be damaged (alive)false otherwise. + public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) + { + var mob = this.LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); mob.Health -= damage; return mob.Health > 0; } - public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) { - LStructureLayer.Add(new LSPlacedTile(stock_id, health, yPos, xPos)); - + /// + /// Adds a structure's stock_id, it's health and the specified position in the structure layer table + /// + public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.LStructureLayer.Add(new LSPlacedTile(stock_id, health, yPos, xPos)); } - public void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos) { - LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; - + /// + /// Sets the structure's stock_id and health for the specified position of the structure layer table + /// + public void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; + this.LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; } - public void RemoveStructureFromPosition(int yPos, int xPos) { - LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the structure layer table + /// + public void RemoveStructureFromPosition(int yPos, int xPos) + { + this.LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; + this.LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; } - public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) { - var structure = LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); + + /// + /// Removes health from the structure on the specified position in the structure layer table + /// + /// trueIf the structure can still be damaged false otherwise. + public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) + { + var structure = this.LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); structure.Health -= damage; return structure.Health > 0; } - public void AddGroundAtPosition(string stock_id, int yPos, int xPos) { - LGroundLayer.Add(new LGPlacedTile(stock_id, yPos, xPos)); - + /// + /// Adds a ground (tile)'s stock_id and the specified position in the ground (tile) layer table + /// + public void AddGroundAtPosition(string stock_id, int yPos, int xPos) + { + this.LGroundLayer.Add(new LGPlacedTile(stock_id, yPos, xPos)); } - public void SetGroundAtPosition(string stock_id, int yPos, int xPos) { - LGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - - } - public void RemoveGroundFromPosition(int yPos, int xPos) { - LGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - + /// + /// Sets the ground (tile)'s stock_id and health for the specified position of the ground (tile) layer table + /// + public void SetGroundAtPosition(string stock_id, int yPos, int xPos) + { + this.LGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; } - public string SuperLayerName() { - return "Land"; + /// + /// Sets invalid values for stock_id (null) for the specified position of the ground (tile) layer table + /// + public void RemoveGroundFromPosition(int yPos, int xPos) + { + this.LGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + // Used to set the connection string + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); } } diff --git a/Mundus/Data/SuperLayers/Mobs/MI.cs b/Mundus/Data/SuperLayers/Mobs/MI.cs index f309968..0a805f8 100644 --- a/Mundus/Data/SuperLayers/Mobs/MI.cs +++ b/Mundus/Data/SuperLayers/Mobs/MI.cs @@ -1,16 +1,24 @@ -using Mundus.Data.SuperLayers; -using Mundus.Service.Tiles.Mobs.LandMobs; -using Mundus.Service.Tiles.Items.Presets; +namespace Mundus.Data.Superlayers.Mobs +{ + using Mundus.Service.Tiles.Items.Presets; + using Mundus.Service.Tiles.Mobs.LandMobs; -namespace Mundus.Data.Superlayers.Mobs { - public static class MI { //stands for Mob Instances + /// + /// Used to store universally accessed mob instances (player) + /// + public static class MI + { + /// + /// Gets the mob that is used by the person who plays the game + /// public static Player Player { get; private set; } /// /// Creates the instances of the universally accessed mobs. - /// Note: player has a health of 4 * inventorySize + /// Note: player has a health of 4 * inventorySize and gets a wooden axe and a wooden pickaxe /// - public static void CreateInstances() { + public static void CreateInstances() + { Player = new Player("player", 5, DataBaseContexts.LContext); Player.Inventory.AppendToHotbar(ToolPresets.GetAWoodenAxe()); Player.Inventory.AppendToHotbar(ToolPresets.GetAWoodenPickaxe()); diff --git a/Mundus/Data/SuperLayers/SkyContext.cs b/Mundus/Data/SuperLayers/SkyContext.cs index af446b1..72bef8d 100644 --- a/Mundus/Data/SuperLayers/SkyContext.cs +++ b/Mundus/Data/SuperLayers/SkyContext.cs @@ -1,93 +1,166 @@ -using System; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using Mundus.Data.SuperLayers.DBTables; -using Mundus.Service.SuperLayers; -using Mundus.Service.SuperLayers.Generators; - -namespace Mundus.Data.SuperLayers { - public class SkyContext : DbContext, ISuperLayerContext { +namespace Mundus.Data.SuperLayers +{ + using System.Linq; + using Microsoft.EntityFrameworkCore; + using Mundus.Data.SuperLayers.DBTables; + + /// + /// Add, remove and change values in the sky superlayer + /// + public class SkyContext : DbContext, ISuperLayerContext + { + /// + /// Initializes a new instance of the SkyContext class and truncates all related tables + /// + public SkyContext() : base() + { + this.Database.ExecuteSqlRaw("TRUNCATE TABLE SMobLayer"); + this.Database.ExecuteSqlRaw("TRUNCATE TABLE SStructureLayer"); + this.Database.ExecuteSqlRaw("TRUNCATE TABLE SGroundLayer"); + + this.SaveChanges(); + } + + /// + /// Gets DBSet of the sky mob layer table + /// public DbSet SMobLayer { get; private set; } + + /// + /// Gets DBSet of the sky structure layer table + /// public DbSet SStructureLayer { get; private set; } + + /// + /// Gets DBSet of the sky structure layer table + /// public DbSet SGroundLayer { get; private set; } - public SkyContext() :base() { - Database.ExecuteSqlRaw("TRUNCATE TABLE SMobLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE SStructureLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE SGroundLayer"); - SaveChanges(); + /// + /// Returns the stock_id of the mob at the specified positoin + /// + public string GetMobLayerStock(int yPos, int xPos) + { + return this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public string GetMobLayerStock(int yPos, int xPos) { - return SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; + /// + /// Returns the stock_id of the structure at the specified positoin + /// + public string GetStructureLayerStock(int yPos, int xPos) + { + return this.SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public string GetStructureLayerStock(int yPos, int xPos) { - return SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; - } - public string GetGroundLayerStock(int yPos, int xPos) { - return SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; + + /// + /// Returns the stock_id of the ground (tile) at the specified positoin + /// + public string GetGroundLayerStock(int yPos, int xPos) + { + return this.SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) { - SMobLayer.Add(new SMPlacedTile(stock_id, health, yPos, xPos)); - + /// + /// Adds a mob's stock_id, it's health and the specified position in the mob layer table + /// + public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.SMobLayer.Add(new SMPlacedTile(stock_id, health, yPos, xPos)); } - public void SetMobAtPosition(string stock_id, int health, int yPos, int xPos) { - SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; + /// + /// Sets the mob's stock_id and health for the specified position of the mob layer table + /// + public void SetMobAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; + this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; } - public void RemoveMobFromPosition(int yPos, int xPos) { - SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the mob layer table + /// + public void RemoveMobFromPosition(int yPos, int xPos) + { + this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; + this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; } - public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) { - var mob = SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); + + /// + /// Removes health from the mob on the specified position in the mob layer table + /// + /// trueIf the mob can still be damaged (alive)false otherwise. + public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) + { + var mob = this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); mob.Health -= damage; return mob.Health > 0; } - public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) { - SStructureLayer.Add(new SSPlacedTile(stock_id, health, yPos, xPos)); - + /// + /// Adds a structure's stock_id, it's health and the specified position in the structure layer table + /// + public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.SStructureLayer.Add(new SSPlacedTile(stock_id, health, yPos, xPos)); } - public void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos) { - SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; - + /// + /// Sets the structure's stock_id and health for the specified position of the structure layer table + /// + public void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; + this.SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; } - public void RemoveStructureFromPosition(int yPos, int xPos) { - SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the structure layer table + /// + public void RemoveStructureFromPosition(int yPos, int xPos) + { + this.SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; + this.SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; } - public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) { - var structure = SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); + + /// + /// Removes health from the structure on the specified position in the structure layer table + /// + /// trueIf the structure can still be damaged false otherwise. + public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) + { + var structure = this.SStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); structure.Health -= damage; return structure.Health > 0; } - public void AddGroundAtPosition(string stock_id, int yPos, int xPos) { - SGroundLayer.Add(new SGPlacedTile(stock_id, yPos, xPos)); - + /// + /// Adds a ground (tile)'s stock_id and the specified position in the ground (tile) layer table + /// + public void AddGroundAtPosition(string stock_id, int yPos, int xPos) + { + this.SGroundLayer.Add(new SGPlacedTile(stock_id, yPos, xPos)); } - public void SetGroundAtPosition(string stock_id, int yPos, int xPos) { - SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - - } - public void RemoveGroundFromPosition(int yPos, int xPos) { - SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - + /// + /// Sets the ground (tile)'s stock_id and health for the specified position of the ground (tile) layer table + /// + public void SetGroundAtPosition(string stock_id, int yPos, int xPos) + { + this.SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; } - public string SuperLayerName() { - return "Sky"; + /// + /// Sets invalid values for stock_id (null) for the specified position of the ground (tile) layer table + /// + public void RemoveGroundFromPosition(int yPos, int xPos) + { + this.SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + // Used to set the connection string + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); } } diff --git a/Mundus/Data/SuperLayers/UndergroundContext.cs b/Mundus/Data/SuperLayers/UndergroundContext.cs index 0d16979..8e06ae4 100644 --- a/Mundus/Data/SuperLayers/UndergroundContext.cs +++ b/Mundus/Data/SuperLayers/UndergroundContext.cs @@ -1,93 +1,166 @@ -using System; -using System.Linq; -using Microsoft.EntityFrameworkCore; -using Mundus.Data.SuperLayers.DBTables; -using Mundus.Service.SuperLayers; - -namespace Mundus.Data.SuperLayers { - public class UndergroundContext : DbContext, ISuperLayerContext { +namespace Mundus.Data.SuperLayers +{ + using System.Linq; + using Microsoft.EntityFrameworkCore; + using Mundus.Data.SuperLayers.DBTables; + + /// + /// Add, remove and change values in the underground superlayer + /// + public class UndergroundContext : DbContext, ISuperLayerContext + { + /// + /// Initializes a new instance of the UndergroundContext class and truncates all related tables + /// + public UndergroundContext() : base() + { + this.Database.ExecuteSqlRaw("TRUNCATE TABLE UMobLayer"); + this.Database.ExecuteSqlRaw("TRUNCATE TABLE UStructureLayer"); + this.Database.ExecuteSqlRaw("TRUNCATE TABLE UGroundLayer"); + + this.SaveChanges(); + } + + /// + /// Gets DBSet of the underground mob layer table + /// public DbSet UMobLayer { get; private set; } + + /// + /// Gets DBSet of the underground structure layer table + /// public DbSet UStructureLayer { get; private set; } + + /// + /// Gets DBSet of the sky underground layer table + /// public DbSet UGroundLayer { get; private set; } - public UndergroundContext() : base() { - Database.ExecuteSqlRaw("TRUNCATE TABLE UMobLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE UStructureLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE UGroundLayer"); - SaveChanges(); + /// + /// Returns the stock_id of the mob at the specified positoin + /// + public string GetMobLayerStock(int yPos, int xPos) + { + return this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public string GetMobLayerStock(int yPos, int xPos) { - return UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; + /// + /// Returns the stock_id of the structure at the specified positoin + /// + public string GetStructureLayerStock(int yPos, int xPos) + { + return this.UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public string GetStructureLayerStock(int yPos, int xPos) { - return UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; - } - public string GetGroundLayerStock(int yPos, int xPos) { - return UGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; + + /// + /// Returns the stock_id of the ground (tile) at the specified positoin + /// + public string GetGroundLayerStock(int yPos, int xPos) + { + return this.UGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) { - UMobLayer.Add(new UMPlacedTile(stock_id, health, yPos, xPos)); - + /// + /// Adds a mob's stock_id, it's health and the specified position in the mob layer table + /// + public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.UMobLayer.Add(new UMPlacedTile(stock_id, health, yPos, xPos)); } - public void SetMobAtPosition(string stock_id, int health, int yPos, int xPos) { - UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; - + /// + /// Sets the mob's stock_id and health for the specified position of the mob layer table + /// + public void SetMobAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; + this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; } - public void RemoveMobFromPosition(int yPos, int xPos) { - UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the mob layer table + /// + public void RemoveMobFromPosition(int yPos, int xPos) + { + this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; + this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; } - public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) { - var mob = UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); + + /// + /// Removes health from the mob on the specified position in the mob layer table + /// + /// trueIf the mob can still be damaged (alive)false otherwise. + public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) + { + var mob = this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); mob.Health -= damage; return mob.Health > 0; } - public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) { - UStructureLayer.Add(new USPlacedTile(stock_id, health, yPos, xPos)); - + /// + /// Adds a structure's stock_id, it's health and the specified position in the structure layer table + /// + public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.UStructureLayer.Add(new USPlacedTile(stock_id, health, yPos, xPos)); } - public void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos) { - UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; - + /// + /// Sets the structure's stock_id and health for the specified position of the structure layer table + /// + public void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos) + { + this.UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; + this.UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = health; } - public void RemoveStructureFromPosition(int yPos, int xPos) { - UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; + /// + /// Sets invalid values for stock_id (null) and health (-1) for the specified position of the structure layer table + /// + public void RemoveStructureFromPosition(int yPos, int xPos) + { + this.UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; + this.UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health = -1; } - public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) { - var structure = UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); + + /// + /// Removes health from the structure on the specified position in the structure layer table + /// + /// trueIf the structure can still be damaged false otherwise. + public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) + { + var structure = this.UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); structure.Health -= damage; return structure.Health > 0; } - public void AddGroundAtPosition(string stock_id, int yPos, int xPos) { - UGroundLayer.Add(new UGPlacedTile(stock_id, yPos, xPos)); - + /// + /// Adds a ground (tile)'s stock_id and the specified position in the ground (tile) layer table + /// + public void AddGroundAtPosition(string stock_id, int yPos, int xPos) + { + this.UGroundLayer.Add(new UGPlacedTile(stock_id, yPos, xPos)); } - public void SetGroundAtPosition(string stock_id, int yPos, int xPos) { - UGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - - } - public void RemoveGroundFromPosition(int yPos, int xPos) { - UGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - + /// + /// Sets the ground (tile)'s stock_id and health for the specified position of the ground (tile) layer table + /// + public void SetGroundAtPosition(string stock_id, int yPos, int xPos) + { + this.UGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; } - public string SuperLayerName() { - return "Underground"; + /// + /// Sets invalid values for stock_id (null) for the specified position of the ground (tile) layer table + /// + public void RemoveGroundFromPosition(int yPos, int xPos) + { + this.UGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + // Used to set the connection string + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); } } diff --git a/Mundus/Data/Values.cs b/Mundus/Data/Values.cs index 6091b3c..eb9812b 100644 --- a/Mundus/Data/Values.cs +++ b/Mundus/Data/Values.cs @@ -1,34 +1,51 @@ -using System; -namespace Mundus.Data { - public static class Values { - - public static MapSize CurrMapSize { get; set; } - public enum MapSize { +namespace Mundus.Data +{ + /// + /// Stores all needed values + /// + public static class Values + { + public enum MapSize + { SMALL = 14, MEDIUM = 16, LARGE = 12 } - public static Difficulty CurrDifficulty { get; set; } - public enum Difficulty { + public enum Difficulty + { Peaceful = -10, Easy = -5, Normal = 10, Hard = 40, Insane = 80 } - /// - /// Returns selected difficulty divided by a number. Used to change energy drain values. - /// - public static double DifficultyValueModifier() { - return (int)CurrDifficulty / 80.0; - } - public enum ToolType { + public enum ToolType + { Shovel, Axe, Pickaxe, Sword } + + /// + /// Gets or sets the current (selected) map size + /// + public static MapSize CurrMapSize { get; set; } + + /// + /// Gets or sets the current (selected) difficulty + /// + public static Difficulty CurrDifficulty { get; set; } + + /// + /// Returns selected difficulty divided by a number (80). + /// Used to change energy drain values. + /// + public static double DifficultyValueModifier() + { + return (int)CurrDifficulty / 80.0; + } } -} +} \ No newline at end of file diff --git a/Mundus/Data/Windows/WI.cs b/Mundus/Data/Windows/WI.cs index dbba9a8..0aa04a2 100644 --- a/Mundus/Data/Windows/WI.cs +++ b/Mundus/Data/Windows/WI.cs @@ -1,42 +1,106 @@ -using Mundus.Views.Windows; +namespace Mundus.Data.Windows +{ + using Mundus.Views.Windows; -namespace Mundus.Data.Windows { - public static class WI { //stands for Window Instances + /// + /// Used to store universally accessed windows + /// + public static class WI + { + /// + /// Full name of the build that is used in MainMenu and Pause windows + /// public const string BuildName = "Requirements Build"; + /// + /// Gets or sets the selected game window (should be WSGame, WMGame or WLGame) + /// + /// The sel window. public static IGameWindow SelWin { get; set; } + /// + /// Gets the main window + /// public static MainWindow WMain { get; private set; } + + /// + /// Gets the new game window + /// public static NewGameWindow WNewGame { get; private set; } + + /// + /// Gets the small (sized) game window + /// public static SmallGameWindow WSGame { get; private set; } + + /// + /// Gets the medium (sized) window + /// public static MediumGameWindow WMGame { get; private set; } + + /// + /// Gets the large (sized) window + /// public static LargeGameWindow WLGame { get; private set; } + + /// + /// Gets the settings window + /// public static SettingsWindow WSettings { get; private set; } + + /// + /// Gets the pause window + /// public static PauseWindow WPause { get; private set; } + + /// + /// Gets the music window + /// public static MusicWindow WMusic { get; private set; } + + /// + /// Gets the crafting window + /// public static CraftingWindow WCrafting { get; private set; } + + /// + /// Gets the log window + /// public static LogWindow WLog { get; private set; } - //Gtk opens all window instances in the project automatically, unless they are hidden - public static void CreateInstances() { + /// + /// Creates all instances of the windows and hides them + /// Gtk opens all window instances in the project automatically, unless they are hidden + /// + public static void CreateInstances() + { WMain = new MainWindow(); WMain.Hide(); + WNewGame = new NewGameWindow(); WNewGame.Hide(); + WSGame = new SmallGameWindow(); WSGame.Hide(); + WMGame = new MediumGameWindow(); WMGame.Hide(); + WLGame = new LargeGameWindow(); WLGame.Hide(); + WSettings = new SettingsWindow(); WSettings.Hide(); + WPause = new PauseWindow(); WPause.Hide(); + WMusic = new MusicWindow(); WMusic.Hide(); + WCrafting = new CraftingWindow(); WCrafting.Hide(); + WLog = new LogWindow(); WLog.Hide(); } diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index dfe8ea5..8b371a8 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -284,16 +284,18 @@ - - - + + false + + + false + - @@ -302,6 +304,8 @@ + + @@ -327,6 +331,7 @@ + diff --git a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs index 85833e2..148e76b 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs @@ -5,7 +5,7 @@ using System.Linq; using Mundus.Service.Tiles.Items; namespace Mundus.Service.Tiles.Crafting { - [Table("Recipes", Schema = "Mundus")] + [Table("CraftingRecipes", Schema = "Mundus")] public class CraftingRecipe { [Key] public int ID { get; set; } -- cgit v1.2.3