Exemplo n.º 1
0
        public void AddCelestialObject(int sessionId, int objectId, float positionX, float positionY, int direction, int speed,
                                       int classification, string name)
        {
            Logger.Debug($"[{GetType().Name}]\t Add celestial object sessionId={sessionId} objectId={objectId} positionX={positionX} positionY={positionY} classification={classification}");

            ICelestialObject celestialObject;

            switch (classification)
            {
            case 300:
                celestialObject = new Missile
                {
                    Id             = objectId,
                    PositionX      = positionX,
                    PositionY      = positionY,
                    Classification = classification,
                    Direction      = direction,
                    Speed          = speed,
                    Name           = name
                };
                break;

            default:
                celestialObject = new PointInSpace
                {
                    Id             = objectId,
                    PositionX      = positionX,
                    PositionY      = positionY,
                    Classification = classification,
                    Direction      = direction,
                    Speed          = speed,
                    Name           = name
                };
                break;
            }

            _gameSession.AddCelestialObject(celestialObject);
        }
Exemplo n.º 2
0
        public CommandExecuteResult Execute(GameSession gameSession, Command command)
        {
            Logger.Debug(TraceMessage.Execute(this, "Execute command scanning is started."));

            gameSession.AddHistoryMessage("started.", GetType().Name, true);

            if (RandomGenerator.DiceRoller() < gameSession.Rules.Spawn.AsteroidSmallSize)
            {
                Logger.Debug(TraceMessage.Execute(this, "Add new asteroid."));

                gameSession.AddCelestialObject(CelestialObjectsFactory.GenerateAsteroid(gameSession));
            }

            return(new CommandExecuteResult {
                Command = command, IsResume = false
            });
        }
Exemplo n.º 3
0
        private void ImplementAttack(Spaceship npcShip, Spaceship targetSpaceship, GameSession session, List <Command> sessionCommands)
        {
            Logger.Debug(TraceMessage.Execute(this, $"Set attack npc-commend for {npcShip.Id} to {targetSpaceship.Id}."));

            var modulesWeapon = npcShip.Modules.
                                Where(module => module.Category == Category.Weapon).
                                                                                               //Map(_ => _.ToWeapon()). // Convert to weapon type
                                Where(_ => _.ToWeapon().ReloadTime <= _.ToWeapon().Reloading); // GetInteger only modules with ready to use


            var distance = Coordinates.GetDistance(npcShip.GetLocation(), targetSpaceship.GetLocation());



            foreach (var weaponModule in modulesWeapon)
            {
                var missile = MissilesFactory.GetMissile(weaponModule.ToWeapon().AmmoId).ToCelestialObject();

                missile.Id        = RandomGenerator.GetId();
                missile.OwnerId   = npcShip.Id;
                missile.PositionX = npcShip.PositionX;
                missile.PositionY = npcShip.PositionY;

                var weaponTargetPointInSpace = GetTargetLocation(targetSpaceship, missile, distance);

                var targetPointInSpace = new PointInSpace
                {
                    Id             = RandomGenerator.GetId(),
                    PositionY      = weaponTargetPointInSpace.Y,
                    PositionX      = weaponTargetPointInSpace.X,
                    Speed          = 0,
                    Direction      = 0,
                    Name           = "Missile Target",
                    Signature      = 1,
                    Classification = (int)CelestialObjectTypes.PointInMap,
                    IsScanned      = true
                };

                session.AddCelestialObject(targetPointInSpace);
                session.AddCelestialObject(missile);

                var command = new Command
                {
                    CelestialObjectId       = missile.Id,
                    TargetCelestialObjectId = targetPointInSpace.Id,
                    MemberId     = 0,
                    TargetCellId = 0,
                    Type         = CommandTypes.Fire
                };

                session.AddCommand(command);

                var commandReloadModule = new Command
                {
                    CelestialObjectId       = npcShip.Id,
                    TargetCelestialObjectId = weaponModule.Id,
                    MemberId     = 0,
                    TargetCellId = 0,
                    Type         = CommandTypes.ReloadWeapon
                };

                session.AddCommand(commandReloadModule);
            }
        }