From 7e8c7ca81ad5b83acd0ce71b9e45315dfe0d0957 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 6 Apr 2020 20:49:24 +0300 Subject: You can now use shovels do dig up the ground --- Mundus/Mundus.csproj | 3 +- Mundus/Service/Mobs/MobMovement.cs | 39 ++++++++++++++++++++++ Mundus/Service/Mobs/MobMoving.cs | 35 ------------------- Mundus/Service/Mobs/MobTerraforming.cs | 37 ++++++++++++++------ Mundus/Service/SuperLayers/GroundPresets.cs | 15 +++++++++ .../Service/SuperLayers/LandSuperLayerGenerator.cs | 7 +--- Mundus/Service/Tiles/GroundTile.cs | 7 +++- Mundus/Service/Tiles/Items/Material.cs | 3 +- Mundus/Service/Tiles/Items/Structure.cs | 4 +++ Mundus/Views/Windows/SmallGameWindow.cs | 2 +- .../Mundus.Views.Windows.SmallGameWindow.cs | 2 +- Mundus/gtk-gui/gui.stetic | 2 +- 12 files changed, 98 insertions(+), 58 deletions(-) create mode 100644 Mundus/Service/Mobs/MobMovement.cs delete mode 100644 Mundus/Service/Mobs/MobMoving.cs create mode 100644 Mundus/Service/SuperLayers/GroundPresets.cs diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index aa75077..fb024df 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -106,7 +106,7 @@ - + @@ -135,6 +135,7 @@ + diff --git a/Mundus/Service/Mobs/MobMovement.cs b/Mundus/Service/Mobs/MobMovement.cs new file mode 100644 index 0000000..b043677 --- /dev/null +++ b/Mundus/Service/Mobs/MobMovement.cs @@ -0,0 +1,39 @@ +using Mundus.Data; +using Mundus.Data.Superlayers.Mobs; + +namespace Mundus.Service.Mobs { + public static class MobMovement { + public static void MovePlayer(int yPos, int xPos, int size) { + ChangePosition(LMI.Player, yPos, xPos, size); + } + + public static void ChangePosition(IMob mob, int yPos, int xPos, int size) { + if (yPos >= 0 && xPos >= 0 && yPos < MapSizes.CurrSize && xPos < MapSizes.CurrSize) { + ChangePosition(mob, yPos, xPos); + } + } + + public static void ChangePosition(IMob mob, int yPos, int xPos) { + if (Walkable(mob, yPos, xPos)) { + mob.CurrSuperLayer.RemoveMobFromPosition( mob.YPos, mob.XPos ); + mob.YPos = yPos; + mob.XPos = xPos; + mob.CurrSuperLayer.SetMobAtPosition( mob.Tile, yPos, xPos ); + } + } + + private static bool Walkable(IMob mob, int yPos, int xPos) { + //Mobs can only walk on free ground (no structure on top) or walkable structures + if (mob.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) == null) { + return false; + } + return (mob.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) == null || + mob.CurrSuperLayer.GetStructureLayerTile(yPos, xPos).IsWalkable) || + mob.CurrSuperLayer.GetMobLayerTile(yPos, xPos) != null; + } + + public static bool PlayerCanWalkTo(int yPos, int xPos) { + return Walkable(LMI.Player, yPos, xPos); + } + } +} diff --git a/Mundus/Service/Mobs/MobMoving.cs b/Mundus/Service/Mobs/MobMoving.cs deleted file mode 100644 index 04ce9aa..0000000 --- a/Mundus/Service/Mobs/MobMoving.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Mundus.Data; -using Mundus.Data.Superlayers.Mobs; - -namespace Mundus.Service.Mobs { - public static class MobMoving { - public static void MovePlayer(int yPos, int xPos, int size) { - ChangePosition(LMI.Player, yPos, xPos, size); - } - - public static void ChangePosition(IMob mob, int yPos, int xPos, int size) { - if (yPos >= 0 && xPos >= 0 && yPos < MapSizes.CurrSize && xPos < MapSizes.CurrSize) { - ChangePosition(mob, yPos, xPos); - } - } - - public static void ChangePosition(IMob mob, int yPos, int xPos) { - if (Walkable(mob, yPos, xPos)) { - mob.CurrSuperLayer.RemoveMobFromPosition( mob.YPos, mob.XPos ); - mob.YPos = yPos; - mob.XPos = xPos; - mob.CurrSuperLayer.SetMobAtPosition( mob.Tile, yPos, xPos ); - } - } - - private static bool Walkable(IMob mob, int yPos, int xPos) { - return (mob.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) == null || - mob.CurrSuperLayer.GetStructureLayerTile(yPos, xPos).IsWalkable) || - mob.CurrSuperLayer.GetMobLayerTile(yPos, xPos) != null; - } - - public static bool PlayerCanWalkTo(int yPos, int xPos) { - return Walkable(LMI.Player, yPos, xPos); - } - } -} diff --git a/Mundus/Service/Mobs/MobTerraforming.cs b/Mundus/Service/Mobs/MobTerraforming.cs index c05e645..485c047 100644 --- a/Mundus/Service/Mobs/MobTerraforming.cs +++ b/Mundus/Service/Mobs/MobTerraforming.cs @@ -1,31 +1,45 @@ using System.Linq; using Mundus.Data.Superlayers.Mobs; using Mundus.Data.SuperLayers; +using Mundus.Data.Tiles; using Mundus.Service.Tiles.Items; namespace Mundus.Service.Mobs { public static class MobTerraforming { 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); - var selStructure = LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos); - - if (selStructure.ReqToolType == selTool.Type && selStructure.ReqToolClass <= selTool.Class) { - if (LMI.Player.Inventory.Items.Any(x => x == null)) { - LMI.Player.Inventory.AppendToItems(new Material(selStructure.DroppedMaterial.stock_id)); + //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); + + if (LMI.Player.Inventory.Items.Contains(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); + + if (selStructure.ReqToolType == selTool.Type && selStructure.ReqToolClass <= selTool.Class) { + if (LMI.Player.Inventory.Items.Contains(null)) { + LMI.Player.Inventory.AppendToItems(new Material(selStructure.DroppedMaterial)); + } + if (!selStructure.Damage()) { LMI.Player.CurrSuperLayer.SetStructureAtPosition(null, mapYPos, mapXPos); } - } + } else { - //TODO: put the item on the ground + //TODO: add error to log } } - else { - //TODO: add error to log - } } } @@ -60,7 +74,8 @@ namespace Mundus.Service.Mobs { } public static bool PlayerCanDestroyAt(int yPos, int xPos) { - return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) != null; + return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) != null || + LMI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) != null; } } } diff --git a/Mundus/Service/SuperLayers/GroundPresets.cs b/Mundus/Service/SuperLayers/GroundPresets.cs new file mode 100644 index 0000000..bfdcf51 --- /dev/null +++ b/Mundus/Service/SuperLayers/GroundPresets.cs @@ -0,0 +1,15 @@ +using System; +using Mundus.Service.Tiles; +using Mundus.Service.Tiles.ItemPresets; + +namespace Mundus.Service.SuperLayers { + public static class GroundPresets { + /// + /// Returns a new instance of the grass ground tile + /// + /// New instance of the grass ground tile + public static GroundTile GetAGrass() { + return new GroundTile("grass", 1, MaterialPresets.GetALandRock()); + } + } +} diff --git a/Mundus/Service/SuperLayers/LandSuperLayerGenerator.cs b/Mundus/Service/SuperLayers/LandSuperLayerGenerator.cs index 673d644..fca20af 100644 --- a/Mundus/Service/SuperLayers/LandSuperLayerGenerator.cs +++ b/Mundus/Service/SuperLayers/LandSuperLayerGenerator.cs @@ -37,12 +37,7 @@ namespace Mundus.Service.SuperLayers { for(int col = 0; col < size; col++) { for(int row = 0; row < size; row++) { - if (rnd.Next(0, 50) == -1) { - tiles[col, row] = new GroundTile("water"); - } - else { - tiles[col, row] = new GroundTile("grass"); - } + tiles[col, row] = GroundPresets.GetAGrass(); } } return tiles; diff --git a/Mundus/Service/Tiles/GroundTile.cs b/Mundus/Service/Tiles/GroundTile.cs index d5d3a42..6e89781 100644 --- a/Mundus/Service/Tiles/GroundTile.cs +++ b/Mundus/Service/Tiles/GroundTile.cs @@ -1,12 +1,17 @@ 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) { + public GroundTile(string stock_id, int reqShovelClass, Material droppedMaterial) { 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/Items/Material.cs b/Mundus/Service/Tiles/Items/Material.cs index 7c7afbf..5853763 100644 --- a/Mundus/Service/Tiles/Items/Material.cs +++ b/Mundus/Service/Tiles/Items/Material.cs @@ -1,6 +1,7 @@ namespace Mundus.Service.Tiles.Items { public class Material : ItemTile { - public Material(Material material) : base(material.stock_id) { } + public Material(Material material) : base(material.stock_id) + { } public Material(string stock_id) : base(stock_id) { } diff --git a/Mundus/Service/Tiles/Items/Structure.cs b/Mundus/Service/Tiles/Items/Structure.cs index 94e808a..75ed3c8 100644 --- a/Mundus/Service/Tiles/Items/Structure.cs +++ b/Mundus/Service/Tiles/Items/Structure.cs @@ -20,6 +20,10 @@ this.DroppedMaterial = droppedMaterial; } + /// + /// Removes 1 health from structure + /// + /// If the structure can still be damaged public bool Damage() { this.Health--; return this.Health > 0; diff --git a/Mundus/Views/Windows/SmallGameWindow.cs b/Mundus/Views/Windows/SmallGameWindow.cs index 515db93..1afe00f 100644 --- a/Mundus/Views/Windows/SmallGameWindow.cs +++ b/Mundus/Views/Windows/SmallGameWindow.cs @@ -561,7 +561,7 @@ namespace Mundus.Views.Windows { int mapYPos = Calculate.CalculateYFromButton(buttonYPos, Size); if (!HasSelection()) { - MobMoving.MovePlayer(mapYPos, mapXPos, Size); + MobMovement.MovePlayer(mapYPos, mapXPos, Size); } else { if (Inventory.GetPlayerItem(selPlace, selIndex) != null) { diff --git a/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs b/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs index 0e82868..9b63aa4 100644 --- a/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs +++ b/Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs @@ -2616,7 +2616,7 @@ namespace Mundus.Views.Windows // Container child tbUI.Gtk.Table+TableChild this.lblItemLayer = new global::Gtk.Label(); this.lblItemLayer.Name = "lblItemLayer"; - this.lblItemLayer.LabelProp = global::Mono.Unix.Catalog.GetString("Item Layer"); + this.lblItemLayer.LabelProp = global::Mono.Unix.Catalog.GetString("Structure Layer"); this.tbUI.Add(this.lblItemLayer); global::Gtk.Table.TableChild w224 = ((global::Gtk.Table.TableChild)(this.tbUI[this.lblItemLayer])); w224.TopAttach = ((uint)(9)); diff --git a/Mundus/gtk-gui/gui.stetic b/Mundus/gtk-gui/gui.stetic index 0988406..5a185ab 100644 --- a/Mundus/gtk-gui/gui.stetic +++ b/Mundus/gtk-gui/gui.stetic @@ -5032,7 +5032,7 @@ - Item Layer + Structure Layer 9 -- cgit v1.2.3