private void UpdateTargetList() { Vector3 strafePos = Vector3.zero; bool isStrafing = false; bool shouldUseNapalm = false; for (int i = _targets.Count - 1; i >= 0; i--) { PatrolHelicopterAI.targetinfo targetinfo = _targets[i]; if (targetinfo == null || targetinfo.ent == null) { _targets.Remove(targetinfo); } else { if (Time.realtimeSinceStartup > targetinfo.nextLOSCheck) { targetinfo.nextLOSCheck = Time.realtimeSinceStartup + 1f; if (PlayerVisible(targetinfo.ply)) { targetinfo.lastSeenTime = Time.realtimeSinceStartup; targetinfo.visibleFor += 1f; } else { targetinfo.visibleFor = 0f; } } bool isDead = targetinfo.ply ? targetinfo.ply.IsDead() : (targetinfo.ent.Health() <= 0f); if (targetinfo.TimeSinceSeen() >= 6f || isDead) { if ((CanStrafe() || CanUseNapalm()) && AI.IsAlive() && !isStrafing && !isDead && (targetinfo.ply == AI.leftGun._target || targetinfo.ply == AI.rightGun._target)) { shouldUseNapalm = (!ValidStrafeTarget(targetinfo.ply) || UnityEngine.Random.Range(0f, 1f) > 0.75f); strafePos = targetinfo.ply.transform.position; isStrafing = true; } _targets.Remove(targetinfo); } } } foreach (EventManager.BaseEventPlayer eventPlayer in Event.eventPlayers) { BasePlayer player = eventPlayer.Player; if (Vector3Ex.Distance2D(tr.position, player.transform.position) <= 150f) { bool isCurrentTarget = false; for (int i = 0; i < _targets.Count; i++) { PatrolHelicopterAI.targetinfo targetInfo = _targets[i]; if (targetInfo.ply == player) { isCurrentTarget = true; break; } } if (!isCurrentTarget && PlayerVisible(player)) { _targets.Add(new PatrolHelicopterAI.targetinfo(player, player)); } } } if (isStrafing) { AI.ExitCurrentState(); AI.State_Strafe_Enter(strafePos, shouldUseNapalm); } AI._targetList.Clear(); AI._targetList.AddRange(_targets); }
public bool IsAtFinalDestination() { return(Vector3Ex.Distance2D(base.transform.position, this.finalDestination) <= this.stoppingDist); }
private static bool InDistance(Vector3 target, Vector3 position, float distance) => Vector3Ex.Distance2D(target, position) <= distance;
public bool IsAtDestination() { return(Vector3Ex.Distance2D(base.transform.position, destination) <= stoppingDist); }
public bool AtPatrolDestination() { return(Vector3Ex.Distance2D(this.brain.mainInterestPoint, this.brain.GetEntity().GetPosition()) < CH47AIBrain.PatrolState.patrolApproachDist); }
public override void StateThink(float delta) { bool flag; Vector3 entity = this.brain.GetEntity().transform.position; CH47LandingZone closest = CH47LandingZone.GetClosest(this.brain.GetEntity().landingTarget); if (!closest) { return; } float single = this.brain.GetEntity().rigidBody.velocity.magnitude; Vector3.Distance(closest.transform.position, entity); float single1 = Vector3Ex.Distance2D(closest.transform.position, entity); Mathf.InverseLerp(1f, 20f, single1); bool flag1 = single1 < 100f; bool flag2 = (single1 <= 15f ? false : entity.y < closest.transform.position.y + 10f); this.brain.GetEntity().EnableFacingOverride(flag1); this.brain.GetEntity().SetAltitudeProtection(flag2); flag = (Mathf.Abs(closest.transform.position.y - entity.y) >= 3f || single1 > 5f ? false : single < 1f); if (flag) { this.landedForSeconds += delta; if (this.lastLandtime == 0f) { this.lastLandtime = Time.time; } } float single2 = 1f - Mathf.InverseLerp(0f, 7f, single1); this.landingHeight = this.landingHeight - 4f * single2 * Time.deltaTime; if (this.landingHeight < -5f) { this.landingHeight = -5f; } this.brain.GetEntity().SetAimDirection(closest.transform.forward); this.brain.GetEntity().SetMoveTarget(this.brain.mainInterestPoint + new Vector3(0f, this.landingHeight, 0f)); if (flag) { if (this.landedForSeconds > 1f && Time.time > this.nextDismountTime) { BaseVehicle.MountPointInfo[] mountPointInfoArray = this.brain.GetEntity().mountPoints; int num = 0; while (num < (int)mountPointInfoArray.Length) { BaseVehicle.MountPointInfo mountPointInfo = mountPointInfoArray[num]; if (!mountPointInfo.mountable || !mountPointInfo.mountable.IsMounted()) { num++; } else { this.nextDismountTime = Time.time + 0.5f; mountPointInfo.mountable.DismountAllPlayers(); break; } } } if (this.landedForSeconds > 8f) { this.brain.GetComponent <CH47AIBrain>().age = Single.PositiveInfinity; } } }