Exemplo n.º 1
0
        private static void OnVendorSell(PacketReader pvSrc, PacketHandlerEventArgs args)
        {
            if (!Engine.MainWindow.SellCheckBox.Checked)             // Filtro disabilitato
            {
                return;
            }

            Assistant.Item bag = new Assistant.Item(SellBag);
            if (bag == null)             // Verifica HotBag
            {
                AddLog("Invalid or not accessible Container");
                return;
            }

            int  total  = 0;
            uint serial = pvSrc.ReadUInt32();

            Assistant.Mobile vendor = Assistant.World.FindMobile(serial);
            if (vendor == null)
            {
                Assistant.World.AddMobile(vendor = new Assistant.Mobile(serial));
            }

            int count = pvSrc.ReadUInt16();

            if (count == 0)             // Il vendor non compra nulla
            {
                return;
            }

            int sold = 0;

            List <Assistant.SellListItem> list = new List <Assistant.SellListItem>(count);                              // Lista item checkati per vendita (non so dove sia dichiarata)
            List <RazorEnhanced.SellAgent.SellAgentItem> templist = new List <RazorEnhanced.SellAgent.SellAgentItem>(); // Lista temporanea per controlli amount

            AddLog("Container: 0x" + SellBag.ToString("X8"));

            for (int i = 0; i < count; i++)             // Scansione item in lista menu vendor
            {
                uint   ser    = pvSrc.ReadUInt32();
                ushort gfx    = pvSrc.ReadUInt16();
                ushort hue    = pvSrc.ReadUInt16();
                ushort amount = pvSrc.ReadUInt16();
                ushort price  = pvSrc.ReadUInt16();
                pvSrc.ReadString(pvSrc.ReadUInt16());                 //name

                Assistant.Item item = Assistant.World.FindItem(ser);

                List <SellAgent.SellAgentItem> items = Settings.SellAgent.ItemsRead(SellListName);

                foreach (SellAgentItem sellItem in items)                 // Scansione item presenti in lista agent item
                {
                    if (!sellItem.Selected)
                    {
                        continue;
                    }

                    if (gfx != sellItem.Graphics || (item == null || item == bag || !item.IsChildOf(bag)) || !RazorEnhanced.SellAgent.ColorCheck(sellItem.Color, hue))
                    {
                        continue;
                    }

                    int  amountLeft  = int.MaxValue;
                    int  index       = 0;
                    bool alreadySold = false;

                    for (int y = 0; y < templist.Count; y++)                     // Controllo che non ho gia venduto item simili
                    {
                        if (templist[y].Graphics != gfx || !RazorEnhanced.SellAgent.ColorCheck(templist[y].Color, hue))
                        {
                            continue;
                        }

                        alreadySold = true;
                        amountLeft  = templist[y].Amount;
                        index       = y;
                    }

                    if (amountLeft == int.MaxValue)                     // Valore limite e inizzializzazione
                    {
                        amountLeft = sellItem.Amount;
                    }

                    if (amountLeft <= 0)
                    {
                        continue;
                    }

                    if (alreadySold)                     // Gia venduto oggetto stessa grafica
                    {
                        AddLog("Item match: 0x" + sellItem.Graphics.ToString("X4") + " - Amount: " + sellItem.Amount);
                        if (amount < amountLeft)                                // In caso che quella listata nel vendor sia minore di quella che voglio vendere vendo il massimo possibile
                        {
                            int amountTemp = amountLeft - amount;
                            list.Add(new SellListItem(ser, amount));                                        // Lista processo vendita
                            templist.RemoveAt(index);
                            templist.Insert(index, new SellAgentItem(sellItem.Name, gfx, amountTemp, sellItem.Color, sellItem.Selected));
                            total += amount * price;
                            sold  += amount;
                        }
                        else                                                               // Caso che quella listata nel vendor sia maggiore vendo solo quella mancante
                        {
                            list.Add(new SellListItem(ser, Convert.ToUInt16(amountLeft))); // Lista processo vendita
                            templist.RemoveAt(index);
                            templist.Insert(index, new SellAgentItem(sellItem.Name, gfx, 0, sellItem.Color, sellItem.Selected));
                            total += amountLeft * price;
                            sold  += amountLeft;
                        }
                    }
                    else                     // Mai venduto oggetto stessa grafica
                    {
                        AddLog("Item match: 0x" + sellItem.Graphics.ToString("X4") + " - Amount: " + sellItem.Amount);
                        if (amount < sellItem.Amount)                         // In caso che quella listata nel vendor sia minore di quella che voglio vendere vendo il massimo possibile
                        {
                            list.Add(new SellListItem(ser, amount));          // Lista processo vendita
                            templist.Add(new SellAgentItem(sellItem.Name, gfx, (sellItem.Amount - amount), sellItem.Color, sellItem.Selected));
                            total += amount * price;
                            sold  += amount;
                        }
                        else                                                                    // Caso che quella listata nel vendor sia maggiore vendo solo quella mancante
                        {
                            list.Add(new SellListItem(ser, Convert.ToUInt16(sellItem.Amount))); // Lista processo vendita
                            templist.Add(new SellAgentItem(sellItem.Name, gfx, 0, sellItem.Color, sellItem.Selected));
                            total += sellItem.Amount * price;
                            sold  += sellItem.Amount;
                        }
                    }
                }
            }

            if (list.Count <= 0)
            {
                return;
            }

            Assistant.Client.Instance.SendToServer(new VendorSellResponse(vendor, list));
            AddLog("Sold " + sold.ToString() + " items for " + total.ToString() + " gold coins");
            string message = "Enhanced Sell Agent: sold " + sold.ToString() + " items for " + total.ToString() + " gold coins";

            World.Player.Journal.Enqueue(new RazorEnhanced.Journal.JournalEntry(message, "System", 1, "Vendor", vendor.Serial));                      // Journal buffer
            World.Player.SendMessage(message);
            args.Block = true;
        }
