/// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                if (InventoryUpdate != null)
                {
                    InventoryUpdate.Abort();
                    InventoryUpdate = null;
                }

                if (_EditTimer != null)
                {
                    _EditTimer.Dispose();
                    _EditTimer = null;
                }

                if (TreeUpdateTimer != null)
                {
                    TreeUpdateTimer.Dispose();
                    TreeUpdateTimer = null;
                }

                components.Dispose();
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post([FromBody] InventoryUpdate value)
        {
            String resp;

            try
            {
                var context = new NestinDBEntities();

                var inv = context.RentInventories.Where(X => X.RentInventoryID == value.InventoryId).First();

                if (inv != null)
                {
                    inv.Available = false;
                    context.SaveChanges();
                    resp = "{\"Response\":\"Ok\"}";
                    var response = Request.CreateResponse(HttpStatusCode.OK);
                    response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json");
                    return(response);
                }
                else
                {
                    resp = "{\"Response\":\"NotFound\"}";
                    var response = Request.CreateResponse(HttpStatusCode.NotFound);
                    response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                resp = "{\"Response\":\"Fail\"}";
                var response = Request.CreateResponse(HttpStatusCode.InternalServerError);
                response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json");
                return(response);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a stack of items to a given slot.
        /// </summary>
        /// <param name="amount">Amount of items to remove the inventory</param>
        /// <param name="slotNum">Inventory slot to remove the item from</param>
        /// <returns>
        /// Number of items left in stack after adding to slot.
        /// </returns>
        public bool RemoveItems(int amount, int slotNum)
        {
            if (!IsValidSlotNumber(slotNum))
            {
                Debug.Log(INVALID_SLOT);
                return(false);
            }

            Slot s = inventory[slotNum];

            if (s.IsEmpty())
            {
                Debug.Log(SLOT_EMPTY);
                return(false);
            }

            if (amount > s.GetAmount())
            {
                Debug.Log(NOT_ENOUGH_ITEMS);
                return(false);
            }

            s.RemoveAmount(amount);
            InventoryUpdate?.Invoke();
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a stack of items to a given slot.
        /// </summary>
        /// <param name="name">Name of the item to remove</param>
        /// <param name="amount">Amount of items to remove from the inventory</param>
        /// <returns>
        /// Number of items left in stack after adding to slot.
        /// </returns>
        public bool RemoveItemsByName(string name, int amount)
        {
            Dictionary <Slot, int> toRemove = new Dictionary <Slot, int>();

            foreach (Slot s in inventory)
            {
                if (s.GetItem() != null && s.GetItem().Name.Equals(name))
                {
                    int removeAmount = Mathf.Min(s.GetAmount(), amount);
                    toRemove.Add(s, removeAmount);
                    amount -= removeAmount;
                    if (amount <= 0)
                    {
                        break;
                    }
                }
            }

            if (amount > 0)
            {
                return(false);
            }
            foreach (Slot s in toRemove.Keys)
            {
                s.RemoveAmount(toRemove[s]);
            }
            InventoryUpdate?.Invoke();
            return(true);
        }
Ejemplo n.º 5
0
        public void CreateInventoryUpdate(string location)
        {
            switch (location)
            {
            case WarehouseLocation.CHI:
                inventoryupdate = new InventoryUpdate(email, password, "CHI");
                break;

            case WarehouseLocation.LAX:
                inventoryupdate = new InventoryUpdate(email, password, "LAX");
                break;

            case WarehouseLocation.REN:
                inventoryupdate = new InventoryUpdate(email, password, "REN");
                break;

            case WarehouseLocation.TOR:
                inventoryupdate = new InventoryUpdate(email, password, "TOR");
                break;

            case WarehouseLocation.UK:
                inventoryupdate = new InventoryUpdate(email, password, "UK");
                break;

            case WarehouseLocation.VAN:
                inventoryupdate = new InventoryUpdate(email, password, "VAN");
                break;

            default:
                Syslog.Write("Unknown warehouse location: " + location);
                throw new Exception();
            }
        }
Ejemplo n.º 6
0
        static string BuildInventoryUpdateFeed()
        {
            var details = new InventoryDetails();

            details.sellingParty = new InventoryModel.SellingParty()
            {
                partyId = "your_vendor_id"
            };
            details.isFullUpdate = false;

            var update = new InventoryUpdate();

            update.inventory = details;

            var list = new List <InventoryItem>();
            var item = new InventoryItem();

            item.buyerProductIdentifier  = "buyer_item";
            item.vendorProductIdentifier = "vendor_item";
            item.isObsolete = false;

            var available = new Available();

            available.amount        = 345;
            available.unitOfMeasure = "Each";

            item.availableQuantity = available;

            list.Add(item);

            details.items = list;

            return(JsonConvert.SerializeObject(update, Formatting.Indented));
        }
Ejemplo n.º 7
0
        public override EffectResult OnStart(L2Character caster, L2Character target)
        {
            if (!(caster is L2Player))
            {
                return(Nothing);
            }

            L2Player player = (L2Player)caster;
            L2Item   item   = player.GetWeaponItem();

            //int newid = ItemTable.Instance.ConvertDataList[item.Template.ItemID];

            //int pdollId = player.Inventory.getPaperdollId(item.Template);
            //player.setPaperdoll(pdollId, null, false);
            //player.broadcastUserInfo();

            //int oldweight = item.Template.Weight;
            //item.Template = ItemTable.Instance.GetItem(newid);
            //item.sql_update();

            //if (oldweight != item.Template.Weight)
            //    player.updateWeight();

            //player.setPaperdoll(pdollId, item, false);
            //player.broadcastUserInfo();

            InventoryUpdate iu = new InventoryUpdate();

            iu.AddModItem(item);
            player.SendPacket(iu);

            return(Nothing);
        }
Ejemplo n.º 8
0
 private Inventory(int capacity, IList <Item> initialItems)
 {
     this.capacity = capacity;
     items         = new List <Item>(capacity);
     items.AddRange(Enumerable.Repeat(Item.NullItem, capacity));
     for (var itemSlot = 0; itemSlot < initialItems.Count;
          itemSlot = itemSlot + 1)
     {
         items[itemSlot] = initialItems[itemSlot];
     }
     onInventoryUpdate = new InventoryUpdate();
 }
Ejemplo n.º 9
0
 private void OnEnable()
 {
     if (initialItemTemplates != null)
     {
         var items = new List <Item>();
         foreach (var itemTemplate in initialItemTemplates)
         {
             var item = Item.FromTemplate(itemTemplate);
             items.Add(item);
         }
         inventory = Inventory.WithCapacityAndInitialItems(capacity, items);
     }
     onInventoryUpdate = inventory.OnInventoryUpdate;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a specified number of an item to any available free slots.
        /// </summary>
        /// <param name="item">Item to add to the inventory</param>
        /// <param name="amount">Amount of items to add to the inventory</param>
        /// <returns>
        /// True if operation is successful.
        /// </returns>
        public bool AddItems(Item item, int amount)
        {
            if (amount <= 0)
            {
                Debug.Log(INVALID_AMOUNT);
                return(false);
            }

            if (amount == 1)
            {
                return(AddItem(item));
            }

            Dictionary <Slot, int> toAdd = new Dictionary <Slot, int>();

            while (amount > 0)
            {
                int slotIndex = getNextFreeSlotIndex(item, new List <Slot>(toAdd.Keys));
                if (slotIndex == -1)
                {
                    Debug.Log(NO_SPACE);
                    return(false);
                }

                Slot s = inventory[slotIndex];

                int addAmount = GetAmountToAdd(s, item, amount);
                toAdd.Add(s, addAmount);
                amount -= addAmount;
            }

            foreach (Slot s in toAdd.Keys)
            {
                if (s.GetItem() == null)
                {
                    s.SetItem(item, toAdd[s]);
                }
                else
                {
                    s.AddAmount(toAdd[s]);
                }
            }
            InventoryUpdate?.Invoke();
            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds a single item to the specified slot
        /// </summary>
        /// <param name="item">Item to add to the inventory</param>
        /// <param name="slotNum">Inventory slot to add the item to</param>
        /// <returns>
        /// True if operation is successful
        /// </returns>
        public bool AddItem(Item item, int slotNum)
        {
            if (!ValidateSlot(item, slotNum, 1))
            {
                return(false);
            }

            Slot s = inventory[slotNum];

            if (s.GetItem() == null)
            {
                s.SetItem(item, 1);
            }
            else
            {
                s.AddAmount(1);
            }

            InventoryUpdate?.Invoke();
            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds a stack of items to a given slot.
        /// </summary>
        /// <param name="item">Item to add to the inventory</param>
        /// <param name="amount">Amount of items to add to the inventory</param>
        /// <param name="slotNum">Inventory slot to add the item to</param>
        /// <returns>
        /// Number of items left in stack after adding to slot.
        /// </returns>
        public int AddItems(Item item, int amount, int slotNum)
        {
            if (!ValidateSlot(item, slotNum, 1))
            {
                return(amount);
            }

            Slot s         = inventory[slotNum];
            int  addAmount = GetAmountToAdd(s, item, amount);

            if (s.GetItem() == null)
            {
                s.SetItem(item, addAmount);
            }
            else
            {
                s.AddAmount(addAmount);
            }

            InventoryUpdate?.Invoke();
            return(amount - addAmount);
        }
Ejemplo n.º 13
0
        public override TEffectResult onStart(world.L2Character caster, world.L2Character target)
        {
            L2Player player = caster as L2Player;
            L2Item   item   = player.getWeaponItem();

            if (item == null || !ItemTable.getInstance().ConvertDataList.ContainsKey(item.Template.ItemID))
            {
                caster.sendSystemMessage(2130);//You cannot convert this item.
                return(nothing);
            }

            int newid = ItemTable.getInstance().ConvertDataList[item.Template.ItemID];

            int pdollId = player.Inventory.getPaperdollId(item.Template);

            player.setPaperdoll(pdollId, null, false);
            player.broadcastUserInfo();

            int oldweight = item.Template.Weight;

            item.Template = ItemTable.getInstance().getItem(newid);
            item.sql_update();

            if (oldweight != item.Template.Weight)
            {
                player.updateWeight();
            }

            player.setPaperdoll(pdollId, item, false);
            player.broadcastUserInfo();

            InventoryUpdate iu = new InventoryUpdate();

            iu.addModItem(item);
            player.sendPacket(iu);

            return(nothing);
        }
Ejemplo n.º 14
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);
                }
            }
        }
Ejemplo n.º 15
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);
                }
            }
        }
