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); }
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(); } } }
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); } } }
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); } }
private void AddClientGameEvent(AGameEvent gameEvent) { lock (_locker) _lastClientGameEvents.Enqueue(gameEvent); _queue.Set(); }