示例#1
0
        public TrileInstance ActualInstanceAt(Vector3 position)
        {
            Vector3          vector3             = FezMath.ForwardVector(this.CameraManager.Viewpoint);
            bool             depthIsZ            = (double)vector3.Z != 0.0;
            bool             flag                = depthIsZ;
            int              forwardSign         = depthIsZ ? (int)vector3.Z : (int)vector3.X;
            Vector3          screenSpacePosition = new Vector3(flag ? position.X : position.Z, position.Y, depthIsZ ? position.Z : position.X);
            TrileEmplacement emplacement         = new TrileEmplacement((int)Math.Floor((double)position.X), (int)Math.Floor((double)position.Y), (int)Math.Floor((double)position.Z));
            float            num = FezMath.Frac(screenSpacePosition.Z);

            LevelManager.QueryResult queryResult;
            TrileInstance            trileInstance = this.OffsetInstanceAt(emplacement, screenSpacePosition, depthIsZ, forwardSign, false, false, QueryOptions.None, out queryResult);

            if (trileInstance != null)
            {
                return(trileInstance);
            }
            if ((double)num >= 0.5)
            {
                return(this.OffsetInstanceAt(emplacement.GetOffset(depthIsZ ? 0 : 1, 0, depthIsZ ? 1 : 0), screenSpacePosition, depthIsZ, forwardSign, false, false, QueryOptions.None, out queryResult));
            }
            else
            {
                return(this.OffsetInstanceAt(emplacement.GetOffset(depthIsZ ? 0 : -1, 0, depthIsZ ? -1 : 0), screenSpacePosition, depthIsZ, forwardSign, false, false, QueryOptions.None, out queryResult));
            }
        }
