Пример #1
0
        public override IEnumerable <AGameEvent> Think(List <AGameObject> gameObjects, List <AGameObject> newGameObjects, long time)
        {
            var res = new AGameEvent[] { };

            if (Wait == 0)
            {
                Speed = DefaultSpeed;
                if (ThinkCounter % 10 == 0)
                {
                    if (!gameObjects.Contains(Target) || Target == null)
                    {
                        FindTarget(gameObjects);
                    }
                    if (Target == null)
                    {
                        return(res);
                    }
                    Vector2 DirectionOnTarget = new Vector2(Target.Coordinates.X - Coordinates.X, Target.Coordinates.Y - Coordinates.Y);
                    if (DirectionOnTarget.LengthSquared() > Constants.EPSILON)
                    {
                        RunVector = DirectionOnTarget;
                    }
                }
                ThinkCounter++;
            }
            else
            {
                Wait--;
            }
            ShootVector = RunVector;

            return(res);
        }
Пример #2
0
        public void Run()
        {
            while (true)
            {
                AGameEvent gameEvent = null;

                lock (_locker)
                {
                    if (_lastClientGameEvents.Count > 0)
                    {
                        gameEvent = _lastClientGameEvents.Dequeue();
                        if (gameEvent == null)
                        {
                            return;
                        }
                    }
                }

                if (gameEvent != null)
                {
                    SendClientGameEvent(gameEvent);
                }
                else
                {
                    _queue.WaitOne();
                }
            }
        }
Пример #3
0
 protected void PushEvent(AGameEvent gameEvent)
 {
     foreach (var playerConverted in _gameObjects.Where(player => player.Is(AGameObject.EnumObjectType.Player)).OfType <MainSkyShootService>())
     {
         lock (playerConverted.NewEvents)
         {
             playerConverted.NewEvents.Enqueue(gameEvent);
         }
     }
 }
Пример #4
0
        private void SendClientGameEvent(AGameEvent gameEvent)
        {
            try
            {
                switch (gameEvent.Type)
                {
                case EventType.ObjectShootEvent:
                    var objectShootEvent = gameEvent as ObjectShootEvent;
                    if (objectShootEvent != null)
                    {
                        _service.Shoot(objectShootEvent.ShootDirection);
                    }
                    break;

                case EventType.ObjectDirectionChangedEvent:
                    var objectDirectionChanged = gameEvent as ObjectDirectionChanged;
                    if (objectDirectionChanged != null)
                    {
                        _service.Move(objectDirectionChanged.NewRunDirection);
                    }
                    break;

                case EventType.RequestForEvents:
                    GetLatestServerGameEvents();
                    break;

                case EventType.WeaponChangedEvent:
                    var weaponChanged = gameEvent as WeaponChanged;
                    if (weaponChanged != null)
                    {
                        _service.ChangeWeapon(weaponChanged.WeaponType);
                    }
                    break;

                default:
                    throw new Exception("Invalid argument");
                }
            }
            catch (Exception e)
            {
                FatalError(e);
            }
        }
Пример #5
0
 private void AddClientGameEvent(AGameEvent gameEvent)
 {
     lock (_locker)
         _lastClientGameEvents.Enqueue(gameEvent);
     _queue.Set();
 }