static bool Prefix(Contract __instance)
        {
            string shouldDisablePilotDeath = MissionControl.Instance.GetGameLogicData(DisablePilotDeathGameLogic.DISABLE_PILOT_DEATH);

            if (UnityGameInstance.BattleTechGame.Combat != null)
            {
                if (shouldDisablePilotDeath != null && shouldDisablePilotDeath == "true")
                {
                    Main.LogDebug($"[ContractFinalizeKilledMechwarriorsPatch.Prefix] DisablePilotDeathGameLogic - Preventing pilot death.");

                    foreach (UnitResult playerUnitResult in __instance.PlayerUnitResults)
                    {
                        Pilot    pilot    = playerUnitResult.pilot;
                        PilotDef pilotDef = pilot.pilotDef;
                        pilotDef?.SetRecentInjuryDamageType(DamageType.NOT_SET);
                    }

                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        public static bool Prefix(Contract __instance, SimGameState sim)
        {
            Traverse.Create(__instance).Method("PushReport", new Type[] { typeof(string) }).GetValue("MechWarriorFinalizeKill");
            foreach (UnitResult unitResult in __instance.PlayerUnitResults)
            {
                Pilot    pilot    = unitResult.pilot;
                PilotDef pilotDef = pilot.pilotDef;
                if (!unitResult.pilot.IsIncapacitated || unitResult.pilot.pilotDef.IsImmortal)
                {
                    if (pilotDef != null)
                    {
                        pilotDef.SetRecentInjuryDamageType(DamageType.NOT_SET);
                    }
                }
                else
                {
                    var lethalDeathChance        = sim.Constants.Pilot.LethalDeathChance;
                    var incapacitatedDeathChance = sim.Constants.Pilot.IncapacitatedDeathChance;
                    foreach (var upgrade in sim.ShipUpgrades)
                    {
                        foreach (var foo in upgrade.Stats)
                        {
                            if (foo.name == "IncapacitatedDeathChance")
                            {
                                incapacitatedDeathChance += float.Parse(foo.value);
                            }
                            if (foo.name == "LethalDeathChance")
                            {
                                lethalDeathChance += float.Parse(foo.value);
                            }
                        }
                    }
                    incapacitatedDeathChance = Mathf.Max(0, incapacitatedDeathChance);
                    lethalDeathChance        = Mathf.Max(0, lethalDeathChance);

                    float num = pilot.LethalInjuries ? lethalDeathChance : incapacitatedDeathChance;
                    if (pilot.LethalInjuries)
                    {
                        num = Mathf.Max(0f, num);
                    }
                    else
                    {
                        num = Mathf.Max(0f, num - sim.Constants.Pilot.GutsDeathReduction * (float)pilot.Guts);
                    }

                    float  num2 = sim.NetworkRandom.Float(0f, 1f);
                    string s    = string.Format("Pilot {0} needs to roll above {1} to survive. They roll {2} resulting in {3}", new object[]
                    {
                        pilot.Name,
                        num,
                        num2,
                        (num2 < num) ? "DEATH" : "LIFE"
                    });
                    Traverse.Create(__instance).Method("ReportLog", new Type[] { typeof(string) }).GetValue("s");

                    if (num2 < num)
                    {
                        __instance.KilledPilots.Add(pilot);
                    }
                    else if (pilotDef != null)
                    {
                        pilotDef.SetRecentInjuryDamageType(DamageType.NOT_SET);
                    }
                }
            }
            Traverse.Create(__instance).Method("PopReport").GetValue();
            return(false);
        }