コード例 #1
0
 protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, ref DamageWorker.DamageResult result)
 {
     if (dinfo.HitPart.depth == BodyPartDepth.Inside)
     {
         List <BodyPartRecord> list = new List <BodyPartRecord>();
         for (BodyPartRecord bodyPartRecord = dinfo.HitPart; bodyPartRecord != null; bodyPartRecord = bodyPartRecord.parent)
         {
             list.Add(bodyPartRecord);
             if (bodyPartRecord.depth == BodyPartDepth.Outside)
             {
                 break;
             }
         }
         float num = (float)(list.Count - 1) + 0.5f;
         for (int i = 0; i < list.Count; i++)
         {
             DamageInfo dinfo2 = dinfo;
             dinfo2.SetHitPart(list[i]);
             base.FinalizeAndAddInjury(pawn, totalDamage / num * ((i != 0) ? 1f : 0.5f), dinfo2, ref result);
         }
     }
     else
     {
         int num2 = (this.def.cutExtraTargetsCurve == null) ? 0 : GenMath.RoundRandom(this.def.cutExtraTargetsCurve.Evaluate(Rand.Value));
         List <BodyPartRecord> list2;
         if (num2 != 0)
         {
             IEnumerable <BodyPartRecord> enumerable = dinfo.HitPart.GetDirectChildParts();
             if (dinfo.HitPart.parent != null)
             {
                 enumerable = enumerable.Concat(dinfo.HitPart.parent);
                 enumerable = enumerable.Concat(dinfo.HitPart.parent.GetDirectChildParts());
             }
             list2 = enumerable.Except(dinfo.HitPart).InRandomOrder(null).Take(num2).ToList <BodyPartRecord>();
         }
         else
         {
             list2 = new List <BodyPartRecord>();
         }
         list2.Add(dinfo.HitPart);
         float num3 = totalDamage * (1f + this.def.cutCleaveBonus) / ((float)list2.Count + this.def.cutCleaveBonus);
         if (num2 == 0)
         {
             num3 = base.ReduceDamageToPreserveOutsideParts(num3, dinfo, pawn);
         }
         for (int j = 0; j < list2.Count; j++)
         {
             DamageInfo dinfo3 = dinfo;
             dinfo3.SetHitPart(list2[j]);
             base.FinalizeAndAddInjury(pawn, num3, dinfo3, ref result);
         }
     }
 }
コード例 #2
0
 private void CheckDuplicateSmallPawnDamageToPartParent(DamageInfo dinfo, Pawn pawn, ref DamageWorker.DamageResult result)
 {
     if (!dinfo.AllowDamagePropagation)
     {
         return;
     }
     if (result.LastHitPart != null && dinfo.Def.harmsHealth && result.LastHitPart != pawn.RaceProps.body.corePart && result.LastHitPart.parent != null && pawn.health.hediffSet.GetPartHealth(result.LastHitPart.parent) > 0f && dinfo.Amount >= 10 && pawn.HealthScale <= 0.5001f)
     {
         DamageInfo dinfo2 = dinfo;
         dinfo2.SetHitPart(result.LastHitPart.parent);
         this.ApplyDamageToPart(dinfo2, pawn, ref result);
     }
 }
コード例 #3
0
        protected float FinalizeAndAddInjury(Pawn pawn, Hediff_Injury injury, DamageInfo dinfo, DamageWorker.DamageResult result)
        {
            HediffComp_GetsPermanent hediffComp_GetsPermanent = injury.TryGetComp <HediffComp_GetsPermanent>();

            if (hediffComp_GetsPermanent != null)
            {
                hediffComp_GetsPermanent.PreFinalizeInjury();
            }
            pawn.health.AddHediff(injury, null, new DamageInfo?(dinfo), result);
            float num = Mathf.Min(injury.Severity, pawn.health.hediffSet.GetPartHealth(injury.Part));

            result.totalDamageDealt += num;
            result.wounded           = true;
            result.AddPart(pawn, injury.Part);
            result.AddHediff(injury);
            return(num);
        }
