コード例 #1
0
 public static CardLibrary GetInstance()
 {
     if (instance == null)
     {
         CLConfig config = CLConfig.GetInstance();
         Path         = System.AppDomain.CurrentDomain.BaseDirectory;
         KeepInMemory = string.Equals(config.GetSetting("KeepInMemory"), "true", StringComparison.OrdinalIgnoreCase);
         if (KeepInMemory)
         {
             ramdir = new Lucene.Net.Store.RAMDirectory(Path + "CardIndex");
             CardsReader Reader = new LuceneReader();
             instance = new CardLibrary(Reader.Read(ramdir));
             if (Directory.Exists(Path + "DIYCardIndex"))
             {
                 ramdiydir = new Lucene.Net.Store.RAMDirectory(Path + "DIYCardIndex");
                 instance.AddDIYCards(Reader.Read(ramdiydir));
             }
         }
         else
         {
             CardsReader Reader = new LuceneReader();
             instance = new CardLibrary(Reader.Read(Path + "CardIndex"));
             if (Directory.Exists(Path + "DIYCardIndex"))
             {
                 instance.AddDIYCards(Reader.Read(Path + "DIYCardIndex"));
             }
         }
     }
     return(instance);
 }
コード例 #2
0
        public bool isFull(int id)
        {
            CardDescription card  = CardLibrary.GetInstance().GetCardByID(id);
            int             limit = card.limit;
            string          s     = CLConfig.GetInstance().GetSetting("AllowForbiddenCard");

            if (string.Equals(s, "True", StringComparison.OrdinalIgnoreCase))
            {
                limit = 3;
            }
            return(GetCount(id) >= limit);
        }
コード例 #3
0
        public oldDictSearcher()
        {
            cardLibrary = CardLibrary.GetInstance();
            CardDescription[] cards = cardLibrary.GetCards();

            nametable    = new Hashtable(cards.Length);
            japnametable = new Hashtable(cards.Length);
            ennametable  = new Hashtable(cards.Length);

            for (int i = 1; i <= cards.Length; i++)
            {
                CardDescription card = cards[i - 1];
                nametable.Add(card.name, card.ID);
                //if (card.japName != "")
                //    japnametable.Add(card.japName, i);
                //if (card.enName != "")
                //    ennametable.Add(card.enName, i);
                japnametable[card.japName] = card.ID;
                ennametable[card.enName]   = card.ID;
            }
        }
コード例 #4
0
        public bool SaveFileForCGI(string filename)
        {
            try
            {
                StreamWriter sw          = new StreamWriter(filename, false, System.Text.Encoding.Unicode);
                CardLibrary  cardLibrary = CardLibrary.GetInstance();

                Card[] Cards = MainDeck.GetList();
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    string          s  = CharacterSet.JPDBCToSBC(cd.japName);
                    sw.WriteLine(s);
                }

                Cards = SideDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("####");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    sw.WriteLine(CharacterSet.JPDBCToSBC(cd.japName));
                }

                Cards = FusionDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("====");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    sw.WriteLine(CharacterSet.JPDBCToSBC(cd.japName));
                }

                Cards = TempDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("$$$$");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    sw.WriteLine(CharacterSet.JPDBCToSBC(cd.japName));
                }

                sw.Close();

                DeckName             = Regex.Replace(filename, @".[^.]*$", "");
                DeckName             = Regex.Replace(DeckName, @"^.*\\", "");
                MainDeck.isChanged   = false;
                SideDeck.isChanged   = false;
                FusionDeck.isChanged = false;
                TempDeck.isChanged   = false;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #5
