public new void ApplyDamageToPart(DamageInfo dinfo, Pawn pawn, DamageWorker.DamageResult result) { BodyPartRecord exactPartFromDamageInfo = this.GetExactPartFromDamageInfo(dinfo, pawn); if (exactPartFromDamageInfo == null) { return; } dinfo.SetHitPart(exactPartFromDamageInfo); float num = dinfo.Amount; bool deflectedByMetalArmor = false; if (!dinfo.InstantPermanentInjury && !dinfo.IgnoreArmor) { DamageDef def = dinfo.Def; num = ArmorUtility.GetPostArmorDamage(pawn, num, dinfo.ArmorPenetrationInt, dinfo.HitPart, ref def, out deflectedByMetalArmor, out bool diminishedByMetalArmor); dinfo.Def = def; if (num < dinfo.Amount) { result.diminished = true; result.diminishedByMetalArmor = diminishedByMetalArmor; } } if (dinfo.Def.ExternalViolenceFor(pawn)) { num *= pawn.GetStatValue(StatDefOf.IncomingDamageFactor, true); } if (num <= 0f) { result.AddPart(pawn, dinfo.HitPart); result.deflected = true; result.deflectedByMetalArmor = deflectedByMetalArmor; return; } if (DamageWorker_AddInjuryStrengthX.IsHeadshot(dinfo, pawn)) { result.headshot = true; } if (dinfo.InstantPermanentInjury && (HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart).CompPropsFor(typeof(HediffComp_GetsPermanent)) == null || dinfo.HitPart.def.permanentInjuryChanceFactor == 0f || pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(dinfo.HitPart))) { return; } if (!dinfo.AllowDamagePropagation) { this.FinalizeAndAddInjury(pawn, num, dinfo, result); return; } this.ApplySpecialEffectsToPart(pawn, num, dinfo, result); }
public new DamageWorker.DamageResult ApplyToPawn(DamageInfo dinfo, Pawn pawn) { DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult(); if (dinfo.Amount <= 0f) { return(damageResult); } if (!DebugSettings.enablePlayerDamage && pawn.Faction == Faction.OfPlayer) { return(damageResult); } dinfo.SetAmount((dinfo.Amount * pawn.def.race.baseHealthScale)); Map mapHeld = pawn.MapHeld; bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned; if (dinfo.AllowDamagePropagation && dinfo.Amount >= (float)dinfo.Def.minDamageToFragment) { Rand.PushState(); int num = Rand.RangeInclusive(2, 4); Rand.PopState(); for (int i = 0; i < num; i++) { DamageInfo dinfo2 = dinfo; dinfo2.SetAmount(dinfo.Amount / (float)num); this.ApplyDamageToPart(dinfo2, pawn, damageResult); } } else { this.ApplyDamageToPart(dinfo, pawn, damageResult); this.ApplySmallPawnDamagePropagation(dinfo, pawn, damageResult); } if (damageResult.wounded) { DamageWorker_AddInjuryStrengthX.PlayWoundedVoiceSound(dinfo, pawn); pawn.Drawer.Notify_DamageApplied(dinfo); EffecterDef damageEffecter = pawn.RaceProps.FleshType.damageEffecter; if (damageEffecter != null) { if (pawn.health.woundedEffecter != null && pawn.health.woundedEffecter.def != damageEffecter) { pawn.health.woundedEffecter.Cleanup(); } pawn.health.woundedEffecter = damageEffecter.Spawn(); pawn.health.woundedEffecter.Trigger(pawn, dinfo.Instigator ?? pawn); } if (dinfo.Def.damageEffecter != null) { Effecter effecter = dinfo.Def.damageEffecter.Spawn(); effecter.Trigger(pawn, pawn); effecter.Cleanup(); } } if (damageResult.headshot && pawn.Spawned) { MoteMaker.ThrowText(new Vector3((float)pawn.Position.x + 1f, (float)pawn.Position.y, (float)pawn.Position.z + 1f), pawn.Map, "Headshot".Translate(), Color.white, -1f); if (dinfo.Instigator != null) { Pawn pawn2 = dinfo.Instigator as Pawn; if (pawn2 != null) { pawn2.records.Increment(RecordDefOf.Headshots); } } } if ((damageResult.deflected || damageResult.diminished) && spawnedOrAnyParentSpawned) { EffecterDef effecterDef; if (damageResult.deflected) { if (damageResult.deflectedByMetalArmor && dinfo.Def.canUseDeflectMetalEffect) { if (dinfo.Def == DamageDefOf.Bullet) { effecterDef = EffecterDefOf.Deflect_Metal_Bullet; } else { effecterDef = EffecterDefOf.Deflect_Metal; } } else if (dinfo.Def == DamageDefOf.Bullet) { effecterDef = EffecterDefOf.Deflect_General_Bullet; } else { effecterDef = EffecterDefOf.Deflect_General; } } else if (damageResult.diminishedByMetalArmor) { effecterDef = EffecterDefOf.DamageDiminished_Metal; } else { effecterDef = EffecterDefOf.DamageDiminished_General; } if (pawn.health.deflectionEffecter == null || pawn.health.deflectionEffecter.def != effecterDef) { if (pawn.health.deflectionEffecter != null) { pawn.health.deflectionEffecter.Cleanup(); pawn.health.deflectionEffecter = null; } pawn.health.deflectionEffecter = effecterDef.Spawn(); } pawn.health.deflectionEffecter.Trigger(pawn, dinfo.Instigator ?? pawn); if (damageResult.deflected) { pawn.Drawer.Notify_DamageDeflected(dinfo); } } if (!damageResult.deflected && spawnedOrAnyParentSpawned) { ImpactSoundUtility.PlayImpactSound(pawn, dinfo.Def.impactSoundType, mapHeld); } return(damageResult); }