Пример #1
0
        private void ProcessQIKey(string key, int pos, string line, bool force = false)
        {
            Regex           myRegex = null;
            MatchCollection mc = null;
            Match           m = null;
            int             j, k;

            switch (key)
            {
            case "level":
                if (force || Level < 1)
                {
                    k = line.Length - 1;
                    while (Char.IsDigit(line[k]))
                    {
                        k--;
                    }
                    Level = Helper.ParseInt(line.Substring(k + 1));
                }
                break;

            case "requires":
                if (force || RequiredLevel < 1)
                {
                    k = line.Length - 1;
                    while (Char.IsDigit(line[k]))
                    {
                        k--;
                    }
                    Level = Helper.ParseInt(line.Substring(k + 1));
                }
                break;

            case "loremaster":
                Loremaster = true;
                break;

            case "side":
                if (force || (int)Side == -1)
                {
                    myRegex = new Regex(@"](?<side>\w+)\[", RegexOptions.Compiled);
                    mc      = myRegex.Matches(line);

                    m = mc.Count > 0 ? mc[0] : null;
                    if (m == null || !m.Success)
                    {
                        line = line.Substring(pos + 1).Trim();
                    }
                    else
                    {
                        line = m.Groups["side"].Value;
                    }
                    Side _dside = (Wowhead.Side)(-1);

                    if (!Enum.TryParse(line, true, out _dside))
                    {
                        Helper.LogDebug("Can't parse QI Side[" + Id + "]:" + line);
                    }
                    else
                    {
                        Side = _dside;
                    }
                }
                break;

            case "[icon":
                myRegex = new Regex(@"](?<key>\w+):\s*\[(url=/)?(?<type>\w*)=(?<id>\d+)]", RegexOptions.Compiled);
                mc      = myRegex.Matches(line);

                m = mc.Count > 0 ? mc[0] : null;
                if (m == null || !m.Success)
                {
                    Helper.LogDebug("Can't parse QI Icon[" + Id + "]:" + line);
                }

                Group             gKey     = m.Groups["key"];
                CaptureCollection gTypeCap = m.Groups["type"].Captures;
                CaptureCollection gIdCap   = m.Groups["id"].Captures;
                for (j = 0; j < gKey.Captures.Count; j++)
                {
                    Capture c = gKey.Captures[j];

                    switch (c.Value.ToLower())
                    {
                    case "start":
                        QuestGiver = Helper.GetInteractEntity(Helper.ParseInt(gIdCap[j].Value), gTypeCap[j].Value);
                        break;

                    case "end":
                        QuestTurnIn = Helper.GetInteractEntity(Helper.ParseInt(gIdCap[j].Value), gTypeCap[j].Value);
                        break;

                    default:
                        Helper.LogDebug("Unknown QI line[" + Id + "]:" + line);
                        break;
                    }
                }

                break;

            case "not":
                line = line.Substring(3).Trim().ToLower();
                if (line == "sharable")
                {
                    Sharable = false;
                }
                else
                {
                    Helper.LogDebug("Unknown sub 'not' key[" + Id + "]:" + line);
                }
                break;

            case "difficulty":
                myRegex = new Regex(@"r(?<d>\d)](?<level>\d+)\[", RegexOptions.Compiled);
                mc      = myRegex.Matches(line);

                for (j = 0; j < mc.Count; j++)
                {
                    if (!mc[j].Success)
                    {
                        Helper.LogDebug("Can't parse QI difficulty[" + Id + "]:" + line);
                    }

                    Group             gIdx      = mc[j].Groups["d"];
                    CaptureCollection gLevelCap = mc[j].Groups["level"].Captures;

                    pos             = Helper.ParseInt(gIdx.Captures[0].Value) - 1;
                    Difficulty[pos] = Helper.ParseInt(gLevelCap[0].Value);
                }
                break;

            case "added":
                k = line.Length - 1;
                while (Char.IsDigit(line[k]) || line[k] == '.')
                {
                    k--;
                }
                AddedIn = line.Substring(k + 1);
                break;

            case "type":
                string    lt = line.Substring("Type:".Length).Trim();
                QuestType qt = (QuestType)(-1);
                if (!Enum.TryParse(lt, out qt))
                {
                    Helper.LogDebug("Unknown QI Type [" + Id + "]:" + lt);
                }
                else
                if (force || Type == QuestType.Normal)
                {
                    Type = qt;
                }
                break;

            case "race":
            case "races":
                if (force || _races == null)
                {
                    myRegex = new Regex(@"=(?<id>\d+)", RegexOptions.Compiled);
                    mc      = myRegex.Matches(line);
                    _races  = new List <Race>();

                    for (j = 0; j < mc.Count; j++)
                    {
                        if (!mc[j].Success)
                        {
                            Helper.LogDebug("Can't parse QI Races[" + Id + "]:" + line);
                        }

                        _races.Add(Race.GetById(Helper.ParseInt(mc[j].Groups["id"].Captures[0].Value)));
                    }
                }
                break;

            case "class":
                if (force || _classes == null)
                {
                    myRegex  = new Regex(@"=(?<id>\d+)", RegexOptions.Compiled);
                    mc       = myRegex.Matches(line);
                    _classes = new List <wClass>();

                    for (j = 0; j < mc.Count; j++)
                    {
                        if (!mc[j].Success)
                        {
                            Helper.LogDebug("Can't parse QI Races[" + Id + "]:" + line);
                        }

                        _classes.Add(wClass.GetById(Helper.ParseInt(mc[j].Groups["id"].Captures[0].Value)));
                    }
                }
                break;

            case "sharable":     // by default - sharable
                break;

            default:
                Helper.LogDebug("Unknown key[" + Id + "]:" + key);
                break;
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="capKeys"></param>
        /// <param name="capVals"></param>
        /// <param name="sid">Just for Logger</param>
        private void ParseFoundProperties(CaptureCollection capKeys, CaptureCollection capVals, string sid)
        {
            for (int i = 0; i < capKeys.Count; i++)
            {
                Capture capKey = capKeys[i];
                Capture capVal = capVals[i];

                switch (capKey.Value)
                {
                case "category":
                    _categoryId = Helper.ParseInt(capVal.Value);
                    break;

                case "category2":
                    _category2Id = Helper.ParseInt(capVal.Value);
                    break;

                case "level":
                    Level = Helper.ParseInt(capVal.Value);
                    break;

                case "name":
                    Name = Helper.ParseString(capVal.Value);
                    break;

                case "reqlevel":
                    RequiredLevel = Helper.ParseInt(capVal.Value);
                    break;

                case "side":
                    Side = (Side)Helper.ParseInt(capVal.Value);
                    break;

                case "wflags":
                    wflags = Helper.ParseInt(capVal.Value);
                    break;

                case "reqrace":
                    _races = Race.ParseFlags(Helper.ParseInt(capVal.Value));
                    break;

                case "reqclass":
                    _classes = wClass.ParseFlags(Helper.ParseInt(capVal.Value));
                    break;

                case "type":
                    int t = Helper.ParseInt(capVal.Value);
                    if (!Enum.IsDefined(typeof(QuestType), t))
                    {
                        Helper.LogDebug("Unknown Type [" + (Id == 0 ? sid : Id.ToString()) + "]:" + capVal.Value);
                    }
                    else
                    {
                        Type = (QuestType)t;
                    }

                    break;

                case "id":
                    if (Id == 0)
                    {
                        Id = Helper.ParseInt(capVal.Value);
                    }
                    break;

                case "money":
                case "xp":
                case "reprewards":
                case "itemrewards":
                case "itemchoices":
                case "currencyrewards":
                case "race":                         // same as reqrace
                case "classs":                       // same as reqclass
                    break;

                default:
                    Helper.LogDebug("Unknown property[" + (Id == 0 ? sid : Id.ToString()) + "]:" + capKey.Value);
                    break;
                }
            }
        }