Ejemplo n.º 1
0
    private void AddNoise()
    {
        int cell = Grid.PosToCell(position);
        int val  = effectExtents.x + effectExtents.width;
        int val2 = effectExtents.y + effectExtents.height;
        int x    = effectExtents.x;
        int y    = effectExtents.y;
        int x2   = 0;
        int y2   = 0;

        Grid.CellToXY(cell, out x2, out y2);
        val  = Math.Min(val, Grid.WidthInCells);
        val2 = Math.Min(val2, Grid.HeightInCells);
        x    = Math.Max(0, x);
        y    = Math.Max(0, y);
        for (int i = y; i < val2; i++)
        {
            for (int j = x; j < val; j++)
            {
                if (Grid.VisibilityTest(x2, y2, j, i, false))
                {
                    int   num       = Grid.XYToCell(j, i);
                    float dBForCell = GetDBForCell(num);
                    if (dBForCell > 0f)
                    {
                        float num2 = AudioEventManager.DBToLoudness(dBForCell);
                        Grid.Loudness[num] += num2;
                        Pair <int, float> item = new Pair <int, float>(num, num2);
                        decibels.Add(item);
                    }
                }
            }
        }
    }
        public static bool ResolvePilotInjuryCheck(Mech mech, int heatToCheck, int rootSequenceGUID, int sequenceGUID, float heatCheck)
        {
            bool failedInjuryCheck = !CheckHelper.DidCheckPassThreshold(Mod.Config.Heat.PilotInjury, heatToCheck, mech, heatCheck, ModText.FT_Check_Injury);

            Mod.Log.Debug?.Write($"  failedInjuryCheck: {failedInjuryCheck}");
            if (failedInjuryCheck)
            {
                Mod.Log.Info?.Write($"-- Pilot Heat Injury check failed for {CombatantUtils.Label(mech)}, forcing injury from heat");
                mech.pilot.InjurePilot(sequenceGUID.ToString(), rootSequenceGUID, 1, DamageType.OverheatSelf, null, mech);
                if (!mech.pilot.IsIncapacitated)
                {
                    AudioEventManager.SetPilotVOSwitch <AudioSwitch_dialog_dark_light>(AudioSwitch_dialog_dark_light.dark, mech);
                    AudioEventManager.PlayPilotVO(VOEvents.Pilot_TakeDamage, mech, null, null, true);
                    if (mech.team.LocalPlayerControlsTeam)
                    {
                        AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "friendly_warrior_injured", null, null);
                    }
                }
                else
                {
                    mech.FlagForDeath("Pilot Killed", DeathMethod.PilotKilled, DamageType.OverheatSelf, 1, sequenceGUID, "0", false);
                    string localText = new Text(Mod.LocalizedText.Floaties[ModText.FT_Death_By_Overheat]).ToString();

                    mech.Combat.MessageCenter.PublishMessage(new AddSequenceToStackMessage(
                                                                 new ShowActorInfoSequence(mech, new Text(localText, Array.Empty <object>()), FloatieMessage.MessageNature.PilotInjury, true))
                                                             );
                    mech.HandleDeath("0");
                }
            }

            return(failedInjuryCheck);
        }
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);


        foreach (Sound snd in sounds)
        {
            snd.source             = gameObject.AddComponent <AudioSource>();
            snd.source.clip        = snd.clip;
            snd.source.volume      = snd.volume;
            snd.source.pitch       = snd.pitch;
            snd.source.panStereo   = snd.pan;
            snd.source.playOnAwake = snd.onAwake;
            snd.source.loop        = snd.loop;
        }
    }
Ejemplo n.º 4
0
 void Awake()
 {
     name = "AudioEventManager";
     if (instance == null) { instance = this; }
     events = new Children<AudioEvent>(transform);
     AudioManager.instance.managers.AddChild (GetComponent<AudioEventManager>());
 }
Ejemplo n.º 5
0
 public static void PlayVFX(AIMCritInfo info)
 {
     try {
         ICombatant target = info.target;
         if (target.GameRep == null)
         {
             return;
         }
         MechComponent component = info.component;
         bool          isAmmo = component is AmmunitionBox, isJumpJet = component is Jumpjet, isHeatSink = component.componentDef is HeatSinkDef;
         if (target.team.LocalPlayerControlsTeam)
         {
             AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "critical_hit_friendly ", null, null);
         }
         else if (!target.team.IsFriendly(Combat.LocalPlayerTeam))
         {
             AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "critical_hit_enemy", null, null);
         }
         if (target.GameRep is MechRepresentation MechRep && !isJumpJet && !isHeatSink && !isAmmo && component.DamageLevel > ComponentDamageLevel.Functional)
         {
             MechRep.PlayComponentCritVFX(info.GetCritLocation());
         }
         if (isAmmo && component.DamageLevel > ComponentDamageLevel.Functional)
         {
             target.GameRep.PlayVFX(info.GetCritLocation(), Combat.Constants.VFXNames.componentDestruction_AmmoExplosion, true, Vector3.zero, true, -1f);
         }
     }                 catch (Exception ex) { Error(ex); }
 }
    public static string GetLoudestNoisePolluterAtCell(int cell)
    {
        float             num               = float.NegativeInfinity;
        string            result            = null;
        AudioEventManager audioEventManager = Get();
        Vector2I          vector2I          = Grid.CellToXY(cell);
        Vector2           pos               = new Vector2((float)vector2I.x, (float)vector2I.y);
        IEnumerator       enumerator        = audioEventManager.spatialSplats.GetAllIntersecting(pos).GetEnumerator();

        try
        {
            while (enumerator.MoveNext())
            {
                NoiseSplat noiseSplat = (NoiseSplat)enumerator.Current;
                float      loudness   = noiseSplat.GetLoudness(cell);
                if (loudness > num)
                {
                    result = noiseSplat.GetProvider().GetName();
                }
            }
            return(result);
        }
        finally
        {
            IDisposable disposable;
            if ((disposable = (enumerator as IDisposable)) != null)
            {
                disposable.Dispose();
            }
        }
    }
