public virtual bool CheckErrors()
    {
        error = false;

        if (weapons.Length > 0)
        {
            for (int cw = 0; cw < weapons.Length; cw++)
            {
                if (weapons[cw].weapon == false)
                {
                    Debug.Log(this + ": TurretControl weapon index " + cw + " hasn't been defined."); error = true;
                }
            }
        }

        if (!targetingScript)
        {
            targetingScript = UtilityMF.GetComponentInParent <MF_AbstractTargeting>(transform);
        }

        if (!GetComponent <MF_AbstractPlatform>())
        {
            Debug.Log(this + ": No platform script found."); error = true;
        }

        return(error);
    }
Пример #2
0
    // -------------------------------------- end of FxItem

    void OnValidate()
    {
        if (Application.isPlaying == true)
        {
            if (dying == true || dead == true)
            {
                return;
            }                                      // don't change while effects are possibly detached
            if (validate == false)                 // prevent Add() running more than once
            {
                statsScript = UtilityMF.GetComponentInParent <MF_AbstractStats>(transform);
                if (statsScript)
                {
                    statsScript.fxScript.Add(this);
                }
            }

            float dur = 0f;
            for (int i = 0; i < fxList.Length; i++)
            {
                fxList[i].thisScript  = this;
                fxList[i].statsScript = statsScript;
                fxList[i].Validate();
                dur             = Mathf.Max(fxList[i].fxDuration, fxList[i].duration == true ? fxList[i].minTime : 0f);
                longestDuration = Mathf.Max(longestDuration, dur);
            }
            validate = true;
            CheckUnit();
        }
    }
    public virtual bool CheckErrors()
    {
        error = false;
        Transform rps;

        if (weapons.Length > 0)
        {
            for (int cw = 0; cw < weapons.Length; cw++)
            {
                if (weapons[cw].weapon == false)
                {
                    Debug.Log(this + ": TurretControl weapon index " + cw + " hasn't been defined."); error = true;
                }
            }
        }

        // look for defined targeting script
        if (!targetingScript)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractTargeting", transform);
            if (rps != null)
            {
                targetingScript = rps.GetComponent <MF_AbstractTargeting>();
            }
        }

        return(error);
    }
Пример #4
0
    public virtual bool CheckErrors()
    {
        // look for defined receiving object
        if (!receivingObject && dontSearchForReceivingObject == false)
        {
            MF_AbstractPlatform ap = UtilityMF.GetComponentInParent <MF_AbstractPlatform>(transform);
            if (ap)
            {
                receivingObject = ap.gameObject;
            }
        }

        return(error);
    }
Пример #5
0
    public override bool CheckErrors()
    {
        base.CheckErrors();

        if (!targetListScript)
        {
            targetListScript = UtilityMF.GetComponentInParent <MF_B_TargetList>(transform);
            if (targetListScript == null)
            {
                Debug.Log(this + ": No target list found."); error = true;
            }
        }

        return(error);
    }
Пример #6
0
    public virtual bool CheckErrors()
    {
        error = false;

        if (!selectionScript)
        {
            selectionScript = UtilityMF.GetComponentInParent <MF_AbstractSelection>(transform);
            if (selectionScript == null)
            {
                Debug.Log(this + ": No selection script found."); error = true;
            }
        }

        return(error);
    }
Пример #7
0
    bool CheckErrors()
    {
        error = false;

        if (!mobilityScript)
        {
            mobilityScript = UtilityMF.GetComponentInParent <MF_AbstractMobility>(transform);
        }

        if (!targetingScript)
        {
            targetingScript = GetComponent <MF_AbstractTargeting>();
        }

        return(error);
    }
    public virtual bool CheckErrors()
    {
        Transform rps;

        // look for defined receiving object
        if (!receivingObject && dontSearchForReceivingObject == false)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractPlatform", transform);
            if (rps != null)
            {
                receivingObject = rps.gameObject;
            }
        }

        return(error);
    }
    public virtual bool CheckErrors()
    {
        error = false;

        Transform rps;

        if (selectionManager)
        {
            if (!selectionManager.GetComponent <MF_SelectionManager>())
            {
                Debug.Log(this + ": No MF_SelectionManager script found on defined selection manager."); error = true;
            }
        }
        else
        {
            Debug.Log(this + ": No Selection Manager defined."); error = true;
        }

        if (!targetListScript && NoTargetList == false)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractTargetList", transform);
            if (rps != null)
            {
                targetListScript = rps.GetComponent <MF_AbstractTargetList>();
            }
        }

        if (!targetingScript && NoTargetingScript == false)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractTargeting", transform);
            if (rps != null)
            {
                targetingScript = rps.GetComponent <MF_AbstractTargeting>();
            }
        }

        if (!navigationScript && NoNavigationScript == false)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractNavigation", transform);
            if (rps != null)
            {
                navigationScript = rps.GetComponent <MF_AbstractNavigation>();
            }
        }

        return(error);
    }
