diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-04-06 20:49:24 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-04-06 20:49:24 +0300 |
| commit | 7e8c7ca81ad5b83acd0ce71b9e45315dfe0d0957 (patch) | |
| tree | dedb288db396985bc8274bc9a3273b0c70f21886 | |
| parent | 275c7c3ad54a906913280a082dfbdba3b28937d0 (diff) | |
| download | Mundus-7e8c7ca81ad5b83acd0ce71b9e45315dfe0d0957.tar Mundus-7e8c7ca81ad5b83acd0ce71b9e45315dfe0d0957.tar.gz Mundus-7e8c7ca81ad5b83acd0ce71b9e45315dfe0d0957.zip | |
You can now use shovels do dig up the ground
| -rw-r--r-- | Mundus/Mundus.csproj | 3 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/MobMovement.cs (renamed from Mundus/Service/Mobs/MobMoving.cs) | 8 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/MobTerraforming.cs | 37 | ||||
| -rw-r--r-- | Mundus/Service/SuperLayers/GroundPresets.cs | 15 | ||||
| -rw-r--r-- | Mundus/Service/SuperLayers/LandSuperLayerGenerator.cs | 7 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/GroundTile.cs | 7 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Items/Material.cs | 3 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Items/Structure.cs | 4 | ||||
| -rw-r--r-- | Mundus/Views/Windows/SmallGameWindow.cs | 2 | ||||
| -rw-r--r-- | Mundus/gtk-gui/Mundus.Views.Windows.SmallGameWindow.cs | 2 | ||||
| -rw-r--r-- | Mundus/gtk-gui/gui.stetic | 2 |
11 files changed, 65 insertions, 25 deletions
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 @@ <Compile Include="Service\Mobs\LandMobs\Player.cs" />
<Compile Include="Service\Inventory.cs" />
<Compile Include="Views\Windows\IGameWindow.cs" />
- <Compile Include="Service\Mobs\MobMoving.cs" />
+ <Compile Include="Service\Mobs\MobMovement.cs" />
<Compile Include="Data\MapSizes.cs" />
<Compile Include="Service\SuperLayers\LandSuperLayerGenerator.cs" />
<Compile Include="Service\SwitchItems.cs" />
@@ -135,6 +135,7 @@ <Compile Include="Data\Crafting\RI.cs" />
<Compile Include="Service\Tiles\ItemPresets\ToolPresets.cs" />
<Compile Include="Service\Tiles\ItemPresets\MaterialPresets.cs" />
+ <Compile Include="Service\SuperLayers\GroundPresets.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Service\" />
diff --git a/Mundus/Service/Mobs/MobMoving.cs b/Mundus/Service/Mobs/MobMovement.cs index 04ce9aa..b043677 100644 --- a/Mundus/Service/Mobs/MobMoving.cs +++ b/Mundus/Service/Mobs/MobMovement.cs @@ -2,7 +2,7 @@ using Mundus.Data.Superlayers.Mobs; namespace Mundus.Service.Mobs { - public static class MobMoving {
+ public static class MobMovement {
public static void MovePlayer(int yPos, int xPos, int size) { ChangePosition(LMI.Player, yPos, xPos, size); }
@@ -22,7 +22,11 @@ namespace Mundus.Service.Mobs { } }
- private static bool Walkable(IMob mob, int yPos, int 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; 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 { + /// <summary> + /// Returns a new instance of the grass ground tile + /// </summary> + /// <returns>New instance of the grass ground tile</returns> + 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; } + /// <summary> + /// Removes 1 health from structure + /// </summary> + /// <returns>If the structure can still be damaged</returns> 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 @@ <child> <widget class="Gtk.Label" id="lblItemLayer"> <property name="MemberName" /> - <property name="LabelProp" translatable="yes">Item Layer</property> + <property name="LabelProp" translatable="yes">Structure Layer</property> </widget> <packing> <property name="TopAttach">9</property> |
