Ejemplo n.º 1
0
        public PZClient ToClient()
        {
            PZClient cl = null;

            for (int i = TradeBotCore.clientlist.Count - 1; i >= 0; i--)
            {
                if (TradeBotCore.clientlist[i].client.PlayerData.Name == this.clientname)
                {
                    cl = TradeBotCore.clientlist[i];
                    // TradeBotCore.clientlist.RemoveAt(i);
                }
            }
            if (cl == null)
            {
                return(null);
            }

            cl.enabled     = this.enabled;
            cl.tradequeue  = this.tradequeue;
            cl.last        = this.last;
            cl.index       = this.index;
            cl.spamenabled = this.spamenabled;

            //KRelayMove.Core.clientlist[KRelayMove.Core.IndexOfClient(cl.client)].StartMove(this.clientloc);

            return(cl);
        }
Ejemplo n.º 2
0
        public static void FinCycle(PZClient client)
        {
            if (false)
            {
#pragma warning disable CS0162 // Unreachable code detected
                switch (HelperTypeof(client))
                {
                case HelperType.neutral:
                    return;

                case HelperType.output:
                    HandleOutput(GetHelper <PZOutput>(client));
                    break;

                case HelperType.converter:
                    HandleConverter(GetHelper <PZConverter>(client));
                    break;

                case HelperType.storage:
                    HandleStorage(GetHelper <PZStorage>(client));
                    break;
                }
#pragma warning restore CS0162 // Unreachable code detected
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 3
0
        public static HelperType HelperTypeof(PZClient client)
        {
            foreach (var item in slist)
            {
                if (item.client.ToString() == client.ToString())
                {
                    return(HelperType.storage);
                }
            }

            foreach (var item in clist)
            {
                if (item.client.ToString() == client.ToString())
                {
                    return(HelperType.converter);
                }
            }

            foreach (var item in olist)
            {
                if (item.client.ToString() == client.ToString())
                {
                    return(HelperType.output);
                }
            }

            return(HelperType.neutral);
        }
Ejemplo n.º 4
0
        public void Com(Client client, string command, string[] args)
        {
            PZClient cl = clientlist[IndexOfClient(client)];

            if (args.Length == 0)
            {
                PluginUtils.ShowGUI(new TradeBotSettings(clientlist[IndexOfClient(client)]));
            }
            try
            {
                if (args[0] == "stopspam" || args[0] == "stop")
                {
                    cl.spamenabled = false;
                    if (args[0] == "stop")
                    {
                        cl.enabled = false;
                    }
                }
                if (args[0] == "startspam" || args[0] == "start")
                {
                    cl.spamenabled = !false;
                    if (args[0] == "start")
                    {
                        cl.enabled = !false;
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 5
0
        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++;
        }
Ejemplo n.º 6
0
        public SnapshotClient(PZClient cl)
        {
            this.spamenabled = cl.spamenabled;
            this.enabled     = cl.enabled;
            this.tradequeue  = cl.tradequeue;
            this.last        = cl.last;
            this.index       = cl.index;

            this.clientname = cl.client.PlayerData.Name;
            this.clientloc  = cl.client.PlayerData.Pos;
        }
Ejemplo n.º 7
0
        public static void GiveItem(PZClient giver, PZClient reciever, PZItem item)
        {
            //int tries = 0;
            giver.enabled        = false;
            reciever.enabled     = false;
            reciever.spamenabled = false;
            giver.spamenabled    = false;
            int start = reciever.CountItem(item.ID);

            GiveItemRetry(giver, reciever, item, start, 0);
        }
Ejemplo n.º 8
0
        public TradeBotSettings(PZClient cl)
        {
            client = cl;
            InitializeComponent();
            UpdtListBox();
            //tradeSel = new TradeSel(cl.client.PlayerData.Name);
            //tradeSel.Dock = DockStyle.Fill;
            //this.panel1.Controls.Add(tradeSel);

            this.Text           += " - " + cl.client.PlayerData.Name;
            numericUpDown1.Value = client.index;
        }
Ejemplo n.º 9
0
        public void TD(Client client, Packet packet)
        {
            TradeDonePacket p  = (TradeDonePacket)packet;
            PZClient        cl = clientlist[IndexOfClient(client)];

            cl.InTrade = false;
            if (cl.enabled)
            {
                if (p.Message.ToLower().Contains("successful"))
                {
                    cl.index++;
                }
            }
        }
Ejemplo n.º 10
0
        public static T GetHelper <T>(PZClient client)
        {
            object ret = null;

            if (typeof(T) == typeof(PZStorage))
            {
                foreach (var item in slist)
                {
                    if (item.client.ToString() == client.ToString())
                    {
                        ret = item;
                    }
                }
            }

            if (typeof(T) == typeof(PZOutput))
            {
                foreach (var item in olist)
                {
                    if (item.client.ToString() == client.ToString())
                    {
                        ret = item;
                    }
                }
            }

            if (typeof(T) == typeof(PZConverter))
            {
                foreach (var item in clist)
                {
                    if (item.client.ToString() == client.ToString())
                    {
                        ret = item;
                    }
                }
            }

            return((T)ret);
        }
Ejemplo n.º 11
0
        public void TC(Client client, Packet packet)
        {
            TradeChangedPacket p  = (TradeChangedPacket)packet;
            PZClient           cl = clientlist[IndexOfClient(client)];

            cl.customer.UpdateItems(p.Offers);
            if (cl.enabled)
            {
                Console.WriteLine("--------------------------");
                int    totlefts = 0;
                string msg      = "";
                foreach (var item in cl.CheckCustomer(true))
                {
                    Console.WriteLine(item.ToString() + " - " + item.amount);
                    totlefts += item.amount;
                    if (item.amount > 0)
                    {
                        msg += item.amount + " " + item.ToString() + ";";
                    }
                }
                Console.WriteLine("Verdict: " + (totlefts <= 0));
                if (totlefts <= 0)
                {
                    cl.SelectSelling();
                    AcceptTradePacket ac = (AcceptTradePacket)Packet.Create(PacketType.ACCEPTTRADE);
                    ac.YourOffers = p.Offers;
                    ac.MyOffers   = cl.GetToSel();
                    cl.client.SendToServer(ac);
                }
                else
                {
                    PlayerTextPacket ptpkt = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT);
                    ptpkt.Text = "/t " + cl.customer.name + " An extra: " + msg + " plz!";
                    cl.client.SendToServer(ptpkt);
                }
            }
        }
Ejemplo n.º 12
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();
                }
            }
        }
Ejemplo n.º 13
0
 public GiveDialog(PZClient c)
 {
     client = c;
     InitializeComponent();
 }
Ejemplo n.º 14
0
        public void CT(Client client, Packet packet)
        {
            PZClient cl = clientlist[IndexOfClient(client)];

            cl.InTrade = false;
        }
Ejemplo n.º 15
0
 public PZConverter(PZClient c, PZItem i, PZItem o)
 {
     client = c;
     input  = i;
     output = o;
 }
Ejemplo n.º 16
0
 public PZOutput(PZClient cl, int outitem)
 {
     client     = cl;
     outputitem = outitem;
 }
Ejemplo n.º 17
0
        public bool CheckBuying(PZClient cl, Item[] yitems)
        {
            int no = 0;

            foreach (PZItem item in cl.curTrade.buying)
            {
                if (item.Check(yitems))
                {
                    no++;
                }
            }

            #region alts (depr)

            /*
             *          if (no < cl.curTrade.buying.Count)
             *          {
             *              int altindex = 0;
             *              foreach (var alt in cl.curTrade.alts)
             *              {
             *                  int na = 0;
             *                  foreach (PZItem item in alt.buying)
             *                  {
             *                      if (item.Check(yitems)) na++;
             *                  }
             *
             *                  if (na >= alt.buying.Count)
             *                  {
             *                      Console.WriteLine("Changing to alternative!");
             *                      continue;
             *                  }
             *                  else if (altindex == cl.curTrade.alts.Count - 1)
             *                  {
             *                      altindex = -1;
             *                      continue;
             *                  }
             *
             *                  altindex++;
             *              }
             *
             *
             *              if (altindex != -1)
             *              {
             *                  PZTrade temp = cl.curTrade;
             *                  List<PZTrade> olalts = cl.curTrade.alts;
             *                  cl.curTrade = cl.curTrade.alts[altindex];
             *                  olalts.RemoveAt(altindex);
             *                  olalts.Add(temp);
             *                  cl.curTrade.alts = olalts;
             *
             *
             *                  Console.WriteLine("Switched from: " + temp.ToString());
             *                  Console.WriteLine("To alternative: " + cl.curTrade.ToString());
             *                  Console.WriteLine("------[Extra Details]----");
             *                  foreach (var item in cl.curTrade.alts)
             *                  {
             *                      Console.WriteLine("Alt: " + item.ToString());
             *                  }
             *                  return true;
             *              }
             *              else
             *              {
             *                  return false;
             *              }
             *          }
             *          else
             *          {
             *              return true;
             *          }
             *          //*/
            #endregion
            return(no >= cl.curTrade.buying.Count);
        }
Ejemplo n.º 18
0
 public PZStorage(PZClient cl, int initem)
 {
     client    = cl;
     inputitem = initem;
 }