//Function used to equip turret to battleship object
    public void equipTurret(MenuManagerScript menuManagerScript, int id)
    {
        arsenalId = id;
        cargoId   = -1;
        slotName  = SlotName.Arsenal;

        battleship = FindObjectOfType <Battleship>();

        //Instantiate turret GO and its position
        Quaternion     turretOrientation = new Quaternion(0, 0, -90, 0);
        RotationTurret turretGO          = Instantiate(turretPrefab, battleship.rotationStandardTurretPositions[id], false);

        turretGO.transform.parent = battleship.rotationStandardTurretPositions[id];

        //Initiate turret
        turretGO.idTurret       = arsenalId;
        turretGO.turretButtonId = turretGO.idTurret % 4;
        if (turretGO.GetComponent <RotationTurret>() != null)
        {
            turretGO.GetComponent <RotationTurret>().viseur = battleship.viseurs[arsenalId];
        }

        //Initiate turret in battlsehip object
        if (turretGO.GetComponent <RotationTurret>() != null)
        {
            battleship.standardRotationTurrets[id] = turretGO.GetComponent <RotationTurret>();
        }
        else if (turretGO.GetComponent <FrontalTurret>() != null)
        {
            battleship.standardFrontalTurrets[id] = turretGO.GetComponent <FrontalTurret>();
        }

        //Set image turret hud
        PlayerStats.current.turretsImages[arsenalId].sprite = cargoIcone;
        PlayerStats.current.turretsImages[arsenalId].rectTransform.localScale = new Vector3(0.8f, 0.8f, 1);
        PlayerStats.current.turretsImages[arsenalId].SetNativeSize();
    }
Ejemplo n.º 2
0
    public void rotationTurretsFireManagement()
    {
        if (Input.GetMouseButtonDown(2))
        {
            equipNextTurretSet();
        }


        if (setTypeActive == SetTypeActive.Standard)
        {
            for (int i = 0; i < standardRotationTurrets.Length; i++)
            {
                RotationTurret turretToCheck = standardRotationTurrets[i];
                int            key           = turretToCheck.turretButtonId + 1;

                if ((turretToCheck.maxAmmo > 0 && turretToCheck.actualAmmo > 0) || (turretToCheck.maxAmmo == 0 && turretToCheck.cooldownTimer == 0) &&
                    Input.GetKeyDown(key.ToString()) && turretToCheck.idTurret >= 4 * indexRotationStandardTurretsSet && turretToCheck.idTurret < (indexRotationStandardTurretsSet + 1) * 4)
                {
                    if (alternativeFire)
                    {
                        if (!turretSelectedToFire.Contains(turretToCheck)) //Turret is not inside the list
                        {
                            if (overdriveIsActive && actualOverdrive >= turretToCheck.GetComponent <Turret>().descritpion.overdriveCost)
                            {
                                actualOverdrive -= turretToCheck.GetComponent <Turret>().descritpion.overdriveCost;
                                turretToCheck.GetComponent <RotationTurret>().turretOverdriveActivated = true;
                                turretSelectedToFire.Add(turretToCheck.GetComponent <RotationTurret>());
                                lockFiringRotationTurrets();
                            }
                            else
                            {
                                turretSelectedToFire.Add(turretToCheck.GetComponent <RotationTurret>());
                                lockFiringRotationTurrets();
                            }
                        }
                        else //Turret is inside the list, then remove it
                        {
                            if (turretToCheck.GetComponent <RotationTurret>().turretOverdriveActivated)
                            {
                                actualOverdrive += turretToCheck.GetComponent <Turret>().descritpion.overdriveCost;
                                turretToCheck.GetComponent <RotationTurret>().turretOverdriveActivated = false;
                            }
                            turretSelectedToFire.Remove(turretToCheck.GetComponent <RotationTurret>());
                        }
                    }
                    else
                    {
                        turretToCheck.GetComponent <RotationTurret>().fire();
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < heavyRotationTurrets.Length; i++)
            {
                RotationTurret turretToCheck = heavyRotationTurrets[i];
                int            key           = turretToCheck.turretButtonId + 1;

                if ((turretToCheck.maxAmmo > 0 && turretToCheck.actualAmmo > 0) || (turretToCheck.maxAmmo == 0 && turretToCheck.cooldownTimer == 0) &&
                    Input.GetKeyDown(key.ToString()) && turretToCheck.idTurret >= 4 * indexRotationHeavyTurretsSet && turretToCheck.idTurret < (indexRotationHeavyTurretsSet + 1) * 4)
                {
                    if (alternativeFire)
                    {
                        turretSelectedToFire.Add(turretToCheck.GetComponent <RotationTurret>());
                        lockFiringRotationTurrets();
                    }
                    else
                    {
                        turretToCheck.GetComponent <RotationTurret>().fire();
                    }
                }
            }
        }

        //Alternative fire
        if (alternativeFire && Input.GetMouseButtonDown(0) && turretSelectedToFire != null && turretSelectedToFire.Count > 0)
        {
            for (int i = 0; i < turretSelectedToFire.Count; i++)
            {
                turretSelectedToFire[i].fire();
            }
            turretSelectedToFire.Clear();
        }
    }