示例#2
0
        private void TryInitialize()
        {
            this.Enabled   = this.LevelManager.Name == "CLOCK";
            this.RedAo     = this.BlueAo = this.GreenAo = this.WhiteAo = (ArtObjectInstance)null;
            this.sTickTock = (SoundEffect)null;
            this.eTickTock = (SoundEmitter)null;
            if (!this.Enabled)
            {
                return;
            }
            foreach (ArtObjectInstance artObjectInstance in (IEnumerable <ArtObjectInstance>) this.LevelManager.ArtObjects.Values)
            {
                if (artObjectInstance.ArtObjectName == "CLOCKHAND_RAO")
                {
                    this.RedAo = artObjectInstance;
                }
                if (artObjectInstance.ArtObjectName == "CLOCKHAND_GAO")
                {
                    this.GreenAo = artObjectInstance;
                }
                if (artObjectInstance.ArtObjectName == "CLOCKHAND_BAO")
                {
                    this.BlueAo = artObjectInstance;
                }
                if (artObjectInstance.ArtObjectName == "CLOCKHAND_WAO")
                {
                    this.WhiteAo = artObjectInstance;
                }
            }
            this.RedOriginalRotation   = this.RedAo.Rotation;
            this.BlueOriginalRotation  = this.BlueAo.Rotation;
            this.GreenOriginalRotation = this.GreenAo.Rotation;
            this.WhiteOriginalRotation = this.WhiteAo.Rotation;
            this.RedOriginalPosition   = this.RedAo.Position + 1.125f * Vector3.UnitX;
            this.GreenOriginalPosition = this.GreenAo.Position - 1.125f * Vector3.UnitX;
            this.BlueOriginalPosition  = this.BlueAo.Position + 1.125f * Vector3.UnitZ;
            this.WhiteOriginalPosition = this.WhiteAo.Position - 1.125f * Vector3.UnitZ;
            this.RedGroup     = this.LevelManager.Groups[23];
            this.BlueGroup    = this.LevelManager.Groups[24];
            this.GreenGroup   = this.LevelManager.Groups[25];
            this.WhiteGroup   = this.LevelManager.Groups[26];
            this.RedTopMost   = Enumerable.First <TrileInstance>((IEnumerable <TrileInstance>) this.RedGroup.Triles, (Func <TrileInstance, bool>)(x => x.Emplacement.Y == 58));
            this.BlueTopMost  = Enumerable.First <TrileInstance>((IEnumerable <TrileInstance>) this.BlueGroup.Triles, (Func <TrileInstance, bool>)(x => x.Emplacement.Y == 58));
            this.GreenTopMost = Enumerable.First <TrileInstance>((IEnumerable <TrileInstance>) this.GreenGroup.Triles, (Func <TrileInstance, bool>)(x => x.Emplacement.Y == 58));
            this.WhiteTopMost = Enumerable.First <TrileInstance>((IEnumerable <TrileInstance>) this.WhiteGroup.Triles, (Func <TrileInstance, bool>)(x => x.Emplacement.Y == 58));
            if (this.GameState.SaveData.ThisLevel.InactiveArtObjects.Contains(this.RedAo.Id))
            {
                this.RedAo.Enabled = false;
                this.LevelManager.RemoveArtObject(this.RedAo);
            }
            if (this.GameState.SaveData.ThisLevel.InactiveArtObjects.Contains(this.GreenAo.Id))
            {
                this.GreenAo.Enabled = false;
                this.LevelManager.RemoveArtObject(this.GreenAo);
            }
            if (this.GameState.SaveData.ThisLevel.InactiveArtObjects.Contains(this.BlueAo.Id))
            {
                this.BlueAo.Enabled = false;
                this.LevelManager.RemoveArtObject(this.BlueAo);
            }
            if (this.GameState.SaveData.ThisLevel.InactiveArtObjects.Contains(this.WhiteAo.Id))
            {
                this.WhiteAo.Enabled = false;
                this.LevelManager.RemoveArtObject(this.WhiteAo);
            }
            TimeSpan timeSpan = TimeSpan.FromTicks((DateTime.UtcNow - DateTime.FromFileTimeUtc(this.GameState.SaveData.CreationTime)).Ticks);

            if (this.RedAo.Enabled)
            {
                float angle = FezMath.WrapAngle((float)((double)FezMath.Round(timeSpan.TotalSeconds) / 60.0 * 6.28318548202515));
                this.lastRedAngle   = angle;
                this.RedAo.Rotation = Quaternion.CreateFromAxisAngle(-Vector3.UnitZ, angle) * this.RedOriginalRotation;
            }
            if (!this.WhiteAo.Enabled && !this.BlueAo.Enabled && (!this.GreenAo.Enabled && !this.RedAo.Enabled))
            {
                return;
            }
            this.sTickTock = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/MiscActors/TickTockLoop");
            Waiters.Wait(FezMath.Frac(timeSpan.TotalSeconds), (Action)(() => this.eTickTock = SoundEffectExtensions.EmitAt(this.sTickTock, new Vector3(41.5f, 61.5f, 35.5f), true)));
        }