コード例 #4
0
 private void CheckDuplicateDamageToOuterParts(DamageInfo dinfo, Pawn pawn, float totalDamage, DamageWorker.DamageResult result)
 {
     if (!dinfo.AllowDamagePropagation)
     {
         return;
     }
     if (dinfo.Def.harmAllLayersUntilOutside && dinfo.HitPart.depth == BodyPartDepth.Inside)
     {
         BodyPartRecord parent = dinfo.HitPart.parent;
         do
         {
             if (pawn.health.hediffSet.GetPartHealth(parent) != 0f && parent.coverageAbs > 0f)
             {
                 HediffDef     hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, parent);
                 Hediff_Injury hediff_Injury       = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
                 hediff_Injury.Part   = parent;
                 hediff_Injury.source = dinfo.Weapon;
                 hediff_Injury.sourceBodyPartGroup = dinfo.WeaponBodyPartGroup;
                 hediff_Injury.Severity            = totalDamage;
                 if (hediff_Injury.Severity <= 0f)
                 {
                     hediff_Injury.Severity = 1f;
                 }
                 this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, result);
             }
             if (parent.depth == BodyPartDepth.Outside)
             {
                 break;
             }
             parent = parent.parent;
         }while (parent != null);
     }
 }
コード例 #5
0
        public void AddDirect(Hediff hediff, DamageInfo?dinfo = null, DamageWorker.DamageResult damageResult = null)
        {
            if (hediff.def == null)
            {
                Log.Error("Tried to add health diff with null def. Canceling.", false);
                return;
            }
            if (hediff.Part != null && !this.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).Contains(hediff.Part))
            {
                Log.Error("Tried to add health diff to missing part " + hediff.Part, false);
                return;
            }
            hediff.ageTicks = 0;
            hediff.pawn     = this.pawn;
            bool flag = false;

            for (int i = 0; i < this.hediffs.Count; i++)
            {
                if (this.hediffs[i].TryMergeWith(hediff))
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                this.hediffs.Add(hediff);
                hediff.PostAdd(dinfo);
                if (this.pawn.needs != null && this.pawn.needs.mood != null)
                {
                    this.pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
                }
            }
            bool flag2 = hediff is Hediff_MissingPart;

            if (!(hediff is Hediff_MissingPart) && hediff.Part != null && hediff.Part != this.pawn.RaceProps.body.corePart && this.GetPartHealth(hediff.Part) == 0f && hediff.Part != this.pawn.RaceProps.body.corePart)
            {
                bool flag3 = this.HasDirectlyAddedPartFor(hediff.Part);
                Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, this.pawn, null);
                hediff_MissingPart.IsFresh    = !flag3;
                hediff_MissingPart.lastInjury = hediff.def;
                this.pawn.health.AddHediff(hediff_MissingPart, hediff.Part, dinfo, null);
                if (damageResult != null)
                {
                    damageResult.AddHediff(hediff_MissingPart);
                }
                if (flag3)
                {
                    if (dinfo.HasValue)
                    {
                        hediff_MissingPart.lastInjury = HealthUtility.GetHediffDefFromDamage(dinfo.Value.Def, this.pawn, hediff.Part);
                    }
                    else
                    {
                        hediff_MissingPart.lastInjury = null;
                    }
                }
                flag2 = true;
            }
            this.DirtyCache();
            if (flag2 && this.pawn.apparel != null)
            {
                this.pawn.apparel.Notify_LostBodyPart();
            }
            if (hediff.def.causesNeed != null && !this.pawn.Dead)
            {
                this.pawn.needs.AddOrRemoveNeedsAsAppropriate();
            }
        }
コード例 #6
0
        private 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);
            }
            Map  mapHeld = pawn.MapHeld;
            bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned;

            if (dinfo.AllowDamagePropagation && dinfo.Amount >= (float)dinfo.Def.minDamageToFragment)
            {
                int num = Rand.RangeInclusive(2, 4);
                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_AddInjury.PlayWoundedVoiceSound(dinfo, pawn);
                pawn.Drawer.Notify_DamageApplied(dinfo);
            }
            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);
        }
