public override int Compare(PickupState x, PickupState y) { int num1 = 0; int num2 = 0; TrileInstance trileInstance1 = (TrileInstance)null; TrileInstance trileInstance2 = (TrileInstance)null; for (InstancePhysicsState physicsState = x.Instance.PhysicsState; physicsState.Grounded && physicsState.Ground.First.PhysicsState != null && (physicsState.Ground.First != x.Instance && physicsState.Ground.First != trileInstance2); physicsState = trileInstance1.PhysicsState) { trileInstance2 = trileInstance1; ++num1; trileInstance1 = physicsState.Ground.First; } InstancePhysicsState physicsState1 = y.Instance.PhysicsState; TrileInstance trileInstance3; for (TrileInstance trileInstance4 = trileInstance3 = (TrileInstance)null; physicsState1.Grounded && physicsState1.Ground.First.PhysicsState != null && (physicsState1.Ground.First != y.Instance && physicsState1.Ground.First != trileInstance3); physicsState1 = trileInstance4.PhysicsState) { trileInstance3 = trileInstance4; ++num2; trileInstance4 = physicsState1.Ground.First; } if (num1 - num2 != 0) { return(num1 - num2); } Vector3 b = FezMath.Sign(x.Instance.PhysicsState.Velocity) * FezMath.XZMask; if (b == FezMath.Sign(y.Instance.PhysicsState.Velocity) * FezMath.XZMask) { return(Math.Sign(FezMath.Dot(x.Instance.Position - y.Instance.Position, b))); } else { return(Math.Sign(x.Instance.Position.Y - y.Instance.Position.Y)); } }
protected override bool Act(TimeSpan elapsed) { if (this.PlayerManager.PushedInstance == null || this.PlayerManager.PushedInstance.Hidden || this.PlayerManager.PushedInstance.PhysicsState == null) { this.PlayerManager.Action = ActionType.Idle; this.PlayerManager.PushedInstance = (TrileInstance)null; return(false); } else { Vector3 b = FezMath.SideMask(this.CameraManager.Viewpoint); Vector3 vector3 = FezMath.RightVector(this.CameraManager.Viewpoint) * (float)FezMath.Sign(this.PlayerManager.LookingDirection); TrileInstance pushedInstance = this.PlayerManager.PushedInstance; InstancePhysicsState physicsState = pushedInstance.PhysicsState; this.eCratePush.Position = pushedInstance.Center; this.eGomezPush.Position = this.PlayerManager.Center; if (!physicsState.Grounded) { this.PlayerManager.PushedInstance = (TrileInstance)null; this.PlayerManager.Action = ActionType.Idle; return(false); } else { int stackSize = this.FindStackSize(pushedInstance, 0); if (stackSize <= 2) { this.movementHelper.Entity = (IPhysicsEntity)physicsState; float num = this.InputManager.Movement.X; if (BoxCollisionResultExtensions.AnyCollided(physicsState.WallCollision) && ActorTypeExtensions.IsPickable(physicsState.WallCollision.First.Destination.Trile.ActorSettings.Type)) { num *= 5f; } if (pushedInstance.Trile.ActorSettings.Type == ActorType.Couch) { num *= 2f; } this.movementHelper.Update((float)elapsed.TotalSeconds, num / (float)(stackSize + 1)); if (this.pickupGroup != null) { pushedInstance.PhysicsState.Puppet = false; foreach (TrileInstance trileInstance in this.pickupGroup.Triles) { if (trileInstance != pushedInstance) { trileInstance.PhysicsState.Velocity = pushedInstance.PhysicsState.Velocity; trileInstance.PhysicsState.Puppet = true; } } } this.PlayerManager.Center = Vector3.Up * this.PlayerManager.Center + (FezMath.DepthMask(this.CameraManager.Viewpoint) + b) * physicsState.Center + -vector3 * (pushedInstance.TransformedSize / 2f + this.PlayerManager.Size / 2f); this.eCratePush.VolumeFactor = FezMath.Saturate(Math.Abs(FezMath.Dot(physicsState.Velocity, b)) / 0.024f); if (FezMath.AlmostEqual(FezMath.Dot(physicsState.Velocity, b), 0.0f)) { this.PlayerManager.Action = ActionType.Grabbing; return(false); } } else { this.PlayerManager.Action = ActionType.Grabbing; this.eCratePush.Cue.Pause(); this.eGomezPush.Cue.Pause(); } return(this.PlayerManager.Action == ActionType.Pushing); } } }
private void UpdatePickups(float elapsedSeconds) { Vector3 vector3 = Vector3.UnitY * this.CameraManager.Radius / this.CameraManager.AspectRatio; foreach (PickupState pickupState in this.PickupStates) { TrileInstance trileInstance = pickupState.Instance; InstancePhysicsState physicsState = trileInstance.PhysicsState; ActorType type = trileInstance.Trile.ActorSettings.Type; if (!physicsState.Paused && (physicsState.ShouldRespawn || trileInstance.Enabled && trileInstance != this.PlayerManager.CarriedInstance && (!physicsState.Static || pickupState.TouchesWater))) { this.TryFloat(pickupState, elapsedSeconds); if (!physicsState.Vanished && (!pickupState.TouchesWater || !ActorTypeExtensions.IsBuoyant(type))) { physicsState.Velocity += (float)(3.15000009536743 * (double)this.CollisionManager.GravityFactor * 0.150000005960464) * elapsedSeconds * Vector3.Down; } bool grounded = trileInstance.PhysicsState.Grounded; Vector3 center = physicsState.Center; this.PhysicsManager.Update((ISimplePhysicsEntity)physicsState, false, pickupState.Group == null && (!physicsState.Floating || !FezMath.AlmostEqual(physicsState.Velocity.X, 0.0f) || !FezMath.AlmostEqual(physicsState.Velocity.Z, 0.0f))); pickupState.LastMovement = physicsState.Center - center; if (physicsState.NoVelocityClamping) { physicsState.NoVelocityClamping = false; physicsState.Velocity = Vector3.Zero; } if (pickupState.AttachedAOs != null) { foreach (ArtObjectInstance artObjectInstance in pickupState.AttachedAOs) { artObjectInstance.Position += pickupState.LastMovement; } } if (((double)pickupState.LastGroundedCenter.Y - (double)trileInstance.Position.Y) * (double)Math.Sign(this.CollisionManager.GravityFactor) > (double)vector3.Y) { physicsState.Vanished = true; } else if (this.LevelManager.Loops) { while ((double)trileInstance.Position.Y < 0.0) { trileInstance.Position += this.LevelManager.Size * Vector3.UnitY; } while ((double)trileInstance.Position.Y > (double)this.LevelManager.Size.Y) { trileInstance.Position -= this.LevelManager.Size * Vector3.UnitY; } } if (physicsState.Floating && physicsState.Grounded && !physicsState.PushedUp) { physicsState.Floating = pickupState.TouchesWater = (double)trileInstance.Position.Y <= (double)this.LevelManager.WaterHeight - 13.0 / 16.0 + (double)pickupState.FloatMalus; } physicsState.ForceNonStatic = false; if (ActorTypeExtensions.IsFragile(type)) { if (!trileInstance.PhysicsState.Grounded) { pickupState.FlightApex = Math.Max(pickupState.FlightApex, trileInstance.Center.Y); } else if (!trileInstance.PhysicsState.Respawned && (double)pickupState.FlightApex - (double)trileInstance.Center.Y > (double)PickupsHost.BreakHeight(type)) { this.PlayBreakSound(type, trileInstance.Position); trileInstance.PhysicsState.Vanished = true; this.ParticleSystemManager.Add(new TrixelParticleSystem(this.Game, new TrixelParticleSystem.Settings() { ExplodingInstance = trileInstance, EnergySource = new Vector3?(trileInstance.Center - Vector3.Normalize(pickupState.LastVelocity) * trileInstance.TransformedSize / 2f), ParticleCount = 30, MinimumSize = 1, MaximumSize = 8, GravityModifier = 1f, Energy = 0.25f, BaseVelocity = pickupState.LastVelocity * 0.5f })); this.LevelMaterializer.CullInstanceOut(trileInstance); if (type == ActorType.Vase) { trileInstance.PhysicsState = (InstancePhysicsState)null; this.LevelManager.ClearTrile(trileInstance); break; } else { trileInstance.Enabled = false; trileInstance.PhysicsState.ShouldRespawn = true; } } } this.TryPushHorizontalStack(pickupState, elapsedSeconds); if (physicsState.Static) { pickupState.LastMovement = pickupState.LastVelocity = physicsState.Velocity = Vector3.Zero; physicsState.Respawned = false; } if (physicsState.Vanished) { physicsState.ShouldRespawn = true; } if (physicsState.ShouldRespawn && this.PlayerManager.Action != ActionType.FreeFalling) { physicsState.Center = pickupState.OriginalCenter + new Vector3(1.0 / 1000.0); physicsState.UpdateInstance(); physicsState.Velocity = Vector3.Zero; physicsState.ShouldRespawn = false; pickupState.LastVelocity = Vector3.Zero; pickupState.TouchesWater = false; physicsState.Floating = false; physicsState.PushedDownBy = (TrileInstance)null; trileInstance.Enabled = false; trileInstance.Hidden = true; physicsState.Ground = new MultipleHits <TrileInstance>() { NearLow = this.LevelManager.ActualInstanceAt(physicsState.Center - trileInstance.Trile.Size.Y * Vector3.UnitY) }; ServiceHelper.AddComponent((IGameComponent) new GlitchyRespawner(ServiceHelper.Game, trileInstance)); } physicsState.UpdateInstance(); this.LevelManager.UpdateInstance(trileInstance); if (!grounded && trileInstance.PhysicsState.Grounded && (double)Math.Abs(pickupState.LastVelocity.Y) > 0.0500000007450581) { float num1 = FezMath.Dot(pickupState.LastVelocity, FezMath.RightVector(this.CameraManager.Viewpoint)); float val1 = FezMath.Saturate(pickupState.LastVelocity.Y / (-0.2f * (float)Math.Sign(this.CollisionManager.GravityFactor))); AnimatedTexture animation; if (ActorTypeExtensions.IsHeavy(trileInstance.Trile.ActorSettings.Type)) { if ((double)val1 > 0.5) { animation = this.largeDust; } else { animation = this.smallDust; val1 *= 2f; } } else { animation = this.smallDust; } float num2 = Math.Max(val1, 0.4f); this.SpawnDust(trileInstance, num2, animation, (double)num1 >= 0.0, (double)num1 <= 0.0); if (animation == this.largeDust && (double)num1 != 0.0) { this.SpawnDust(trileInstance, num2, this.smallDust, (double)num1 <0.0, (double)num1> 0.0); } SoundEffectExtensions.EmitAt(this.thudSound, trileInstance.Position, (float)((double)num2 * -0.600000023841858 + 0.300000011920929), num2); } if (physicsState.Grounded && physicsState.Ground.First.PhysicsState != null) { physicsState.Ground.First.PhysicsState.PushedDownBy = trileInstance; } pickupState.LastVelocity = trileInstance.PhysicsState.Velocity; } } }
public override void Update(GameTime gameTime) { if (this.CameraManager.Viewpoint == Viewpoint.Perspective || !this.CameraManager.ActionRunning || (this.GameState.Paused || this.GameState.InMap) || (this.GameState.Loading || this.PickupStates == null || this.PickupStates.Count == 0)) { return; } this.sinceLevelChanged += (float)gameTime.ElapsedGameTime.TotalSeconds; this.initLock.WaitOne(); for (int index = this.PickupStates.Count - 1; index >= 0; --index) { if (this.PickupStates[index].Instance.PhysicsState == null) { this.PickupStates.RemoveAt(index); } } foreach (PickupState pickupState in this.PickupStates) { if (pickupState.Instance.PhysicsState.StaticGrounds) { pickupState.Instance.PhysicsState.GroundMovement = Vector3.Zero; } } this.PickupStates.Sort((IComparer <PickupState>)MovingGroundsPickupComparer.Default); this.UpdatePickups((float)gameTime.ElapsedGameTime.TotalSeconds); foreach (TrileGroup trileGroup1 in (IEnumerable <TrileGroup>) this.LevelManager.PickupGroups.Values) { if (trileGroup1.InMidAir) { foreach (TrileInstance trileInstance in trileGroup1.Triles) { if (!trileInstance.PhysicsState.Paused && trileInstance.PhysicsState.Grounded) { trileGroup1.InMidAir = false; if (trileInstance.PhysicsState.Puppet) { trileInstance.PhysicsState.Puppet = false; using (List <TrileInstance> .Enumerator enumerator = trileGroup1.Triles.GetEnumerator()) { while (enumerator.MoveNext()) { TrileInstance current = enumerator.Current; if (current != trileInstance) { current.PhysicsState.Puppet = true; } } break; } } else { break; } } } } else { trileGroup1.InMidAir = true; foreach (TrileInstance trileInstance in trileGroup1.Triles) { TrileGroup trileGroup2 = trileGroup1; int num = trileGroup2.InMidAir & !trileInstance.PhysicsState.Grounded ? 1 : 0; trileGroup2.InMidAir = num != 0; } } } foreach (PickupState pickupState1 in this.PickupStates) { if (pickupState1.Group != null && !pickupState1.Instance.PhysicsState.Puppet) { PickupState pickupState2 = pickupState1; foreach (PickupState pickupState3 in this.PickupStates) { if (pickupState3.Group == pickupState2.Group && pickupState3 != pickupState2) { pickupState3.Instance.PhysicsState.Center += pickupState2.LastMovement - pickupState3.LastMovement; pickupState3.Instance.PhysicsState.Background = pickupState2.Instance.PhysicsState.Background; pickupState3.Instance.PhysicsState.Velocity = pickupState2.Instance.PhysicsState.Velocity; pickupState3.Instance.PhysicsState.UpdateInstance(); this.LevelManager.UpdateInstance(pickupState3.Instance); pickupState3.LastMovement = Vector3.Zero; pickupState3.FloatMalus = pickupState2.FloatMalus; pickupState3.FloatSeed = pickupState2.FloatSeed; } } } if (pickupState1.VisibleOverlapper != null) { PickupState pickupState2 = pickupState1.VisibleOverlapper; InstancePhysicsState physicsState = pickupState1.Instance.PhysicsState; physicsState.Background = pickupState2.Instance.PhysicsState.Background; physicsState.Ground = pickupState2.Instance.PhysicsState.Ground; physicsState.Floating = pickupState2.Instance.PhysicsState.Floating; Array.Copy((Array)physicsState.CornerCollision, (Array)pickupState1.Instance.PhysicsState.CornerCollision, 4); physicsState.GroundMovement = pickupState2.Instance.PhysicsState.GroundMovement; physicsState.Sticky = pickupState2.Instance.PhysicsState.Sticky; physicsState.WallCollision = pickupState2.Instance.PhysicsState.WallCollision; physicsState.PushedDownBy = pickupState2.Instance.PhysicsState.PushedDownBy; pickupState1.LastGroundedCenter = pickupState2.LastGroundedCenter; pickupState1.LastVelocity = pickupState2.LastVelocity; pickupState1.TouchesWater = pickupState2.TouchesWater; } } foreach (PickupState pickupState in this.PickupStates) { if (pickupState.Instance.PhysicsState != null && (pickupState.Instance.PhysicsState.Grounded || this.PlayerManager.CarriedInstance == pickupState.Instance || pickupState.Instance.PhysicsState.Floating)) { pickupState.FlightApex = pickupState.Instance.Center.Y; pickupState.LastGroundedCenter = pickupState.Instance.Center; } } this.initLock.Set(); }