Ejemplo n.º 7
0
 public void PlayMessage()
 {
     AudioEventManager.InterruptPilotVOForTeam(base.Combat.LocalPlayerTeam, null);
     WwiseManager.PostEvent <AudioEventList_vo>(AudioEventList_vo.vo_stop_missions, WwiseManager.GlobalAudioObject, null, null);
     this.Play();
     this.SetState(DialogState.Finished);
 }
Ejemplo n.º 8
0
    /**
     * Monobehavior Update
     */
    void Update()
    {
        float x = Input.GetAxis("Horizontal");

        currentPitch += x * 0.1f * Time.deltaTime;

        AudioEventManager.SetRTPCValue("Music_Pitch", currentPitch);
    }
Ejemplo n.º 9
0
 void Start()
 {
     elementManager   = (AudioElementManager)managers.GetChild("AudioElementManager");
     eventManager     = (AudioEventManager)managers.GetChild("AudioEventManager");
     sendManager      = (AudioSendManager)managers.GetChild("AudioSendManager");
     energyManager    = (EnergyManager)managers.GetChild("EnergyManager");
     metronomeManager = (MetronomeManager)managers.GetChild("MetronomeManager");
 }
Ejemplo n.º 10
0
 private static void PlayInjuryMusic(this Pilot pilot)
 {
     AudioEventManager.PlayAudioEvent(
         AudioConstantsDef.MUSICTRIGGERS_COMBAT,
         pilot.ParentActor.team.LocalPlayerControlsTeam
             ? nameof(AudioTriggerList.friendly_warrior_injured)
             : nameof(AudioTriggerList.enemy_warrior_injured)
         );
 }
Ejemplo n.º 11
0
 public void SetActive(bool active = true)
 {
     if (!active && splat != null)
     {
         AudioEventManager.Get().ClearNoiseSplat(splat);
         splat.Clear();
     }
     this.active = active;
 }
Ejemplo n.º 12
0
 void Subscribe()
 {
     audio     = GameObject.Find("Music").GetComponent <AudioEventManager> ();
     this.keys = keys;
     for (var i = 0; i < keys.Length; i++)
     {
         audio.Subscribe(keys[i], this);
     }
 }
 public void Clear()
 {
     if (splat != null)
     {
         AudioEventManager.Get().ClearNoiseSplat(splat);
         splat.Clear();
         splat = null;
     }
 }
Ejemplo n.º 14
0
 void Awake()
 {
     name = "AudioEventManager";
     if (instance == null)
     {
         instance = this;
     }
     events = new Children <AudioEvent>(transform);
     AudioManager.instance.managers.AddChild(GetComponent <AudioEventManager>());
 }
 public void SetSplat(NoiseSplat new_splat)
 {
     if (new_splat == null && splat != null)
     {
         Clear();
     }
     splat = new_splat;
     if (splat != null)
     {
         AudioEventManager.Get().AddSplat(splat);
     }
 }
Ejemplo n.º 16
0
            public static bool Prefix(string defId, string eventId, AkGameObj audioObject, AkCallbackManager.EventCallback audioEventCallback, ref bool __result)
            {
                // play everything except contract_lanceconfirm because you can't launch a mission without it
                if (modSettings.EnableBarks || defId != "audioeventdef_simgame_vo_barks")
                {
                    return(true);
                }
                if (eventId == "contract_lanceconfirm" || eventId == "skirmish_lanceconfirm")
                {
                    __result = AudioEventManager.PlayAudioEvent(AudioEventManager.GetAudioEvent(defId, eventId), audioObject, audioEventCallback);
                }

                return(false);
            }
Ejemplo n.º 17
0
 public void Refresh()
 {
     if (active)
     {
         if (splat != null)
         {
             AudioEventManager.Get().ClearNoiseSplat(splat);
             splat.Clear();
         }
         KSelectable component  = GetComponent <KSelectable>();
         string      name       = (!((UnityEngine.Object)component != (UnityEngine.Object)null)) ? base.name : component.GetName();
         GameObject  gameObject = GetComponent <KMonoBehaviour>().gameObject;
         splat = AudioEventManager.Get().CreateNoiseSplat(GetPosition(), noise, radius, name, gameObject);
     }
 }