Ejemplo n.º 16
0
        public override void run()
        {
            L2Player player = Client.CurrentPlayer;

            if (player.EnchantState != ItemEnchantManager.STATE_ENCHANT_START)
            {
                player.sendSystemMessage(355);//Inappropriate enchant conditions.
                player.sendActionFailed();
                return;
            }

            if (a_sTargetID != player.EnchantItem.ObjID)
            {
                player.sendSystemMessage(355);//Inappropriate enchant conditions.
                player.sendActionFailed();
                return;
            }

            short rate = 50;

            if (player.EnchantStone != null)
            {
                EnchantScroll stone = ItemEnchantManager.getInstance().getSupport(player.EnchantStone.Template.ItemID);
                rate += stone.bonus;
            }

            if (player.EnchantItem.Enchant < 4)
            {
                rate = 100;
            }

            if (rate > 100)
            {
                rate = 100;
            }

            InventoryUpdate iu    = null;
            bool            equip = false;

            if (rate == 100 ? true : new Random().Next(100) < rate)
            {
                player.EnchantItem.Enchant += 1;
                player.EnchantItem.sql_update();

                iu = new InventoryUpdate();
                iu.addModItem(player.EnchantItem);

                player.sendPacket(new EnchantResult(EnchantResultVal.success));

                equip = player.EnchantItem._isEquipped == 1;

                if (equip && player.EnchantItem.Enchant == 4 && player.EnchantItem.Template.item_skill_ench4 != null)
                {
                    player.addSkill(player.EnchantItem.Template.item_skill_ench4, false, false);
                    player.updateSkillList();
                }
                //todo check +6 set
            }
            else
            {
                EnchantScroll scr = ItemEnchantManager.getInstance().getScroll(player.EnchantScroll.Template.ItemID);
                switch (scr.Type)
                {
                case EnchantType.blessed:
                    player.EnchantItem.Enchant = 0;
                    player.EnchantItem.sql_update();

                    iu = new InventoryUpdate();
                    iu.addModItem(player.EnchantItem);

                    player.sendPacket(new EnchantResult(EnchantResultVal.breakToOne));
                    break;

                case EnchantType.ancient:
                    player.sendPacket(new EnchantResult(EnchantResultVal.safeBreak));
                    break;

                default:
                {
                    if (player.EnchantItem._isEquipped == 1)
                    {
                        int pdollId = player.Inventory.getPaperdollId(player.EnchantItem.Template);
                        player.setPaperdoll(pdollId, null, false);
                        equip = true;
                    }

                    player.Inventory.removeItem(player.EnchantItem);
                    iu = new InventoryUpdate();
                    iu.addDelItem(player.EnchantItem);

                    long cry = player.EnchantItem.Template._cryCount;

                    if (cry == 0)
                    {
                        player.sendPacket(new EnchantResult(EnchantResultVal.breakToNothing));
                    }
                    else
                    {
                        int id = player.EnchantItem.Template.getCrystallId();
                        player.sendPacket(new EnchantResult(EnchantResultVal.breakToCount, id, cry));
                        player.Inventory.addItem(id, cry, true, true);
                    }
                }
                break;
                }
            }

            if (player.EnchantStone != null)
            {
                player.Inventory.destroyItem(player.EnchantStone, 1, true, true);
            }

            player.Inventory.destroyItem(player.EnchantScroll, 1, false, true);

            if (iu != null)
            {
                player.sendPacket(iu);
            }

            player.EnchantItem   = null;
            player.EnchantScroll = null;
            player.EnchantStone  = null;
            player.EnchantState  = 0;

            if (equip)
            {
                player.broadcastUserInfo();
            }
        }
