static void Prefix(Mech __instance, int originalHitLoc, WeaponHitInfo hitInfo, ArmorLocation aLoc, Weapon weapon, float totalArmorDamage, float directStructureDamage, int hitIndex, AttackImpactQuality impactQuality, DamageType damageType) { if (aLoc == ArmorLocation.None || aLoc == ArmorLocation.Invalid) { return; } float num = totalArmorDamage; float currentArmor = __instance.GetCurrentArmor(aLoc); if (currentArmor > 0f) { num = totalArmorDamage - currentArmor; } num += directStructureDamage; // account for damage split: this should get us back where we were when we both had armour spillover damage and // any damage done directly to the structure if (num <= 0f) { return; //no need to continue if the shot doesn't do anything we care about } ChassisLocations chassisLocationFromArmorLocation = MechStructureRules.GetChassisLocationFromArmorLocation(aLoc); float currentStructure = __instance.GetCurrentStructure(chassisLocationFromArmorLocation); if (currentStructure > 0f) { float num4 = Math.Min(num, currentStructure); bool WasDestroyed = (currentStructure - num) <= 0; //if currentstructure minus remaining damage is less or equal to 0, then the location is destroyed. num -= num4; if (WasDestroyed && num4 > 0.01f) //this location was destroyed, so we now check for dependents. { if (chassisLocationFromArmorLocation == ChassisLocations.LeftArm) { Holder.LeftArmSurvived = false; //invalidate if the actual arm was destroyed } else if (chassisLocationFromArmorLocation == ChassisLocations.RightArm) { Holder.RightArmSurvived = false; //invalidate if the actual arm was destroyed } ChassisLocations dependentLocation = MechStructureRules.GetDependentLocation(chassisLocationFromArmorLocation); if (dependentLocation != ChassisLocations.None && !__instance.IsLocationDestroyed(dependentLocation)) { if (dependentLocation == ChassisLocations.LeftArm) { Holder.LeftArmSurvived = true; //side torso was destroyed, no reason the arm should be totally trashed. } else if (dependentLocation == ChassisLocations.RightArm) { Holder.RightArmSurvived = true; //side torso was destroyed, no reason the arm should be totally trashed. } } } } }
public static void Postfix(Mech __instance, int stackID, string attackerID) { if (__instance.IsDead || (__instance.IsFlaggedForDeath && __instance.HasHandledDeath) || !__instance.IsOverheated && !__instance.IsShutDown) { return; //don't bother if they're dead or not overheating } foreach (MechComponent mechComponent in __instance.allComponents) { if (mechComponent as AmmunitionBox != null) { AmmunitionBox ammoBox = mechComponent as AmmunitionBox; if (ammoBox != null) { int value = ammoBox.StatCollection.GetValue <int>("CurrentAmmo"); int capacity = ammoBox.ammunitionBoxDef.Capacity; float num = value / (float)capacity; if (num < 0.5f && Settings.UseHBSMercySetting) { return; } var rng = (new System.Random()).Next(100); var rollToBeat = __instance.IsShutDown ? Settings.ShutdownHeatChance : Settings.OverheatChance; //if shut down, we use the Shutdown chance. Otherwise, the normal overheat chance. if (rng < rollToBeat) //things are exploding captain! { if (__instance.Combat.Constants.PilotingConstants.InjuryFromAmmoExplosion) { Pilot pilot = __instance.GetPilot(); if (pilot != null) { pilot.SetNeedsInjury(InjuryReason.AmmoExplosion); } } string text = string.Format("{0} EXPLOSION", ammoBox.Name); ammoBox.parent.Combat.MessageCenter.PublishMessage(new FloatieMessage(ammoBox.parent.GUID, ammoBox.parent.GUID, text, FloatieMessage.MessageNature.CriticalHit)); //we make a fake hit info to apply the nuking WeaponHitInfo hitInfo = new WeaponHitInfo(stackID, -1, -1, -1, string.Empty, string.Empty, -1, null, null, null, null, null, null, null, new AttackDirection[] { AttackDirection.FromFront }, null, null, null); Vector3 onUnitSphere = UnityEngine.Random.onUnitSphere; __instance.NukeStructureLocation(hitInfo, ammoBox.Location, (ChassisLocations)ammoBox.Location, onUnitSphere, DamageType.Overheat); ChassisLocations dependentLocation = MechStructureRules.GetDependentLocation((ChassisLocations)ammoBox.Location); if (dependentLocation != ChassisLocations.None && !__instance.IsLocationDestroyed(dependentLocation)) { __instance.NukeStructureLocation(hitInfo, ammoBox.Location, dependentLocation, onUnitSphere, DamageType.Overheat); } } } } } }