コード例 #1
0
    /// <summary>
    /// Lance une salve
    /// </summary>
    /// <param name="salvo">Salve à lancer</param>
    public void Shoot(Salvo salvo)
    {
        currentTimeBeforeNextSalvo = currentShootParameters.GetTimeBewteenSalvos;
        currentShootParameters.IncreaseSalvoIndex();

        shootedPositions = new List <List <Vector3> >();

        #region Calculate Directions
        PoolingManager poolManager           = GameManager.gameManager.PoolManager;
        Projectile     shootProjectilePrefab = poolManager.GetProjectile(salvo.GetProjectileType, PoolInteractionType.PeekFromPool);
        bool           isBoulder             = shootProjectilePrefab.IsBoulder;

        List <Vector3> allShootDirections = isBoulder ? GetAllShootPositions(salvo) : GetAllShootDirections(salvo);
        float          projectilesSpacing = salvo.GetProjectilesSpacing;
        foreach (Vector3 direction in allShootDirections)
        {
            List <Vector3>      thisShootedPos       = new List <Vector3>();
            /**/ List <Vector3> allPossiblePositions = CirclePositionsGenerator.GetAllPositionsInCircle(salvo.GetProjectileParameters.GetCurrentProjectileSize, projectilesSpacing, salvo.GetImprecisionParameter);
            for (int i = 0; i < salvo.GetNumberOfProjectiles; i++)
            {
                Projectile shootProjectile = poolManager.GetProjectile(salvo.GetProjectileType, PoolInteractionType.GetFromPool);
                shootProjectile.transform.position = transform.position;
                shootProjectile.transform.rotation = Quaternion.identity;

                if (relatedShip != null)
                {
                    shootProjectile.SetSource(relatedShip);
                }
                else if (relatedTurret != null)
                {
                    shootProjectile.SetSource(relatedTurret);
                }

                if (isBoulder)
                {
                    //List<Vector3> allPossiblePositions

                    //Vector3 modifiedPosition = direction + new Vector3(Random.Range(-salvo.GetImprecisionParameter, salvo.GetImprecisionParameter), 0, Random.Range(-salvo.GetImprecisionParameter, salvo.GetImprecisionParameter));
                    /**/
                    int     randomIndex      = Random.Range(0, allPossiblePositions.Count);
                    Vector3 modifiedPosition = direction + allPossiblePositions[randomIndex] + new Vector3(Random.Range(-projectilesSpacing / 2, projectilesSpacing / 2), 0, Random.Range(-projectilesSpacing / 2, projectilesSpacing / 2));
                    allPossiblePositions.RemoveAt(randomIndex);
                    /**/
                    shootProjectile.ShootProjectile(salvo.GetProjectileParameters, transform.position, modifiedPosition);

                    thisShootedPos.Add(modifiedPosition);
                }
                else
                {
                    Vector3 modifiedDirection = Quaternion.Euler(0, Random.Range(-salvo.GetImprecisionParameter, salvo.GetImprecisionParameter), 0) * direction;
                    shootProjectile.ShootProjectile(salvo.GetProjectileParameters, modifiedDirection, GameManager.gameManager.Player.GetShipVelocity);
                }

                shootProjectile.SetProjectileTag(currentShootParameters.GetProjectileTag);

                #region Special Parameters
                if (projectileSpecialParameters != null)
                {
                    shootProjectile.SetProjectileSpecialParameters(
                        new ProjectileSpecialParameters(
                            new ShipSpeedModifier(projectileSpecialParameters.GetSpeedModifier),
                            new ProjectilePiercingParameters(projectileSpecialParameters.GetPiercingParameters),
                            new ProjectileSkeweringParameters(projectileSpecialParameters.GetSkeweringParameters),
                            projectileSpecialParameters.GetExplosionParameters,
                            new SmokeZoneParameters(projectileSpecialParameters.GetSmokeZoneParameters),
                            new SlowingZoneParameters(projectileSpecialParameters.GetSlowingZoneParameters)
                            ));
                    shootProjectile.GetProjectileSpecialParameters.GetSkeweringParameters.SetSourceProjectile(shootProjectile);
                }
                #endregion

                if (allPossiblePositions.Count == 0 && isBoulder)
                {
                    Debug.LogWarning("couldn't shoot all boulders");
                    break;
                }
            }
            shootedPositions.Add(thisShootedPos);
        }
        #endregion

        #region Feedback
        if (shootParticleSystem != null)
        {
            //ParticleSystem.EmitParams parameters = shootParticleSystem.emission.;
            //if (shootParticleSystem.isPlaying)
            //{
            //Debug.Log("ui");
            //shootParticleSystem.Stop();
            //shootParticleSystem.Play();
            //shootParticleSystem.Emit(8);
            //waitingTimeToRelaunchShootEffect = 0.05f;

            /*}
             * else
             *  shootParticleSystem.Play();*/
            shootParticleSystem.Emit(2);
        }

        if (currentShootParameters.GetProjectileTag == AttackTag.Player)
        {
            Vibration.Vibrate(shootVibrationDuration);
            GameManager.gameManager.ScrshkManager.StartScreenshake(shootShakeParameters);
        }

        if (shootAudioSource != null)
        {
            shootAudioSource.PlaySound(currentShootParameters.GetShootSound);
        }
        #endregion

        if (currentShootParameters.GetCurrentSalvoIndex > 1)
        {
            ContinueLaunchedPreview(salvo);
        }
    }