示例#3
0
        public override void Update(GameTime gameTime)
        {
            if (this.CameraManager.Viewpoint == Viewpoint.Perspective || !this.CameraManager.ActionRunning || (this.GameState.Paused || this.GameState.InMap) || (this.CameraManager.RequestedViewpoint != Viewpoint.None || this.GameState.Loading))
            {
                return;
            }
            foreach (BombsHost.DestructibleGroup destructibleGroup1 in this.destructibleGroups)
            {
                if (destructibleGroup1.RespawnIn.HasValue)
                {
                    BombsHost.DestructibleGroup destructibleGroup2 = destructibleGroup1;
                    float?nullable1 = destructibleGroup2.RespawnIn;
                    float num       = (float)gameTime.ElapsedGameTime.TotalSeconds;
                    float?nullable2 = nullable1.HasValue ? new float?(nullable1.GetValueOrDefault() - num) : new float?();
                    destructibleGroup2.RespawnIn = nullable2;
                    if ((double)destructibleGroup1.RespawnIn.Value <= 0.0)
                    {
                        bool flag = true;
                        foreach (TrileInstance instance in destructibleGroup1.AllTriles)
                        {
                            if (!instance.Enabled || instance.Hidden || instance.Removed)
                            {
                                instance.Enabled = false;
                                instance.Hidden  = true;
                                ServiceHelper.AddComponent((IGameComponent) new GlitchyRespawner(ServiceHelper.Game, instance, flag || RandomHelper.Probability(0.25)));
                                flag = false;
                            }
                        }
                        destructibleGroup1.RespawnIn = new float?();
                    }
                }
            }
            TrileInstance carriedInstance = this.PlayerManager.CarriedInstance;

            if (carriedInstance != null && ActorTypeExtensions.IsBomb(carriedInstance.Trile.ActorSettings.Type) && !this.bombStates.ContainsKey(carriedInstance))
            {
                carriedInstance.Foreign = carriedInstance.PhysicsState.Respawned = false;
                this.bombStates.Add(carriedInstance, new BombsHost.BombState());
            }
            bool flag1 = false;
            bool flag2 = false;

            foreach (TrileInstance instance in this.bombStates.Keys)
            {
                BombsHost.BombState state = this.bombStates[instance];
                if (!ActionTypeExtensions.IsEnteringDoor(this.PlayerManager.Action))
                {
                    state.SincePickup += gameTime.ElapsedGameTime;
                }
                bool flag3 = instance.Trile.ActorSettings.Type == ActorType.BigBomb;
                bool flag4 = instance.Trile.ActorSettings.Type == ActorType.TntBlock || instance.Trile.ActorSettings.Type == ActorType.TntPickup;
                if (ActorTypeExtensions.IsBomb(instance.Trile.ActorSettings.Type) && instance.Hidden)
                {
                    this.bsToRemove.Add(instance);
                    if (state.Flash != null)
                    {
                        this.flashesMesh.RemoveGroup(state.Flash);
                        state.Flash = (Group)null;
                    }
                    if (state.Emitter != null && state.Emitter.Cue != null)
                    {
                        state.Emitter.Cue.Stop(false);
                    }
                }
                else
                {
                    if (state.SincePickup > this.FlashTime && state.Explosion == null)
                    {
                        if (state.Flash == null)
                        {
                            state.Flash = this.flashesMesh.AddFace(Vector3.One, Vector3.Zero, FaceOrientation.Front, this.FlashColor, true);
                            if (ActorTypeExtensions.IsBomb(instance.Trile.ActorSettings.Type) && !state.IsChainsploding)
                            {
                                state.Emitter = SoundEffectExtensions.EmitAt(this.countdownSound, instance.Center);
                                state.Emitter.PauseViewTransitions = true;
                            }
                        }
                        double totalSeconds = state.SincePickup.TotalSeconds;
                        if (totalSeconds > this.ExplodeStart.TotalSeconds - 1.0)
                        {
                            totalSeconds *= 2.0;
                        }
                        state.Flash.Enabled = FezMath.Frac(totalSeconds) < 0.5;
                        if (state.Flash.Enabled)
                        {
                            state.Flash.Position = instance.Center;
                            state.Flash.Rotation = this.CameraManager.Rotation;
                        }
                    }
                    if (state.SincePickup > this.ExplodeStart && state.Explosion == null)
                    {
                        if (flag4 && !flag1 || !flag4 && !flag2)
                        {
                            SoundEffectExtensions.EmitAt(flag4 ? this.crystalsplodeSound : this.explodeSound, instance.Center, RandomHelper.Centered(0.025));
                            if (flag4)
                            {
                                flag1 = true;
                            }
                            else
                            {
                                flag2 = true;
                            }
                        }
                        if (state.ChainsplodedBy != null && state.ChainsplodedBy.Emitter != null)
                        {
                            state.ChainsplodedBy.Emitter.FadeOutAndDie(0.0f);
                        }
                        float num1 = (flag3 ? 0.6f : 0.3f) * FezMath.Saturate((float)(1.0 - (double)(instance.Center - this.PlayerManager.Center).Length() / 15.0));
                        if (CamShake.CurrentCamShake == null)
                        {
                            ServiceHelper.AddComponent((IGameComponent) new CamShake(this.Game)
                            {
                                Duration = TimeSpan.FromSeconds(0.75),
                                Distance = num1
                            });
                        }
                        else
                        {
                            CamShake.CurrentCamShake.Reset();
                        }
                        this.ParticleSystemManager.PropagateEnergy(instance.Center, flag3 ? 6f : 3f);
                        this.flashesMesh.RemoveGroup(state.Flash);
                        state.Flash = (Group)null;
                        switch (instance.Trile.ActorSettings.Type)
                        {
                        case ActorType.BigBomb:
                            state.Explosion = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.bigBombAnimation)
                            {
                                ActorType = ActorType.Bomb
                            };
                            break;

                        case ActorType.TntBlock:
                        case ActorType.TntPickup:
                            state.Explosion = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.tntAnimation)
                            {
                                ActorType = ActorType.Bomb
                            };
                            break;

                        default:
                            state.Explosion = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.bombAnimation)
                            {
                                ActorType = ActorType.Bomb
                            };
                            break;
                        }
                        state.Explosion.Timing.Loop      = false;
                        state.Explosion.Billboard        = true;
                        state.Explosion.Fullbright       = true;
                        state.Explosion.OriginalRotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)RandomHelper.Random.Next(0, 4) * 1.570796f);
                        state.Explosion.Timing.Restart();
                        this.LevelManager.AddPlane(state.Explosion);
                        state.Flare = new BackgroundPlane(this.LevelMaterializer.StaticPlanesMesh, (Texture)this.flare)
                        {
                            AlwaysOnTop         = true,
                            LightMap            = true,
                            AllowOverbrightness = true,
                            Billboard           = true
                        };
                        this.LevelManager.AddPlane(state.Flare);
                        state.Flare.Scale        = Vector3.One * (flag3 ? 3f : 1.5f);
                        state.Explosion.Position = state.Flare.Position = instance.Center + (RandomHelper.Centered(1.0 / 1000.0) - 0.5f) * FezMath.ForwardVector(this.CameraManager.Viewpoint);
                        float num2 = flag3 ? 3f : 1.5f;
                        float num3 = ((this.PlayerManager.Position - instance.Center) * FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint)).Length();
                        if ((this.PlayerManager.CarriedInstance == instance || (double)num3 < (double)num2) && this.PlayerManager.Action != ActionType.Dying)
                        {
                            this.PlayerManager.Action = ActionType.Suffering;
                        }
                        if ((instance.Trile.ActorSettings.Type == ActorType.TntBlock || state.IsChainsploding) && instance.InstanceId != -1)
                        {
                            this.ParticleSystemManager.Add(new TrixelParticleSystem(this.Game, new TrixelParticleSystem.Settings()
                            {
                                ExplodingInstance = instance,
                                EnergySource      = new Vector3?(instance.Center),
                                MaximumSize       = 7,
                                Energy            = flag4 ? 3f : 1.5f,
                                Darken            = true,
                                ParticleCount     = 4 + 12 / Math.Max(1, this.TrixelParticleSystems.Count - 3)
                            }));
                        }
                        if (ActorTypeExtensions.IsPickable(instance.Trile.ActorSettings.Type))
                        {
                            instance.Enabled = false;
                            this.LevelMaterializer.GetTrileMaterializer(instance.Trile).UpdateInstance(instance);
                        }
                        else
                        {
                            this.ClearDestructible(instance, false);
                        }
                        this.DropSupportedTriles(instance);
                        this.DestroyNeighborhood(instance, state);
                    }
                    if (state.Explosion != null)
                    {
                        state.Flare.Filter = Color.Lerp(flag4 ? new Color(0.5f, 1f, 0.25f) : new Color(1f, 0.5f, 0.25f), Color.Black, state.Explosion.Timing.NormalizedStep);
                        if (state.Explosion.Timing.Ended)
                        {
                            this.bsToRemove.Add(instance);
                            if (instance.PhysicsState != null)
                            {
                                instance.PhysicsState.ShouldRespawn = ActorTypeExtensions.IsPickable(instance.Trile.ActorSettings.Type);
                            }
                            this.LevelManager.RemovePlane(state.Explosion);
                            this.LevelManager.RemovePlane(state.Flare);
                        }
                    }
                }
            }
            foreach (TrileInstance key in this.bsToRemove)
            {
                this.bombStates.Remove(key);
            }
            this.bsToRemove.Clear();
            foreach (KeyValuePair <TrileInstance, BombsHost.BombState> keyValuePair in this.bsToAdd)
            {
                if (!this.bombStates.ContainsKey(keyValuePair.Key))
                {
                    this.bombStates.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }
            this.bsToAdd.Clear();
        }