Ejemplo n.º 17
0
 internal void OnInventoryUpdate()
 {
     InventoryUpdate?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 18
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();
            }
        }
Ejemplo n.º 19
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();
            }
        }
Ejemplo n.º 20
0
        public void setPaperdoll(int pdollId, L2Item item, bool update)
        {
            InventoryUpdate iu = null;

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

            List <object[]> unequipAction = new List <object[]>();
            int             sbt           = item != null?item.Template.BodyPartId() : -1;

            byte uiUpdate = 0;

            switch (pdollId)
            {
            case SBT_RLEAR:
                if (_paperdoll[EQUIPITEM_LEar][PDOLL_OBJID] == 0)
                {
                    pdollId = EQUIPITEM_LEar;
                }
                else
                {
                    pdollId = EQUIPITEM_REar;
                    if (_paperdoll[EQUIPITEM_REar][PDOLL_OBJID] > 0)
                    {
                        unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_REar][PDOLL_OBJID]), EQUIPITEM_REar });
                    }
                }
                uiUpdate = 2;
                break;

            case SBT_RLFINGER:
                if (_paperdoll[EQUIPITEM_LFinger][PDOLL_OBJID] == 0)
                {
                    pdollId = EQUIPITEM_LFinger;
                }
                else
                {
                    pdollId = EQUIPITEM_RFinger;
                    if (_paperdoll[EQUIPITEM_RFinger][PDOLL_OBJID] > 0)
                    {
                        unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_RFinger][PDOLL_OBJID]), EQUIPITEM_RFinger });
                    }
                }
                uiUpdate = 2;
                break;

            case SBT_RLHAND:
                if (_paperdoll[EQUIPITEM_LHand][PDOLL_OBJID] > 0)
                {
                    unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_LHand][PDOLL_OBJID]), EQUIPITEM_LHand });
                    uiUpdate = 1;
                }
                break;

            case SBT_LHAND:
                if (_paperdoll[EQUIPITEM_RHand][PDOLL_OBJID] > 0)
                {
                    L2Item temp = getByObject(_paperdoll[EQUIPITEM_RHand][PDOLL_OBJID]);
                    if (temp != null && temp.Template.BodyPartId() == SBT_RLHAND)
                    {
                        unequipAction.Add(new object[] { temp, EQUIPITEM_RHand });
                        uiUpdate = 1;
                    }
                }
                break;

            case SBT_ONEPIECE:
                if (_paperdoll[EQUIPITEM_Legs][PDOLL_OBJID] > 0)
                {
                    unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_Legs][PDOLL_OBJID]), EQUIPITEM_Legs });
                    uiUpdate = 1;
                }
                break;

            case SBT_ALLDRESS:
                if (_paperdoll[EQUIPITEM_Head][PDOLL_OBJID] > 0)
                {
                    unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_Head][PDOLL_OBJID]), EQUIPITEM_Head });
                }
                if (_paperdoll[EQUIPITEM_Gloves][PDOLL_OBJID] > 0)
                {
                    unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_Gloves][PDOLL_OBJID]), EQUIPITEM_Gloves });
                }
                if (_paperdoll[EQUIPITEM_Legs][PDOLL_OBJID] > 0)
                {
                    unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_Legs][PDOLL_OBJID]), EQUIPITEM_Legs });
                }
                if (_paperdoll[EQUIPITEM_Feet][PDOLL_OBJID] > 0)
                {
                    unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_Feet][PDOLL_OBJID]), EQUIPITEM_Feet });
                }
                uiUpdate = 1;
                break;

            case SBT_HAIRALL:
                if (_paperdoll[EQUIPITEM_Hair2][PDOLL_OBJID] > 0)
                {
                    unequipAction.Add(new object[] { getByObject(_paperdoll[EQUIPITEM_Hair2][PDOLL_OBJID]), EQUIPITEM_Hair2 });
                    uiUpdate = 1;
                }
                break;

            default:
                if (_paperdoll[pdollId][PDOLL_OBJID] != 0)
                {
                    L2Item old = getByObject(_paperdoll[pdollId][PDOLL_OBJID]);
                    unequipAction.Add(new object[] { old, pdollId });
                }
                break;
            }

            switch (uiUpdate)
            {
            case 1:
                _owner.broadcastUserInfo();
                break;

            case 2:
                _owner.sendPacket(new UserInfo(_owner));
                break;
            }

            if (unequipAction.Count > 0)
            {
                foreach (object[] oa in unequipAction)
                {
                    L2Item temp = oa[0] as L2Item;
                    if (temp != null)
                    {
                        temp.unequip(_owner);
                        if (update)
                        {
                            iu.addModItem(temp);
                        }
                    }

                    int dollId = (int)oa[1];
                    _paperdoll[dollId][PDOLL_ID]      = 0;
                    _paperdoll[dollId][PDOLL_OBJID]   = 0;
                    _paperdoll[dollId][PDOLL_AUGMENT] = 0;
                }
            }

            if (item == null)
            {
                if (update)
                {
                    _owner.sendPacket(iu);
                }
                return;
            }

            _paperdoll[pdollId][PDOLL_ID]      = item.Template.ItemID;
            _paperdoll[pdollId][PDOLL_OBJID]   = item.ObjID;
            _paperdoll[pdollId][PDOLL_AUGMENT] = item.AugmentationID;
            item.equip(_owner);
            item._paperdollSlot = pdollId;
            if (update)
            {
                iu.addModItem(item);
                _owner.sendPacket(iu);
            }
        }
