public static bool Prefix(Pawn pawn, ref float amount, ref float armorPenetration, BodyPartRecord part, ref DamageDef damageDef, out bool deflectedByMetalArmor, out bool diminishedByMetalArmor, ref float __result) { deflectedByMetalArmor = false; diminishedByMetalArmor = false; MechSuit mechSuit = pawn.GetMechSuit(); if (mechSuit != null && !mechSuit.broken) { __result = 0f; deflectedByMetalArmor = true; diminishedByMetalArmor = true; var armorDamage = GetPostArmorDamage(pawn, mechSuit, amount, armorPenetration, part, ref damageDef, out deflectedByMetalArmor, out diminishedByMetalArmor); if (part.IsInGroup(DefDatabase <BodyPartGroupDef> .GetNamed("Shoulders"))) { var comp = mechSuit.AllComps.Where(x => x is OgsOld_CompTurretGunDamagable).RandomElement() as OgsOld_CompTurretGunDamagable; if (comp != null) { comp.TakeDamage((int)armorDamage); } } mechSuit.TakeArmorDamage(armorDamage); return(false); } return(true); }
public static float GetPostArmorDamage(Pawn pawn, MechSuit mechSuit, float amount, float armorPenetration, BodyPartRecord part, ref DamageDef damageDef, out bool deflectedByMetalArmor, out bool diminishedByMetalArmor) { deflectedByMetalArmor = false; diminishedByMetalArmor = false; if (damageDef.armorCategory == null) { return(amount); } StatDef armorRatingStat = damageDef.armorCategory.armorRatingStat; if (mechSuit.def.apparel.CoversBodyPart(part)) { float num2 = amount; ApplyArmor(ref amount, armorPenetration, mechSuit.GetStatValue(armorRatingStat), mechSuit, ref damageDef, pawn, out bool metalArmor); if (amount < 0.001f) { deflectedByMetalArmor = metalArmor; return(0f); } if (amount < num2 && metalArmor) { diminishedByMetalArmor = true; } } float num3 = amount; ApplyArmor(ref amount, armorPenetration, pawn.GetStatValue(armorRatingStat), null, ref damageDef, pawn, out bool metalArmor2); if (amount < 0.001f) { deflectedByMetalArmor = metalArmor2; return(0f); } if (amount < num3 && metalArmor2) { diminishedByMetalArmor = true; } return(amount); }