Example #1
0
 private void TryInitialize()
 {
     this.flashesMesh.ClearGroups();
     this.bombStates.Clear();
     this.indexedDg.Clear();
     this.destructibleGroups.Clear();
     foreach (TrileGroup trileGroup in (IEnumerable <TrileGroup>) this.LevelManager.Groups.Values)
     {
         if (trileGroup.Triles.Count != 0 && ActorTypeExtensions.IsDestructible(trileGroup.Triles[0].Trile.ActorSettings.Type) && ActorTypeExtensions.IsDestructible(trileGroup.Triles[trileGroup.Triles.Count - 1].Trile.ActorSettings.Type))
         {
             BombsHost.DestructibleGroup destructibleGroup = new BombsHost.DestructibleGroup()
             {
                 AllTriles = new List <TrileInstance>((IEnumerable <TrileInstance>)trileGroup.Triles),
                 Group     = trileGroup
             };
             this.destructibleGroups.Add(destructibleGroup);
             FaceOrientation face = FaceOrientation.Down;
             foreach (TrileInstance key in trileGroup.Triles)
             {
                 this.indexedDg.Add(key, destructibleGroup);
                 TrileEmplacement traversal = key.Emplacement.GetTraversal(ref face);
                 TrileInstance    instance  = this.LevelManager.TrileInstanceAt(ref traversal);
                 if (instance != null && !ActorTypeExtensions.IsDestructible(instance.Trile.ActorSettings.Type) && instance.PhysicsState == null)
                 {
                     instance.PhysicsState = new InstancePhysicsState(instance);
                 }
             }
         }
     }
 }
Example #2
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();
        }
Example #3
0
 private void TryInitialize()
 {
   this.flashesMesh.ClearGroups();
   this.bombStates.Clear();
   this.indexedDg.Clear();
   this.destructibleGroups.Clear();
   foreach (TrileGroup trileGroup in (IEnumerable<TrileGroup>) this.LevelManager.Groups.Values)
   {
     if (trileGroup.Triles.Count != 0 && ActorTypeExtensions.IsDestructible(trileGroup.Triles[0].Trile.ActorSettings.Type) && ActorTypeExtensions.IsDestructible(trileGroup.Triles[trileGroup.Triles.Count - 1].Trile.ActorSettings.Type))
     {
       BombsHost.DestructibleGroup destructibleGroup = new BombsHost.DestructibleGroup()
       {
         AllTriles = new List<TrileInstance>((IEnumerable<TrileInstance>) trileGroup.Triles),
         Group = trileGroup
       };
       this.destructibleGroups.Add(destructibleGroup);
       FaceOrientation face = FaceOrientation.Down;
       foreach (TrileInstance key in trileGroup.Triles)
       {
         this.indexedDg.Add(key, destructibleGroup);
         TrileEmplacement traversal = key.Emplacement.GetTraversal(ref face);
         TrileInstance instance = this.LevelManager.TrileInstanceAt(ref traversal);
         if (instance != null && !ActorTypeExtensions.IsDestructible(instance.Trile.ActorSettings.Type) && instance.PhysicsState == null)
           instance.PhysicsState = new InstancePhysicsState(instance);
       }
     }
   }
 }