0
        public ArrayList LoadFileByCharSet(string FileName, string CharSet)
        {
            try
            {
                Clear();

                StreamReader sr          = new StreamReader(FileName, System.Text.Encoding.GetEncoding(CharSet));
                int          lastNumber  = 0;
                int          currentDeck = 0;
                ArrayList    lastList    = new ArrayList();

                while (!sr.EndOfStream)
                {
                    string s = sr.ReadLine().Trim();
                    if (s.StartsWith("===="))
                    {
                        currentDeck = 1;
                        continue;
                    }
                    else if (s.StartsWith("####"))
                    {
                        currentDeck = 2;
                        continue;
                    }
                    else if (s.StartsWith("$$$$"))
                    {
                        currentDeck = 3;
                        continue;
                    }
                    else if (s.Length == 0)
                    {
                        continue;
                    }

                    CardDescription card     = null;
                    string          lastname = null;
                    if (s[0] == '[')
                    {
                        string name = s.Substring(s.LastIndexOf('[') + 1, s.LastIndexOf(']') - s.LastIndexOf('[') - 1);
                        lastname = name;
                        card     = CardLibrary.GetInstance().GetCardByName(name);
                        if (card == null)
                        {
                            card = CardLibrary.GetInstance().GetCardByOldName(name);
                        }
                    }
                    else
                    {
                        string japname = CharacterSet.JPSBCToDBC(s);
                        lastname = japname;
                        card     = CardLibrary.GetInstance().GetCardByJapName(japname);
                    }

                    if (card != null)
                    {
                        string err = null;
                        switch (currentDeck)
                        {
                        case 0:
                            if (card.iCardtype == 2 || card.iCardtype == 6)
                            {
                                err = FusionDeck.AddCard(card.ID);
                            }
                            else
                            {
                                err = MainDeck.AddCard(card.ID);
                            }
                            break;

                        case 1:
                            err = FusionDeck.AddCard(card.ID);
                            break;

                        case 2:
                            err = SideDeck.AddCard(card.ID);
                            break;

                        case 3:
                            err = TempDeck.AddCard(card.ID);
                            break;
                        }
                        if (err != null)
                        {
                            lastNumber++;
                            lastList.Add(card.name);
                        }
                    }
                    else
                    {
                        lastNumber++;
                        lastList.Add(lastname);
                    }
                }

                sr.Close();
                DeckName             = Regex.Replace(FileName, @".[^.]*$", "");
                DeckName             = Regex.Replace(DeckName, @"^.*\\", "");
                MainDeck.isChanged   = false;
                SideDeck.isChanged   = false;
                FusionDeck.isChanged = false;
                TempDeck.isChanged   = false;

                return(lastList);
            }
            catch
            {
                Clear();
                return(null);
            }
        }
コード例 #6
0
        public bool SaveFileForPRO(string filename)
        {
            try
            {
                StreamWriter sw          = new StreamWriter(filename, false, System.Text.Encoding.ASCII);
                CardLibrary  cardLibrary = CardLibrary.GetInstance();

                sw.WriteLine("#created by DeckBuilder2");

                //Êä³öÖ÷¿¨×é
                Card[] Cards = MainDeck.GetList();
                sw.WriteLine("#main");
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    sw.WriteLine(cd.cheatcode);
                }

                //Êä³ö¶îÍ⿨×é
                Cards = ExtraDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("#extra");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    sw.WriteLine(cd.cheatcode);
                }

                //Êä³ö¸±¿¨×é
                Cards = SideDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("!side");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    sw.WriteLine(cd.cheatcode);
                }

                //Êä³öºòÑ¡¿¨±í
                Cards = TempDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("#wait list");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    sw.WriteLine("#" + cd.cheatcode);
                }

                sw.Close();

                deckname            = Regex.Replace(filename, @".[^.]*$", "");
                deckname            = Regex.Replace(deckname, @"^.*\\", "");
                MainDeck.isChanged  = false;
                SideDeck.isChanged  = false;
                ExtraDeck.isChanged = false;
                TempDeck.isChanged  = false;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #7
0
        public bool SaveFile(string filename)
        {
            this.filename = filename;

            try
            {
                StreamWriter sw          = new StreamWriter(filename, false, System.Text.Encoding.GetEncoding("gb2312"));
                CardLibrary  cardLibrary = CardLibrary.GetInstance();

                Card[] Cards = MainDeck.GetList();
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    if (card.Text.Length > 0)
                    {
                        sw.WriteLine("[" + cd.name + "]#" + card.Text + "#");
                    }
                    else
                    {
                        sw.WriteLine("[" + cd.name + "]");
                    }
                }

                Cards = SideDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("####");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    if (card.Text.Length > 0)
                    {
                        sw.WriteLine("[" + cd.name + "]#" + card.Text + "#");
                    }
                    else
                    {
                        sw.WriteLine("[" + cd.name + "]");
                    }
                }

                Cards = ExtraDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("====");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    if (card.Text.Length > 0)
                    {
                        sw.WriteLine("[" + cd.name + "]#" + card.Text + "#");
                    }
                    else
                    {
                        sw.WriteLine("[" + cd.name + "]");
                    }
                }

                Cards = TempDeck.GetList();
                if (Cards.Length > 0)
                {
                    sw.WriteLine("$$$$");
                }
                foreach (Card card in Cards)
                {
                    CardDescription cd = cardLibrary.GetCardByID(card.ID);
                    if (card.Text.Length > 0)
                    {
                        sw.WriteLine("[" + cd.name + "]#" + card.Text + "#");
                    }
                    else
                    {
                        sw.WriteLine("[" + cd.name + "]");
                    }
                }

                sw.Close();

                deckname            = Regex.Replace(filename, @".[^.]*$", "");
                deckname            = Regex.Replace(deckname, @"^.*\\", "");
                MainDeck.isChanged  = false;
                SideDeck.isChanged  = false;
                ExtraDeck.isChanged = false;
                TempDeck.isChanged  = false;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #8
