diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-14 13:14:52 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-05-14 13:14:52 +0300 |
| commit | 97bb830a57e8eb2458e74710d91670493f629dd0 (patch) | |
| tree | 0686b90497a1b481a2fc53c2f8ed50633b9b9034 | |
| parent | 3c94464f9ba6760b9f90912732ceaae9e82cf1c1 (diff) | |
| download | Mundus-97bb830a57e8eb2458e74710d91670493f629dd0.tar Mundus-97bb830a57e8eb2458e74710d91670493f629dd0.tar.gz Mundus-97bb830a57e8eb2458e74710d91670493f629dd0.zip | |
Did Service/SuperLayers refactorization and documentation. Layers of superlayers are now chosen with an enum (in ImageController).
11 files changed, 404 insertions, 275 deletions
diff --git a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs index 8cfbd6e..f259ab6 100644 --- a/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/LandSuperLayerGenerator.cs @@ -1,19 +1,34 @@ -using System; -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Data.SuperLayers; -using Mundus.Service.Tiles.Mobs.LandMobs; -using Mundus.Service.Tiles.Mobs; -using Mundus.Service.Tiles.Items.Presets; -using Mundus.Service.Tiles.Items; -using static Mundus.Data.Values; +namespace Mundus.Service.SuperLayers.Generators +{ + using System; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.SuperLayers; + using Mundus.Service.Tiles.Items.Presets; + using Mundus.Service.Tiles.Mobs.LandMobs; + using static Mundus.Data.Values; -namespace Mundus.Service.SuperLayers.Generators { - public static class LandSuperLayerGenerator { + /// <summary> + /// Generates all tiles in the Land superlayer + /// </summary> + public static class LandSuperLayerGenerator + { + /// <summary> + /// Variable that is used for random generation + /// </summary> private static Random rnd; + + /// <summary> + /// Land context, it is used to add generated tiles to the database + /// </summary> private static LandContext context = DataBaseContexts.LContext; - public static void GenerateAllLayers(MapSize mapSize) { + /// <summary> + /// Generates ground, structure and mob layers for Land superlayer + /// </summary> + /// <param name="mapSize">Size of ingame world/map</param> + public static void GenerateAllLayers(MapSize mapSize) + { rnd = new Random(); int size = (int)mapSize; @@ -22,74 +37,99 @@ namespace Mundus.Service.SuperLayers.Generators { GenerateMobLayer(size); } - private static void GenerateGroundLayer(int size) { - for(int col = 0; col < size; col++) { - for(int row = 0; row < size; row++) { + private static void GenerateGroundLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { bool atPlayerSpawnPosition = (col == size / 2) && (row == size / 2); + // Holes in the ground should be more common with higher difficulties - if (rnd.Next(0, 210 - (int)CurrDifficulty) == 1 && !atPlayerSpawnPosition) { + if (rnd.Next(0, 210 - (int)CurrDifficulty) == 1 && !atPlayerSpawnPosition) + { context.AddGroundAtPosition(null, row, col); } - else { + else + { context.AddGroundAtPosition(GroundPresets.GetLGrass().stock_id, row, col); } } } + context.SaveChanges(); } - private static void GenerateStructureLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { + private static void GenerateStructureLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { bool atPlayerSpawnPosition = (col == size / 2) && (row == size / 2); - if (context.GetGroundLayerStock(row, col) != null && - !atPlayerSpawnPosition) { - if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) { + if (context.GetGroundLayerStock(row, col) != null && !atPlayerSpawnPosition) + { + if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) + { context.AddStructureAtPosition(StructurePresets.GetLTree().stock_id, StructurePresets.GetLTree().Health, row, col); } - else if (rnd.Next(0, 40 + (int)CurrDifficulty) == 1) { + else if (rnd.Next(0, 40 + (int)CurrDifficulty) == 1) + { context.AddStructureAtPosition(StructurePresets.GetLBoulder().stock_id, StructurePresets.GetLBoulder().Health, row, col); } - else { + else + { context.AddStructureAtPosition(null, -1, row, col); } } - else { + else + { context.AddStructureAtPosition(null, -1, row, col); } } } + context.SaveChanges(); } - private static void GenerateMobLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { + private static void GenerateMobLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { bool atPlayerSpawnPosition = (col == size / 2) && (row == size / 2); if (context.GetGroundLayerStock(row, col) != null && - context.GetStructureLayerStock(row, col) == null) { - if (atPlayerSpawnPosition) { + context.GetStructureLayerStock(row, col) == null) + { + if (atPlayerSpawnPosition) + { MI.Player.YPos = row; MI.Player.XPos = col; context.AddMobAtPosition(MI.Player.stock_id, MI.Player.Health, row, col); } - else if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) { + else if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) + { context.AddMobAtPosition(LandMobsPresets.GetCow().stock_id, LandMobsPresets.GetCow().Health, row, col); } - else if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) { + else if (rnd.Next(0, 15 + (int)CurrDifficulty) == 1) + { context.AddMobAtPosition(LandMobsPresets.GetSheep().stock_id, LandMobsPresets.GetSheep().Health, row, col); } - else { + else + { context.AddMobAtPosition(null, -1, row, col); } } - else { + else + { context.AddMobAtPosition(null, -1, row, col); } } } + context.SaveChanges(); } } diff --git a/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs b/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs index 0a5ff6c..c16db26 100644 --- a/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/SkySuperLayerGenerator.cs @@ -1,17 +1,32 @@ -using System; -using Mundus.Data.SuperLayers; -using Mundus.Service.Tiles.Mobs; -using Mundus.Service.Tiles.Items.Presets; -using Mundus.Service.Tiles.Items; -using Mundus.Data; -using static Mundus.Data.Values; - -namespace Mundus.Service.SuperLayers.Generators { - public static class SkySuperLayerGenerator { +namespace Mundus.Service.SuperLayers.Generators +{ + using System; + using Mundus.Data; + using Mundus.Data.SuperLayers; + using Mundus.Service.Tiles.Items.Presets; + using static Mundus.Data.Values; + + /// <summary> + /// Generates all tiles in the Sky superlayer + /// </summary> + public static class SkySuperLayerGenerator + { + /// <summary> + /// Variable that is used for random generation + /// </summary> private static Random rnd; + + /// <summary> + /// Sky context, it is used to add generated tiles to the database + /// </summary> private static SkyContext context = DataBaseContexts.SContext; - public static void GenerateAllLayers(MapSize mapSize) { + /// <summary> + /// Generates ground, structure and mob layers for Sky superlayer + /// </summary> + /// <param name="mapSize">Size of ingame world/map</param> + public static void GenerateAllLayers(MapSize mapSize) + { rnd = new Random(); int size = (int)mapSize; @@ -20,30 +35,42 @@ namespace Mundus.Service.SuperLayers.Generators { GenerateStructureLayer(size); } - private static void GenerateMobLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { + private static void GenerateMobLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { context.AddMobAtPosition(null, -1, row, col); } } + context.SaveChanges(); } - private static void GenerateGroundLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { + private static void GenerateGroundLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { context.AddGroundAtPosition(GroundPresets.GetSSky().stock_id, row, col); } } + context.SaveChanges(); } - private static void GenerateStructureLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { + private static void GenerateStructureLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { 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 bf045c8..807533f 100644 --- a/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/Generators/UndergroundSuperLayerGenerator.cs @@ -1,17 +1,32 @@ -using System; -using Mundus.Data.SuperLayers; -using Mundus.Service.Tiles.Mobs; -using Mundus.Service.Tiles.Items.Presets; -using Mundus.Service.Tiles.Items; -using Mundus.Data; -using static Mundus.Data.Values; - -namespace Mundus.Service.SuperLayers.Generators { - public static class UndergroundSuperLayerGenerator { +namespace Mundus.Service.SuperLayers.Generators +{ + using System; + using Mundus.Data; + using Mundus.Data.SuperLayers; + using Mundus.Service.Tiles.Items.Presets; + using static Mundus.Data.Values; + + /// <summary> + /// Generates all tiles in the Underground superlayer + /// </summary> + public static class UndergroundSuperLayerGenerator + { + /// <summary> + /// Variable that is used for random generation + /// </summary> private static Random rnd; + + /// <summary> + /// Underground context, it is used to add generated tiles to the database + /// </summary> private static UndergroundContext context = DataBaseContexts.UContext; - public static void GenerateAllLayers(MapSize mapSize) { + /// <summary> + /// Generates ground, structure and mob layers for Underground superlayer + /// </summary> + /// <param name="mapSize">Size of ingame world/map</param> + public static void GenerateAllLayers(MapSize mapSize) + { rnd = new Random(); int size = (int)mapSize; @@ -20,38 +35,52 @@ namespace Mundus.Service.SuperLayers.Generators { GenerateStructureLayer(size); } - private static void GenerateMobLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { + private static void GenerateMobLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { context.AddMobAtPosition(null, -1, row, col); } } + context.SaveChanges(); } - private static void GenerateGroundLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { + private static void GenerateGroundLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { context.AddGroundAtPosition(GroundPresets.GetURoche().stock_id, row, col); } } + context.SaveChanges(); } - private static void GenerateStructureLayer(int size) { - for (int col = 0; col < size; col++) { - for (int row = 0; row < size; row++) { - if (context.GetGroundLayerStock(row, col) != null) { - if (rnd.Next(0, 10) == 1) { + private static void GenerateStructureLayer(int size) + { + for (int col = 0; col < size; col++) + { + for (int row = 0; row < size; row++) + { + if (context.GetGroundLayerStock(row, col) != null) + { + if (rnd.Next(0, 10) == 1) + { context.AddStructureAtPosition(null, -1, row, col); } - else { + else + { context.AddStructureAtPosition(StructurePresets.GetURock().stock_id, StructurePresets.GetURock().Health, row, col); - } } } } + context.SaveChanges(); } } diff --git a/Mundus/Service/SuperLayers/HeightController.cs b/Mundus/Service/SuperLayers/HeightController.cs index 4757aac..0a3afb9 100644 --- a/Mundus/Service/SuperLayers/HeightController.cs +++ b/Mundus/Service/SuperLayers/HeightController.cs @@ -1,41 +1,70 @@ -using Mundus.Data;
-using Mundus.Data.SuperLayers; -using Mundus.Service.Tiles.Mobs; +namespace Mundus.Service.SuperLayers +{ + using System; + using System.Linq; + using Mundus.Data; + using Mundus.Data.SuperLayers; + using Mundus.Service.Tiles.Mobs; -namespace Mundus.Service.SuperLayers { - public static class HeightController { - // Order of layers (top to bottom): sky, land, underground + /// <summary> + /// Works out which superlayer is above or below the given one + /// </summary> + public static class HeightController + { + /// <summary> + /// Contains the order of superlayers, from the one that is the highest (above all others) + /// to the one that is the lowest (underneath all other) + /// </summary> + private static ISuperLayerContext[] superLayers = { + DataBaseContexts.SContext, + DataBaseContexts.LContext, + DataBaseContexts.UContext + }; + + /// <summary> + /// Returns the superlayer that is underneath the given one + /// If there isn't any, returns null + /// </summary> + public static ISuperLayerContext GetSuperLayerUnderneath(ISuperLayerContext currentLayer) + { + if (Array.IndexOf(superLayers, currentLayer) == superLayers.Length - 1) + { + return null; + } - private static ISuperLayerContext sky = DataBaseContexts.SContext; - private static ISuperLayerContext land = DataBaseContexts.LContext; - private static ISuperLayerContext underground = DataBaseContexts.UContext; + return superLayers[Array.IndexOf(superLayers, currentLayer) + 1]; + } - public static ISuperLayerContext GetLayerUnderneath(ISuperLayerContext currentLayer) { - if (land == currentLayer) { - return underground; - } - if (sky == currentLayer) { - return land; + /// <summary> + /// Returns the superlayer that is above the given one + /// If there isn't any, returns null + /// </summary> + public static ISuperLayerContext GetSuperLayerAbove(ISuperLayerContext currentLayer) + { + if (Array.IndexOf(superLayers, currentLayer) == 0) + { + return null; } - return null; - } - public static ISuperLayerContext GetLayerUnderneathMob(MobTile currentMob) { - return GetLayerUnderneath(currentMob.CurrSuperLayer); + return superLayers[Array.IndexOf(superLayers, currentLayer) - 1]; } - public static ISuperLayerContext GetLayerAbove(ISuperLayerContext currentLayer) { - if (underground == currentLayer) { - return land; - } - if (land == currentLayer) { - return sky; - } - return null; + /// <summary> + /// Returns the superlayer that is underneath the one that the given mob is in + /// If there isn't any, returns null + /// </summary> + public static ISuperLayerContext GetSuperLayerUnderneathMob(MobTile currentMob) + { + return GetSuperLayerUnderneath(currentMob.CurrSuperLayer); } - public static ISuperLayerContext GetLayerAboveMob(MobTile currentMob) { - return GetLayerAbove(currentMob.CurrSuperLayer); + /// <summary> + /// Returns the superlayer that is above the one that the given mob is in + /// If there isn't any, returns null + /// </summary> + public static ISuperLayerContext GetSuperLayerAboveMob(MobTile currentMob) + { + return GetSuperLayerAbove(currentMob.CurrSuperLayer); } } } diff --git a/Mundus/Service/SuperLayers/ImageController.cs b/Mundus/Service/SuperLayers/ImageController.cs index aafd487..5ac1d42 100644 --- a/Mundus/Service/SuperLayers/ImageController.cs +++ b/Mundus/Service/SuperLayers/ImageController.cs @@ -1,149 +1,109 @@ -using Gtk; -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Data.SuperLayers; -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Items.Types; -using static Mundus.Data.Values; - -namespace Mundus.Service.SuperLayers { - public static class ImageController { +namespace Mundus.Service.SuperLayers +{ + using Gtk; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.SuperLayers; + using Mundus.Service.Tiles.Items.Types; + using static Mundus.Service.Tiles.Mobs.Inventory; + + public static class ImageController + { + private static ISuperLayerContext superLayer = MI.Player.CurrSuperLayer; + + public enum Layer + { + Ground, + Structure, + Mob + } /// <summary> /// Returns the image of the selected layer in the superlayer - /// Note: Layer 0 is GroundLayer, 1 is ItemLayer and 2 is Moblayer - /// Note: null structure tiles and null mob tiles are skipped (returns null) + /// If there is no item/mob at the position, returns null /// </summary> - public static Image GetScreenImage(int row, int col, int layer) { - ISuperLayerContext superLayer = MI.Player.CurrSuperLayer; + public static Image GetPlayerScreenImage(int y, int x, Layer layer) + { Image img = null; - //Layer 0 is GroundLayer, 1 is ItemLayer and 2 is Moblayer - if (layer == 0) + if (layer == Layer.Ground) { - img = new Image(GetPlayerGroundImage(row, col).Stock, IconSize.Dnd); + img = new Image(GetPlayerGroundStockID(y, x), IconSize.Dnd); } - else if (layer == 1 && superLayer.GetStructureLayerStock( row, col ) != null) + else if (layer == Layer.Structure && superLayer.GetStructureLayerStock(y, x) != null) { - img = new Image(GetPlayerStructureImage(row, col).Stock, IconSize.Dnd ); + img = new Image(GetPlayerStructureStockID(y, x), IconSize.Dnd ); } - else if (layer == 2 && superLayer.GetMobLayerStock(row, col) != null) + else if (layer == Layer.Mob && superLayer.GetMobLayerStock(y, x) != null) { - img = new Image(superLayer.GetMobLayerStock(row, col), IconSize.Dnd); + img = new Image(superLayer.GetMobLayerStock(y, x), IconSize.Dnd); } return img; } /// <summary> - /// Returns the Image on the given position of the ground layer the player is currently in - /// Note: null values (holes) get the "L_hole" image + /// Returns the stock_id at the given position in player's superlayer + /// If there is no stock_id, returns "L_hole" /// </summary> - public static Image GetPlayerGroundImage(int row, int col) { - ISuperLayerContext superLayer = MI.Player.CurrSuperLayer; - Image img = new Image("L_hole", IconSize.Dnd); - - if (row >= 0 && col >= 0 && col < (int)Values.CurrMapSize && row < (int)Values.CurrMapSize && - superLayer.GetGroundLayerStock(row, col) != null) { - img = new Image(superLayer.GetGroundLayerStock(row, col), IconSize.Dnd); + private static string GetPlayerGroundStockID(int y, int x) + { + if (InsideBoundaries(y, x) && superLayer.GetGroundLayerStock(y, x) != null) + { + return superLayer.GetGroundLayerStock(y, x); } - return img; + + return "L_hole"; } /// <summary> - /// Returns the Image on the given position of the structure layer the player is currently in + /// Returns the stock_id on the given position of the structure layer the player is currently in /// Note: null values get the "blank" image ; GetScreenImage skips if the value is null /// </summary> - public static Image GetPlayerStructureImage(int row, int col) { - ISuperLayerContext superLayer = MI.Player.CurrSuperLayer; - Image img = new Image("blank", IconSize.Dnd ); - - if (IsInsideBoundaries(row, col) && - superLayer.GetStructureLayerStock(row, col) != null) + private static string GetPlayerStructureStockID(int y, int x) + { + if (InsideBoundaries(y, x) && superLayer.GetStructureLayerStock(y, x) != null) { - img = new Image(superLayer.GetStructureLayerStock(row, col), IconSize.Dnd); + return superLayer.GetStructureLayerStock(y, x); } - return img; - } - - // Checks if the position is inside the map - private static bool IsInsideBoundaries(int row, int col) { - return row >= 0 && col >= 0 && col < (int)Values.CurrMapSize && row < (int)Values.CurrMapSize; + return "blank"; } /// <summary> - /// Returns the Image on the given position of the player's hotbar (Incentory.Hotbar) - /// Note: null values get the "blank" image + /// Checks if the position is inside the map /// </summary> - public static Image GetPlayerHotbarImage(int index) { - Image img = new Image("blank", IconSize.Dnd); - - if (index < MI.Player.Inventory.Hotbar.Length) { - if (MI.Player.Inventory.Hotbar[index] != null) { - // Structures have two icons, one when they are placed and one as an inventory item. - // All other item types have only one icon (texture). - if (MI.Player.Inventory.Hotbar[index].GetType() == typeof(Structure)) { - Structure tmp = (Structure)MI.Player.Inventory.Hotbar[index]; - img = new Image(tmp.inventory_stock_id, IconSize.Dnd); - } - else { - img = MI.Player.Inventory.Hotbar[index].Texture; - } - } - } - return img; + private static bool InsideBoundaries(int y, int x) + { + return y >= 0 && x >= 0 && x < (int)Values.CurrMapSize && y < (int)Values.CurrMapSize; } /// <summary> - /// Returns the Image on the given position of the player's items inventory (Inventory.Items) - /// Note: null values get the "blank" image + /// Returns the Image on the given inventory place of the player at the given index + /// If there isn't one, returns a "blank" image /// </summary> - public static Image GetPlayerInventoryItemImage(int index) { - Image img = new Image("blank", IconSize.Dnd); + public static Image GetPlayerInventoryImage(InventoryPlace place, int index) + { + string stock_id = "blank"; - if (index < MI.Player.Inventory.Items.Length) { - if (MI.Player.Inventory.Items[index] != null) { - // Structures have two icons, one when they are placed and one as an inventory item. - // All other item types have only one icon (texture). - if (MI.Player.Inventory.Items[index].GetType() == typeof(Structure)) { - Structure tmp = (Structure)MI.Player.Inventory.Items[index]; - img = new Image(tmp.inventory_stock_id, IconSize.Dnd); - } - else { - img = MI.Player.Inventory.Items[index].Texture; - } + if (MI.Player.Inventory.GetItemTile(place, index) != null) + { + // Structures have two icons, one when they are placed and one when they are in the inventory + // All other item types have only one icon. + if (MI.Player.Inventory.GetItemTile(place, index).GetType() == typeof(Structure)) + { + stock_id = ((Structure)MI.Player.Inventory.GetItemTile(place, index)).inventory_stock_id; } - } - return img; - } - - /// <summary> - /// Returns the Image on the given position of the player's accessories (Inventory.Accessories) - /// Note: null values get the "blank" image - /// </summary> - public static Image GetPlayerAccessoryImage(int index) { - Image img = new Image("blank_gear", IconSize.Dnd); - - if (index < MI.Player.Inventory.Accessories.Length) { - if (MI.Player.Inventory.Accessories[index] != null) { - img = MI.Player.Inventory.Accessories[index].Texture; + else + { + stock_id = MI.Player.Inventory.GetItemTile(place, index).stock_id; } } - return img; - } - - /// <summary> - /// Returns the Image on the given position of the player's gear (Inventory.Gear) - /// Note: null values get the "blank" image - /// </summary> - public static Image GetPlayerGearImage(int index) { - Image img = new Image("blank_gear", IconSize.Dnd); - - if (index < MI.Player.Inventory.Gear.Length) { - if (MI.Player.Inventory.Gear[index] != null) { - img = MI.Player.Inventory.Gear[index].Texture; - } + // Accessories and gear menus have a different blank icon + else if (place == InventoryPlace.Accessories || place == InventoryPlace.Gear) + { + stock_id = "blank_gear"; } - return img; + + return new Image(stock_id, IconSize.Dnd); } } } diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs index 73463a3..153bb72 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs @@ -70,69 +70,69 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { // If mob can go down a layer from a hole if (mob.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) == null &&
- HeightController.GetLayerUnderneathMob(mob) != null)
+ HeightController.GetSuperLayerUnderneathMob(mob) != null)
{
- if (HeightController.GetLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos) == null)
+ if (HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos) == null)
{ - mob.CurrSuperLayer = HeightController.GetLayerUnderneathMob(mob);
+ mob.CurrSuperLayer = HeightController.GetSuperLayerUnderneathMob(mob);
if (mob.GetType() == typeof(Player)) { GameEventLogController.AddMessage($"Player fell down a superlayer, to {mob.CurrSuperLayer}"); }
}
else if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Cannot fall down a superlayer, blocked by {HeightController.GetLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos)}"); + GameEventLogController.AddMessage($"Cannot fall down a superlayer, blocked by {HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos)}"); } }
// If mob can go down a layer from non-solid ground
else if (!GroundPresets.GetFromStock(mob.CurrSuperLayer.GetGroundLayerStock(yPos, xPos)).Solid &&
- HeightController.GetLayerUnderneathMob(mob) != null)
+ HeightController.GetSuperLayerUnderneathMob(mob) != null)
{
- if (HeightController.GetLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos) == null)
+ if (HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos) == null)
{ - mob.CurrSuperLayer = HeightController.GetLayerUnderneathMob(mob);
+ mob.CurrSuperLayer = HeightController.GetSuperLayerUnderneathMob(mob);
if (mob.GetType() == typeof(Player)) {
GameEventLogController.AddMessage($"Player descended a superlayer, to {mob.CurrSuperLayer}");
} }
else if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Cannot descend a superlayer, blocked by {HeightController.GetLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos)}"); + GameEventLogController.AddMessage($"Cannot descend a superlayer, blocked by {HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos)}"); } }
// If mob can climb up else if (mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos) != null &&
- HeightController.GetLayerAboveMob(mob).GetMobLayerStock(yPos, xPos) == null)
+ HeightController.GetSuperLayerAboveMob(mob).GetMobLayerStock(yPos, xPos) == null)
{ // Mobs can only climb to the superlayer on top of them, if
// there is a climable structure and there is a "hole" on top of the climable structure if (StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)).IsClimable && - HeightController.GetLayerAboveMob(mob) != null)
+ HeightController.GetSuperLayerAboveMob(mob) != null)
{
// The ground above isn't solid or doesnt exist and there are no mobs on top
- if (HeightController.GetLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos) == null ||
- !GroundPresets.GetFromStock(HeightController.GetLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos)).Solid)
+ if (HeightController.GetSuperLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos) == null ||
+ !GroundPresets.GetFromStock(HeightController.GetSuperLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos)).Solid)
{ - mob.CurrSuperLayer = HeightController.GetLayerAboveMob(mob);
+ mob.CurrSuperLayer = HeightController.GetSuperLayerAboveMob(mob);
if (mob.GetType() == typeof(Player)) { GameEventLogController.AddMessage($"Player climbed up a superlayer"); } }
- else if (HeightController.GetLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos) != null && mob.GetType() == typeof(Player)) { + else if (HeightController.GetSuperLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos) != null && mob.GetType() == typeof(Player)) { GameEventLogController.AddMessage($"Cannot climb up a superlayer, there is solid ground above"); } }
else if (!StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)).IsClimable && mob.GetType() == typeof(Player)) {
GameEventLogController.AddMessage($"Cannot climb up a superlayer using a \"{mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)}\"");
}
- else if (HeightController.GetLayerAboveMob(mob) == null && mob.GetType() == typeof(Player)) {
+ else if (HeightController.GetSuperLayerAboveMob(mob) == null && mob.GetType() == typeof(Player)) {
GameEventLogController.AddMessage($"There is no superlayer to climb up to");
} }
- else if (HeightController.GetLayerAboveMob(mob).GetMobLayerStock(yPos, xPos) != null && mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Cannot climb up a superlayer, {HeightController.GetLayerAboveMob(mob).GetMobLayerStock(yPos, xPos)} is blocking the way"); + else if (HeightController.GetSuperLayerAboveMob(mob).GetMobLayerStock(yPos, xPos) != null && mob.GetType() == typeof(Player)) { + GameEventLogController.AddMessage($"Cannot climb up a superlayer, {HeightController.GetSuperLayerAboveMob(mob).GetMobLayerStock(yPos, xPos)} is blocking the way"); } mob.YPos = yPos;
diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs index a0ce9f7..4b89b54 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs @@ -72,11 +72,11 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { /// </summary> public static bool ExistsHoleOnTopOfPlayer() { //There can't be a hole if there isn't a layer above the player - if (HeightController.GetLayerAboveMob(MI.Player) == null) { + if (HeightController.GetSuperLayerAboveMob(MI.Player) == null) { return false; } - return HeightController.GetLayerAboveMob(MI.Player).GetGroundLayerStock(MI.Player.YPos, MI.Player.XPos) == null || - !GroundPresets.GetFromStock(HeightController.GetLayerAboveMob(MI.Player).GetGroundLayerStock(MI.Player.YPos, MI.Player.XPos)).Solid; + return HeightController.GetSuperLayerAboveMob(MI.Player).GetGroundLayerStock(MI.Player.YPos, MI.Player.XPos) == null || + !GroundPresets.GetFromStock(HeightController.GetSuperLayerAboveMob(MI.Player).GetGroundLayerStock(MI.Player.YPos, MI.Player.XPos)).Solid; } } } diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs index 0e641f8..687e5aa 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs @@ -79,7 +79,7 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { if (selectedGround.ReqShovelClass <= shovel.Class && selectedGround.ReqShovelClass >= 0) { MI.Player.CurrSuperLayer.SetGroundAtPosition(null, mapYPos, mapXPos); - ISuperLayerContext under = HeightController.GetLayerUnderneathMob(MI.Player); + ISuperLayerContext under = HeightController.GetSuperLayerUnderneathMob(MI.Player); // When a shovel destroys ground tile, it destroys the structure below it (but only if it is not walkable) if (under != null && under.GetStructureLayerStock(mapYPos, mapXPos) != null) { if (!StructurePresets.GetFromStock(under.GetStructureLayerStock(mapYPos, mapXPos)).IsWalkable) { @@ -170,11 +170,11 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { // Climable structures will be placed under a hole (if they can be).
// Non climable structures won't be placed anywhere if there is a hole.
if (toBuild.IsClimable && MI.Player.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) == null &&
- HeightController.GetLayerUnderneathMob(MI.Player).GetStructureLayerStock(yPos, xPos) == null)
+ HeightController.GetSuperLayerUnderneathMob(MI.Player).GetStructureLayerStock(yPos, xPos) == null)
{
- HeightController.GetLayerUnderneathMob(MI.Player).SetStructureAtPosition(toBuild.stock_id, toBuild.Health, yPos, xPos);
+ HeightController.GetSuperLayerUnderneathMob(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}"); + GameEventLogController.AddMessage($"Set structure \"{toBuild.stock_id}\" on layer \"{HeightController.GetSuperLayerUnderneathMob(MI.Player)}\" at Y:{yPos}, X:{xPos}"); }
else if (MI.Player.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) != null) { MI.Player.CurrSuperLayer.SetStructureAtPosition(toBuild.stock_id, toBuild.Health, yPos, xPos);
diff --git a/Mundus/Views/Windows/GameWindows/Large/LargePrinting.cs b/Mundus/Views/Windows/GameWindows/Large/LargePrinting.cs index 2111a17..8001f32 100644 --- a/Mundus/Views/Windows/GameWindows/Large/LargePrinting.cs +++ b/Mundus/Views/Windows/GameWindows/Large/LargePrinting.cs @@ -6,18 +6,31 @@ using Mundus.Service.Tiles.Items; using Mundus.Service.Tiles.Mobs.Controllers; using Mundus.Service.Windows; + using static Mundus.Service.SuperLayers.ImageController; + using static Mundus.Service.Tiles.Mobs.Inventory; public partial class LargeGameWindow { + /// <summary> + /// Prints the screen that the player uses to interract with the game map + /// </summary> public void PrintWorldScreen() { - for (int layer = 0; layer < 3; layer++) + Layer layer = 0; + + for (int layerIndex = 0; layerIndex < 3; layerIndex++) { + switch (layerIndex) { + case 0: layer = Layer.Ground; break; + case 1: layer = Layer.Structure; break; + case 2: layer = ImageController.Layer.Mob; break; + } + for (int row = Calculate.CalculateStartY(Size), maxY = Calculate.CalculateMaxY(Size), btn = 1; row <= maxY; row++) { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, btn++) { - Image img = ImageController.GetScreenImage(row, col, layer); + Image img = GetPlayerScreenImage(row, col, layer); if (img == null) { @@ -215,7 +228,7 @@ { for (int i = 0; i < Size; i++) { - Image img = ImageController.GetPlayerHotbarImage(i); + Image img = GetPlayerInventoryImage(InventoryPlace.Hotbar, i); switch (i) { @@ -262,7 +275,7 @@ { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetPlayerInventoryItemImage((row * Size) + col); + Image img = GetPlayerInventoryImage(InventoryPlace.Items, (row * Size) + col); switch ((row * Size) + col + 1) { @@ -358,7 +371,7 @@ { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetPlayerAccessoryImage((row * Size) + col); + Image img = GetPlayerInventoryImage(InventoryPlace.Accessories, (row * Size) + col); switch ((row * Size) + col + 1) { @@ -389,7 +402,7 @@ { for (int i = 0; i < Size; i++) { - Image img = ImageController.GetPlayerGearImage(i); + Image img = GetPlayerInventoryImage(InventoryPlace.Gear, i); switch (i + 1) { @@ -416,7 +429,7 @@ { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string stockName = ImageController.GetPlayerGroundImage(row, col).Stock; + string stockName = GetPlayerScreenImage(row, col, Layer.Ground).Stock; switch (img) { @@ -512,7 +525,7 @@ { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string stockName = ImageController.GetPlayerStructureImage(row, col).Stock; + string stockName = GetPlayerScreenImage(row, col, Layer.Structure).Stock; switch (img) { diff --git a/Mundus/Views/Windows/GameWindows/Medium/MediumPrinting.cs b/Mundus/Views/Windows/GameWindows/Medium/MediumPrinting.cs index 5010f86..afe4ea9 100644 --- a/Mundus/Views/Windows/GameWindows/Medium/MediumPrinting.cs +++ b/Mundus/Views/Windows/GameWindows/Medium/MediumPrinting.cs @@ -6,6 +6,8 @@ using Mundus.Service.Tiles.Items; using Mundus.Service.Tiles.Mobs.Controllers; using Mundus.Service.Windows; + using static Mundus.Service.SuperLayers.ImageController; + using static Mundus.Service.Tiles.Mobs.Inventory; public partial class MediumGameWindow { @@ -14,13 +16,22 @@ /// </summary> public void PrintWorldScreen() { - for (int layer = 0; layer < 3; layer++) + Layer layer = 0; + + for (int layerIndex = 0; layerIndex < 3; layerIndex++) { + switch (layerIndex) + { + case 0: layer = Layer.Ground; break; + case 1: layer = Layer.Structure; break; + case 2: layer = ImageController.Layer.Mob; break; + } + for (int row = Calculate.CalculateStartY(Size), maxY = Calculate.CalculateMaxY(Size), btn = 1; row <= maxY; row++) { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, btn++) { - Image img = ImageController.GetScreenImage(row, col, layer); + Image img = GetPlayerScreenImage(row, col, layer); if (img == null) { @@ -182,7 +193,7 @@ { for (int i = 0; i < Size; i++) { - Image img = ImageController.GetPlayerHotbarImage(i); + Image img = GetPlayerInventoryImage(InventoryPlace.Hotbar, i); switch (i) { @@ -222,7 +233,7 @@ private void PrintItemsInventory() { for (int row = 0; row < Size; row++) { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetPlayerInventoryItemImage((row * Size) + col); + Image img = GetPlayerInventoryImage(InventoryPlace.Items, (row * Size) + col); switch ((row * Size) + col + 1) { case 1: btnI1.Image = img; break; @@ -282,7 +293,7 @@ private void PrintAccessoriesInventory() { for (int row = 0; row < 2; row++) { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetPlayerAccessoryImage((row * Size) + col); + Image img = GetPlayerInventoryImage(InventoryPlace.Accessories, (row * Size) + col + 1); switch ((row * Size) + col + 1) { case 1: btnA1.Image = img; break; @@ -306,7 +317,7 @@ private void PrintGearInventory() { for (int i = 0; i < Size; i++) { - Image img = ImageController.GetPlayerGearImage(i); + Image img = GetPlayerInventoryImage(InventoryPlace.Gear, i); switch (i + 1) { case 1: btnG1.Image = img; break; @@ -330,7 +341,7 @@ { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string stockName = ImageController.GetPlayerGroundImage(row, col).Stock; + string stockName = GetPlayerScreenImage(row, col, Layer.Ground).Stock; switch (img) { @@ -394,7 +405,7 @@ { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string stockName = ImageController.GetPlayerStructureImage(row, col).Stock; + string stockName = GetPlayerScreenImage(row, col, Layer.Structure).Stock; switch (img) { diff --git a/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs b/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs index bbf3594..1bd5618 100644 --- a/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs +++ b/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs @@ -6,6 +6,8 @@ using Mundus.Service.Tiles.Items; using Mundus.Service.Tiles.Mobs.Controllers; using Mundus.Service.Windows; + using static Mundus.Service.SuperLayers.ImageController; + using static Mundus.Service.Tiles.Mobs.Inventory; public partial class SmallGameWindow { @@ -14,13 +16,22 @@ /// </summary> public void PrintWorldScreen() { - for (int layer = 0; layer < 3; layer++) + Layer layer = 0; + + for (int layerIndex = 0; layerIndex < 3; layerIndex++) { + switch(layerIndex) + { + case 0: layer = Layer.Ground; break; + case 1: layer = Layer.Structure; break; + case 2: layer = ImageController.Layer.Mob; break; + } + for (int row = Calculate.CalculateStartY(Size), maxY = Calculate.CalculateMaxY(Size), btn = 1; row <= maxY; row++) { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, btn++) { - Image img = ImageController.GetScreenImage(row, col, layer); + Image img = GetPlayerScreenImage(row, col, layer); if (img == null) { @@ -154,7 +165,7 @@ { for (int i = 0; i < Size; i++) { - Image img = ImageController.GetPlayerHotbarImage(i); + Image img = GetPlayerInventoryImage(InventoryPlace.Hotbar, i); switch (i + 1) { @@ -187,12 +198,16 @@ #region Inventory - private void PrintItemsInventory() { - for (int row = 0; row < Size; row++) { - for (int col = 0; col < Size; col++) { - Image img = ImageController.GetPlayerInventoryItemImage((row * Size) + col); + private void PrintItemsInventory() + { + for (int row = 0; row < Size; row++) + { + for (int col = 0; col < Size; col++) + { + Image img = GetPlayerInventoryImage(InventoryPlace.Items, (row * Size) + col); - switch ((row * Size) + col + 1) { + switch ((row * Size) + col + 1) + { case 1: btnI1.Image = img; break; case 2: btnI2.Image = img; break; case 3: btnI3.Image = img; break; @@ -223,12 +238,16 @@ } } - private void PrintAccessoriesInventory() { - for (int row = 0; row < 2; row++) { - for (int col = 0; col < Size; col++) { - Image img = ImageController.GetPlayerAccessoryImage((row * Size) + col); + private void PrintAccessoriesInventory() + { + for (int row = 0; row < 2; row++) + { + for (int col = 0; col < Size; col++) + { + Image img = GetPlayerInventoryImage(InventoryPlace.Accessories, (row * Size) + col); - switch ((row * Size) + col + 1) { + switch ((row * Size) + col + 1) + { case 1: btnA1.Image = img; break; case 2: btnA2.Image = img; break; case 3: btnA3.Image = img; break; @@ -244,9 +263,11 @@ } } - private void PrintGearInventory() { - for (int i = 0; i < Size; i++) { - Image img = ImageController.GetPlayerGearImage(i); + private void PrintGearInventory() + { + for (int i = 0; i < Size; i++) + { + Image img = GetPlayerInventoryImage(InventoryPlace.Gear, i); switch (i + 1) { case 1: btnG1.Image = img; break; @@ -268,7 +289,7 @@ { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string stockName = ImageController.GetPlayerGroundImage(row, col).Stock; + string stockName = GetPlayerScreenImage(row, col, Layer.Ground).Stock; switch (img) { @@ -308,7 +329,7 @@ { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string stockName = ImageController.GetPlayerStructureImage(row, col).Stock; + string stockName = GetPlayerScreenImage(row, col, Layer.Structure).Stock; switch (img) { @@ -343,6 +364,5 @@ } #endregion - } } |