Exemplo n.º 2
0
 public bool IsChildOf(object parent)
 {
     return(m_AssistantItem.IsChildOf(parent));
 }
Exemplo n.º 3
0
        public void Dress()
        {
            if (World.Player == null)
            {
                return;
            }

            int       skipped = 0, gone = 0, done = 0;
            ArrayList list         = new ArrayList();
            bool      remConflicts = Config.GetBool("UndressConflicts");

            if (World.Player.Backpack == null)
            {
                World.Player.SendMessage(LocString.NoBackpack);
                return;
            }

            if (Macros.MacroManager.AcceptActions)
            {
                Macros.MacroManager.Action(new Macros.DressAction(m_Name));
            }

            for (int i = 0; i < m_Items.Count; i++)
            {
                Item item = null;
                if (m_Items[i] is Serial)
                {
                    item = World.FindItem((Serial)m_Items[i]);
                    if (item == null)
                    {
                        gone++;
                    }
                    else
                    {
                        list.Add(item);
                    }
                }
                else if (m_Items[i] is ItemID)
                {
                    ItemID id = (ItemID)m_Items[i];

                    // search to make sure they are not already wearing this...
                    item = World.Player.FindItemByID(id);
                    if (item != null)
                    {
                        skipped++;
                    }
                    else
                    {
                        item = World.Player.Backpack.FindItemByID(id);
                        if (item == null)
                        {
                            gone++;
                        }
                        else
                        {
                            list.Add(item);
                        }
                    }
                }
            }

            foreach (Item item in list)
            {
                if (item.Container == World.Player)
                {
                    skipped++;
                }
                else if (item.IsChildOf(World.Player.Backpack) || item.RootContainer == null)
                {
                    Layer layer = GetLayerFor(item);
                    if (layer == Layer.Invalid || layer > Layer.LastUserValid)
                    {
                        continue;
                    }

                    if (remConflicts)
                    {
                        Item conflict = World.Player.GetItemOnLayer(layer);
                        if (conflict != null)
                        {
                            DragDropManager.DragDrop(conflict, FindUndressBag(conflict));
                        }

                        // try to also undress conflicting hand(s)
                        if (layer == Layer.RightHand)
                        {
                            conflict = World.Player.GetItemOnLayer(Layer.LeftHand);
                        }
                        else if (layer == Layer.LeftHand)
                        {
                            conflict = World.Player.GetItemOnLayer(Layer.RightHand);
                        }
                        else
                        {
                            conflict = null;
                        }

                        if (conflict != null && (conflict.IsTwoHanded || item.IsTwoHanded))
                        {
                            DragDropManager.DragDrop(conflict, FindUndressBag(conflict));
                        }
                    }
                    DragDropManager.DragDrop(item, World.Player, layer);
                    done++;
                }
            }

            if (done > 0)
            {
                World.Player.SendMessage(LocString.DressQueued, done);
            }
            if (skipped > 0)
            {
                World.Player.SendMessage(LocString.AlreadyDressed, skipped);
            }
            if (gone > 0)
            {
                World.Player.SendMessage(LocString.ItemsNotFound, gone);
            }
        }