Ejemplo n.º 21
0
        public void destroyItemAll(int id, bool msg, bool update)
        {
            InventoryUpdate iu = null;

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

            bool       weightUp = false;
            List <int> nulled   = new List <int>();

            foreach (L2Item item in Items.Values)
            {
                if (item.Template.ItemID == id)
                {
                    weightUp = item.Template.Weight > 0;
                    if (item.Template.isStackable())
                    {
                        long c = item.Count;
                        nulled.Add(item.ObjID);
                        if (update)
                        {
                            iu.addDelItem(item);
                        }

                        item.sql_delete();

                        if (msg)
                        {
                            SystemMessage sm = new SystemMessage(301);
                            sm.addItemName(item.Template.ItemID);
                            sm.addItemCount(c);

                            _owner.sendPacket(sm);
                        }

                        break;
                    }
                    else
                    {
                        nulled.Add(item.ObjID);

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

                        if (msg)
                        {
                            SystemMessage sm = new SystemMessage(301);
                            sm.addItemName(item.Template.ItemID);
                            sm.addNumber(1);

                            _owner.sendPacket(sm);
                        }

                        item.sql_delete();
                        break;
                    }
                }
            }

            lock (Items)
                foreach (int ids in nulled)
                {
                    Items.Remove(ids);
                }

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

            if (weightUp)
            {
                _owner.updateWeight();
            }
        }
