internal Threat GetTarget() { IEnumerable <Threat> allThreats = this.GetAllThreats(); foreach (Threat threat in allThreats) { threat.ThreatValue *= (float)(0.899999976158142 + (double)MBRandom.RandomFloat * 0.200000002980232); } if (this.currentThreat != null) { this.currentThreat = allThreats.SingleOrDefault <Threat>((Func <Threat, bool>)(t => t.Equals((object)this.currentThreat))); if (this.currentThreat != null) { this.currentThreat.ThreatValue *= 2f; } } IEnumerable <Threat> source = allThreats.Where <Threat>((Func <Threat, bool>)(t => { if ((t.WeaponEntity != null || t.Agent != null) && this.Weapon.CanShootAtBox(t.BoundingBoxMin, t.BoundingBoxMax)) { return(true); } return(t.Formation != null && t.Formation.GetCountOfUnitsWithCondition((Func <Agent, bool>)(agent => { RangedSiegeWeapon weapon = this.Weapon; CapsuleData collisionCapsule = agent.CollisionCapsule; Vec3 boxMin = collisionCapsule.GetBoxMin(); collisionCapsule = agent.CollisionCapsule; Vec3 boxMax = collisionCapsule.GetBoxMax(); return weapon.CanShootAtBox(boxMin, boxMax); })) > 0); })); if (source.IsEmpty <Threat>()) { return((Threat)null); } this.currentThreat = source.MaxBy <Threat, float>((Func <Threat, float>)(t => t.ThreatValue)); if (this.currentThreat.WeaponEntity == null) { if (this.targetAgent != null && this.targetAgent.IsActive() && this.currentThreat.Formation.HasUnitsWithCondition((Func <Agent, bool>)(agent => agent == this.targetAgent))) { RangedSiegeWeapon weapon = this.Weapon; CapsuleData collisionCapsule = this.targetAgent.CollisionCapsule; Vec3 boxMin = collisionCapsule.GetBoxMin(); collisionCapsule = this.targetAgent.CollisionCapsule; Vec3 boxMax = collisionCapsule.GetBoxMax(); if (weapon.CanShootAtBox(boxMin, boxMax)) { goto label_15; } } float selectedAgentScore = float.MaxValue; Agent selectedAgent = this.targetAgent; this.currentThreat.Formation.ApplyActionOnEachUnit((Action <Agent>)(agent => { float num = agent.Position.DistanceSquared(this.Weapon.GameEntity.GlobalPosition) * (float)((double)MBRandom.RandomFloat * 0.200000002980232 + 0.800000011920929); if (agent == this.targetAgent) { num *= 0.5f; } if ((double)selectedAgentScore <= (double)num || !this.Weapon.CanShootAtBox(agent.CollisionCapsule.GetBoxMin(), agent.CollisionCapsule.GetBoxMax())) { return; } selectedAgent = agent; selectedAgentScore = num; })); this.targetAgent = selectedAgent ?? this.currentThreat.Formation.GetUnitWithIndex(MBRandom.RandomInt(this.currentThreat.Formation.CountOfUnits)); this.currentThreat.Agent = this.targetAgent; } label_15: this.targetAgent = (Agent)null; return(this.currentThreat.WeaponEntity == null && this.currentThreat.Agent == null ? (Threat)null : this.currentThreat); }