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); }
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); }
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); }
GameObject ChooseTarget(MF_AbstractPlatform receivingObjectScript, PriorityType priority, MF_B_TargetList targetListScript) { GameObject _bestTarget = null; float? _bestValue = null; bool _priorityFound = false; foreach (int key in targetListScript.targetList.Keys) // iterate through target list { if (targetListScript.targetList[key] == null) { continue; } // skip null entries if (targetListScript.targetList[key].transform == null) { continue; } // skip missing objects if (checkArcLimits == true && receivingObjectScript) { if (receivingObjectScript.TargetWithinLimits(targetListScript.targetList[key].transform) == false) { continue; } // check arc limits } if (receivingControllerScript && checkWeapRange == true) { if (receivingControllerScript.weapons.Length > 0) { if (receivingControllerScript.weapons[receivingControllerScript.curWeapon].script.RangeCheck(targetListScript.targetList[key].transform) == false) { continue; } // check weapon range } } if (_priorityFound == true) { if (targetListScript.targetList[key].clickedPriority == false) { continue; } } else // _priorityFound == false { if (targetListScript.targetList[key].clickedPriority == true) // found first priority target { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = targetListScript.targetList[key].sqrMagnitude; _priorityFound = true; continue; } } float?_value; switch (priority) { case PriorityType.Closest: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sqrMagnitude; if (_value < _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.Furthest: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sqrMagnitude; if (_value > _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.MostHealth: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health; if (_value > _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.LeastHealth: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health; if (_value < _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.MostHealthPercent: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health / targetListScript.targetList[key].script.maxHealth;; if (_value > _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; case PriorityType.LeastHealthPercent: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].script.health / targetListScript.targetList[key].script.maxHealth;; if (_value < _bestValue) { _bestTarget = targetListScript.targetList[key].transform.gameObject; _bestValue = _value; } break; // add additional priority types default: break; } } return(_bestTarget); }
GameObject ChooseTarget(MF_AbstractPlatform receivingObjectScript, PriorityType priority, MF_B_TargetList targetListScript) { int? _bestKey = null; float?_bestValue = null; bool _priorityFound = false; foreach (int key in targetListScript.targetList.Keys) // iterate through target list { if (targetListScript.targetList[key] == null) { continue; } // skip null entries if (targetListScript.targetList[key].transform == null) { continue; } // skip missing objects // if ( targetListScript.targetList[key].poi.isPoi == true ) { continue; } // skip points of interest if (checkArcLimits == true && receivingObjectScript) { if (receivingObjectScript.TargetWithinLimits(targetListScript.targetList[key].transform) == false) { continue; } // check arc limits } if (receivingControllerScript && checkWeapRange == true) { if (receivingControllerScript.weapons.Length > 0) { if (receivingControllerScript.weapons[receivingControllerScript.curWeapon].script.RangeCheck(targetListScript.targetList[key].transform) == false) { continue; } // check weapon range } } if (_priorityFound == true) { if (targetListScript.targetList[key].clickedPriority == false) { continue; } } else // _priorityFound == false { if (targetListScript.targetList[key].clickedPriority == true) // found first priority target { _bestKey = key; _bestValue = (transform.position - targetListScript.targetList[key].transform.position).sqrMagnitude; _priorityFound = true; continue; } } float?_value = null; switch (priority) { case PriorityType.Closest: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = (transform.position - targetListScript.targetList[key].transform.position).sqrMagnitude; if (_value < _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.Furthest: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = (transform.position - targetListScript.targetList[key].transform.position).sqrMagnitude; if (_value > _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.MostHealth: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health; if (_value > _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.LeastHealth: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health; if (_value < _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.MostHealthPercent: if (_bestValue == null) { _bestValue = -Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health / targetListScript.targetList[key].sScript.healthMax; if (_value > _bestValue) { _bestKey = key; _bestValue = _value; } break; case PriorityType.LeastHealthPercent: if (_bestValue == null) { _bestValue = Mathf.Infinity; } // initialize _bestValue _value = targetListScript.targetList[key].sScript.health / targetListScript.targetList[key].sScript.healthMax; if (_value < _bestValue) { _bestKey = key; _bestValue = _value; } break; // add additional priority types default: break; } } if (_bestKey != null) { MF_B_TargetList.TargetData tlk = targetListScript.targetList[(int)_bestKey]; hasPrecision = tlk.hasPrecision; hasAngle = tlk.hasAngle; hasRange = tlk.hasRange; hasVelocity = tlk.hasVelocity; return(tlk.transform.gameObject); } else { hasPrecision = MFnum.ScanSource.None; hasAngle = MFnum.ScanSource.None; hasRange = MFnum.ScanSource.None; hasVelocity = MFnum.ScanSource.None; return(null); } }