Ejemplo n.º 1
0
        public void Command(int sessionId, int objectId, int targetObjectId, int memberId, int targetCell, int typeId)
        {
            Logger.Debug($"[{GetType().Name}]\t Add command sessionId={sessionId} objectId={objectId} targetObjectId={targetObjectId} typeId={typeId}");
            var command = new Command
            {
                CelestialObjectId       = objectId,
                TargetCelestialObjectId = targetObjectId,
                MemberId     = memberId,
                TargetCellId = targetCell,
                Type         = (CommandTypes)typeId
            };

            _gameSession.AddCommand(command);
        }
Ejemplo n.º 2
0
        private bool Flow(GameSession gameSession, IModule module)
        {
            module.ToWeapon().Reloading = 0;

            gameSession.AddCommand(new Command
            {
                Type = CommandTypes.Scanning,
                CelestialObjectId = module.OwnerId,
                TargetCellId      = (int)module.Id
            });

            gameSession.AddCommand(new Command
            {
                Type = CommandTypes.ReloadWeapon,
                CelestialObjectId = module.OwnerId,
                TargetCellId      = (int)module.Id
            });

            var spaceship = gameSession.GetCelestialObject(module.OwnerId).ToSpaceship();

            gameSession.AddHistoryMessage($"Spaceship '{spaceship.Name}' automatic launch module '{module.Name}'", GetType().Name);

            return(true);
        }
Ejemplo 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);
            }
        }