Example #1
0
        private void UnLockExchangeCases(GameClient client, GameClient receiverClient)
        {
            _firstValidated = false;
            _secondValidated = false;

            client.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, "0",
                    FirstTrader.Id));

            receiverClient.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, "0",
                FirstTrader.Id));

            client.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, "0",
                    SecondTrader.Id));

            receiverClient.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, "0",
                SecondTrader.Id));
        }
Example #2
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)));
            }
        }
Example #3
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);
            }
        }
Example #4
0
        private void LockExchangeCases(GameClient client, GameClient receiverClient, Character character, bool validated)
        {
            client.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, validated ? "1" : "0",
                    character.Id));

            receiverClient.SendPackets(string.Format("{0}{1}{2}", Packet.ExchangeReady, validated ? "1" : "0",
                character.Id));
        }
Example #5
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);
            }
        }
Example #6
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)));
            }
        }
Example #7
0
        public void AddKamas(Character character, int kamas, GameClient client, GameClient receiverClient)
        {
            _timer = DateTime.Now;

            UnLockExchangeCases(client, receiverClient);

            if (FirstTrader == character)
                FirstKamas = kamas;
            else
                SecondKamas = kamas;

            client.SendPackets(string.Format("{0}{1}", Packet.ExchangeObjectLocalKamasMove, kamas));
            receiverClient.SendPackets(string.Format("{0}{1}", Packet.ExchangeObjectDistantKamasMove, kamas));
        }