public void Tick(IHTNAgent npc, float deltaTime, float time) { NavMeshHit navMeshHit; ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null || npcContext.Domain.NavAgent == null) { return; } if (npcContext.Location == null || npcContext.Location.PatrolPointGroup == null) { return; } if (this.WaypointSet == null) { this.WaypointSet = npcContext.Location.PatrolPointGroup.GetComponent <Rust.Ai.WaypointSet>(); } if (this.WaypointSet == null || this.WaypointSet.Points.Count == 0) { return; } if (npcContext.IsFact(Facts.IsReturningHome) || npcContext.IsFact(Facts.HasEnemyTarget) || npcContext.IsFact(Facts.NearbyAnimal) || !npcContext.IsFact(Facts.IsUsingTool)) { this.isFollowingWaypoints = false; this.hasAlreadyPassedOnPrevCheck = false; return; } if (!this.isFollowingWaypoints) { if (!this.hasAlreadyPassedOnPrevCheck && (npcContext.GetPreviousFact(Facts.HasEnemyTarget) == 1 || npcContext.GetPreviousFact(Facts.NearbyAnimal) == 1) || this.isFirstTick) { this.CurrentWaypointIndex = this.GetClosestWaypointIndex(npcContext.BodyPosition); if (!this.isFirstTick) { this.hasAlreadyPassedOnPrevCheck = true; } else { this.isFirstTick = false; } } Rust.Ai.WaypointSet.Waypoint item = this.WaypointSet.Points[this.CurrentWaypointIndex]; if (item.Transform == null) { this.CurrentWaypointIndex = this.GetNextWaypointIndex(); this.isFollowingWaypoints = false; return; } Vector3 transform = item.Transform.position; if ((npcContext.Memory.TargetDestination - transform).sqrMagnitude > 0.1f && NavMesh.SamplePosition(transform + (Vector3.up * 2f), out navMeshHit, 4f, npcContext.Domain.NavAgent.areaMask)) { item.Transform.position = navMeshHit.position; npcContext.Domain.SetDestination(navMeshHit.position); this.isFollowingWaypoints = true; npcContext.SetFact(Facts.IsNavigating, true, true, true, true); return; } } float single = 2f; float navAgent = npcContext.Domain.NavAgent.stoppingDistance * npcContext.Domain.NavAgent.stoppingDistance; if ((npcContext.BodyPosition - npcContext.Memory.TargetDestination).sqrMagnitude > navAgent + single) { return; } this.CurrentWaypointIndex = this.GetNextWaypointIndex(); this.isFollowingWaypoints = false; }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null || Object.op_Equality((Object)npcContext.Domain.NavAgent, (Object)null) || (Object.op_Equality((Object)npcContext.Location, (Object)null) || Object.op_Equality((Object)npcContext.Location.PatrolPointGroup, (Object)null))) { return; } if (Object.op_Equality((Object)this.WaypointSet, (Object)null)) { this.WaypointSet = (WaypointSet)((Component)npcContext.Location.PatrolPointGroup).GetComponent <WaypointSet>(); } if (Object.op_Equality((Object)this.WaypointSet, (Object)null) || this.WaypointSet.Points.Count == 0) { return; } if (npcContext.IsFact(Facts.IsReturningHome) || npcContext.IsFact(Facts.HasEnemyTarget) || (npcContext.IsFact(Facts.NearbyAnimal) || !npcContext.IsFact(Facts.IsUsingTool))) { this.isFollowingWaypoints = false; this.hasAlreadyPassedOnPrevCheck = false; } else { if (!this.isFollowingWaypoints) { if (!this.hasAlreadyPassedOnPrevCheck && (npcContext.GetPreviousFact(Facts.HasEnemyTarget) == (byte)1 || npcContext.GetPreviousFact(Facts.NearbyAnimal) == (byte)1) || this.isFirstTick) { this.CurrentWaypointIndex = this.GetClosestWaypointIndex(npcContext.BodyPosition); if (this.isFirstTick) { this.isFirstTick = false; } else { this.hasAlreadyPassedOnPrevCheck = true; } } WaypointSet.Waypoint point = this.WaypointSet.Points[this.CurrentWaypointIndex]; if (Object.op_Equality((Object)point.Transform, (Object)null)) { this.CurrentWaypointIndex = this.GetNextWaypointIndex(); this.isFollowingWaypoints = false; return; } Vector3 position = point.Transform.get_position(); Vector3 vector3 = Vector3.op_Subtraction(npcContext.Memory.TargetDestination, position); NavMeshHit navMeshHit; if ((double)((Vector3) ref vector3).get_sqrMagnitude() > 0.100000001490116 && NavMesh.SamplePosition(Vector3.op_Addition(position, Vector3.op_Multiply(Vector3.get_up(), 2f)), ref navMeshHit, 4f, npcContext.Domain.NavAgent.get_areaMask())) { point.Transform.set_position(((NavMeshHit) ref navMeshHit).get_position()); npcContext.Domain.SetDestination(((NavMeshHit) ref navMeshHit).get_position()); this.isFollowingWaypoints = true; npcContext.SetFact(Facts.IsNavigating, true, true, true, true); return; } } float num1 = 2f; float num2 = npcContext.Domain.NavAgent.get_stoppingDistance() * npcContext.Domain.NavAgent.get_stoppingDistance(); Vector3 vector3_1 = Vector3.op_Subtraction(npcContext.BodyPosition, npcContext.Memory.TargetDestination); if ((double)((Vector3) ref vector3_1).get_sqrMagnitude() > (double)num2 + (double)num1) { return; } this.CurrentWaypointIndex = this.GetNextWaypointIndex(); this.isFollowingWaypoints = false; } }