private void UseItem(int SQLID) { System.Collections.ArrayList InventorySnapshop = TheInventory.GetInventoryList(); for (int i = 0; i < InventorySnapshop.Count; i++) { Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)InventorySnapshop[i]; if (MyInventoryItem.SqlID == SQLID && MyInventoryItem.pos < 36) { slotUsed = MyInventoryItem.pos; qtyBefore = (int)MyInventoryItem.quantity; usingItem = true; TheTCPWrapper.Send(CommandCreator.USE_ITEM(slotUsed)); TheInventory.requestInventory(); break; } } }
private uint DropItems(int SQLID, UInt32 quantity) { UInt32 QuantityDropItems = 0; System.Collections.ArrayList InventorySnapshop = TheInventory.GetInventoryList(); for (int i = 0; i < InventorySnapshop.Count; i++) { Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)InventorySnapshop[i]; if (MyInventoryItem.SqlID == SQLID && MyInventoryItem.pos < 36) { if (MyInventoryItem.quantity <= (quantity - QuantityDropItems)) { TheTCPWrapper.Send(CommandCreator.DROP_ITEM(MyInventoryItem.pos, MyInventoryItem.quantity)); QuantityDropItems += MyInventoryItem.quantity; MyInventoryItem.quantity = 0; InventorySnapshop[i] = MyInventoryItem; } else { TheTCPWrapper.Send(CommandCreator.DROP_ITEM(MyInventoryItem.pos, (quantity - QuantityDropItems))); QuantityDropItems += quantity; MyInventoryItem.quantity -= quantity; InventorySnapshop[i] = MyInventoryItem; } if (QuantityDropItems >= quantity) { return(QuantityDropItems); } } } return(QuantityDropItems); }
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("\"", "\\\""); string[] Inv=new string[64]; int maxlen = 4; bool validCommand = false; if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); if (CommandArray[0] == "#reserve" ) { bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#reserve", 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; } int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid); if (rank < TheMySqlManager.GetCommandRank("#reserve", Settings.botid)) { 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; if (CommandArray[1] == "withdraw") { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Still working on this function...")); validCommand = true; } if (CommandArray[1] == "details") { TheMySqlManager.reservedDetails(Settings.botid, e.username); validCommand = true; } if (CommandArray[1] == "list") { validCommand = true; // list all of the inventory items that have reserved amounts //set up the current inventory list System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList(); //set up a sorted inventory list for output purposes System.Collections.SortedList TheInventoryList = new System.Collections.SortedList(); //loop through the inventory finding reserved amounts foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList) { //find the largest name length for output purposes if (maxlen < MyInventoryItem.name.Length && (MyInventoryItem.pos < 36)) maxlen = MyInventoryItem.name.Length; //if it's not in the output array, put it there if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36) { //add the item quantities (these should be the unstackables...) 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); } } } //loop through the storage finding reserved amounts System.Collections.ArrayList MyStorageList = TheStorage.GetStorageList(); foreach (Storage.StorageItem MyStorageItem in MyStorageList) { if (maxlen < MyStorageItem.name.Length) { maxlen = MyStorageItem.name.Length; } if (TheInventoryList.Contains(MyStorageItem.knownItemsID)) { //already in the list, do nothing since storage quantity is already the total //and it repeats, kinda like an unstackable item } else { Inventory.inventory_item MyInventoryItem = new Inventory.inventory_item(); MyInventoryItem.name = MyStorageItem.name; MyInventoryItem.SqlID = MyStorageItem.knownItemsID; MyInventoryItem.quantity = MyStorageItem.quantity; MyInventoryItem.reservedQuantity = MyStorageItem.reservedQuantity; TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem); } } // pm the reserved items string str = ""; string msg = ""; str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values) { uint reservedQuantity = TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID); if (MyInventoryItem.pos < 36 && reservedQuantity > 0) { msg = "["; msg += MyInventoryItem.name + " " + reservedQuantity + " of " + MyInventoryItem.quantity; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, msg)); } } str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } if (CommandArray.Length > 2) { validCommand = true; try { if (CommandArray[1] == "delete") { Int32 rowIndex = Int32.Parse(CommandArray[2]); if (TheMySqlManager.reservedDelete(Settings.botid, e.username, rowIndex)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Row Deleted.")); } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Index not found.")); } } else { Int32 numberToReserve = Int32.Parse(CommandArray[1]); int i; string itemName = ""; for (i = 2; i < CommandArray.Length; i++) { itemName += CommandArray[i] + " "; } int itemId = TheMySqlManager.GetItemID(itemName,false); if (itemId > 0) { if (TheMySqlManager.reserveItem(itemId, (uint)numberToReserve, e.username) == true) { TheTradeHandler.AddTrade(itemId, 0, (uint)numberToReserve, "reserved"); TradeHandler.TradeLogItem myItem = new TradeHandler.TradeLogItem(); myItem.KnownItemsSqlID = itemId; myItem.quantity = (uint)numberToReserve; myItem.action = "reserved by"; TheMySqlManager.LogTrade(myItem, e.username, Settings.botid, true); TheInventory.requestInventory(); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[You just reserved " + myItem.quantity + " " + TheMySqlManager.GetKnownItemsname(myItem.KnownItemsSqlID))); } else //probably never get to this one... { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!")); } } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!")); } } } catch { goto WrongArguments; } } else { if (!validCommand) { goto WrongArguments; } } } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #reserve command: ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#reserve <list>[withdraw] <amount item> ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve list ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve amount item ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve details ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve delete <idx>* ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[*<idx> provided by #reserve details command. ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------")); return; }
private bool WearItem(int SQLID, string wearAction) { System.Collections.ArrayList InventorySnapshop = TheInventory.GetInventoryList(); bool[] slotfull = new bool[44]; byte fromSlot = 128; byte toSlot = 128; for (int i = 0; i < 44; i++) { slotfull[i] = false; } if (wearAction == "wore") { for (int i = 0; i < InventorySnapshop.Count; i++) { Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)InventorySnapshop[i]; //find the item in non-worn inventory //if found, find an open wear slot and try to wear it //take notes of which slots are full.... slotfull[MyInventoryItem.pos] = true; if (MyInventoryItem.SqlID == SQLID && MyInventoryItem.pos < 36) { //item is in inventory, try to wear it? fromSlot = (byte)MyInventoryItem.pos; } } //find a wear slot that's open for (int i = 36; i < 44; i++) { if (slotfull[i] == false) { //put the item in this slot (slot i) toSlot = (byte)i; break; } } } else { for (int i = 0; i < InventorySnapshop.Count; i++) { Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)InventorySnapshop[i]; //find the item in the wear slots //if found, find an open inventory slot and move it there slotfull[MyInventoryItem.pos] = true; if (MyInventoryItem.SqlID == SQLID && MyInventoryItem.pos > 35) { fromSlot = (byte)MyInventoryItem.pos; } } //find an inventory slot that's open for (int i = 0; i < 36; i++) { if (slotfull[i] == false) { //put the item in this slot (slot i) toSlot = (byte)i; break; } } } if (fromSlot != 128 && toSlot != 128) { TheTCPWrapper.Send(CommandCreator.MOVE_INVENTORY_ITEM(fromSlot, toSlot)); return(true); } else { wearAction = ""; TheTCPWrapper.Send(CommandCreator.SEND_PM(username, "Wrong item or no free slot!")); return(false); } }
private void AdvertTimer_Tick(object sender, ElapsedEventArgs e) { try { int i = 0; uint advertchannel = TheMySqlManager.advertchannel(Settings.botid); Random RandomClass = new Random(); string advertstr = "", str2 = "", endm = TheMySqlManager.advertendmessage().Trim(); if (TheTradeHandler.AmITrading() || (TheInventory.GettingInventoryItems == true)) { this.AdvertTimer.Interval = (1 * 1000);// +RandomClass.Next(0, (60 * 60 * 1000)); ;//m*s*us=1 hour TheLogger.Debug("Advert delayed due to current trade\n"); return; } if (advertchannel != 99999999) { //this.AdvertTimer.Interval = (15 * 60 * 1000) + RandomClass.Next(0, (60 * 60 * 1000)); ;//m*s*us=1 hour //this.AdvertTimer.Interval=60* i = TheMySqlManager.minadverttime() * 1000; i += (RandomClass.Next(0, TheMySqlManager.randomadvertdelay()) * 1000); if (i < 900000) { i = 900000;//minimum 15 minute delay } this.AdvertTimer.Interval = i; } else { if (MainClass.serverName == "test") { this.AdvertTimer.Interval = 1000; } } TheLogger.Debug("New AdvertTimer.Interval: " + this.AdvertTimer.Interval + "\n"); if (advertchannel != 99999999 && TheMySqlManager.lastadverttime(Settings.botid) < TheMySqlManager.minadverttime() && MainClass.serverName != "test") { return; } //Start the advertising here, if it's set to true... //Assumptions: 140 characters max length //Need to get advert_rates from the database for this bot to see how the weights are distributed if (TheMySqlManager.advertise()) { //decide if we should do a text message or a _goods_ message //get the rate for text adverts, it's a number between 0 and 1 //then get a random number between 0 and one, if the random number is less than the advert rate, do the advert //otherwise, do a _goods_ advert (buying and selling...) double advertTextRate = TheMySqlManager.getAdvertTextRate(); double sellRate = TheMySqlManager.getSellRate(); Random randomDouble = new Random(); double randomRate = randomDouble.NextDouble(); if (randomRate < advertTextRate) { //do a text advert //get a random row from the adverts table and use it as the advertisement //select * from adverts where botid = 2 order by rand() LIMIT 1; advertstr = TheMySqlManager.getTextAdvert(); } else { //do a goods advert (buying and selling) //get the selling rate, it's between 0 and 1 //get a random number between 0 and 1, if the rate is less than the selling rate, do a "selling" advert //otherwise, do a "buying" advert System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList(); System.Collections.ArrayList MySellingItemsList = TheMySqlManager.GetSellingList(1); // sum up all inventory items if the items are on sale System.Collections.SortedList TheInventoryList = new System.Collections.SortedList(); System.Collections.ArrayList MyWantedItemsList = TheMySqlManager.GetWantedList(1); //add up the inventory stuff foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList) { 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); } } } randomRate = randomDouble.NextDouble(); if (randomRate < sellRate) { //selling advertstr = "Selling:"; foreach (TradeHandler.SellingItem MySellingItem in MySellingItemsList) { if (TheInventoryList.Contains(MySellingItem.KnownItemsSqlID)) { Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)TheInventoryList[MySellingItem.KnownItemsSqlID]; if (MySellingItem.pricesale > 0) { uint tempAmount = 0; if ((TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)) < MyInventoryItem.quantity) { tempAmount = MyInventoryItem.quantity; tempAmount = tempAmount - (TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID)); } else { continue; } str2 = tempAmount.ToString() + " " + MyInventoryItem.name + ":" + MySellingItem.pricesale.ToString() + "gc"; if (advertstr.Length + str2.Length + endm.Length < 140) { if (advertstr.Length > 8) { advertstr += ", "; } advertstr += str2; } } } } if (advertstr.Length > 8) { advertstr += "|" + endm; } else { advertstr = ""; } } else { //buying advertstr = "Buying:"; foreach (TradeHandler.WantedItem MyWantedItem in MyWantedItemsList) { if (TheInventoryList.Contains(MyWantedItem.KnownItemsSqlID)) { Inventory.inventory_item MyInventoryItem = (Inventory.inventory_item)TheInventoryList[MyWantedItem.KnownItemsSqlID]; if (MyWantedItem.pricepurchase > 0 && MyInventoryItem.quantity < MyWantedItem.maxquantity) { str2 = TheMySqlManager.GetKnownItemsname(MyWantedItem.KnownItemsSqlID) + ":" + MyWantedItem.pricepurchase.ToString() + "gc"; if (advertstr.Length + str2.Length + endm.Length < 140) { if (advertstr.Length > 7) { advertstr += ", "; } advertstr += str2; } } } else { if (MyWantedItem.pricepurchase > 0) { str2 = TheMySqlManager.GetKnownItemsname(MyWantedItem.KnownItemsSqlID) + ":" + MyWantedItem.pricepurchase.ToString() + "gc"; if (advertstr.Length + str2.Length + endm.Length < 140) { if (advertstr.Length > 7) { advertstr += ", "; } advertstr += str2; } } } } if (advertstr.Length > 7) { advertstr += "|" + endm; } else { advertstr = ""; } } } } if (advertstr != "") { TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#jc " + advertchannel.ToString())); TheTCPWrapper.Send(CommandCreator.RAW_TEXT("@" + advertstr)); TheTCPWrapper.Send(CommandCreator.RAW_TEXT("#lc " + advertchannel.ToString())); TheMySqlManager.advertlog("@@" + advertchannel.ToString() + " " + advertstr); string sql = "UPDATE bots SET lastadverttime = NOW() WHERE botid = " + Settings.botid; TheMySqlManager.raw_sql(sql); } advertstr = ""; } catch (Exception exception) { TheErrorHandler.writeErrorMessage("Exception raised in the advert handler..." + exception); } finally { } }
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[512]; if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); if (CommandArray[0] == "#invlist" || CommandArray[0] == "#il") { bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#invlist", Settings.botid); if (disabled == true) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "This command is disabled")); return; } int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid); if (rank < TheMySqlManager.GetCommandRank("#invlist", Settings.botid)) { 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; } char invFiller = TheMySqlManager.getInvFiller(); 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 (CommandArray.Length < 1) { goto WrongArguments; } System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList(); System.Collections.Hashtable MySellingItemsList = TheMySqlManager.GetSellingItemList(0); // sum up all inventory items if the items are on sale int i = 0; for (i = 0; i < 512; i++) { Inv[i] = "ZZZZZZZZZZZZZZZZ"; } int c = 0; System.Collections.SortedList TheInventoryList = new System.Collections.SortedList(); System.Collections.SortedList TheWornList = new System.Collections.SortedList(); int ii = 0; foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList) { ii++; if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36) { // if (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); } } if (MyInventoryItem.pos > 35 && MyInventoryItem.pos < 44) { TheWornList.Add(MyInventoryItem.SqlID, MyInventoryItem); } } int maxlen = 4; foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values) { // if (maxlen < MyInventoryItem.name.Length && MyInventoryItem.pos < 44) if (maxlen < MyInventoryItem.name.Length && MyInventoryItem.pos < 36) { maxlen = MyInventoryItem.name.Length; } } foreach (Inventory.inventory_item MyInventoryItem in TheWornList.Values) { if (maxlen <= MyInventoryItem.name.Length + 3) { maxlen = MyInventoryItem.name.Length + 3; } } str2 = ""; str1 = "["; str1 = str1.PadRight(maxlen + 16, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); str1 = "[ id |"; str2 = "quantity"; str2 = str2.PadRight(9, ' ') + "|"; str1 += str2; str2 = "name"; str2 = str2.PadRight(maxlen, ' '); str1 = str1 + str2; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); str1 = "["; str1 = str1.PadRight(maxlen + 16, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); // pm all summed up inventory items on sale c = 0; i = 1; foreach (Inventory.inventory_item MyInventoryItem in TheWornList.Values) { if (MyInventoryItem.pos < 44) { if (MyInventoryItem.pos < 36) { if (MyInventoryItem.is_stackable) { UsedSlots++; } else { UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity); } } str1 = ""; str2 = ""; str2 += MyInventoryItem.SqlID.ToString(); str2 = str2.PadLeft(4, i == 0 ? ' ' : invFiller); str2 = "[" + str2 + "|"; str1 = MyInventoryItem.quantity.ToString(); str1 = str1.PadLeft(9, i == 0 ? ' ' : invFiller); str2 += str1 + "|"; if (MyInventoryItem.pos > 35) { str1 = "{E}" + MyInventoryItem.name; } else { str1 = MyInventoryItem.name; } str1 = str1.PadRight(maxlen, i == 0 ? ' ' : invFiller); str1 = str2 + str1; //TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]); //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); Inv[c++] = str1; //i = 1 - i; } } foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values) { if (MyInventoryItem.pos < 44) { if (MyInventoryItem.pos < 36) { if (MyInventoryItem.is_stackable) { UsedSlots++; } else { UsedSlots = UsedSlots + (int)(MyInventoryItem.quantity); } } str1 = ""; str2 = ""; str2 += MyInventoryItem.SqlID.ToString(); str2 = str2.PadLeft(4, i == 0 ? ' ' : invFiller); str2 = "[" + str2 + "|"; str1 = MyInventoryItem.quantity.ToString(); str1 = str1.PadLeft(9, i == 0 ? ' ' : invFiller); str2 += str1 + "|"; if (MyInventoryItem.pos > 35) { str1 = "{E}" + MyInventoryItem.name; } else { str1 = MyInventoryItem.name; } str1 = str1.PadRight(maxlen, i == 0 ? ' ' : invFiller); str1 = str2 + str1; //TradeHandler.SellingItem MySellingItem = (TradeHandler.SellingItem)(MySellingItemsList[MyInventoryItem.SqlID]); //TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); Inv[c++] = str1; //i = 1 - i; } } int d; string str; 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 = c - 1; d >= 0; d--) for (d = 0; d < c; d++) { i = Inv[d].Length - 16; str = Inv[d].Substring(i); str += Inv[d].Substring(0, i); Inv[d] = str.Substring(str.Length - 16); if (filter == "" || str.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 = "[...".PadRight(maxlen, ' '); // foreach (string tempString in outFields) // { // outString += "|" + tempString; // } //} TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } else { //for (i = 1; i < CommandArray.Length; i++) { if (str.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 = "[...".PadRight(maxlen, ' '); // foreach (string tempString in outFields) // { // outString += "|" + tempString; // } //} TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); i = CommandArray.Length; } } } } int Phys = TheMySqlManager.GetBotPhysqiue(Settings.botid); int Coord = TheMySqlManager.GetBotCoordination(Settings.botid); int carry = (Phys + Coord) * 10; int UsedSpace = TheStats.MyCurrentCarryingAmt; int FreeSpace = carry - UsedSpace; str1 = "["; str1 = str1.PadRight(maxlen + 16, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); str1 = "["; str1 += FreeSpace.ToString() + " EMU Avail|"; str1 += (36 - UsedSlots).ToString() + " Open slot(s)"; if (rank > 89) { str1 += "|" + TheInventory.GetMoneyAmount().ToString() + " gc"; } str1 = str1.PadRight(maxlen + 16, ' '); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); str1 = "["; str1 = str1.PadRight(maxlen + 16, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str1)); return; } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #invlist command:")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#invlist ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[------------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #invlist ")); return; }
private void OnGotPM(object sender, BasicCommunication.MessageParser.Got_PM_EventArgs e) { string Message = e.Message.ToLower().Replace("\'", "\\\'").Replace("\"", "\\\""); string[] Inv = new string[64]; int maxlen = 4; bool validCommand = false; if (Message[0] != '#') { Message = "#" + Message; } string[] CommandArray = Message.Split(' '); if (CommandArray[0] == "#reserve") { bool disabled = TheMySqlManager.CheckIfCommandIsDisabled("#reserve", 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; } int rank = TheMySqlManager.GetUserRank(e.username, Settings.botid); if (rank < TheMySqlManager.GetCommandRank("#reserve", Settings.botid)) { 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; } if (CommandArray[1] == "withdraw") { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "Still working on this function...")); validCommand = true; } if (CommandArray[1] == "details") { TheMySqlManager.reservedDetails(Settings.botid, e.username); validCommand = true; } if (CommandArray[1] == "list") { validCommand = true; // list all of the inventory items that have reserved amounts //set up the current inventory list System.Collections.ArrayList MyInventoryList = TheInventory.GetInventoryList(); //set up a sorted inventory list for output purposes System.Collections.SortedList TheInventoryList = new System.Collections.SortedList(); //loop through the inventory finding reserved amounts foreach (Inventory.inventory_item MyInventoryItem in MyInventoryList) { //find the largest name length for output purposes if (maxlen < MyInventoryItem.name.Length && (MyInventoryItem.pos < 36)) { maxlen = MyInventoryItem.name.Length; } //if it's not in the output array, put it there if (TheInventoryList.Contains(MyInventoryItem.SqlID) && MyInventoryItem.pos < 36) { //add the item quantities (these should be the unstackables...) 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); } } } //loop through the storage finding reserved amounts System.Collections.ArrayList MyStorageList = TheStorage.GetStorageList(); foreach (Storage.StorageItem MyStorageItem in MyStorageList) { if (maxlen < MyStorageItem.name.Length) { maxlen = MyStorageItem.name.Length; } if (TheInventoryList.Contains(MyStorageItem.knownItemsID)) { //already in the list, do nothing since storage quantity is already the total //and it repeats, kinda like an unstackable item } else { Inventory.inventory_item MyInventoryItem = new Inventory.inventory_item(); MyInventoryItem.name = MyStorageItem.name; MyInventoryItem.SqlID = MyStorageItem.knownItemsID; MyInventoryItem.quantity = MyStorageItem.quantity; MyInventoryItem.reservedQuantity = MyStorageItem.reservedQuantity; TheInventoryList.Add(MyInventoryItem.SqlID, MyInventoryItem); } } // pm the reserved items string str = ""; string msg = ""; str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); foreach (Inventory.inventory_item MyInventoryItem in TheInventoryList.Values) { uint reservedQuantity = TheMySqlManager.ReservedAmount(MyInventoryItem.SqlID); if (MyInventoryItem.pos < 36 && reservedQuantity > 0) { msg = "["; msg += MyInventoryItem.name + " " + reservedQuantity + " of " + MyInventoryItem.quantity; TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, msg)); } } str = "["; str = str.PadRight(maxlen + 27, '-'); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, str)); } if (CommandArray.Length > 2) { validCommand = true; try { if (CommandArray[1] == "delete") { Int32 rowIndex = Int32.Parse(CommandArray[2]); if (TheMySqlManager.reservedDelete(Settings.botid, e.username, rowIndex)) { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Row Deleted.")); } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Index not found.")); } } else { Int32 numberToReserve = Int32.Parse(CommandArray[1]); int i; string itemName = ""; for (i = 2; i < CommandArray.Length; i++) { itemName += CommandArray[i] + " "; } int itemId = TheMySqlManager.GetItemID(itemName, false); if (itemId > 0) { if (TheMySqlManager.reserveItem(itemId, (uint)numberToReserve, e.username) == true) { TheTradeHandler.AddTrade(itemId, 0, (uint)numberToReserve, "reserved"); TradeHandler.TradeLogItem myItem = new TradeHandler.TradeLogItem(); myItem.KnownItemsSqlID = itemId; myItem.quantity = (uint)numberToReserve; myItem.action = "reserved by"; TheMySqlManager.LogTrade(myItem, e.username, Settings.botid, true); TheInventory.requestInventory(); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[You just reserved " + myItem.quantity + " " + TheMySqlManager.GetKnownItemsname(myItem.KnownItemsSqlID))); } else //probably never get to this one... { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!")); } } else { TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Item not found!")); } } } catch { goto WrongArguments; } } else { if (!validCommand) { goto WrongArguments; } } } return; WrongArguments: TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Here is the usage of the #reserve command: ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[#reserve <list>[withdraw] <amount item> ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve list ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve amount item ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve details ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[Example: #reserve delete <idx>* ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[*<idx> provided by #reserve details command. ")); TheTCPWrapper.Send(CommandCreator.SEND_PM(e.username, "[----------------------------------------------------")); return; }