示例#1
0
        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);
        }
 protected override void OnTick(
     Func <Agent, bool> isAgentManagedByThisMachineAI,
     Team potentialUsersTeam,
     float dt)
 {
     base.OnTick(isAgentManagedByThisMachineAI, potentialUsersTeam, dt);
     if (this.UsableMachine.PilotAgent != null && this.UsableMachine.PilotAgent.IsAIControlled)
     {
         RangedSiegeWeapon usableMachine = this.UsableMachine as RangedSiegeWeapon;
         if (usableMachine.State == RangedSiegeWeapon.WeaponState.WaitingAfterShooting && usableMachine.PilotAgent != null && usableMachine.PilotAgent.IsAIControlled)
         {
             usableMachine.ManualReload();
         }
         if ((double)dt > 0.0 && this._target == null && usableMachine.State == RangedSiegeWeapon.WeaponState.Idle)
         {
             if ((double)this._delayTimer <= 0.0)
             {
                 this.FindNextTarget();
             }
             this._delayTimer -= dt;
         }
         if (this._target != null)
         {
             if (this._target.Agent != null && !this._target.Agent.IsActive())
             {
                 this._target = (Threat)null;
                 return;
             }
             if (usableMachine.State == RangedSiegeWeapon.WeaponState.Idle && usableMachine.UserCount > 0)
             {
                 if (DebugSiegeBehaviour.ToggleTargetDebug)
                 {
                     Agent pilotAgent = this.UsableMachine.PilotAgent;
                 }
                 if (this._targetEvaluationTimer.Check(MBCommon.GetTime(MBCommon.TimeType.Mission)) && !(this.UsableMachine as RangedSiegeWeapon).CanShootAtBox(this._target.BoundingBoxMin, this._target.BoundingBoxMax))
                 {
                     ++this._cannotShootCounter;
                 }
                 if (this._cannotShootCounter < 4)
                 {
                     if (usableMachine.AimAtTarget(this._target.Position) && usableMachine.PilotAgent != null)
                     {
                         this._delayTimer -= dt;
                         if ((double)this._delayTimer <= 0.0)
                         {
                             usableMachine.Shoot();
                             this._target = (Threat)null;
                             this.SetTargetingTimer();
                             this._cannotShootCounter = 0;
                             this._targetEvaluationTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
                         }
                     }
                 }
                 else
                 {
                     this._target = (Threat)null;
                     this.SetTargetingTimer();
                     this._cannotShootCounter = 0;
                 }
             }
             else
             {
                 this._targetEvaluationTimer.Reset(MBCommon.GetTime(MBCommon.TimeType.Mission));
             }
         }
     }
     this.AfterTick(isAgentManagedByThisMachineAI, potentialUsersTeam, dt);
 }
示例#3
0
 internal void Release()
 {
     this.targetAgent   = (Agent)null;
     this.currentThreat = (Threat)null;
 }