public void Execute(Transform position)
    {
        Debug.Log("Sea mine fired!");

        AmmoFactory.CreateSeaMineShot(position, Data);
        ParticleFactory.CreateShotSmoke(position);
    }
Esempio n. 2
0
    public void Execute(Transform position)
    {
        Debug.Log("Cannonball fired!");

        AmmoFactory.CreateCannonballShot(position, Data);
        ParticleFactory.CreateShotSmoke(position);
    }
    public void Execute(Transform position)
    {
        Debug.Log("Gatling fired!");

        AmmoFactory.CreateGatlingShot(position, Data);
        ParticleFactory.CreateShotSmoke(position);
    }
Esempio n. 4
0
        public void Fire(Vector2 direction)
        {
            if (CurrentReloadTime == 0.0)
            {
                float deltaY = direction.Y - Position.Y;
                float deltaX = direction.X - Position.X;
                int   angle  = (int)MathHelper.ToDegrees((float)Math.Atan2(deltaY, deltaX));

                Vector2 shellOffs = _tankTurret.CursorPosition - Position;
                shellOffs.Normalize();
                shellOffs *= 45;

                Ammo shell = AmmoFactory.GetInstance()
                             .CreateShell("Piercing", PiercingAmmoName, Position + shellOffs, direction - Position, angle);
                shell.LoadContent(_content);
                _shells.Add(shell);

                ThreadPool.QueueUserWorkItem(OnReload);
            }
        }
Esempio n. 5
0
        public GameSession Execution(GameSession gameSession, EngineSettings settings, Command command, Action <int, string> addCommand)
        {
            var spaceship = gameSession.GetCelestialObject(command.CelestialObjectId).ToSpaceship();

            Logger.Debug($"[{GetType().Name}][Execution] Execution Shot command - {command.Type} turn '{gameSession.Turn}'");

            var jObject = JObject.Parse(command.Body);

            var targetId = (int)jObject["TargetId"];
            var objectId = (int)jObject["ObjectId"];
            var moduleId = (int)jObject["ModuleId"];
            var actionId = (int)jObject["ActionId"];

            var currentModule = spaceship.GetModule(moduleId);

            // TODO: Check is module reloaded
            if (currentModule.IsReloaded == false && settings.DebugProperties.IsAlwaysSuccessful == false)
            {
                Logger.Debug($"[{GetType().Name}][Execution] Module not reloaded. {currentModule.Reloading}/{currentModule.ReloadTime} turn '{gameSession.Turn}'");
                return(gameSession);
            }

            var commandPrediction = Prediction(gameSession, command.Type, objectId, moduleId, targetId);

            var shotResult = RandomGenerator.GetDouble(100);


            float damage = 0;

            if (commandPrediction.Max >= shotResult || settings.DebugProperties.IsAlwaysSuccessful)
            {
                // Hit
                // TODO: Move hit calculation to separate class

                var ammoId = spaceship.GetModule(moduleId).ToWeapon().AmmoId;

                damage = AmmoFactory.GetAmmo(ammoId).Damage;
            }

            var module = spaceship.GetWeaponModule(moduleId);

            var celestialObject = new Missile
            {
                Id             = RandomGenerator.GetId(),
                Chance         = commandPrediction.Max,
                Damage         = damage,
                ModuleId       = moduleId,
                ActionId       = actionId,
                Dice           = (int)shotResult,
                OwnerId        = spaceship.Id,
                TargetId       = targetId,
                PositionX      = spaceship.PositionX,
                PositionY      = spaceship.PositionY,
                Classification = CelestialObjectTypes.Missile.ToInt(),
                Direction      = 0,
                Speed          = 50,
                Name           = module.AmmoId.ToString()
            };

            // TODO: Refactor it - create Add Celestial object method on Game Session level
            gameSession.CelestialObjects.Add(celestialObject);

            // Reload module
            gameSession.GetCelestialObject(objectId).ToSpaceship().GetModule(moduleId).Reload();

            return(gameSession);
        }