Пример #1
0
 public static InventoryItem ExistItem(InventoryItem item, Character character, StatsManager.Position position = StatsManager.Position.None, int quantity = 1)
 {
     return DatabaseProvider.InventoryItems.Find(
         x =>
             x.ItemInfos == item.ItemInfos &&
             string.Join(",", x.Stats).Equals(string.Join(",", item.Stats)) &&
             x.Character == character && x.ItemPosition == position && x.Quantity >= quantity);
 }
Пример #2
0
        public static void Remove(InventoryItem inventoryItem, bool removeFromList)
        {
            const string query =
                "DELETE FROM Inventory_items WHERE id=@id";

            Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(),
                (command) => command.Parameters.Add(new MySqlParameter("@id", inventoryItem.Id)));

            if (!removeFromList) return;

            lock (DatabaseProvider.InventoryItems)
                DatabaseProvider.InventoryItems.Remove(inventoryItem);
        }
Пример #3
0
        public static void Update(InventoryItem inventoryItem)
        {
            const string query =
                "UPDATE inventory_items SET id=@id, characterId=@characterId, itemId=@itemId, position=@position," +
                "stats=@stats, quantity=@quantity WHERE id=@id";

            Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(),
                (command) =>
                {
                    command.Parameters.Add(new MySqlParameter("@id", inventoryItem.Id));
                    command.Parameters.Add(new MySqlParameter("@characterId", inventoryItem.Character.Id));
                    command.Parameters.Add(new MySqlParameter("@itemId", inventoryItem.ItemInfos.Id));
                    command.Parameters.Add(new MySqlParameter("@position", (int) inventoryItem.ItemPosition));
                    command.Parameters.Add(new MySqlParameter("@stats", string.Join(",", inventoryItem.Stats)));
                    command.Parameters.Add(new MySqlParameter("@quantity", inventoryItem.Quantity));
                });
        }
Пример #4
0
        public static void Create(InventoryItem inventoryItem, bool addToList)
        {
            const string query =
                "INSERT INTO inventory_items SET id=@id, characterId=@characterId, itemId=@itemId, position=@position," +
                "stats=@stats, quantity=@quantity";

            Base.Repository.ExecuteQuery(query, GameDbManager.GetDatabaseConnection(),
                (command) =>
                {
                    command.Parameters.Add(new MySqlParameter("@id", inventoryItem.Id));
                    command.Parameters.Add(new MySqlParameter("@characterId", inventoryItem.Character.Id));
                    command.Parameters.Add(new MySqlParameter("@itemId", inventoryItem.ItemInfos.Id));
                    command.Parameters.Add(new MySqlParameter("@position", (int) inventoryItem.ItemPosition));
                    command.Parameters.Add(new MySqlParameter("@stats", string.Join(",", inventoryItem.Stats)));
                    command.Parameters.Add(new MySqlParameter("@quantity", inventoryItem.Quantity));
                });

            if (!addToList) return;

            lock (DatabaseProvider.InventoryItems)
                DatabaseProvider.InventoryItems.Add(inventoryItem);
        }
Пример #5
0
        public void AddItem(Character character, InventoryItem item, int quantity, GameClient client,
            GameClient receiverClient)
        {
            _timer = DateTime.Now;

            UnLockExchangeCases(client, receiverClient); // Update exchange board

            InventoryItem existItem;

            if (FirstTrader == character)
            {
                existItem =
                    _firstTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }
            else
            {
                existItem =
                    _secondTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }

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

                client.SendPackets(string.Format("{0}+{1}|{2}", Packet.ExchangeObjectLocalObjectMove, item.Id,
                    existItem.Quantity));

                receiverClient.SendPackets(string.Format("{0}+{1}", Packet.ExchangeObjectDistantObjectMove,
                    item.ToExchangeFormat(existItem.Quantity)));
            }
            else
            {
                var newItem = item.Copy(quantity: quantity);

                if (character == FirstTrader)
                    _firstTraderItems.Add(newItem);
                else
                    _secondTraderItems.Add(newItem);

                client.SendPackets(string.Format("{0}+{1}|{2}", Packet.ExchangeObjectLocalObjectMove, item.Id,
                    newItem.Quantity));

                receiverClient.SendPackets(string.Format("{0}+{1}", Packet.ExchangeObjectDistantObjectMove,
                    item.ToExchangeFormat(newItem.Quantity)));
            }
        }
