public void ChangeTrade(RealmTime time, ChangeTradePacket pkt) { if (trade != pkt.Offers) { tradeAccepted = false; tradeTarget.tradeAccepted = false; trade = pkt.Offers; for (int i = 0; i < pkt.Offers.Length; i++) { if (pkt.Offers[i]) { if (Inventory[i].Soulbound || Inventory[i].AdminOnly) { trade[i] = false; } else { trade[i] = true; } } } tradeTarget.client.SendPacket(new TradeChangedPacket { Offers = trade }); } }
public void ChangeTrade(RealmTime time, ChangeTradePacket pkt) { // validate input if (tradeTarget == null) { this.Client.SendPacket(new TradeDonePacket { Result = 1, Message = "Trade cancelled." }); trade = null; tradeAccepted = false; return; } if (trade != pkt.Offers) { tradeAccepted = false; tradeTarget.tradeAccepted = false; trade = pkt.Offers; tradeTarget.psr.SendPacket(new TradeChangedPacket { Offers = trade }); } }
public void SendSel(bool[] sels) { ChangeTradePacket ch = (ChangeTradePacket)Packet.Create(PacketType.CHANGETRADE); ch.Offers = sels; client.SendToServer(ch); }
private static void GiveItemRetry(PZClient giver, PZClient reciever, PZItem item, int start, int no) { int na = no + 1; bool[] sel = PZClient.GetToSel(giver.client, item); RequestTradePacket req = (RequestTradePacket)Packet.Create(PacketType.REQUESTTRADE); req.Name = reciever.ToString(); giver.client.SendToServer(req); req.Name = giver.ToString(); reciever.client.SendToServer(req); ChangeTradePacket cht = (ChangeTradePacket)Packet.Create(PacketType.CHANGETRADE); cht.Offers = sel; giver.client.SendToServer(cht); AcceptTradePacket atpkt = (AcceptTradePacket)Packet.Create(PacketType.ACCEPTTRADE); atpkt.MyOffers = sel; atpkt.YourOffers = new bool[12]; giver.client.SendToServer(atpkt); atpkt.MyOffers = new bool[12]; atpkt.YourOffers = sel; reciever.client.SendToServer(atpkt); Console.WriteLine(giver.ToString() + " gave " + item + " to " + reciever); PluginUtils.Delay(2000, new Action(() => { int now = reciever.CountItem(item.ID); int addition = now - start; if (addition < item.amount) { Console.WriteLine("[ERROR]" + (item.amount - addition) + " " + item.ActualName() + " failed to be recieved so trying again"); if (na <= 7) { PluginUtils.Delay(500, new Action(() => GiveItemRetry(giver, reciever, item, start, na))); } else { Console.WriteLine("Tried over 7 times, give up!"); } } else { Console.WriteLine("Recieve success!"); PluginUtils.Delay(500, new Action(() => { giver.enabled = true; reciever.enabled = true; reciever.spamenabled = true; giver.spamenabled = true; })); } })); na++; }
public void ChangeTrade(RealmTime time, ChangeTradePacket pkt) { this.tradeAccepted = false; tradeTarget.tradeAccepted = false; this.trade = pkt.Offers; tradeTarget.psr.SendPacket(new TradeChangedPacket() { Offers = this.trade }); }
public void ChangeTrade(RealmTime time, ChangeTradePacket pkt) { TradeHandler?.TradeChanged(this, pkt.Offers); }
public void SelectItems() { int x = 0; // Check if they selected all the items we are buying and if they did 2x or 3x or 4x List <ItemStruct> tmpYList = MasterBuying.Select(itemb => new ItemStruct(itemb.Name, itemb.Qty, itemb.Alt, itemb.AltQty)).ToList(); for (int j = 4; j < YourItems.Count; j++) { if (YourItems[j].selected) { for (int i = 0; i < tmpYList.Count; i++) { if (tmpYList[i].Name == YourItems[j].GetName()) { if (tmpYList[i].Qty > 0) { tmpYList[i].Qty--; } break; } else if (tmpYList[i].Alt == YourItems[j].GetName()) { if (tmpYList[i].AltQty > 0) { tmpYList[i].AltQty--; } break; } } } bool all = true; for (int i = 0; i < tmpYList.Count; i++) { if (tmpYList[i].Qty > 0) { if (tmpYList[i].AltQty == -1) { all = false; } else { if (tmpYList[i].AltQty > 0) { all = false; } } } } if (all) { x++; for (int i = 0; i < tmpYList.Count; i++) { if (tmpYList[i].Qty == 0) { tmpYList[i] = new ItemStruct(MasterBuying[i].Name, MasterBuying[i].Qty, MasterBuying[i].Alt, tmpYList[i].AltQty); } else if (tmpYList[i].AltQty == 0) { tmpYList[i] = new ItemStruct(MasterBuying[i].Name, tmpYList[i].Qty, MasterBuying[i].Alt, MasterBuying[i].AltQty); } } //tmpYList = MasterBuying.Select(itemb => new ItemStruct(itemb.Name, itemb.Qty, itemb.Alt, itemb.AltQty)).ToList(); } } // Clear all the selected items from our list for (int j = 4; j < MyItems.Count; j++) { MyItems[j].selected = false; } // Select all the items we are trading List <ItemStruct> tmpMList = MasterSelling.Select(itemb => new ItemStruct(itemb.Name, itemb.Qty)).ToList(); // Change the quantity to match the multiplier for (int i = 0; i < tmpMList.Count; i++) { tmpMList[i].Qty *= x; } for (int j = 4; j < MyItems.Count; j++) { if (!MyItems[j].selected) { for (int i = 0; i < tmpMList.Count; i++) { if (tmpMList[i].Name == MyItems[j].GetName()) { if (tmpMList[i].Qty > 0) { tmpMList[i].Qty--; MyItems[j].selected = true; } break; } } } } bool[] offer = new bool[12]; for (int i = 0; i < 12; i++) { if (MyItems[i].selected) { offer[i] = true; } else { offer[i] = false; } } //Console.WriteLine(_c.PlayerData.Name + " Sending ChangeTrade"); // Send the change ChangeTradePacket ctp = (ChangeTradePacket)Packet.Create(PacketType.CHANGETRADE); ctp.Offers = offer; _c.SendToServer(ctp); }
public bool Good() { int x = 0; // Check if they selected all the items we are buying and if they did 2x or 3x or 4x List <ItemStruct> tmpYList = MasterBuying.Select(itemb => new ItemStruct(itemb.Name, itemb.Qty, itemb.Alt, itemb.AltQty)).ToList(); foreach (var item in YourItems) { if (item.selected) { for (int i = 0; i < tmpYList.Count; i++) { if (tmpYList[i].Name == item.GetName()) { if (tmpYList[i].Qty > 0) { tmpYList[i].Qty--; } break; } else if (tmpYList[i].Alt == item.GetName()) { if (tmpYList[i].AltQty > 0) { tmpYList[i].AltQty--; } break; } } } bool all = true; for (int i = 0; i < tmpYList.Count; i++) { if (tmpYList[i].Qty > 0) { if (tmpYList[i].AltQty == -1) { all = false; } else { if (tmpYList[i].AltQty > 0) { all = false; } } } } if (all) { x++; // Reset the Qty of whichever one just hit 0 for (int i = 0; i < tmpYList.Count; i++) { if (tmpYList[i].Qty == 0) { tmpYList[i] = new ItemStruct(MasterBuying[i].Name, MasterBuying[i].Qty, MasterBuying[i].Alt, tmpYList[i].AltQty); } else if (tmpYList[i].AltQty == 0) { tmpYList[i] = new ItemStruct(MasterBuying[i].Name, tmpYList[i].Qty, MasterBuying[i].Alt, MasterBuying[i].AltQty); } } //tmpYList = MasterBuying.Select(itemb => new ItemStruct(itemb.Name, itemb.Qty, itemb.Alt, itemb.AltQty)).ToList(); } } if (x == 0) { return(false); } bool changes = false; List <ItemStruct> tmpMList = MasterSelling.Select(itemb => new ItemStruct(itemb.Name, itemb.Qty)).ToList(); // Change the quantity to match the multiplier for (int i = 0; i < tmpMList.Count; i++) { tmpMList[i].Qty *= x; } // Check if we selected the right number of items foreach (var item in MyItems) { if (item.selected) { bool found = false; for (int i = 0; i < tmpMList.Count; i++) { if (tmpMList[i].Name == item.GetName()) { if (tmpMList[i].Qty > 0) { found = true; tmpMList[i].Qty--; } break; } } if (!found) { // This item shouldnt of been selected? item.selected = false; changes = true; } } } if (changes) { bool[] offer = new bool[12]; for (int i = 0; i < 12; i++) { if (MyItems[i].selected) { offer[i] = true; } else { offer[i] = false; } } //Console.WriteLine(_c.PlayerData.Name + " Sending ChangeTrade"); // Send the change ChangeTradePacket ctp = (ChangeTradePacket)Packet.Create(PacketType.CHANGETRADE); ctp.Offers = offer; _c.SendToServer(ctp); return(false); } return(true); }