Ejemplo n.º 22
0
        public void destroyItem(L2Item item, int count, bool msg, bool update)
        {
            InventoryUpdate iu = null;

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

            SystemMessage sm = null;

            if (msg)
            {
                sm = new SystemMessage(count == 1 ? 302 : 301);
            }

            List <int> nulled = new List <int>();
            bool       nonstackmass = false; int iditem = 0;

            if (item.Template.isStackable())
            {
                if (item.Count > count)
                {
                    item.Count -= count;
                    if (update)
                    {
                        iu.addModItem(item);
                    }

                    item.sql_update();
                }
                else
                {
                    nulled.Add(item.ObjID);
                    if (update)
                    {
                        iu.addDelItem(item);
                    }

                    item.sql_delete();
                }

                if (msg)
                {
                    sm.addItemName(item.Template.ItemID);

                    if (count > 1)
                    {
                        sm.addNumber(count);
                    }
                }
            }
            else
            {
                if (count == 1)
                {
                    nulled.Add(item.ObjID);

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

                    if (msg)
                    {
                        sm.addItemName(item.Template.ItemID);
                    }

                    item.sql_delete();
                }
                else
                {
                    nonstackmass = true;
                    iditem       = item.Template.ItemID;
                    nulled.Add(item.ObjID);
                    if (update)
                    {
                        iu.addDelItem(item);
                    }

                    item.sql_delete();
                }
            }

            lock (Items)
                foreach (int id in nulled)
                {
                    Items.Remove(id);
                }

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

            if (msg)
            {
                if (nonstackmass)
                {
                    sm.addItemName(iditem);
                    sm.addNumber(count);
                }

                _owner.sendPacket(sm);
            }

            if (item.Template.Weight > 0)
            {
                _owner.updateWeight();
            }
        }
