diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-04-09 10:44:13 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-04-09 10:44:13 +0300 |
| commit | 685f6a12c7c7ea05a390532f94cd5a755d12291e (patch) | |
| tree | 82eb54fb3a3229c462a9b0b91c7568f1ff2aa86e | |
| parent | 55bd30cf68f36021ffe159a147fd43792d229512 (diff) | |
| download | Mundus-685f6a12c7c7ea05a390532f94cd5a755d12291e.tar Mundus-685f6a12c7c7ea05a390532f94cd5a755d12291e.tar.gz Mundus-685f6a12c7c7ea05a390532f94cd5a755d12291e.zip | |
GroundTile is now an item tile. When breaking ground, you get the ground tile. Refactored and restructured mob terraforming code. Updated execuatable.
| -rw-r--r-- | Mundus Build 09-04-2020 No1.exe (renamed from Mundus Build 08-04-2020 No3.exe) | bin | 539648 -> 540160 bytes | |||
| -rw-r--r-- | Mundus/Mundus.csproj | 2 | ||||
| -rw-r--r-- | Mundus/Service/Inventory.cs | 13 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/MobTerraforming.cs | 162 | ||||
| -rw-r--r-- | Mundus/Service/SuperLayers/GroundPresets.cs | 2 | ||||
| -rw-r--r-- | Mundus/Service/SwitchItems.cs | 2 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/GroundTile.cs | 18 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/ItemPresets/MaterialPresets.cs | 4 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Items/GroundTile.cs | 19 | ||||
| -rw-r--r-- | Mundus/Service/Tiles/Items/Structure.cs | 2 | ||||
| -rw-r--r-- | Mundus/Views/Windows/SmallGameWindow.cs | 10 |
11 files changed, 123 insertions, 111 deletions
diff --git a/Mundus Build 08-04-2020 No3.exe b/Mundus Build 09-04-2020 No1.exe Binary files differindex 6629492..3ca324a 100644 --- a/Mundus Build 08-04-2020 No3.exe +++ b/Mundus Build 09-04-2020 No1.exe 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 @@ <Compile Include="gtk-gui\Mundus.Views.Windows.MainWindow.cs" />
<Compile Include="Views\Dialogs\ExitDialog.cs" />
<Compile Include="gtk-gui\Mundus.Views.Dialogs.ExitDialog.cs" />
- <Compile Include="Service\Tiles\GroundTile.cs" />
<Compile Include="Service\Tiles\ITile.cs" />
<Compile Include="Service\Mobs\IMob.cs" />
<Compile Include="Service\Tiles\MobTile.cs" />
@@ -143,6 +142,7 @@ <Compile Include="Service\SuperLayers\Generators\LandSuperLayerGenerator.cs" />
<Compile Include="Service\SuperLayers\Generators\UndergroundSuperLayerGenerator.cs" />
<Compile Include="Service\Tiles\ItemPresets\StructurePresets.cs" />
+ <Compile Include="Service\Tiles\Items\GroundTile.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Service\" />
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 @@ } /// <summary> - /// Removes 1 health from structure + /// Removes health from structure /// </summary> /// <returns>If the structure can still be damaged</returns> 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(); } |
