Пример #1
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)));
            }
        }
Пример #2
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)));
            }
        }