Exemple #1
0
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            int    UsedSlots = 0;
            string Message   = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");

            string[] Inv    = new string[64];
            int      maxlen = 4;

            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            bool     isinv = false, isinvmembers = false;

            if (CommandArray[0] == "#inv" || CommandArray[0] == "#i" || CommandArray[0] == "#inb" || CommandArray[0] == "#sell" || CommandArray[0] == "#selling" || CommandArray[0] == "#inventory")
            {
                isinv = true;
            }
            if (CommandArray[0] == "#invmembers" || CommandArray[0] == "#im" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver")
            {
                isinvmembers = true;
            }
            if (isinv || isinvmembers)
            {
                bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#inv", Settings.botid);

                string str1 = "", str2 = "";

                if (TheInventory.GettingInventoryItems == true)
                {
                    str2 = "I am building my inventory list, please try again in a few seconds";
                    str1 = str1.PadRight(str2.Length, '=');
                    str1 = "[" + str1;
                    str2 = "[" + str2;
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str2));
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1));

                    return;
                }

                if (disabled == true)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled"));
                    return;
                }

                if (Settings.IsTradeBot == false)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!"));
                    return;
                }
                int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);
                if (rank < TheMySqlManager.GetCommandRank("#inv", Settings.botid))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if ((CommandArray[0] == "#im" || CommandArray[0] == "#invmembers" || CommandArray[0] == "#invmemvers" || CommandArray[0] == "#invmember" || CommandArray[0] == "#invmemver") && ((rank < TheMySqlManager.GetCommandRank("#invmembers", Settings.botid)) && TheMySqlManager.CheckIfBannedGuild(e.username, Settings.botid) < 1))
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                    return;
                }

                if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
                {
                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                    return;
                }

                if (CommandArray.Length < 1)
                {
                    goto WrongArguments;
                }

                char invFiller = TheMySqlManager.getInvFiller();

                System.Collections.ArrayList MyInventoryList    = TheInventory.GetInventoryList();
                System.Collections.Hashtable MySellingItemsList = TheMySqlManager.GetSellingItemList(0);

                // sum up all inventory items if the items are on sale
                System.Collections.SortedList TheInventoryList = new System.Collections.SortedList();

                foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList)
                {
                    //adjust the number of slots used...
                    if (MyInventoryItem.pos < 36)
                    {
                        if (MyInventoryItem.is_stackable)
                        {
                            UsedSlots++;
                        }
                        else
                        {
                            UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity);
                        }
                    }
                    //adjust the amount

                    //only display if in selling list
                    if (MySellingItemsList.Contains(MyInventoryItem.SqlID))
                    {
                        //if already in inventory output (eg.., two slots) just sum the quantity
                        //otherwise add to inventory output
                        if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36)
                        {
                            Inventory.inventory_item TempInventoryItem = (Inventory.inventory_item)TheInventoryList[MyInventoryItem.SqlID];
                            TempInventoryItem.quantity += MyInventoryItem.quantity;
                            TheInventoryList[MyInventoryItem.SqlID] = TempInventoryItem;
                        }
                        else
                        {
                            if (MyInventoryItem.pos < 36)
                            {
                                TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem);
                            }
                        }
                    }
                }

                //foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                //{
                //    if(maxlen<MyInventoryItem.name.Length && (MyInventoryItem.pos < 36))
                //        maxlen = MyInventoryItem.name.Length;
                //}
                //maxlen++;
                maxlen = 20 + 25 - Settings.Loginname.Length;
                // pm all summed up inventory items on sale
                int i = 0;
                for (i = 0; i < 64; i++)
                {
                    Inv[i] = "ZZZZZZZZZZZZZZZZ";
                }
                int    c   = 0;
                string str = "";
                str2 = "";
                str  = "[";
                str  = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                bool Member = (TheMySqlManager.CheckIfTradeMember(e.username, Settings.botid) == true);

                str = "[name".PadRight(maxlen, ' ');
                str = str + "|qty".PadRight(7, ' ');
                str = str + "|price".PadRight(14, ' ');
                str = str + "|id".PadRight(6, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                string msg, msg2;

                foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values)
                {
                    if (MyInventoryItem.pos < 36)
                    {
                        msg = ("[" + MyInventoryItem.name).PadRight(maxlen, i == 0 ? ' ' : invFiller);
                        {
                            uint tempAmount = 0;
                            if ((TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)) < MyInventoryItem.quantity)
                            {
                                tempAmount = MyInventoryItem.quantity;
                                tempAmount = tempAmount - (TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID));
                            }
                            else
                            {
                                continue;
                            }

                            msg2 = tempAmount.ToString();
                        }
                        msg2 = msg2.PadLeft(6, i == 0 ? ' ' : invFiller);
                        msg  = msg + "|" + msg2;
                        TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]);
                        if (isinv)
                        {
                            msg2 = MySellingItem.pricesale.ToString();
                        }
                        else
                        {
                            msg2 = MySellingItem.pricesalemembers.ToString();
                        }
                        if (!msg2.Contains("."))
                        {
                            msg2 += ".00gc";
                        }
                        else if (msg2[msg2.Length - 2] == '.')
                        {
                            msg2 += "0gc";
                        }
                        else
                        {
                            msg2 += "gc";
                        }
                        msg2   = msg2.PadLeft(13, i == 0 ? ' ' : invFiller);
                        msg    = msg + "|" + msg2;
                        msg2   = MyInventoryItem.SqlID.ToString().PadLeft(5, i == 0 ? ' ' : invFiller);
                        msg    = msg + "|" + msg2;
                        Inv[c] = msg;
                        c++;
                        i = 1 - i;
                    }
                }
                int d;
