Пример #1
0
 public static void GiveInjuriesOperationFailureMinor(Pawn p, BodyPartRecord part)
 {
     HealthUtility.GiveRandomSurgeryInjuries(p, 20, part);
 }
Пример #2
0
 public static void GiveInjuriesOperationFailureCatastrophic(Pawn p, BodyPartRecord part)
 {
     HealthUtility.GiveRandomSurgeryInjuries(p, 65, part);
 }
Пример #3
0
 public DamageInfo(DamageDef def, float amount, float armorPenetration = 0f, float angle = -1f, Thing instigator = null, BodyPartRecord hitPart = null, ThingDef weapon = null, SourceCategory category = SourceCategory.ThingOrUnknown, Thing intendedTarget = null)
 {
     defInt              = def;
     amountInt           = amount;
     armorPenetrationInt = armorPenetration;
     if (angle < 0f)
     {
         angleInt = (float)Rand.RangeInclusive(0, 359);
     }
     else
     {
         angleInt = angle;
     }
     instigatorInt             = instigator;
     categoryInt               = category;
     hitPartInt                = hitPart;
     heightInt                 = BodyPartHeight.Undefined;
     depthInt                  = BodyPartDepth.Undefined;
     weaponInt                 = weapon;
     weaponBodyPartGroupInt    = null;
     weaponHediffInt           = null;
     instantPermanentInjuryInt = false;
     allowDamagePropagationInt = true;
     intendedTargetInt         = intendedTarget;
 }
Пример #4
0
 public virtual string GetLabelWhenUsedOn(Pawn pawn, BodyPartRecord part)
 {
     return(this.recipe.LabelCap);
 }
        public static float CalculateImmediatePartEfficiencyAndRecord(HediffSet diffSet, BodyPartRecord part, List <PawnCapacityUtility.CapacityImpactor> impactors = null)
        {
            float result;

            if (diffSet.AncestorHasDirectlyAddedParts(part))
            {
                result = 1f;
            }
            else
            {
                result = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors);
            }
            return(result);
        }
Пример #6
0
 public BattleLogEntry_StateTransition(Thing subject, RulePackDef transitionDef, Pawn initiator, Hediff culpritHediff, BodyPartRecord culpritTargetDef)
 {
     if (subject is Pawn)
     {
         subjectPawn = (subject as Pawn);
     }
     else if (subject != null)
     {
         subjectThing = subject.def;
     }
     this.transitionDef = transitionDef;
     this.initiator     = initiator;
     if (culpritHediff != null)
     {
         culpritHediffDef = culpritHediff.def;
         if (culpritHediff.Part != null)
         {
             culpritHediffTargetPart = culpritHediff.Part;
         }
     }
     culpritTargetPart = culpritTargetDef;
 }
Пример #7
0
 public bool IsSkinCovered(BodyPartRecord part, HediffSet body)
 {
     return(!body.PartOrAnyAncestorHasDirectlyAddedParts(part) && this.skinCovered);
 }
Пример #8
0
 public virtual string GetLabelWhenUsedOn(Pawn pawn, BodyPartRecord part)
 {
     return(recipe.label);
 }
Пример #9
0
 public bool AncestorHasDirectlyAddedParts(BodyPartRecord part)
 {
     return(part.parent != null && this.PartOrAnyAncestorHasDirectlyAddedParts(part.parent));
 }
Пример #10
0
 public virtual bool IsViolationOnPawn(Pawn pawn, BodyPartRecord part, Faction billDoerFaction)
 {
     return(pawn.Faction != billDoerFaction && this.recipe.isViolation);
 }
Пример #11
0
        public BodyPartRecord GetRandomNotMissingPart(DamageDef damDef, BodyPartHeight height = BodyPartHeight.Undefined, BodyPartDepth depth = BodyPartDepth.Undefined, BodyPartRecord partParent = null)
        {
            IEnumerable <BodyPartRecord> notMissingParts;

            if (this.GetNotMissingParts(height, depth, null, partParent).Any <BodyPartRecord>())
            {
                notMissingParts = this.GetNotMissingParts(height, depth, null, partParent);
            }
            else
            {
                if (!this.GetNotMissingParts(BodyPartHeight.Undefined, depth, null, partParent).Any <BodyPartRecord>())
                {
                    return(null);
                }
                BodyPartHeight height2 = BodyPartHeight.Undefined;
                notMissingParts = this.GetNotMissingParts(height2, depth, null, partParent);
            }
            BodyPartRecord result;

            if (notMissingParts.TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs * x.def.GetHitChanceFactorFor(damDef), out result))
            {
                return(result);
            }
            if (notMissingParts.TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out result))
            {
                return(result);
            }
            throw new InvalidOperationException();
        }
