Esempio n. 1
0
        protected float FinalizeAndAddInjury(Pawn pawn, float totalDamage, DamageInfo dinfo, 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.InstantPermanentInjury)
            {
                HediffComp_GetsPermanent hediffComp_GetsPermanent = hediff_Injury.TryGetComp <HediffComp_GetsPermanent>();
                if (hediffComp_GetsPermanent != null)
                {
                    hediffComp_GetsPermanent.IsPermanent = true;
                }
                else
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Tried to create instant permanent injury on Hediff without a GetsPermanent comp: ",
                        hediffDefFromDamage,
                        " on ",
                        pawn
                    }), false);
                }
            }
            return(this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, result));
        }
Esempio n. 2
0
        private void CalculatePermanentInjuryDamageThreshold(Pawn pawn, Hediff_Injury injury)
        {
            HediffCompProperties_GetsPermanent hediffCompProperties_GetsPermanent = injury.def.CompProps <HediffCompProperties_GetsPermanent>();

            if (hediffCompProperties_GetsPermanent != null)
            {
                if (!injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(injury.Part) && !injury.IsPermanent() && injury.Part.def.permanentInjuryBaseChance >= 1E-05f)
                {
                    bool isDelicate = injury.Part.def.IsDelicate;
                    if ((Rand.Value <= injury.Part.def.permanentInjuryBaseChance * hediffCompProperties_GetsPermanent.becomePermanentChance && injury.Severity >= injury.Part.def.GetMaxHealth(pawn) * 0.25f && injury.Severity >= 7f) || isDelicate)
                    {
                        HediffComp_GetsPermanent hediffComp_GetsPermanent = injury.TryGetComp <HediffComp_GetsPermanent>();
                        float num  = 1f;
                        float num2 = injury.Severity / 2f;
                        if (num <= num2)
                        {
                            hediffComp_GetsPermanent.permanentDamageThreshold = Rand.Range(num, num2);
                        }
                        if (isDelicate)
                        {
                            hediffComp_GetsPermanent.permanentDamageThreshold = injury.Severity;
                            hediffComp_GetsPermanent.IsPermanent = true;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static bool IsPermanent(this Hediff hd)
        {
            HediffWithComps hediffWithComps = hd as HediffWithComps;

            if (hediffWithComps == null)
            {
                return(false);
            }
            HediffComp_GetsPermanent hediffComp_GetsPermanent = hediffWithComps.TryGetComp <HediffComp_GetsPermanent>();

            return(hediffComp_GetsPermanent != null && hediffComp_GetsPermanent.IsPermanent);
        }
Esempio n. 4
0
        public static bool IsPermanent(this Hediff hd)
        {
            HediffWithComps hediffWithComps = hd as HediffWithComps;
            bool            result;

            if (hediffWithComps == null)
            {
                result = false;
            }
            else
            {
                HediffComp_GetsPermanent hediffComp_GetsPermanent = hediffWithComps.TryGetComp <HediffComp_GetsPermanent>();
                result = (hediffComp_GetsPermanent != null && hediffComp_GetsPermanent.IsPermanent);
            }
            return(result);
        }
Esempio n. 5
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);
        }
        public override void PostExposeData(object obj)
        {
            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                Map map = obj as Map;
                if (map != null)
                {
                    if (map.retainedCaravanData == null)
                    {
                        map.retainedCaravanData = new RetainedCaravanData(map);
                    }
                    if (map.wildAnimalSpawner == null)
                    {
                        map.wildAnimalSpawner = new WildAnimalSpawner(map);
                    }
                    if (map.wildPlantSpawner == null)
                    {
                        map.wildPlantSpawner = new WildPlantSpawner(map);
                    }
                }
                Thing thing = obj as Thing;
                if (thing != null && thing.def.useHitPoints && thing.MaxHitPoints != thing.HitPoints && Mathf.Abs((float)thing.HitPoints / (float)thing.MaxHitPoints - 0.617f) < 0.02f && thing.Stuff == ThingDefOf.WoodLog)
                {
                    thing.HitPoints = thing.MaxHitPoints;
                }
                Pawn pawn = obj as Pawn;
                if (pawn != null && !pawn.Destroyed && !pawn.Dead && pawn.needs == null)
                {
                    Log.Error(pawn.ToStringSafe() + " has null needs tracker even though he's not dead. Fixing...");
                    pawn.needs = new Pawn_NeedsTracker(pawn);
                    pawn.needs.SetInitialLevels();
                }
                History history = obj as History;
                if (history != null && history.archive == null)
                {
                    history.archive = new Archive();
                }
                WorldInfo worldInfo = obj as WorldInfo;
                if (worldInfo != null && worldInfo.persistentRandomValue == 0)
                {
                    worldInfo.persistentRandomValue = Rand.Int;
                }
                Caravan caravan = obj as Caravan;
                if (caravan != null)
                {
                    if (caravan.forage == null)
                    {
                        caravan.forage = new Caravan_ForageTracker(caravan);
                    }
                    if (caravan.needs == null)
                    {
                        caravan.needs = new Caravan_NeedsTracker(caravan);
                    }
                    if (caravan.carryTracker == null)
                    {
                        caravan.carryTracker = new Caravan_CarryTracker(caravan);
                    }
                    if (caravan.beds == null)
                    {
                        caravan.beds = new Caravan_BedsTracker(caravan);
                    }
                }
                PlaySettings playSettings = obj as PlaySettings;
                if (playSettings != null)
                {
                    playSettings.defaultCareForColonyHumanlike = MedicalCareCategory.Best;
                    playSettings.defaultCareForColonyAnimal    = MedicalCareCategory.HerbalOrWorse;
                    playSettings.defaultCareForColonyPrisoner  = MedicalCareCategory.HerbalOrWorse;
                    playSettings.defaultCareForNeutralFaction  = MedicalCareCategory.HerbalOrWorse;
                    playSettings.defaultCareForNeutralAnimal   = MedicalCareCategory.HerbalOrWorse;
                    playSettings.defaultCareForHostileFaction  = MedicalCareCategory.HerbalOrWorse;
                }
            }
            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                Hediff hediff = obj as Hediff;
                if (hediff != null)
                {
                    Scribe_Values.Look(ref hediff.temp_partIndexToSetLater, "partIndex", -1);
                }
                Bill_Medical bill_Medical = obj as Bill_Medical;
                if (bill_Medical != null)
                {
                    Scribe_Values.Look(ref bill_Medical.temp_partIndexToSetLater, "partIndex", -1);
                }
                FactionRelation factionRelation = obj as FactionRelation;
                if (factionRelation != null)
                {
                    bool value = false;
                    Scribe_Values.Look(ref value, "hostile", defaultValue: false);
                    if (value || factionRelation.goodwill <= -75)
                    {
                        factionRelation.kind = FactionRelationKind.Hostile;
                    }
                    else if (factionRelation.goodwill >= 75)
                    {
                        factionRelation.kind = FactionRelationKind.Ally;
                    }
                }
                HediffComp_GetsPermanent hediffComp_GetsPermanent = obj as HediffComp_GetsPermanent;
                if (hediffComp_GetsPermanent != null)
                {
                    bool value2 = false;
                    Scribe_Values.Look(ref value2, "isOld", defaultValue: false);
                    if (value2)
                    {
                        hediffComp_GetsPermanent.isPermanentInt = true;
                    }
                }
                if (obj is World)
                {
                    UniqueIDsManager target = null;
                    Scribe_Deep.Look(ref target, "uniqueIDsManager");
                    if (target != null)
                    {
                        Current.Game.uniqueIDsManager = target;
                    }
                }
                WorldFeature worldFeature = obj as WorldFeature;
                if (worldFeature != null && worldFeature.maxDrawSizeInTiles == 0f)
                {
                    Vector2 value3 = Vector2.zero;
                    Scribe_Values.Look(ref value3, "maxDrawSizeInTiles");
                    worldFeature.maxDrawSizeInTiles = value3.x;
                }
            }
            if (Scribe.mode != LoadSaveMode.ResolvingCrossRefs)
            {
                return;
            }
            Hediff hediff2 = obj as Hediff;

            if (hediff2 != null && hediff2.temp_partIndexToSetLater >= 0 && hediff2.pawn != null)
            {
                if (hediff2.temp_partIndexToSetLater == 0)
                {
                    hediff2.Part = hediff2.pawn.RaceProps.body.GetPartAtIndex(hediff2.temp_partIndexToSetLater);
                }
                else
                {
                    hediff2.pawn.health.hediffSet.hediffs.Remove(hediff2);
                }
                hediff2.temp_partIndexToSetLater = -1;
            }
            Bill_Medical bill_Medical2 = obj as Bill_Medical;

            if (bill_Medical2 != null)
            {
                if (bill_Medical2.temp_partIndexToSetLater == 0)
                {
                    bill_Medical2.Part = bill_Medical2.GiverPawn.RaceProps.body.GetPartAtIndex(bill_Medical2.temp_partIndexToSetLater);
                }
                else
                {
                    bill_Medical2.GiverPawn.BillStack.Bills.Remove(bill_Medical2);
                }
                bill_Medical2.temp_partIndexToSetLater = -1;
            }
        }
Esempio n. 7
0
 public static void SetPainCategory(Verse.HediffComp_GetsPermanent comp, PainCategory painCategory)
 {
     ReflectionCache.Instance.HediffComp_GetsPermanent_PainCategory.SetValue(comp, painCategory);
 }