Example #1
0
        private void LeaveExchange(string data)
        {
            if (_client.Character.State != Character.CharacterState.OnExchange)
            {
                return;
            }

            var receiverCharacter = _client.Character.ExchangeWithCharacter;

            if (receiverCharacter != null)
            {
                _client.Character.LeaveExchangeWithPlayer();
            }

            var receiverClient = GameServer.Clients.Find(x => x.Character == receiverCharacter);

            var exchangeSession =
                ExchangeManager.Exchanges.Find(
                    x => x.FirstTrader == _client.Character && x.SecondTrader == receiverClient.Character ||
                    x.FirstTrader == receiverClient.Character && x.SecondTrader == _client.Character);

            if (exchangeSession != null)
            {
                ExchangeManager.CloseExchangeSession(exchangeSession);
            }

            receiverClient.SendPackets(Packet.ExchangeLeave);
            _client.SendPackets(Packet.ExchangeLeave);
        }
Example #2
0
        private void ExchangeReady(string data)
        {
            if (_client.Character.State != Character.CharacterState.OnExchange)
            {
                return;
            }

            var receiverCharacter = _client.Character.ExchangeWithCharacter;

            var receiverClient = GameServer.Clients.Find(x => x.Character == receiverCharacter);

            if (receiverClient == null)
            {
                return;
            }

            var exchangeSession =
                ExchangeManager.Exchanges.Find(
                    x => x.FirstTrader == _client.Character && x.SecondTrader == receiverClient.Character ||
                    x.FirstTrader == receiverClient.Character && x.SecondTrader == _client.Character);

            if (exchangeSession == null)
            {
                return;
            }

            var finishedExchange = exchangeSession.Accepted(_client.Character, _client, receiverClient);

            if (!finishedExchange)
            {
                return;
            }

            exchangeSession.Swap();

            ExchangeManager.CloseExchangeSession(exchangeSession);

            receiverClient.Character.State = Character.CharacterState.Free;
            receiverClient.Character.ExchangeWithCharacter = null;

            _client.Character.State = Character.CharacterState.Free;
            _client.Character.ExchangeWithCharacter = null;
        }