Пример #12
0
        public IEnumerable <BodyPartRecord> GetNotMissingParts(BodyPartHeight height = BodyPartHeight.Undefined, BodyPartDepth depth = BodyPartDepth.Undefined, BodyPartTagDef tag = null, BodyPartRecord partParent = null)
        {
            List <BodyPartRecord> allPartsList = this.pawn.def.race.body.AllParts;

            for (int i = 0; i < allPartsList.Count; i++)
            {
                BodyPartRecord part = allPartsList[i];
                if (!this.PartIsMissing(part))
                {
                    if (height == BodyPartHeight.Undefined || part.height == height)
                    {
                        if (depth == BodyPartDepth.Undefined || part.depth == depth)
                        {
                            if (tag == null || part.def.tags.Contains(tag))
                            {
                                if (partParent == null || part.parent == partParent)
                                {
                                    yield return(part);
                                }
                            }
                        }
                    }
                }
            }
        }
 private static string <Options_Hediff_BodyParts> m__1(BodyPartRecord pa)
 {
     return(pa.Label);
 }
Пример #14
0
        public static Pair <string, Color> GetPartConditionLabel(Pawn pawn, BodyPartRecord part)
        {
            float  partHealth = pawn.health.hediffSet.GetPartHealth(part);
            float  maxHealth  = part.def.GetMaxHealth(pawn);
            float  num        = partHealth / maxHealth;
            string empty      = string.Empty;
            Color  white      = Color.white;

            if (partHealth <= 0.0)
            {
                Hediff_MissingPart        hediff_MissingPart          = null;
                List <Hediff_MissingPart> missingPartsCommonAncestors = pawn.health.hediffSet.GetMissingPartsCommonAncestors();
                int num2 = 0;
                while (num2 < missingPartsCommonAncestors.Count)
                {
                    if (missingPartsCommonAncestors[num2].Part != part)
                    {
                        num2++;
                        continue;
                    }
                    hediff_MissingPart = missingPartsCommonAncestors[num2];
                    break;
                }
                if (hediff_MissingPart == null)
                {
                    bool fresh = false;
                    if (hediff_MissingPart != null && hediff_MissingPart.IsFreshNonSolidExtremity)
                    {
                        fresh = true;
                    }
                    bool solid = part.def.IsSolid(part, pawn.health.hediffSet.hediffs);
                    empty = HealthUtility.GetGeneralDestroyedPartLabel(part, fresh, solid);
                    white = Color.gray;
                }
                else
                {
                    empty = hediff_MissingPart.LabelCap;
                    white = hediff_MissingPart.LabelColor;
                }
            }
            else if (num < 0.40000000596046448)
            {
                empty = "SeriouslyImpaired".Translate();
                white = HealthUtility.DarkRedColor;
            }
            else if (num < 0.699999988079071)
            {
                empty = "Impaired".Translate();
                white = HealthUtility.ImpairedColor;
            }
            else if (num < 0.99900001287460327)
            {
                empty = "SlightlyImpaired".Translate();
                white = HealthUtility.SlightlyImpairedColor;
            }
            else
            {
                empty = "GoodCondition".Translate();
                white = HealthUtility.GoodConditionColor;
            }
            return(new Pair <string, Color>(empty, white));
        }
        public float DiseaseContractChanceFactor(HediffDef diseaseDef, BodyPartRecord part = null)
        {
            HediffDef hediffDef = null;

            return(this.DiseaseContractChanceFactor(diseaseDef, out hediffDef, part));
        }
Пример #16
0
 public virtual void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
 {
 }
        public float DiseaseContractChanceFactor(HediffDef diseaseDef, out HediffDef immunityCause, BodyPartRecord part = null)
        {
            immunityCause = null;
            float result;

            if (!this.pawn.RaceProps.IsFlesh)
            {
                result = 0f;
            }
            else
            {
                List <Hediff> hediffs = this.pawn.health.hediffSet.hediffs;
                for (int i = 0; i < hediffs.Count; i++)
                {
                    if (hediffs[i].def == diseaseDef && hediffs[i].Part == part)
                    {
                        return(0f);
                    }
                }
                for (int j = 0; j < this.immunityList.Count; j++)
                {
                    if (this.immunityList[j].hediffDef == diseaseDef)
                    {
                        immunityCause = this.immunityList[j].source;
                        return(Mathf.Lerp(1f, 0f, this.immunityList[j].immunity / 0.6f));
                    }
                }
                result = 1f;
            }
            return(result);
        }
