Example #1
0
 private void OnGainVision(byte[] packet, Channel channel)
 {
     if (!_isOdin)
     {
         Send(Deserialize <MovementRequest>(MovementRequest.CreateCoop(_myNetId)));
     }
 }
Example #2
0
        public async void Start()
        {
            var ip          = _credentials.serverIp;
            var port        = Convert.ToUInt16(_credentials.serverPort);
            var blowfishKey = Convert.FromBase64String(_credentials.encryptionKey);

            _mySummonerId = Convert.ToUInt64(_credentials.summonerId);

            _blowfish = new BlowFish(blowfishKey);

            // Initialize ENetCS
            Library.Initialize();

            // Initialize Log Class.
            Log.Initialize();

            _enetHost = new Host();
            _enetHost.Create(null, 1);

            var address = new Address();

            address.SetHost(ip);
            address.Port = port;

            _peer = _enetHost.Connect(address, 8);

            _movementTimer          = new Timer();
            _movementTimer.Interval = TimeSpan.FromSeconds(6).TotalMilliseconds;
            _movementTimer.Elapsed += (s, e) =>
            {
                if (_gameStarted && _myNetId != 0)
                {
                    if (!_isOdin)
                    {
                        //                      Log.Write("[{0}] Attempting to move down mid.", _myPlayer);
                        Send(Deserialize <MovementRequest>(MovementRequest.CreateCoop(_myNetId)));
                    }
                    else
                    {
                        if (_isOrder && _captures == 0 && (DateTime.Now - _gameStartTime).TotalSeconds >= 90)
                        {
                            Log.Write("[{0}] Capturing point A", _myPlayer);
                            Send(Deserialize <CapturePoint>(CapturePoint.Create(_myNetId, _capturePoints[0])));
                        }
                        else if (_isOrder && _captures == 8)
                        {
                            if ((DateTime.Now - _gameStartTime).TotalMilliseconds >= 170000)
                            {
                                Send(Deserialize <CapturePoint>(CapturePoint.Create(_myNetId, _capturePoints[4])));
                            }
                            else
                            {
                                Send(Deserialize <MovementRequest>(MovementRequest.CreateOdin(_myNetId, _move)));
                                _move = !_move;
                            }
                        }
                        else if (!_isOrder)
                        {
                            Send(Deserialize <MovementRequest>(MovementRequest.CreateOdin(_myNetId, _move)));
                            _move = !_move;
                        }
                    }

                    if ((DateTime.Now - _gameStartTime).TotalMinutes >= 20)
                    {
//                        Log.Write("[{0}] Attempting to surrender.", _myPlayer);
                        Send(Deserialize <Surrender>(Surrender.Create(_myNetId, 1)));
                    }
                }
            };

            _movementTimer.Start();
            while (_enetHost.Service(1) >= 0)
            {
                Event enetEvent;
                try
                {
                    while (_enetHost.CheckEvents(out enetEvent) > 0)
                    {
                        switch (enetEvent.Type)
                        {
                        case EventType.Connect:
                            OnConnect(blowfishKey);
                            break;

                        case EventType.Receive:
                            OnRecieve(enetEvent);
                            break;

                        case EventType.Disconnect:
                            break;
                        }
                    }
                }catch (InvalidOperationException)
                {
                    break;
                }
            }
        }