Exemple #1
0
        private void AddDroppedItem(InventoryItem droppedItem)
        {
            var existItem = InventoryItem.ExistItem(droppedItem, _client.Character);

            _client.Character.Map.Send(string.Format("{0}-{1};{2};0", Packet.CellObject, droppedItem.Cell,
                                                     droppedItem.ItemInfos.Id));

            if (existItem != null)
            {
                existItem.Quantity += droppedItem.Quantity;

                lock (DatabaseProvider.InventoryItems)
                    DatabaseProvider.InventoryItems.Remove(droppedItem);

                _client.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectQuantity, existItem.Id,
                                                  existItem.Quantity));
            }
            else
            {
                droppedItem.Map       = null;
                droppedItem.Cell      = 0;
                droppedItem.Character = _client.Character;

                InventoryItemRepository.Create(droppedItem, true);

                _client.SendPackets(string.Format("{0}{1}", Packet.ObjectAdd, droppedItem.ItemInfo()));
            }
        }
Exemple #2
0
        public void Generate(Character character, int quantity = 1)
        {
            var item = new InventoryItem
            {
                Id = DatabaseProvider.InventoryItems.Count > 0
                    ? DatabaseProvider.InventoryItems.OrderByDescending(x => x.Id).First().Id + 1
                    : 1,
                Character    = character,
                ItemInfos    = this,
                ItemPosition = StatsManager.Position.None,
                Stats        = ItemStats.GenerateRandomStats(Stats).ToList(),
                Quantity     = quantity
            };

            var existItem = InventoryItem.ExistItem(item, item.Character, item.ItemPosition);

            if (existItem != null)
            {
                existItem.Quantity += 1;
                InventoryItemRepository.Update(existItem);
            }
            else
            {
                InventoryItemRepository.Create(item, true);
            }
        }
Exemple #3
0
        private void UpdateDetailedItem(InventoryItemCreated @event)
        {
            InventoryItemEntity inventoryItem = new InventoryItemEntity
            {
                Rsn                = @event.Rsn,
                Name               = @event.Name,
                CurrentCount       = 0,
                IsLogicallyDeleted = false
            };

            // As this is the first event for this instance, no existing instance will exist, thus a create operation is executed
            InventoryItemRepository.Create(inventoryItem);
        }
Exemple #4
0
        private void CreateTraderItem(Character trader, InventoryItem existItemTrader, GameClient traderClient,
                                      InventoryItem item)
        {
            if (existItemTrader != null)
            {
                existItemTrader.Quantity += item.Quantity;

                traderClient.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectQuantity, existItemTrader.Id,
                                                       existItemTrader.Quantity));

                InventoryItemRepository.Update(existItemTrader);
            }
            else
            {
                var newItem = item.Copy(quantity: item.Quantity);

                newItem.Character = trader;

                traderClient.SendPackets(string.Format("{0}{1}", Packet.ObjectAdd, newItem.ItemInfo()));

                InventoryItemRepository.Create(newItem, true);
            }
        }
Exemple #5
0
        private void MoveItem(string data)
        {
            var itemId = int.Parse(data.Split('|')[0]);

            var itemPosition = (StatsManager.Position) int.Parse(data.Split('|')[1]);

            var item =
                DatabaseProvider.InventoryItems.Find(
                    x =>
                    x.Id == itemId &&
                    x.Character.Id == _client.Character.Id);

            if (item == null)
            {
                return;
            }

            if (itemPosition == StatsManager.Position.None)
            {
                var existItem = InventoryItem.ExistItem(item, item.Character, itemPosition);

                if (existItem != null)
                {
                    var id = item.Id;
                    existItem.Quantity += item.Quantity;

                    InventoryItemRepository.Remove(item, true);

                    _client.SendPackets(string.Format("{0}{1}", Packet.ObjectRemove, id));

                    InventoryItemRepository.Update(existItem);

                    _client.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectQuantity, existItem.Id,
                                                      existItem.Quantity));
                }
                else
                {
                    item.ItemPosition = StatsManager.Position.None;
                    InventoryItemRepository.Update(item);

                    _client.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectMove, item.Id, (int)itemPosition));
                }

                _client.Character.Stats.RemoveItemStats(item.Stats);

                if (item.ItemInfos.HasSet())
                {
                    _client.Character.Stats.DecreaseItemSetEffect(item);
                }
            }
            else
            {
                if (item.ItemInfos.Level > _client.Character.Level)
                {
                    _client.SendPackets(Packet.ObjectErrorLevel);
                    return;
                }

                if (itemPosition == StatsManager.Position.Anneau1 || itemPosition == StatsManager.Position.Anneau2)
                {
                    if (item.ItemInfos.HasSet())
                    {
                        var itemSet = item.ItemInfos.GetSet();

                        if (_client.Character.CheckIfRingInSetAlredyEquiped(itemSet) == true)
                        {
                            _client.SendPackets(Packet.ObjectErrorRingInSetAlredyEquiped);
                            return;
                        }
                    }
                }

                if (ItemCondition.VerifyIfCharacterMeetItemCondition(_client.Character, item.ItemInfos.Conditions) ==
                    false)
                {
                    _client.SendPackets(string.Format("{0}{1}", Packet.Message, Packet.ConditionToEquipItem));
                    return;
                }

                var existItem = DatabaseProvider.InventoryItems.Find(
                    x =>
                    x.Character == _client.Character &&
                    x.ItemPosition == itemPosition);

                // TODO : debug Pets food & Obvis

                if (existItem != null)
                {
                    _client.SendPackets(Packet.Nothing);
                    return;
                }

                if (item.Quantity > 1)
                {
                    var newItem = item.Copy(quantity: item.Quantity - 1);

                    InventoryItemRepository.Create(newItem, true);

                    item.Quantity = 1;

                    item.ItemPosition = itemPosition;

                    InventoryItemRepository.Update(item);

                    _client.SendPackets(string.Format("{0}{1}|{2}", Packet.ObjectMove, item.Id, (int)itemPosition));

                    _client.SendPackets(string.Format("{0}{1}", Packet.ObjectAdd, newItem.ItemInfo()));
                }
                else
                {
                    item.ItemPosition = itemPosition;

                    InventoryItemRepository.Update(item);

                    _client.SendPackets(string.Format("{0}{1}", Packet.ObjectMove, data));
                }

                _client.Character.Stats.AddItemStats(item.Stats);

                if (item.ItemInfos.HasSet())
                {
                    _client.Character.Stats.IncreaseItemSetEffect(item);
                }
            }

            if (item.ItemInfos.HasSet())
            {
                var set = item.ItemInfos.GetSet();

                SendItemSetBonnus(set);
            }

            RefreshCharacterStats();

            _client.Character.Map.Send(string.Format("{0}{1}|{2}", Packet.ObjectAccessories, _client.Character.Id,
                                                     _client.Character.GetItemsWheneChooseCharacter()));
        }