Пример #10
0
    public virtual void Awake()
    {
        MF_AbstractStats sScript = null;

        if (transform.parent)
        {
            sScript = transform.parent.GetComponentInParent <MF_AbstractStats>();
        }
        if (sScript)
        {
            sScript.statsScript.Add(this);
        }
        poolRefScript = gameObject.GetComponent <AP_Reference>();
        if (size == 0)             // Find size of object if not already defined
        {
            size = UtilityMF.FindColliderBoundsSize(transform, true);
        }
    }
Пример #11
0
    private bool CheckErrors()
    {
        Transform rps;

        if (!targetListScript)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_B_TargetList", transform);
            if (rps != null)
            {
                targetListScript = rps.GetComponent <MF_B_TargetList>();
            }
            else
            {
                Debug.Log(this + ": Target list location not found."); error = true;
            }
        }
        return(error);
    }
Пример #12
0
    private bool CheckErrors()
    {
        if (!targetListScript)
        {
            targetListScript = UtilityMF.GetComponentInParent <MF_B_TargetList>(transform);
            if (targetListScript == null)
            {
                Debug.Log(this + ": Target list location not found."); error = true;
            }
        }

        cScript = UtilityMF.GetComponentInParent <MF_AbstractClassify>(transform);
        if (cScript == null)
        {
            Debug.Log(this + ": Classify script not found."); error = true;
        }

        return(error);
    }
Пример #13
0
    public virtual bool CheckErrors()
    {
        error = false;

        if (!targetListScript && NoTargetList == false)
        {
            targetListScript = UtilityMF.GetComponentInParent <MF_AbstractTargetList>(transform);
        }

        if (!targetingScript && NoTargetingScript == false)
        {
            targetingScript = UtilityMF.GetComponentInParent <MF_AbstractTargeting>(transform);
        }

        if (!navigationScript && NoNavigationScript == false)
        {
            navigationScript = UtilityMF.GetComponentInParent <MF_AbstractNavigation>(transform);
        }

        return(error);
    }
Пример #14
0
    public virtual bool CheckErrors()
    {
        error = false;

        Transform rps;

        if (!selectionScript)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractSelection", transform);
            if (rps != null)
            {
                selectionScript = rps.GetComponent <MF_AbstractSelection>();
            }
            else
            {
                Debug.Log(this + ": No selection script found."); error = true;
            }
        }

        return(error);
    }
    // create brackets
    public GameObject MakeBracket(GameObject prefab)
    {
        if (prefab == null)
        {
            return(null);
        }
        GameObject newBracket = (GameObject)Instantiate(prefab, transform.position, transform.rotation);

        newBracket.transform.SetParent(transform);
        if (bracketSize == 0)             // try to determine size from collider bounds
        {
            bracketSize = UtilityMF.FindColliderBoundsSize(clickObjectBase.transform, true) * 3f;
            if (bracketSize == 0)
            {
                bracketSize = 1;
            }                                                        // if no collider found, set to 1
        }
        newBracket.GetComponent <ParticleSystem>().startSize = bracketSize;
        newBracket.SetActive(false);
        return(newBracket);
    }
Пример #16
0
    // create brackets
    public GameObject MakeMark(GameObject prefab)
    {
        if (prefab == null)
        {
            return(null);
        }
        GameObject newMark = (GameObject)Instantiate(prefab, transform.position, transform.rotation);

        newMark.transform.SetParent(transform);
        if (markSize == 0)             // try to determine size from collider bounds
        {
            markSize = UtilityMF.FindColliderBoundsSize(clickObjectBase.transform, true) * 3f;
            if (markSize == 0)
            {
                markSize = 1;
            }                                                  // if no collider found, set to 1
        }
        ParticleSystem.MainModule ps = newMark.GetComponent <ParticleSystem>().main;
        ps.startSize = markSize;
        newMark.SetActive(false);
        return(newMark);
    }
Пример #17
0
    bool CheckErrors()
    {
        error = false;
        Transform rps = null;

        if (!mobilityScript)
        {
            rps = UtilityMF.RecursiveParentComponentSearch("MF_AbstractMobility", transform);
            if (rps != null)
            {
                mobilityScript = rps.GetComponent <MF_AbstractMobility>();
            }
        }

        if (!targetingScript)
        {
            if (GetComponent <MF_AbstractTargeting>())
            {
                targetingScript = GetComponent <MF_AbstractTargeting>();
            }
        }

        return(error);
    }