コード例 #7
0
        protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result)
        {
            bool       flag     = Rand.Chance(this.def.bluntInnerHitChance);
            float      num      = (!flag) ? 0f : this.def.bluntInnerHitDamageFractionToConvert.RandomInRange;
            float      num2     = totalDamage * (1f - num);
            DamageInfo lastInfo = dinfo;

            for (;;)
            {
                num2 -= base.FinalizeAndAddInjury(pawn, num2, lastInfo, result);
                if (!pawn.health.hediffSet.PartIsMissing(lastInfo.HitPart))
                {
                    break;
                }
                if (num2 <= 1f)
                {
                    break;
                }
                BodyPartRecord parent = lastInfo.HitPart.parent;
                if (parent == null)
                {
                    break;
                }
                lastInfo.SetHitPart(parent);
            }
            if (flag && !lastInfo.HitPart.def.IsSolid(lastInfo.HitPart, pawn.health.hediffSet.hediffs) && lastInfo.HitPart.depth == BodyPartDepth.Outside)
            {
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
                                                      where x.parent == lastInfo.HitPart && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside
                                                      select x;
                BodyPartRecord hitPart;
                if (source.TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out hitPart))
                {
                    DamageInfo lastInfo2 = lastInfo;
                    lastInfo2.SetHitPart(hitPart);
                    float totalDamage2 = totalDamage * num + totalDamage * this.def.bluntInnerHitDamageFractionToAdd.RandomInRange;
                    base.FinalizeAndAddInjury(pawn, totalDamage2, lastInfo2, result);
                }
            }
            if (!pawn.Dead)
            {
                SimpleCurve simpleCurve = null;
                if (lastInfo.HitPart.parent == null)
                {
                    simpleCurve = this.def.bluntStunChancePerDamagePctOfCorePartToBodyCurve;
                }
                else
                {
                    foreach (BodyPartRecord lhs in pawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource))
                    {
                        if (this.InSameBranch(lhs, lastInfo.HitPart))
                        {
                            simpleCurve = this.def.bluntStunChancePerDamagePctOfCorePartToHeadCurve;
                            break;
                        }
                    }
                }
                if (simpleCurve != null)
                {
                    float x2 = totalDamage / pawn.def.race.body.corePart.def.GetMaxHealth(pawn);
                    if (Rand.Chance(simpleCurve.Evaluate(x2)))
                    {
                        DamageInfo dinfo2 = dinfo;
                        dinfo2.Def = DamageDefOf.Stun;
                        dinfo2.SetAmount((float)this.def.bluntStunDuration.SecondsToTicks() / 30f);
                        pawn.TakeDamage(dinfo2);
                    }
                }
            }
        }
コード例 #8
0
        protected float FinalizeAndAddInjury(Pawn pawn, Hediff_Injury injury, DamageInfo dinfo, ref DamageWorker.DamageResult result)
        {
            this.CalculateOldInjuryDamageThreshold(pawn, injury);
            pawn.health.AddHediff(injury, null, new DamageInfo?(dinfo));
            float num = Mathf.Min(injury.Severity, pawn.health.hediffSet.GetPartHealth(injury.Part));

            result.totalDamageDealt += num;
            result.wounded           = true;
            result.AddPart(pawn, injury.Part);
            return(num);
        }
