public void Tick(IHTNAgent npc, float deltaTime, float time) { NavMeshHit navMeshHit; ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } if (!npcContext.IsFact(Facts.IsReturningHome)) { if ((npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null || time - npcContext.Memory.PrimaryKnownEnemyPlayer.Time > npcContext.Body.AiDefinition.Memory.NoSeeReturnToSpawnTime) && npcContext.Domain.SqrDistanceToSpawn() > npcContext.Domain.SqrMovementRadius) { npcContext.SetFact(Facts.IsReturningHome, true, true, true, true); if (NavMesh.SamplePosition(npcContext.Domain.SpawnPosition, out navMeshHit, 1f, npcContext.Domain.NavAgent.areaMask)) { npcContext.Domain.SetDestination(navMeshHit.position); return; } } } else if (npcContext.IsFact(Facts.CanSeeEnemy) || time - npcContext.Body.lastAttackedTime < 2f || npcContext.IsFact(Facts.AtLocationHome)) { npcContext.SetFact(Facts.IsReturningHome, false, true, true, true); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } if (npcContext.IsFact(Facts.MaintainCover) || npcContext.IsFact(Facts.IsReloading) || npcContext.IsFact(Facts.IsApplyingMedical)) { if (npcContext.ReservedCoverPoint != null && !npcContext.ReservedCoverPoint.IsCompromised && !npcContext.IsFact(Facts.AtLocationCover) && time - npcContext.ReservedCoverTime < 0.8f) { return; } if (!npcContext.IsFact(Facts.CanSeeEnemy) && npcContext.Body.SecondsSinceAttacked - 1f > time - npcContext.ReservedCoverTime) { return; } if (ScientistJunkpileDomain.JunkpileCanNavigateToCoverLocation.Try(CoverTactic.Retreat, npcContext)) { Vector3 coverPosition = ScientistJunkpileDomain.JunkpileNavigateToCover.GetCoverPosition(CoverTactic.Retreat, npcContext); npcContext.Domain.SetDestination(coverPosition); npcContext.Body.modelState.ducked = false; npcContext.SetFact(Facts.IsDucking, 0, false, true, true); npcContext.SetFact(Facts.FirearmOrder, FirearmOrders.FireAtWill, false, true, true); } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null || !npcContext.IsFact(Facts.Frustration) || (double)time - (double)this._lastFrustrationDecrementTime <= 5.0) { return; } this._lastFrustrationDecrementTime = time; npcContext.IncrementFact(Facts.Frustration, -1, true, true, true); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } npcContext.SetFact(Facts.HasNearbyCover, (npcContext.CoverPoints.Count > 0 ? 1 : 0), true, true, true); if (!npcContext.IsFact(Facts.HasEnemyTarget)) { npcContext.ReserveCoverPoint(null); return; } HTNPlayer hTNPlayer = npc as HTNPlayer; if (hTNPlayer == null) { return; } float single = 0f; float single1 = 0f; float single2 = 0f; foreach (CoverPoint coverPoint in npcContext.CoverPoints) { if (coverPoint.IsCompromised || coverPoint.IsReserved && !coverPoint.ReservedFor.EqualNetID(hTNPlayer)) { continue; } float single3 = -0.8f; BaseNpcMemory.EnemyPlayerInfo primaryKnownEnemyPlayer = npcContext.Memory.PrimaryKnownEnemyPlayer; if (!coverPoint.ProvidesCoverFromPoint(primaryKnownEnemyPlayer.LastKnownPosition, single3)) { continue; } Vector3 position = coverPoint.Position - npc.transform.position; Vector3 lastKnownPosition = primaryKnownEnemyPlayer.LastKnownPosition - npc.transform.position; float single4 = Vector3.Dot(position.normalized, lastKnownPosition.normalized); if (single < 1f) { CoverPointsReasoner.EvaluateAdvancement(npc, npcContext, ref single, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, single4); } if (single2 < 1f) { CoverPointsReasoner.EvaluateRetreat(npc, npcContext, ref single2, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, ref single4); } if (single1 >= 1f) { continue; } CoverPointsReasoner.EvaluateFlanking(npc, npcContext, ref single1, ref primaryKnownEnemyPlayer, coverPoint, position, lastKnownPosition, single4); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) return; if (!npcContext.IsFact(Facts.IsReturningHome)) { if (!Object.op_Equality((Object) npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object) null) && (double) time - (double) npcContext.Memory.PrimaryKnownEnemyPlayer.Time <= (double) npcContext.Body.AiDefinition.Memory.NoSeeReturnToSpawnTime || (double) npcContext.Domain.SqrDistanceToSpawn() <= (double) npcContext.Domain.SqrMovementRadius) return; npcContext.SetFact(Facts.IsReturningHome, true, true, true, true); NavMeshHit navMeshHit; if (!NavMesh.SamplePosition(npcContext.Domain.SpawnPosition, ref navMeshHit, 1f, npcContext.Domain.NavAgent.get_areaMask())) return; npcContext.Domain.SetDestination(((NavMeshHit) ref navMeshHit).get_position()); } else { if (!npcContext.IsFact(Facts.CanSeeEnemy) && (double) time - (double) npcContext.Body.lastAttackedTime >= 2.0 && !npcContext.IsFact(Facts.AtLocationHome)) return; npcContext.SetFact(Facts.IsReturningHome, false, true, true, true); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } npcContext.SetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.HasNearbyCover, npcContext.CoverPoints.Count > 0 ? 1 : 0, true, true, true); if (!npcContext.IsFact(Rust.Ai.HTN.ScientistJunkpile.Facts.HasEnemyTarget)) { npcContext.ReserveCoverPoint((CoverPoint)null); } else { HTNPlayer htnPlayer = npc as HTNPlayer; if (Object.op_Equality((Object)htnPlayer, (Object)null)) { return; } float bestScore1 = 0.0f; float bestScore2 = 0.0f; float bestScore3 = 0.0f; foreach (CoverPoint coverPoint in npcContext.CoverPoints) { if (!coverPoint.IsCompromised && (!coverPoint.IsReserved || coverPoint.ReservedFor.EqualNetID((BaseNetworkable)htnPlayer))) { float arcThreshold = -0.8f; BaseNpcMemory.EnemyPlayerInfo knownEnemyPlayer = npcContext.Memory.PrimaryKnownEnemyPlayer; if (coverPoint.ProvidesCoverFromPoint(knownEnemyPlayer.LastKnownPosition, arcThreshold)) { Vector3 dirCover = Vector3.op_Subtraction(coverPoint.Position, npc.transform.get_position()); Vector3 dirDanger = Vector3.op_Subtraction(knownEnemyPlayer.LastKnownPosition, npc.transform.get_position()); float directness = Vector3.Dot(((Vector3) ref dirCover).get_normalized(), ((Vector3) ref dirDanger).get_normalized()); if ((double)bestScore1 < 1.0) { CoverPointsReasoner.EvaluateAdvancement(npc, npcContext, ref bestScore1, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, directness); } if ((double)bestScore3 < 1.0) { CoverPointsReasoner.EvaluateRetreat(npc, npcContext, ref bestScore3, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, ref directness); } if ((double)bestScore2 < 1.0) { CoverPointsReasoner.EvaluateFlanking(npc, npcContext, ref bestScore2, ref knownEnemyPlayer, coverPoint, dirCover, dirDanger, directness); } } } } } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } if (npcContext.IsFact(Facts.Frustration) && time - this._lastFrustrationDecrementTime > 5f) { this._lastFrustrationDecrementTime = time; npcContext.IncrementFact(Facts.Frustration, -1, true, true, true); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null || !npcContext.IsFact(Facts.Alertness)) { return; } if (npcContext.GetFact(Facts.Alertness) > (byte)10) { npcContext.SetFact(Facts.Alertness, 10, true, false, true); } if ((double)time - (double)this._lastFrustrationDecrementTime <= 1.0) { return; } this._lastFrustrationDecrementTime = time; npcContext.IncrementFact(Facts.Alertness, -1, true, true, true); }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } HTNPlayer htnPlayer = npc as HTNPlayer; if (Object.op_Equality((Object)htnPlayer, (Object)null)) { return; } NpcOrientation npcOrientation = NpcOrientation.Heading; if (npc.IsDestroyed || htnPlayer.IsDead() || htnPlayer.IsWounded()) { npcOrientation = NpcOrientation.None; } else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownAnimal.Animal, (Object)null)) { npcOrientation = !Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null) ? NpcOrientation.LookAtAnimal : ((double)npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= (double)npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance ? (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation)) : NpcOrientation.LookAtAnimal); } else if (Object.op_Inequality((Object)npcContext.PrimaryEnemyPlayerInLineOfSight.Player, (Object)null)) { npcOrientation = npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible ? NpcOrientation.PrimaryTargetBody : (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } else if (Object.op_Inequality((Object)htnPlayer.lastAttacker, (Object)null) && (double)htnPlayer.lastAttackedTime > 0.0 && (double)time - (double)htnPlayer.lastAttackedTime < 2.0) { npcOrientation = NpcOrientation.LastAttackedDirection; } else if (Object.op_Inequality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null)) { npcOrientation = npcContext.GetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.IsSearching) <= (byte)0 || npcContext.GetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.IsNavigating) != (byte)0 ? (npcContext.GetFact(Rust.Ai.HTN.ScientistJunkpile.Facts.IsIdle) <= (byte)0 ? NpcOrientation.LastKnownPrimaryTargetLocation : (!npcContext.IsFact(Rust.Ai.HTN.ScientistJunkpile.Facts.CanHearEnemy) ? NpcOrientation.Heading : NpcOrientation.AudibleTargetDirection)) : NpcOrientation.LookAround; } else if (npcContext.IsFact(Rust.Ai.HTN.ScientistJunkpile.Facts.CanHearEnemy)) { npcOrientation = NpcOrientation.AudibleTargetDirection; } npcContext.OrientationType = npcOrientation; }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } HTNPlayer hTNPlayer = npc as HTNPlayer; if (hTNPlayer == null) { return; } if (time - hTNPlayer.lastAttackedTime > 3f && npcContext.IsFact(Facts.Vulnerability) && time - this._lastVulnerabilityDecrementTime > 2f) { this._lastVulnerabilityDecrementTime = time; npcContext.IncrementFact(Facts.Vulnerability, -1, true, true, true); } }
public void Tick(IHTNAgent npc, float deltaTime, float time) { ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } HTNPlayer htnPlayer = npc as HTNPlayer; if (Object.op_Equality((Object)htnPlayer, (Object)null) || (double)time - (double)htnPlayer.lastAttackedTime <= 3.0 || (!npcContext.IsFact(Rust.Ai.HTN.ScientistJunkpile.Facts.Vulnerability) || (double)time - (double)this._lastVulnerabilityDecrementTime <= 2.0)) { return; } this._lastVulnerabilityDecrementTime = time; npcContext.IncrementFact(Rust.Ai.HTN.ScientistJunkpile.Facts.Vulnerability, -1, true, true, true); }
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) { NpcOrientation npcOrientation; NpcOrientation npcOrientation1; ScientistJunkpileContext npcContext = npc.AiDomain.NpcContext as ScientistJunkpileContext; if (npcContext == null) { return; } HTNPlayer hTNPlayer = npc as HTNPlayer; if (hTNPlayer == null) { return; } NpcOrientation npcOrientation2 = NpcOrientation.Heading; if (npc.IsDestroyed || hTNPlayer.IsDead() || hTNPlayer.IsWounded()) { npcOrientation2 = NpcOrientation.None; } else if (npcContext.Memory.PrimaryKnownAnimal.Animal != null) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player == null) { npcOrientation2 = NpcOrientation.LookAtAnimal; } else if (npcContext.Memory.PrimaryKnownAnimal.SqrDistance >= npcContext.PrimaryEnemyPlayerInLineOfSight.SqrDistance) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible) { npcOrientation1 = NpcOrientation.PrimaryTargetBody; } else { npcOrientation1 = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } npcOrientation2 = npcOrientation1; } else { npcOrientation2 = NpcOrientation.LookAtAnimal; } } else if (npcContext.PrimaryEnemyPlayerInLineOfSight.Player != null) { if (npcContext.PrimaryEnemyPlayerInLineOfSight.BodyVisible) { npcOrientation = NpcOrientation.PrimaryTargetBody; } else { npcOrientation = (npcContext.PrimaryEnemyPlayerInLineOfSight.HeadVisible ? NpcOrientation.PrimaryTargetHead : NpcOrientation.LastKnownPrimaryTargetLocation); } npcOrientation2 = npcOrientation; } else if (hTNPlayer.lastAttacker != null && hTNPlayer.lastAttackedTime > 0f && time - hTNPlayer.lastAttackedTime < 2f) { npcOrientation2 = NpcOrientation.LastAttackedDirection; } else if (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null) { if (npcContext.IsFact(Facts.CanHearEnemy)) { npcOrientation2 = NpcOrientation.AudibleTargetDirection; } } else if (npcContext.GetFact(Facts.IsSearching) > 0 && npcContext.GetFact(Facts.IsNavigating) == 0) { npcOrientation2 = NpcOrientation.LookAround; } else if (npcContext.GetFact(Facts.IsIdle) <= 0) { npcOrientation2 = NpcOrientation.LastKnownPrimaryTargetLocation; } else { npcOrientation2 = (!npcContext.IsFact(Facts.CanHearEnemy) ? NpcOrientation.Heading : NpcOrientation.AudibleTargetDirection); } npcContext.OrientationType = npcOrientation2; }
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; } }