diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-11 18:17:54 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-11 18:17:54 +0300 |
| commit | 54054ba622ed7188074e1792ec85808597e6e028 (patch) | |
| tree | 34e1ef4512e2ddf233adf67fdbc3273bf4d5e762 | |
| parent | e5cab4f8f638f510077ba7ba936e856197841de6 (diff) | |
| download | Mundus-54054ba622ed7188074e1792ec85808597e6e028.tar Mundus-54054ba622ed7188074e1792ec85808597e6e028.tar.gz Mundus-54054ba622ed7188074e1792ec85808597e6e028.zip | |
Fixed/implimented mob fighting and mob terraforming. Random mob movement might be broken though.
21 files changed, 275 insertions, 218 deletions
diff --git a/CREATE MySQL queries.sql b/CREATE MySQL queries.sql index 6d7d585..399eff9 100644 --- a/CREATE MySQL queries.sql +++ b/CREATE MySQL queries.sql @@ -26,14 +26,16 @@ CREATE TABLE SMobLayer( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, XPos INT NOT NULL, YPos INT NOT NULL, - stock_id VARCHAR(45) + stock_id VARCHAR(45), + Health INT NOT NULL ); CREATE TABLE SStructureLayer( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, XPos INT NOT NULL, YPos INT NOT NULL, - stock_id VARCHAR(45) + stock_id VARCHAR(45), + Health INT NOT NULL ); CREATE TABLE SGroundLayer( @@ -48,14 +50,16 @@ CREATE TABLE LMobLayer( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, XPos INT NOT NULL, YPos INT NOT NULL, - stock_id VARCHAR(45) + stock_id VARCHAR(45), + Health INT NOT NULL ); CREATE TABLE LStructureLayer( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, XPos INT NOT NULL, YPos INT NOT NULL, - stock_id VARCHAR(45) + stock_id VARCHAR(45), + Health INT NOT NULL ); CREATE TABLE LGroundLayer( @@ -70,14 +74,16 @@ CREATE TABLE UMobLayer( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, XPos INT NOT NULL, YPos INT NOT NULL, - stock_id VARCHAR(45) + stock_id VARCHAR(45), + Health INT NOT NULL ); CREATE TABLE UStructureLayer( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, XPos INT NOT NULL, YPos INT NOT NULL, - stock_id VARCHAR(45) + stock_id VARCHAR(45), + Health INT NOT NULL ); CREATE TABLE UGroundLayer( diff --git a/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs index d5a15be..a61c39c 100644 --- a/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/LMPlacedTile.cs @@ -1,10 +1,14 @@ using System; using System.ComponentModel.DataAnnotations.Schema; +using Mundus.Data.Windows; namespace Mundus.Data.SuperLayers.DBTables { [Table("LMobLayer", Schema = "Mundus")] public class LMPlacedTile : PlacedTile { - public LMPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public int Health { get; set; } + + public LMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + this.Health = health; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs index ed54601..a4ab6e3 100644 --- a/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/LSPlacedTile.cs @@ -4,7 +4,10 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Mundus.Data.SuperLayers.DBTables { [Table("LStructureLayer", Schema = "Mundus")] public class LSPlacedTile : PlacedTile { - public LSPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public int Health { get; set; } + + public LSPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + this.Health = health; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs index 9a3cf00..36bc5bf 100644 --- a/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/SMPlacedTile.cs @@ -4,7 +4,10 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Mundus.Data.SuperLayers.DBTables { [Table("SMobLayer", Schema = "Mundus")] public class SMPlacedTile : PlacedTile { - public SMPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public int Health { get; set; } + + public SMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + this.Health = health; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs index e7734fa..251a568 100644 --- a/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/SSPlacedTile.cs @@ -4,7 +4,10 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Mundus.Data.SuperLayers.DBTables { [Table("SStructureLayer", Schema = "Mundus")] public class SSPlacedTile : PlacedTile { - public SSPlacedTile(string stock_id, int yPos, int xPos):base(stock_id, yPos, xPos) { + public int Health { get; set; } + + public SSPlacedTile(string stock_id, int health, int yPos, int xPos):base(stock_id, yPos, xPos) { + this.Health = health; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs index 5c27c2c..0f2fdbc 100644 --- a/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/UMPlacedTile.cs @@ -4,7 +4,10 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Mundus.Data.SuperLayers.DBTables { [Table("UMobLayer", Schema = "Mundus")] public class UMPlacedTile : PlacedTile { - public UMPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public int Health { get; set; } + + public UMPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + this.Health = health; } } } diff --git a/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs b/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs index 4999913..d536640 100644 --- a/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs +++ b/Mundus/Data/SuperLayers/DBTables/USPlacedTile.cs @@ -4,7 +4,10 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Mundus.Data.SuperLayers.DBTables { [Table("UStructureLayer", Schema = "Mundus")] public class USPlacedTile : PlacedTile { - public USPlacedTile(string stock_id, int yPos, int xPos) : base(stock_id, yPos, xPos) { + public int Health { get; set; } + + public USPlacedTile(string stock_id, int health, int yPos, int xPos) : base(stock_id, yPos, xPos) { + this.Health = health; } } } diff --git a/Mundus/Data/SuperLayers/ISuperLayerContext.cs b/Mundus/Data/SuperLayers/ISuperLayerContext.cs index ecdb592..20a5551 100644 --- a/Mundus/Data/SuperLayers/ISuperLayerContext.cs +++ b/Mundus/Data/SuperLayers/ISuperLayerContext.cs @@ -5,13 +5,15 @@ namespace Mundus.Data.SuperLayers { string GetStructureLayerStock(int yPos, int xPos); string GetGroundLayerStock(int yPos, int xPos); - void AddMobAtPosition(string stock_id, int yPos, int xPos); - void SetMobAtPosition(string stock_id, int yPos, int xPos); + void AddMobAtPosition(string stock_id, int health, int yPos, int xPos); + void SetMobAtPosition(string stock_id, int health, int yPos, int xPos); void RemoveMobFromPosition(int yPos, int xPos); + bool TakeDamageMobAtPosition(int yPos, int xPos, int damage); - void AddStructureAtPosition(string stock_id, int yPos, int xPos); - void SetStructureAtPosition(string stock_id, int yPos, int xPos); + void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos); + void SetStructureAtPosition(string stock_id, int health, int yPos, int xPos); void RemoveStructureFromPosition(int yPos, int xPos); + bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage); void AddGroundAtPosition(string stock_id, int yPos, int xPos); void SetGroundAtPosition(string stock_id, int yPos, int xPos); diff --git a/Mundus/Data/SuperLayers/LandContext.cs b/Mundus/Data/SuperLayers/LandContext.cs index adbd9b8..7411ea3 100644 --- a/Mundus/Data/SuperLayers/LandContext.cs +++ b/Mundus/Data/SuperLayers/LandContext.cs @@ -3,78 +3,92 @@ 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 { - public DbSet<LMPlacedTile> LMobLayer { get; private set; } - public DbSet<LSPlacedTile> LStructureLayer { get; private set; } - public DbSet<LGPlacedTile> LGroundLayer { get; private set; } + public DbSet<LMPlacedTile> LMobLayer { get; private set; } + public DbSet<LSPlacedTile> LStructureLayer { get; private set; } + public DbSet<LGPlacedTile> LGroundLayer { get; private set; } - public LandContext() : base() { - Database.ExecuteSqlRaw("TRUNCATE TABLE LMobLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE LStructureLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE LGroundLayer"); - SaveChanges(); - } + public LandContext() : base() { + Database.ExecuteSqlRaw("TRUNCATE TABLE LMobLayer"); + Database.ExecuteSqlRaw("TRUNCATE TABLE LStructureLayer"); + Database.ExecuteSqlRaw("TRUNCATE TABLE LGroundLayer"); + SaveChanges(); + } - public string GetMobLayerStock(int yPos, int xPos) { - return LMobLayer.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; - } + public string GetMobLayerStock(int yPos, int xPos) { + return LMobLayer.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; + } - public void AddMobAtPosition(string stock_id, int yPos, int xPos) { - LMobLayer.Add(new LMPlacedTile(stock_id, yPos, xPos)); - - } + public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) { + LMobLayer.Add(new LMPlacedTile(stock_id, health, yPos, xPos)); + + } - public void SetMobAtPosition(string stock_id, int yPos, int xPos) { - LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - - } - public void RemoveMobFromPosition(int yPos, int xPos) { - LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - - } + 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; + } + 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; - public void AddStructureAtPosition(string stock_id, int yPos, int xPos) { - LStructureLayer.Add(new LSPlacedTile(stock_id, yPos, xPos)); - - } + } + public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) { + var mob = LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); + mob.Health -= damage; + return mob.Health > 0; + } - public void SetStructureAtPosition(string stock_id, int yPos, int xPos) { - LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - - } - public void RemoveStructureFromPosition(int yPos, int xPos) { - LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - - } + public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) { + LStructureLayer.Add(new LSPlacedTile(stock_id, health, yPos, xPos)); + + } - public void AddGroundAtPosition(string stock_id, int yPos, int xPos) { - LGroundLayer.Add(new LGPlacedTile(stock_id, 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; + + } + 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; - 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; - - } + } + public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) { + var structure = LStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); + structure.Health -= damage; + return structure.Health > 0; + } - public string SuperLayerName() { - return "Land"; - } + public void AddGroundAtPosition(string stock_id, int yPos, int xPos) { + 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; + + } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); + public string SuperLayerName() { + return "Land"; + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); + } } } -} diff --git a/Mundus/Data/SuperLayers/SkyContext.cs b/Mundus/Data/SuperLayers/SkyContext.cs index 273f503..af446b1 100644 --- a/Mundus/Data/SuperLayers/SkyContext.cs +++ b/Mundus/Data/SuperLayers/SkyContext.cs @@ -28,32 +28,45 @@ namespace Mundus.Data.SuperLayers { return SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id; } - public void AddMobAtPosition(string stock_id, int yPos, int xPos) { - SMobLayer.Add(new SMPlacedTile(stock_id, yPos, xPos)); + public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) { + SMobLayer.Add(new SMPlacedTile(stock_id, health, yPos, xPos)); } - public void SetMobAtPosition(string stock_id, int yPos, int 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; } 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; + + } + public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) { + var mob = SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); + mob.Health -= damage; + return mob.Health > 0; } - public void AddStructureAtPosition(string stock_id, int yPos, int xPos) { - SStructureLayer.Add(new SSPlacedTile(stock_id, yPos, xPos)); + public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) { + SStructureLayer.Add(new SSPlacedTile(stock_id, health, yPos, xPos)); } - public void SetStructureAtPosition(string stock_id, int yPos, int 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; } 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; + + } + public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) { + var structure = 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) { diff --git a/Mundus/Data/SuperLayers/UndergroundContext.cs b/Mundus/Data/SuperLayers/UndergroundContext.cs index 96a854d..0d16979 100644 --- a/Mundus/Data/SuperLayers/UndergroundContext.cs +++ b/Mundus/Data/SuperLayers/UndergroundContext.cs @@ -6,75 +6,89 @@ using Mundus.Service.SuperLayers; namespace Mundus.Data.SuperLayers { public class UndergroundContext : DbContext, ISuperLayerContext { - public DbSet<UMPlacedTile> UMobLayer { get; private set; } - public DbSet<USPlacedTile> UStructureLayer { get; private set; } - public DbSet<UGPlacedTile> UGroundLayer { get; private set; } + public DbSet<UMPlacedTile> UMobLayer { get; private set; } + public DbSet<USPlacedTile> UStructureLayer { get; private set; } + public DbSet<UGPlacedTile> UGroundLayer { get; private set; } - public UndergroundContext() : base() { - Database.ExecuteSqlRaw("TRUNCATE TABLE UMobLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE UStructureLayer"); - Database.ExecuteSqlRaw("TRUNCATE TABLE UGroundLayer"); - SaveChanges(); - } + public UndergroundContext() : base() { + Database.ExecuteSqlRaw("TRUNCATE TABLE UMobLayer"); + Database.ExecuteSqlRaw("TRUNCATE TABLE UStructureLayer"); + Database.ExecuteSqlRaw("TRUNCATE TABLE UGroundLayer"); + SaveChanges(); + } - public string GetMobLayerStock(int yPos, int xPos) { - return UMobLayer.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; - } + public string GetMobLayerStock(int yPos, int xPos) { + return UMobLayer.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; + } - public void AddMobAtPosition(string stock_id, int yPos, int xPos) { - UMobLayer.Add(new UMPlacedTile(stock_id, yPos, xPos)); - - } + public void AddMobAtPosition(string stock_id, int health, int yPos, int xPos) { + UMobLayer.Add(new UMPlacedTile(stock_id, health, yPos, xPos)); + + } - public void SetMobAtPosition(string stock_id, int yPos, int xPos) { - UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - - } - public void RemoveMobFromPosition(int yPos, int xPos) { - UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - - } + 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; + + } + 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; - public void AddStructureAtPosition(string stock_id, int yPos, int xPos) { - UStructureLayer.Add(new USPlacedTile(stock_id, yPos, xPos)); - - } + } + public bool TakeDamageMobAtPosition(int yPos, int xPos, int damage) { + var mob = UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos); + mob.Health -= damage; + return mob.Health > 0; + } - public void SetStructureAtPosition(string stock_id, int yPos, int xPos) { - UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = stock_id; - - } - public void RemoveStructureFromPosition(int yPos, int xPos) { - UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; - - } + public void AddStructureAtPosition(string stock_id, int health, int yPos, int xPos) { + UStructureLayer.Add(new USPlacedTile(stock_id, health, yPos, xPos)); + + } - public void AddGroundAtPosition(string stock_id, int yPos, int xPos) { - UGroundLayer.Add(new UGPlacedTile(stock_id, 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; + + } + 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; - 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; - - } + } + public bool TakeDamageStructureAtPosition(int yPos, int xPos, int damage) { + var structure = UStructureLayer.First(x => x.YPos == yPos && x.XPos == xPos); + structure.Health -= damage; + return structure.Health > 0; + } - public string SuperLayerName() { - return "Underground"; - } + public void AddGroundAtPosition(string stock_id, int yPos, int xPos) { + 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; + + } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); + public string SuperLayerName() { + return "Underground"; + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); + } } } -} diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index 1fb328d..dfe8ea5 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -326,7 +326,6 @@ <Folder Include="Service\Tiles\Items\Presets\" />
<Folder Include="Views\Windows\GameWindows\" />
<Folder Include="Icons\UI\Hearth\" />
- <Folder Include="Service\SuperLayers\PlacedTiles\" />
<Folder Include="Data\SuperLayers\DBTables\" />
</ItemGroup>
<ItemGroup>
diff --git a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs index eedd87a..8cfbd6e 100644 --- a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs @@ -31,7 +31,7 @@ namespace Mundus.Service.SuperLayers.Generators { context.AddGroundAtPosition(null, row, col); } else { - context.AddGroundAtPosition(GroundPresets.GetALGrass().stock_id, row, col); + context.AddGroundAtPosition(GroundPresets.GetLGrass().stock_id, row, col); } } } @@ -46,17 +46,17 @@ namespace Mundus.Service.SuperLayers.Generators { if (context.GetGroundLayerStock(row, col) != null && !atPlayerSpawnPosition) { if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) { - context.AddStructureAtPosition(StructurePresets.GetALTree().stock_id, row, col); + context.AddStructureAtPosition(StructurePresets.GetLTree().stock_id, StructurePresets.GetLTree().Health, row, col); } else if (rnd.Next(0, 40 + (int)CurrDifficulty) == 1) { - context.AddStructureAtPosition(StructurePresets.GetALBoulder().stock_id, row, col); + context.AddStructureAtPosition(StructurePresets.GetLBoulder().stock_id, StructurePresets.GetLBoulder().Health, row, col); } else { - context.AddStructureAtPosition(null, row, col); + context.AddStructureAtPosition(null, -1, row, col); } } else { - context.AddStructureAtPosition(null, row, col); + context.AddStructureAtPosition(null, -1, row, col); } } } @@ -73,20 +73,20 @@ namespace Mundus.Service.SuperLayers.Generators { if (atPlayerSpawnPosition) { MI.Player.YPos = row; MI.Player.XPos = col; - context.AddMobAtPosition(MI.Player.stock_id, row, col); + context.AddMobAtPosition(MI.Player.stock_id, MI.Player.Health, row, col); } else if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) { - context.AddMobAtPosition(LandMobsPresets.GetACow().stock_id, row, col); + context.AddMobAtPosition(LandMobsPresets.GetCow().stock_id, LandMobsPresets.GetCow().Health, row, col); } else if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) { - context.AddMobAtPosition(LandMobsPresets.GetASheep().stock_id, row, col); + context.AddMobAtPosition(LandMobsPresets.GetSheep().stock_id, LandMobsPresets.GetSheep().Health, row, col); } else { - context.AddMobAtPosition(null, row, col); + context.AddMobAtPosition(null, -1, row, col); } } else { - context.AddMobAtPosition(null, row, col); + context.AddMobAtPosition(null, -1, row, col); } } } diff --git a/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs index 866e431..0a5ff6c 100644 --- a/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs @@ -23,7 +23,7 @@ namespace Mundus.Service.SuperLayers.Generators { private static void GenerateMobLayer(int size) { for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { - context.AddMobAtPosition(null, row, col); + context.AddMobAtPosition(null, -1, row, col); } } context.SaveChanges(); @@ -32,7 +32,7 @@ namespace Mundus.Service.SuperLayers.Generators { private static void GenerateGroundLayer(int size) { for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { - context.AddGroundAtPosition(GroundPresets.GetASSky().stock_id, row, col); + context.AddGroundAtPosition(GroundPresets.GetSSky().stock_id, row, col); } } context.SaveChanges(); @@ -41,7 +41,7 @@ namespace Mundus.Service.SuperLayers.Generators { private static void GenerateStructureLayer(int size) { for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { - context.AddStructureAtPosition(null, row, col); + context.AddStructureAtPosition(null, -1, row, col); } } context.SaveChanges(); diff --git a/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs index 1caace1..bf045c8 100644 --- a/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs @@ -23,7 +23,7 @@ namespace Mundus.Service.SuperLayers.Generators { private static void GenerateMobLayer(int size) { for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { - context.AddMobAtPosition(null, row, col); + context.AddMobAtPosition(null, -1, row, col); } } context.SaveChanges(); @@ -32,7 +32,7 @@ namespace Mundus.Service.SuperLayers.Generators { private static void GenerateGroundLayer(int size) { for (int col = 0; col < size; col++) { for (int row = 0; row < size; row++) { - context.AddGroundAtPosition(GroundPresets.GetAURoche().stock_id, row, col); + context.AddGroundAtPosition(GroundPresets.GetURoche().stock_id, row, col); } } context.SaveChanges(); @@ -43,10 +43,10 @@ namespace Mundus.Service.SuperLayers.Generators { for (int row = 0; row < size; row++) { if (context.GetGroundLayerStock(row, col) != null) { if (rnd.Next(0, 10) == 1) { - context.AddStructureAtPosition(null, row, col); + context.AddStructureAtPosition(null, -1, row, col); } else { - context.AddStructureAtPosition(StructurePresets.GetAURock().stock_id, row, col); + context.AddStructureAtPosition(StructurePresets.GetURock().stock_id, StructurePresets.GetURock().Health, row, col); } } diff --git a/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs b/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs index 76184a4..2222fa4 100644 --- a/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs @@ -1,31 +1,26 @@ namespace Mundus.Service.Tiles.Items.Presets { public static class GroundPresets { - /// <summary> - /// Returns a new instance of the sky ground tile - /// </summary> - public static GroundTile GetASSky() { - return new GroundTile("S_sky", -1, false); + private static GroundTile sSky = new GroundTile("S_sky", -1, false); + private static GroundTile lGrass = new GroundTile("L_grass", 1); + private static GroundTile uRoche = new GroundTile("U_roche", 10); + + public static GroundTile GetSSky() { + return sSky; } - /// <summary> - /// Returns a new instance of the land grass ground tile - /// </summary> - public static GroundTile GetALGrass() { - return new GroundTile("L_grass", 1); + public static GroundTile GetLGrass() { + return lGrass; } - /// <summary> - /// Returns a new instance of the underground roche ground tile - /// </summary> - public static GroundTile GetAURoche() { - return new GroundTile("U_roche", 10); + public static GroundTile GetURoche() { + return uRoche; } public static GroundTile GetFromStock(string stock_id) { switch(stock_id) { - case "S_sky": return GetASSky(); - case "L_grass": return GetALGrass(); - case "U_roche": return GetAURoche(); + case "S_sky": return GetSSky(); + case "L_grass": return GetLGrass(); + case "U_roche": return GetURoche(); default: return null; } } diff --git a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs b/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs index 7fbfa21..815d4a1 100644 --- a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs @@ -2,25 +2,20 @@ namespace Mundus.Service.Tiles.Items.Presets { public static class StructurePresets { - /// <summary> - /// Returns a new instance of the land boulder structure - /// </summary> - public static Structure GetALBoulder() { - return new Structure("L_boulder", "L_boulder_inventory", 7, ToolType.Pickaxe, 1, false, false, MaterialPresets.GetALandRock()); + private static Structure lBoulder = new Structure("L_boulder", "L_boulder_inventory", 7, ToolType.Pickaxe, 1, false, false, MaterialPresets.GetALandRock()); + private static Structure lTree = new Structure("L_tree", "L_tree_inventory", 5, ToolType.Axe, 1, false, false, MaterialPresets.GetALandStick()); + private static Structure uRock = new Structure("U_rock", "U_rock", 10, ToolType.Pickaxe, 2, false, false, MaterialPresets.GetAStone()); + + public static Structure GetLBoulder() { + return lBoulder; } - /// <summary> - /// Returns a new instance of the land tree structure - /// </summary> - public static Structure GetALTree() { - return new Structure("L_tree", "L_tree_inventory", 5, ToolType.Axe, 1, false, false, MaterialPresets.GetALandStick()); + public static Structure GetLTree() { + return lTree; } - /// <summary> - /// Returns a new instance of the underground rock structure - /// </summary> - public static Structure GetAURock() { - return new Structure("U_rock", "U_rock", 10, ToolType.Pickaxe, 2, false, false, MaterialPresets.GetAStone()); + public static Structure GetURock() { + return uRock; } public static Structure GetAWoodenLadder() { @@ -29,9 +24,9 @@ namespace Mundus.Service.Tiles.Items.Presets { public static Structure GetFromStock(string stock_id) { switch(stock_id) { - case "L_boulder": return GetALBoulder(); - case "L_tree": return GetALTree(); - case "U_rock": return GetAURock(); + case "L_boulder": return GetLBoulder(); + case "L_tree": return GetLTree(); + case "U_rock": return GetURock(); case "L_wooden_ladder_inventory": case "L_wooden_ladder": return GetAWoodenLadder(); default: return null; diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs index ed9b51e..5114a18 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs @@ -65,8 +65,8 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { if (selTool.Class >= targetMob.Defense) { int damagePoints = 1 + (selTool.Class - targetMob.Defense); - if (!targetMob.TakeDamage(damagePoints)) { - mob.CurrSuperLayer.SetMobAtPosition(null, mapYPos, mapXPos); + if (!mob.CurrSuperLayer.TakeDamageMobAtPosition(mapYPos, mapXPos, damagePoints)) { + mob.CurrSuperLayer.RemoveMobFromPosition(mapYPos, mapXPos); if (mob.Inventory.Items.Contains(null)) { mob.Inventory.AppendToItems(targetMob.DroppedUponDeath); @@ -76,7 +76,7 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { GameEventLogController.AddMessage($"Player killed \"{targetMob.stock_id}\""); } } else if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Player did {damagePoints} damage to \"{targetMob.stock_id}\" (H:{targetMob.Health}) "); + GameEventLogController.AddMessage($"Player did {damagePoints} damage to \"{targetMob.stock_id}\""); } return true; } diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs index 9b0b3a2..bb0c03e 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs @@ -133,7 +133,7 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { mob.YPos = yPos; mob.XPos = xPos; - mob.CurrSuperLayer.SetMobAtPosition(mob.stock_id, yPos, xPos); + mob.CurrSuperLayer.SetMobAtPosition(mob.stock_id, mob.Health, yPos, xPos); }
private static bool CanWalkTo(MobTile mob, int yPos, int xPos) { diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs index f460970..e4ba86c 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs @@ -124,13 +124,13 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { } // Damage to the structure is done after adding the dropped item/items. - if (!selStructure.TakeDamage(damagePoints)) { - MI.Player.CurrSuperLayer.SetStructureAtPosition(null, mapYPos, mapXPos);
+ if (!MI.Player.CurrSuperLayer.TakeDamageStructureAtPosition(mapYPos, mapXPos, damagePoints)) { + MI.Player.CurrSuperLayer.SetStructureAtPosition(null, -1, mapYPos, mapXPos);
GameEventLogController.AddMessage($"Player destroyed \"{selStructure.stock_id}\" from layer \"{MI.Player.CurrSuperLayer}\" at Y:{mapYPos}, X:{mapXPos}"); } else { - GameEventLogController.AddMessage($"Player did {damagePoints} damage to \"{selStructure.stock_id}\" (H:{selStructure.Health})");
+ GameEventLogController.AddMessage($"Player did {damagePoints} damage to \"{selStructure.stock_id}\"");
}
return true; }
@@ -173,12 +173,12 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { if (toBuild.IsClimable && MI.Player.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) == null &&
HeightController.GetLayerUnderneathMob(MI.Player).GetStructureLayerStock(yPos, xPos) == null)
{
- HeightController.GetLayerUnderneathMob(MI.Player).SetStructureAtPosition(toBuild.stock_id, yPos, xPos);
+ HeightController.GetLayerUnderneathMob(MI.Player).SetStructureAtPosition(toBuild.stock_id, toBuild.Health, yPos, xPos);
GameEventLogController.AddMessage($"Set structure \"{toBuild.stock_id}\" on layer \"{HeightController.GetLayerUnderneathMob(MI.Player)}\" at Y:{yPos}, X:{xPos}"); }
else if (MI.Player.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) != null) { - MI.Player.CurrSuperLayer.SetStructureAtPosition(toBuild.stock_id, yPos, xPos);
+ MI.Player.CurrSuperLayer.SetStructureAtPosition(toBuild.stock_id, toBuild.Health, yPos, xPos);
GameEventLogController.AddMessage($"Set structure \"{toBuild.stock_id}\" on layer \"{MI.Player.CurrSuperLayer}\" at Y:{yPos}, X:{xPos}");
}
diff --git a/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs b/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs index eb1c7f4..642116a 100644 --- a/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs +++ b/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs @@ -4,22 +4,22 @@ using Mundus.Data.SuperLayers; using Mundus.Service.Tiles.Items.Presets; namespace Mundus.Service.Tiles.Mobs.LandMobs { - public static class LandMobsPresets { - /// <summary> - /// Returns a new instance of the cow mob tile - /// </summary> - public static MobTile GetACow() { - return new MobTile("L_cow", 10, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandBeefSteak()); + public static class LandMobsPresets {
+ private static MobTile cow = new MobTile("L_cow", 10, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandBeefSteak());
+ private static MobTile sheep = new MobTile("L_sheep", 8, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandMuttonSteak());
+ + public static MobTile GetCow() { + return cow; } - public static MobTile GetASheep() { - return new MobTile("L_sheep", 8, 1, DataBaseContexts.LContext, 1, MaterialPresets.GetALandMuttonSteak()); + public static MobTile GetSheep() { + return sheep; }
public static MobTile GetFromStock(string stock_id) { switch(stock_id) { - case "L_cow": return GetACow();
- case "L_sheep": return GetASheep();
+ case "L_cow": return GetCow();
+ case "L_sheep": return GetSheep();
case "player": return MI.Player;
default: return null; } |