Ejemplo n.º 23
0
        public override void run()
        {
            L2Player  player = getClient().CurrentPlayer;
            L2Citizen npc    = player.FolkNpc;

            if (npc == null)
            {
                player.sendActionFailed();
                return;
            }

            long totalCost = 0;
            int  weight    = 0;

            for (int i = 0; i < _count; i++)
            {
                int  objectId = (int)_items[i * 3 + 0];
                long count    = _items[i * 3 + 2];

                if (count < 0 || count > int.MaxValue)
                {
                    player.sendSystemMessage(1801); //The attempt to sell has failed.
                    player.sendActionFailed();
                    return;
                }

                L2Item item = (L2Item)player.Inventory.Items[objectId];

                if (item.Template.isStackable())
                {
                    totalCost += (int)(item.Count * (item.Template.Price * .5));
                }
                else
                {
                    totalCost += (int)(item.Template.Price * .5);
                }

                weight += item.Template.Weight;
            }

            if (totalCost > long.MaxValue)
            {
                player.sendSystemMessage(1801); //The attempt to sell has failed.
                player.sendActionFailed();
                return;
            }

            long added = 0, currentAdena = player.getAdena();

            if (currentAdena + totalCost >= int.MaxValue)
            {
                added = int.MaxValue - currentAdena;
            }
            else
            {
                added = (int)totalCost;
            }

            List <long[]>   transfer = new List <long[]>();
            InventoryUpdate iu       = new InventoryUpdate();

            for (int i = 0; i < _count; i++)
            {
                int  objectId = (int)_items[i * 3 + 0];
                long count    = _items[i * 3 + 2];

                transfer.Add(new long[] { objectId, count });
            }
            player.Refund.transferHere(player, transfer, false);
            player.Refund.validate();

            player.addAdena(added, false, false);
            player.sendItemList(true);
            player.sendPacket(new ExBuySellList_Close());

            if (weight != 0)
            {
                player.updateWeight();
            }

            //if (npc.Template.fnSell != null)
            //{
            //    player.sendPacket(new NpcHtmlMessage(player, npc.Template.fnSell, npc.ObjID, 0));
            //}
        }