コード例 #9
0
 protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result)
 {
     if (dinfo.HitPart.depth == BodyPartDepth.Inside)
     {
         List <BodyPartRecord> list = new List <BodyPartRecord>();
         for (BodyPartRecord bodyPartRecord = dinfo.HitPart; bodyPartRecord != null; bodyPartRecord = bodyPartRecord.parent)
         {
             list.Add(bodyPartRecord);
             if (bodyPartRecord.depth == BodyPartDepth.Outside)
             {
                 break;
             }
         }
         float num = (float)list.Count;
         for (int i = 0; i < list.Count; i++)
         {
             DamageInfo dinfo2 = dinfo;
             dinfo2.SetHitPart(list[i]);
             base.FinalizeAndAddInjury(pawn, totalDamage / num, dinfo2, result);
         }
     }
     else
     {
         IEnumerable <BodyPartRecord> enumerable = dinfo.HitPart.GetDirectChildParts();
         if (dinfo.HitPart.parent != null)
         {
             enumerable = enumerable.Concat(dinfo.HitPart.parent);
             if (dinfo.HitPart.parent.parent != null)
             {
                 enumerable = enumerable.Concat(dinfo.HitPart.parent.GetDirectChildParts());
             }
         }
         enumerable = from target in enumerable
                      where target != dinfo.HitPart && !target.def.conceptual && target.depth == BodyPartDepth.Outside && !pawn.health.hediffSet.PartIsMissing(target)
                      select target;
         BodyPartRecord bodyPartRecord2 = enumerable.RandomElementWithFallback(null);
         if (bodyPartRecord2 == null)
         {
             base.FinalizeAndAddInjury(pawn, base.ReduceDamageToPreserveOutsideParts(totalDamage, dinfo, pawn), dinfo, result);
         }
         else
         {
             base.FinalizeAndAddInjury(pawn, base.ReduceDamageToPreserveOutsideParts(totalDamage * this.def.scratchSplitPercentage, dinfo, pawn), dinfo, result);
             DamageInfo dinfo3 = dinfo;
             dinfo3.SetHitPart(bodyPartRecord2);
             base.FinalizeAndAddInjury(pawn, base.ReduceDamageToPreserveOutsideParts(totalDamage * this.def.scratchSplitPercentage, dinfo3, pawn), dinfo3, result);
         }
     }
 }
コード例 #10
0
        protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, ref DamageWorker.DamageResult result)
        {
            bool  flag = Rand.Chance(this.def.bluntInnerHitFrequency);
            float num  = (!flag) ? 0f : this.def.bluntInnerHitConverted.RandomInRange;
            float num2 = totalDamage * (1f - num);

            while (true)
            {
                num2 -= base.FinalizeAndAddInjury(pawn, num2, dinfo, ref result);
                if (!pawn.health.hediffSet.PartIsMissing(dinfo.HitPart))
                {
                    break;
                }
                if (num2 <= 1f)
                {
                    break;
                }
                BodyPartRecord parent = dinfo.HitPart.parent;
                if (parent == null)
                {
                    break;
                }
                dinfo.SetHitPart(parent);
            }
            if (flag && !dinfo.HitPart.def.IsSolid(dinfo.HitPart, pawn.health.hediffSet.hediffs) && dinfo.HitPart.depth == BodyPartDepth.Outside)
            {
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)
                                                      where x.parent == dinfo.HitPart && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside
                                                      select x;
                BodyPartRecord hitPart;
                if (source.TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out hitPart))
                {
                    DamageInfo lastInfo = dinfo;
                    lastInfo.SetHitPart(hitPart);
                    base.FinalizeAndAddInjury(pawn, totalDamage * num + totalDamage * this.def.bluntInnerHitAdded.RandomInRange, lastInfo, ref result);
                }
            }
        }
コード例 #11
0
        protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result)
        {
            totalDamage = base.ReduceDamageToPreserveOutsideParts(totalDamage, dinfo, pawn);
            List <BodyPartRecord> list = new List <BodyPartRecord>();

            for (BodyPartRecord bodyPartRecord = dinfo.HitPart; bodyPartRecord != null; bodyPartRecord = bodyPartRecord.parent)
            {
                list.Add(bodyPartRecord);
                if (bodyPartRecord.depth == BodyPartDepth.Outside)
                {
                    break;
                }
            }
            float totalDamage2 = totalDamage * (1f + this.def.stabPierceBonus) / ((float)list.Count + this.def.stabPierceBonus);

            for (int i = 0; i < list.Count; i++)
            {
                DamageInfo dinfo2 = dinfo;
                dinfo2.SetHitPart(list[i]);
                base.FinalizeAndAddInjury(pawn, totalDamage2, dinfo2, result);
            }
        }
