aboutsummaryrefslogtreecommitdiff
path: root/Mundus/Service/Tiles/Mobs/Inventory.cs
blob: ae4f141a4e73e162e74a79bfec69114964356740 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using Mundus.Service.Tiles.Items;
using Mundus.Service.Tiles.Items.Types;
using System;
using System.Linq;

namespace Mundus.Service.Tiles.Mobs {
    public class Inventory {
        public enum InventoryPlace {
            Hotbar,
            Items,
            Accessories,
            Gear
        }

        /// <summary>
        /// Has a size of "Screen and Inventory" and can hold Tools, Materials, Structures and Gear
        /// </summary>
        public ItemTile[] Hotbar { get; set; }
        /// <summary>
        /// Has a size of the "Screen and Inventory" squared and can hold Tools, Materials, Structures and Gear
        /// </summary>
        public ItemTile[] Items { get; set; }
        /// <summary>
        /// Has a size of double the "Screen and Inventory" and can only hold Gear
        /// </summary>
        public Gear[] Accessories { get; set; }
        /// <summary>
        /// Has a size of "Screen and Inventory" and can only hold Gear
        /// </summary>
        public Gear[] Gear { get; set; }

        public Inventory(int screenInvSize) {
            this.SetSizes(screenInvSize);
        }

        public void SetSizes(int screenInvSize) {
            this.Hotbar = new ItemTile[screenInvSize];
            this.Items = new ItemTile[screenInvSize * screenInvSize];
            this.Accessories = new Gear[screenInvSize * 2];
            this.Gear = new Gear[screenInvSize];
        }

        public void AppendToHotbar(ItemTile itemTile) {
            this.AddToHotbar(itemTile, Array.IndexOf(this.Hotbar, this.Hotbar.First(x => x == null)));
        }

        public void AddToHotbar(ItemTile itemTile, int index) {
            this.Hotbar[index] = itemTile;
        }

        public void DeleteFromHotbar(int index) {
            this.Hotbar[index] = null;
        }

        public void AppendToItems(ItemTile itemTile) {
            this.AddToItems(itemTile, Array.IndexOf(this.Items, this.Items.First(x => x == null)));
        }

        public void AddToItems(ItemTile itemTile, int index) {
            this.Items[index] = itemTile;
        }

        public void DeleteFromItems(int index) {
            this.Items[index] = null;
        }

        public void EquipAccessory(Gear accessory, int index) {
            this.Accessories[index] = accessory;
        }

        public void AppendAccessories(Gear accessory) {
            this.EquipAccessory(accessory, Array.IndexOf(this.Accessories, this.Accessories.First(x => x == null)));
        }

        public void DeleteAccessory(int index) {
            this.Accessories[index] = null;
        }

        public void EquipGear(Gear gear, int index) {
            this.Gear[index] = gear;
        }

        public void AppendGear(Gear gear) {
            this.EquipGear(gear, Array.IndexOf(this.Gear, this.Gear.First(x => x == null)));
        }

        public void DeleteGear(int index) {
            this.Gear[index] = null;
        }

        /// <summary>
        /// Returns an ItemTile depending on specified place ("hotbar", "items", "accessories" or "gear")
        /// and specified index
        /// </summary>
        public ItemTile GetItemTile(InventoryPlace place, int index) {
            ItemTile toReturn = null;

            switch (place) {
                case InventoryPlace.Hotbar: toReturn = this.Hotbar[index]; break;
                case InventoryPlace.Items: toReturn = this.Items[index]; break;
                case InventoryPlace.Accessories: toReturn = this.Accessories[index]; break;
                case InventoryPlace.Gear: toReturn = this.Gear[index]; break;
            }
            return toReturn;
        }

        /// <summary>
        /// Deletes an ItemTile depending on specified place ("hotbar", "items", "accessories" or "gear")
        /// and specified index
        /// </summary>
        public static void DeletePlayerItemTileFromItemSelection() {
            Data.Superlayers.Mobs.MI.Player.Inventory.DeleteItem(ItemController.SelItemPlace, ItemController.SelItemIndex);
        }

        /// <summary>
        /// Returns an ItemTile depending on specified place ("hotbar", "items", "accessories" or "gear")
        /// and specified index in player's inventory
        /// </summary>
        public static ItemTile GetPlayerItemFromItemSelection() {
            return Data.Superlayers.Mobs.MI.Player.Inventory.GetItemTile(ItemController.SelItemPlace, ItemController.SelItemIndex);
        }

        public void DeleteItem(InventoryPlace place, int index) {
            switch (place) {
                case InventoryPlace.Hotbar: this.Hotbar[index] = null; break;
                case InventoryPlace.Items: this.Items[index] = null; break;
                case InventoryPlace.Accessories: this.Accessories[index] = null; break;
                case InventoryPlace.Gear: this.Gear[index] = null; break;
            }
        }
    }
}