Exemplo n.º 1
0
        public static DropInfo FromLine(string s)
        {
            string[] parts = s.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);

            DropInfo info = new DropInfo();

            if (!int.TryParse(parts[0].Substring(2), out info.Chance)) return null;
            if (string.Compare(parts[1], "Gold", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (parts.Length < 3) return null;
                if (!uint.TryParse(parts[2], out info.Gold) || info.Gold == 0) return null;
            }
            else
            {
                info.Item = SMain.Envir.GetItemInfo(parts[1]);
                if (info.Item == null) return null;

                if (parts.Length > 2)
                {
                    string dropRequirement = parts[2];
                    if (dropRequirement.ToUpper() == "Q") info.QuestRequired = true;
                }
            }

            return info;
        }
Exemplo n.º 2
0
            public static DropInfo FromLine(string s)
            {
                string[] parts = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                DropInfo info = new DropInfo();

                if (!int.TryParse(parts[0].Substring(2), out info.Chance)) return null;
                if (string.Compare(parts[1], "Gold", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    if (parts.Length < 4) return null;
                    if (!uint.TryParse(parts[2], out info.Gold) || info.Gold == 0) return null;
                    if (!byte.TryParse(parts[3], out info.level)) return null;
                }
                else
                {
                    if (parts.Length < 3) return null;
                    info.Item = SMain.Envir.GetItemInfo(parts[1]);
                    if (info.Item == null) return null;
                    if (!byte.TryParse(parts[2], out info.level)) return null;
                }
                return info;
            }
Exemplo n.º 3
0
        public void LoadDrops()
        {
            for (int i = 0; i < Globals.MaxDragonLevel; i++)
            {
                Drops[i].Clear();
            }
            string path = Path.Combine(Settings.DropPath, "DragonItem.txt");

            if (!File.Exists(path))
            {
                string[] contents = new[]
                {
                    ";Pots + Other", string.Empty, string.Empty,
                    ";Weapons", string.Empty, string.Empty,
                    ";Armour", string.Empty, string.Empty,
                    ";Helmets", string.Empty, string.Empty,
                    ";Necklace", string.Empty, string.Empty,
                    ";Bracelets", string.Empty, string.Empty,
                    ";Rings", string.Empty, string.Empty,
                    ";Shoes", string.Empty, string.Empty,
                    ";Belts", string.Empty, string.Empty,
                    ";Stone",
                };

                File.WriteAllLines(path, contents);


                return;
            }

            string[] lines = File.ReadAllLines(path);

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith(";") || string.IsNullOrWhiteSpace(lines[i]))
                {
                    continue;
                }

                DropInfo drop = DropInfo.FromLine(lines[i]);
                if (drop == null)
                {
                    SMain.Enqueue(string.Format("Could not load Drop: DragonItem, Line {0}", lines[i]));
                    continue;
                }

                if (drop.level <= 0 || drop.level > Globals.MaxDragonLevel)
                {
                    return;
                }
                Drops[drop.level - 1].Add(drop);
            }

            for (int i = 0; i < Globals.MaxDragonLevel; i++)
            {
                Drops[i].Sort((drop1, drop2) =>
                {
                    if (drop1.Gold > 0 && drop2.Gold == 0)
                    {
                        return(1);
                    }
                    if (drop1.Gold == 0 && drop2.Gold > 0)
                    {
                        return(-1);
                    }

                    return(drop1.Item.Type.CompareTo(drop2.Item.Type));
                });
            }
        }
Exemplo n.º 4
0
        public static void Load(List <DropInfo> list, string name, string path, byte type = 0, bool createIfNotExists = true)
        {
            if (!File.Exists(path))
            {
                if (createIfNotExists)
                {
                    string[] contents = new[]
                    {
                        ";Pots + Other", string.Empty, string.Empty,
                        ";Weapons", string.Empty, string.Empty,
                        ";Armour", string.Empty, string.Empty,
                        ";Helmets", string.Empty, string.Empty,
                        ";Necklace", string.Empty, string.Empty,
                        ";Bracelets", string.Empty, string.Empty,
                        ";Rings", string.Empty, string.Empty,
                        ";Shoes", string.Empty, string.Empty,
                        ";Belts", string.Empty, string.Empty,
                        ";Stone",
                    };

                    File.WriteAllLines(path, contents);
                }

                return;
            }

            var lines = File.ReadAllLines(path).ToList();

            lines = ParseInsert(lines);

            for (int i = 0; i < lines.Count; i++)
            {
                if (lines[i].StartsWith(";") || string.IsNullOrWhiteSpace(lines[i]))
                {
                    continue;
                }

                DropInfo drop = DropInfo.FromLine(lines[i]);

                if (drop == null)
                {
                    MessageQueue.Enqueue(string.Format("Could not load Drop: {0}, Line {1}", name, lines[i]));
                    continue;
                }

                if (drop.GroupedDrop != null)
                {
                    ParseGroup(drop, name, lines, i + 1);
                }

                drop.Type = type;

                list.Add(drop);
            }

            list.Sort((drop1, drop2) =>
            {
                if (drop1.Gold > 0 && drop2.Gold == 0)
                {
                    return(1);
                }
                if (drop1.Gold == 0 && drop2.Gold > 0)
                {
                    return(-1);
                }

                if (drop1.Item == null || drop2.Item == null)
                {
                    return(0);
                }

                return(drop1.Item.Type.CompareTo(drop2.Item.Type));
            });
        }