Пример #1
0
    /// <summary>
    /// Reset this bullet.
    /// </summary>
    public virtual void Reset()
    {
        this.source = null;

        this.GetComponent<Collider>().enabled = true;
        //this.specialCollision = false;
        this.distanceTravelled = 0.0f;

        this.GetComponent<Rigidbody>().velocity = Vector3.zero;
        this.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
        this.damageScale = 1.0f;

        this.fadeTime = 0.0f;
        this.GetComponent<Collider>().enabled = true;

        foreach ( ParticleEmitter emitter in this.GetComponentsInChildren<ParticleEmitter>() )
        {
            emitter.emit = true;
        }

        TrailRenderer trail = this.GetComponent<TrailRenderer>();
        if ( trail != null )
        {
            float originalLength = this.desc.prefab.GetComponent<TrailRenderer>().time;

            trail.time = originalLength;
        }
    }
Пример #2
0
    public BaseHealth GetCentreTarget( BaseWeaponManager _weaponScript )
    {
        List<BaseHealth> targets = this.GetTargets( _weaponScript );

        BaseHealth currentTarget = null;
        float closestAngle = float.MaxValue;
        foreach ( BaseHealth target in targets )
        {
            if ( target.currentHealth <= 0.0f )
                continue;

            Vector3 vectorToTarget = target.transform.position - _weaponScript.restrictions.transform.position;
            float angle = Vector3.Angle( _weaponScript.restrictions.transform.forward, vectorToTarget );

            if ( angle < closestAngle )
            {
                currentTarget = target;
                closestAngle = angle;
            }
        }
        return currentTarget;
    }
Пример #3
0
    public void ShiftTargetIndex( BaseWeaponManager _weaponScript, int _direction )
    {
        List<BaseHealth> validTargets = this.GetTargets( _weaponScript );

        if ( validTargets.Count == 0 )
        {
            _weaponScript.currentTarget = null;
            return;
        }

        if ( _weaponScript.currentTarget == null
          || validTargets.Count == 1 )
        {
            _weaponScript.currentTarget = validTargets[0];
            return;
        }

        int index = validTargets.IndexOf( _weaponScript.currentTarget );

        if ( index == -1 )
        {
            _weaponScript.currentTarget = validTargets[0];
            return;
        }

        index += _direction;

        while ( index >= validTargets.Count )
        {
            index -= validTargets.Count;
        }

        while ( index < 0 )
        {
            index += validTargets.Count;
        }
        _weaponScript.currentTarget = validTargets[index];
    }
Пример #4
0
    public bool IsValidTarget( BaseHealth _health, BaseWeaponManager _weaponScript )
    {
        // Ignore dead targets
        if ( _health == null
          || _health.currentHealth <= 0.0f
          || _health.enabled == false
          || _health.gameObject.activeInHierarchy == false
            // The target that is doing the search
          || _health == _weaponScript.health
            // And those that aren't of the type specfied
          || ((int)(_health.targetType) & _weaponScript.restrictions.types) == 0 )
        {
            return false;
        }

        Vector3 vectorToTarget = _health.transform.position - _weaponScript.transform.position;
        if ( _weaponScript.restrictions.ignoreBelowHorizon && Vector3.Dot( vectorToTarget, _weaponScript.transform.up ) < 0.0f )
        {
            return false;
        }

        // Ignore targets out of range
        Vector3 v = _health.transform.position - _weaponScript.restrictions.transform.position;
        float dist = v.magnitude;
        if ( _weaponScript.restrictions.maxDistance > 0.0f && dist > _weaponScript.restrictions.maxDistance )
        {
            return false;
        }

        // Ignore targets not in the team target list
        if ( _health.Owner == null || ((int)_health.Owner.team & _weaponScript.restrictions.teams ) == 0 )
        {
            return false;
        }

        RaycastHit hitInfo;
        bool hit = Physics.Linecast( _weaponScript.transform.position, _health.transform.position,
                                    out hitInfo, this.lineOfSightBlockingLayers );

        if ( hit
          && hitInfo.collider.gameObject != _health.gameObject
          && hitInfo.collider.gameObject != _weaponScript.gameObject )
        {
            return false;
        }

        return true;
    }
Пример #5
0
    public List<BaseHealth> GetTargets( BaseWeaponManager _weaponScript )
    {
        List<BaseHealth> targetList = new List<BaseHealth>();
        #if UNITY_EDITOR
        if ( Network.peerType == NetworkPeerType.Disconnected )
        {
            foreach ( KeyValuePair<int, BaseHealth> pair in this.debugTargetMap )
            {
                if ( this.IsValidTarget( pair.Value, _weaponScript ) )
                {
                    targetList.Add( pair.Value );
                }
            }
        }
        else
        #endif
        {
            foreach ( KeyValuePair<NetworkViewID, BaseHealth> pair in this.targetMap )
            {
                if ( this.IsValidTarget( pair.Value, _weaponScript ) )
                {
                    targetList.Add( pair.Value );
                }
            }
        }

        return targetList;
    }
Пример #6
0
    public BaseHealth GetNextMissileLock( BaseWeaponManager _weaponManager, int _direction )
    {
        List<BaseHealth> missiles  = new List<BaseHealth>();

        foreach ( KeyValuePair<NetworkViewID, SmartBullet> pair in this.smartBulletMap )
        {
            SeekingBullet seekingBullet = pair.Value as SeekingBullet;
            if ( seekingBullet == null )
            {
                continue;

            }
            if ( seekingBullet.target == _weaponManager.health )
            {
                missiles.Add( seekingBullet.health );
            }
        }

        #if UNITY_EDITOR
        if ( Network.peerType == NetworkPeerType.Disconnected )
        {
            foreach ( KeyValuePair<int, SmartBullet> pair in this.debugSmartBulletMap )
            {
                SeekingBullet seekingBullet = pair.Value as SeekingBullet;
                if ( seekingBullet == null )
                {
                    continue;
                }

                if ( seekingBullet.target == _weaponManager.health )
                {
                    missiles.Add( seekingBullet.health );
                }
            }
        }
        #endif

        if ( missiles.Count == 0 )
        {
            return null;
        }

        int index = missiles.IndexOf( _weaponManager.currentTarget );

        if ( index == -1 )
        {
            return missiles[0];
        }
        index += _direction;

        while ( index >= missiles.Count )
        {
            index -= missiles.Count;
        }

        while ( index < 0 )
        {
            index += missiles.Count;
        }

        return missiles[index];
    }