aboutsummaryrefslogtreecommitdiff
path: root/Mundus/Service/Mobs/MobTerraforming.cs
blob: e80f7cb5768a2892c8027d20273e4aa9bf4fc3da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Mundus.Data.Superlayers.Mobs;
using Mundus.Data.SuperLayers;
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) {
            if (LMI.Player.Inventory.GetTile(place, index).GetType() == typeof(Tool)) {
                var selTool = (Tool)LMI.Player.Inventory.GetTile(place, index);
                if (LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos).ReqToolType == selTool.Type &&
                    LMI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos).ReqToolClass == selTool.Class) {
                    LMI.Player.CurrSuperLayer.SetStructureAtPosition(null, mapYPos, mapXPos);
                }
            }
        }

        public static void PlayerBuildAt(int mapYPos, int mapXPos, string inventoryPlace, int inventoryPlaceIndex) {
            if (PlayerCanBuildAt(mapYPos, mapXPos)) {
                Structure toPlace = null;

                switch (inventoryPlace) {
                    case "hotbar": toPlace = (Structure)LMI.Player.Inventory.Hotbar[inventoryPlaceIndex]; break;
                    case "items": toPlace = (Structure)LMI.Player.Inventory.Items[inventoryPlaceIndex]; break;
                }

                if (toPlace != null) {
                    PlayerBuildAt(mapYPos, mapXPos, toPlace);
                }
            }
        }

        public static void PlayerBuildAt(int mapYPos, int mapXPos, Structure toPlace) {
            LMI.Player.CurrSuperLayer.SetStructureAtPosition(toPlace, mapYPos, mapXPos);
        }

        public static void TryPlaceStructure(ISuperLayer superLayer, int yPos, int xPos, Structure toPlace) {
            if (superLayer.GetStructureLayerTile(yPos, xPos) != null) {
                superLayer.SetStructureAtPosition(toPlace, yPos, xPos);
            }
        }

        public static bool PlayerCanBuildAt(int yPos, int xPos) {
            return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) == null;
        }

        public static bool PlayerCanDestroyAt(int yPos, int xPos) {
            return LMI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) != null;
        }
    }
}