Beispiel #1
0
        public void transferHere(L2Player player, List <long[]> items, bool update)
        {
            InventoryUpdate iu     = update ? new InventoryUpdate() : null;
            List <int>      nulled = new List <int>();

            foreach (L2Item item in player.Inventory.Items.Values)
            {
                foreach (long[] itemd in items)
                {
                    if (item.ObjID == itemd[0])
                    {
                        if (item.Template.isStackable())
                        {
                            if (itemd[1] >= item.Count)
                            {
                                nulled.Add((int)itemd[0]);

                                item.Location = L2Item.L2ItemLocation.refund;
                                _items.Add(item);
                                item.sql_update();

                                if (update)
                                {
                                    iu.addDelItem(item);
                                }
                            }
                            else
                            {
                                item.Count -= itemd[1];

                                L2Item ins = new L2Item(item.Template);
                                ins.Count    = itemd[1];
                                ins.Location = L2Item.L2ItemLocation.refund;
                                _items.Add(ins);

                                ins.sql_insert(_owner.ObjID);

                                if (update)
                                {
                                    iu.addModItem(item);
                                }
                            }
                        }
                        else
                        {
                            nulled.Add((int)itemd[0]);
                            item.Location = L2Item.L2ItemLocation.refund;
                            _items.Add(item);

                            item.sql_update();

                            if (update)
                            {
                                iu.addModItem(item);
                            }
                        }
                    }
                }
            }

            lock (player.Inventory.Items)
            {
                foreach (int itemd in nulled)
                {
                    player.Inventory.Items.Remove(itemd);
                }
            }
        }