Пример #18
0
    void Shoot()
    {
        // check line of sight
        losClear = true;
        if (checkLOS == true)
        {
            if (Time.time >= lastLosCheck + losCheckInterval)
            {
                RaycastHit _hit;
                Vector3    _startPos = weapons[curWeapon].script.exits[weapons[curWeapon].script.curExit].transform.position;
                if (Physics.Linecast(_startPos, _target.position, out _hit))
                {
                    // recursively search parent of hit collider for target
                    losClear = UtilityMF.RecursiveParentTransformSearch(_target, _hit.transform);
                }
                lastLosCheck = Time.time;
            }
        }

        // fire weapons
        if (losClear == true)
        {
            if (weapons[curWeapon].script.RangeCheck(_target) == true)
            {
                // if targeting script can mark targets, mark when firing
                if (targetingScript.isMarkingTarg == true)
                {
                    if (weapons.Length > 0)
                    {
                        targetingScript.SetMarkedTime(weapons[curWeapon].script.GetTimeOfFlight(_target));
                    }
                }

                if (alternatingFire == true && weapons.Length > 1)                        // alternate fire bewteen weapons
                {
                    weapons[curWeapon].script.platformVelocity = platformScript.velocity; // send velocity to weapon script

                    if (fullBurst == true && bursting != null)
                    {
                        // based on weapons[0] cycle rate. for best results, all weapons should have the same cycle time
                        float _delay = lastFire + (weapons[0].script.cycleTime / weapons.Length);
                        if (weapons[curWeapon].script.ReadyCheck() == true)                             // needed to keep weapon cycle time in sync with delay in this script. (Make sure ShootBurst() is ready to be called)
                        {
                            if (Time.time >= _delay)
                            {
                                bursting = true;
                                if (weapons[curWeapon].burst == false)
                                {
                                    weapons[curWeapon].burst = true;
                                    weapons[curWeapon].script.ShootBurst();
                                    curWeapon = MFmath.Mod(curWeapon + 1, weapons.Length);
                                    lastFire  = Time.time;
                                }
                            }
                        }
                    }
                    else
                    {
                        // based on weapons[0] cycle rate. for best results, all weapons should have the same cycle time
                        if (Time.time >= lastFire + (weapons[0].script.cycleTime / weapons.Length))
                        {
                            weapons[curWeapon].script.Shoot();
                            curWeapon = MFmath.Mod(curWeapon + 1, weapons.Length);
                            lastFire  = Time.time;
                        }
                    }
                }
                else                     // fire all weapons at once
                {
                    for (int sw = 0; sw < weapons.Length; sw++)
                    {
                        weapons[sw].script.platformVelocity = platformScript.velocity;                         // send velocity to weapon script
                        if (fullBurst == true && bursting != null)
                        {
                            bursting = true;
                            if (weapons[sw].burst == false)
                            {
                                weapons[sw].burst = true;
                                weapons[sw].script.ShootBurst(_target);
                            }
                        }
                        else
                        {
                            weapons[sw].script.Shoot(_target);
                        }
                    }
                }
            }
        }
    }
Пример #19
0
 void OnValidate()
 {
     spawnsPoints = UtilityMF.BuildArrayFromChildren(spawnPointsGroup);
 }
