Example #1
0
        public Trade(Client cli, TradeStartPacket tsp)
        {
            _c = cli;

            MyItems   = new List <TradeItem>();
            YourItems = new List <TradeItem>();

            MasterBuying  = TraderBot.Buying[_c].Select(item => new ItemStruct(item.Name, item.Qty, item.Alt, item.AltQty)).ToList();
            MasterSelling = TraderBot.Selling[_c].Select(item => new ItemStruct(item.Name, item.Qty)).ToList();

            isTrading = true;

            foreach (Item item in tsp.YourItems)
            {
                YourItems.Add(new TradeItem(item));
            }
            foreach (Item item in tsp.MyItems)
            {
                MyItems.Add(new TradeItem(item));
            }

            /*foreach (var item in YourItems)
             * {
             *      Console.WriteLine(item.GetName());
             * }*/
        }
Example #2
0
 public PZCustomer(TradeStartPacket ts)
 {
     name = ts.YourName;
     foreach (var item in ts.YourItems)
     {
         items.Add(new PZItem(item.ItemItem, 1));
     }
 }
Example #3
0
 private void OnTradeStart(TradeStartPacket tradeStart)
 {
     if (_request != null && tradeStart.PartnerName.Equals(_request.Name, StringComparison.CurrentCultureIgnoreCase))
     {
         Log($"Trade accepted by {tradeStart.PartnerName}");
         _request.OnAccept?.Invoke(_trade = new TradeEvent(this, tradeStart.ClientItems, tradeStart.PartnerItems));
         _request = null;
         return;
     }
     // wtf
     _net.SendPacket(new CancelTradePacket());
 }
Example #4
0
        public void OnTradeStart(Client client, Packet packet)
        {
            TradeStartPacket start = (TradeStartPacket)packet;

            if (_Enabled[client] && _Started[client])
            {
                Console.WriteLine("Trade Started with \"" + start.YourName + "\"");
                //CurrentTrade = new Trade(client, start);
                CurrentTrades[client] = new Trade(client, start);

                //if (CurrentTrade.HasItems())
                if (CurrentTrades[client].HasItems())
                {
                    Console.WriteLine("Have Item!");
                    // Wait 30 seconds and then cancel the trade if it is still going
                    PluginUtils.Delay(30000, new Action(() =>
                    {
                        if (CurrentTrades[client].isTrading)
                        {
                            client.SendToServer(Packet.Create(PacketType.CANCELTRADE));
                            CurrentTrades[client].isTrading = false;
                            Console.WriteLine("Canceling Trade Due To Time!");
                        }
                    }));
                }
                else
                {
                    Console.WriteLine("No Have Item!");
                    // Wait 4 seconds and then cancel the trade
                    PluginUtils.Delay(4000, new Action(() =>
                    {
                        if (CurrentTrades[client].isTrading)
                        {
                            client.SendToServer(Packet.Create(PacketType.CANCELTRADE));
                            CurrentTrades[client].isTrading = false;
                            Console.WriteLine("Canceling Trade Due To Missing Items!");
                        }
                    }));
                }
            }
        }
Example #5
0
        public void TS(Client client, Packet packet)
        {
            TradeStartPacket ts = (TradeStartPacket)packet;

            PZClient cl = clientlist[IndexOfClient(client)];

            cl.InTrade = true;
            if (cl.enabled)
            {
                cl.customer = new PZCustomer(ts);
                cl.last     = client.PlayerData.Slot;
                cl.CancelTimerStart();
                if (!cl.curTrade.CheckBuying(cl, ts.YourItems))
                {
                    PlayerTextPacket pt = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT);
                    try
                    {
                        pt.Text = @"/tell " + ts.YourName + " You don't have " + cl.curTrade.BuyingToString();
                        client.SendToServer(pt);
                    }
                    catch
                    {
                        Console.WriteLine("Please define trades for \"" + client.PlayerData.Name + "\" to do");
                    }

                    CancelTradePacket ct = (CancelTradePacket)Packet.Create(PacketType.CANCELTRADE);
                    client.SendToServer(ct);
                    cl.InTrade = false;
                }
                else
                {
                    Console.WriteLine("Found correct stuff!");
                    cl.InTrade = true;
                    cl.SelectSelling();
                }
            }
        }
Example #6
0
 private void HandleTradeStart(TradeStartPacket packet)
 {
     Module.OnTradeConfirm(this, Module.GetClient(packet.DestinationPlayerID));
 }