Beispiel #2
0
        public void transferHere(L2Player player, List <long[]> items, bool update)
        {
            InventoryUpdate iu     = update ? new InventoryUpdate() : null;
            List <int>      nulled = new List <int>();

            foreach (L2Item item in player.Inventory.Items.Values)
            {
                foreach (long[] itemd in items)
                {
                    if (item.ObjID == itemd[0])
                    {
                        bool ex = false;
                        foreach (L2Item itp in Items.Values)
                        {
                            if (itp.Template.ItemID == item.Template.ItemID)
                            {
                                ex = true;
                                break;
                            }
                        }

                        if (item.Template.isStackable())
                        {
                            if (itemd[1] >= item.Count)
                            {
                                nulled.Add((int)itemd[0]);
                                if (ex)
                                {
                                    foreach (L2Item itp in Items.Values)
                                    {
                                        if (itp.Template.ItemID == item.Template.ItemID)
                                        {
                                            itp.Count += item.Count;
                                            itp.sql_update();
                                            break;
                                        }
                                    }

                                    item.sql_delete();
                                }
                                else
                                {
                                    item.Location = L2Item.L2ItemLocation.warehouse;
                                    Items.Add(item.ObjID, item);
                                    item.sql_update();
                                }

                                if (update)
                                {
                                    iu.addDelItem(item);
                                }
                            }
                            else
                            {
                                item.Count -= itemd[1];

                                if (ex)
                                {
                                    foreach (L2Item itp in Items.Values)
                                    {
                                        if (itp.Template.ItemID == item.Template.ItemID)
                                        {
                                            itp.Count += itemd[1];
                                            itp.sql_update();
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    L2Item ins = new L2Item(item.Template);
                                    ins.Count    = itemd[1];
                                    ins.Location = L2Item.L2ItemLocation.warehouse;
                                    Items.Add(ins.ObjID, ins);

                                    ins.sql_insert(_owner.ObjID);
                                }

                                if (update)
                                {
                                    iu.addModItem(item);
                                }
                            }
                        }
                        else
                        {
                            nulled.Add((int)itemd[0]);
                            item.Location = L2Item.L2ItemLocation.warehouse;
                            Items.Add(item.ObjID, item);

                            item.sql_update();

                            if (update)
                            {
                                iu.addModItem(item);
                            }
                        }
                    }
                }
            }


            lock (player.Inventory.Items)
            {
                foreach (int itemd in nulled)
                {
                    player.Inventory.Items.Remove(itemd);
                }
            }
        }
Beispiel #3
0
        public void addItem(L2Item item, bool msg, bool update)
        {
            item.Location = L2Item.L2ItemLocation.inventory;
            foreach (QuestInfo qi in _owner._quests)
            {
                if (!qi.completed)
                {
                    qi._template.onEarnItem(_owner, qi.stage, item.Template.ItemID);
                }
            }

            InventoryUpdate iu = null;

            if (update)
            {
                iu = new InventoryUpdate();
            }

            if (!item.Template.isStackable())
            {
                Items.Add(item.ObjID, item);

                if (update)
                {
                    iu.addNewItem(item);
                }

                item.sql_insert(_owner.ObjID);
                if (msg)
                {
                    SystemMessage sm = new SystemMessage(30); //You have obtained $s1.
                    if (item.Enchant > 0 && item.Template.ItemID != 4443)
                    {
                        sm.MessgeID = 1666; //You have obtained +$s1$s2.
                        sm.addNumber(item.Enchant);
                        sm.addItemName(item.Template.ItemID);
                    }
                    else
                    {
                        sm.addItemName(item.Template.ItemID);
                    }

                    _owner.sendPacket(sm);
                }
            }
            else
            {
                bool find = false;
                foreach (L2Item it in Items.Values)
                {
                    if (it.Template.ItemID == item.Template.ItemID)
                    {
                        it.Count += item.Count;

                        if (update)
                        {
                            iu.addModItem(it);
                        }

                        it.sql_update();
                        find = true;
                        break;
                    }
                }

                if (!find)
                {
                    Items.Add(item.ObjID, item);

                    if (update)
                    {
                        iu.addNewItem(item);
                    }

                    item.sql_insert(_owner.ObjID);
                }

                if (msg)
                {
                    SystemMessage sm = null;
                    if (item.Template.ItemID == 57)
                    {
                        sm = new SystemMessage(28); //You have obtained $s1 adena.
                        sm.addItemCount(item.Count);
                    }
                    else if (item.Count > 1)
                    {
                        sm = new SystemMessage(29); //You have obtained $s2 $s1.
                        sm.addItemName(item.Template.ItemID);
                        sm.addItemCount(item.Count);
                    }
                    else
                    {
                        sm = new SystemMessage(30); //You have obtained $s1.
                        sm.addItemName(item.Template.ItemID);
                    }

                    _owner.sendPacket(sm);
                }
            }

            if (update)
            {
                _owner.sendPacket(iu);
            }

            if (item.Template.Weight > 0)
            {
                _owner.updateWeight();
            }
        }
Beispiel #4
0
        public void transferFrom(L2Player player, List <int[]> transfer, bool update)
        {
            InventoryUpdate iu     = update ? new InventoryUpdate() : null;
            List <int>      nulled = new List <int>();

            foreach (L2Item item in Items.Values)
            {
                foreach (int[] itemd in transfer)
                {
                    if (item.ObjID == itemd[0])
                    {
                        bool ex = false;
                        foreach (L2Item itp in player.getAllItems())
                        {
                            if (itp.Template.ItemID == item.Template.ItemID)
                            {
                                ex = true;
                                break;
                            }
                        }

                        if (item.Template.isStackable())
                        {
                            if (itemd[1] >= item.Count)
                            {
                                nulled.Add(itemd[0]);
                                if (ex)
                                {
                                    foreach (L2Item itp in player.getAllItems())
                                    {
                                        if (itp.Template.ItemID == item.Template.ItemID)
                                        {
                                            itp.Count += item.Count;
                                            itp.sql_update();
                                            if (update)
                                            {
                                                iu.addModItem(itp);
                                            }

                                            break;
                                        }
                                    }

                                    item.sql_delete();
                                }
                                else
                                {
                                    item.Location = L2Item.L2ItemLocation.inventory;
                                    player.Inventory.Items.Add(item.ObjID, item);
                                    item.sql_update();

                                    if (update)
                                    {
                                        iu.addNewItem(item);
                                    }
                                }
                            }
                            else
                            {
                                item.Count -= itemd[1];
                                if (ex)
                                {
                                    foreach (L2Item itp in player.getAllItems())
                                    {
                                        if (itp.Template.ItemID == item.Template.ItemID)
                                        {
                                            itp.Count += itemd[1];
                                            itp.sql_update();
                                            if (update)
                                            {
                                                iu.addModItem(itp);
                                            }

                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    L2Item ins = new L2Item(item.Template);
                                    ins.Count    = itemd[1];
                                    ins.Location = L2Item.L2ItemLocation.inventory;
                                    player.Inventory.Items.Add(ins.ObjID, ins);
                                    ins.sql_insert(_owner.ObjID);

                                    if (update)
                                    {
                                        iu.addNewItem(ins);
                                    }
                                }
                            }
                        }
                        else
                        {
                            nulled.Add(itemd[0]);
                            item.Location = L2Item.L2ItemLocation.inventory;
                            player.Inventory.Items.Add(item.ObjID, item);

                            item.sql_update();

                            if (update)
                            {
                                iu.addNewItem(item);
                            }
                        }

                        foreach (QuestInfo qi in _owner._quests)
                        {
                            if (!qi.completed)
                            {
                                qi._template.onEarnItem(_owner, qi.stage, item.Template.ItemID);
                            }
                        }
                    }
                }
            }

            lock (Items)
            {
                foreach (int itemd in nulled)
                {
                    Items.Remove(itemd);
                }
            }
        }
Beispiel #5
0
        public override void addItem(ItemTemplate template, long count, short enchant, bool msg, bool update)
        {
            foreach (QuestInfo qi in _owner._quests)
            {
                if (!qi.completed)
                {
                    qi._template.onEarnItem(_owner, qi.stage, template.ItemID);
                }
            }

            InventoryUpdate iu = null;

            if (update)
            {
                iu = new InventoryUpdate();
            }

            if (!template.isStackable())
            {
                bool mass = count > 1;
                for (int i = 0; i < count; i++)
                {
                    L2Item ins = new L2Item(template);
                    ins.Enchant  = enchant;
                    ins.Location = L2Item.L2ItemLocation.inventory;
                    Items.Add(ins.ObjID, ins);

                    if (update)
                    {
                        iu.addNewItem(ins);
                    }

                    ins.sql_insert(_owner.ObjID);
                    if (msg && !mass)
                    {
                        SystemMessage sm = new SystemMessage(54); //You have earned $s1.
                        if (enchant > 0)
                        {
                            sm.MessgeID = 1666; //You have obtained +$s1$s2.
                            sm.addNumber(enchant);
                            sm.addItemName(template.ItemID);
                        }
                        else
                        {
                            sm.addItemName(template.ItemID);
                        }

                        _owner.sendPacket(sm);
                    }
                }

                if (msg && mass)
                {
                    SystemMessage sm = new SystemMessage(53); //You have earned $s2 $s1(s).
                    sm.addItemName(template.ItemID);
                    sm.addItemCount(count);
                    _owner.sendPacket(sm);
                }
            }
            else
            {
                bool find = false;
                foreach (L2Item it in Items.Values)
                {
                    if (it.Template.ItemID == template.ItemID)
                    {
                        it.Count += count;

                        if (update)
                        {
                            iu.addModItem(it);
                        }

                        it.sql_update();
                        find = true;
                        break;
                    }
                }

                if (!find)
                {
                    L2Item ins = new L2Item(template);
                    ins.Count    = count;
                    ins.Location = L2Item.L2ItemLocation.inventory;
                    Items.Add(ins.ObjID, ins);

                    if (update)
                    {
                        iu.addNewItem(ins);
                    }

                    ins.sql_insert(_owner.ObjID);
                }

                if (msg)
                {
                    SystemMessage sm = null;
                    if (template.ItemID == 57)
                    {
                        sm = new SystemMessage(52); //You have earned $s1 adena.
                        sm.addItemCount(count);
                    }
                    else if (count > 1)
                    {
                        sm = new SystemMessage(53); //You have earned $s2 $s1(s).
                        sm.addItemName(template.ItemID);
                        sm.addItemCount(count);
                    }
                    else
                    {
                        sm = new SystemMessage(54); //You have earned $s1.
                        sm.addItemName(template.ItemID);
                    }

                    _owner.sendPacket(sm);
                }

                if (update)
                {
                    _owner.sendPacket(iu);
                }
            }

            if (template.Weight > 0)
            {
                _owner.updateWeight();
            }
        }