public static bool PreFix(EcoTargetType type, Vector3 wsPos, EcoRegion.TargetFilter isTargetValid, ref float bestDist, ref IEcoTarget best) { // Explody fish runs regular code - everybody else runs postfix return(DeathRun.crashFishSemaphore); }
public static void PostFix(EcoRegion __instance, EcoTargetType type, Vector3 wsPos, EcoRegion.TargetFilter isTargetValid, ref float bestDist, ref IEcoTarget best) { if (DeathRun.crashFishSemaphore) { return; } ProfilingUtils.BeginSample("EcoRegion.FindNearestTarget"); __instance.timeStamp = Time.time; System.Collections.Generic.HashSet <IEcoTarget> hashSet; if (!__instance.ecoTargets.TryGetValue((int)type, out hashSet)) { ProfilingUtils.EndSample(null); return; } float num = float.MaxValue; foreach (IEcoTarget ecoTarget in hashSet) { if (ecoTarget != null && !ecoTarget.Equals(null)) { float sqrMagnitude = (wsPos - ecoTarget.GetPosition()).sqrMagnitude; if (((ecoTarget.GetGameObject() == Player.main.gameObject) && !Player.main.IsInside() && Player.main.IsUnderwater() && !Player.main.precursorOutOfWater) || (ecoTarget.GetGameObject().GetComponent <Vehicle>() && (ecoTarget.GetGameObject().GetComponent <Vehicle>() == Player.main.currentMountedVehicle)) && !Player.main.currentMountedVehicle.precursorOutOfWater) { bool feeding = false; if (ecoTarget.GetGameObject() == Player.main.gameObject) { Pickupable held = Inventory.main.GetHeld(); if (held != null && (held.GetTechType() == TechType.Peeper)) { feeding = true; } } float depth = Ocean.main.GetDepthOf(ecoTarget.GetGameObject()); if ((depth > 5) && !feeding) { if (Config.DEATHRUN.Equals(DeathRun.config.creatureAggression) || Config.EXORBITANT.Equals(DeathRun.config.creatureAggression)) { if (DayNightCycle.main.timePassedAsFloat >= DeathRun.FULL_AGGRESSION) { sqrMagnitude = 1; //BR// Player appears very close! (i.e. attractive target) } else if (DayNightCycle.main.timePassedAsFloat >= DeathRun.MORE_AGGRESSION) { sqrMagnitude /= 4; } else { sqrMagnitude /= 2; } } else if (Config.HARD.Equals(DeathRun.config.creatureAggression)) { if (DayNightCycle.main.timePassedAsFloat >= DeathRun.FULL_AGGRESSION) { sqrMagnitude /= 3; //BR// Player appears closer! (i.e. attractive target) } else if (DayNightCycle.main.timePassedAsFloat >= DeathRun.MORE_AGGRESSION) { sqrMagnitude /= 2; } } } } if (sqrMagnitude < num && (isTargetValid == null || isTargetValid(ecoTarget))) { best = ecoTarget; num = sqrMagnitude; } } } if (best != null) { bestDist = Mathf.Sqrt(num); } ProfilingUtils.EndSample(null); }
void Start() { targetFilter = new EcoRegion.TargetFilter(IsValidTarget); }