Пример #20
0
    void Shoot()
    {
        // check line of sight
        if (checkLOS == false || controller == ControlType.Player_Mouse || controller == ControlType.Player_Click)             // always clear when not using LOS or under player control
        {
            losClear = true;
        }
        else
        {
            if (Time.time >= lastLosCheck + losCheckInterval)
            {
                RaycastHit _hit;
                losClear = false;
                Vector3 _startPos = weapons[curWeapon].script.exits[weapons[curWeapon].script.curExit].transform.position;

                bool _directLos = (turretScript.useGravity == false || alwaysDirectLos == true) ? true : false;
                if (_directLos == false)                     // use ballistic approximation los line
                {
                    float?  _shotSpeed     = turretScript.shotSpeed;
                    Vector3 _startDir      = weapons[curWeapon].script.exits[weapons[curWeapon].script.curExit].transform.forward;
                    Vector3 _startDirHoriz = new Vector3(_startDir.x, 0f, _startDir.z);

                    int   _factor   = -Physics.gravity.y > 0 ? 1 : -1;
                    float _aimAngle = MFmath.AngleSigned(_startDirHoriz, _startDir, Vector3.Cross(_startDir, Vector3.up));
                    if (_factor * _aimAngle > 0)                         // aiming up, find apex, use los to apex and then to target
                    {
                        float _ballRange = (float)((_shotSpeed * _shotSpeed) * Mathf.Sin(_factor * 2 * _aimAngle * Mathf.Deg2Rad)) / (_factor * -Physics.gravity.y);
                        // compare range
                        if ((_startPos - _target.position).sqrMagnitude <= _ballRange * _ballRange * .25) // squaring 1/2 _ballRange
                        {
                            _directLos = true;                                                            // if target before apex, just use direct los
                        }
                        else                                                                              // continue to do ballistic los

                        {
                            Vector3 _midPos   = _startPos + (_startDirHoriz.normalized * _ballRange * .5f);
                            float   _ballPeak = (float)((_startDir.y * _shotSpeed) * (_startDir.y * _shotSpeed)) / (-Physics.gravity.y * 2f);
                            Vector3 _apexPos  = _midPos + (Vector3.up * _ballPeak);

//							//Debug.DrawLine( _startPos, _startPos + ((_startDirHoriz).normalized * _ballRange), Color.cyan, .1f );
//							Debug.DrawLine( _startPos, target.transform.position, Color.green, .1f );
//							Debug.DrawLine( _startPos, _apexPos, Color.red, .1f );
//							Debug.DrawLine( _apexPos, target.transform.position, Color.red, .1f );

                            // check los
                            if (Physics.Linecast(_startPos, _apexPos, out _hit))                                // check exit to apex
                            // recursively search parent of hit collider for target
                            {
                                losClear = UtilityMF.RecursiveParentTransformSearch(_target, _hit.transform);
                            }
                            else if (Physics.Linecast(_apexPos, _target.position, out _hit))                                  // check apex to target
                            // recursively search parent of hit collider for target
                            {
                                losClear = UtilityMF.RecursiveParentTransformSearch(_target, _hit.transform);
                            }

                            if (losClear == false)
                            {
                                if (losMayChangeArc == true)
                                {
                                    turretScript.curArc = turretScript.defaultArc == MFnum.ArcType.Low ? MFnum.ArcType.High : MFnum.ArcType.Low;
                                }
                            }
                        }
                    }
                    else                         // aiming downwards (already past apex) just use direct los
                    {
                        _directLos = true;
                    }
                }
                if (_directLos == true)                     // use direct los line
                {
                    if (Physics.Raycast(_startPos, _target.position - _startPos, out _hit, weapons[curWeapon].script.maxRange))
                    {
                        // recursively search parent of hit collider for target
                        losClear = UtilityMF.RecursiveParentTransformSearch(_target, _hit.transform);
                    }
                }
                lastLosCheck = Time.time;
            }
        }

        // fire weapons
        if (losClear == true)
        {
            if (weapons[curWeapon].script.RangeCheck(_target) == true)
            {
                if (alternatingFire == true && weapons.Length > 1)                      // alternate fire bewteen weapons
                {
                    weapons[curWeapon].script.platformVelocity = turretScript.velocity; // send velocity to current weapon script

                    if (fullBurst == true && bursting != null)
                    {
                        // based on weapons[0] cycle rate. for best results, all weapons should have the same cycle time
                        float _delay = lastFire + (weapons[0].script.cycleTime / weapons.Length);
                        if (weapons[curWeapon].script.ReadyCheck() == true)                             // needed to keep weapon cycle time in sync with delay in this script. (Make sure ShootBurst() is ready to be called)
                        {
                            if (Time.time >= _delay)
                            {
                                bursting = true;
                                if (weapons[curWeapon].burst == false)
                                {
                                    weapons[curWeapon].burst = true;
                                    weapons[curWeapon].script.ShootBurst();
                                    curWeapon = MFmath.Mod(curWeapon + 1, weapons.Length);
                                    lastFire  = Time.time;
                                }
                            }
                        }
                    }
                    if (fullBurst == false)
                    {
                        // based on weapons[0] cycle rate. for best results, all weapons should have the same cycle time
                        if (Time.time >= lastFire + (weapons[0].script.cycleTime / weapons.Length))
                        {
                            weapons[curWeapon].script.Shoot();
                            turretScript.curArc = turretScript.defaultArc;                             // reset default arc
                            curWeapon           = MFmath.Mod(curWeapon + 1, weapons.Length);
                            lastFire            = Time.time;
                        }
                    }
                }
                else                     // fire all weapons at once
                {
                    for (int sw = 0; sw < weapons.Length; sw++)
                    {
                        weapons[sw].script.platformVelocity = turretScript.velocity;                         // send velocity to all weapon scripts

                        if (fullBurst == true && bursting != null)
                        {
                            bursting = true;
                            if (weapons[sw].burst == false)
                            {
                                weapons[sw].burst = true;
                                weapons[sw].script.ShootBurst();
                            }
                        }
                        else
                        {
                            weapons[sw].script.Shoot();
                            turretScript.curArc = turretScript.defaultArc;                             // reset default arc
                        }
                    }
                }
            }
        }
    }