//                for (d = 0; d < c; d++)
//                {
//                    str = Inv[d].Substring(16) + Inv[d].Substring(0, 16);
//                    Inv[d] = str;
//                }
                Array.Sort(Inv);
                i = maxlen + 13;

                string filter = "";
                if (CommandArray.Length > 1)
                {
                    bool firstTime = true;
                    foreach (string filterPart in CommandArray)
                    {
                        if (firstTime)
                        {
                            firstTime = false;
                            continue;
                        }
                        filter += (" " + filterPart);
                    }
                    //filter = Message.Substring(CommandArray[0].Length);
                }
                else
                {
                    filter = "";
                }

                for (d = 0; d < c; d++)
                {
                    str = Inv[d];
                    //27 chars after the name....
                    if (filter == "" || Inv[d].ToLower().Contains(filter.ToLower().Trim()))
                    {
                        string[] outFields = Inv[d].Split('|');
                        string   outString = Inv[d];
                        if (outFields[0].Length > maxlen)
                        {
                            outString = outFields[0].Substring(0, maxlen - 3) + "...";
                            outString = outString.PadRight(maxlen, ' ') + "|".PadRight(7, ' ') + "|".PadRight(14, ' ') + "|".PadRight(6, ' ');
                            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                            outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' ');
                            int count = 0;
                            foreach (string tempString in outFields)
                            {
                                if (count == 0)
                                {
                                    count++;
                                    continue;
                                }
                                outString += "|" + tempString;
                            }
                        }
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                    }
                    else
                    {
                        //for (i = 1; i < CommandArray.Length; i++)
                        {
                            //if (Inv[d].ToLower().Contains(CommandArray[i].ToLower().Trim()))
                            Console.WriteLine("inv(d): " + Inv[d] + " filter: " + filter);
                            if (Inv[d].ToLower().Contains(filter.ToLower().Trim()))
                            {
                                string[] outFields = Inv[d].Split('|');
                                string   outString = Inv[d];
                                if (outFields[0].Length > maxlen)
                                {
                                    outString = outFields[0].Substring(0, maxlen - 3) + "...";
                                    outString = outString.PadRight(maxlen, ' ') + "|".PadRight(14, ' ') + "|".PadRight(9, ' ');
                                    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                    outString = ("[..." + outFields[0].Substring(maxlen - 3).Trim()).PadRight(maxlen, ' ');
                                    foreach (string tempString in outFields)
                                    {
                                        outString += "|" + tempString;
                                    }
                                }
                                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, outString));
                                i = CommandArray.Length;
                            }
                        }
                    }
                }

                int Phys  = TheMySqlManager.GetBotPhysqiue(Settings.botid);
                int Coord = TheMySqlManager.GetBotCoordination(Settings.botid);
                int carry = (Phys + Coord) * 10;
                //int UsedSpace = TheMySqlManager.GetBotUsedSpace(Settings.botid);
                //int UsedSlots = TheMySqlManager.GetBotUsedSlots(Settings.botid);
                int UsedSpace = TheStats.MyCurrentCarryingAmt;
                int FreeSpace = carry - UsedSpace;
                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                str  = "[";
                str += FreeSpace.ToString() + " EMU Avail|";
                str += (36 - UsedSlots).ToString() + " Open slot(s)";
                if (rank > 89)
                {
                    //str += TheMySqlManager.moneylevel(Settings.botid).ToString() + " gc";
                    str += "|" + TheInventory.GetMoneyAmount().ToString() + " gc";
                }

                str = str.PadRight(maxlen + 27, ' ');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                str = "[";
                if (Member)
                {
                    if ((CommandArray[0] != "#im" && CommandArray[0] != "#invmembers" && CommandArray[0] != "#invmemvers" && CommandArray[0] != "#invmember" && CommandArray[0] != "#invmemver"))
                    {
                        str = str.PadRight(maxlen + 27, '-');
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                        str = "[Use invmembers (im) to see member prices";
                        str = str.PadRight(maxlen + 27, ' ');
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    }
                    //if (isinv)
                    //{
                    //    str = "[to see member prices use invmembers or im";
                    //    str = str.PadRight(maxlen + 28, ' ');
                    //    TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));
                    //}
                }
                str = "[";
                str = str.PadRight(maxlen + 27, '-');
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str));

                return;
            }
            return;

WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #inv command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#inv                                  "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv                         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #inv silver ore              "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[--------------------------------------"));
            return;
        }
        private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e)
        {
            string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\"");


            if (Message[0] != '#')
            {
                Message = "#" + Message;
            }

            string[] CommandArray = Message.Split(' ');
            if (CommandArray[0] != "#prize" && CommandArray[0] != "#prizes")
            {
                return;
            }
            if (claimingPrize || TheTradeHandler.claimingPrize)
            {
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You're already claiming your prize!"));
                TheTCPWrapper.Send(CommandCreator.EXIT_TRADE());
                return;
            }
            claimingPrize = false;
            acceptedOnce  = false;

            if (!TheMySqlManager.IGamble())
            {
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I don't gamble, sorry!"));
                return;
            }

            if (Settings.IsTradeBot == false)
            {
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Sorry, I am not a trade bot!"));
                return;
            }

            int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid);

            if (rank < TheMySqlManager.GetCommandRank("#prize", Settings.botid))
            {
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                return;
            }

            if (TheMySqlManager.CheckIfBannedGuild(e.username, Settings.botid) < 0)
            {
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You are not authorized to use this command!"));
                return;
            }

            if (this.TheTradeHandler.AmITrading() && e.username != TradeHandler.username)
            {
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "I am currently trading, please retry shortly."));
                return;
            }
            if (TheTradeHandler.Gambling)
            {
                TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You cannot calim prizes if you're already gambling, cancel and reissue the command!"));
                return;
            }
            if (CommandArray.Length != 2)
            {
                goto WrongArguments;
            }

            username = e.username;
            string argument = CommandArray[1];

            switch (argument)
            {
            case "high":
            case "low":
            case "medium":
                TheMySqlManager.displayPrizes(argument, e.username);
                break;

            case "claim":
                if (!acceptedOnce)
                {
                    Int16 TradePartnerUserID = TheActorHandler.GetUserIDFromname(username);
                    //Console.WriteLine("usernames: " + TradeHandler.username + " " + username);
                    if (!TheTradeHandler.Trading || (TradeHandler.username != username))
                    {
                        TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "You must be trading with me first!"));
                        TheTCPWrapper.Send(CommandCreator.TRADE_WITH(TradePartnerUserID));
                        claimingPrize = true;
                    }
                    else if (TheTradeHandler.Trading && itemCount == 0)
                    {
                        TheTradeHandler.claimingPrize = true;
                        claimingPrize = true;
                        itemCount     = TheMySqlManager.putPrizesInWindow(username);
                    }
                }
                break;

            case "list":
                TheMySqlManager.listPrizesWon(username);
                //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Not yet implemented, sorry..."));
                break;

            default:
                goto WrongArguments;
            }
            return;

WrongArguments:
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #prize command:"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#prize <level> list prizes you can win  "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#prize <claim> claim your prize         "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#prize <list> lists prizes you can claim"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------"));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #prize high                    "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #prize medium                  "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #prize low                     "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #prize claim                   "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #prize list                    "));
            TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------"));
            return;
        }