0
        public ArrayList LoadFileByCharSetForPRO(string FileName, string CharSet)
        {
            try
            {
                Clear();

                StreamReader sr          = new StreamReader(FileName, System.Text.Encoding.GetEncoding(CharSet));
                int          lastNumber  = 0;
                int          currentDeck = 0;
                ArrayList    lastList    = new ArrayList();

                while (!sr.EndOfStream)
                {
                    string s = sr.ReadLine().Trim();
                    if (s.StartsWith("!side"))
                    {
                        currentDeck = 2;
                        continue;
                    }
                    else if (s.StartsWith("#wait list"))
                    {
                        currentDeck = 3;
                        continue;
                    }
                    else if (s.Length == 0 || s.StartsWith("#") || s.StartsWith("!"))
                    {
                        continue;
                    }

                    CardDescription card     = null;
                    string          lastname = s;
                    if (currentDeck == 3)
                    {
                        lastname = s.Substring(1);
                    }
                    card = CardLibrary.GetInstance().GetCardByCheatCode(lastname);
                    string text = null;


                    if (card != null)
                    {
                        string err = null;
                        switch (currentDeck)
                        {
                        case 0:
                            if (CardDescription.isExtraCard(card))
                            {
                                err = ExtraDeck.AddCard(card.ID, -1, text);
                            }
                            else
                            {
                                err = MainDeck.AddCard(card.ID, -1, text);
                            }
                            break;

                        case 1:
                            err = ExtraDeck.AddCard(card.ID, -1, text);
                            break;

                        case 2:
                            err = SideDeck.AddCard(card.ID, -1, text);
                            break;

                        case 3:
                            err = TempDeck.AddCard(card.ID, -1, text);
                            break;
                        }
                        if (err != null)
                        {
                            lastNumber++;
                            lastList.Add(card.name);
                        }
                    }
                    else
                    {
                        lastNumber++;
                        lastList.Add(lastname);
                    }
                }

                sr.Close();
                deckname            = Regex.Replace(FileName, @".[^.]*$", "");
                deckname            = Regex.Replace(deckname, @"^.*\\", "");
                MainDeck.isChanged  = false;
                SideDeck.isChanged  = false;
                ExtraDeck.isChanged = false;
                TempDeck.isChanged  = false;

                return(lastList);
            }
            catch
            {
                Clear();
                return(null);
            }
        }
コード例 #9
0
 public DictSearcherCompare()
 {
     cardLibrary = CardLibrary.GetInstance();
 }
コード例 #10
0
        public static CardLibrary GetInstance()
        {
            //单实例
            if (instance == null)
            {
                //读取配置
                CLConfig config = CLConfig.GetInstance();

                //获取路径
                path = Global.GetPath();

                //清除多余索引文件
                if (File.Exists(path + "CardIndex\\list.txt"))
                {
                    string[] files = File.ReadAllLines(path + "CardIndex\\list.txt", Encoding.UTF8);

                    foreach (string s in Directory.GetFiles(path + "CardIndex"))
                    {
                        string ss     = s.Substring(s.LastIndexOf('\\') + 1);
                        bool   inlist = false;
                        foreach (string s2 in files)
                        {
                            if (string.Equals(ss, s2, StringComparison.OrdinalIgnoreCase))
                            {
                                inlist = true;
                                break;
                            }
                        }

                        if (!(inlist || string.Equals(ss, "list.txt", StringComparison.OrdinalIgnoreCase)))
                        {
                            File.Delete(s);
                        }
                    }
                }

                //读取主索引
                indexdir = new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(path + "CardIndex"), new Lucene.Net.Store.SimpleFSLockFactory());

                //读取DIY索引
                if (Directory.Exists(path + "DIYCardIndex"))
                {
                    diydir = new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(path + "DIYCardIndex"), new Lucene.Net.Store.SimpleFSLockFactory());
                }

                //是否使用内存索引
                KeepInMemory = string.Equals(config.GetSetting("KeepInMemory"), "true", StringComparison.OrdinalIgnoreCase);
                if (KeepInMemory)
                {
                    indexdir = new Lucene.Net.Store.RAMDirectory(indexdir);

                    if (diydir != null)
                    {
                        diydir = new Lucene.Net.Store.RAMDirectory(diydir);
                    }
                }

                //读取所有卡片信息,建立卡片数据库实例
                LuceneReader Reader = new LuceneReader();
                instance = new CardLibrary(Reader.Read(indexdir));
                if (diydir != null)
                {
                    instance.AddDIYCards(Reader.Read(diydir));
                }

                //建立搜索器实例
                instance.BuildSearcher();
            }

            return(instance);
        }