public override void DoExecute(BaseContext ctx) { if (Object.op_Equality((Object)SingletonComponent <AiManager> .Instance, (Object)null) || !((Behaviour)SingletonComponent <AiManager> .Instance).get_enabled() || (!((AiManager)SingletonComponent <AiManager> .Instance).UseCover || Object.op_Equality((Object)ctx.AIAgent.AttackTarget, (Object)null))) { return; } NPCHumanContext npcHumanContext = ctx as NPCHumanContext; if (npcHumanContext == null) { return; } if (npcHumanContext.sampledCoverPoints.Count > 0) { npcHumanContext.sampledCoverPoints.Clear(); npcHumanContext.sampledCoverPointTypes.Clear(); } if (!(npcHumanContext.AIAgent.AttackTarget is BasePlayer)) { return; } if (Object.op_Equality((Object)npcHumanContext.CurrentCoverVolume, (Object)null) || !npcHumanContext.CurrentCoverVolume.Contains(npcHumanContext.Position)) { npcHumanContext.CurrentCoverVolume = ((AiManager)SingletonComponent <AiManager> .Instance).GetCoverVolumeContaining(npcHumanContext.Position); if (Object.op_Equality((Object)npcHumanContext.CurrentCoverVolume, (Object)null)) { npcHumanContext.CurrentCoverVolume = AiManager.CreateNewCoverVolume(npcHumanContext.Position, (Transform)null); } } if (!Object.op_Inequality((Object)npcHumanContext.CurrentCoverVolume, (Object)null)) { return; } foreach (CoverPoint coverPoint in npcHumanContext.CurrentCoverVolume.CoverPoints) { if (!coverPoint.IsReserved) { Vector3 position = coverPoint.Position; Vector3 vector3_1 = Vector3.op_Subtraction(npcHumanContext.Position, position); if ((double)((Vector3) ref vector3_1).get_sqrMagnitude() <= (double)this.MaxDistanceToCover) { Vector3 vector3_2 = Vector3.op_Subtraction(position, npcHumanContext.AIAgent.AttackTargetMemory.Position); Vector3 normalized = ((Vector3) ref vector3_2).get_normalized(); if (ScanForCover.ProvidesCoverFromDirection(coverPoint, normalized, this.CoverArcThreshold)) { npcHumanContext.sampledCoverPointTypes.Add(coverPoint.NormalCoverType); npcHumanContext.sampledCoverPoints.Add(coverPoint); } } } } }
public override void DoExecute(BaseContext ctx) { if (SingletonComponent <AiManager> .Instance == null || !SingletonComponent <AiManager> .Instance.enabled || !SingletonComponent <AiManager> .Instance.UseCover || ctx.AIAgent.AttackTarget == null) { return; } NPCHumanContext coverVolumeContaining = ctx as NPCHumanContext; if (coverVolumeContaining == null) { return; } if (coverVolumeContaining.sampledCoverPoints.Count > 0) { coverVolumeContaining.sampledCoverPoints.Clear(); coverVolumeContaining.sampledCoverPointTypes.Clear(); } if (!(coverVolumeContaining.AIAgent.AttackTarget is BasePlayer)) { return; } if (coverVolumeContaining.CurrentCoverVolume == null || !coverVolumeContaining.CurrentCoverVolume.Contains(coverVolumeContaining.Position)) { coverVolumeContaining.CurrentCoverVolume = SingletonComponent <AiManager> .Instance.GetCoverVolumeContaining(coverVolumeContaining.Position); if (coverVolumeContaining.CurrentCoverVolume == null) { coverVolumeContaining.CurrentCoverVolume = AiManager.CreateNewCoverVolume(coverVolumeContaining.Position, null); } } if (coverVolumeContaining.CurrentCoverVolume != null) { foreach (CoverPoint coverPoint in coverVolumeContaining.CurrentCoverVolume.CoverPoints) { if (coverPoint.IsReserved) { continue; } Vector3 position = coverPoint.Position; if ((coverVolumeContaining.Position - position).sqrMagnitude > this.MaxDistanceToCover || !ScanForCover.ProvidesCoverFromDirection(coverPoint, (position - coverVolumeContaining.AIAgent.AttackTargetMemory.Position).normalized, this.CoverArcThreshold)) { continue; } coverVolumeContaining.sampledCoverPointTypes.Add(coverPoint.NormalCoverType); coverVolumeContaining.sampledCoverPoints.Add(coverPoint); } } }