Пример #6
0
        private void RemoveTraderItem(InventoryItem existItemTrader, GameClient traderClient, InventoryItem item)
        {
            existItemTrader.Quantity -= item.Quantity;

            if (existItemTrader.Quantity <= 0)
            {
                traderClient.SendPackets(string.Format("{0}{1}", Packet.ObjectRemove, existItemTrader.Id));

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

                InventoryItemRepository.Update(existItemTrader);
            }
        }
Пример #7
0
        private void EchangeItem(GameClient firstTraderClient, GameClient secondTraderClient, InventoryItem item,
            Character trader)
        {
            var existItemSecondTrader = InventoryItem.ExistItem(item, SecondTrader);
            var existItemFirstTrader = InventoryItem.ExistItem(item, FirstTrader);

            if (FirstTrader == trader)
            {
                RemoveTraderItem(existItemFirstTrader, firstTraderClient, item);
                CreateTraderItem(SecondTrader, existItemSecondTrader, secondTraderClient, item);
            }
            else
            {
                RemoveTraderItem(existItemSecondTrader, secondTraderClient, item);
                CreateTraderItem(FirstTrader, existItemFirstTrader, firstTraderClient, item);
            }
        }
Пример #8
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);
            }
        }
Пример #9
0
        public void RemoveItem(Character character, InventoryItem item, int quantity, GameClient client,
            GameClient receiverClient)
        {
            _timer = DateTime.Now;

            UnLockExchangeCases(client, receiverClient);

            InventoryItem existItem;

            if (character == FirstTrader)
            {
                existItem =
                    _firstTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }
            else
            {
                existItem =
                    _secondTraderItems.Find(
                        x =>
                            x.Character == item.Character && x.ItemPosition == item.ItemPosition &&
                            x.ItemInfos == item.ItemInfos && x.Stats == item.Stats);
            }

            if (existItem == null) return;

            if (existItem.Quantity >= quantity)
                existItem.Quantity -= quantity;

            if (existItem.Quantity == 0)
            {
                client.SendPackets(string.Format("{0}-{1}", Packet.ExchangeObjectLocalObjectMove, item.Id));

                receiverClient.SendPackets(string.Format("{0}-{1}", Packet.ExchangeObjectDistantObjectMove, item.Id));

                if (FirstTrader == character)
                    _firstTraderItems.Remove(existItem);
                else
                    _secondTraderItems.Remove(existItem);
            }
            else
            {
                client.SendPackets(string.Format("{0}+{1}|{2}", Packet.ExchangeObjectLocalObjectMove, item.Id,
                    existItem.Quantity));

                receiverClient.SendPackets(string.Format("{0}+{1}", Packet.ExchangeObjectDistantObjectMove,
                    item.ToExchangeFormat(existItem.Quantity)));
            }
        }
Пример #10
0
        public void IncreaseItemSetEffect(InventoryItem item)
        {
            var itemSet = item.ItemInfos.GetSet();
            var character = item.Character;

            try
            {
                var numberOfItemsEquipedInSet = DatabaseProvider.InventoryItems.Count(
               x => x.Character == character && x.ItemInfos.GetSet() == itemSet && x.IsEquiped());

                if (itemSet.BonusesDictionary.ContainsKey(numberOfItemsEquipedInSet - 1))
                {
                    var oldBonusSet = itemSet.BonusesDictionary[numberOfItemsEquipedInSet - 1];

                    RemoveItemStats(oldBonusSet);
                }

                if (!itemSet.BonusesDictionary.ContainsKey(numberOfItemsEquipedInSet)) return;

                var newBonusSet = itemSet.BonusesDictionary[numberOfItemsEquipedInSet];

                AddItemStats(newBonusSet);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #11
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()));
            }
        }
Пример #12
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);
        }