Ejemplo n.º 1
0
 public void removeMessages(string seller, Auction.OfferType aot, string cname)
 {
     fullSellOfferList.RemoveAll(a => a.seller.Equals(seller) && a.card.getType() == helpf.cardnamesToID[cname] && a.offer == aot);
     sellOfferListFiltered.RemoveAll(a => a.seller.Equals(seller) && a.card.getType() == helpf.cardnamesToID[cname] && a.offer == aot);
     fullBuyOfferList.RemoveAll(a => a.seller.Equals(seller) && a.card.getType() == helpf.cardnamesToID[cname] && a.offer == aot);
     buyOfferListFiltered.RemoveAll(a => a.seller.Equals(seller) && a.card.getType() == helpf.cardnamesToID[cname] && a.offer == aot);
 }
Ejemplo n.º 2
0
        /*private void additemtolist(Card c, string from, int gold, bool wts, string wholemsg)
         * {
         * if (wts)
         * {
         * this.addingcards.Add(new Auction(from, DateTime.Now, Auction.OfferType.SELL, c, wholemsg, gold));
         * }
         * else
         * {
         *
         * this.addingcards.Add(new Auction(from, DateTime.Now, Auction.OfferType.BUY, c, wholemsg, gold));
         * }
         *
         * }*/

        private static void GetAuctionsFromShortIntoList(string shortList, string from, Auction.OfferType offerType, List <Auction> outList)
        {
            string[] words = shortList.Split(';');
            for (int i = 0; i < words.Length; i++)
            {
                if (words[i] == "" || words[i] == " ")
                {
                    break;
                }
                string price;
                string ids;
                if (words[i].Contains(' '))
                {
                    price = words[i].Split(' ')[1];
                    if (price == "")
                    {
                        price = "0";
                    }
                    ids = words[i].Split(' ')[0];
                }

                else
                {
                    price = "0";
                    ids   = words[i];
                }

                string[] ideen = ids.Split(','); //When string does not contain a , the whole string is the first element of the returned array.
                foreach (string idd in ideen)
                {
                    int      id   = Convert.ToInt32(idd);
                    CardType type = CardTypeManager.getInstance().get(id);
                    Card     card = new Card(id, type, true);
                    outList.Add(new Auction(from, DateTime.Now, offerType, card, "(Network Auction)", Convert.ToInt32(price)));
                }
            }
        }
Ejemplo n.º 3
0
        public List <Auction> GetAuctionsFromMessage(string msgg, string from, string room)
        {
            string msg = Regex.Replace(msgg, @"(<color=#[A-Za-z0-9]{0,6}>)|(</color>)", String.Empty);

            // todo: delete old msgs from author
            if (msg.StartsWith("aucs ") || msg.StartsWith("aucb "))
            {
                return(GetAuctionsFromShortMessage(msg, from));
            }
            //if (msg.StartsWith("aucc ")) { respondtocommand(msg,from); return; }
            Auction.OfferType currentOfferType = Auction.OfferType.BUY; //Will be overwritten
            //string[] words=msg.Split(' ');
            List <Auction> addingAuctions = new List <Auction>();
            List <char>    delimiters     = new List <char>();

            //{ '\r', '\n', ' ', ',', ';' };
            foreach (char a in msg)
            {
                if (!char.IsLetterOrDigit(a))
                {
                    delimiters.Add(a);
                }
            }
            string[] words = msg.Split(delimiters.ToArray(), StringSplitOptions.RemoveEmptyEntries);

            //words = Regex.Split(msg, @"");

            if (!msg.ToLower().Contains("wts") && !msg.ToLower().Contains("wtb") && !msg.ToLower().Contains("sell") && !msg.ToLower().Contains("buy"))
            {
                return(addingAuctions);
            }
            bool     wtxfound = false;
            DateTime now1     = DateTime.Now;

            for (int i = 0; i < words.Length; i++)
            {
                Card   c; int price = 0;
                string word = words[i].ToLower();
                // save in wts or wtb?
                if (word.Contains("wts") || word.Contains("sell"))
                {
                    currentOfferType = Auction.OfferType.SELL; wtxfound = true;
                }
                ;
                if (word.Contains("wtb") || word.Contains("buy"))
                {
                    currentOfferType = Auction.OfferType.BUY; wtxfound = true;
                }
                ;
                if (!wtxfound)
                {
                    continue;           // if no wts or wtb was found, skip card search
                }
                //int arrindex = Array.FindIndex(this.cardnames, element => word.Contains(element.Split(' ')[0])); // changed words[i] and element!
                int arrindex = this.searchscrollsnicks.FindIndex(element => word.Contains(element.nick.Split(' ')[0]));
                int iadder   = 0;

                if (arrindex >= 0) // wort in cardlist enthalten
                {
                    //Console.WriteLine(word + " " + arrindex);
                    //string[] possiblecards = Array.FindAll(this.cardnames, element => word.Contains(element.Split(' ')[0]));
                    List <nickelement> possibnics = this.searchscrollsnicks.FindAll(element => word.Contains(element.nick.Split(' ')[0]));
                    bool   findcard    = false;
                    string foundedcard = "";
                    string textplace   = "";

                    for (int ii = 0; ii < possibnics.Count; ii++)
                    {
                        //string match = possiblecards[ii].ToLower();
                        string match    = possibnics[ii].nick.ToLower();
                        int    posleng  = Math.Min(match.Split(' ').Length, words.Length - i);
                        string searchob = string.Join(" ", words, i, posleng).ToLower();
                        if (searchob.Contains(match))
                        {
                            findcard = true; foundedcard = possibnics[ii].cardname.ToLower(); iadder = posleng; textplace = searchob; break;
                        }
                        ;
                    }
                    //

                    i = i + iadder;

                    if (findcard)
                    {
                        //CardType type = CardTypeManager.getInstance().get(cardnametoid(foundedcard.ToLower()));
                        CardType type = CardTypeManager.getInstance().get(helpf.cardnamesToID[foundedcard.ToLower()]);
                        //int realarrindex = Array.FindIndex(helpf.cardnames, element => foundedcard.Equals(element));
                        int realarrindex = helpf.cardnameToArrayIndex(foundedcard);
                        c = new Card(helpf.cardids[realarrindex], type, true);
                        //Console.WriteLine("found " + foundedcard + " in " + textplace);
                        string tmpgold = pricetestfirst((textplace.Split(' '))[(textplace.Split(' ')).Length - 1]);
                        if (!(tmpgold == "")) // && iadder >1
                        {                     // case: cardnamegold
                            //Console.WriteLine("found " + this.numberregx.Match(tmpgold).Value);
                            price = Convert.ToInt32(this.numberregx.Match(tmpgold).Value);
                        }
                        else if (i < words.Length)
                        {
                            int j = i;
                            tmpgold = pricetest(words[j]);
                            while (tmpgold == "")
                            {
                                if (j + 1 < words.Length)
                                {
                                    j++;
                                    tmpgold = pricetest(words[j]);
                                }
                                else
                                {
                                    tmpgold = "fail";
                                }
                            }

                            if (!(tmpgold == "fail"))
                            { // cardname gold
                                //Console.WriteLine("found gold " + this.numberregx.Match(tmpgold).Value);
                                price = Convert.ToInt32(this.numberregx.Match(tmpgold).Value);
                            }
                        }
                        now1 = now1.AddMilliseconds(1);
                        addingAuctions.Add(new Auction(from, now1, currentOfferType, c, msgg, price));
                        //additemtolist(c, from, price, wts, msgg);
                        i--;
                    }//if (find) ende
                }
            }
            return(addingAuctions);
        }