Exemplo n.º 1
0
 public override void OnEnable()
 {
     playedSoundsCache = new HashSet <long>();
     currentAlerts     = new Dictionary <EntityWrapper, AlertDrawStyle>();
     currencyNames     = LoadCurrency("config/currency.txt");
     craftingBases     = CraftingBase.LoadFromFile("config/crafting_bases.txt");
 }
Exemplo n.º 2
0
        private ItemUsefulProperties initItem(IEntity item)
        {
            BaseItemType bit = GameController.Files.BaseItemTypes.Translate(item.Path);

            if (bit == null)
            {
                return(null);
            }
            string       name         = bit.BaseName;
            CraftingBase craftingBase = new CraftingBase();

            if (Settings.Crafting)
            {
                foreach (CraftingBase cb in craftingBases
                         .Where(cb => cb.Name
                                .Equals(name, StringComparison.InvariantCultureIgnoreCase) || new Regex(cb.Name)
                                .Match(name).Success))
                {
                    craftingBase = cb;
                    break;
                }
            }

            return(new ItemUsefulProperties(name, item, craftingBase));
        }
Exemplo n.º 3
0
        private static HashSet <CraftingBase> LoadCraftingBases()
        {
            if (!File.Exists("config/crafting_bases.txt"))
            {
                return(new HashSet <CraftingBase>());
            }
            var hashSet     = new HashSet <CraftingBase>();
            var parseErrors = new List <string>();

            string[] array = File.ReadAllLines("config/crafting_bases.txt");
            foreach (string text in array.Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith("#")))
            {
                string[] parts    = text.Split(',');
                string   itemName = parts[0].Trim();

                var item = new CraftingBase {
                    Name = itemName
                };

                int tmpVal;
                if (parts.Length > 1 && int.TryParse(parts[1], out tmpVal))
                {
                    item.MinItemLevel = tmpVal;
                }

                if (parts.Length > 2 && int.TryParse(parts[2], out tmpVal))
                {
                    item.MinQuality = tmpVal;
                }

                const int RARITY_POSITION = 3;
                if (parts.Length > RARITY_POSITION)
                {
                    item.Rarities = new ItemRarity[parts.Length - 3];
                    for (int i = RARITY_POSITION; i < parts.Length; i++)
                    {
                        if (item.Rarities != null && !Enum.TryParse(parts[i], true, out item.Rarities[i - RARITY_POSITION]))
                        {
                            parseErrors.Add("Incorrect rarity definition at line: " + text);
                            item.Rarities = null;
                        }
                    }
                }

                if (!hashSet.Add(item))
                {
                    parseErrors.Add("Duplicate definition for item was ignored: " + text);
                }
            }

            if (parseErrors.Any())
            {
                throw new Exception("Error parsing config/crafting_bases.txt\r\n" + string.Join(Environment.NewLine, parseErrors));
            }

            return(hashSet);
        }
Exemplo n.º 4
0
        private ItemUsefulProperties initItem(IEntity item)
        {
            string name = GameController.Files.BaseItemTypes.Translate(item.Path);

            CraftingBase craftingBase = new CraftingBase();

            if (Settings.Crafting)
            {
                craftingBases.TryGetValue(name, out craftingBase);
            }

            return(new ItemUsefulProperties(name, item, craftingBase));
        }
Exemplo n.º 5
0
        private ItemUsefulProperties initItem(IEntity item)
        {
            string name = GameController.Files.BaseItemTypes.Translate(item.Path).BaseName;

            CraftingBase craftingBase = new CraftingBase();

            if (Settings.Crafting)
            {
                foreach (KeyValuePair <string, CraftingBase> cb in craftingBases)
                {
                    if (cb.Key.Equals(name) ||
                        (new Regex(cb.Value.Name)).Match(name).Success)
                    {
                        craftingBase = cb.Value;
                        break;
                    }
                }
            }

            return(new ItemUsefulProperties(name, item, craftingBase));
        }
 public ItemUsefulProperties(string name, IEntity item, CraftingBase craftingBase)
 {
     _name         = name;
     _item         = item;
     _craftingBase = craftingBase;
 }
Exemplo n.º 7
0
 public ItemUsefulProperties(string name, IEntity item, CraftingBase craftingBase)
 {
     _name = name;
     _item = item;
     _craftingBase = craftingBase;
 }
Exemplo n.º 8
0
        private Dictionary <string, CraftingBase> LoadCraftingBases()
        {
            if (!File.Exists("config/crafting_bases.txt"))
            {
                return(new Dictionary <string, CraftingBase>());
            }
            Dictionary <string, CraftingBase> dictionary = new Dictionary <string, CraftingBase>(StringComparer.OrdinalIgnoreCase);
            List <string> parseErrors = new List <string>();

            string[] array = File.ReadAllLines("config/crafting_bases.txt");
            foreach (
                string text2 in
                array.Select(text => text.Trim()).Where(text2 => !string.IsNullOrWhiteSpace(text2) && !text2.StartsWith("#")))
            {
                string[] parts    = text2.Split(new[] { ',' });
                string   itemName = parts[0].Trim();

                CraftingBase item = new CraftingBase()
                {
                    Name = itemName
                };

                int tmpVal = 0;
                if (parts.Length > 1 && int.TryParse(parts[1], out tmpVal))
                {
                    item.MinItemLevel = tmpVal;
                }

                if (parts.Length > 2 && int.TryParse(parts[2], out tmpVal))
                {
                    item.MinQuality = tmpVal;
                }

                const int RarityPosition = 3;
                if (parts.Length > RarityPosition)
                {
                    item.Rarities = new ItemRarity[parts.Length - 3];
                    for (int i = RarityPosition; i < parts.Length; i++)
                    {
                        if (!Enum.TryParse(parts[i], true, out item.Rarities[i - RarityPosition]))
                        {
                            parseErrors.Add("Incorrect rarity definition at line: " + text2);
                            item.Rarities = null;
                        }
                    }
                }

                if (!dictionary.ContainsKey(itemName))
                {
                    dictionary.Add(itemName, item);
                }
                else
                {
                    parseErrors.Add("Duplicate definition for item was ignored: " + text2);
                }
            }

            if (parseErrors.Any())
            {
                throw new Exception("Error parsing config/crafting_bases.txt \r\n" + string.Join(Environment.NewLine, parseErrors) + Environment.NewLine + Environment.NewLine);
            }

            return(dictionary);
        }
Exemplo n.º 9
0
 public void SetCraftingBase(CraftingBase craftingBase)
 {
     isCraftingBase = itemLevel >= craftingBase.MinItemLevel &&
                      quality >= craftingBase.MinQuality &&
                      (craftingBase.Rarities == null || craftingBase.Rarities.Contains(rarity));
 }