Ejemplo n.º 18
0
        public static void ReadyMech(SimGameState s, MechDef d, int baySlot)
        {
            WorkOrderEntry_ReadyMech workOrderEntry_ReadyMech = new WorkOrderEntry_ReadyMech(string.Format("ReadyMech-{0}", d.GUID), string.Format("Readying 'Mech - {0}", new object[]
            {
                d.Chassis.Description.Name
            }), s.Constants.Story.MechReadyTime, baySlot, d, string.Format(s.Constants.Story.MechReadiedWorkOrderCompletedText, new object[]
            {
                d.Chassis.Description.Name
            }));

            s.MechLabQueue.Add(workOrderEntry_ReadyMech);
            s.ReadyingMechs[baySlot] = d;
            s.RoomManager.AddWorkQueueEntry(workOrderEntry_ReadyMech);
            s.UpdateMechLabWorkQueue(false);
            AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", "workqueue_readymech", WwiseManager.GlobalAudioObject, null);
        }
Ejemplo n.º 19
0
            public static void Prefix(AbstractActor __instance)
            {
                try
                {
                    //Logger.Info($"[AbstractActor_OnActivationEnd_PREFIX] {__instance.DisplayName}");

                    foreach (Weapon weapon in __instance.Weapons)
                    {
                        if (IsUltraAutocannon(weapon))
                        {
                            // Already jammed
                            if (IsJammed(weapon))
                            {
                                Logger.Info($"[AbstractActor_OnActivationEnd_PREFIX] {weapon.Name} is jammed");
                            }
                            // Fired this round
                            else if (weapon.roundsSinceLastFire == 0)
                            {
                                Logger.Info($"[AbstractActor_OnActivationEnd_PREFIX] {weapon.Name} was fired this round");
                                Logger.Info($"[AbstractActor_OnActivationEnd_PREFIX] {weapon.Name} is checked for a potential jam");

                                float jammingChance = jammingChanceBase;
                                float jammingRoll   = UnityEngine.Random.Range(0f, 1f);
                                Logger.Info($"[AbstractActor_OnActivationEnd_PREFIX] Rolled {jammingRoll} against {jammingChance}");

                                if (jammingRoll <= jammingChance)
                                {
                                    Logger.Info($"[AbstractActor_OnActivationEnd_PREFIX] {weapon.Name} got jammed");

                                    weapon.StatCollection.Set <bool>("Jammed", true);
                                    weapon.StatCollection.Set <bool>("TemporarilyDisabled", true);

                                    __instance.Combat.MessageCenter.PublishMessage(new FloatieMessage(__instance.GUID, __instance.GUID, "UAC JAMMED", FloatieMessage.MessageNature.Debuff));

                                    AudioEventManager.SetPilotVOSwitch <AudioSwitch_dialog_dark_light>(AudioSwitch_dialog_dark_light.dark, __instance);
                                    AudioEventManager.PlayPilotVO(VOEvents.TakeDamage_WeaponLost, __instance, null, null, true);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
Ejemplo n.º 20
0
 public override void OnAdded()
 {
     base.OnAdded();
     if (this.OwningMech.GameRep != null)
     {
         string text = string.Format("MechOverheatSequence_{0}_{1}", base.RootSequenceGUID, base.SequenceGUID);
         AudioEventManager.CreateVOQueue(text, -1f, null, null);
         AudioEventManager.QueueVOEvent(text, VOEvents.Mech_Overheat_Shutdown, this.OwningMech);
         AudioEventManager.StartVOQueue(1f);
         this.OwningMech.GameRep.PlayVFX(1, this.OwningMech.Combat.Constants.VFXNames.heat_heatShutdown, true, Vector3.zero, false, -1f);
         this.AddChildSequence(new ShowActorInfoSequence(this.OwningMech, "Emergency Shutdown Initiated!", FloatieMessage.MessageNature.Debuff, true), this.ChildSequenceCount - 1);
         WwiseManager.PostEvent <AudioEventList_ui>(AudioEventList_ui.ui_overheat_alarm_3, WwiseManager.GlobalAudioObject, null, null);
         if (this.OwningMech.team.LocalPlayerControlsTeam)
         {
             AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "friendly_overheating", null, null);
         }
     }
 }
Ejemplo n.º 21
0
    /**
     * Called when the object is loaded
     */
    void Awake()
    {
        if (UnityAudioState)
        {
            DisplayLogMessage("AudioEventManager : Unity Audio Initialization");
            InitializeUnityAudio();
            DisplayLogMessage("AudioEventManager : Unity Audio Initialized");
        }

        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            DestroyImmediate(gameObject);
        }
    }
        public static void ReadyMech(SimGameState s, MechDef d, int baySlot, bool donotoverridetime = false)
        {
            int mechReadyTime = s.Constants.Story.MechReadyTime;

            if (Settings.AssembledMechsReadyingFlatCost > 0 && !donotoverridetime)
            {
                mechReadyTime = Settings.AssembledMechsReadyingFlatCost + Settings.AssembledMechsReadyingPerNonFixedComponentCost * d.Inventory.Where((a) => !a.IsFixed).Count();
            }
            WorkOrderEntry_ReadyMech workOrderEntry_ReadyMech = new WorkOrderEntry_ReadyMech(string.Format("ReadyMech-{0}", d.GUID), $"Readying {d.GetMechOmniVehicle()} - {d.Chassis.Description.Name}",
                                                                                             mechReadyTime, baySlot, d, string.Format(s.Constants.Story.MechReadiedWorkOrderCompletedText, new object[]
            {
                d.Chassis.Description.Name
            }));

            s.MechLabQueue.Add(workOrderEntry_ReadyMech);
            s.ReadyingMechs[baySlot] = d;
            s.RoomManager.AddWorkQueueEntry(workOrderEntry_ReadyMech);
            s.UpdateMechLabWorkQueue(false);
            AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", "workqueue_readymech", WwiseManager.GlobalAudioObject, null);
            s.CompanyStats.ModifyStat("Mission", 0, "COMPANY_MechsAdded", StatCollection.StatOperation.Int_Add, 1, -1, true);
        }
        private static void AddBullsharkLT(SimGameState s)
        {
            MechDef d = s.DataManager.MechDefs.Get("mechdef_bullshark_BSK-LT");

            d = new MechDef(d, s.GenerateSimGameUID(), true);
            d.SetInventory(d.Inventory.Where((x) => x.IsFixed || x.ComponentDefID.Equals("Ammo_AmmunitionBox_Generic_LongTom")).ToArray());
            int baySlot       = s.GetFirstFreeMechBay();
            int mechReadyTime = 625000; // about 50 days
            WorkOrderEntry_ReadyMech workOrderEntry_ReadyMech = new WorkOrderEntry_ReadyMech(string.Format("ReadyMech-{0}", d.GUID), string.Format("Readying 'Mech - {0}", new object[]
            {
                d.Chassis.Description.Name
            }), mechReadyTime, baySlot, d, string.Format(s.Constants.Story.MechReadiedWorkOrderCompletedText, new object[]
            {
                d.Chassis.Description.Name
            }));

            s.MechLabQueue.Add(workOrderEntry_ReadyMech);
            s.ReadyingMechs[baySlot] = d;
            s.RoomManager.AddWorkQueueEntry(workOrderEntry_ReadyMech);
            s.UpdateMechLabWorkQueue(false);
            AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", "workqueue_readymech", WwiseManager.GlobalAudioObject, null);
        }
Ejemplo n.º 24
0
        // Prevent the debuff floatie
        public override void OnAdded()
        {
            base.OnAdded();
            if (this.OwningMech.GameRep != null)
            {
                Mod.Log.Info?.Write("Sending floatie notification.");

                string text = string.Format("MechOverheatSequence_{0}_{1}", base.RootSequenceGUID, base.SequenceGUID);

                AudioEventManager.CreateVOQueue(text, -1f, null, null);
                AudioEventManager.QueueVOEvent(text, VOEvents.Mech_Overheat_Shutdown, this.OwningMech);
                AudioEventManager.StartVOQueue(1f);

                this.OwningMech.GameRep.PlayVFX(8, this.OwningMech.Combat.Constants.VFXNames.heat_heatShutdown, true, Vector3.zero, false, -1f);

                WwiseManager.PostEvent <AudioEventList_ui>(AudioEventList_ui.ui_overheat_alarm_3, WwiseManager.GlobalAudioObject, null, null);
                if (this.OwningMech.team.LocalPlayerControlsTeam)
                {
                    AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "friendly_overheating", null, null);
                }
            }
        }
 public static AudioEventManager Get()
 {
     if ((UnityEngine.Object)instance == (UnityEngine.Object)null)
     {
         if (App.IsExiting)
         {
             return(null);
         }
         GameObject gameObject = GameObject.Find("/AudioEventManager");
         if ((UnityEngine.Object)gameObject == (UnityEngine.Object)null)
         {
             gameObject      = new GameObject();
             gameObject.name = "AudioEventManager";
         }
         instance = gameObject.GetComponent <AudioEventManager>();
         if ((UnityEngine.Object)instance == (UnityEngine.Object)null)
         {
             instance = gameObject.AddComponent <AudioEventManager>();
         }
     }
     return(instance);
 }
Ejemplo n.º 26
0
 protected override void OnCleanUp()
 {
     base.OnCleanUp();
     if (base.isSpawned)
     {
         if (dB != null)
         {
             AttributeInstance attributeInstance = dB;
             attributeInstance.OnDirty = (System.Action)Delegate.Remove(attributeInstance.OnDirty, refreshCallback);
             AttributeInstance attributeInstance2 = dBRadius;
             attributeInstance2.OnDirty = (System.Action)Delegate.Remove(attributeInstance2.OnDirty, refreshCallback);
         }
         if (isMovable)
         {
             Singleton <CellChangeMonitor> .Instance.UnregisterCellChangedHandler(base.transform, OnCellChange);
         }
     }
     if (splat != null)
     {
         AudioEventManager.Get().ClearNoiseSplat(splat);
         splat.Clear();
     }
 }
Ejemplo n.º 27
0
        private static void OnBuyItem(int num)
        {
            var selected = ShopHelper.selectedController;
            var shop_def = selected.shopDefItem;

            Control.LogDebug(DInfo.ShopActions, $"-- {num}x{shop_def.ID}");

            if (selected == null)
            {
                Control.LogError("OnBuyItem null item, cancel");
                return;
            }
            var id = selected.GetId();

            if (!shop_def.IsInfinite && num > selected.quantity)
            {
                Control.LogDebug(DInfo.ShopActions, $"--- {num} > {selected.quantity}, adjucting");
                num = selected.quantity;
            }


            if (BuyItem(shop_def, num))
            {
                Control.LogDebug(DInfo.ShopActions, $"--- refresh shop");
                if (!shop_def.IsInfinite)
                {
                    if (num < selected.quantity)
                    {
                        Control.LogDebug(DInfo.ShopActions, $"---- {num} < {selected.quantity} - reducing");
                        selected.ModifyQuantity(-num);
                    }
                    else
                    {
                        Control.LogDebug(DInfo.ShopActions, $"--- {num} >= {selected.quantity} - removing");
                        selected.quantity = 1;
                        ShopHelper.inventoryWidget.RemoveDataItem(selected);
                        selected.Pool();
                        ShopHelper.selectedController = null;
                    }
                }

                Control.LogDebug(DInfo.ShopActions, $"--- PlayVO");
                if (ShopHelper.canPlayVO)
                {
                    ShopHelper.canPlayVO = false;
                    ShopItemType type = shop_def.Type;
                    string       text;
                    if (type != ShopItemType.Weapon)
                    {
                        if (type == ShopItemType.Mech)
                        {
                            text = "store_newmechs";
                        }
                        else
                        {
                            text = "store_newequipment";
                        }
                    }
                    else
                    {
                        text = "store_newweapons";
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", text, WwiseManager.GlobalAudioObject, null);
                    }
                    ShopScreen.StartCoroutine(PurchaseVOCooldown(5f));
                }
            }

            ShopHelper.inventoryWidget.RefreshInventoryList();

            ShopScreen.UpdateMoneySpot();
            ShopScreen.RefreshAllMoneyListings();
            if (shop_def.Type == ShopItemType.MechPart)
            {
                ShopScreen.OnItemSelected(ShopHelper.inventoryWidget.GetSelectedViewItem());
            }
            ShopHelper.triggerIronManAutoSave = true;
        }
Ejemplo n.º 28
0
 /**
  * Monobehavior Start
  */
 void Start()
 {
     AudioEventManager.PostEvent("Music_Play");
     StartCoroutine("MusicDelayer");
 }
Ejemplo n.º 29
0
    /**
     * Stops the music after 10 seconds
     */
    private IEnumerator MusicDelayer()
    {
        yield return(new WaitForSeconds(120.0f));

        AudioEventManager.PostEvent("Music_Stop");
    }
Ejemplo n.º 30
0
            public static bool Prefix(MechHeatSequence __instance, HeatSequenceState newState)
            {
                if (newState != HeatSequenceState.Finished)
                {
                    return(true);
                }

                Traverse          stateT       = Traverse.Create(__instance).Field("state");
                HeatSequenceState currentState = (HeatSequenceState)stateT.GetValue <int>();

                if (currentState == newState)
                {
                    return(true);
                }

                Mod.Log.Info($"MHS - executing updated logic for state: {newState} on actor:{__instance.OwningMech.DisplayName}_{__instance.OwningMech.GetPilot().Name}.");
                stateT.SetValue((int)newState);

                Traverse timeInCurrentStateT = Traverse.Create(__instance).Field("timeInCurrentState");

                timeInCurrentStateT.SetValue(0f);

                /* Finished Can be invoked from a rising state (heat being added):
                 *  Attack Sequence, artillery sequence, actor burning effect, (heatSinkStep=false, applyStartupHeatSinks=false)
                 *  On End of turn sequence - (heatSinkStep=true, applyStartupHeatSinks=false)
                 *  On Mech Startup sequence - (heatSinkStep=true, applyStartupHeatSinks=true)
                 */

                if (!__instance.PerformHeatSinkStep)
                {
                    Mod.Log.Debug($"Reconciling heat for actor: {CombatantUtils.Label(__instance.OwningMech)}");
                    Mod.Log.Debug($"  Before - currentHeat: {__instance.OwningMech.CurrentHeat}  tempHeat: {__instance.OwningMech.TempHeat}  " +
                                  $"isPastMaxHeat: {__instance.OwningMech.IsPastMaxHeat}  hasAppliedHeatSinks: {__instance.OwningMech.HasAppliedHeatSinks}");
                    // Checks for heat damage, clamps heat to max and min
                    __instance.OwningMech.ReconcileHeat(__instance.RootSequenceGUID, __instance.InstigatorID);
                    Mod.Log.Debug($"  After - currentHeat: {__instance.OwningMech.CurrentHeat}  tempHeat: {__instance.OwningMech.TempHeat}  " +
                                  $"isPastMaxHeat: {__instance.OwningMech.IsPastMaxHeat}  hasAppliedHeatSinks: {__instance.OwningMech.HasAppliedHeatSinks}");
                }

                //if (__instance.OwningMech.IsPastMaxHeat && !__instance.OwningMech.IsShutDown) {
                //    __instance.OwningMech.GenerateOverheatedSequence(__instance);
                //    return;
                //}

                if (__instance.PerformHeatSinkStep && !__instance.ApplyStartupHeatSinks)
                {
                    // We are at the end of the turn - force an overheat
                    Mod.Log.Info("AT END OF TURN - CHECKING EFFECTS");

                    MultiSequence sequence = new MultiSequence(__instance.OwningMech.Combat);

                    // Possible sequences
                    //  Shutdown
                    //  Fall from shutdown
                    //  Ammo Explosion
                    //  System damage
                    //  Pilot injury
                    //  Pilot death

                    float heatCheck  = __instance.OwningMech.HeatCheckMod(Mod.Config.Piloting.SkillMulti);
                    float pilotCheck = __instance.OwningMech.PilotCheckMod(Mod.Config.Piloting.SkillMulti);
                    Mod.Log.Debug($" Actor: {CombatantUtils.Label(__instance.OwningMech)} has gutsMulti: {heatCheck}  pilotingMulti: {pilotCheck}");

                    // Resolve Pilot Injury
                    bool failedInjuryCheck = !CheckHelper.DidCheckPassThreshold(Mod.Config.Heat.PilotInjury, __instance.OwningMech.CurrentHeat, __instance.OwningMech, heatCheck, ModConfig.FT_Check_Injury);
                    Mod.Log.Debug($"  failedInjuryCheck: {failedInjuryCheck}");
                    if (failedInjuryCheck)
                    {
                        Mod.Log.Debug("-- Pilot Injury check failed, forcing injury from heat");
                        __instance.OwningMech.pilot.InjurePilot(__instance.SequenceGUID.ToString(), __instance.RootSequenceGUID, 1, DamageType.OverheatSelf, null, __instance.OwningMech);
                        if (!__instance.OwningMech.pilot.IsIncapacitated)
                        {
                            AudioEventManager.SetPilotVOSwitch <AudioSwitch_dialog_dark_light>(AudioSwitch_dialog_dark_light.dark, __instance.OwningMech);
                            AudioEventManager.PlayPilotVO(VOEvents.Pilot_TakeDamage, __instance.OwningMech, null, null, true);
                            if (__instance.OwningMech.team.LocalPlayerControlsTeam)
                            {
                                AudioEventManager.PlayAudioEvent("audioeventdef_musictriggers_combat", "friendly_warrior_injured", null, null);
                            }
                        }
                    }

                    // Resolve System Damage
                    bool failedSystemFailureCheck = !CheckHelper.DidCheckPassThreshold(Mod.Config.Heat.SystemFailures, __instance.OwningMech.CurrentHeat, __instance.OwningMech, heatCheck, ModConfig.FT_Check_System_Failure);
                    Mod.Log.Debug($"  failedSystemFailureCheck: {failedSystemFailureCheck}");
                    if (failedSystemFailureCheck)
                    {
                        Mod.Log.Debug("-- System Failure check failed, forcing system damage");
                        List <MechComponent> functionalComponents = __instance.OwningMech.allComponents.Where(mc => mc.IsFunctional).ToList();
                        MechComponent        componentToDamage    = functionalComponents.GetRandomElement();
                        Mod.Log.Debug($" Destroying component: {componentToDamage.UIName} from heat damage.");

                        WeaponHitInfo fakeHit = new WeaponHitInfo(__instance.RootSequenceGUID, -1, -1, -1, string.Empty, string.Empty, -1, null, null, null, null, null, null, null,
                                                                  new AttackDirection[] { AttackDirection.None }, null, null, null);
                        componentToDamage.DamageComponent(fakeHit, ComponentDamageLevel.Destroyed, true);
                    }

                    // Resolve Ammo Explosion - regular ammo
                    bool          failedAmmoCheck = false;
                    AmmunitionBox mostDamaging    = HeatHelper.FindMostDamagingAmmoBox(__instance.OwningMech, false);
                    if (mostDamaging != null)
                    {
                        failedAmmoCheck = !CheckHelper.DidCheckPassThreshold(Mod.Config.Heat.Explosion, __instance.OwningMech.CurrentHeat, __instance.OwningMech, heatCheck, ModConfig.FT_Check_Explosion);
                        Mod.Log.Debug($"  failedAmmoCheck: {failedAmmoCheck}");
                        if (failedAmmoCheck)
                        {
                            Mod.Log.Debug("-- Ammo Explosion check failed, forcing ammo explosion");

                            if (mostDamaging != null)
                            {
                                Mod.Log.Debug($" Exploding ammo: {mostDamaging.UIName}");
                                WeaponHitInfo fakeHit = new WeaponHitInfo(__instance.RootSequenceGUID, -1, -1, -1, string.Empty, string.Empty, -1, null, null, null, null, null, null, null,
                                                                          new AttackDirection[] { AttackDirection.None }, null, null, null);
                                mostDamaging.DamageComponent(fakeHit, ComponentDamageLevel.Destroyed, true);
                            }
                            else
                            {
                                Mod.Log.Debug(" Unit has no ammo boxes, skipping.");
                            }
                        }
                    }

                    // Resolve Ammo Explosion - inferno ammo
                    bool          failedVolatileAmmoCheck = false;
                    AmmunitionBox mostDamagingVolatile    = HeatHelper.FindMostDamagingAmmoBox(__instance.OwningMech, true);
                    if (mostDamagingVolatile != null)
                    {
                        failedVolatileAmmoCheck = !CheckHelper.DidCheckPassThreshold(Mod.Config.Heat.Explosion, __instance.OwningMech.CurrentHeat, __instance.OwningMech, heatCheck, ModConfig.FT_Check_Explosion);
                        Mod.Log.Debug($"  failedVolatileAmmoCheck: {failedVolatileAmmoCheck}");
                        if (failedVolatileAmmoCheck)
                        {
                            Mod.Log.Debug("-- Volatile Ammo Explosion check failed, forcing volatile ammo explosion");

                            if (mostDamaging != null)
                            {
                                Mod.Log.Debug($" Exploding inferno ammo: {mostDamagingVolatile.UIName}");
                                WeaponHitInfo fakeHit = new WeaponHitInfo(__instance.RootSequenceGUID, -1, -1, -1, string.Empty, string.Empty, -1, null, null, null, null, null, null, null,
                                                                          new AttackDirection[] { AttackDirection.None }, null, null, null);
                                mostDamagingVolatile.DamageComponent(fakeHit, ComponentDamageLevel.Destroyed, true);
                            }
                            else
                            {
                                Mod.Log.Debug(" Unit has no inferno ammo boxes, skipping.");
                            }
                        }
                    }

                    bool failedShutdownCheck = false;
                    if (!__instance.OwningMech.IsShutDown)
                    {
                        // Resolve Shutdown + Fall
                        failedShutdownCheck = !CheckHelper.DidCheckPassThreshold(Mod.Config.Heat.Shutdown, __instance.OwningMech.CurrentHeat, __instance.OwningMech, heatCheck, ModConfig.FT_Check_Shutdown);
                        Mod.Log.Debug($"  failedShutdownCheck: {failedShutdownCheck}");
                        if (failedShutdownCheck)
                        {
                            Mod.Log.Debug("-- Shutdown check failed, forcing unit to shutdown");

                            string debuffText = new Text(Mod.Config.LocalizedFloaties[ModConfig.FT_Shutdown_Failed_Overide]).ToString();
                            sequence.AddChildSequence(new ShowActorInfoSequence(__instance.OwningMech, debuffText,
                                                                                FloatieMessage.MessageNature.Debuff, true), sequence.ChildSequenceCount - 1);

                            MechEmergencyShutdownSequence mechShutdownSequence = new MechEmergencyShutdownSequence(__instance.OwningMech)
                            {
                                RootSequenceGUID = __instance.SequenceGUID
                            };
                            sequence.AddChildSequence(mechShutdownSequence, sequence.ChildSequenceCount - 1);

                            if (__instance.OwningMech.IsOrWillBeProne)
                            {
                                bool failedFallingCheck = !CheckHelper.DidCheckPassThreshold(Mod.Config.Heat.ShutdownFallThreshold, __instance.OwningMech, pilotCheck, ModConfig.FT_Check_Fall);
                                Mod.Log.Debug($"  failedFallingCheck: {failedFallingCheck}");
                                if (failedFallingCheck)
                                {
                                    Mod.Log.Info("Pilot check from shutdown failed! Forcing a fall!");

                                    string fallDebuffText = new Text(Mod.Config.LocalizedFloaties[ModConfig.FT_Shutdown_Fall]).ToString();
                                    sequence.AddChildSequence(new ShowActorInfoSequence(__instance.OwningMech, fallDebuffText,
                                                                                        FloatieMessage.MessageNature.Debuff, true), sequence.ChildSequenceCount - 1);

                                    MechFallSequence mfs = new MechFallSequence(__instance.OwningMech, "Overheat", new Vector2(0f, -1f))
                                    {
                                        RootSequenceGUID = __instance.SequenceGUID
                                    };
                                    sequence.AddChildSequence(mfs, sequence.ChildSequenceCount - 1);
                                }
                                else
                                {
                                    Mod.Log.Info($"Pilot check to avoid falling passed.");
                                }
                            }
                            else
                            {
                                Mod.Log.Debug("Unit is already prone, skipping.");
                            }
                        }
                    }
                    else
                    {
                        Mod.Log.Debug("Unit is already shutdown, skipping.");
                    }

                    if (failedInjuryCheck || failedSystemFailureCheck || failedAmmoCheck || failedShutdownCheck)
                    {
                        __instance.OwningMech.Combat.MessageCenter.PublishMessage(new AddSequenceToStackMessage(sequence));
                    }

                    return(false);
                }

                if (__instance.OwningMech.GameRep != null)
                {
                    if (__instance.OwningMech.team.LocalPlayerControlsTeam)
                    {
                        if (__instance.OwningMech.CurrentHeat > __instance.OwningMech.OverheatLevel)
                        {
                            string text = string.Format("MechHeatSequence_{0}_{1}", __instance.RootSequenceGUID, __instance.SequenceGUID);
                            AudioEventManager.CreateVOQueue(text, -1f, null, null);
                            AudioEventManager.QueueVOEvent(text, VOEvents.Mech_Overheat_Warning, __instance.OwningMech);
                            AudioEventManager.StartVOQueue(1f);
                        }

                        if ((float)__instance.OwningMech.CurrentHeat > (float)__instance.OwningMech.MaxHeat - (float)(__instance.OwningMech.MaxHeat - __instance.OwningMech.OverheatLevel) * 0.333f)
                        {
                            WwiseManager.PostEvent <AudioEventList_ui>(AudioEventList_ui.ui_overheat_alarm_3, WwiseManager.GlobalAudioObject, null, null);
                        }
                        else if ((float)__instance.OwningMech.CurrentHeat > (float)__instance.OwningMech.MaxHeat - (float)(__instance.OwningMech.MaxHeat - __instance.OwningMech.OverheatLevel) * 0.666f)
                        {
                            WwiseManager.PostEvent <AudioEventList_ui>(AudioEventList_ui.ui_overheat_alarm_2, WwiseManager.GlobalAudioObject, null, null);
                        }
                        else if (__instance.OwningMech.CurrentHeat > __instance.OwningMech.OverheatLevel)
                        {
                            WwiseManager.PostEvent <AudioEventList_ui>(AudioEventList_ui.ui_overheat_alarm_1, WwiseManager.GlobalAudioObject, null, null);
                        }
                    }

                    if (__instance.OwningMech.CurrentHeat > Mod.Config.Heat.ShowLowOverheatAnim)
                    {
                        __instance.OwningMech.GameRep.StopManualPersistentVFX(__instance.OwningMech.Combat.Constants.VFXNames.heat_midHeat_persistent);
                        __instance.OwningMech.GameRep.PlayVFX(8, __instance.OwningMech.Combat.Constants.VFXNames.heat_highHeat_persistent, true, Vector3.zero, false, -1f);
                        return(false);
                    }

                    if ((float)__instance.OwningMech.CurrentHeat > Mod.Config.Heat.ShowExtremeOverheatAnim)
                    {
                        __instance.OwningMech.GameRep.StopManualPersistentVFX(__instance.OwningMech.Combat.Constants.VFXNames.heat_highHeat_persistent);
                        __instance.OwningMech.GameRep.PlayVFX(8, __instance.OwningMech.Combat.Constants.VFXNames.heat_midHeat_persistent, true, Vector3.zero, false, -1f);
                        return(false);
                    }

                    __instance.OwningMech.GameRep.StopManualPersistentVFX(__instance.OwningMech.Combat.Constants.VFXNames.heat_highHeat_persistent);
                    __instance.OwningMech.GameRep.StopManualPersistentVFX(__instance.OwningMech.Combat.Constants.VFXNames.heat_midHeat_persistent);
                }

                return(false);
            }
    /**
     * Called to draw the custom inspector
     */
    public override void OnInspectorGUI()
    {
        AudioEventManager manager = (AudioEventManager)target;

#if UNITY_EDITOR
        // Gets the audio settings from the unity project settings folder
        Object             audioSettings      = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/AudioManager.asset")[0];
        SerializedObject   serializedSettings = new SerializedObject(audioSettings);
        SerializedProperty disableProperty    = serializedSettings.FindProperty("m_DisableAudio");

        bool bUpdated = false;
        if (manager.UnityAudioState)
        {
            if (disableProperty.boolValue)
            {
                bUpdated = true;
                disableProperty.boolValue = false;
            }
        }
        else
        {
            if (!disableProperty.boolValue)
            {
                bUpdated = true;
                disableProperty.boolValue = true;
            }
        }

        if (bUpdated)
        {
            serializedSettings.ApplyModifiedProperties();
        }
#endif

        EditorGUILayout.HelpBox(
            "If you check this checkbox, it will disable Wwise and enable " +
            "Unity audio from the project settings. It will also add an" +
            "Audio Listener to this game object. All calls to Wwise will " +
            "be nullified and replaced by a call to the audio event manager. " +
            "In the case of a RTPC event, your callbacks will be called. But " +
            "you still have to remove the Wwise folder (the one in the assets " +
            "folder) for the time of the build. Once you have built your game " +
            "you can put the wwise folder back into your assets folder.",
            MessageType.Warning);

        manager.Verbose = EditorGUILayout.Toggle(new GUIContent("Verbose"), manager.Verbose);

        if (!Application.isPlaying)
        {
            manager.UnityAudioState = EditorGUILayout.Toggle(new GUIContent("Use Unity Audio"), manager.UnityAudioState);
        }
        else
        {
            if (manager.UnityAudioState)
            {
                DrawDefaultInspector();
            }
        }

        // Fixup for unexpected serialization problems
        EditorUtility.SetDirty(manager);
    }