Ejemplo n.º 24
0
        public override void RunImpl()
        {
            L2Player player = _client.CurrentPlayer;

            if (player.EnchantState != ItemEnchantManager.StateEnchantStart)
            {
                player.SendSystemMessage(SystemMessage.SystemMessageId.InappropriateEnchantCondition);
                player.SendActionFailed();
                return;
            }

            if (_aSTargetId != player.EnchantItem.ObjId)
            {
                player.SendSystemMessage(SystemMessage.SystemMessageId.InappropriateEnchantCondition);
                player.SendActionFailed();
                return;
            }

            short rate = 50;

            if (player.EnchantStone != null)
            {
                EnchantScroll stone = ItemEnchantManager.GetInstance().GetSupport(player.EnchantStone.Template.ItemId);
                rate += stone.Bonus;
            }

            if (player.EnchantItem.Enchant < 4)
            {
                rate = 100;
            }

            if (rate > 100)
            {
                rate = 100;
            }

            InventoryUpdate iu    = null;
            bool            equip = false;

            if ((rate == 100) || (new Random().Next(100) < rate))
            {
                player.EnchantItem.Enchant += 1;
                //player.EnchantItem.sql_update();

                iu = new InventoryUpdate();
                iu.AddModItem(player.EnchantItem);

                player.SendPacket(new EnchantResult(EnchantResultVal.Success));

                equip = player.EnchantItem.IsEquipped == 1;

                //if (equip && (player.EnchantItem.Enchant == 4) && (player.EnchantItem.Template.ItemSkillEnch4 != null))
                //{
                //    player.AddSkill(player.EnchantItem.Template.ItemSkillEnch4, false, false);
                //    player.UpdateSkillList();
                //}
                //todo check +6 set
            }
            else
            {
                EnchantScroll scr = ItemEnchantManager.GetInstance().GetScroll(player.EnchantScroll.Template.ItemId);
                switch (scr.Type)
                {
                case EnchantType.Blessed:
                    player.EnchantItem.Enchant = 0;
                    //player.EnchantItem.sql_update();

                    iu = new InventoryUpdate();
                    iu.AddModItem(player.EnchantItem);

                    player.SendPacket(new EnchantResult(EnchantResultVal.BreakToOne));
                    break;

                case EnchantType.Ancient:
                    player.SendPacket(new EnchantResult(EnchantResultVal.SafeBreak));
                    break;

                default:
                {
                    if (player.EnchantItem.IsEquipped == 1)
                    {
                        //int pdollId = player.Inventory.getPaperdollId(player.EnchantItem.Template);
                        // player.setPaperdoll(pdollId, null, false);
                        equip = true;
                    }

                    iu = new InventoryUpdate();
                    iu.AddDelItem(player.EnchantItem);

                    //int id = player.EnchantItem.Template.CrystalType.CrystalId;
                    //player.SendPacket(new EnchantResult(EnchantResultVal.BreakToCount, id, cry));
                    //player.AddItem(id, cry);
                }
                break;
                }
            }

            if (player.EnchantStone != null)
            {
                player.DestroyItem(player.EnchantStone, 1);
            }

            player.DestroyItem(player.EnchantScroll, 1);

            if (iu != null)
            {
                player.SendPacket(iu);
            }

            player.EnchantItem   = null;
            player.EnchantScroll = null;
            player.EnchantStone  = null;
            player.EnchantState  = 0;

            if (equip)
            {
                player.BroadcastUserInfo();
            }
        }
Ejemplo n.º 25
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);
                }
            }
        }