Пример #18
0
        public static float GetPostArmorDamage(Pawn pawn, 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 (pawn.apparel != null)
            {
                List <Apparel> wornApparel = pawn.apparel.WornApparel;
                for (int num = wornApparel.Count - 1; num >= 0; num--)
                {
                    Apparel apparel = wornApparel[num];
                    if (apparel.def.apparel.CoversBodyPart(part))
                    {
                        float num2 = amount;
                        ApplyArmor(ref amount, armorPenetration, apparel.GetStatValue(armorRatingStat), apparel, ref damageDef, pawn, out var 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 var metalArmor2);
            if (amount < 0.001f)
            {
                deflectedByMetalArmor = metalArmor2;
                return(0f);
            }
            if (amount < num3 && metalArmor2)
            {
                diminishedByMetalArmor = true;
            }
            return(amount);
        }
Пример #19
0
 public DamageInfo(DamageDef def, int amount, float angle = -1f, Thing instigator = null, BodyPartRecord hitPart = null, ThingDef weapon = null, DamageInfo.SourceCategory category = DamageInfo.SourceCategory.ThingOrUnknown)
 {
     this.defInt    = def;
     this.amountInt = amount;
     if (angle < 0f)
     {
         this.angleInt = (float)Rand.RangeInclusive(0, 359);
     }
     else
     {
         this.angleInt = angle;
     }
     this.instigatorInt             = instigator;
     this.categoryInt               = category;
     this.hitPartInt                = hitPart;
     this.heightInt                 = BodyPartHeight.Undefined;
     this.depthInt                  = BodyPartDepth.Undefined;
     this.weaponInt                 = weapon;
     this.weaponBodyPartGroupInt    = null;
     this.weaponHediffInt           = null;
     this.instantOldInjuryInt       = false;
     this.allowDamagePropagationInt = true;
 }
        public static float CalculatePartEfficiency(HediffSet diffSet, BodyPartRecord part, bool ignoreAddedParts = false, List <PawnCapacityUtility.CapacityImpactor> impactors = null)
        {
            BodyPartRecord rec;

            for (rec = part.parent; rec != null; rec = rec.parent)
            {
                if (diffSet.HasDirectlyAddedPartFor(rec))
                {
                    Hediff_AddedPart hediff_AddedPart = (from x in diffSet.GetHediffs <Hediff_AddedPart>()
                                                         where x.Part == rec
                                                         select x).First <Hediff_AddedPart>();
                    if (impactors != null)
                    {
                        impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff
                        {
                            hediff = hediff_AddedPart
                        });
                    }
                    return(hediff_AddedPart.def.addedPartProps.partEfficiency);
                }
            }
            if (part.parent != null && diffSet.PartIsMissing(part.parent))
            {
                return(0f);
            }
            float num = 1f;

            if (!ignoreAddedParts)
            {
                for (int i = 0; i < diffSet.hediffs.Count; i++)
                {
                    Hediff_AddedPart hediff_AddedPart2 = diffSet.hediffs[i] as Hediff_AddedPart;
                    if (hediff_AddedPart2 != null && hediff_AddedPart2.Part == part)
                    {
                        num *= hediff_AddedPart2.def.addedPartProps.partEfficiency;
                        if (hediff_AddedPart2.def.addedPartProps.partEfficiency != 1f && impactors != null)
                        {
                            impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff
                            {
                                hediff = hediff_AddedPart2
                            });
                        }
                    }
                }
            }
            float b    = -1f;
            float num2 = 0f;
            bool  flag = false;

            for (int j = 0; j < diffSet.hediffs.Count; j++)
            {
                if (diffSet.hediffs[j].Part == part && diffSet.hediffs[j].CurStage != null)
                {
                    HediffStage curStage = diffSet.hediffs[j].CurStage;
                    num2 += curStage.partEfficiencyOffset;
                    flag |= curStage.partIgnoreMissingHP;
                    if (curStage.partEfficiencyOffset != 0f && curStage.becomeVisible && impactors != null)
                    {
                        impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff
                        {
                            hediff = diffSet.hediffs[j]
                        });
                    }
                }
            }
            if (!flag)
            {
                float num3 = diffSet.GetPartHealth(part) / part.def.GetMaxHealth(diffSet.pawn);
                if (num3 != 1f)
                {
                    if (DamageWorker_AddInjury.ShouldReduceDamageToPreservePart(part))
                    {
                        num3 = Mathf.InverseLerp(0.1f, 1f, num3);
                    }
                    if (impactors != null)
                    {
                        impactors.Add(new PawnCapacityUtility.CapacityImpactorBodyPartHealth
                        {
                            bodyPart = part
                        });
                    }
                    num *= num3;
                }
            }
            num += num2;
            if (num > 0.0001f)
            {
                num = Mathf.Max(num, b);
            }
            return(Mathf.Max(num, 0f));
        }
