Exemple #1
0
        public void UpdateBounds()
        {
            if (!this.boundsDirty)
            {
                return;
            }
            Vector3 vector3 = FezMath.Abs(Vector3.Transform(this.Size / 2f * this.scale, this.rotation));

            this.Bounds      = FezMath.Enclose(this.position - vector3, this.position + vector3);
            this.boundsDirty = false;
        }
Exemple #2
0
        public override void Update(GameTime gameTime)
        {
            if (this.CameraManager.Viewpoint == Viewpoint.Perspective || this.GameState.InMap || (this.GameState.Paused || this.GameState.Loading) || this.watchers.Count == 0)
            {
                return;
            }
            Vector3 vector3_1 = FezMath.RightVector(this.CameraManager.Viewpoint);
            Vector3 vector3_2 = FezMath.Abs(vector3_1);
            Vector3 vector3_3 = FezMath.ForwardVector(this.CameraManager.Viewpoint);

            foreach (TrileInstance index in this.watchers.Keys)
            {
                WatchersHost.WatcherState watcherState = this.watchers[index];
                Vector3 vector3_4 = index.PhysicsState.Center + vector3_2 * -5f / 16f + Vector3.UnitY * -2f / 16f - 0.5f * vector3_3;
                watcherState.Eyes.Groups[0].Position = vector3_4 + watcherState.EyeOffset;
                watcherState.Eyes.Groups[1].Position = vector3_4 + vector3_2 * 9f / 16f + watcherState.EyeOffset;
                watcherState.Eyes.Groups[0].Enabled  = true;
                watcherState.Eyes.Groups[1].Enabled  = true;
            }
            if (!this.CameraManager.ActionRunning || !this.CameraManager.ViewTransitionReached)
            {
                return;
            }
            Vector3     center1   = this.PlayerManager.Center;
            BoundingBox box       = FezMath.Enclose(center1 - this.PlayerManager.Size / 2f, center1 + this.PlayerManager.Size / 2f);
            Vector3     vector3_5 = vector3_1 * 8f;
            Vector3     vector3_6 = vector3_3 * this.LevelManager.Size;
            Vector3     vector3_7 = Vector3.Up * 8f;

            this.lastCrushDirections.Clear();
            bool flag1 = false;

            foreach (TrileInstance index in this.watchers.Keys)
            {
                WatchersHost.WatcherState watcherState1 = this.watchers[index];
                Vector3     vector1      = FezMath.Sign(center1 - index.Position) * vector3_2;
                Vector3     vector3_4    = FezMath.Sign(center1 - index.Position) * Vector3.UnitY;
                BoundingBox boundingBox1 = (double)Vector3.Dot(vector1, vector3_1) > 0.0 ? FezMath.Enclose(index.Position + Vector3.UnitY * 0.05f - vector3_6, index.Position + vector3_5 + vector3_6 + new Vector3(0.9f)) : FezMath.Enclose(index.Position + Vector3.UnitY * 0.05f - vector3_6 - vector3_5, index.Position + vector3_6 + new Vector3(0.9f));
                BoundingBox boundingBox2 = FezMath.Enclose(index.Position + Vector3.UnitY * 0.05f - vector3_7 - vector3_6, index.Position + vector3_7 + new Vector3(0.9f) + vector3_6);
                switch (watcherState1.Action)
                {
                case WatchersHost.WatcherAction.Idle:
                    bool flag2 = boundingBox1.Intersects(box);
                    bool flag3 = boundingBox2.Intersects(box);
                    watcherState1.EyeOffset             = !flag2 ? (!flag3 ? Vector3.Lerp(watcherState1.EyeOffset, Vector3.Zero, 0.1f) : Vector3.Lerp(watcherState1.EyeOffset, vector3_4 * 1f / 16f, 0.25f)) : Vector3.Lerp(watcherState1.EyeOffset, vector1 * 1f / 16f, 0.25f);
                    watcherState1.CrushDirection        = flag2 ? vector1 : (flag3 ? vector3_4 : Vector3.Zero);
                    watcherState1.Eyes.Material.Opacity = 1f;
                    WatchersHost.WatcherState watcherState2;
                    if (this.LevelManager.NearestTrile(index.Position + new Vector3(0.5f)).Deep == index && (flag2 || flag3) && (!FezMath.In <ActionType>(this.PlayerManager.Action, ActionType.GrabCornerLedge, ActionType.Suffering, ActionType.Dying, (IEqualityComparer <ActionType>)ActionTypeComparer.Default) && (watcherState2 = this.HasPair(index)) != null))
                    {
                        watcherState1.Action    = WatchersHost.WatcherAction.Spotted;
                        watcherState2.StartTime = watcherState1.StartTime = gameTime.TotalGameTime;
                        if (!watcherState1.SkipNextSound)
                        {
                            SoundEffectExtensions.EmitAt(this.seeSound, index.Center);
                            watcherState2.SkipNextSound = true;
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }

                case WatchersHost.WatcherAction.Spotted:
                    watcherState1.EyeOffset = Vector3.Lerp(watcherState1.EyeOffset, watcherState1.CrushDirection * 1f / 16f, 0.25f);
                    if ((gameTime.TotalGameTime - watcherState1.StartTime).TotalSeconds > 1.0)
                    {
                        watcherState1.Action        = WatchersHost.WatcherAction.Crushing;
                        watcherState1.StartTime     = gameTime.TotalGameTime;
                        index.PhysicsState.Velocity = watcherState1.OriginalCenter - index.Center;
                        this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false);
                        index.PhysicsState.UpdateInstance();
                        this.LevelManager.UpdateInstance(index);
                        watcherState1.MoveEmitter = watcherState1.SkipNextSound ? (SoundEmitter)null : SoundEffectExtensions.EmitAt(this.moveSound, index.Center);
                        break;
                    }
                    else
                    {
                        Vector3 vector3_8 = watcherState1.CrushDirection * RandomHelper.Unit() * 0.5f / 16f;
                        index.PhysicsState.Sticky   = true;
                        index.PhysicsState.Velocity = watcherState1.OriginalCenter + vector3_8 - index.Center;
                        this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false);
                        index.PhysicsState.UpdateInstance();
                        this.LevelManager.UpdateInstance(index);
                        break;
                    }

                case WatchersHost.WatcherAction.Crushing:
                    if (index.PhysicsState.Sticky)
                    {
                        index.PhysicsState.Sticky   = false;
                        index.PhysicsState.Velocity = Vector3.Zero;
                    }
                    watcherState1.EyeOffset = watcherState1.CrushDirection * 1f / 16f;
                    Vector3 vector3_9  = watcherState1.CrushDirection * (float)gameTime.ElapsedGameTime.TotalSeconds * 15f;
                    Vector3 vector3_10 = Vector3.Lerp(index.PhysicsState.Velocity, vector3_9, 0.025f);
                    index.PhysicsState.Velocity = vector3_10 * watcherState1.CrashAttenuation;
                    if (FezMath.VisibleAxis(this.CameraManager.Viewpoint) != FezMath.AsAxis(FezMath.OrientationFromDirection(watcherState1.CrushDirection)))
                    {
                        this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, false, false);
                    }
                    Vector3 vector3_11 = vector3_10 * watcherState1.CrashAttenuation - index.PhysicsState.Velocity;
                    if (watcherState1.MoveEmitter != null)
                    {
                        watcherState1.MoveEmitter.Position = index.Center;
                    }
                    index.PhysicsState.UpdateInstance();
                    this.LevelManager.UpdateInstance(index);
                    this.PlayerManager.ForceOverlapsDetermination();
                    bool flag4 = this.PlayerManager.HeldInstance == index || this.PlayerManager.WallCollision.FarHigh.Destination == index || (this.PlayerManager.WallCollision.NearLow.Destination == index || this.PlayerManager.Ground.NearLow == index) || this.PlayerManager.Ground.FarHigh == index;
                    if (!flag4)
                    {
                        foreach (PointCollision pointCollision in this.PlayerManager.CornerCollision)
                        {
                            if (pointCollision.Instances.Deep == index)
                            {
                                flag4 = true;
                                break;
                            }
                        }
                    }
                    if (flag1 && flag4 && this.lastCrushDirections.Contains(-watcherState1.CrushDirection))
                    {
                        this.PlayerManager.Position    = index.Center + Vector3.One / 2f * watcherState1.CrushDirection + -FezMath.SideMask(this.CameraManager.Viewpoint) * FezMath.Abs(watcherState1.CrushDirection) * 1.5f / 16f;
                        this.PlayerManager.Velocity    = Vector3.Zero;
                        this.PlayerManager.Action      = (double)watcherState1.CrushDirection.Y == 0.0 ? ActionType.CrushHorizontal : ActionType.CrushVertical;
                        watcherState1.CrashAttenuation = this.PlayerManager.Action == ActionType.CrushVertical ? 0.5f : 0.75f;
                    }
                    flag1 = flag1 | flag4;
                    if (flag4 && this.PlayerManager.Action != ActionType.CrushHorizontal && this.PlayerManager.Action != ActionType.CrushVertical)
                    {
                        this.lastCrushDirections.Add(watcherState1.CrushDirection);
                        if ((double)watcherState1.CrushDirection.Y == 0.0)
                        {
                            this.PlayerManager.Position += index.PhysicsState.Velocity;
                        }
                    }
                    if ((double)vector3_11.LengthSquared() > 4.99999987368938E-05 || (double)Math.Abs(Vector3.Dot(index.Center - watcherState1.OriginalCenter, FezMath.Abs(watcherState1.CrushDirection))) >= 8.0)
                    {
                        if (watcherState1.MoveEmitter != null && !watcherState1.MoveEmitter.Dead)
                        {
                            watcherState1.MoveEmitter.Cue.Stop(false);
                        }
                        watcherState1.MoveEmitter = (SoundEmitter)null;
                        if (!watcherState1.SkipNextSound)
                        {
                            SoundEffectExtensions.EmitAt(this.collideSound, index.Center);
                        }
                        watcherState1.Action           = WatchersHost.WatcherAction.Wait;
                        index.PhysicsState.Velocity    = Vector3.Zero;
                        watcherState1.StartTime        = TimeSpan.Zero;
                        watcherState1.CrashAttenuation = 1f;
                        break;
                    }
                    else
                    {
                        break;
                    }

                case WatchersHost.WatcherAction.Wait:
                    watcherState1.StartTime += gameTime.ElapsedGameTime;
                    if (watcherState1.StartTime.TotalSeconds > 1.5)
                    {
                        watcherState1.Action          = WatchersHost.WatcherAction.Withdrawing;
                        watcherState1.StartTime       = gameTime.TotalGameTime;
                        watcherState1.WithdrawEmitter = watcherState1.SkipNextSound ? (SoundEmitter)null : SoundEffectExtensions.EmitAt(this.withdrawSound, index.Center, true);
                        break;
                    }
                    else
                    {
                        break;
                    }

                case WatchersHost.WatcherAction.Withdrawing:
                    watcherState1.EyeOffset = Vector3.Lerp(watcherState1.EyeOffset, -watcherState1.CrushDirection * 0.5f / 16f, 0.05f);
                    Vector3 vector3_12 = -watcherState1.CrushDirection * (float)gameTime.ElapsedGameTime.TotalSeconds * 2f;
                    index.PhysicsState.Velocity = Vector3.Lerp(index.PhysicsState.Velocity, vector3_12, 0.025f);
                    if (watcherState1.WithdrawEmitter != null)
                    {
                        watcherState1.WithdrawEmitter.VolumeFactor = 0.0f;
                    }
                    bool flag5 = false;
                    if (FezMath.DepthMask(this.CameraManager.Viewpoint) == FezMath.GetMask(FezMath.AsAxis(FezMath.OrientationFromDirection(watcherState1.CrushDirection))))
                    {
                        flag5 = true;
                    }
                    if (watcherState1.WithdrawEmitter != null)
                    {
                        watcherState1.WithdrawEmitter.VolumeFactor = 1f;
                    }
                    Vector3 center2  = index.PhysicsState.Center;
                    Vector3 velocity = index.PhysicsState.Velocity;
                    this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false);
                    index.PhysicsState.Center = center2 + velocity;
                    if (watcherState1.WithdrawEmitter != null)
                    {
                        watcherState1.WithdrawEmitter.Position = index.Center;
                    }
                    if (flag5 ? (double)Math.Abs(Vector3.Dot(index.Center - watcherState1.OriginalCenter, vector3_1 + Vector3.Up)) <= 1.0 / 32.0 : (double)Vector3.Dot(index.Center - watcherState1.OriginalCenter, watcherState1.CrushDirection) <= 1.0 / 1000.0)
                    {
                        if (watcherState1.WithdrawEmitter != null)
                        {
                            watcherState1.WithdrawEmitter.FadeOutAndDie(0.1f);
                            watcherState1.WithdrawEmitter = (SoundEmitter)null;
                        }
                        watcherState1.SkipNextSound  = false;
                        watcherState1.Action         = WatchersHost.WatcherAction.Cooldown;
                        watcherState1.CrushDirection = Vector3.Zero;
                        watcherState1.StartTime      = TimeSpan.Zero;
                    }
                    index.PhysicsState.UpdateInstance();
                    this.LevelManager.UpdateInstance(index);
                    break;

                case WatchersHost.WatcherAction.Cooldown:
                    index.PhysicsState.Velocity = watcherState1.OriginalCenter - index.Center;
                    this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false);
                    index.PhysicsState.UpdateInstance();
                    this.LevelManager.UpdateInstance(index);
                    watcherState1.EyeOffset             = Vector3.Lerp(watcherState1.EyeOffset, Vector3.Zero, 0.05f);
                    watcherState1.Eyes.Material.Opacity = 0.5f;
                    watcherState1.StartTime            += gameTime.ElapsedGameTime;
                    if (watcherState1.StartTime.TotalSeconds > 0.5)
                    {
                        index.PhysicsState.Velocity = Vector3.Zero;
                        watcherState1.Action        = WatchersHost.WatcherAction.Idle;
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
                Vector3 vector3_13 = index.PhysicsState.Center + vector3_2 * -5f / 16f + Vector3.UnitY * -2f / 16f - 0.5f * vector3_3;
                watcherState1.Eyes.Groups[0].Position = vector3_13 + watcherState1.EyeOffset;
                watcherState1.Eyes.Groups[1].Position = vector3_13 + vector3_2 * 9f / 16f + watcherState1.EyeOffset;
                watcherState1.Eyes.Groups[2].Position = watcherState1.Eyes.Groups[0].Position;
                watcherState1.Eyes.Groups[3].Position = watcherState1.Eyes.Groups[1].Position;
                watcherState1.Eyes.Groups[0].Enabled  = false;
                watcherState1.Eyes.Groups[1].Enabled  = false;
            }
        }