internal static Vec3 CalculateCenterOfMass(PhysicsShape body)
        {
            if ((NativeObject)body == (NativeObject)null)
            {
                return(Vec3.Zero);
            }
            Vec3  zero = Vec3.Zero;
            float num1 = 0.0f;
            int   num2 = body.CapsuleCount();

            for (int index = 0; index < num2; ++index)
            {
                CapsuleData data = new CapsuleData();
                body.GetCapsule(ref data, index);
                Vec3  vec3 = (data.P1 + data.P2) * 0.5f;
                float num3 = data.P1.Distance(data.P2);
                float num4 = (float)((double)data.Radius * (double)data.Radius * 3.14159274101257 * (1.33333337306976 * (double)data.Radius + (double)num3));
                num1 += num4;
                zero += vec3 * num4;
            }
            int num5 = body.SphereCount();

            for (int index = 0; index < num5; ++index)
            {
                SphereData data = new SphereData();
                body.GetSphere(ref data, index);
                float num3 = 4.18879f * data.Radius * data.Radius * data.Radius;
                num1 += num3;
                zero += data.Origin * num3;
            }
            Vec3 vec3_1;

            if ((double)num1 > 0.0)
            {
                vec3_1 = zero / num1;
                if ((double)Math.Abs(vec3_1.x) < 0.00999999977648258)
                {
                    vec3_1.x = 0.0f;
                }
                if ((double)Math.Abs(vec3_1.y) < 0.00999999977648258)
                {
                    vec3_1.y = 0.0f;
                }
                if ((double)Math.Abs(vec3_1.z) < 0.00999999977648258)
                {
                    vec3_1.z = 0.0f;
                }
            }
            else
            {
                vec3_1 = Vec3.Zero;
            }
            return(vec3_1);
        }
Beispiel #2
0
 protected override void Awake()
 {
     base.Awake();
     this.animator                = this.GetComponent <Animator>();
     this.rb                      = this.GetComponent <Rigidbody>();
     this.collider                = this.GetComponent <CapsuleCollider>();
     this.spawner                 = this.GetComponent <BubbleSpawner>();
     this.fieldOfViewData         = this.GetCapsuleColliderData(this.fieldOfView);
     this.colliderData            = this.GetCapsuleColliderData(this.collider);
     this.entitiesThisEnemyCanSee = new Collider[8];
     this.destRotation            = this.transform.rotation.eulerAngles.y;
 }
 public MoveJob(CapsuleData data, NativeArray <byte> active, NativeArray <float3> position, int stepCount,
                int startIndex, int endIndex, float positionProbability, float3 positionOffset, float scale)
 {
     this.data                = data;
     this.active              = active;
     this.position            = position;
     this.stepCount           = stepCount;
     this.startIndex          = startIndex;
     this.endIndex            = endIndex;
     this.positionProbability = positionProbability;
     this.positionOffset      = positionOffset;
     this.scale               = scale;
 }
Beispiel #4
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);
        }