Exemplo n.º 1
0
        public static List <SqlDataProvider.Data.ItemInfo> SpiltGoodsMaxCount(SqlDataProvider.Data.ItemInfo itemInfo)
        {
            List <SqlDataProvider.Data.ItemInfo> list = new List <SqlDataProvider.Data.ItemInfo>();
            int num1 = 0;

            while (num1 < itemInfo.Count)
            {
                int num2 = itemInfo.Count < itemInfo.Template.MaxCount ? itemInfo.Count : itemInfo.Template.MaxCount;
                SqlDataProvider.Data.ItemInfo itemInfo1 = itemInfo.Clone();
                itemInfo1.Count = num2;
                list.Add(itemInfo1);
                num1 += itemInfo.Template.MaxCount;
            }
            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 拆分物品
        /// </summary>
        /// <param name="item"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public bool SplitItem(ItemInfo item, int count, int toSlot)
        {
            if (item.Count > count  && _items[toSlot] == null)
            {
                ItemInfo clone = item.Clone();
                clone.ItemID = -1;
                clone.Count = count;
                //clone.Place = toSlot;
                if (AddItem(clone) != -1)
                {
                    UseItem(item);
                    UseItem(clone);
                    item.Count -= count;
                    _player.Out.SendUpdateInventorySlot(item.Place, true, item,_bagType);
                    _player.Out.SendUpdateInventorySlot(clone.Place, true, clone,_bagType);
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 3
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            eBageType       bageType   = (eBageType)packet.ReadByte();
            int             slot       = packet.ReadInt();
            eBageType       toBageType = (eBageType)packet.ReadByte();
            int             toSlot     = packet.ReadInt();
            int             count      = packet.ReadInt();
            PlayerInventory bag        = client.Player.GetInventory(bageType);
            PlayerInventory inventory  = client.Player.GetInventory(toBageType);

            if (toSlot < 0)
            {
                if ((inventory.BagType == (int)eBageType.Bank) || (inventory.BagType == (int)eBageType.PropBag))
                {
                    toSlot = inventory.FindFirstEmptySlot(0);
                }
                else
                {
                    toSlot = inventory.FindFirstEmptySlot(31);
                }
            }
            //==================================
            if (count > 0)
            {
                if ((bag == null) || (bag.GetItemAt(slot) == null))
                {
                    return(0);
                }
                if ((bageType == toBageType) && (slot != -1))
                {
                    if (bag.GetItemAt(slot).Count >= count)
                    {
                        Console.WriteLine("-----Stage 1 !");
                        bag.MoveItem(slot, toSlot, count);
                    }
                    else
                    {
                        Console.WriteLine("--" + client.Player.Account + " Hack = CE");
                        bag.MoveItem(slot, toSlot, bag.GetItemAt(slot).Count);
                    }
                    return(1);
                }

                if ((slot == -1) && (toSlot != -1))
                {
                    Console.WriteLine("-----Stage 2 !");
                    bag.RemoveItemAt(toSlot);
                    return(1);
                }

                if (((((slot != -1) && (toSlot == -1)) &&
                      ((bageType != eBageType.CaddyBag) &&
                       (toBageType != eBageType.Bank))) &&
                     (bageType != eBageType.Store)) &&
                    (toBageType != eBageType.Store))
                {
                    if (bageType == eBageType.MainBag)
                    {
                        Console.WriteLine("-----Stage 3 !");
                        bag.AddItem(client.Player.GetItemAt(bageType, slot), 31);
                    }
                    else
                    {
                        Console.WriteLine("-----Stage 4 !");
                        //bag.AddItem(client.Player.GetItemAt(bageType, slot), 0);
                        client.Out.SendMessage(eMessageType.Normal, LanguageMgr.GetTranslation("Bag.Full"));
                    }
                    return(1);
                }

                if ((((slot != -1) && (toBageType != bageType)) && (toBageType != eBageType.Store)) && (toBageType != eBageType.MainBag))
                {
                    ConsortiaInfo info = ConsortiaMgr.FindConsortiaInfo(client.Player.PlayerCharacter.ConsortiaID);
                    if (info != null)
                    {
                        if (toBageType == eBageType.Store)
                        {
                        }
                        Console.WriteLine("-----Stage 5 !");
                        bag.MoveToStore(bag, slot, toSlot, inventory, info.StoreLevel * 10);
                        return(1);
                    }
                }

                if ((toBageType == eBageType.Store) || (bageType == eBageType.Store))
                {
                    SqlDataProvider.Data.ItemInfo itemAt = client.Player.GetItemAt(bageType, slot);
                    if ((itemAt != null) && (itemAt.Count > 1))
                    {
                        itemAt.Count -= count;
                        bag.UpdateItem(itemAt);
                        SqlDataProvider.Data.ItemInfo item = itemAt.Clone();
                        item.Count = count;
                        if (inventory.GetItemAt(toSlot) == null)
                        {
                            Console.WriteLine("-----Stage 6 !");
                            inventory.AddItemTo(item, toSlot);
                        }
                        else
                        {
                            SqlDataProvider.Data.ItemInfo itemByTemplateID = bag.GetItemByTemplateID(0, inventory.GetItemAt(toSlot).TemplateID);
                            if (itemByTemplateID == null)
                            {
                                Console.WriteLine("-----Stage 7 !");
                                bag.MoveToStore(inventory, toSlot, bag.FindFirstEmptySlot(0), bag, 999);
                            }
                            else
                            {
                                Console.WriteLine("-----Stage 8 !");
                                itemByTemplateID.Count++;
                                bag.UpdateItem(itemByTemplateID);
                                inventory.RemoveItemAt(toSlot);
                            }
                            Console.WriteLine("-----Stage 9 !");
                            inventory.AddItemTo(item, toSlot);
                        }
                    }
                    else
                    {
                        if ((((toBageType != eBageType.Store) && (toBageType != eBageType.MainBag)) && ((bag.GetItemAt(slot) != null) && (bag.GetItemAt(slot).Template.CategoryID == 7))) && (((toSlot > 0) && (toSlot < 31)) && (toSlot != 6)))
                        {
                            return(1);
                        }
                        try
                        {
                            Console.WriteLine("-----Stage 10 !");
                            bag.MoveToStore(bag, slot, toSlot, inventory, 50);
                        }
                        catch (Exception)
                        {
                            LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).InfoFormat("ERROR USER CHANGEITEM placce: {0},toplace: {1},bagType: {2},ToBagType {3}", new object[] { slot, toSlot, bageType, toBageType });
                            LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).InfoFormat("item :{0}, toitem {1}", bag.GetItemAt(slot), inventory.GetItemAt(toSlot));
                        }
                    }
                    return(1);
                }
                if ((toBageType == eBageType.MainBag) && (bageType == eBageType.Bank))
                {
                    Console.WriteLine("-----Stage 11!");
                    bag.MoveToStore(bag, slot, toSlot, inventory, 50);
                    return(1);
                }
            }
            //==================================
            return(0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 拆分物品
        /// </summary>
        /// <param name="item"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public bool SplitItem(ItemInfo item, int count, int toSlot)
        {
            if (_bagType == 11)
            {
                ConsortiaInfo info = ConsortiaMgr.FindConsortiaInfo(_player.PlayerCharacter.ConsortiaID);
                if (info != null || toSlot >= info.StoreLevel * 10)
                {
                    _player.Out.SendUpdateInventorySlot(item.Place, true, item, _bagType);
                    return false;
                }
            }

            if (item.Count > count && m_items[toSlot] == null)
            {
                ItemInfo clone = item.Clone();
                clone.ItemID = -1;
                clone.Count = count;
                if (AddItemTo(clone, toSlot) != -1)
                {
                    item.Count -= count;
                    _player.Out.SendUpdateInventorySlot(item.Place, true, item, _bagType);
                    _player.Out.SendUpdateInventorySlot(clone.Place, true, clone, _bagType);
                    return true;
                }
            }
            else
            {
                _player.Out.SendUpdateInventorySlot(item.Place, true, item, _bagType);
            }

            return false;
        }
Exemplo n.º 5
0
        public virtual bool AddTemplate(ItemInfo cloneItem, int count, int minSlot, int maxSlot)
        {
            if (cloneItem == null) return false;
            ItemTemplateInfo template = cloneItem.Template;
            if (template == null) return false;
            if (count <= 0) return false;
            if (minSlot < m_beginSlot || minSlot > m_capalility - 1) return false;
            if (maxSlot < m_beginSlot || maxSlot > m_capalility - 1) return false;
            if (minSlot > maxSlot) return false;


            lock (m_lock)
            {
                List<int> changedSlot = new List<int>();
                int itemcount = count;

                for (int i = minSlot; i <= maxSlot; i++)
                {
                    ItemInfo item = m_items[i];
                    if (item == null)
                    {
                        itemcount -= template.MaxCount;
                        changedSlot.Add(i);
                    }
                    else if (m_autoStack && cloneItem.CanStackedTo(item))
                    {
                        itemcount -= (template.MaxCount - item.Count);
                        changedSlot.Add(i);
                    }
                    if (itemcount <= 0)
                        break;
                }

                if (itemcount <= 0)
                {
                    BeginChanges();
                    try
                    {
                        itemcount = count;
                        foreach (int i in changedSlot)
                        {
                            ItemInfo item = m_items[i];
                            if (item == null)
                            {
                                item = cloneItem.Clone();

                                item.Count = itemcount < template.MaxCount ? itemcount : template.MaxCount;

                                itemcount -= item.Count;

                                AddItemTo(item, i);
                            }
                            else
                            {
                                if (item.TemplateID == template.TemplateID)
                                {
                                    int add = (item.Count + itemcount < template.MaxCount ? itemcount : template.MaxCount - item.Count);
                                    item.Count += add;
                                    itemcount -= add;

                                    OnPlaceChanged(i);
                                }
                                else
                                {
                                    log.Error("Add template erro: select slot's TemplateId not equest templateId");
                                }
                            }
                        }

                        if (itemcount != 0)
                            log.Error("Add template error: last count not equal Zero.");
                    }
                    finally
                    {
                        CommitChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
Exemplo n.º 6
0
        public int HandlePacket(GameClient client, GSPacketIn packet)
        {
            eBageType       bageType  = (eBageType)packet.ReadByte();
            int             slot      = packet.ReadInt();
            eBageType       type2     = (eBageType)packet.ReadByte();
            int             toSlot    = packet.ReadInt();
            int             count     = packet.ReadInt();
            PlayerInventory bag       = client.Player.GetInventory(bageType);
            PlayerInventory inventory = client.Player.GetInventory(type2);

            if (toSlot < 0)
            {
                if ((inventory.BagType == 11) || (inventory.BagType == 1))
                {
                    toSlot = inventory.FindFirstEmptySlot(0);
                }
                else
                {
                    toSlot = inventory.FindFirstEmptySlot(0x1f);
                }
            }
            if (count > 0)
            {
                if ((bag == null) || (bag.GetItemAt(slot) == null))
                {
                    return(0);
                }
                if ((bageType == type2) && (slot != -1))
                {
                    if (bag.GetItemAt(slot).Count >= count)
                    {
                        bag.MoveItem(slot, toSlot, count);
                    }
                    else
                    {
                        Console.WriteLine("--" + client.Player.Account + " Hack = CE");
                        bag.MoveItem(slot, toSlot, bag.GetItemAt(slot).Count);
                    }
                    return(1);
                }
                if ((slot == -1) && (toSlot != -1))
                {
                    bag.RemoveItemAt(toSlot);
                    return(1);
                }
                if (((((slot != -1) && (toSlot == -1)) && ((bageType != eBageType.CaddyBag) && (type2 != eBageType.Bank))) && (bageType != eBageType.Store)) && (type2 != eBageType.Store))
                {
                    if (bageType == eBageType.MainBag)
                    {
                        bag.AddItem(client.Player.GetItemAt(bageType, slot), 0x1f);
                    }
                    else
                    {
                        bag.AddItem(client.Player.GetItemAt(bageType, slot), 0);
                    }
                    return(1);
                }
                if ((((slot != -1) && (type2 != bageType)) && (type2 != eBageType.Store)) && (type2 != eBageType.MainBag))
                {
                    ConsortiaInfo info = ConsortiaMgr.FindConsortiaInfo(client.Player.PlayerCharacter.ConsortiaID);
                    if (info != null)
                    {
                        if (type2 == eBageType.Store)
                        {
                        }
                        bag.MoveToStore(bag, slot, toSlot, inventory, info.StoreLevel * 10);
                        return(1);
                    }
                }
                if ((type2 == eBageType.Store) || (bageType == eBageType.Store))
                {
                    SqlDataProvider.Data.ItemInfo itemAt = client.Player.GetItemAt(bageType, slot);
                    if ((itemAt != null) && (itemAt.Count > 1))
                    {
                        itemAt.Count--;
                        bag.UpdateItem(itemAt);
                        SqlDataProvider.Data.ItemInfo item = itemAt.Clone();
                        item.Count = 1;
                        if (inventory.GetItemAt(toSlot) == null)
                        {
                            inventory.AddItemTo(item, toSlot);
                        }
                        else
                        {
                            SqlDataProvider.Data.ItemInfo itemByTemplateID = bag.GetItemByTemplateID(0, inventory.GetItemAt(toSlot).TemplateID);
                            if (itemByTemplateID == null)
                            {
                                bag.MoveToStore(inventory, toSlot, bag.FindFirstEmptySlot(0), bag, 0x3e7);
                            }
                            else
                            {
                                itemByTemplateID.Count++;
                                bag.UpdateItem(itemByTemplateID);
                                inventory.RemoveItemAt(toSlot);
                            }
                            inventory.AddItemTo(item, toSlot);
                        }
                    }
                    else
                    {
                        if ((((type2 != eBageType.Store) && (type2 != eBageType.MainBag)) && ((bag.GetItemAt(slot) != null) && (bag.GetItemAt(slot).Template.CategoryID == 7))) && (((toSlot > 0) && (toSlot < 0x1f)) && (toSlot != 6)))
                        {
                            return(1);
                        }
                        try
                        {
                            bag.MoveToStore(bag, slot, toSlot, inventory, 50);
                        }
                        catch (Exception)
                        {
                            LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).InfoFormat("ERROR USER CHANGEITEM placce: {0},toplace: {1},bagType: {2},ToBagType {3}", new object[] { slot, toSlot, bageType, type2 });
                            LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).InfoFormat("item :{0}, toitem {1}", bag.GetItemAt(slot), inventory.GetItemAt(toSlot));
                        }
                    }
                    return(1);
                }
                if ((type2 == eBageType.MainBag) && (bageType == eBageType.Bank))
                {
                    bag.MoveToStore(bag, slot, toSlot, inventory, 50);
                    return(1);
                }
            }
            return(0);
        }