コード例 #12
0
 public void AddHediff(Hediff hediff, BodyPartRecord part = null, DamageInfo?dinfo = null, DamageWorker.DamageResult result = null)
 {
     if (part != null)
     {
         hediff.Part = part;
     }
     hediffSet.AddDirect(hediff, dinfo, result);
     CheckForStateChange(dinfo, hediff);
     if (pawn.RaceProps.hediffGiverSets == null)
     {
         return;
     }
     for (int i = 0; i < pawn.RaceProps.hediffGiverSets.Count; i++)
     {
         HediffGiverSetDef hediffGiverSetDef = pawn.RaceProps.hediffGiverSets[i];
         for (int j = 0; j < hediffGiverSetDef.hediffGivers.Count; j++)
         {
             hediffGiverSetDef.hediffGivers[j].OnHediffAdded(pawn, hediff);
         }
     }
 }
コード例 #13
0
        public Hediff AddHediff(HediffDef def, BodyPartRecord part = null, DamageInfo?dinfo = null, DamageWorker.DamageResult result = null)
        {
            Hediff hediff = HediffMaker.MakeHediff(def, pawn);

            AddHediff(hediff, part, dinfo, result);
            return(hediff);
        }
コード例 #14
0
 protected virtual void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, ref DamageWorker.DamageResult result)
 {
     totalDamage = this.ReduceDamageToPreserveOutsideParts(totalDamage, dinfo, pawn);
     this.FinalizeAndAddInjury(pawn, totalDamage, dinfo, ref result);
     this.CheckDuplicateDamageToOuterParts(dinfo, pawn, totalDamage, ref result);
 }
コード例 #15
0
 protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, ref DamageWorker.DamageResult result)
 {
     totalDamage *= this.def.biteDamageMultiplier;
     base.FinalizeAndAddInjury(pawn, totalDamage, dinfo, ref result);
 }
コード例 #16
0
        protected float FinalizeAndAddInjury(Pawn pawn, float totalDamage, DamageInfo dinfo, ref DamageWorker.DamageResult result)
        {
            if (pawn.health.hediffSet.PartIsMissing(dinfo.HitPart))
            {
                return(0f);
            }
            HediffDef     hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart);
            Hediff_Injury hediff_Injury       = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);

            hediff_Injury.Part   = dinfo.HitPart;
            hediff_Injury.source = dinfo.Weapon;
            hediff_Injury.sourceBodyPartGroup = dinfo.WeaponBodyPartGroup;
            hediff_Injury.sourceHediffDef     = dinfo.WeaponLinkedHediff;
            hediff_Injury.Severity            = totalDamage;
            if (dinfo.InstantOldInjury)
            {
                HediffComp_GetsOld hediffComp_GetsOld = hediff_Injury.TryGetComp <HediffComp_GetsOld>();
                if (hediffComp_GetsOld != null)
                {
                    hediffComp_GetsOld.IsOld = true;
                }
                else
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Tried to create instant old injury on Hediff without a GetsOld comp: ",
                        hediffDefFromDamage,
                        " on ",
                        pawn
                    }));
                }
            }
            return(this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, ref result));
        }
コード例 #17
0
 protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result)
 {
     base.FinalizeAndAddInjury(pawn, totalDamage, dinfo, result);
 }
