Beispiel #1
0
 public InventoryItem getItem(int index)
 {
     if (!items.ContainsKey(index))
     {
         return(new InventoryItem(0));
     }
     return(items[index]);
 }
        public void WriteItems(TextAsset textAsset)
        {
            if (textAsset == null)
            {
                return;
            }

            using (var reader = new StringReader(textAsset.text))
            {
                int    lineNum = 0;
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var split = line.Split(',');
                    if (split.Length < 3 || split.Length > 4)
                    {
                        Debug.LogError($"Error in syntax at line {lineNum} reading item from asset {textAsset.name}!");
                        continue;
                    }

                    var x    = Convert.ToInt32(split[0]);
                    var y    = Convert.ToInt32(split[1]);
                    var name = split[2];

                    var pos = new int2(x, y);

                    if (ItemMap.ContainsKey(pos))
                    {
                        Debug.LogError($"Error reading position at line {lineNum} reading item from asset {textAsset.name}. It already exist!");
                        continue;
                    }
                    ItemMap.Add(pos, name);

                    if (split.Length == 4 && ItemSpecialsMap.ContainsKey(pos) == false)
                    {
                        var special = split[3];
                        ItemSpecialsMap.Add(pos, special);
                    }

                    lineNum++;
                }
            }
        }
Beispiel #3
0
 private bool HasItem(PlayerItems item) => ItemMap.ContainsKey(item);
Beispiel #4
0
 public bool ItemExists(string itemID)
 {
     return(ItemMap.ContainsKey(itemID));
 }