Beispiel #1
0
        public bool Accepted(Character character, GameClient client, GameClient receiverClient)
        {
            if (DateTime.Now < _timer.AddMilliseconds(TimeInvtervalToAccept))
                return false;

            if (character == FirstTrader)
            {
                _firstValidated = _firstValidated == false;

                LockExchangeCases(client, receiverClient, FirstTrader, _firstValidated);
            }
            else
            {
                _secondValidated = _secondValidated == false;

                LockExchangeCases(client, receiverClient, SecondTrader, _secondValidated);
            }

            return _firstValidated && _secondValidated;
        }
Beispiel #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)));
            }
        }
Beispiel #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);
            }
        }
Beispiel #4
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));
        }
Beispiel #5
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));
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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)));
            }
        }
Beispiel #9
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));
        }