Пример #21
0
 public void SetHitPart(BodyPartRecord forceHitPart)
 {
     this.hitPartInt = forceHitPart;
 }
Пример #22
0
        public static float GetPostArmorDamage(Pawn pawn, float amount, float armorPenetration, BodyPartRecord part, ref DamageDef damageDef, out bool deflectedByMetalArmor, out bool diminishedByMetalArmor)
        {
            deflectedByMetalArmor  = false;
            diminishedByMetalArmor = false;
            float result;

            if (damageDef.armorCategory == null)
            {
                result = amount;
            }
            else
            {
                StatDef armorRatingStat = damageDef.armorCategory.armorRatingStat;
                if (pawn.apparel != null)
                {
                    List <Apparel> wornApparel = pawn.apparel.WornApparel;
                    for (int i = wornApparel.Count - 1; i >= 0; i--)
                    {
                        Apparel apparel = wornApparel[i];
                        if (apparel.def.apparel.CoversBodyPart(part))
                        {
                            float num = amount;
                            bool  flag;
                            ArmorUtility.ApplyArmor(ref amount, armorPenetration, apparel.GetStatValue(armorRatingStat, true), apparel, ref damageDef, pawn, out flag);
                            if (amount < 0.001f)
                            {
                                deflectedByMetalArmor = flag;
                                return(0f);
                            }
                            if (amount < num && flag)
                            {
                                diminishedByMetalArmor = true;
                            }
                        }
                    }
                }
                float num2 = amount;
                bool  flag2;
                ArmorUtility.ApplyArmor(ref amount, armorPenetration, pawn.GetStatValue(armorRatingStat, true), null, ref damageDef, pawn, out flag2);
                if (amount < 0.001f)
                {
                    deflectedByMetalArmor = flag2;
                    result = 0f;
                }
                else
                {
                    if (amount < num2 && flag2)
                    {
                        diminishedByMetalArmor = true;
                    }
                    result = amount;
                }
            }
            return(result);
        }
Пример #23
0
 private void CacheDataRecursive(BodyPartRecord node)
 {
     if (node.def == null)
     {
         Log.Error("BodyPartRecord with null def. body=" + this);
     }
     else
     {
         node.body = this;
         for (int i = 0; i < node.parts.Count; i++)
         {
             node.parts[i].parent = node;
         }
         if (node.parent != null)
         {
             node.coverageAbsWithChildren = node.parent.coverageAbsWithChildren * node.coverage;
         }
         else
         {
             node.coverageAbsWithChildren = 1f;
         }
         float num = 1f;
         for (int j = 0; j < node.parts.Count; j++)
         {
             num -= node.parts[j].coverage;
         }
         if (Mathf.Abs(num) < 1E-05f)
         {
             num = 0f;
         }
         if (num < 0f)
         {
             num = 0f;
             Log.Warning("BodyDef " + defName + " has BodyPartRecord of " + node.def.defName + " whose children have more coverage than 1.");
         }
         node.coverageAbs = node.coverageAbsWithChildren * num;
         if (node.height == BodyPartHeight.Undefined)
         {
             node.height = BodyPartHeight.Middle;
         }
         if (node.depth == BodyPartDepth.Undefined)
         {
             node.depth = BodyPartDepth.Outside;
         }
         for (int k = 0; k < node.parts.Count; k++)
         {
             if (node.parts[k].height == BodyPartHeight.Undefined)
             {
                 node.parts[k].height = node.height;
             }
             if (node.parts[k].depth == BodyPartDepth.Undefined)
             {
                 node.parts[k].depth = node.depth;
             }
         }
         cachedAllParts.Add(node);
         for (int l = 0; l < node.parts.Count; l++)
         {
             CacheDataRecursive(node.parts[l]);
         }
     }
 }