// FUNCIONES PUBLICAS
    // ================================================================================================

    // Desvia el proyectil, parando todas las co-rutinas de movimiento y forzando la co-rutina de desvio
    public void Deflect(GameObject deflecter)
    {
        ResetAuxiliarValues();
        m_degree_local             += m_degree_parent;
        m_degree_parent             = 0;
        m_target                    = deflecter.transform;
        m_currentTrajectory         = UpgradeData.Trajectory.deflected;
        tempTrajectory_targetDegree = -TrackTo(deflecter.transform) + 180;
    }
 // Algunas trayectorias no son compatibles con rebote, asi que al rebotar, su trayectoria pasa a ser "normal"
 void CancelTrajectoryIfNotCompatibleWithBounce()
 {
     if (m_currentTrajectory == UpgradeData.Trajectory.wave || m_currentTrajectory == UpgradeData.Trajectory.helix ||
         m_currentTrajectory == UpgradeData.Trajectory.arc || m_currentTrajectory == UpgradeData.Trajectory.coil)
     {
         m_currentTrajectory = UpgradeData.Trajectory.normal;
         m_degree_local     += m_degree_parent;
         m_degree_parent     = 0;
     }
 }
Example #3
0
    void InitializeData()
    {
        weaponName = "Test weapon";
        weapon_lifetime_afterSplit     = 4f;
        weapon_lifetime_beforeSplit    = 4f;
        weapon_trajectory              = UpgradeData.Trajectory.normal;
        weapon_trajectoryAfterSplit    = UpgradeData.Trajectory.normal;
        weapon_firerateMultiplier      = 4f;
        weapon_effectivenessMultiplier = 1;
        weapon_multishootSpread        = 20f;
        weapon_multishoot              = 1;
        weapon_split          = 0;
        weapon_critChanceStat = CRITICAL_CHANCE_BASE;
        weapon_critDamageStat = CRITICAL_DAMAGE_BASE;

        switch (weapon_type)
        {
        case WeaponType.bullet:
        {
            weapon_speedScale = 2;
            weapon_bounces    = 0;

            baseEffect_normal      = 100;
            baseEffect_photon      = 0;
            baseEffect_nuclear     = 0;
            baseEffect_explosive   = 0;
            baseEffect_energySteal = 0;
            break;
        }

        case WeaponType.laser:
        {
            weapon_speedScale = 1.5f;
            weapon_bounces    = 2;

            baseEffect_normal      = 80;
            baseEffect_photon      = 0;
            baseEffect_nuclear     = 0;
            baseEffect_explosive   = 0;
            baseEffect_energySteal = 0;

            break;
        }

        case WeaponType.plasma:
        {
            weapon_speedScale = 1f;
            weapon_bounces    = 0;

            baseEffect_normal      = 0;
            baseEffect_photon      = 0;
            baseEffect_nuclear     = 170;
            baseEffect_explosive   = 0;
            baseEffect_energySteal = 0;
            break;
        }

        case WeaponType.photon:
        {
            weapon_speedScale = 1.15f;
            weapon_bounces    = 0;

            baseEffect_normal      = 0;
            baseEffect_photon      = 150;
            baseEffect_nuclear     = 0;
            baseEffect_explosive   = 0;
            baseEffect_energySteal = 0;

            break;
        }

        case WeaponType.missile:
        {
            weapon_speedScale = 1.35f;
            weapon_bounces    = 0;

            baseEffect_normal      = 10;
            baseEffect_photon      = 0;
            baseEffect_nuclear     = 0;
            baseEffect_explosive   = 72;
            baseEffect_energySteal = 0;
            break;
        }

        default:
        {
            weapon_speedScale = 1;
            weapon_bounces    = 0;

            baseEffect_normal      = 100;
            baseEffect_photon      = 0;
            baseEffect_nuclear     = 0;
            baseEffect_explosive   = 0;
            baseEffect_energySteal = 0;
            break;
        }
        }
    }
    private const float SPEED_TO_ARC_MULTIPLIER      = 100f;            // (CONST) Velocidad de giro del modificador Arc.

    // Inicializa los parametros del proyectil, similar a un constructor, se llama cuando alguna entidad intenta disparar.
    public void InitializeBullet(Vector3 _position, float _localRotation, float _parentRotation, WeaponData _weaponRef, EntityBase _entityUser,
                                 float _inheritedStr = 1f, bool _canSplit = true, bool _hasSplit = false, EntityBase _lastEntityDamagedByParent = null)
    {
        ResetAuxiliarValues();
        m_weaponReferenced = _weaponRef;
        m_entityUser       = _entityUser;
        m_bouncesRemaining = _weaponRef.weapon_bounces;
        m_localTimescale   = m_entityUser.m_projectileSpeedScale * m_weaponReferenced.weapon_speedScale;

        gameObject.SetActive(true);
        _entityUser.m_referencesToThisEntityInUse++;

        m_target                    = null;
        m_lastEntityDamaged         = null;
        m_lastEntityDamagedByParent = _lastEntityDamagedByParent;



        m_canSplit                = _canSplit;
        m_localSpeedMultiplier    = 1;
        transform.position        = _position;
        tempFindNewTargetCooldown = 0;

        m_degree_local  = _localRotation;
        m_degree_parent = _parentRotation;

        m_inheritedStrenght  = _inheritedStr;
        transform.localScale = Vector3.one * _inheritedStr;

        if (m_TR == null)
        {
            m_TR = this.GetComponent <TrailRenderer>();
        }
        m_TR.Clear();
        VisualSetup();

        // Comprobamos si el proyectil padre se ha fragmentado ya
        if (_hasSplit)
        {
            m_currentTrajectory = _weaponRef.weapon_trajectoryAfterSplit;
            m_lifetimeRemaining = _weaponRef.weapon_lifetime_afterSplit;
        }
        else
        {
            m_currentTrajectory = _weaponRef.weapon_trajectory;
            m_lifetimeRemaining = _entityUser.m_attachToPlayerEntity == null && _weaponRef.weapon_split > 0 ? 0.75f : _weaponRef.weapon_lifetime_beforeSplit;
        }

        // Ajustes iniciales necesarios para algunos tipos de trayectoria
        switch (m_currentTrajectory)
        {
        case UpgradeData.Trajectory.helix:
        {
            m_localSpeedMultiplier      = 1f + Mathf.Abs(m_degree_local * Mathf.PI * 0.001f);
            tempTrajectory_targetDegree = m_degree_local * -1f;
            break;
        }

        case UpgradeData.Trajectory.arc:
        {
            tempTrajectory_targetDegree     = m_degree_local * -1;
            tempTrajectory_degreeMultiplier = 0.1f + Mathf.Abs(m_degree_local * 0.01f);
            break;
        }

        case UpgradeData.Trajectory.coil:
        {
            tempTrajectory_degreeMultiplier = m_degree_local > 0 ? -8 : 8;
            m_degree_local -= 180;
            break;
        }

        case UpgradeData.Trajectory.tracking:
        {
            m_degree_local += m_degree_parent;
            m_degree_parent = 0;
            break;
        }
        }
    }