示例#4
0
        public NearestTriles NearestTrile(Vector3 position, QueryOptions options, Viewpoint?vp)
        {
            NearestTriles nearestTriles = new NearestTriles();
            bool          hasValue      = vp.HasValue;
            Viewpoint     view          = hasValue ? vp.Value : this.CameraManager.Viewpoint;

            if (!hasValue)
            {
                this.WaitForScreenInvalidation();
            }
            bool             flag1       = view == Viewpoint.Front || view == Viewpoint.Back;
            bool             flag2       = (options & QueryOptions.Background) == QueryOptions.Background;
            bool             simpleTest  = (options & QueryOptions.Simple) == QueryOptions.Simple;
            TrileEmplacement emplacement = new TrileEmplacement((int)position.X, (int)position.Y, (int)position.Z);
            Vector3          vector3     = FezMath.ForwardVector(view);
            int     forwardSign          = flag1 ? (int)vector3.Z : (int)vector3.X;
            Vector3 screenSpacePosition  = new Vector3(flag1 ? position.X : position.Z, position.Y, -1f);
            Point   key = !flag1 ? new Point(emplacement.Z, emplacement.Y) : new Point(emplacement.X, emplacement.Y);
            int     num1;

            if (hasValue)
            {
                forwardSign = flag1 ? (int)vector3.Z : (int)vector3.X;
                if (flag2)
                {
                    forwardSign *= -1;
                }
                float num2 = (float)(((flag1 ? (double)this.Size.Z : (double)this.Size.X) - 1.0) / 2.0);
                if (flag1)
                {
                    emplacement.Z = (int)((double)num2 - (double)forwardSign * (double)num2);
                }
                else
                {
                    emplacement.X = (int)((double)num2 - (double)forwardSign * (double)num2);
                }
                num1 = (int)((double)num2 + (double)forwardSign * (double)num2);
            }
            else if (simpleTest)
            {
                Limit limit;
                if (!this.screenSpaceLimits.TryGetValue(key, out limit))
                {
                    return(nearestTriles);
                }
                int num2 = flag2 ? limit.End : limit.Start;
                if (flag1)
                {
                    emplacement.Z = num2;
                }
                else
                {
                    emplacement.X = num2;
                }
                num1 = flag2 ? limit.Start : limit.End;
                if (flag2)
                {
                    forwardSign *= -1;
                }
            }
            else
            {
                Limit limit1;
                bool  flag3 = this.screenSpaceLimits.TryGetValue(key, out limit1);
                int   num2  = (double)FezMath.Frac(screenSpacePosition.X) > 0.5 ? 1 : -1;
                int   num3  = (double)FezMath.Frac(screenSpacePosition.Y) > 0.5 ? 1 : -1;
                key.X += num2;
                Limit limit2;
                bool  flag4 = this.screenSpaceLimits.TryGetValue(key, out limit2);
                key.X -= num2;
                key.Y += num3;
                Limit limit3;
                bool  flag5 = this.screenSpaceLimits.TryGetValue(key, out limit3);
                if (!flag3 && !flag5 && !flag4)
                {
                    return(nearestTriles);
                }
                Limit limit4;
                if (flag3)
                {
                    limit4 = limit1;
                    if (!flag4 && !flag5)
                    {
                        simpleTest = true;
                    }
                }
                else
                {
                    limit4.Start    = forwardSign == 1 ? int.MaxValue : int.MinValue;
                    limit4.End      = forwardSign == 1 ? int.MinValue : int.MaxValue;
                    limit4.NoOffset = true;
                }
                if (flag4)
                {
                    limit4.Start = forwardSign == 1 ? Math.Min(limit4.Start, limit2.Start) : Math.Max(limit4.Start, limit2.Start);
                    limit4.End   = forwardSign == 1 ? Math.Max(limit4.End, limit2.End) : Math.Min(limit4.End, limit2.End);
                }
                if (flag5)
                {
                    limit4.Start = forwardSign == 1 ? Math.Min(limit4.Start, limit3.Start) : Math.Max(limit4.Start, limit3.Start);
                    limit4.End   = forwardSign == 1 ? Math.Max(limit4.End, limit3.End) : Math.Min(limit4.End, limit3.End);
                }
                int num4 = flag2 ? limit4.End : limit4.Start;
                if (flag1)
                {
                    emplacement.Z = num4;
                }
                else
                {
                    emplacement.X = num4;
                }
                num1 = flag2 ? limit4.Start : limit4.End;
                if (flag2)
                {
                    forwardSign *= -1;
                }
            }
            int  num5  = num1 + forwardSign;
            bool flag6 = flag1 ? emplacement.Z != num5 : emplacement.X != num5;

            if (flag1)
            {
                for (; flag6; flag6 = emplacement.Z != num5)
                {
                    LevelManager.QueryResult nearestQueryResult;
                    TrileInstance            trileInstance = this.OffsetInstanceAt(ref emplacement, ref screenSpacePosition, true, forwardSign, true, false, simpleTest, options, out nearestQueryResult);
                    if (trileInstance != null)
                    {
                        if (nearestQueryResult == LevelManager.QueryResult.Full)
                        {
                            nearestTriles.Deep = trileInstance;
                            break;
                        }
                        else if (nearestTriles.Surface == null)
                        {
                            nearestTriles.Surface = trileInstance;
                        }
                    }
                    emplacement.Z += forwardSign;
                }
            }
            else
            {
                for (; flag6; flag6 = emplacement.X != num5)
                {
                    LevelManager.QueryResult nearestQueryResult;
                    TrileInstance            trileInstance = this.OffsetInstanceAt(ref emplacement, ref screenSpacePosition, false, forwardSign, true, false, simpleTest, options, out nearestQueryResult);
                    if (trileInstance != null)
                    {
                        if (nearestQueryResult == LevelManager.QueryResult.Full)
                        {
                            nearestTriles.Deep = trileInstance;
                            break;
                        }
                        else if (nearestTriles.Surface == null)
                        {
                            nearestTriles.Surface = trileInstance;
                        }
                    }
                    emplacement.X += forwardSign;
                }
            }
            return(nearestTriles);
        }
