Exemple #1
0
    protected void Shoot()
    {
        if (bb.shootPressed)
        {
            if (bb.canShoot)
            {
                rsc.rumbleMng.AddContinousRumble(RumbleId.PLAYER_SHOOT, bb.player.Id, 0.0f, 0.1f);

                if (Time.time > bb.nextFire)
                {
                    if (Time.time - bb.nextFire > Time.deltaTime)
                    {
                        bb.nextFire = Time.time + bb.player.fireRate;
                    }
                    else
                    {
                        bb.nextFire = bb.nextFire + bb.player.fireRate;
                    }
                    //Debug.Log("Time: " + Time.time);
                    //Debug.Log("Next: " + bb.nextFire);

                    // check if it's first shot (single projectile)...
                    if (bb.firstShot || bb.player.numberOfShots == 1)
                    {
                        //Get a shot from pool
                        PlayerShotController shot;

                        switch (bb.player.Id)
                        {
                        case 1:
                            shot = coloredObjMng.GetPlayer1Shot();
                            break;

                        case 2:
                            shot = coloredObjMng.GetPlayer2Shot();
                            break;

                        default:
                            shot = coloredObjMng.GetPlayer1Shot();
                            break;
                        }

                        MuzzleController muzzle = coloredObjMng.GetPlayerMuzzle();

                        if (shot != null && muzzle != null)
                        {
                            Transform shotSpawn = bb.player.shotSpawn;
                            shot.transform.position = shotSpawn.position;
                            shot.transform.rotation = shotSpawn.rotation;
                            if (bb.player.numberOfShots != 1)
                            {
                                shot.damage *= 2;
                            }
                            shot.player = bb.player;
                            shot.Shoot();

                            Transform muzzlePoint = bb.player.muzzlePoint;
                            muzzle.transform.SetParent(muzzlePoint);
                            muzzle.transform.position = muzzlePoint.position;
                            muzzle.transform.rotation = muzzlePoint.rotation;
                            muzzle.Play();
                        }
                        bb.firstShot = false;
                    }
                    // ...or not (double projectile)
                    else
                    {
                        //Get two shots from pool
                        PlayerShotController shot1;
                        PlayerShotController shot2;

                        switch (bb.player.Id)
                        {
                        case 1:
                            shot1 = coloredObjMng.GetPlayer1Shot();
                            shot2 = coloredObjMng.GetPlayer1Shot();
                            break;

                        case 2:
                            shot1 = coloredObjMng.GetPlayer2Shot();
                            shot2 = coloredObjMng.GetPlayer2Shot();
                            break;

                        default:
                            shot1 = coloredObjMng.GetPlayer1Shot();
                            shot2 = coloredObjMng.GetPlayer1Shot();
                            break;
                        }

                        MuzzleController muzzle1 = coloredObjMng.GetPlayerMuzzle();
                        MuzzleController muzzle2 = coloredObjMng.GetPlayerMuzzle();

                        if (shot1 != null && shot2 != null && muzzle1 != null && muzzle2 != null)
                        {
                            Transform shotSpawn   = bb.player.shotSpawn;
                            Transform muzzlePoint = bb.player.muzzlePoint;

                            shot1.transform.rotation = shotSpawn.rotation;
                            shot1.transform.position = shotSpawn.position;
                            shot1.transform.Translate(new Vector3(shotSideOffset, 0, 0));
                            shot1.player = bb.player;
                            shot1.Shoot();

                            muzzle1.transform.position = muzzlePoint.position;
                            muzzle1.transform.rotation = muzzlePoint.rotation;
                            muzzle1.transform.SetParent(muzzlePoint);
                            muzzle1.transform.Translate(new Vector3(shotSideOffset, 0, 0));
                            muzzle1.Play();

                            shot2.transform.rotation = shotSpawn.rotation;
                            shot2.transform.position = shotSpawn.position;
                            shot2.transform.Translate(new Vector3(-shotSideOffset, 0, 0));
                            shot2.player = bb.player;
                            shot2.Shoot();

                            muzzle2.transform.position = muzzlePoint.position;
                            muzzle2.transform.rotation = muzzlePoint.rotation;
                            muzzle2.transform.SetParent(muzzlePoint);
                            muzzle2.transform.Translate(new Vector3(-shotSideOffset, 0, 0));
                            muzzle2.Play();

                            if (shotSideOffset <= minSideOffset || shotSideOffset >= maxSideOffset)
                            {
                                sideOffsetVariation *= -1;
                            }

                            shotSideOffset += sideOffsetVariation;
                        }
                    }
                }
            }
            else
            {
                bb.player.StartNoShoot();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case State.ENABLED:
            if (elapsedTime < attackWaitTime)
            {
                elapsedTime += Time.deltaTime;
            }

            PlayerController target = GetNearestPlayer();
            if (target != null)
            {
                Vector3 lookingVector;

                lookingVector   = target.transform.position - transform.position;
                lookingVector.y = 0f;

                Quaternion newRotation = Quaternion.LookRotation(lookingVector);
                newRotation             = Quaternion.RotateTowards(rotationObject.rotation, newRotation, angularSpeed * Time.deltaTime);
                rotationObject.rotation = newRotation;

                float angle = Vector3.Angle(lookingVector, rotationObject.forward);

                if (angle <= maxShootAngle && elapsedTime >= attackWaitTime)
                {
                    //Shoot
                    MosquitoMainAttackControllerBase attack1;
                    MosquitoMainAttackControllerBase attack2;

                    switch (currentColor)
                    {
                    case ChromaColor.RED:
                        attack1 = rsc.poolMng.mosquitoHomingProjectilePool.GetObject();
                        attack2 = rsc.poolMng.mosquitoHomingProjectilePool.GetObject();
                        break;

                    case ChromaColor.GREEN:
                        attack1 = rsc.poolMng.mosquitoFanProjectilePool.GetObject();
                        attack2 = rsc.poolMng.mosquitoFanProjectilePool.GetObject();
                        break;

                    case ChromaColor.BLUE:
                        attack1 = rsc.poolMng.mosquitoMultipleProjectilePool.GetObject();
                        attack2 = rsc.poolMng.mosquitoMultipleProjectilePool.GetObject();
                        break;

                    case ChromaColor.YELLOW:
                        attack1 = rsc.poolMng.mosquitoSingleProjectilePool.GetObject();
                        attack2 = rsc.poolMng.mosquitoSingleProjectilePool.GetObject();
                        break;

                    default:
                        attack1 = null;
                        attack2 = null;
                        break;
                    }

                    if (attack1 != null)
                    {
                        attack1.Shoot(shotSpawnPoint1, target);

                        MuzzleController muzzle1 = rsc.coloredObjectsMng.GetTurretMuzzle();
                        if (muzzle1 != null)
                        {
                            muzzle1.transform.position = muzzleSpawnPoint1.position;
                            muzzle1.transform.rotation = muzzleSpawnPoint1.rotation;
                            muzzle1.transform.SetParent(muzzleSpawnPoint1);
                            muzzle1.Play();
                        }
                    }

                    if (attack2 != null)
                    {
                        attack2.Shoot(shotSpawnPoint2, target);

                        MuzzleController muzzle2 = rsc.coloredObjectsMng.GetTurretMuzzle();
                        if (muzzle2 != null)
                        {
                            muzzle2.transform.position = muzzleSpawnPoint2.position;
                            muzzle2.transform.rotation = muzzleSpawnPoint2.rotation;
                            muzzle2.transform.SetParent(muzzleSpawnPoint2);
                            muzzle2.Play();
                        }
                    }

                    anim.SetTrigger("Fire");

                    attackWaitTime = UnityEngine.Random.Range(AttackSettingsPhase.minWaitTime, AttackSettingsPhase.maxWaitTime);
                    elapsedTime    = 0f;
                }
            }
            break;

        case State.KNOCKED_OUT:
            if (elapsedTime < AttackSettingsPhase.knockOutTime)
            {
                elapsedTime += Time.deltaTime;

                if (knockOutElapsedTime >= knockOutFXChangeTime)
                {
                    knockOutElapsedTime -= knockOutFXChangeTime;
                    float   newX   = UnityEngine.Random.Range(knockedOutMaxXoffset * -1, knockedOutMaxXoffset);
                    float   newZ   = UnityEngine.Random.Range(knockedOutMaxZoffset * -1, knockedOutMaxZoffset);
                    Vector3 newPos = new Vector3(newX, knockedOutYOffset, newZ);
                    knockedOutFx.transform.localPosition = newPos;
                }
                else
                {
                    knockOutElapsedTime += Time.deltaTime;
                }
            }
            else
            {
                elapsedTime    = 0;
                currentHealth  = AttackSettingsPhase.maxHealth;
                attackWaitTime = UnityEngine.Random.Range(AttackSettingsPhase.minWaitTime, AttackSettingsPhase.maxWaitTime);
                state          = State.ENABLED;
                anim.SetBool("Broken", false);
                knockedOutFx.Stop();
            }
            break;
        }
    }