コード例 #18
0
        private DamageWorker.DamageResult ApplyToPawn(DamageInfo dinfo, Pawn pawn)
        {
            DamageWorker.DamageResult result = DamageWorker.DamageResult.MakeNew();
            if (dinfo.Amount <= 0)
            {
                return(result);
            }
            if (!DebugSettings.enablePlayerDamage && pawn.Faction == Faction.OfPlayer)
            {
                return(result);
            }
            Map  mapHeld = pawn.MapHeld;
            bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned;

            if (dinfo.Def.spreadOut)
            {
                if (pawn.apparel != null)
                {
                    List <Apparel> wornApparel = pawn.apparel.WornApparel;
                    for (int i = wornApparel.Count - 1; i >= 0; i--)
                    {
                        this.CheckApplySpreadDamage(dinfo, wornApparel[i]);
                    }
                }
                if (pawn.equipment != null && pawn.equipment.Primary != null)
                {
                    this.CheckApplySpreadDamage(dinfo, pawn.equipment.Primary);
                }
                if (pawn.inventory != null)
                {
                    ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;
                    for (int j = innerContainer.Count - 1; j >= 0; j--)
                    {
                        this.CheckApplySpreadDamage(dinfo, innerContainer[j]);
                    }
                }
            }
            if (this.ShouldFragmentDamageForDamageType(dinfo))
            {
                int num = Rand.RangeInclusive(3, 4);
                for (int k = 0; k < num; k++)
                {
                    DamageInfo dinfo2 = dinfo;
                    dinfo2.SetAmount(dinfo.Amount / num);
                    this.ApplyDamageToPart(dinfo2, pawn, ref result);
                }
            }
            else
            {
                this.ApplyDamageToPart(dinfo, pawn, ref result);
                this.CheckDuplicateSmallPawnDamageToPartParent(dinfo, pawn, ref result);
            }
            if (result.wounded)
            {
                DamageWorker_AddInjury.PlayWoundedVoiceSound(dinfo, pawn);
                pawn.Drawer.Notify_DamageApplied(dinfo);
                DamageWorker_AddInjury.InformPsychology(dinfo, pawn);
            }
            if (result.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 (result.deflected)
            {
                if (pawn.health.deflectionEffecter == null)
                {
                    pawn.health.deflectionEffecter = EffecterDefOf.ArmorDeflect.Spawn();
                }
                pawn.health.deflectionEffecter.Trigger(pawn, pawn);
            }
            else if (spawnedOrAnyParentSpawned)
            {
                ImpactSoundUtility.PlayImpactSound(pawn, dinfo.Def.impactSoundType, mapHeld);
            }
            return(result);
        }
コード例 #19
0
        protected virtual void ExplosionDamageThing(Explosion explosion, Thing t, List <Thing> damagedThings, IntVec3 cell)
        {
            if (t.def.category == ThingCategory.Mote || t.def.category == ThingCategory.Ethereal)
            {
                return;
            }
            if (damagedThings.Contains(t))
            {
                return;
            }
            damagedThings.Add(t);
            if (this.def == DamageDefOf.Bomb && t.def == ThingDefOf.Fire && !t.Destroyed)
            {
                t.Destroy(DestroyMode.Vanish);
                return;
            }
            float num;

            if (t.Position == explosion.Position)
            {
                num = (float)Rand.RangeInclusive(0, 359);
            }
            else
            {
                num = (t.Position - explosion.Position).AngleFlat;
            }
            DamageDef  damageDef          = this.def;
            float      amount             = (float)explosion.GetDamageAmountAt(cell);
            float      armorPenetrationAt = explosion.GetArmorPenetrationAt(cell);
            float      angle      = num;
            Thing      instigator = explosion.instigator;
            ThingDef   weapon     = explosion.weapon;
            DamageInfo dinfo      = new DamageInfo(damageDef, amount, armorPenetrationAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown, explosion.intendedTarget);

            if (this.def.explosionAffectOutsidePartsOnly)
            {
                dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
            }
            if (t.def.category == ThingCategory.Building)
            {
                int num2 = Mathf.RoundToInt(dinfo.Amount * this.def.explosionBuildingDamageFactor);
                dinfo.SetAmount((float)num2);
            }
            else if (t.def.category == ThingCategory.Plant)
            {
                int num3 = Mathf.RoundToInt(dinfo.Amount * this.def.explosionPlantDamageFactor);
                dinfo.SetAmount((float)num3);
            }
            BattleLogEntry_ExplosionImpact battleLogEntry_ExplosionImpact = null;
            Pawn pawn = t as Pawn;

            if (pawn != null)
            {
                battleLogEntry_ExplosionImpact = new BattleLogEntry_ExplosionImpact(explosion.instigator, t, explosion.weapon, explosion.projectile, this.def);
                Find.BattleLog.Add(battleLogEntry_ExplosionImpact);
            }
            DamageWorker.DamageResult damageResult = t.TakeDamage(dinfo);
            damageResult.AssociateWithLog(battleLogEntry_ExplosionImpact);
            if (pawn != null && damageResult.wounded && pawn.stances != null)
            {
                pawn.stances.StaggerFor(95);
            }
        }