示例#5
0
        private TrileInstance OffsetInstanceAt(ref TrileEmplacement emplacement, ref Vector3 screenSpacePosition, bool depthIsZ, int forwardSign, bool useSelector, bool keepNearest, bool simpleTest, QueryOptions context, out LevelManager.QueryResult nearestQueryResult)
        {
            LevelManager.QueryResult queryResult = LevelManager.QueryResult.Nothing;
            TrileInstance            instance1;

            if (this.Triles.TryGetValue(emplacement, out instance1))
            {
                instance1 = this.OffsetInstanceOrOverlapsContain(instance1, screenSpacePosition, depthIsZ, forwardSign, useSelector, context, out queryResult);
            }
            if (simpleTest || instance1 != null && !keepNearest)
            {
                nearestQueryResult = queryResult;
                return(instance1);
            }
            else
            {
                TrileInstance nearest = instance1;
                nearestQueryResult = queryResult;
                bool             flag      = depthIsZ;
                int              num       = (double)FezMath.Frac(screenSpacePosition.X) > 0.5 ? 1 : -1;
                TrileEmplacement id        = flag ? emplacement.GetOffset(num, 0, 0) : emplacement.GetOffset(0, 0, num);
                TrileInstance    instance2 = this.TrileInstanceAt(ref id);
                if (instance2 != null)
                {
                    TrileInstance contender = this.OffsetInstanceOrOverlapsContain(instance2, screenSpacePosition, depthIsZ, forwardSign, useSelector, context, out queryResult);
                    if (contender != null)
                    {
                        nearestQueryResult = queryResult;
                        if (!keepNearest)
                        {
                            return(contender);
                        }
                        nearest = LevelManager.KeepNearestInstance(nearest, contender, depthIsZ, forwardSign);
                    }
                }
                int offsetY                = (double)FezMath.Frac(screenSpacePosition.Y) > 0.5 ? 1 : -1;
                TrileEmplacement offset    = emplacement.GetOffset(0, offsetY, 0);
                TrileInstance    instance3 = this.TrileInstanceAt(ref offset);
                if (instance3 != null)
                {
                    TrileInstance contender = this.OffsetInstanceOrOverlapsContain(instance3, screenSpacePosition, depthIsZ, forwardSign, useSelector, context, out queryResult);
                    if (contender != null)
                    {
                        nearestQueryResult = queryResult;
                        if (!keepNearest)
                        {
                            return(contender);
                        }
                        nearest = LevelManager.KeepNearestInstance(nearest, contender, depthIsZ, forwardSign);
                    }
                }
                offset = id.GetOffset(0, offsetY, 0);
                TrileInstance instance4 = this.TrileInstanceAt(ref offset);
                if (instance4 != null)
                {
                    TrileInstance contender = this.OffsetInstanceOrOverlapsContain(instance4, screenSpacePosition, depthIsZ, forwardSign, useSelector, context, out queryResult);
                    if (contender != null)
                    {
                        nearestQueryResult = queryResult;
                        if (!keepNearest)
                        {
                            return(contender);
                        }
                        nearest = LevelManager.KeepNearestInstance(nearest, contender, depthIsZ, forwardSign);
                    }
                }
                return(nearest);
            }
        }
