From 685f6a12c7c7ea05a390532f94cd5a755d12291e Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 9 Apr 2020 10:44:13 +0300 Subject: GroundTile is now an item tile. When breaking ground, you get the ground tile. Refactored and restructured mob terraforming code. Updated execuatable. --- Mundus Build 08-04-2020 No3.exe | Bin 539648 -> 0 bytes Mundus Build 09-04-2020 No1.exe | Bin 0 -> 540160 bytes Mundus/Mundus.csproj | 2 +- Mundus/Service/Inventory.cs | 13 +- Mundus/Service/Mobs/MobTerraforming.cs | 162 +++++++++++---------- Mundus/Service/SuperLayers/GroundPresets.cs | 2 +- Mundus/Service/SwitchItems.cs | 2 +- Mundus/Service/Tiles/GroundTile.cs | 18 --- .../Service/Tiles/ItemPresets/MaterialPresets.cs | 4 + Mundus/Service/Tiles/Items/GroundTile.cs | 19 +++ Mundus/Service/Tiles/Items/Structure.cs | 2 +- Mundus/Views/Windows/SmallGameWindow.cs | 10 +- 12 files changed, 123 insertions(+), 111 deletions(-) delete mode 100644 Mundus Build 08-04-2020 No3.exe create mode 100644 Mundus Build 09-04-2020 No1.exe delete mode 100644 Mundus/Service/Tiles/GroundTile.cs create mode 100644 Mundus/Service/Tiles/Items/GroundTile.cs diff --git a/Mundus Build 08-04-2020 No3.exe b/Mundus Build 08-04-2020 No3.exe deleted file mode 100644 index 6629492..0000000 Binary files a/Mundus Build 08-04-2020 No3.exe and /dev/null differ diff --git a/Mundus Build 09-04-2020 No1.exe b/Mundus Build 09-04-2020 No1.exe new file mode 100644 index 0000000..3ca324a Binary files /dev/null and b/Mundus Build 09-04-2020 No1.exe differ diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index cbe1e24..4e5d42a 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -104,7 +104,6 @@ - @@ -143,6 +142,7 @@ + diff --git a/Mundus/Service/Inventory.cs b/Mundus/Service/Inventory.cs index 05de625..7a45299 100644 --- a/Mundus/Service/Inventory.cs +++ b/Mundus/Service/Inventory.cs @@ -68,7 +68,7 @@ namespace Mundus.Service { this.Gear[index] = null; } - public ItemTile GetTile(string place, int index) { + public ItemTile GetItemTile(string place, int index) { ItemTile toReturn = null; switch (place.ToLower()) { @@ -80,8 +80,17 @@ namespace Mundus.Service { return toReturn; } + public void DeleteItemTile(string place, int index) { + switch (place.ToLower()) { + case "hotbar": this.Hotbar[index] = null; break; + case "items": this.Items[index] = null; break; + case "accessories": this.Accessories[index] = null; break; + case "gear": this.Gear[index] = null; break; + } + } + public static ItemTile GetPlayerItem(string place, int index) { - return Data.Superlayers.Mobs.LMI.Player.Inventory.GetTile(place, index); + return Data.Superlayers.Mobs.LMI.Player.Inventory.GetItemTile(place, index); } } } diff --git a/Mundus/Service/Mobs/MobTerraforming.cs b/Mundus/Service/Mobs/MobTerraforming.cs index 1105ce0..0d1ef4e 100644 --- a/Mundus/Service/Mobs/MobTerraforming.cs +++ b/Mundus/Service/Mobs/MobTerraforming.cs @@ -6,106 +6,110 @@ using Mundus.Service.Tiles.Items; namespace Mundus.Service.Mobs { public static class MobTerraforming { + public static void PlayerTerraformAt(int mapYPos, int mapXPos, string inventoryPlace, int inventoryIndex) { + var selectedType = Inventory.GetPlayerItem(inventoryPlace, inventoryIndex).GetType(); + + if (selectedType == typeof(Structure) && PlayerCanBuildStructureAt(mapYPos, mapXPos)) { + PlayerBuildStructureAt(mapYPos, mapXPos, inventoryPlace, inventoryIndex); + LMI.Player.Inventory.DeleteItemTile(inventoryPlace, inventoryIndex); + } + else if (selectedType == typeof(GroundTile) && PlayerCanPlaceGroundAt(mapYPos, mapXPos)) { + PlayerPlaceGroundAt(mapYPos, mapXPos, inventoryPlace, inventoryIndex); + LMI.Player.Inventory.DeleteItemTile(inventoryPlace, inventoryIndex); + } + else if (selectedType == typeof(Tool) && PlayerCanDestroyAt(mapYPos, mapXPos)) { + PlayerDestroyAt(mapYPos, mapXPos, inventoryPlace, inventoryIndex); + } + } - public static void PlayerDestroyAt(int mapYPos, int mapXPos, string place, int index) { - //sel means selected - if (LMI.Player.Inventory.GetTile(place, index).GetType() == typeof(Tool)) { - var selTool = (Tool)LMI.Player.Inventory.GetTile(place, index); - - //Only shovels can destroy ground layer tiles, but not when there is something over the ground tile - if (selTool.Type == ToolTypes.Shovel && LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos) == null) { - var selGround = LMI.Player.CurrSuperLayer.GetGroundLayerTile(mapYPos, mapXPos); - - if (selGround.ReqShovelClass <= selTool.Class) { - LMI.Player.CurrSuperLayer.SetGroundAtPosition(null, mapYPos, mapXPos); - //When a shovel destroys ground tile, it destroys the structure below, if it is not walkable - ISuperLayer under = LMI.Player.GetLayerUndearneathCurr(); - if (under != null && under.GetStructureLayerTile(mapYPos, mapXPos) != null) { - if (!under.GetStructureLayerTile(mapYPos, mapXPos).IsWalkable) { - under.RemoveStructureFromPosition(mapYPos, mapXPos); - } - } + private static bool PlayerCanDestroyAt(int yPos, int xPos) { + return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) != null || + LMI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) != null; + } - if (LMI.Player.Inventory.Items.Contains(null) && selGround.DroppedMaterial != null) { - LMI.Player.Inventory.AppendToItems(new Material(selGround.DroppedMaterial)); - } - } - } - else if (LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos) != null) { - var selStructure = LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos); + private static void PlayerDestroyAt(int mapYPos, int mapXPos, string place, int index) { + var selectedTool = (Tool)LMI.Player.Inventory.GetItemTile(place, index); - if (selStructure.ReqToolType == selTool.Type && selStructure.ReqToolClass <= selTool.Class) { - int damagePoints = 1 + (selTool.Class - selStructure.ReqToolClass); + //Only shovels can destroy ground layer tiles, but not when there is something over the ground tile + if (selectedTool.Type == ToolTypes.Shovel && LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos) == null) { + PlayerTryDestroyGroundAt(mapYPos, mapXPos, selectedTool); + } + else if (LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos) != null) { + PlayerTryDestroyStructureAt(mapYPos, mapXPos, selectedTool); + } + } + + private static void PlayerTryDestroyGroundAt(int mapYPos, int mapXPos, Tool shovel) { + var selectedGround = LMI.Player.CurrSuperLayer.GetGroundLayerTile(mapYPos, mapXPos); - if (selStructure.GetDrop() != selStructure) { - for (int i = 0; (i < damagePoints && i < selStructure.Health) && LMI.Player.Inventory.Items.Contains(null); i++) { - LMI.Player.Inventory.AppendToItems(new Material((Material)selStructure.GetDrop())); - } - } - else if (LMI.Player.Inventory.Items.Contains(null)) { - LMI.Player.Inventory.AppendToItems((Structure)selStructure.GetDrop()); - } + if (selectedGround.ReqShovelClass <= shovel.Class) { + LMI.Player.CurrSuperLayer.SetGroundAtPosition(null, mapYPos, mapXPos); - if (!selStructure.Damage(damagePoints)) { - LMI.Player.CurrSuperLayer.SetStructureAtPosition(null, mapYPos, mapXPos); - } - } - else { - //TODO: add error to log + //When a shovel destroys ground tile, it destroys the structure below (if it is not walkable) + ISuperLayer under = LMI.Player.GetLayerUndearneathCurr(); + if (under != null && under.GetStructureLayerTile(mapYPos, mapXPos) != null) { + if (!under.GetStructureLayerTile(mapYPos, mapXPos).IsWalkable) { + under.RemoveStructureFromPosition(mapYPos, mapXPos); } - } + } + + if (LMI.Player.Inventory.Items.Contains(null)) { + LMI.Player.Inventory.AppendToItems(new GroundTile(selectedGround)); + } } } - - public static void PlayerBuildAt(int mapYPos, int mapXPos, string inventoryPlace, int inventoryPlaceIndex) { - if (PlayerCanBuildAt(mapYPos, mapXPos)) { - ItemTile[] toPlace = null; - switch (inventoryPlace) { - case "hotbar": toPlace = LMI.Player.Inventory.Hotbar; break; - case "items": toPlace = LMI.Player.Inventory.Items; break; - } - - if (toPlace != null) { - //Remove item from inventory, only if it is placed - if (PlayerBuildAt(mapYPos, mapXPos, (Structure)toPlace[inventoryPlaceIndex])) { - toPlace[inventoryPlaceIndex] = null; + private static void PlayerTryDestroyStructureAt(int mapYPos, int mapXPos, Tool tool) { + var selStructure = LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos); + + if (selStructure.ReqToolType == tool.Type && selStructure.ReqToolClass <= tool.Class) { + int damagePoints = 1 + (tool.Class - selStructure.ReqToolClass); + + if (selStructure.GetDrop() != selStructure) { + for (int i = 0; i < damagePoints && i < selStructure.Health && LMI.Player.Inventory.Items.Contains(null); i++) { + LMI.Player.Inventory.AppendToItems(new Material((Material)selStructure.GetDrop())); } } + else if (LMI.Player.Inventory.Items.Contains(null)) { + LMI.Player.Inventory.AppendToItems((Structure)selStructure.GetDrop()); + } + + if (!selStructure.Damage(damagePoints)) { + LMI.Player.CurrSuperLayer.SetStructureAtPosition(null, mapYPos, mapXPos); + } } } - private static bool PlayerBuildAt(int mapYPos, int mapXPos, Structure toPlace) { - //You can't place things on top of "holes" (null in ground), but climable structures will be placed - //under the hole (if they can be) - if (toPlace.IsClimable && LMI.Player.CurrSuperLayer.GetGroundLayerTile(mapYPos, mapXPos) == null - && LMI.Player.GetLayerUndearneathCurr().GetStructureLayerTile(mapYPos, mapXPos) == null) { - LMI.Player.GetLayerUndearneathCurr().SetStructureAtPosition(toPlace, mapYPos, mapXPos); - return true; - } - else if (LMI.Player.CurrSuperLayer.GetGroundLayerTile(mapYPos, mapXPos) != null) { - LMI.Player.CurrSuperLayer.SetStructureAtPosition(toPlace, mapYPos, mapXPos); + private static bool PlayerCanPlaceGroundAt(int yPos, int xPos) { + return LMI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) == null && + LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) == null; + } - return true; - } - return false; + private static void PlayerPlaceGroundAt(int yPos, int xPos, string inventoryPlace, int inventoryIndex) { + GroundTile toPlace = (GroundTile)LMI.Player.Inventory.GetItemTile(inventoryPlace, inventoryIndex); + + LMI.Player.CurrSuperLayer.SetGroundAtPosition(toPlace, yPos, xPos); } - - public static void TryPlaceStructure(ISuperLayer superLayer, int yPos, int xPos, Structure toPlace) { - if (superLayer.GetStructureLayerTile(yPos, xPos) != null) { - superLayer.SetStructureAtPosition(toPlace, yPos, xPos); - } + + + private static bool PlayerCanBuildStructureAt(int yPos, int xPos) { + return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) == null; } - public static bool PlayerCanBuildAt(int yPos, int xPos) { - return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) == null; - } + private static void PlayerBuildStructureAt(int yPos, int xPos, string inventoryPlace, int inventoryIndex) { + Structure toBuild = (Structure)LMI.Player.Inventory.GetItemTile(inventoryPlace, inventoryIndex); - public static bool PlayerCanDestroyAt(int yPos, int xPos) { - return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) != null || - LMI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) != null; + //Climable structures will be placed under a hole (if they can be) + if (toBuild.IsClimable && LMI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) == null + && LMI.Player.GetLayerUndearneathCurr().GetStructureLayerTile(yPos, xPos) == null) { + + LMI.Player.GetLayerUndearneathCurr().SetStructureAtPosition(toBuild, yPos, xPos); + } + else if (LMI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) != null) { + LMI.Player.CurrSuperLayer.SetStructureAtPosition(toBuild, yPos, xPos); + } } } } diff --git a/Mundus/Service/SuperLayers/GroundPresets.cs b/Mundus/Service/SuperLayers/GroundPresets.cs index 6feb1c6..d2f748f 100644 --- a/Mundus/Service/SuperLayers/GroundPresets.cs +++ b/Mundus/Service/SuperLayers/GroundPresets.cs @@ -1,5 +1,5 @@ using System; -using Mundus.Service.Tiles; +using Mundus.Service.Tiles.Items; using Mundus.Service.Tiles.ItemPresets; namespace Mundus.Service.SuperLayers { diff --git a/Mundus/Service/SwitchItems.cs b/Mundus/Service/SwitchItems.cs index 3de9a38..90a0794 100644 --- a/Mundus/Service/SwitchItems.cs +++ b/Mundus/Service/SwitchItems.cs @@ -39,7 +39,7 @@ namespace Mundus.Service { var toTransfer = origin[oIndex]; if (toTransfer != null) { - if ((toTransfer.GetType() == typeof(Tool) && (destination == "hotbar" || destination == "items")) || + if (((toTransfer.GetType() == typeof(Tool) || toTransfer.GetType() == typeof(GroundTile)) && (destination == "hotbar" || destination == "items")) || ((toTransfer.GetType() == typeof(Material) || toTransfer.GetType() == typeof(Structure)) && (destination == "hotbar" || destination == "items")) || (toTransfer.GetType() == typeof(Gear) && (destination == "hotbar" || destination == "items" || destination == "accessories" || destination == "gear"))) { diff --git a/Mundus/Service/Tiles/GroundTile.cs b/Mundus/Service/Tiles/GroundTile.cs deleted file mode 100644 index 20f484e..0000000 --- a/Mundus/Service/Tiles/GroundTile.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Gtk; -using Mundus.Service.Tiles.Items; - -namespace Mundus.Service.Tiles { - public class GroundTile : ITile { - public string stock_id { get; private set; } - public Image Texture { get; private set; } - public int ReqShovelClass { get; private set; } - public Material DroppedMaterial { get; private set; } - - public GroundTile(string stock_id, int reqShovelClass, Material droppedMaterial = null) { - this.stock_id = stock_id; - this.ReqShovelClass = reqShovelClass; - this.DroppedMaterial = droppedMaterial; - this.Texture = new Image(stock_id, IconSize.Dnd); - } - } -} diff --git a/Mundus/Service/Tiles/ItemPresets/MaterialPresets.cs b/Mundus/Service/Tiles/ItemPresets/MaterialPresets.cs index 6211e98..a398561 100644 --- a/Mundus/Service/Tiles/ItemPresets/MaterialPresets.cs +++ b/Mundus/Service/Tiles/ItemPresets/MaterialPresets.cs @@ -10,5 +10,9 @@ namespace Mundus.Service.Tiles.ItemPresets { public static Material GetAStick() { return new Material("L_stick"); } + + public static Material GetAGrass() { + return new Material("L_grass"); + } } } diff --git a/Mundus/Service/Tiles/Items/GroundTile.cs b/Mundus/Service/Tiles/Items/GroundTile.cs new file mode 100644 index 0000000..3b1b846 --- /dev/null +++ b/Mundus/Service/Tiles/Items/GroundTile.cs @@ -0,0 +1,19 @@ +using Gtk; +using Mundus.Data.Tiles; + +namespace Mundus.Service.Tiles.Items { + public class GroundTile : ItemTile { + public int ReqShovelClass { get; private set; } + + public GroundTile(GroundTile groundTile) :this(groundTile.stock_id, groundTile.ReqShovelClass) + { } + + public GroundTile(string stock_id, int reqShovelClass) :base(stock_id) { + this.ReqShovelClass = reqShovelClass; + } + + public override string ToString() { + return $"GroundTile | ID: {this.stock_id} TT: {ToolTypes.Shovel} TC: {this.ReqShovelClass}"; + } + } +} diff --git a/Mundus/Service/Tiles/Items/Structure.cs b/Mundus/Service/Tiles/Items/Structure.cs index 54bb548..26fdbba 100644 --- a/Mundus/Service/Tiles/Items/Structure.cs +++ b/Mundus/Service/Tiles/Items/Structure.cs @@ -46,7 +46,7 @@ } /// - /// Removes 1 health from structure + /// Removes health from structure /// /// If the structure can still be damaged public bool Damage(int damagePoints) { diff --git a/Mundus/Views/Windows/SmallGameWindow.cs b/Mundus/Views/Windows/SmallGameWindow.cs index d37137b..a63bfb4 100644 --- a/Mundus/Views/Windows/SmallGameWindow.cs +++ b/Mundus/Views/Windows/SmallGameWindow.cs @@ -581,21 +581,15 @@ namespace Mundus.Views.Windows { } else { if (Inventory.GetPlayerItem(selPlace, selIndex) != null) { - var selType = Inventory.GetPlayerItem(selPlace, selIndex).GetType(); //try to do MobFighting - if (selType == typeof(Structure) && MobTerraforming.PlayerCanBuildAt(mapYPos, mapXPos)) { - MobTerraforming.PlayerBuildAt(mapYPos, mapXPos, selPlace, selIndex); - - } - else if (selType == typeof(Tool) && MobTerraforming.PlayerCanDestroyAt(mapYPos, mapXPos)) { - MobTerraforming.PlayerDestroyAt(mapYPos, mapXPos, selPlace, selIndex); - } + MobTerraforming.PlayerTerraformAt(mapYPos, mapXPos, selPlace, selIndex); } ResetSelection(); } this.PrintScreen(); this.PrintMainMenu(); + if (this.MapMenuIsVisible()) { this.PrintMap(); } -- cgit v1.2.3