Exemplo n.º 1
0
        /// <summary>
        /// 取得並分析POE倉庫頁面中所有物品的資訊
        /// </summary>
        /// <param name="length">倉庫頁的大小,12或24,由於本人沒有24*24倉庫頁,因此24未完成</param>
        public async void GetWarehouse(int length = 12)
        {
            await Task.Delay(0);

            Items.Clear();
            used.Clear();
            resoult.Clear();

            string reg_itemlevel = @"物品等級:\s(\d+)", reg_itemlevel_eng = @"Item Level:\s(\d+)";
            string reg_quality = @"品質:\s\+(\d+)", reg_quality_eng = @"Quality:\s\+(\d+)";
            string reg_level = @"(?<!需求:)\r\n^等級:\s(\d+)", reg_level_eng = @"(?<!Requirements:)\r\n^Level:\s(\d+)";
            string reg_maplevel = @"地圖階級:\s(\d+)", reg_maplevel_eng = @"Map Tier:\s(\d+)";


            Regex r_itemlevel     = new Regex(reg_itemlevel, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_itemlevel_eng = new Regex(reg_itemlevel_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            Regex r_quality       = new Regex(reg_quality, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_quality_eng   = new Regex(reg_quality_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            Regex r_level         = new Regex(reg_level, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_level_eng     = new Regex(reg_level_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            Regex r_maplevel      = new Regex(reg_maplevel, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_maplevel_eng  = new Regex(reg_maplevel_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);

            Regex r = new Regex(reg, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            Match m, m_itemlevel, m_quality, m_level, m_maplevel;
            int   id = 0;

            for (int x = 0; x < length; x++)
            {
                for (int y = 0; y < length; y++)
                {
                    if (Stop)
                    {
                        DrawBoxRegion(Items, length, 1);
                        return;
                    }
                    if (used.Any(u => u.X == x && u.Y == y))
                    {
                        continue;
                    }
                    Clipboard.Clear();
                    if (length == 12)
                    {
                        POE_GetItemInfo((int)(startPos1.X + cellWidth1 * x), (int)(startPos1.Y + cellHeight1 * y));
                    }
                    else
                    {
                        POE_GetItemInfo((int)(startPos4.X + cellWidth4 * x), (int)(startPos4.Y + cellHeight4 * y));
                    }

                    string clip = Clipboard.GetText(TextDataFormat.UnicodeText);
                    if (clip == "")
                    {
                        clip = Clipboard.GetText(TextDataFormat.UnicodeText);
                    }
                    if (clip == "")
                    {
                        continue;
                    }

                    m = r.Match(clip);

                    Item temp = new Item();
                    if (m.Groups[3].ToString() == "")
                    {
                        temp.Name = PrivateFunction.GetStringAfterSomething(m.Groups[2].ToString().Trim(), "」");
                    }
                    else
                    {
                        if (m.Groups[1].ToString() == "傳奇" || m.Groups[1].ToString() == "Unique")
                        {
                            temp.Name = m.Groups[2].ToString().Trim() + " " + m.Groups[3].ToString().Trim();
                        }
                        else
                        {
                            temp.Name = m.Groups[3].ToString().Trim();
                        }
                    }

                    temp.Rarity    = m.Groups[1].ToString().Trim();
                    m_itemlevel    = r_itemlevel.Match(m.Groups[4].ToString());
                    m_itemlevel    = m_itemlevel.Groups.Count == 1 ? r_itemlevel_eng.Match(m.Groups[4].ToString()) : m_itemlevel;
                    m_level        = r_level.Match(m.Groups[4].ToString());
                    m_level        = m_level.Groups.Count == 1 ? r_level_eng.Match(m.Groups[4].ToString()) : m_level;
                    m_maplevel     = r_maplevel.Match(m.Groups[4].ToString());
                    m_maplevel     = m_maplevel.Groups.Count == 1 ? r_maplevel_eng.Match(m.Groups[4].ToString()) : m_maplevel;
                    m_quality      = r_quality.Match(m.Groups[4].ToString());
                    m_quality      = m_quality.Groups.Count == 1 ? r_quality_eng.Match(m.Groups[4].ToString()) : m_quality;
                    temp.itemlevel = m_itemlevel.Groups.Count == 1 ? 0 : int.Parse(m_itemlevel.Groups[1].ToString());
                    temp.level     = m_level.Groups.Count == 1 ? 0 : int.Parse(m_level.Groups[1].ToString());
                    temp.quality   = m_quality.Groups.Count == 1 ? 0 : int.Parse(m_quality.Groups[1].ToString());
                    temp.maplevel  = m_maplevel.Groups.Count == 1 ? 0 : int.Parse(m_maplevel.Groups[1].ToString());

                    Data t;
                    if (m.Groups[1].ToString() == "傳奇" || m.Groups[1].ToString() == "Unique")
                    {
                        t = ItemList_Unique.Where(a => a.Name_Chinese.EndsWith(PrivateFunction.GetStringAfterSomething(temp.Name, "」")) ||
                                                  PrivateFunction.GetStringAfterSomething(temp.Name, "」").StartsWith(a.Name_English) ||
                                                  PrivateFunction.GetStringAfterSomething(temp.Name, "」").Contains(a.Name_English)
                                                  ).FirstOrDefault();
                    }
                    else
                    {
                        t = ItemList.Where(a => temp.Name.Equals(a.Name_Chinese) || temp.Name.Equals(a.Name_English)).FirstOrDefault();
                        if (t == null)
                        {
                            t = ItemList.Where(a => temp.Name.EndsWith(a.Name_Chinese) || temp.Name.EndsWith(a.Name_English)).FirstOrDefault();
                        }
                        if (t == null)
                        {
                            t = ItemList.Where(a => temp.Name.Contains(a.Name_English)).FirstOrDefault();
                        }
                    }
                    if (t == null)
                    {
                        t = ItemList_Adden.Where(a => a.Name_Chinese.EndsWith(PrivateFunction.GetStringAfterSomething(temp.Name, "」")) || a.Name_English.StartsWith(PrivateFunction.GetStringAfterSomething(temp.Name, "」"))).FirstOrDefault();
                    }

                    while (t == null)
                    {
                        Form2 f = new Form2(clip, temp.Name);
                        f.ShowDialog();
                        var databasePath = Path.Combine(Application.StartupPath, "Datas_Adden.db");
                        var db           = new SQLiteAsyncConnection(databasePath);
                        await db.CreateTableAsync <Data>();

                        await db.CreateIndexAsync("Data", "Name_Chinese");

                        await db.CreateIndexAsync("Data", "Name_English");

                        ItemList_Adden = await db.Table <Data>().ToListAsync();

                        await db.CloseAsync();

                        t = ItemList_Adden.Where(a => temp.Name.Equals(a.Name_Chinese) || temp.Name.Equals(a.Name_English)).FirstOrDefault();
                    }
                    temp.w        = t.Width;
                    temp.h        = t.Height;
                    temp.point    = new POINT(x, y);
                    temp.url      = t.ImageURL;
                    temp.GC       = t.GemColor.ToCharArray()[0];
                    temp.Name_eng = t.Name_English;
                    temp.type     = t.Type;

                    temp.priority = Array.IndexOf(Config.Species, t.Type);

                    temp.id = ++id;

                    for (int i = x; i < x + t.Width; i++)
                    {
                        for (int j = y; j < y + t.Height; j++)
                        {
                            used.Add(new POINT(i, j));
                        }
                    }
                    Items.Add(temp);
                }
            }
            DrawBoxRegion(Items, length, 1);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 取得並分析POE倉庫頁面中所有物品的資訊
        /// </summary>
        /// <param name="length">倉庫頁的大小,12或24,由於本人沒有24*24倉庫頁,因此24未完成</param>
        public async void GetWarehouse(int length = 12)
        {
            await Task.Delay(0);

            Items.Clear();
            used.Clear();
            resoult.Clear();

            //可能需要英文化
            string reg_itemlevel = @"物品等級:\s(\d+)", reg_itemlevel_eng = @"Item Level:\s(\d+)";
            string reg_quality = @"品質:\s\+(\d+)", reg_quality_eng = @"Quality:\s\+(\d+)";
            string reg_level = @"(?<!需求:)\r\n^等級:\s(\d+)", reg_level_eng = @"(?<!Requirements:)\r\n^Level:\s(\d+)";
            string reg_maplevel = @"地圖階級:\s(\d+)", reg_maplevel_eng = @"Map Tier:\s(\d+)";


            Regex r_itemlevel     = new Regex(reg_itemlevel, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_itemlevel_eng = new Regex(reg_itemlevel_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            Regex r_quality       = new Regex(reg_quality, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_quality_eng   = new Regex(reg_quality_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            Regex r_level         = new Regex(reg_level, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_level_eng     = new Regex(reg_level_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);
            Regex r_maplevel      = new Regex(reg_maplevel, RegexOptions.IgnoreCase | RegexOptions.Multiline),
                  r_maplevel_eng  = new Regex(reg_maplevel_eng, RegexOptions.IgnoreCase | RegexOptions.Multiline);

            Regex r = new Regex(reg, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            Match m, m_itemlevel, m_quality, m_level, m_maplevel;
            int   id = 0;

            for (int x = 0; x < length; x++)
            {
                for (int y = 0; y < length; y++)
                {
                    if (Stop)
                    {
                        DrawBoxRegion(Items, length, 1);
                        return;
                    }
                    if (used.Any(u => u.X == x && u.Y == y))
                    {
                        continue;
                    }
                    Clipboard.Clear();
                    if (length == 12)
                    {
                        POE_GetItemInfo((int)(startPos1.X + cellWidth1 * x), (int)(startPos1.Y + cellHeight1 * y));
                    }
                    else
                    {
                        POE_GetItemInfo((int)(startPos4.X + cellWidth4 * x), (int)(startPos4.Y + cellHeight4 * y));
                    }

                    string clip = Clipboard.GetText(TextDataFormat.UnicodeText);
                    if (clip == "")
                    {
                        clip = Clipboard.GetText(TextDataFormat.UnicodeText);
                    }
                    if (clip == "")
                    {
                        continue;
                    }

                    m = r.Match(clip);

                    Item temp = new Item();
                    if (m.Groups[3].ToString() == "")
                    {
                        temp.Name = PrivateFunction.GetStringAfterSomething(m.Groups[2].ToString().Trim(), "」");
                    }
                    else
                    {
                        if (m.Groups[1].ToString() == "傳奇" || m.Groups[1].ToString() == "Unique")
                        {
                            temp.Name = m.Groups[2].ToString().Trim() + " " + m.Groups[3].ToString().Trim();
                        }
                        else
                        {
                            temp.Name = m.Groups[3].ToString().Trim();
                        }
                    }

                    temp.Rarity    = m.Groups[1].ToString().Trim();
                    m_itemlevel    = r_itemlevel.Match(m.Groups[4].ToString());
                    m_itemlevel    = m_itemlevel.Groups.Count == 1 ? r_itemlevel_eng.Match(m.Groups[4].ToString()) : m_itemlevel;
                    m_level        = r_level.Match(m.Groups[4].ToString());
                    m_level        = m_level.Groups.Count == 1 ? r_level_eng.Match(m.Groups[4].ToString()) : m_level;
                    m_maplevel     = r_maplevel.Match(m.Groups[4].ToString());
                    m_maplevel     = m_maplevel.Groups.Count == 1?r_maplevel_eng.Match(m.Groups[4].ToString()):m_maplevel;
                    m_quality      = r_quality.Match(m.Groups[4].ToString());
                    m_quality      = m_quality.Groups.Count == 1? r_quality_eng.Match(m.Groups[4].ToString()):m_quality;
                    temp.itemlevel = m_itemlevel.Groups.Count == 1 ? 0 : int.Parse(m_itemlevel.Groups[1].ToString());
                    temp.level     = m_level.Groups.Count == 1 ? 0 : int.Parse(m_level.Groups[1].ToString());
                    temp.quality   = m_quality.Groups.Count == 1 ? 0 : int.Parse(m_quality.Groups[1].ToString());
                    temp.maplevel  = m_maplevel.Groups.Count == 1 ? 0 : int.Parse(m_maplevel.Groups[1].ToString());

                    JsonClass.RootObject t;
                    if (m.Groups[1].ToString() == "傳奇" || m.Groups[1].ToString() == "Unique")
                    {
                        t = ItemList_Unique.Where(a => a.c.EndsWith(PrivateFunction.GetStringAfterSomething(temp.Name, "」")) || a.e.EndsWith(PrivateFunction.GetStringAfterSomething(temp.Name, "」"))).FirstOrDefault();
                    }
                    else
                    {
                        t = ItemList.Where(a => temp.Name.Equals(a.c) || temp.Name.Equals(a.e)).FirstOrDefault();
                        if (t == null)
                        {
                            t = ItemList.Where(a => temp.Name.EndsWith(a.c) || temp.Name.EndsWith(a.e)).FirstOrDefault();
                        }
                        if (t == null)
                        {
                            t = ItemList.Where(a => temp.Name.Contains(a.e)).FirstOrDefault();
                        }
                    }
                    if (t == null)
                    {
                        t = ItemList_Adden.Where(a => a.c.EndsWith(PrivateFunction.GetStringAfterSomething(temp.Name, "」")) || a.e.EndsWith(PrivateFunction.GetStringAfterSomething(temp.Name, "」"))).FirstOrDefault();
                    }

                    while (t == null)
                    {
                        Form2 f = new Form2(clip, temp.Name);
                        f.ShowDialog();
                        if (File.Exists(Path.Combine(Application.StartupPath, "ItemList_Adden.txt")))
                        {
                            using (StreamReader rr = new StreamReader(Path.Combine(Application.StartupPath, "ItemList_Adden.txt"), Encoding.UTF8))
                            {
                                ItemList_Adden = JsonConvert.DeserializeObject <List <JsonClass.RootObject> >(rr.ReadToEnd());
                                if (ItemList_Adden == null)
                                {
                                    ItemList_Adden = new List <RootObject>();
                                }
                            }
                        }
                        t = ItemList_Adden.Where(a => temp.Name.Equals(a.c) || temp.Name.Equals(a.e)).FirstOrDefault();
                    }
                    temp.w        = t.w;
                    temp.h        = t.h;
                    temp.point    = new POINT(x, y);
                    temp.url      = t.url;
                    temp.GC       = t.GC;
                    temp.Name_eng = t.e;
                    temp.type     = t.type;

                    temp.priority = Array.IndexOf(Config.Species, t.type);

                    temp.id = ++id;

                    for (int i = x; i < x + t.w; i++)
                    {
                        for (int j = y; j < y + t.h; j++)
                        {
                            used.Add(new POINT(i, j));
                        }
                    }
                    Items.Add(temp);
                }
            }
            DrawBoxRegion(Items, length, 1);
        }