public float EvaluateUnit(AbstractActor unit) { var hostiles = AIUtil.HostilesToUnit(unit); if (hostiles.Count == 0) { return(float.MinValue); } var minDistance = float.MaxValue; foreach (var hostile in hostiles) { if (hostile.IsDead) { continue; } var distance = Vector3.Distance(unit.CurrentPosition, hostile.CurrentPosition); minDistance = Mathf.Min(minDistance, distance); } // ReSharper disable once CompareOfFloatsByEqualityOperator if (minDistance == float.MaxValue) { return(float.MinValue); } return(minDistance); }
public static bool Prefix(AITeam __instance, List <AbstractActor> unusedUnits, ref AbstractActor __result) { try { if (!__instance.CanEntireEnemyTeamBeGhosted()) { __result = null; return(false); } AbstractActor result = (AbstractActor)null; float minDistance = float.MaxValue; for (int index1 = 0; index1 < unusedUnits.Count; ++index1) { AbstractActor unusedUnit = unusedUnits[index1]; List <AbstractActor> enemies = AIUtil.HostilesToUnit(unusedUnit); AuraBubble sensors = unusedUnit.sensorAura(); if (sensors == null) { continue; } ; for (int index2 = 0; index2 < enemies.Count; ++index2) { AbstractActor enemy = enemies[index2]; if (enemy.HasECMAbilityInstalled) { float floatVal = unusedUnit.BehaviorTree.GetBehaviorVariableValue(BehaviorVariableName.Float_SignalInWeapRngWhenEnemyGhostedWithinMoveDistance).FloatVal; float maxMoveDist = Mathf.Lerp(unusedUnit.MaxWalkDistance, unusedUnit.MaxSprintDistance, floatVal); float range = sensors.collider.radius; float needMoveDist = Vector3.Distance(unusedUnit.CurrentPosition, enemy.CurrentPosition) - range; if ((double)needMoveDist <= (double)maxMoveDist && (double)needMoveDist < (double)minDistance) { result = unusedUnit; minDistance = needMoveDist; } } } } __result = result; return(false); }catch (Exception e) { Log.WriteCritical(e.ToString() + "\n"); __result = null; return(false); } }