示例#6
0
        private void Fly(TimeSpan elapsed)
        {
            if (!this.flyRight.HasValue)
            {
                this.flyRight = new Vector3?(Vector3.Transform(Vector3.Right, this.Group.Rotation));
            }
            if ((!this.FlyingBack || this.Npc.ActorType != ActorType.Owl) && FezMath.AlmostEqual(FezMath.Dot(FezMath.Abs(Vector3.Transform(Vector3.Right, this.Group.Rotation)), FezMath.Abs(this.flyRight.Value)), 0.0f, 0.1f))
            {
                NpcState npcState  = this;
                Vector3? nullable1 = npcState.flyRight;
                Vector3  vector3   = Vector3.Transform(Vector3.Right, this.Group.Rotation);
                Vector3? nullable2 = nullable1.HasValue ? new Vector3?(nullable1.GetValueOrDefault() + vector3) : new Vector3?();
                npcState.flyRight = nullable2;
            }
            this.flySpeed = Vector2.Lerp(this.flySpeed, new Vector2(4f, 3f), 0.03333334f);
            Vector2 vector2 = this.flySpeed * ((1f - FezMath.Frac(this.CurrentTiming.Step + 0.75f)) * new Vector2(0.4f, 0.6f) + new Vector2(0.6f, 0.4f));

            this.Position += (float)elapsed.TotalSeconds * (vector2.X * this.flyRight.Value + Vector3.Up * vector2.Y * (this.FlyingBack ? -1f : 1f));
            if (FezMath.IsOrthographic(this.CameraManager.Viewpoint) && this.CameraManager.ViewTransitionReached)
            {
                Vector3 b = FezMath.ForwardVector(this.CameraManager.Viewpoint);
                if (this.InBackground)
                {
                    b *= -1f;
                }
                NearestTriles nearestTriles = this.LevelManager.NearestTrile(this.Position, QueryOptions.Simple);
                TrileInstance trileInstance = nearestTriles.Surface ?? nearestTriles.Deep;
                if (trileInstance != null)
                {
                    Vector3 a       = trileInstance.Center + trileInstance.TransformedSize / 2f * -b;
                    Vector3 vector3 = FezMath.DepthMask(this.CameraManager.Viewpoint);
                    if ((double)FezMath.Dot(this.Position, b) > (double)FezMath.Dot(a, b))
                    {
                        this.Position = this.Position * FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint) + a * vector3 - b;
                    }
                }
            }
            if (this.CurrentTiming.Frame == 0 && this.lastFrame != 0)
            {
                SoundEffectExtensions.EmitAt(this.flySound, this.Position);
            }
            this.lastFrame = this.CurrentTiming.Frame;
            if (this.FlyingBack)
            {
                if ((double)this.Position.Y > (double)this.Npc.Position.Y)
                {
                    return;
                }
                this.Position      = this.Npc.Position;
                this.CurrentAction = NpcAction.Land;
                this.flySpeed      = Vector2.Zero;
                this.UpdateAction();
                this.FlyingBack = false;
                this.flyRight   = new Vector3?();
            }
            else
            {
                if (this.CameraManager.Frustum.Contains(new BoundingBox(this.Position - Vector3.One, this.Position + Vector3.One)) != ContainmentType.Disjoint)
                {
                    return;
                }
                if (this.MayComeBack)
                {
                    this.OwlInvisible  = true;
                    this.MayComeBack   = false;
                    this.CurrentAction = NpcAction.Idle;
                    this.flySpeed      = Vector2.Zero;
                    this.flyRight      = new Vector3?();
                    this.UpdateAction();
                }
                else
                {
                    ServiceHelper.RemoveComponent <NpcState>(this);
                }
            }
        }
