From eedebcec8ca02b6d2f1786a852fb1467c9131be2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 15 May 2020 16:24:36 +0300 Subject: Finished all refactoring and documentation. Fixed bugs with fighting and moving. --- Mundus/Data/Crafting/CraftingTableContext.cs | 4 +- Mundus/Data/GameEventLogs/GameEventLogContext.cs | 4 +- Mundus/Data/SuperLayers/ISuperLayerContext.cs | 8 +- Mundus/Data/SuperLayers/LandContext.cs | 18 +- Mundus/Data/SuperLayers/SkyContext.cs | 10 +- Mundus/Data/SuperLayers/UndergroundContext.cs | 9 +- Mundus/Data/Values.cs | 10 + Mundus/Program.cs | 2 - Mundus/Service/GameEventLogController.cs | 19 +- Mundus/Service/GameGenerator.cs | 41 ++-- Mundus/Service/SuperLayers/HeightController.cs | 5 +- Mundus/Service/SuperLayers/ImageController.cs | 59 +++-- Mundus/Service/Tiles/Crafting/CraftingRecipe.cs | 28 +-- Mundus/Service/Tiles/ITile.cs | 9 +- Mundus/Service/Tiles/Items/ItemController.cs | 107 ++++++--- Mundus/Service/Tiles/Items/ItemTile.cs | 19 +- .../Service/Tiles/Items/Presets/GroundPresets.cs | 21 +- .../Service/Tiles/Items/Presets/MaterialPresets.cs | 22 +- .../Tiles/Items/Presets/StructurePresets.cs | 28 ++- Mundus/Service/Tiles/Items/Presets/ToolPresets.cs | 42 ++-- Mundus/Service/Tiles/Items/Types/Gear.cs | 15 +- Mundus/Service/Tiles/Items/Types/GroundTile.cs | 35 +-- Mundus/Service/Tiles/Items/Types/Material.cs | 28 ++- Mundus/Service/Tiles/Items/Types/Structure.cs | 68 +++--- Mundus/Service/Tiles/Items/Types/Tool.cs | 26 ++- .../Service/Tiles/Mobs/Controllers/MobFighting.cs | 149 +++++++------ .../Service/Tiles/Mobs/Controllers/MobMovement.cs | 204 +++++++++-------- .../Tiles/Mobs/Controllers/MobStatsController.cs | 95 +++++--- .../Tiles/Mobs/Controllers/MobTerraforming.cs | 248 ++++++++++++--------- Mundus/Service/Tiles/Mobs/Inventory.cs | 110 +++++---- .../Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs | 36 ++- Mundus/Service/Tiles/Mobs/LandMobs/Player.cs | 43 ++-- Mundus/Service/Tiles/Mobs/MobTile.cs | 92 ++++---- Mundus/Service/Windows/Calculate.cs | 147 +++++++++--- Mundus/Service/Windows/WindowController.cs | 113 +++++----- Mundus/Views/Dialogs/ExitDialog.cs | 1 + Mundus/Views/Windows/CraftingWindow.cs | 3 +- .../Windows/GameWindows/Small/SmallPrinting.cs | 4 +- 38 files changed, 1153 insertions(+), 729 deletions(-) diff --git a/Mundus/Data/Crafting/CraftingTableContext.cs b/Mundus/Data/Crafting/CraftingTableContext.cs index 284573f..d7ea2d6 100644 --- a/Mundus/Data/Crafting/CraftingTableContext.cs +++ b/Mundus/Data/Crafting/CraftingTableContext.cs @@ -34,7 +34,9 @@ return recipes.Where(cr => cr.HasEnoughItems(MI.Player.Inventory.Items)).ToArray(); } - // Used to set the connection string + /// + /// Used to set the connection string + /// protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); diff --git a/Mundus/Data/GameEventLogs/GameEventLogContext.cs b/Mundus/Data/GameEventLogs/GameEventLogContext.cs index 5440bd8..7a5dc57 100644 --- a/Mundus/Data/GameEventLogs/GameEventLogContext.cs +++ b/Mundus/Data/GameEventLogs/GameEventLogContext.cs @@ -46,7 +46,9 @@ return this.GameEventLogs.Count(); } - // Used to set the connection string + /// + /// Used to set the connection string + /// protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); diff --git a/Mundus/Data/SuperLayers/ISuperLayerContext.cs b/Mundus/Data/SuperLayers/ISuperLayerContext.cs index e6884ad..78a2d83 100644 --- a/Mundus/Data/SuperLayers/ISuperLayerContext.cs +++ b/Mundus/Data/SuperLayers/ISuperLayerContext.cs @@ -1,9 +1,11 @@ -namespace Mundus.Data.SuperLayers +using System; + +namespace Mundus.Data.SuperLayers { /// /// Add, remove and change values in the different superlayers (database tables) /// - public interface ISuperLayerContext + public interface ISuperLayerContext { /// /// Returns the stock_id of the mob at the specified positoin @@ -37,8 +39,8 @@ /// /// Removes health from the mob on the specified position in the mob layer table + /// Returns true if the mob can still be damaged (is still alive) /// - /// trueIf the mob can still be damaged (alive)false otherwise. bool TakeDamageMobAtPosition(int yPos, int xPos, int damage); /// diff --git a/Mundus/Data/SuperLayers/LandContext.cs b/Mundus/Data/SuperLayers/LandContext.cs index 7e23498..0607e23 100644 --- a/Mundus/Data/SuperLayers/LandContext.cs +++ b/Mundus/Data/SuperLayers/LandContext.cs @@ -75,6 +75,7 @@ { 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; + this.SaveChanges(); } /// @@ -82,8 +83,7 @@ /// 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; + this.SetMobAtPosition(null, -1, yPos, xPos); } /// @@ -92,9 +92,9 @@ /// 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; + this.LMobLayer.FirstOrDefault(x => x.YPos == yPos && x.XPos == xPos).Health -= damage; + this.SaveChanges(); + return this.LMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health > 0; } /// @@ -119,8 +119,8 @@ /// 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; + this.SetStructureAtPosition(null, -1, yPos, xPos); + this.SaveChanges(); } /// @@ -158,7 +158,9 @@ this.LGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; } - // Used to set the connection string + /// + /// Used to set the connection string + /// 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 72bef8d..45d58a2 100644 --- a/Mundus/Data/SuperLayers/SkyContext.cs +++ b/Mundus/Data/SuperLayers/SkyContext.cs @@ -92,9 +92,9 @@ /// 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; + this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health -= damage; + this.SaveChanges(); + return this.SMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health > 0; } /// @@ -158,7 +158,9 @@ this.SGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; } - // Used to set the connection string + /// + /// 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 8e06ae4..4874360 100644 --- a/Mundus/Data/SuperLayers/UndergroundContext.cs +++ b/Mundus/Data/SuperLayers/UndergroundContext.cs @@ -92,9 +92,8 @@ /// 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; + this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health -= damage; + return this.UMobLayer.First(x => x.YPos == yPos && x.XPos == xPos).Health > 0; } /// @@ -158,7 +157,9 @@ this.UGroundLayer.First(x => x.YPos == yPos && x.XPos == xPos).stock_id = null; } - // Used to set the connection string + /// + /// 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 eb9812b..970f189 100644 --- a/Mundus/Data/Values.cs +++ b/Mundus/Data/Values.cs @@ -5,6 +5,16 @@ /// public static class Values { + public const double TAKEN_ENERGY_FROM_FIGHTING = 0.5; + + public const double TAKEN_ENERGY_FROM_MOVEMENT = 0.1; + + public const double ENERGY_TAKEN_FROM_PLACING_GROUND = 0.4; + + public const double ENERGY_TAKEN_FROM_BUILDING_STRUCTURE = 0.5; + + public const double ENERGY_TAKEN_FROM_DESTROYING = 0.6; + public enum MapSize { SMALL = 14, diff --git a/Mundus/Program.cs b/Mundus/Program.cs index 3d4530c..a4cc679 100644 --- a/Mundus/Program.cs +++ b/Mundus/Program.cs @@ -7,8 +7,6 @@ public static class MainClass { - private static bool runGame = true; - public static void Main(string[] args) { DataBaseContexts.CreateInstances(); diff --git a/Mundus/Service/GameEventLogController.cs b/Mundus/Service/GameEventLogController.cs index 65eb9c6..4d11146 100644 --- a/Mundus/Service/GameEventLogController.cs +++ b/Mundus/Service/GameEventLogController.cs @@ -1,18 +1,21 @@ -using System; -using System.Collections.Generic; -using Mundus.Data; +namespace Mundus.Service +{ + using Mundus.Data; -namespace Mundus.Service { - public static class GameEventLogController { - public static void AddMessage(string logMessage) { + public static class GameEventLogController + { + public static void AddMessage(string logMessage) + { DataBaseContexts.GELContext.AddMessage(logMessage); } - public static string GetMessagage(int index) { + public static string GetMessagage(int index) + { return (0 <= index && index < GetCount()) ? DataBaseContexts.GELContext.GetMessage(index + 1) : null; } - public static int GetCount() { + public static int GetCount() + { return DataBaseContexts.GELContext.GetCount(); } } diff --git a/Mundus/Service/GameGenerator.cs b/Mundus/Service/GameGenerator.cs index 17dba54..13d43ca 100644 --- a/Mundus/Service/GameGenerator.cs +++ b/Mundus/Service/GameGenerator.cs @@ -1,21 +1,25 @@ -using System; -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Data.Windows; -using Mundus.Service.SuperLayers.Generators; +namespace Mundus.Service +{ + using System; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Windows; + using Mundus.Service.SuperLayers.Generators; -namespace Mundus.Service { - public static class GameGenerator { + public static class GameGenerator + { /// /// Sets the map size and starts generation of all superlayers /// /// Size of the map ("small", "medium" or "large") - public static void GenerateMap(string size) { - switch (size.ToLower()) { - case "small": Values.CurrMapSize =Values.MapSize.SMALL; break; + public static void GenerateMap(string size) + { + switch (size.ToLower()) + { + case "small": Values.CurrMapSize = Values.MapSize.SMALL; break; case "medium": Values.CurrMapSize = Values.MapSize.MEDIUM; break; case "large": Values.CurrMapSize = Values.MapSize.LARGE; break; - default: throw new ArgumentException( "Map size must be \"small\", \"medium\" or \"large\"" ); + default: throw new ArgumentException("Map size must be \"small\", \"medium\" or \"large\""); } SkySuperLayerGenerator.GenerateAllLayers(Values.CurrMapSize); @@ -28,8 +32,10 @@ namespace Mundus.Service { /// Note: certain mobs base their inventory size from the game window size /// /// Size of the game window ("small", "medium" or "large") - public static void GameWindowSizeSetup(string size) { - switch (size.ToLower()) { + public static void GameWindowSizeSetup(string size) + { + switch (size.ToLower()) + { case "small": WI.SelWin = WI.WSGame; break; case "medium": WI.SelWin = WI.WMGame; break; case "large": WI.SelWin = WI.WLGame; break; @@ -40,7 +46,8 @@ namespace Mundus.Service { MI.CreateInstances(); } - public static void GameWindowInitialize() { + public static void GameWindowInitialize() + { WI.WPause.GameWindow = WI.SelWin; WI.SelWin.PrintWorldScreen(); WI.SelWin.PrintMainMenu(); @@ -51,8 +58,10 @@ namespace Mundus.Service { /// Sets the game difficulty (that affects map generation). /// /// Must be "peaceful", "easy", "normal", "hard" or "insane" - public static void SetDifficulty(string value) { - switch(value.ToLower()) { + public static void SetDifficulty(string value) + { + switch (value.ToLower()) + { case "peaceful": Values.CurrDifficulty = Values.Difficulty.Peaceful; break; case "easy": Values.CurrDifficulty = Values.Difficulty.Easy; break; case "normal": Values.CurrDifficulty = Values.Difficulty.Normal; break; diff --git a/Mundus/Service/SuperLayers/HeightController.cs b/Mundus/Service/SuperLayers/HeightController.cs index 0a3afb9..6fa854d 100644 --- a/Mundus/Service/SuperLayers/HeightController.cs +++ b/Mundus/Service/SuperLayers/HeightController.cs @@ -15,11 +15,12 @@ /// 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) /// - private static ISuperLayerContext[] superLayers = { + private static ISuperLayerContext[] superLayers = + { DataBaseContexts.SContext, DataBaseContexts.LContext, DataBaseContexts.UContext - }; + }; /// /// Returns the superlayer that is underneath the given one diff --git a/Mundus/Service/SuperLayers/ImageController.cs b/Mundus/Service/SuperLayers/ImageController.cs index 5ac1d42..b501091 100644 --- a/Mundus/Service/SuperLayers/ImageController.cs +++ b/Mundus/Service/SuperLayers/ImageController.cs @@ -32,15 +32,41 @@ } else if (layer == Layer.Structure && superLayer.GetStructureLayerStock(y, x) != null) { - img = new Image(GetPlayerStructureStockID(y, x), IconSize.Dnd ); + img = new Image(GetPlayerStructureStockID(y, x), IconSize.Dnd); } else if (layer == Layer.Mob && superLayer.GetMobLayerStock(y, x) != null) { img = new Image(superLayer.GetMobLayerStock(y, x), IconSize.Dnd); } + return img; } + /// + /// Returns the Image on the given inventory place of the player at the given index + /// If there isn't one, returns a "blank" image + /// + public static Image GetPlayerInventoryImage(InventoryPlace place, int index) { + string stock_id = "blank"; + + 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; + } + else { + stock_id = MI.Player.Inventory.GetItemTile(place, index).stock_id; + } + } + // Accessories and gear menus have a different blank icon + else if (place == InventoryPlace.Accessories || place == InventoryPlace.Gear) { + stock_id = "blank_gear"; + } + + return new Image(stock_id, IconSize.Dnd); + } + /// /// Returns the stock_id at the given position in player's superlayer /// If there is no stock_id, returns "L_hole" @@ -65,6 +91,7 @@ { return superLayer.GetStructureLayerStock(y, x); } + return "blank"; } @@ -75,35 +102,5 @@ { return y >= 0 && x >= 0 && x < (int)Values.CurrMapSize && y < (int)Values.CurrMapSize; } - - /// - /// Returns the Image on the given inventory place of the player at the given index - /// If there isn't one, returns a "blank" image - /// - public static Image GetPlayerInventoryImage(InventoryPlace place, int index) - { - string stock_id = "blank"; - - 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; - } - else - { - stock_id = MI.Player.Inventory.GetItemTile(place, index).stock_id; - } - } - // Accessories and gear menus have a different blank icon - else if (place == InventoryPlace.Accessories || place == InventoryPlace.Gear) - { - stock_id = "blank_gear"; - } - - return new Image(stock_id, IconSize.Dnd); - } } } diff --git a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs index 3d495a3..1bdb625 100644 --- a/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs +++ b/Mundus/Service/Tiles/Crafting/CraftingRecipe.cs @@ -8,11 +8,6 @@ [Table("CraftingRecipes", Schema = "Mundus")] public class CraftingRecipe { - /// - /// Required fifth item - /// - public string ReqItem5 { get; private set; } - public CraftingRecipe(string resultItem, int count1, string reqItem1) : this(resultItem, count1, reqItem1, 0, null, 0, null, 0, null, 0, null) { } @@ -59,49 +54,54 @@ public string ResultItem { get; private set; } /// - /// Required amount of the first item + /// Gets the required amount of the first item /// public int Count1 { get; private set; } /// - /// Required first item + /// Gets the required first item /// public string ReqItem1 { get; private set; } /// - /// Required amount of the second item + /// Gets the required amount of the second item /// public int Count2 { get; private set; } /// - /// Required second item + /// Gets the required second item /// public string ReqItem2 { get; private set; } /// - /// Required amount of the third item + /// Gets the required amount of the third item /// public int Count3 { get; private set; } /// - /// Required third item + /// Gets the required third item /// public string ReqItem3 { get; private set; } /// - /// Required amount of the fourth item + /// Gets the required amount of the fourth item /// public int Count4 { get; private set; } /// - /// Required fourth item + /// Gets the required fourth item /// public string ReqItem4 { get; private set; } /// - /// Required amount of the fifth item + /// Gets the required amount of the fifth item /// public int Count5 { get; private set; } + + /// + /// Gets the required fifth item + /// + public string ReqItem5 { get; private set; } /// /// Checks if the given array of items has enough of every requried item diff --git a/Mundus/Service/Tiles/ITile.cs b/Mundus/Service/Tiles/ITile.cs index c6c4d17..564edbe 100644 --- a/Mundus/Service/Tiles/ITile.cs +++ b/Mundus/Service/Tiles/ITile.cs @@ -1,8 +1,7 @@ -using Gtk; - -namespace Mundus.Service.Tiles { - public interface ITile { +namespace Mundus.Service.Tiles +{ + public interface ITile + { string stock_id { get; } - Image Texture { get; } } } diff --git a/Mundus/Service/Tiles/Items/ItemController.cs b/Mundus/Service/Tiles/Items/ItemController.cs index 13e03cd..172b622 100644 --- a/Mundus/Service/Tiles/Items/ItemController.cs +++ b/Mundus/Service/Tiles/Items/ItemController.cs @@ -1,45 +1,62 @@ -using System; -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Data.Windows; -using Mundus.Service.Tiles.Items.Types; -using static Mundus.Data.Values; -using static Mundus.Service.Tiles.Mobs.Inventory; - -namespace Mundus.Service.Tiles.Items { - public static class ItemController { +namespace Mundus.Service.Tiles.Items +{ + using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.Windows; + using Mundus.Service.Tiles.Items.Types; + using static Mundus.Service.Tiles.Mobs.Inventory; + + /// + /// Contains the item that the player has selected and switches it's location + /// + public static class ItemController + { private static ItemTile[] selItemLocation; + + /// + /// Gets the index of the selected item in the selected item location + /// public static int SelItemIndex { get; private set; } + /// + /// Gets the inventory place in which the selected item is stored + /// public static InventoryPlace SelItemPlace { get; private set; } /// /// Sets the item that will be moved (switched) /// - public static void SelectItem(InventoryPlace place, int index) { + public static void SelectItem(InventoryPlace place, int index) + { + selItemLocation = GetPlayerInventoryArray(place); + SelItemPlace = place; - selItemLocation = GetInventoryArray(place); SelItemIndex = index; WI.SelWin.PrintSelectedItemInfo(selItemLocation[SelItemIndex]); } /// - /// Tries to switch the location of the originally selected item (origin) with the currently selected item + /// Tries to switch the location of the selected item with the given one + /// If a material is moved to it's current location (double clicked), and + /// it can restore energy, it restores the player's energy /// - public static void SwitchItems(InventoryPlace destination, int index) { - ItemTile[] destinationLocation = GetInventoryArray(destination); + public static void SwitchItems(InventoryPlace destination, int index) + { + ItemTile[] destinationLocation = GetPlayerInventoryArray(destination); ItemTile toTransfer = selItemLocation[SelItemIndex]; - if (toTransfer != null) { + if (toTransfer != null) + { // Consumable materials can be consumed by double clicking on them (transfering them to their current location) - if (toTransfer == destinationLocation[index]) { - if (toTransfer.GetType() == typeof(Material) && - PlayerTryEat((Material)toTransfer)) { + if (toTransfer == destinationLocation[index]) + { + if (toTransfer.GetType() == typeof(Material) && PlayerDidEat((Material)toTransfer)) + { selItemLocation[SelItemIndex] = null; } } - else if (ItemCanGoThere(toTransfer, destination)) { + else if (ItemCanGoThere(toTransfer, destination)) + { selItemLocation[SelItemIndex] = destinationLocation[index]; destinationLocation[index] = toTransfer; } @@ -48,16 +65,32 @@ namespace Mundus.Service.Tiles.Items { ResetSelection(); } - public static void ResetSelection() { + /// + /// Sets the selected item place and index to invalid values + /// + public static void ResetSelection() + { selItemLocation = null; - SelItemIndex = -1; + SelItemIndex = -1; SelItemPlace = 0; } - // Certain item types can only be placed inside certain inventory places. - private static ItemTile[] GetInventoryArray(InventoryPlace place) { - switch (place) { + /// + /// Returns whether an item has been selected + /// + public static bool HasSelectedItem() + { + return selItemLocation != null && SelItemIndex > -1; + } + + /// + /// Returns an ItemTile array, corresponding to a given place inside the player's inventory + /// + private static ItemTile[] GetPlayerInventoryArray(InventoryPlace place) + { + switch (place) + { case InventoryPlace.Hotbar: return MI.Player.Inventory.Hotbar; case InventoryPlace.Items: return MI.Player.Inventory.Items; case InventoryPlace.Accessories: return MI.Player.Inventory.Accessories; @@ -66,8 +99,13 @@ namespace Mundus.Service.Tiles.Items { } } - private static bool ItemCanGoThere(ItemTile toTransfer, InventoryPlace place) { - switch (place) { + /// + /// Checks if the given ItemTile can be inside the given destination + /// + private static bool ItemCanGoThere(ItemTile toTransfer, InventoryPlace place) + { + switch (place) + { case InventoryPlace.Hotbar: return toTransfer.GetType() != typeof(GroundTile); case InventoryPlace.Items: return true; case InventoryPlace.Accessories: return toTransfer.GetType() == typeof(Gear); @@ -76,15 +114,18 @@ namespace Mundus.Service.Tiles.Items { } } - public static bool HasSelectedItem() { - return selItemLocation != null && SelItemIndex != -1; - } - - private static bool PlayerTryEat(Material material) { - if (material.EnergyRestorePoints > 0) { + /// + /// If the given material can restore energy, it restores that player's energy and returns true + /// + private static bool PlayerDidEat(Material material) + { + if (material.EnergyRestorePoints > 0) + { MI.Player.RestoreEnergy(material.EnergyRestorePoints); + return true; } + return false; } } diff --git a/Mundus/Service/Tiles/Items/ItemTile.cs b/Mundus/Service/Tiles/Items/ItemTile.cs index 4b6b6d7..83c5590 100644 --- a/Mundus/Service/Tiles/Items/ItemTile.cs +++ b/Mundus/Service/Tiles/Items/ItemTile.cs @@ -1,17 +1,16 @@ -using Gtk; -using Mundus.Service.Tiles; - -namespace Mundus.Service.Tiles.Items { - public abstract class ItemTile : ITile { +namespace Mundus.Service.Tiles.Items +{ + public abstract class ItemTile : ITile + { public string stock_id { get; private set; } - public Image Texture { get; private set; } - public ItemTile(ItemTile item) :this(item.stock_id) - { } + public ItemTile(ItemTile item) : this(item.stock_id) + { + } - public ItemTile(string stock_id) { + public ItemTile(string stock_id) + { this.stock_id = stock_id; - this.Texture = new Image( stock_id, IconSize.Dnd ); } } } diff --git a/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs b/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs index 9ec33eb..f763309 100644 --- a/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/GroundPresets.cs @@ -1,16 +1,21 @@ -using Mundus.Service.Tiles.Items.Types; + +namespace Mundus.Service.Tiles.Items.Presets +{ + using Mundus.Service.Tiles.Items.Types; -namespace Mundus.Service.Tiles.Items.Presets { - public static class GroundPresets { + public static class GroundPresets + { 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() { + public static GroundTile GetSSky() + { return sSky; } - public static GroundTile GetLGrass() { + public static GroundTile GetLGrass() + { return lGrass; } @@ -18,8 +23,10 @@ namespace Mundus.Service.Tiles.Items.Presets { return uRoche; } - public static GroundTile GetFromStock(string stock_id) { - switch(stock_id) { + public static GroundTile GetFromStock(string stock_id) + { + switch (stock_id) + { case "S_sky": return GetSSky(); case "L_grass": return GetLGrass(); case "U_roche": return GetURoche(); diff --git a/Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs b/Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs index 0f2d44b..9b5ac1e 100644 --- a/Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/MaterialPresets.cs @@ -1,29 +1,35 @@ -using Mundus.Service.Tiles.Items.Types; +namespace Mundus.Service.Tiles.Items.Presets +{ + using Mundus.Service.Tiles.Items.Types; -namespace Mundus.Service.Tiles.Items.Presets { - public static class MaterialPresets { + public static class MaterialPresets + { /// New instance - public static Material GetALandRock() { + public static Material GetALandRock() + { return new Material("L_rock"); } /// New instance - public static Material GetALandStick() { + public static Material GetALandStick() + { return new Material("L_stick"); } /// New instance - public static Material GetALandBeefSteak() { + public static Material GetALandBeefSteak() + { return new Material("L_beef_steak", 5); } // New instance - public static Material GetALandMuttonSteak() { + public static Material GetALandMuttonSteak() + { return new Material("L_mutton_steak", 4); } /// - /// (TEMPORARY) + /// TEMPORARY /// public static Material GetAStone() { return new Material("U_stone"); diff --git a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs b/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs index f2ca7ea..b16a952 100644 --- a/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/StructurePresets.cs @@ -1,30 +1,38 @@ -using Mundus.Service.Tiles.Items.Types; -using static Mundus.Data.Values; +namespace Mundus.Service.Tiles.Items.Presets +{ + using Mundus.Service.Tiles.Items.Types; + using static Mundus.Data.Values; -namespace Mundus.Service.Tiles.Items.Presets { - public static class StructurePresets { + public static class StructurePresets + { 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() { + public static Structure GetLBoulder() + { return lBoulder; } - public static Structure GetLTree() { + public static Structure GetLTree() + { return lTree; } - public static Structure GetURock() { + public static Structure GetURock() + { return uRock; } - public static Structure GetAWoodenLadder() { + public static Structure GetAWoodenLadder() + { return new Structure("L_wooden_ladder", "L_wooden_ladder_inventory", 1, ToolType.Axe, 1, true, true); } - public static Structure GetFromStock(string stock_id) { - switch(stock_id) { + public static Structure GetFromStock(string stock_id) + { + switch (stock_id) + { case "L_boulder": return GetLBoulder(); case "L_tree": return GetLTree(); case "U_rock": return GetURock(); diff --git a/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs b/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs index 791e77c..04d6798 100644 --- a/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs +++ b/Mundus/Service/Tiles/Items/Presets/ToolPresets.cs @@ -1,42 +1,54 @@ -using Mundus.Service.Tiles.Items.Types; -using static Mundus.Data.Values; - -namespace Mundus.Service.Tiles.Items.Presets { - public static class ToolPresets { - public static Tool GetAWoodenPickaxe() { +namespace Mundus.Service.Tiles.Items.Presets +{ + using Mundus.Service.Tiles.Items.Types; + using static Mundus.Data.Values; + + public static class ToolPresets + { + public static Tool GetAWoodenPickaxe() + { return new Tool("wooden_pickaxe", ToolType.Pickaxe, 1); } - public static Tool GetAWoodenAxe() { + public static Tool GetAWoodenAxe() + { return new Tool("wooden_axe", ToolType.Axe, 1); } - public static Tool GetAWoodenShovel() { + public static Tool GetAWoodenShovel() + { return new Tool("wooden_shovel", ToolType.Shovel, 1); } - public static Tool GetAWoodenLongsword() { + public static Tool GetAWoodenLongsword() + { return new Tool("wooden_longsword", ToolType.Sword, 2); } - public static Tool GetARockPickaxe() { + public static Tool GetARockPickaxe() + { return new Tool("rock_pickaxe", ToolType.Pickaxe, 2); } - public static Tool GetARockAxe() { + public static Tool GetARockAxe() + { return new Tool("rock_axe", ToolType.Axe, 2); } - public static Tool GetARockShovel() { + public static Tool GetARockShovel() + { return new Tool("rock_shovel", ToolType.Shovel, 2); } - public static Tool GetARockLongsword() { + public static Tool GetARockLongsword() + { return new Tool("rock_longsword", ToolType.Sword, 4); } - public static Tool GetFromStock(string stock_id) { - switch(stock_id) { + public static Tool GetFromStock(string stock_id) + { + switch (stock_id) + { case "wooden_pickaxe": return GetAWoodenPickaxe(); case "wooden_axe": return GetAWoodenAxe(); case "wooden_shovel": return GetAWoodenShovel(); diff --git a/Mundus/Service/Tiles/Items/Types/Gear.cs b/Mundus/Service/Tiles/Items/Types/Gear.cs index 52f8d9d..4dbfbc9 100644 --- a/Mundus/Service/Tiles/Items/Types/Gear.cs +++ b/Mundus/Service/Tiles/Items/Types/Gear.cs @@ -1,12 +1,17 @@ -namespace Mundus.Service.Tiles.Items.Types { - public class Gear : ItemTile { +namespace Mundus.Service.Tiles.Items.Types +{ + public class Gear : ItemTile + { public Gear(Gear gear) : base(gear.stock_id) - { } + { + } public Gear(string stock_id) : base(stock_id) - { } + { + } - public override string ToString() { + public override string ToString() + { return $"Gear | ID: {stock_id}"; } } diff --git a/Mundus/Service/Tiles/Items/Types/GroundTile.cs b/Mundus/Service/Tiles/Items/Types/GroundTile.cs index 215ff96..8e2280d 100644 --- a/Mundus/Service/Tiles/Items/Types/GroundTile.cs +++ b/Mundus/Service/Tiles/Items/Types/GroundTile.cs @@ -1,26 +1,31 @@ -using Gtk; -using static Mundus.Data.Values; +namespace Mundus.Service.Tiles.Items.Types +{ + using static Mundus.Data.Values; + + public class GroundTile : ItemTile + { + public GroundTile(GroundTile groundTile) :this(groundTile.stock_id, groundTile.ReqShovelClass, groundTile.Solid) + { + } + + public GroundTile(string stock_id, int reqShovelClass, bool solid = true) : base(stock_id) + { + this.ReqShovelClass = reqShovelClass; + this.Solid = solid; + } -namespace Mundus.Service.Tiles.Items.Types { - public class GroundTile : ItemTile { /// - /// Required minimal shovel class for destroying the ground tile + /// Gets the required minimal shovel class for destroying the ground tile /// public int ReqShovelClass { get; private set; } + /// - /// Determines whether mobs can go through and structures can be placed (if not solid) + /// Gets whether mobs can go through and structures can be placed (if not solid) /// public bool Solid { get; private set; } - public GroundTile(GroundTile groundTile) :this(groundTile.stock_id, groundTile.ReqShovelClass, groundTile.Solid) - { } - - public GroundTile(string stock_id, int reqShovelClass, bool solid = true) :base(stock_id) { - this.ReqShovelClass = reqShovelClass; - this.Solid = solid; - } - - public override string ToString() { + public override string ToString() + { return $"GroundTile | ID: {this.stock_id} TT: {ToolType.Shovel} TC: {this.ReqShovelClass}"; } } diff --git a/Mundus/Service/Tiles/Items/Types/Material.cs b/Mundus/Service/Tiles/Items/Types/Material.cs index 565713e..acee078 100644 --- a/Mundus/Service/Tiles/Items/Types/Material.cs +++ b/Mundus/Service/Tiles/Items/Types/Material.cs @@ -1,23 +1,29 @@ -namespace Mundus.Service.Tiles.Items.Types { - public class Material : ItemTile { - /// - /// Certain materials can be eaten to replenish energy points. This stores by how much to restore energy points. - /// Note: If a material mustn't be consumed, his energy points should be less or equal to 0 - /// - public double EnergyRestorePoints { get; private set; } - +namespace Mundus.Service.Tiles.Items.Types +{ + public class Material : ItemTile + { public Material(Material material) : this(material.stock_id, material.EnergyRestorePoints) - { } + { + } public Material(string stock_id, double energyRestorePoints = -1) : base(stock_id) { this.EnergyRestorePoints = energyRestorePoints; } - public override string ToString() { - if (EnergyRestorePoints > 0) { + /// + /// Certain materials can be eaten to replenish energy points. This stores by how much to restore energy points. + /// Note: If a material mustn't be consumed, his energy points should be less or equal to 0 + /// + public double EnergyRestorePoints { get; private set; } + + public override string ToString() + { + if (this.EnergyRestorePoints > 0) + { return $"Material | ID: {this.stock_id} EnergyRP: {this.EnergyRestorePoints}"; } + return $"Material | ID: {this.stock_id}"; } } diff --git a/Mundus/Service/Tiles/Items/Types/Structure.cs b/Mundus/Service/Tiles/Items/Types/Structure.cs index 8b84978..a9dfaf7 100644 --- a/Mundus/Service/Tiles/Items/Types/Structure.cs +++ b/Mundus/Service/Tiles/Items/Types/Structure.cs @@ -1,54 +1,64 @@ -using static Mundus.Data.Values; +namespace Mundus.Service.Tiles.Items.Types +{ + using static Mundus.Data.Values; -namespace Mundus.Service.Tiles.Items.Types { - public class Structure : ItemTile { + public class Structure : ItemTile + { private Material droppedMaterial; + public Structure(Structure structure) :this(structure.stock_id, structure.inventory_stock_id, structure.Health, structure.ReqToolType, structure.ReqToolClass, structure.IsWalkable, + structure.IsWalkable, (structure.droppedMaterial != null)?new Material(structure.droppedMaterial.stock_id):null) + { + } + + public Structure(string stock_id, string inventory_stock_id, int health, ToolType reqToolType, int reqToolClass, bool isWalkable = false, bool isClimable = false, Material droppedMaterial = null) : base(stock_id) + { + this.inventory_stock_id = inventory_stock_id; + this.Health = health; + this.ReqToolType = reqToolType; + this.ReqToolClass = reqToolClass; + this.IsWalkable = isWalkable; + this.IsClimable = isClimable; + this.droppedMaterial = droppedMaterial; + } + /// - /// stock_id for when the structure is in an inventory + /// Gets the stock_id for when the structure is in an inventory /// public string inventory_stock_id { get; private set; } + /// - /// Required type of tool to break the structure + /// Gets the required type of tool to break the structure /// public ToolType ReqToolType { get; private set; } + /// - /// Required minimal tool class to break the structure + /// Gets the required minimal tool class to break the structure /// public int ReqToolClass { get; private set; } + public int Health { get; private set; } /// - /// Determines whether mobs can change superlayers (climb up or down a superlayer ; true) or not (false) + /// Gets whether mobs can change superlayers (climb up or down a superlayer ; true) or not (false) /// public bool IsClimable { get; private set; } + /// - /// Determines whether mob can walk on top of the structure (true) or not (false) + /// Gets whether mob can walk on top of the structure (true) or not (false) /// public bool IsWalkable { get; private set; } - - public Structure(Structure structure) :this(structure.stock_id, structure.inventory_stock_id, structure.Health, structure.ReqToolType, structure.ReqToolClass, structure.IsWalkable, - structure.IsWalkable, (structure.droppedMaterial != null)?new Material(structure.droppedMaterial.stock_id):null) { - } - - public Structure(string stock_id, string inventory_stock_id, int health, ToolType reqToolType, int reqToolClass, bool isWalkable = false, bool isClimable = false, Material droppedMaterial = null) : base(stock_id) { - this.inventory_stock_id = inventory_stock_id; - this.Health = health; - this.ReqToolType = reqToolType; - this.ReqToolClass = reqToolClass; - this.IsWalkable = isWalkable; - this.IsClimable = isClimable; - this.droppedMaterial = droppedMaterial; - } - /// /// Returns what the structure drops after being broken /// - public ItemTile GetDrop() { - if (droppedMaterial == null) { + public ItemTile GetDrop() + { + if (this.droppedMaterial == null) + { return this; } + return droppedMaterial; } @@ -56,14 +66,16 @@ namespace Mundus.Service.Tiles.Items.Types { /// Removes health from structure /// /// Whether the structure can still be damaged - public bool TakeDamage(int damagePoints) { + public bool TakeDamage(int damagePoints) + { this.Health -= damagePoints; return this.Health > 0; } - public override string ToString() { + public override string ToString() + { return $"Structure | ID: {this.stock_id} H: {this.Health} TT: {this.ReqToolType} TC: {this.ReqToolClass} " + - $"W: {this.IsWalkable} DM ID: {((droppedMaterial != null)?this.droppedMaterial.stock_id:null)}"; + $"W: {this.IsWalkable} DM ID: {((this.droppedMaterial != null) ? this.droppedMaterial.stock_id : null)}"; } } } diff --git a/Mundus/Service/Tiles/Items/Types/Tool.cs b/Mundus/Service/Tiles/Items/Types/Tool.cs index 424a15a..901b503 100644 --- a/Mundus/Service/Tiles/Items/Types/Tool.cs +++ b/Mundus/Service/Tiles/Items/Types/Tool.cs @@ -1,19 +1,25 @@ -using static Mundus.Data.Values; +namespace Mundus.Service.Tiles.Items.Types +{ + using static Mundus.Data.Values; -namespace Mundus.Service.Tiles.Items.Types { - public class Tool : ItemTile { - public ToolType Type { get; private set; } - public int Class { get; private set; } - - public Tool(Tool tool) : this(tool.stock_id, tool.Type, tool.Class) - { } + public class Tool : ItemTile + { + public Tool(Tool tool) : this(tool.stock_id, tool.Type, tool.Class) + { + } - public Tool(string stock_id, ToolType toolType, int toolClass) : base(stock_id) { + public Tool(string stock_id, ToolType toolType, int toolClass) : base(stock_id) + { this.Type = toolType; this.Class = toolClass; } - public override string ToString() { + public ToolType Type { get; private set; } + + public int Class { get; private set; } + + public override string ToString() + { return $"Tool | ID: {this.stock_id} Type: {this.Type} Class: {this.Class}"; } } diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs index 3b813d3..d1e8744 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobFighting.cs @@ -1,97 +1,116 @@ -using System.Linq; -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Items.Types; -using Mundus.Service.Tiles.Mobs.LandMobs; +namespace Mundus.Service.Tiles.Mobs.Controllers +{ + using System; + using System.Linq; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Service.Tiles.Items.Types; + using Mundus.Service.Tiles.Mobs.LandMobs; + using static Mundus.Data.Values; -namespace Mundus.Service.Tiles.Mobs.Controllers { - public static class MobFighting { + public static class MobFighting + { /// /// Returns if for the specified position in the superlayer the payer is in, there exists a mob + /// Returns false also if the specified positoin is the player's current position /// - /// YPos of target mob - /// XPos of target mob - public static bool ExistsFightTargetForPlayer(int mapYPos, int mapXPos) { + public static bool ExistsFightTargetForPlayer(int mapYPos, int mapXPos) + { return ExistsFightTargetForMob(MI.Player, mapYPos, mapXPos); } + /// + /// The player tries to damage mob on the specified map position + /// Note: will fail of the player uses an invalid tool to fight with + /// + public static void PlayerTryFight(int mapYPos, int mapXPos) + { + if (PlayerTryFightWithMobAtPosition(mapYPos, mapXPos)) + { + MI.Player.DrainEnergy(TAKEN_ENERGY_FROM_FIGHTING + DifficultyValueModifier()); + } + } + /// /// Returns if for the specified position in the superlayer the given mob is in, there exists a mob + /// Returns false also if the specified positoin is the mob's current position /// - /// YPos of target mob - /// XPos of target mob - public static bool ExistsFightTargetForMob(MobTile mob, int mapYPos, int mapXPos) { + private static bool ExistsFightTargetForMob(MobTile mob, int mapYPos, int mapXPos) + { return mob.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos) != null && - (mob.YPos != mapYPos && mob.XPos != mapXPos); + !(mob.YPos == mapYPos && mob.XPos == mapXPos); } - private const double TAKEN_ENERGY_FROM_FIGHTING = 0.5; /// - /// The player tries to damage (or kill) mob on the specified map position - /// Note: will fail of the player uses an invalid item + /// The given mob tries to damage the mob on the specified map position + /// Note: will fail of the given mob uses an invalid item /// - /// Inventory place of the selected item (item will be checked if its a valid tool) - /// Inventory index of the selected item place (item will be checked if its a valid tool) - /// YPos of target mob - /// XPos of target mob - public static void PlayerTryFight(int mapYPos, int mapXPos) { - if (MobTryFight(MI.Player, mapYPos, mapXPos)) { - MI.Player.DrainEnergy(TAKEN_ENERGY_FROM_FIGHTING + Values.DifficultyValueModifier()); + private static bool PlayerTryFightWithMobAtPosition(int mapYPos, int mapXPos) + { + if (PlayerCanFightWithMob(mapYPos, mapXPos)) + { + Tool selTool = (Tool)Inventory.GetPlayerItemFromItemSelection(); + MobTile targetMob = LandMobsPresets.GetFromStock(MI.Player.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos)); + + if (selTool.Class >= targetMob.Defense) + { + targetMob.XPos = mapXPos; + targetMob.YPos = mapYPos; + + PlayerFightWithMob(targetMob, selTool); + return true; + } + + GameEventLogController.AddMessage($"You need a tool class of atleast {targetMob.Defense} to fight this mob"); + } + else if (MI.Player.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos) == null) + { + GameEventLogController.AddMessage($"There is no mob to fight on \"{MI.Player.CurrSuperLayer}\" at Y:{mapYPos}, X:{mapXPos}"); + } + else + { + GameEventLogController.AddMessage($"You need a Tool of type {Values.ToolType.Sword} to fight with other mobs"); } + + return false; } - // Checks if the mob has a proper fighting item selected - private static bool MobCanFight(MobTile mob, int mapYPos, int mapXPos) { + /// + /// Checks if there exists a mob at the given location in the player's superlayer + /// and if the player has selected a proper fighting tool + /// + private static bool PlayerCanFightWithMob(int mapYPos, int mapXPos) + { return Inventory.GetPlayerItemFromItemSelection().GetType() == typeof(Tool) && - ((Tool)Inventory.GetPlayerItemFromItemSelection()).Type == Values.ToolType.Sword && - mob.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos) != null; + ((Tool)Inventory.GetPlayerItemFromItemSelection()).Type == ToolType.Sword && + MI.Player.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos) != null; } /// - /// The given mob tries to damage (or kill) mob on the specified map position - /// Note: will fail of the given mob uses an invalid item + /// Reduces health of target mob /// - /// true If mob was able to fight false otherwise. - /// Mob that will fight - /// Inventory place of the selected item (item will be checked if its a valid tool) - /// Inventory index of the selected item place (item will be checked if its a valid tool) - /// YPos of target mob - /// XPos of target mob - public static bool MobTryFight(MobTile mob, int mapYPos, int mapXPos) { - if (MobCanFight(mob, mapYPos, mapXPos)) { - Tool selTool = (Tool)Inventory.GetPlayerItemFromItemSelection(); - MobTile targetMob = LandMobsPresets.GetFromStock(mob.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos)); + private static void PlayerFightWithMob(MobTile targetMob, Tool selTool) + { + int damagePoints = 1 + (selTool.Class - targetMob.Defense); - if (selTool.Class >= targetMob.Defense) { - int damagePoints = 1 + (selTool.Class - targetMob.Defense); + if (!MI.Player.CurrSuperLayer.TakeDamageMobAtPosition(targetMob.YPos, targetMob.XPos, damagePoints)) + { + MI.Player.CurrSuperLayer.RemoveMobFromPosition(targetMob.YPos, targetMob.XPos); - if (!mob.CurrSuperLayer.TakeDamageMobAtPosition(mapYPos, mapXPos, damagePoints)) { - mob.CurrSuperLayer.RemoveMobFromPosition(mapYPos, mapXPos); + targetMob.XPos = -1; + targetMob.YPos = -1; - if (mob.Inventory.Items.Contains(null)) { - mob.Inventory.AppendToItems(targetMob.DroppedUponDeath); - } - - if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Player killed \"{targetMob.stock_id}\""); - } - } else if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Player did {damagePoints} damage to \"{targetMob.stock_id}\""); - } - return true; + if (MI.Player.Inventory.Items.Contains(null)) + { + MI.Player.Inventory.AppendToItems(targetMob.DroppedUponDeath); } - else if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"You need a tool class of atleast {targetMob.Defense} to fight this mob"); - } - } - else if (mob.CurrSuperLayer.GetMobLayerStock(mapYPos, mapXPos) == null && mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"There is no mob to fight on \"{mob.CurrSuperLayer}\" at Y:{mapYPos}, X:{mapXPos}"); + + GameEventLogController.AddMessage($"Player killed \"{targetMob.stock_id}\""); } - else if (mob.GetType() == typeof(Player)) { // Inventory.GetPlayerItem(selPlace, selIndex).GetType() != typeof(Tool) || ((Tool)Inventory.GetPlayerItem(selPlace, selIndex)).Type != ToolTypes.Sword - GameEventLogController.AddMessage($"You need a Tool of type {Values.ToolType.Sword} to fight with other mobs"); + else + { + GameEventLogController.AddMessage($"Player did {damagePoints} damage to \"{targetMob.stock_id}\""); } - return false; } } } diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs index 153bb72..0e63928 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobMovement.cs @@ -1,22 +1,24 @@ -using System; -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Data.SuperLayers; -using Mundus.Service.SuperLayers; -using Mundus.Service.Tiles.Items.Presets; -using Mundus.Service.Tiles.Mobs; -using Mundus.Service.Tiles.Mobs.LandMobs; +namespace Mundus.Service.Tiles.Mobs.Controllers +{ + using System; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Service.SuperLayers; + using Mundus.Service.Tiles.Items.Presets; + using Mundus.Service.Tiles.Mobs.LandMobs; + using static Mundus.Data.Values; + + public static class MobMovement + { + private static Random rnd = new Random(); -namespace Mundus.Service.Tiles.Mobs.Controllers { - public static class MobMovement { - private static Random rnd = new Random(); - /// /// Moves all mobs that have a RndMovementRate of more than one on a random tile /// in a 3x3 radius (including the tile they are currently on) /// - public static void MoveRandomlyAllMobs() { - foreach(var superLayer in DataBaseContexts.SuperLayerContexts) + public static void MoveRandomlyAllMobs() + { + foreach (var superLayer in DataBaseContexts.SuperLayerContexts) { for (int y = 0; y < (int)Values.CurrMapSize; y++) { @@ -24,17 +26,18 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { { MobTile mob = LandMobsPresets.GetFromStock(superLayer.GetMobLayerStock(y, x)); - if (mob != null) { - mob.YPos = y; - mob.XPos = x; - + if (mob != null) + { // Checks validity of RndMovementRate and descides if a mob will move to another tile if (mob.RndMovementRate > 0 && rnd.Next(0, mob.RndMovementRate) == 1) { int newYPos = rnd.Next(y - 1, y + 2); int newXPos = rnd.Next(x - 1, x + 2); - mob.CurrSuperLayer = superLayer; + mob.XPos = x; + mob.YPos = y; + mob.CurrSuperLayer = superLayer; + ChangeMobPosition(mob, newYPos, newXPos, (int)Values.CurrMapSize); } } @@ -43,27 +46,33 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { } } - public static void ChangeMobPosition(MobTile mob, int yPos, int xPos, int mapSize) { - if (InBoundaries(yPos, xPos)) { - if (CanWalkTo(mob, yPos, xPos)) { - ChangeMobPosition(mob, yPos, xPos); + public static void ChangeMobPosition(MobTile mob, int destinationYPos, int destinationXPos, int mapSize) + { + if (InBoundaries(destinationYPos, destinationXPos)) + { + if (CanWalkTo(mob, destinationYPos, destinationXPos)) + { + ChangeMobPosition(mob, destinationYPos, destinationXPos); } - else if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Cannot walk to Y:{yPos}, X:{xPos}"); + else if (mob.GetType() == typeof(Player)) + { + GameEventLogController.AddMessage($"Cannot walk to Y:{destinationYPos}, X:{destinationXPos}"); } } } - private const double TAKEN_ENERGY_FROM_MOVEMENT = 0.1; - public static void MovePlayer(int yPos, int xPos, int mapSize) { + public static void MovePlayer(int yPos, int xPos, int mapSize) + { ChangeMobPosition(MI.Player, yPos, xPos, mapSize); - if (MI.Player.YPos == yPos && MI.Player.XPos == xPos) { + if (MI.Player.YPos == yPos && MI.Player.XPos == xPos) + { MI.Player.DrainEnergy(TAKEN_ENERGY_FROM_MOVEMENT + Values.DifficultyValueModifier()); } } - private static void ChangeMobPosition(MobTile mob, int yPos, int xPos) { + private static void ChangeMobPosition(MobTile mob, int yPos, int xPos) + { // Mob is removed from his current superlayer and in the end is added to the new one // Note: mob could not move, but will still be removed and readded to the superlayer mob.CurrSuperLayer.RemoveMobFromPosition(mob.YPos, mob.XPos); @@ -71,90 +80,103 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { // If mob can go down a layer from a hole if (mob.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) == null && HeightController.GetSuperLayerUnderneathMob(mob) != null) - { - if (HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos) == null) - { - 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.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos)}"); - } + { + MobDescendASuperLayer(mob, yPos, xPos); } + // If mob can go down a layer from non-solid ground else if (!GroundPresets.GetFromStock(mob.CurrSuperLayer.GetGroundLayerStock(yPos, xPos)).Solid && HeightController.GetSuperLayerUnderneathMob(mob) != null) - { - - if (HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos) == null) - { - 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.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos)}"); - } + { + MobDescendASuperLayer(mob, yPos, xPos); } + // If mob can climb up else if (mob.CurrSuperLayer.GetStructureLayerStock(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.GetSuperLayerAboveMob(mob) != null) - { - // The ground above isn't solid or doesnt exist and there are no mobs on top - if (HeightController.GetSuperLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos) == null || - !GroundPresets.GetFromStock(HeightController.GetSuperLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos)).Solid) - { - mob.CurrSuperLayer = HeightController.GetSuperLayerAboveMob(mob); - - if (mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"Player climbed up a superlayer"); - } - } - 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.GetSuperLayerAboveMob(mob) == null && mob.GetType() == typeof(Player)) { - GameEventLogController.AddMessage($"There is no superlayer to climb up to"); - } + { + MobAscendASuperLayer(mob, yPos, xPos); } - else if (HeightController.GetSuperLayerAboveMob(mob).GetMobLayerStock(yPos, xPos) != null && mob.GetType() == typeof(Player)) { + 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; - mob.XPos = xPos; + mob.XPos = xPos; + mob.CurrSuperLayer.SetMobAtPosition(mob.stock_id, mob.Health, yPos, xPos); } + + private static void MobDescendASuperLayer(MobTile mob, int yPos, int xPos) + { + if (HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos) == null) + { + mob.CurrSuperLayer = HeightController.GetSuperLayerUnderneathMob(mob); - private static bool CanWalkTo(MobTile mob, int yPos, int xPos) { - //Mobs can only walk on free ground (no structure or mob ; you can walk on the same place you are) or walkable structures - if (StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)) == null) { - return mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos) == null || - (mob.YPos == yPos && mob.XPos == xPos); + if (mob.GetType() == typeof(Player)) + { + GameEventLogController.AddMessage($"Player descend a superlayer, to {mob.CurrSuperLayer}"); + } } - else if (StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)).IsWalkable) { - return mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos) == null || + else if (mob.GetType() == typeof(Player)) + { + GameEventLogController.AddMessage($"Cannot descend a superlayer, blocked by {HeightController.GetSuperLayerUnderneathMob(mob).GetMobLayerStock(yPos, xPos)}"); + } + } + + private static void MobAscendASuperLayer(MobTile mob, int yPos, int xPos) + { + if (StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)).IsClimable && + HeightController.GetSuperLayerAboveMob(mob) != null) + { + var superLayerAbove = HeightController.GetSuperLayerAboveMob(mob); + + // To ascend, the ground above mustn't be solid or exist and there are no mobs on top + if (superLayerAbove.GetGroundLayerStock(yPos, xPos) == null || + !GroundPresets.GetFromStock(superLayerAbove.GetGroundLayerStock(yPos, xPos)).Solid) + { + mob.CurrSuperLayer = superLayerAbove; + + if (mob.GetType() == typeof(Player)) + { + GameEventLogController.AddMessage($"Player ascended a superlayer"); + } + } + else if (HeightController.GetSuperLayerAboveMob(mob).GetGroundLayerStock(yPos, xPos) != null && mob.GetType() == typeof(Player)) + { + GameEventLogController.AddMessage($"Cannot ascend a superlayer, there is solid ground above"); + } + } + else if (!StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)).IsClimable && mob.GetType() == typeof(Player)) + { + GameEventLogController.AddMessage($"Cannot ascend a superlayer using a \"{mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)}\""); + } + else if (HeightController.GetSuperLayerAboveMob(mob) == null && mob.GetType() == typeof(Player)) + { + GameEventLogController.AddMessage($"There is no superlayer to climb up to"); + } + } + + private static bool CanWalkTo(MobTile mob, int yPos, int xPos) + { + // Mobs can only walk on if there is no structure or the structure is walkable + // Mobs can move to the same location they're in + if (mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos) == null || + StructurePresets.GetFromStock(mob.CurrSuperLayer.GetStructureLayerStock(yPos, xPos)).IsWalkable) + { + return mob.CurrSuperLayer.GetMobLayerStock(yPos, xPos) == null || (mob.YPos == yPos && mob.XPos == xPos); } + return false; } - // Returns if the chosen new location is inside the map - private static bool InBoundaries(int yPos, int xPos) { + /// + /// Returns if the chosen new location is inside the boundaries of the map + /// + private static bool InBoundaries(int yPos, int xPos) + { return yPos >= 0 && xPos >= 0 && yPos < (int)Values.CurrMapSize && xPos < (int)Values.CurrMapSize; } } diff --git a/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs b/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs index 4b89b54..13140b2 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobStatsController.cs @@ -1,26 +1,37 @@ -using Gtk; -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Service.SuperLayers; -using Mundus.Service.Tiles.Items.Presets; +namespace Mundus.Service.Tiles.Mobs.Controllers +{ + using Mundus.Data.Superlayers.Mobs; + using Mundus.Service.SuperLayers; + using Mundus.Service.Tiles.Items.Presets; -namespace Mundus.Service.Tiles.Mobs.Controllers { - public static class MobStatsController { + public static class MobStatsController + { public static object GroundPresetsHeightController { get; private set; } /// /// Returns the stock_id of the hearth icon that must be used on the given position of the health bar /// - /// stock_id of hearth icon - /// Health bar index public static string GetPlayerHearthStock(int index) { string stock_id = "hearth_0"; - int diff = MI.Player.Health - index * 4; - if (diff >= 4) stock_id = "hearth_4"; - else if (diff == 1) stock_id = "hearth_1"; - else if (diff == 2) stock_id = "hearth_2"; - else if (diff == 3) stock_id = "hearth_3"; + int diff = MI.Player.Health - (index * 4); + + if (diff >= 4) + { + stock_id = "hearth_4"; + } + else if (diff == 1) + { + stock_id = "hearth_1"; + } + else if (diff == 2) + { + stock_id = "hearth_2"; + } + else if (diff == 3) + { + stock_id = "hearth_3"; + } return stock_id; } @@ -30,16 +41,36 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { /// /// stock_id of energy icon /// Energy bar index - public static string GetPlayerEnergyStock(int index) { + public static string GetPlayerEnergyStock(int index) + { string stock_id = "energy_0"; int diff = (int)MI.Player.Energy - index * 6; - if (diff >= 6) stock_id = "energy_6"; - else if (diff == 1) stock_id = "energy_1"; - else if (diff == 2) stock_id = "energy_2"; - else if (diff == 3) stock_id = "energy_3"; - else if (diff == 4) stock_id = "energy_4"; - else if (diff == 5) stock_id = "energy_5"; + + if (diff >= 6) + { + stock_id = "energy_6"; + } + else if (diff == 1) + { + stock_id = "energy_1"; + } + else if (diff == 2) + { + stock_id = "energy_2"; + } + else if (diff == 3) + { + stock_id = "energy_3"; + } + else if (diff == 4) + { + stock_id = "energy_4"; + } + else if (diff == 5) + { + stock_id = "energy_5"; + } return stock_id; } @@ -47,34 +78,42 @@ namespace Mundus.Service.Tiles.Mobs.Controllers { /// /// Returns the name of the superlayer the player is curently on /// - public static string GetPlayerSuperLayerName() { + public static string GetPlayerSuperLayerName() + { return MI.Player.CurrSuperLayer.ToString(); } /// - /// Returns the player's horizontal (X) coordinates + /// Returns the player's horizontal (x) coordinates /// /// Player.XPos - public static int GetPlayerXCoord() { + public static int GetPlayerXCoord() + { return MI.Player.XPos; } /// - /// Returns the player's vertical (Y) coordinates + /// Returns the player's vertical (y) coordinates /// /// Player.YPos - public static int GetPlayerYCoord() { + public static int GetPlayerYCoord() + { return MI.Player.YPos; } /// /// Checks if the player has an an empty/non-solid tile directly on the superlayer above him /// - public static bool ExistsHoleOnTopOfPlayer() { + public static bool ExistsHoleOnTopOfPlayer() + { + //There can't be a hole if there isn't a layer above the player - if (HeightController.GetSuperLayerAboveMob(MI.Player) == null) { + if (HeightController.GetSuperLayerAboveMob(MI.Player) == null) + { return false; } + + // Returns true if the ground stock above the player is null or isnt 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 687e5aa..f85a142 100644 --- a/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs +++ b/Mundus/Service/Tiles/Mobs/Controllers/MobTerraforming.cs @@ -1,188 +1,230 @@ -using System.Linq; -using static Mundus.Data.Values; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Data.SuperLayers; -using Mundus.Service.SuperLayers; -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Items.Presets; -using Mundus.Data; -using Mundus.Service.Tiles.Items.Types; - -namespace Mundus.Service.Tiles.Mobs.Controllers { - public static class MobTerraforming { +namespace Mundus.Service.Tiles.Mobs.Controllers +{ + using System.Linq; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Data.SuperLayers; + using Mundus.Service.SuperLayers; + using Mundus.Service.Tiles.Items.Presets; + using Mundus.Service.Tiles.Items.Types; + using static Mundus.Data.Values; + + public static class MobTerraforming + { /// /// Tries to place a selected structure/ground tile or to mine/dig (destroy) at the selected location /// - public static void PlayerTerraformAt(int mapYPos, int mapXPos) { + public static void PlayerTerraformAt(int mapYPos, int mapXPos) + { var selectedItemType = Inventory.GetPlayerItemFromItemSelection().GetType(); // If player can place strucure - if (selectedItemType == typeof(Structure)) { - if (PlayerCanBuildStructureAt(mapYPos, mapXPos)) { - PlayerBuildStructureAt(mapYPos, mapXPos); - Inventory.DeletePlayerItemTileFromItemSelection(); - } - else { - GameEventLogController.AddMessage($"Cannot build structure at Y:{mapYPos}, X:{mapXPos}"); - } - - } + if (selectedItemType == typeof(Structure)) + { + PlayerTryBuildStructureAt(mapYPos, mapXPos); + } + // If Player can place ground - else if (selectedItemType == typeof(GroundTile)) { - if (PlayerCanPlaceGroundAt(mapYPos, mapXPos)) { - PlayerPlaceGroundAt(mapYPos, mapXPos); - Inventory.DeletePlayerItemTileFromItemSelection(); - } - else { - GameEventLogController.AddMessage($"Cannot place ground at Y:{mapYPos}, X:{mapXPos}"); - } - } + else if (selectedItemType == typeof(GroundTile)) + { + PlayerTryPlaceGroundAt(mapYPos, mapXPos); + } + // If player can mine/dig - else if (selectedItemType == typeof(Tool)) { - if (PlayerCanDestroyAt(mapYPos, mapXPos)) { - PlayerDestroyAt(mapYPos, mapXPos); - } - else { - GameEventLogController.AddMessage($"Cannot destroy at Y:{mapYPos}, X:{mapXPos}"); - } + else if (selectedItemType == typeof(Tool)) + { + PlayerTryDestroyAt(mapYPos, mapXPos); } } // Player can't destory structures/ground tiles if there are none - private static bool PlayerCanDestroyAt(int yPos, int xPos) { + private static bool PlayerCanDestroyAt(int yPos, int xPos) + { return MI.Player.CurrSuperLayer.GetStructureLayerStock(yPos, xPos) != null || MI.Player.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) != null; } - private const double ENERGY_TAKEN_FROM_DESTROYING = 0.6; - private static void PlayerDestroyAt(int mapYPos, int mapXPos) { - var selectedTool = (Tool)Inventory.GetPlayerItemFromItemSelection(); + private static void PlayerTryDestroyAt(int mapYPos, int mapXPos) { + if (PlayerCanDestroyAt(mapYPos, mapXPos)) + { + var selectedTool = (Tool)Inventory.GetPlayerItemFromItemSelection(); - // Only shovels can destroy ground layer tiles, but not when there is something over the ground tile - if (selectedTool.Type == ToolType.Shovel && MI.Player.CurrSuperLayer.GetStructureLayerStock(mapYPos, mapXPos) == null) { - if (PlayerTryDestroyGroundAt(mapYPos, mapXPos, selectedTool)) { - MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_DESTROYING + Values.DifficultyValueModifier()); + // Only shovels can destroy ground layer tiles, but not when there is something over the ground tile + if (selectedTool.Type == ToolType.Shovel && MI.Player.CurrSuperLayer.GetStructureLayerStock(mapYPos, mapXPos) == null) + { + if (PlayerTryDestroyGroundAt(mapYPos, mapXPos, selectedTool)) + { + MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_DESTROYING + DifficultyValueModifier()); + } } - } - // Don't try to destroy structure if there is no structure - else if (MI.Player.CurrSuperLayer.GetStructureLayerStock(mapYPos, mapXPos) != null) { - if (PlayerTryDestroyStructureAt(mapYPos, mapXPos, selectedTool)) { - MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_DESTROYING + Values.DifficultyValueModifier()); + + // Don't try to destroy structure if there is no structure + else if (MI.Player.CurrSuperLayer.GetStructureLayerStock(mapYPos, mapXPos) != null) + { + if (PlayerTryDestroyStructureAt(mapYPos, mapXPos, selectedTool)) + { + MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_DESTROYING + DifficultyValueModifier()); + } } } + else + { + GameEventLogController.AddMessage($"Cannot destroy at Y:{mapYPos}, X:{mapXPos}"); + } } - private static bool PlayerTryDestroyGroundAt(int mapYPos, int mapXPos, Tool shovel) { + private static bool PlayerTryDestroyGroundAt(int mapYPos, int mapXPos, Tool shovel) + { var selectedGround = GroundPresets.GetFromStock(MI.Player.CurrSuperLayer.GetGroundLayerStock(mapYPos, mapXPos)); // Ground tiles that should be unbreakable have a negative required shovel class - if (selectedGround.ReqShovelClass <= shovel.Class && selectedGround.ReqShovelClass >= 0) { - MI.Player.CurrSuperLayer.SetGroundAtPosition(null, mapYPos, mapXPos); + if (selectedGround.ReqShovelClass <= shovel.Class && selectedGround.ReqShovelClass >= 0) + { + MI.Player.CurrSuperLayer.RemoveGroundFromPosition(mapYPos, mapXPos); 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) { + if (under != null && under.GetStructureLayerStock(mapYPos, mapXPos) != null) + { + if (!StructurePresets.GetFromStock(under.GetStructureLayerStock(mapYPos, mapXPos)).IsWalkable) + { under.RemoveStructureFromPosition(mapYPos, mapXPos); } } - if (MI.Player.Inventory.Items.Contains(null)) { + if (MI.Player.Inventory.Items.Contains(null)) + { MI.Player.Inventory.AppendToItems(new GroundTile(selectedGround)); } GameEventLogController.AddMessage($"Player destroyed \"{selectedGround.stock_id}\" from layer \"{MI.Player.CurrSuperLayer}\" at Y:{mapYPos}, X:{mapXPos}"); return true; } - else if (selectedGround.ReqShovelClass > shovel.Class) { + else if (selectedGround.ReqShovelClass > shovel.Class) + { GameEventLogController.AddMessage($"Ground \"{selectedGround.stock_id}\" requires minimum shovel class of: {selectedGround.ReqShovelClass}"); } - else { // selectedGround.ReqSHovelClass < 0 + else + { GameEventLogController.AddMessage($"This ground cannot be destroyed."); - } + } + return false; } - private static bool PlayerTryDestroyStructureAt(int mapYPos, int mapXPos, Tool tool) { + private static bool PlayerTryDestroyStructureAt(int mapYPos, int mapXPos, Tool tool) + { var selStructure = StructurePresets.GetFromStock(MI.Player.CurrSuperLayer.GetStructureLayerStock(mapYPos, mapXPos)); - if (selStructure.ReqToolType == tool.Type && selStructure.ReqToolClass <= tool.Class) { + if (selStructure.ReqToolType == tool.Type && selStructure.ReqToolClass <= tool.Class) + { int damagePoints = 1 + (tool.Class - selStructure.ReqToolClass); // Some structures have a "drop", a specific item that they give upon being damaged. // Other structures drop themselves (you "pick up" the structure after breaking it). - if (selStructure.GetDrop() != selStructure) { + if (selStructure.GetDrop() != selStructure) + { // The amount of dropped items it adds to inventory is that of the damage points. // If the structure will "die" (health <= 0) before giving all items, it stops giving items. - for (int i = 0; i < damagePoints && i < selStructure.Health && MI.Player.Inventory.Items.Contains(null); i++) { + for (int i = 0; i < damagePoints && i < selStructure.Health && MI.Player.Inventory.Items.Contains(null); i++) + { MI.Player.Inventory.AppendToItems(new Material((Material)selStructure.GetDrop())); } } - else if (MI.Player.Inventory.Items.Contains(null)) { + else if (MI.Player.Inventory.Items.Contains(null)) + { MI.Player.Inventory.AppendToItems((Structure)selStructure.GetDrop()); } // Damage to the structure is done after adding the dropped item/items. - if (!MI.Player.CurrSuperLayer.TakeDamageStructureAtPosition(mapYPos, mapXPos, damagePoints)) { - MI.Player.CurrSuperLayer.SetStructureAtPosition(null, -1, mapYPos, mapXPos); + if (!MI.Player.CurrSuperLayer.TakeDamageStructureAtPosition(mapYPos, mapXPos, damagePoints)) + { + MI.Player.CurrSuperLayer.RemoveStructureFromPosition(mapYPos, mapXPos); GameEventLogController.AddMessage($"Player destroyed \"{selStructure.stock_id}\" from layer \"{MI.Player.CurrSuperLayer}\" at Y:{mapYPos}, X:{mapXPos}"); } - else { + else + { GameEventLogController.AddMessage($"Player did {damagePoints} damage to \"{selStructure.stock_id}\""); - } + } + return true; } - else if (selStructure.ReqToolType != tool.Type) { + else if (selStructure.ReqToolType != tool.Type) + { GameEventLogController.AddMessage($"Structure \"{selStructure.stock_id}\" requires tool type: {selStructure.ReqToolType}"); } - else { // selStructure.ReqToolClass > tool.Class + else + { GameEventLogController.AddMessage($"Structure \"{selStructure.stock_id}\" requires minimum tool class of: {selStructure.ReqToolClass}"); - } + } + return false; } // Ground can be placed if there isnt a structure on an empty ground layer spot - private static bool PlayerCanPlaceGroundAt(int yPos, int xPos) { + private static bool PlayerCanPlaceGroundAt(int yPos, int xPos) + { return MI.Player.CurrSuperLayer.GetGroundLayerStock(yPos, xPos) == null && MI.Player.CurrSuperLayer.GetStructureLayerStock(yPos, xPos) == null; } - private const double ENERGY_TAKEN_FROM_PLACING_GROUND = 0.4; - private static void PlayerPlaceGroundAt(int yPos, int xPos) { - GroundTile toPlace = (GroundTile)Inventory.GetPlayerItemFromItemSelection(); - MI.Player.CurrSuperLayer.SetGroundAtPosition(toPlace.stock_id, yPos, xPos); - MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_PLACING_GROUND + Values.DifficultyValueModifier()); - - GameEventLogController.AddMessage($"Set ground \"{toPlace.stock_id}\" on layer \"{MI.Player.CurrSuperLayer}\" at Y:{yPos}, X:{xPos}"); + private static void PlayerTryPlaceGroundAt(int yPos, int xPos) + { + if (PlayerCanPlaceGroundAt(yPos, xPos)) + { + GroundTile toPlace = (GroundTile)Inventory.GetPlayerItemFromItemSelection(); + + MI.Player.CurrSuperLayer.SetGroundAtPosition(toPlace.stock_id, yPos, xPos); + MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_PLACING_GROUND + DifficultyValueModifier()); + + GameEventLogController.AddMessage($"Set ground \"{toPlace.stock_id}\" on layer \"{MI.Player.CurrSuperLayer}\" at Y:{yPos}, X:{xPos}"); + + Inventory.DeletePlayerItemTileFromItemSelection(); + } + else + { + GameEventLogController.AddMessage($"Cannot place ground at Y:{yPos}, X:{xPos}"); + } } - - private static bool PlayerCanBuildStructureAt(int yPos, int xPos) { + private static bool PlayerCanBuildStructureAt(int yPos, int xPos) + { return MI.Player.CurrSuperLayer.GetStructureLayerStock(yPos, xPos) == null; } - - private const double ENERGY_TAKEN_FROM_BUILDING_STRUCTURE = 0.5; - private static void PlayerBuildStructureAt(int yPos, int xPos) { - Structure toBuild = (Structure)Inventory.GetPlayerItemFromItemSelection(); - - // 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.GetSuperLayerUnderneathMob(MI.Player).GetStructureLayerStock(yPos, xPos) == null) - { - HeightController.GetSuperLayerUnderneathMob(MI.Player).SetStructureAtPosition(toBuild.stock_id, toBuild.Health, yPos, 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); - - GameEventLogController.AddMessage($"Set structure \"{toBuild.stock_id}\" on layer \"{MI.Player.CurrSuperLayer}\" at Y:{yPos}, X:{xPos}"); + + private static void PlayerTryBuildStructureAt(int yPos, int xPos) + { + if (PlayerCanBuildStructureAt(yPos, xPos)) + { + Structure toBuild = (Structure)Inventory.GetPlayerItemFromItemSelection(); + + // 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.GetSuperLayerUnderneathMob(MI.Player).GetStructureLayerStock(yPos, xPos) == null) + { + HeightController.GetSuperLayerUnderneathMob(MI.Player).SetStructureAtPosition(toBuild.stock_id, toBuild.Health, yPos, 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); + + GameEventLogController.AddMessage($"Set structure \"{toBuild.stock_id}\" on layer \"{MI.Player.CurrSuperLayer}\" at Y:{yPos}, X:{xPos}"); + } + + MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_BUILDING_STRUCTURE + Values.DifficultyValueModifier()); + + Inventory.DeletePlayerItemTileFromItemSelection(); + } + else + { + GameEventLogController.AddMessage($"Cannot build structure at Y:{yPos}, X:{xPos}"); } - - MI.Player.DrainEnergy(ENERGY_TAKEN_FROM_BUILDING_STRUCTURE + Values.DifficultyValueModifier()); } } } diff --git a/Mundus/Service/Tiles/Mobs/Inventory.cs b/Mundus/Service/Tiles/Mobs/Inventory.cs index ae4f141..358666e 100644 --- a/Mundus/Service/Tiles/Mobs/Inventory.cs +++ b/Mundus/Service/Tiles/Mobs/Inventory.cs @@ -1,90 +1,109 @@ -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Items.Types; -using System; -using System.Linq; - -namespace Mundus.Service.Tiles.Mobs { - public class Inventory { - public enum InventoryPlace { - Hotbar, - Items, - Accessories, - Gear - } - +namespace Mundus.Service.Tiles.Mobs +{ + using System; + using System.Linq; + using Mundus.Service.Tiles.Items; + using Mundus.Service.Tiles.Items.Types; + + public class Inventory + { /// /// Has a size of "Screen and Inventory" and can hold Tools, Materials, Structures and Gear /// public ItemTile[] Hotbar { get; set; } + /// /// Has a size of the "Screen and Inventory" squared and can hold Tools, Materials, Structures and Gear /// public ItemTile[] Items { get; set; } + /// /// Has a size of double the "Screen and Inventory" and can only hold Gear /// public Gear[] Accessories { get; set; } + /// /// Has a size of "Screen and Inventory" and can only hold Gear /// public Gear[] Gear { get; set; } - public Inventory(int screenInvSize) { + public Inventory(int screenInvSize) + { this.SetSizes(screenInvSize); } - public void SetSizes(int screenInvSize) { + public enum InventoryPlace { + Hotbar, + Items, + Accessories, + Gear + } + + public void SetSizes(int screenInvSize) + { this.Hotbar = new ItemTile[screenInvSize]; this.Items = new ItemTile[screenInvSize * screenInvSize]; this.Accessories = new Gear[screenInvSize * 2]; this.Gear = new Gear[screenInvSize]; } - public void AppendToHotbar(ItemTile itemTile) { + public void AppendToHotbar(ItemTile itemTile) + { this.AddToHotbar(itemTile, Array.IndexOf(this.Hotbar, this.Hotbar.First(x => x == null))); } - public void AddToHotbar(ItemTile itemTile, int index) { + public void AddToHotbar(ItemTile itemTile, int index) + { this.Hotbar[index] = itemTile; } - public void DeleteFromHotbar(int index) { + public void DeleteFromHotbar(int index) + { this.Hotbar[index] = null; } - public void AppendToItems(ItemTile itemTile) { + public void AppendToItems(ItemTile itemTile) + { this.AddToItems(itemTile, Array.IndexOf(this.Items, this.Items.First(x => x == null))); } - public void AddToItems(ItemTile itemTile, int index) { + public void AddToItems(ItemTile itemTile, int index) + { this.Items[index] = itemTile; } - public void DeleteFromItems(int index) { + public void DeleteFromItems(int index) + { this.Items[index] = null; } - public void EquipAccessory(Gear accessory, int index) { + public void EquipAccessory(Gear accessory, int index) + { this.Accessories[index] = accessory; } - public void AppendAccessories(Gear accessory) { + public void AppendAccessories(Gear accessory) + { this.EquipAccessory(accessory, Array.IndexOf(this.Accessories, this.Accessories.First(x => x == null))); } - public void DeleteAccessory(int index) { + public void DeleteAccessory(int index) + { this.Accessories[index] = null; } - public void EquipGear(Gear gear, int index) { + public void EquipGear(Gear gear, int index) + { this.Gear[index] = gear; } - public void AppendGear(Gear gear) { + public void AppendGear(Gear gear) + { this.EquipGear(gear, Array.IndexOf(this.Gear, this.Gear.First(x => x == null))); } - public void DeleteGear(int index) { + public void DeleteGear(int index) + { this.Gear[index] = null; } @@ -92,23 +111,38 @@ namespace Mundus.Service.Tiles.Mobs { /// Returns an ItemTile depending on specified place ("hotbar", "items", "accessories" or "gear") /// and specified index /// - public ItemTile GetItemTile(InventoryPlace place, int index) { + public ItemTile GetItemTile(InventoryPlace place, int index) + { ItemTile toReturn = null; - switch (place) { + switch (place) + { case InventoryPlace.Hotbar: toReturn = this.Hotbar[index]; break; case InventoryPlace.Items: toReturn = this.Items[index]; break; case InventoryPlace.Accessories: toReturn = this.Accessories[index]; break; case InventoryPlace.Gear: toReturn = this.Gear[index]; break; } + return toReturn; } + public void DeleteItem(InventoryPlace place, int index) + { + switch (place) + { + case InventoryPlace.Hotbar: this.Hotbar[index] = null; break; + case InventoryPlace.Items: this.Items[index] = null; break; + case InventoryPlace.Accessories: this.Accessories[index] = null; break; + case InventoryPlace.Gear: this.Gear[index] = null; break; + } + } + /// /// Deletes an ItemTile depending on specified place ("hotbar", "items", "accessories" or "gear") /// and specified index /// - public static void DeletePlayerItemTileFromItemSelection() { + public static void DeletePlayerItemTileFromItemSelection() + { Data.Superlayers.Mobs.MI.Player.Inventory.DeleteItem(ItemController.SelItemPlace, ItemController.SelItemIndex); } @@ -116,17 +150,9 @@ namespace Mundus.Service.Tiles.Mobs { /// Returns an ItemTile depending on specified place ("hotbar", "items", "accessories" or "gear") /// and specified index in player's inventory /// - public static ItemTile GetPlayerItemFromItemSelection() { + public static ItemTile GetPlayerItemFromItemSelection() + { return Data.Superlayers.Mobs.MI.Player.Inventory.GetItemTile(ItemController.SelItemPlace, ItemController.SelItemIndex); } - - public void DeleteItem(InventoryPlace place, int index) { - switch (place) { - case InventoryPlace.Hotbar: this.Hotbar[index] = null; break; - case InventoryPlace.Items: this.Items[index] = null; break; - case InventoryPlace.Accessories: this.Accessories[index] = null; break; - case InventoryPlace.Gear: this.Gear[index] = null; break; - } - } } -} +} \ No newline at end of file diff --git a/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs b/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs index 642116a..e19cf7c 100644 --- a/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs +++ b/Mundus/Service/Tiles/Mobs/LandMobs/LandMobsPresets.cs @@ -1,23 +1,37 @@ -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using Mundus.Data.SuperLayers; -using Mundus.Service.Tiles.Items.Presets; +namespace Mundus.Service.Tiles.Mobs.LandMobs +{ + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + using Mundus.Service.Tiles.Items.Presets; -namespace Mundus.Service.Tiles.Mobs.LandMobs { - public static class LandMobsPresets { - private static MobTile cow = 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() { + /// + /// Returns a (static) cow MobTile. + /// Do not modify! + /// + public static MobTile GetCow() + { return cow; } - public static MobTile GetSheep() { + /// + /// Returns a (static) sheep MobTile. + /// Do not modify! + /// + public static MobTile GetSheep() + { return sheep; } - public static MobTile GetFromStock(string stock_id) { - switch(stock_id) { + public static MobTile GetFromStock(string stock_id) + { + switch (stock_id) + { case "L_cow": return GetCow(); case "L_sheep": return GetSheep(); case "player": return MI.Player; diff --git a/Mundus/Service/Tiles/Mobs/LandMobs/Player.cs b/Mundus/Service/Tiles/Mobs/LandMobs/Player.cs index f7a1329..11d6805 100644 --- a/Mundus/Service/Tiles/Mobs/LandMobs/Player.cs +++ b/Mundus/Service/Tiles/Mobs/LandMobs/Player.cs @@ -1,47 +1,54 @@ -using System; -using Mundus.Data.SuperLayers; -using Mundus.Data.Windows; -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Items.Types; +namespace Mundus.Service.Tiles.Mobs.LandMobs +{ + using System; + using Mundus.Data.SuperLayers; + using Mundus.Data.Windows; + using Mundus.Service.Tiles.Items.Types; -namespace Mundus.Service.Tiles.Mobs.LandMobs { - public class Player : MobTile { - public double Energy { get; private set; } - + public class Player : MobTile + { /// /// Note: player has an rndMovementQualifier of -1 and drops first item in the hotbar /// public Player(string stock_id, int defence, ISuperLayerContext currentSuperLayer) - : base(stock_id, WI.SelWin.Size * 4, defence, currentSuperLayer, WI.SelWin.Size, null, -1) + : base(stock_id, WI.SelWin.Size * 4, defence, currentSuperLayer, WI.SelWin.Size, null, -1) { this.Energy = WI.SelWin.Size * 6; this.DroppedUponDeath = (Material)this.Inventory.Hotbar[0]; } + + public double Energy { get; private set; } /// /// Removes energy from player. If energy gets below 0 it will start taking health /// /// Energy points to drain from player (will do nothing if value less than 0 - public void DrainEnergy(double value) { - if (value > 0) { + public void DrainEnergy(double value) + { + if (value > 0) + { this.Energy -= value; - if (this.Energy < 0) { + if (this.Energy < 0) + { this.TakeDamage((int)Math.Ceiling(Math.Abs(this.Energy))); this.Energy = 0; } } - } - + } + /// /// Restores energy from player. If energy is maxed out (WI.SelWin.Size * 6) it starts healing the player /// /// Energy points to restore energy (will do nothing if value less than 0 - public void RestoreEnergy(double value) { - if (value > 0) { + public void RestoreEnergy(double value) + { + if (value > 0) + { this.Energy += value; - if (this.Energy > WI.SelWin.Size * 6) { + if (this.Energy > WI.SelWin.Size * 6) + { this.Heal((int)Math.Ceiling(Energy - WI.SelWin.Size * 6)); this.Energy = WI.SelWin.Size * 6; } diff --git a/Mundus/Service/Tiles/Mobs/MobTile.cs b/Mundus/Service/Tiles/Mobs/MobTile.cs index 10d9fef..c527437 100644 --- a/Mundus/Service/Tiles/Mobs/MobTile.cs +++ b/Mundus/Service/Tiles/Mobs/MobTile.cs @@ -1,57 +1,73 @@ -using Gtk; -using Mundus.Data; -using Mundus.Data.SuperLayers; -using Mundus.Data.Windows; -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Items.Types; - -namespace Mundus.Service.Tiles.Mobs { - public class MobTile : ITile { +namespace Mundus.Service.Tiles.Mobs +{ + using Mundus.Data.SuperLayers; + using Mundus.Data.Windows; + using Mundus.Service.Tiles.Items.Types; + + public class MobTile : ITile + { + public MobTile(string stock_id, int health, int defence, ISuperLayerContext currentSuperLayer, int inventorySize = 5, Material droppedUponDeath = null, int rndMovementQualifier = 3) + { + this.stock_id = stock_id; + this.Health = health; + this.Defense = defence; + this.CurrSuperLayer = currentSuperLayer; + this.DroppedUponDeath = droppedUponDeath; + this.Inventory = new Inventory(inventorySize); + this.RndMovementRate = rndMovementQualifier; + } + public string stock_id { get; private set; } - public Image Texture { get; private set; } + /// + /// Gets or sets the superlayer the mob is currently in + /// public ISuperLayerContext CurrSuperLayer { get; set; } + + /// + /// Gets or sets the vertical (y) position where the MobTile is located + /// public int YPos { get; set; } + + /// + /// Gets or sets the horizontal (x) position where the MobTile is located + /// public int XPos { get; set; } - public int Health { get; private set; } + + public int Health { get; private set; } + public int Defense { get; set; } - public Material DroppedUponDeath { get; protected set; } + + public Material DroppedUponDeath { get; protected set; } + public Inventory Inventory { get; set; } - /// - /// Specifies how big the chance of a mob moving (randomly) is. Lower the value, higher the chance for movement. - /// Note: negative values (or 0) means the mob won't move randomly - /// + /// + /// Specifies how big the chance of a mob moving (randomly) is. Lower the value, higher the chance for movement. + /// Note: negative values (or 0) means the mob won't move randomly + /// public int RndMovementRate { get; protected set; } - public MobTile(string stock_id, int health, int defence, ISuperLayerContext currentSuperLayer, int inventorySize = 5, Material droppedUponDeath = null, int rndMovementQualifier = 3) { - this.stock_id = stock_id; - this.Texture = new Image(stock_id, IconSize.Dnd); - this.Health = health; - this.Defense = defence; - this.CurrSuperLayer = currentSuperLayer; - this.RndMovementRate = rndMovementQualifier; - this.DroppedUponDeath = droppedUponDeath; - this.Inventory = new Inventory(inventorySize); - } - - /// - /// Removes health from mob - /// - /// Whether the mob can still be damaged - public bool TakeDamage(int damagePoints) { - this.Health -= damagePoints; - return this.Health > 0; - } + /// + /// Removes health from mob + /// + /// Whether the mob can still be damaged + public bool TakeDamage(int damagePoints) + { + this.Health -= damagePoints; + return this.Health > 0; + } /// - /// Heals the mobtile (unless/until it has full health (4 * inventorySize)) + /// Heals the MobTile (unless/until it has full health (4 * inventorySize)) /// /// Health points to heal with - public void Heal(int healthPoints) { + public void Heal(int healthPoints) + { this.Health += healthPoints; - if (this.Health > WI.SelWin.Size * 4) { + if (this.Health > WI.SelWin.Size * 4) + { this.Health = WI.SelWin.Size * 4; } } diff --git a/Mundus/Service/Windows/Calculate.cs b/Mundus/Service/Windows/Calculate.cs index 873bf63..55220ec 100644 --- a/Mundus/Service/Windows/Calculate.cs +++ b/Mundus/Service/Windows/Calculate.cs @@ -1,44 +1,133 @@ -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; -using System; - -namespace Mundus.Service.Windows { - public static class Calculate { +namespace Mundus.Service.Windows +{ + using System; + using Mundus.Data; + using Mundus.Data.Superlayers.Mobs; + + /// + /// Used to calculate values, related to the buttons on the game windows + /// + public static class Calculate + { /*Depending on whether you are on the edge of the map or in the center, the screen renders a bit differently. *On the edge it doesn't follow the player and only shows the corner "chunk". In the other parts it follows the *the player, making sure he stays in the center of the screen. *This means that when the player is followed, rendered part of the map depend on the player position, but when - *he isn't, it depends on the screen and map sizes.*/ - public static int CalculateMaxY(int size) { - int maxY = (MI.Player.YPos - size/2 >= 0) ? MI.Player.YPos + size/2 : size - 1; - if (maxY >= (int)Values.CurrMapSize) maxY = (int)Values.CurrMapSize - 1; + *he isn't, it depends on the screen and map sizes.*/ + + public static int CalculateMaxY(int size) + { + int maxY = MI.Player.YPos + (size / 2); + + // If you are on the top edge of the map + if (MI.Player.YPos - (size / 2) < 0) + { + maxY = size - 1; + } + + // If you are on the bottom edge of the map + else if (maxY >= (int)Values.CurrMapSize) + { + maxY = (int)Values.CurrMapSize - 1; + } + return maxY; - } - public static int CalculateStartY(int size) { - int startY = (MI.Player.YPos - size/2 <= (int)Values.CurrMapSize - size) ? MI.Player.YPos - size/2 : (int)Values.CurrMapSize - size; - if (startY < 0) startY = 0; + } + + public static int CalculateStartY(int size) + { + int startY = MI.Player.YPos - (size / 2); + + // If you are on the top edge of the map + if (startY < 0) + { + startY = 0; + } + + // If you are on the bottom edge of the map + else if (MI.Player.YPos - (size / 2) > (int)Values.CurrMapSize - size) + { + startY = (int)Values.CurrMapSize - size; + } + return startY; - } - public static int CalculateMaxX(int size) { - int maxX = (MI.Player.XPos - size/2 >= 0) ? MI.Player.XPos + size/2 : size - 1; - if (maxX >= (int)Values.CurrMapSize) maxX = (int)Values.CurrMapSize - 1; + } + + public static int CalculateMaxX(int size) + { + int maxX = MI.Player.XPos + (size / 2); + + // If you are on the leftmost edge of the map + if (MI.Player.XPos - (size / 2) < 0) + { + maxX = size - 1; + } + + // If you are on the rightmost edge of the map + else if (maxX >= (int)Values.CurrMapSize) + { + maxX = (int)Values.CurrMapSize - 1; + } + return maxX; - } - public static int CalculateStartX(int size) { - int startX = (MI.Player.XPos - size/2 <= (int)Values.CurrMapSize - size) ? MI.Player.XPos - size/2 : (int)Values.CurrMapSize - size; - if (startX < 0) startX = 0; + } + + public static int CalculateStartX(int size) + { + int startX = MI.Player.XPos - (size / 2); + + // If you are on the leftmost edge + if (startX < 0) + { + startX = 0; + } + + // If you are on the rightmost edge + if (MI.Player.XPos - (size / 2) > (int)Values.CurrMapSize - size) + { + startX = (int)Values.CurrMapSize - size; + } + return startX; } - //Screen buttons show only a certain part of the whole map - public static int CalculateYFromButton(int buttonYPos, int size) { - int newYPos = (MI.Player.YPos - size/2 >= 0) ? MI.Player.YPos - size/2 + buttonYPos : buttonYPos; - if (MI.Player.YPos > (int)Values.CurrMapSize - Math.Ceiling(size/2.0)) newYPos = buttonYPos + (int)Values.CurrMapSize - size; + // Screen buttons show only a certain part of the whole map + + public static int CalculateYFromButton(int buttonYPos, int size) + { + int newYPos = MI.Player.YPos - (size / 2) + buttonYPos; + + // If you are on the top edge of the map + if (MI.Player.YPos - (size / 2) < 0) + { + newYPos = buttonYPos; + } + + // If you are on the bottom edge of the map + if (MI.Player.YPos > (int)Values.CurrMapSize - Math.Ceiling(size / 2.0)) + { + newYPos = buttonYPos + (int)Values.CurrMapSize - size; + } + return newYPos; } - public static int CalculateXFromButton(int buttonXPos, int size) { - int newXPos = (MI.Player.XPos - size/2 >= 0) ? MI.Player.XPos - size/2 + buttonXPos : buttonXPos; - if (MI.Player.XPos > (int)Values.CurrMapSize - Math.Ceiling(size/2.0)) newXPos = buttonXPos + (int)Values.CurrMapSize - size; + + public static int CalculateXFromButton(int buttonXPos, int size) + { + int newXPos = MI.Player.XPos - (size / 2) + buttonXPos; + + // If you are on the leftmost edge of the map + if (MI.Player.XPos - (size / 2) < 0) + { + newXPos = buttonXPos; + } + + // If you are on the rightmost edge of the map + else if (MI.Player.XPos > (int)Values.CurrMapSize - Math.Ceiling(size / 2.0)) + { + newXPos = buttonXPos + (int)Values.CurrMapSize - size; + } + return newXPos; } } diff --git a/Mundus/Service/Windows/WindowController.cs b/Mundus/Service/Windows/WindowController.cs index 09174ed..1c4a4aa 100644 --- a/Mundus/Service/Windows/WindowController.cs +++ b/Mundus/Service/Windows/WindowController.cs @@ -1,18 +1,20 @@ -using System; -using Gtk; -using Mundus.Data.Windows; -using Mundus.Service.Tiles.Items; -using Mundus.Service.Tiles.Mobs; -using Mundus.Service.Tiles.Mobs.Controllers; -using Mundus.Views.Windows; - -namespace Mundus.Service.Windows { - public static class WindowController { +namespace Mundus.Service.Windows +{ + using Gtk; + using Mundus.Data.Windows; + using Mundus.Service.Tiles.Items; + using Mundus.Service.Tiles.Mobs; + using Mundus.Service.Tiles.Mobs.Controllers; + + public static class WindowController + { + public static bool PauseWindowVisible { get; set; } /// /// Shows the settings window and hides the sender /// - public static void ShowSettingsWindow(Window sender) { + public static void ShowSettingsWindow(Window sender) + { sender.Hide(); WI.WSettings.Show(sender); } @@ -20,7 +22,8 @@ namespace Mundus.Service.Windows { /// /// Shows the new game window, sets it's default values and hides the sender /// - public static void ShowNewGameWindow(Window sender) { + public static void ShowNewGameWindow(Window sender) + { sender.Hide(); WI.WNewGame.SetDefaults(); WI.WNewGame.Show(); @@ -29,17 +32,55 @@ namespace Mundus.Service.Windows { /// /// Shows the main window and hides the sender /// - public static void ShowMainWindow(Window sender) { + public static void ShowMainWindow(Window sender) + { sender.Hide(); WI.WMain.Show(); } - public static bool PauseWindowVisible { get; set; } + public static void React(int button) + { + int size = WI.SelWin.Size; + + int buttonYPos = (button - 1) / size; + int buttonXPos = (button - (buttonYPos * size)) - 1; + + int mapXPos = Calculate.CalculateXFromButton(buttonXPos, size); + int mapYPos = Calculate.CalculateYFromButton(buttonYPos, size); + + if (!ItemController.HasSelectedItem()) + { + MobMovement.MovePlayer(mapYPos, mapXPos, size); + MobMovement.MoveRandomlyAllMobs(); + } + else + { + if (Inventory.GetPlayerItemFromItemSelection() != null) + { + if (MobFighting.ExistsFightTargetForPlayer(mapYPos, mapXPos)) + { + MobFighting.PlayerTryFight(mapYPos, mapXPos); + } + else + { + MobTerraforming.PlayerTerraformAt(mapYPos, mapXPos); + } + } + + ItemController.ResetSelection(); + } + + WI.SelWin.PrintWorldScreen(); + WI.SelWin.PrintMainMenu(); + + WI.SelWin.PrintMapOrInv(); + } /// /// Shows the pause window on top of all windows and "pauses" game input (bool PauseWindowVisible) /// - public static void ShowPauseWindow() { + public static void ShowPauseWindow() + { WI.WPause.Show(); WI.WPause.Present(); PauseWindowVisible = true; @@ -48,7 +89,8 @@ namespace Mundus.Service.Windows { /// /// Shows the music window on top of all windows /// - public static void ShowMusicWindow() { + public static void ShowMusicWindow() + { WI.WMusic.Show(); WI.WMusic.Present(); } @@ -56,49 +98,18 @@ namespace Mundus.Service.Windows { /// /// Shows the crafting window on top of all windows and does initializes it /// - public static void ShowCraftingWindow() { + public static void ShowCraftingWindow() + { WI.WCrafting.Initialize(); WI.WCrafting.Show(); WI.WCrafting.Present(); } - public static void ShowLogWindow() { + public static void ShowLogWindow() + { WI.WLog.Initialize(); WI.WLog.Show(); WI.WLog.Present(); } - - public static void React(int button) - { - int size = WI.SelWin.Size; - - int buttonYPos = (button - 1) / size; - int buttonXPos = (button - (buttonYPos * size)) - 1; - - int mapXPos = Calculate.CalculateXFromButton(buttonXPos, size); - int mapYPos = Calculate.CalculateYFromButton(buttonYPos, size); - - if (!ItemController.HasSelectedItem()) { - MobMovement.MovePlayer(mapYPos, mapXPos, size); - MobMovement.MoveRandomlyAllMobs(); - } - else { - if (Inventory.GetPlayerItemFromItemSelection() != null) { - if (MobFighting.ExistsFightTargetForPlayer(mapYPos, mapXPos)) { - MobFighting.PlayerTryFight(mapYPos, mapXPos); - } - else { - MobTerraforming.PlayerTerraformAt(mapYPos, mapXPos); - } - } - - ItemController.ResetSelection(); - } - - WI.SelWin.PrintWorldScreen(); - WI.SelWin.PrintMainMenu(); - - WI.SelWin.PrintMapOrInv(); - } } } diff --git a/Mundus/Views/Dialogs/ExitDialog.cs b/Mundus/Views/Dialogs/ExitDialog.cs index 73aff2e..698bb10 100644 --- a/Mundus/Views/Dialogs/ExitDialog.cs +++ b/Mundus/Views/Dialogs/ExitDialog.cs @@ -9,6 +9,7 @@ protected void OnDeleteEvent(object o, Gtk.DeleteEventArgs args) { + //To keep window instance (it is needed (stored in WindowInstances.cs) until Application.Quit) args.RetVal = true; } diff --git a/Mundus/Views/Windows/CraftingWindow.cs b/Mundus/Views/Windows/CraftingWindow.cs index 149e33f..f05603d 100644 --- a/Mundus/Views/Windows/CraftingWindow.cs +++ b/Mundus/Views/Windows/CraftingWindow.cs @@ -69,7 +69,8 @@ /// /// Crafts the item (calls CraftingController and hides the window) /// - protected void OnBtnCraftClicked(object sender, EventArgs e) { + protected void OnBtnCraftClicked(object sender, EventArgs e) + { CraftingController.CraftItemPlayer(this.recipes[this.recipeIndex]); this.Hide(); } diff --git a/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs b/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs index 1bd5618..dfcf464 100644 --- a/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs +++ b/Mundus/Views/Windows/GameWindows/Small/SmallPrinting.cs @@ -329,7 +329,9 @@ { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string stockName = GetPlayerScreenImage(row, col, Layer.Structure).Stock; + Image image = GetPlayerScreenImage(row, col, Layer.Structure); + + string stockName = (image == null) ? "blank" : image.Stock; switch (img) { -- cgit v1.2.3