示例#7
0
        public override void Update(GameTime gameTime)
        {
            if (!this.Enabled || this.EngineState.Loading || (this.EngineState.Paused || this.EngineState.InMap))
            {
                return;
            }
            double num1 = FezMath.Frac((double)this.SoundManager.PlayPosition.Ticks / (double)this.measureLength.Ticks);

            this.step = (int)Math.Floor(num1 * 16.0);
            double num2   = FezMath.Frac(num1 * 16.0);
            int    index1 = (this.step + 1) % 16;
            bool   flag   = false;

            foreach (TrileInstance index2 in this.crystals.Keys)
            {
                if (index2.ActorSettings.Sequence != null)
                {
                    Sequencer.CrystalState crystalState = this.crystals[index2];
                    bool enabled = index2.Enabled;
                    index2.Enabled = index2.ActorSettings.Sequence.Length > this.step && index2.ActorSettings.Sequence[this.step];
                    if (!enabled && index2.Enabled)
                    {
                        this.LevelManager.RestoreTrile(index2);
                        index2.Hidden  = false;
                        index2.Enabled = true;
                        if (index2.InstanceId == -1)
                        {
                            this.LevelMaterializer.CullInstanceIn(index2);
                        }
                        if (crystalState.Sample != null)
                        {
                            Vector3 position = index2.Position + new Vector3(0.5f);
                            SoundEffectExtensions.EmitAt(crystalState.Alternate[this.step] ? crystalState.AlternateSample : crystalState.Sample, position);
                        }
                        flag = true;
                    }
                    else if (enabled && !index2.Enabled)
                    {
                        this.LevelMaterializer.UnregisterViewedInstance(index2);
                        this.LevelMaterializer.CullInstanceOut(index2, true);
                        this.LevelManager.ClearTrile(index2, true);
                        this.OnDisappear(index2);
                        flag = true;
                    }
                    else if (num2 > 0.449999988079071 && index2.Enabled && (index2.ActorSettings.Sequence.Length > index1 && !index2.ActorSettings.Sequence[index1]))
                    {
                        if ((int)Math.Round((num2 - 0.449999988079071) / 0.550000011920929 * 6.0) % 3 == 0)
                        {
                            if (!index2.Hidden)
                            {
                                index2.Hidden = true;
                                this.LevelMaterializer.UnregisterViewedInstance(index2);
                                this.LevelMaterializer.CullInstanceOut(index2, true);
                                flag = true;
                            }
                        }
                        else if (index2.Hidden)
                        {
                            index2.Hidden = false;
                            if (index2.InstanceId == -1)
                            {
                                this.LevelMaterializer.CullInstanceIn(index2);
                                flag = true;
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                return;
            }
            this.LevelMaterializer.CommitBatchesIfNeeded();
        }