public override void PostAdd(DamageInfo?dinfo)
        {
            if (base.Part == null)
            {
                Log.Error("Part is null. It should be set before PostAdd for " + this.def + ".", false);
                return;
            }

            this.pawn.health.RestorePart(base.Part, this, false);
            for (int i = 0; i < base.Part.parts.Count; i++)
            {
                if (base.Part.Index == 1)
                {
                    Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, this.pawn, null);
                    hediff_MissingPart.IsFresh    = true;
                    hediff_MissingPart.lastInjury = HediffDefOf.SurgicalCut;
                    hediff_MissingPart.Part       = base.Part.parts[i];
                    this.pawn.health.hediffSet.AddDirect(hediff_MissingPart, null, null);
                }
            }
        }
Example #2
0
        // Token: 0x06000021 RID: 33 RVA: 0x00002878 File Offset: 0x00000A78
        public static void ReplaceHediffFromBodypart(this Pawn pawn, BodyPartRecord startingPart, HediffDef hediffDef,
                                                     HediffDef replaceWithDef)
        {
            var hediffs = pawn.health.hediffSet.hediffs;
            var list    = new List <BodyPartRecord>();
            var list2   = new List <BodyPartRecord>
            {
                startingPart
            };

            do
            {
                list.AddRange(list2);
                list2.Clear();
                foreach (var item2 in list)
                {
                    for (var num = hediffs.Count - 1; num >= 0; num--)
                    {
                        var val = hediffs[num];
                        if (val.Part != item2 || val.def != hediffDef)
                        {
                            continue;
                        }

                        var val2 = hediffs[num];
                        hediffs.RemoveAt(num);
                        val2.PostRemoved();
                        var item = HediffMaker.MakeHediff(replaceWithDef, pawn, item2);
                        hediffs.Insert(num, item);
                    }

                    foreach (var bodyPartRecord in item2.parts)
                    {
                        list2.Add(bodyPartRecord);
                    }
                }

                list.Clear();
            } while (list2.Count > 0);
        }
Example #3
0
        public static void MakeWet(Pawn pawn)
        {
            HediffDef hediffDef = HediffDefOf.TKKN_Wetness;

            if (pawn.health.hediffSet.GetFirstHediffOfDef(hediffDef) == null && pawn.RaceProps.Humanlike)
            {
                Map     map = pawn.MapHeld;
                IntVec3 c   = pawn.Position;
                if (map == null || !c.IsValid)
                {
                    return;
                }
                bool isWet = false;
                if (map.weatherManager.curWeather.rainRate > .001f)
                {
                    Room room   = c.GetRoom(map, RegionType.Set_All);
                    bool roofed = map.roofGrid.Roofed(c);
                    bool flag2  = room != null && room.UsesOutdoorTemperature;
                    if (!roofed)
                    {
                        isWet = true;
                    }
                }
                else
                {
                    TerrainDef currentTerrain = c.GetTerrain(map);
                    if (currentTerrain.HasTag("TKKN_Wet"))
                    {
                        isWet = true;
                    }
                }

                if (isWet)
                {
                    Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn, null);
                    hediff.Severity = 0;
                    pawn.health.AddHediff(hediff, null, null);
                }
            }
        }
        public bool RegenerateBodyPart()
        {
            var injured   = pawn.health.hediffSet.GetInjuredParts();
            var missing   = pawn.health.hediffSet.GetMissingPartsCommonAncestors();
            var potential = missing.Where(x =>
                                          x.Part != null && (
                                              x.Part.parent == null || (
                                                  !injured.Contains(x.Part.parent) &&
                                                  !injured.Intersect(x.Part.parent.GetDirectChildParts()).Any()
                                                  )
                                              )
                                          );

            Hediff_MissingPart hediff = potential.RandomElementWithFallback();

            if (hediff == null)
            {
                return(false);
            }

            BodyPartRecord part = hediff.Part;

            pawn.health.hediffSet.hediffs.Remove(hediff);

            foreach (var subpart in part.GetDirectChildParts())
            {
                Hediff_MissingPart missingPart = HediffMaker.MakeHediff(RimWorld.HediffDefOf.MissingBodyPart, pawn, subpart) as Hediff_MissingPart;
                pawn.health.hediffSet.hediffs.Add(missingPart);
            }

            Hediff_Injury injury = HediffMaker.MakeHediff(RimWorld.HediffDefOf.Shredded, pawn, part) as Hediff_Injury;

            injury.Severity = part.def.hitPoints - 1;
            pawn.health.hediffSet.hediffs.Add(injury);

            pawn.health.hediffSet.DirtyCache();

            RadiologyEffectSpawnerDef.Spawn(def.effectRegeneration, pawn);
            return(true);
        }
Example #5
0
        /// <summary>Does the ingestion outcome special.</summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="ingested">The ingested.</param>
        protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested)
        {
            if (!pawn.health.hediffSet.hediffs.Any(x => hediffDefs.Contains(x.def)))
            {
                _scratchList.Clear();

                if (Rand.RangeInclusive(0, 100) <= completeChance)
                {
                    _scratchList.AddRange(hediffDefsComplete.Where(h => h.CanInfect(pawn)));
                }
                else
                {
                    _scratchList.AddRange(hediffDefs.Where(h => h.CanInfect(pawn)));
                }

                if (_scratchList.Count == 0)
                {
                    return;
                }
                _hediffDef = _scratchList.RandElement();

                Hediff hediff = HediffMaker.MakeHediff(_hediffDef, pawn);
                float  num;
                if (severity > 0f)
                {
                    num = severity;
                }
                else
                {
                    num = _hediffDef.initialSeverity;
                }
                if (divideByBodySize)
                {
                    num /= pawn.BodySize;
                }
                AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, toleranceChemical, ref num);
                hediff.Severity = num;
                pawn.health.AddHediff(hediff, null, null);
            }
        }
 public static void GenerateAddictionsAndTolerancesFor(Pawn pawn)
 {
     if (!pawn.RaceProps.IsFlesh || !pawn.RaceProps.Humanlike || pawn.IsTeetotaler())
     {
         return;
     }
     allDrugs.Clear();
     for (int i = 0; i < 3; i++)
     {
         if (Rand.Value >= pawn.kindDef.chemicalAddictionChance)
         {
             break;
         }
         if (!allDrugs.Any())
         {
             allDrugs.AddRange(DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef x) => x.category == ThingCategory.Item && x.GetCompProperties <CompProperties_Drug>() != null));
         }
         if (!DefDatabase <ChemicalDef> .AllDefsListForReading.Where((ChemicalDef x) => PossibleWithTechLevel(x, pawn.Faction) && !AddictionUtility.IsAddicted(pawn, x)).TryRandomElement(out var result))
         {
             break;
         }
         Hediff hediff = HediffMaker.MakeHediff(result.addictionHediff, pawn);
         hediff.Severity = GeneratedAddictionSeverityRange.RandomInRange;
         pawn.health.AddHediff(hediff);
         if (result.toleranceHediff != null && Rand.Value < result.onGeneratedAddictedToleranceChance)
         {
             Hediff hediff2 = HediffMaker.MakeHediff(result.toleranceHediff, pawn);
             hediff2.Severity = GeneratedToleranceSeverityRange.RandomInRange;
             pawn.health.AddHediff(hediff2);
         }
         if (result.onGeneratedAddictedEvents != null)
         {
             foreach (HediffGiver_Event onGeneratedAddictedEvent in result.onGeneratedAddictedEvents)
             {
                 onGeneratedAddictedEvent.EventOccurred(pawn);
             }
         }
         DoIngestionOutcomeDoers(pawn, result);
     }
 }
        internal static void TryToImpregnate(Pawn male, Pawn female)
        {
            // Only humans can be impregnated for now
            if (female.def.defName != "Human")
            {
                return;
            }

            BodyPartRecord torso         = female.RaceProps.body.AllParts.Find(x => x.def == BodyPartDefOf.Torso);
            HediffDef      contraceptive = HediffDef.Named("Contraceptive");

            // Make sure the woman is not pregnanct and not using a contraceptive
            if (female.health.hediffSet.HasHediff(HediffDefOf.Pregnant, torso) || female.health.hediffSet.HasHediff(contraceptive, null) || male.health.hediffSet.HasHediff(contraceptive, null))
            {
                return;
            }
            // Check the pawn's age to see how likely it is she can carry a fetus
            // 25 and below is guaranteed, 50 and above is impossible, 37.5 is 50% chance
            float preg_chance = Math.Max(1 - (Math.Max(female.ageTracker.AgeBiologicalYearsFloat - 25, 0) / 25), 0) * 0.33f;

            if (preg_chance < Rand.Value)
            {
                //Log.Message ("Impregnation failed. Chance was " + preg_chance);
                return;
            }
            //Log.Message ("Impregnation succeeded. Chance was " + preg_chance);
            // Spawn a bunch of hearts. Sharp eyed players may notice this means impregnation occurred.
            for (int i = 0; i <= 3; i++)
            {
                MoteMaker.ThrowMetaIcon(male.Position, male.MapHeld, ThingDefOf.Mote_Heart);
                MoteMaker.ThrowMetaIcon(female.Position, male.MapHeld, ThingDefOf.Mote_Heart);
            }

            // Do the actual impregnation. We apply it to the torso because Remove_Hediff in operations doesn't work on WholeBody (null body part)
            // for whatever reason.
            Hediff_HumanPregnancy hediff_Pregnant = (Hediff_HumanPregnancy)HediffMaker.MakeHediff(HediffDef.Named("HumanPregnancy"), female, torso);

            hediff_Pregnant.father = male;
            female.health.AddHediff(hediff_Pregnant, torso, null);
        }
        protected override void Impact(Thing hitThing)
        {
            base.Impact(hitThing);

            if (Props != null && hitThing != null && hitThing is Pawn hitPawn)
            {
                float rand = Rand.Value;
                if (rand <= Props.addHediffChance)
                {
                    Messages.Message("SK_Bullet_SuccessMessage".Translate(
                                         this.launcher.Label, hitPawn.Label
                                         ), MessageTypeDefOf.NeutralEvent);

                    // 判断一下目标是否已经触发了瘟疫效果
                    Hediff plagueOnPawn   = hitPawn.health?.hediffSet?.GetFirstHediffOfDef(Props.hediffToAdd);
                    float  randomSeverity = Rand.Range(0.15f, 0.30f);
                    // 已经触发瘟疫
                    if (plagueOnPawn != null)
                    {
                        // 严重程度叠加,超过100%会即死
                        plagueOnPawn.Severity += randomSeverity;
                    }
                    else
                    {
                        // 我们调用HediffMaker.MakeHediff生成一个新的hediff状态,类型就是我们之前设置过的HediffDefOf.Plague瘟疫类型
                        Hediff hediff = HediffMaker.MakeHediff(Props.hediffToAdd, hitPawn);
                        // 严重程度
                        hediff.Severity = randomSeverity;
                        // 把状态添加到被击中目标的身上
                        hitPawn.health.AddHediff(hediff);
                    }
                }
                //本次没有触发
                else
                {
                    //这个方法可以在某个位置(这里是被击中目标的身旁)弹出一小行字,比如未击中,击中头部之类的,也是可以
                    MoteMaker.ThrowText(hitThing.PositionHeld.ToVector3(), hitThing.MapHeld, "SK_Bullet_FailureMote".Translate(Props.addHediffChance), 12f);
                }
            }
        }
        public override bool TryExecute(IncidentParms parms)
        {
            Map     map    = (Map)parms.target;
            Faction player = Find.FactionManager.AllFactions.ToList().Find((Faction x) => x.IsPlayer);
            Pawn    thief  = PawnGenerator.GeneratePawn(DefDatabase <PawnKindDef> .GetNamed("Scavenger"), Find.FactionManager.RandomEnemyFaction());
            IntVec3 intVec;

            if (!RCellFinder.TryFindRandomPawnEntryCell(out intVec, map))
            {
                return(false);
            }
            GenSpawn.Spawn(thief, intVec, map);
            Hediff hediff = HediffMaker.MakeHediff(HediffDefOfPsychology.Thief, thief, null);

            thief.health.AddHediff(hediff);
            IntVec3 c;

            if (!RCellFinder.TryFindBestExitSpot(thief, out c, TraverseMode.ByPawn))
            {
                return(false);
            }
            List <Thing> valuables = (from t in map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableAlways)
                                      where (t.MarketValue * Mathf.Min(t.stackCount, (int)(thief.GetStatValue(StatDefOf.CarryingCapacity, true) / t.def.VolumePerUnit))) >= 250 && HaulAIUtility.PawnCanAutomaticallyHaulFast(thief, t)
                                      select t).ToList();

            if (valuables.Count == 0)
            {
                thief.Destroy();
                return(false);
            }
            Thing valuable = valuables.RandomElement();

            thief.jobs.StartJob(new Job(JobDefOf.Steal)
            {
                targetA = valuable,
                targetB = c,
                count   = Mathf.Min(valuable.stackCount, (int)(thief.GetStatValue(StatDefOf.CarryingCapacity, true) / valuable.def.VolumePerUnit))
            });
            return(true);
        }
Example #10
0
        private void SetQueenHediffSeverity(Pawn pawn)
        {
            float severity = 0f;

            int score = -1;

            score = HiveQueenUtility.GetPawnHQScore(pawn);

            if (score < 0)
            {
                score *= 2;
            }

            score += QueenStrength;

            if (score > 0)
            {
                severity = score * .1f;
                severity = Math.Min(severity, 1f);
            }
            else
            {
                severity = 0f;
            }

            // do hediff
            Hediff olddiff = pawn.health.hediffSet.GetFirstHediffOfDef(AntHQDefOf.Ant_HiveQueenInspHediff, false);

            if (olddiff != null)
            {
                pawn.health.RemoveHediff(olddiff);
            }

            if (severity > 0f)
            {
                Hediff hediff = HediffMaker.MakeHediff(AntHQDefOf.Ant_HiveQueenInspHediff, pawn, null);
                hediff.Severity = severity;
                pawn.health.AddHediff(hediff, null, null, null);
            }
        }
        private void CheckPropagateDamageToInnerSolidParts(DamageInfo dinfo, Pawn pawn, Hediff_Injury injury, bool involveArmor, ref DamageWorker_AddInjuryCE.LocalInjuryResult result)
        {
            if (!dinfo.AllowDamagePropagation)
            {
                return;
            }
            if (Rand.Value >= HealthTunings.ChanceToAdditionallyDamageInnerSolidPart)
            {
                return;
            }
            if (dinfo.Def.hasChanceToAdditionallyDamageInnerSolidParts && !injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) && injury.Part.depth == BodyPartDepth.Outside)
            {
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)
                                                      where x.parent == injury.Part && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside
                                                      select x;
                BodyPartRecord part;
                if (source.TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out part))
                {
                    HediffDef     hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, part);
                    Hediff_Injury hediff_Injury       = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
                    hediff_Injury.Part   = part;
                    hediff_Injury.source = injury.source;
                    hediff_Injury.sourceBodyPartGroup = injury.sourceBodyPartGroup;
                    hediff_Injury.Severity            = (float)(dinfo.Amount / 2);

                    /*
                     * if (involveArmor)
                     * {
                     *  hediff_Injury.Severity = (float)ArmorUtility.GetAfterArmorDamage(pawn, dinfo.Amount / 2, part, dinfo.Def);
                     * }
                     */
                    if (hediff_Injury.Severity <= 0f)
                    {
                        return;
                    }
                    result.lastHitPart = hediff_Injury.Part;
                    this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, ref result);
                }
            }
        }
Example #12
0
        private void CallAid(Pawn caller, Map map, Faction faction, bool free, float biocodeWeaponsChance = 1f)
        {
            List <Thing>   sendColonists = new List <Thing>();
            Pawn           pawn          = PawnGenerator.GeneratePawn(PawnKindDef.Named("Tribal_Warrior"), null);
            Hediff         hediff        = HediffMaker.MakeHediff(HediffDefOf.PsychicShock, pawn);
            BodyPartRecord result        = null;

            pawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource).TryRandomElement(out result);
            pawn.health.AddHediff(hediff, result);

            sendColonists.Add(pawn);

            DropPodUtility.DropThingsNear(DropCellFinder.TradeDropSpot(map), map, sendColonists,
                                          110, canInstaDropDuringInit: false, leaveSlag: false, canRoofPunch: true, forbid: false);

            faction.lastMilitaryAidRequestTick = Find.TickManager.TicksGame;
            if (!free)
            {
                caller.royalty.TryRemoveFavor(faction, def.royalAid.favorCost);
            }
            caller.royalty.Notify_PermitUsed(def);
        }
Example #13
0
        public void ApplyHediff(Pawn pawn)
        {
            for (int i = 0; i < Props.triggeredHediff.Count; i++)
            {
                HediffDef curHD = Props.triggeredHediff[i];

                if (curHD == null)
                {
                    Tools.Warn("cant find hediff; i=" + i, true);
                    return;
                }
                Hediff hediff2apply = HediffMaker.MakeHediff(curHD, pawn, null);
                if (hediff2apply == null)
                {
                    Tools.Warn("cant create hediff " + curHD.defName, true);
                    return;
                }

                Tools.Warn("Adding " + curHD.defName + "for science", Props.debug);
                pawn.health.AddHediff(hediff2apply, null, null);
            }
        }
Example #14
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            Pawn pawn = parent.pawn;

            if (pawn.Spawned)
            {
                onItem = 0;
                foreach (HediffDef hediffDef in conflictingHediffs)
                {
                    Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn, null);
                    if (pawn.health.hediffSet.HasHediff(hediffDef))
                    {
                        pawn.health.RemoveHediff(pawn.health.hediffSet.GetFirstHediffOfDef(hediffDef));
                        if (!(hediffDef.spawnThingOnRemoved == null))
                        {
                            GenSpawn.Spawn(hediffDef.spawnThingOnRemoved, pawn.Position, pawn.Map, WipeMode.Vanish);
                        }
                        Log.Message("Removed hediff: " + hediffDef.defName.ToString() + " from pawn " + hediff.pawn.ToString());
                    }
                }
            }
        }
 public override void Tick()
 {
     if (pawn.Downed)
     {
         absorbedDamage = 0f;
     }
     if (!pawn.IsFighting() && pawn.IsHashIntervalTick(120))
     {
         absorbedDamage -= 1f;
         if (absorbedDamage < 0f)
         {
             absorbedDamage = 0f;
         }
     }
     if (absorbedDamage > 75f)
     {
         Hediff returnDamageHediff = new Hediff();
         returnDamageHediff = HediffMaker.MakeHediff(RWBYDefOf.RWBY_YangReturnDamage, pawn);
         pawn.health.AddHediff(returnDamageHediff);
     }
     base.Tick();
 }
Example #16
0
        public static void GiveSideEffects(Pawn pawn)
        {
            BodyPartRecord brain  = pawn.health.hediffSet.GetBrain();
            Hediff         hediff = HediffMaker.MakeHediff(HediffDefOf.ResurrectionSickness, pawn, null);

            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
            {
                pawn.health.AddHediff(hediff, null, null, null);
            }
            if (Rand.Chance(0.8f) && brain != null)
            {
                Hediff hediff2 = HediffMaker.MakeHediff(HediffDefOf.Dementia, pawn, brain);
                if (!pawn.health.WouldDieAfterAddingHediff(hediff2))
                {
                    pawn.health.AddHediff(hediff2, null, null, null);
                }
            }
            if (Rand.Chance(0.8f))
            {
                foreach (BodyPartRecord bodyPartRecord in Enumerable.Where <BodyPartRecord>(pawn.health.hediffSet.GetNotMissingParts(0, 0, null, null), (BodyPartRecord x) => x.def == BodyPartDefOf.Eye))
                {
                    Hediff hediff3 = HediffMaker.MakeHediff(HediffDefOf.Blindness, pawn, bodyPartRecord);
                    pawn.health.AddHediff(hediff3, null, null, null);
                }
            }
            if (brain != null && Rand.Chance(0.8f))
            {
                Hediff hediff4 = HediffMaker.MakeHediff(HediffDefOf.ResurrectionPsychosis, pawn, brain);
                if (!pawn.health.WouldDieAfterAddingHediff(hediff4))
                {
                    pawn.health.AddHediff(hediff4, null, null, null);
                }
            }
            if (pawn.Dead)
            {
                Log.Error("The pawn has died while being resurrected.", false);
                ResurrectionUtility.Resurrect(pawn);
            }
        }
Example #17
0
        public void DoOPToxicGas(Thing Gas, Thing targ)
        {
            Pawn pawn = targ as Pawn;

            if (pawn != null && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Breathing))
            {
                HediffDef namedSilentFail = DefDatabase <HediffDef> .GetNamedSilentFail(OPToxicDefGetValue.OPToxicGetHediff(Gas.def));

                if (namedSilentFail != null)
                {
                    Pawn_HealthTracker health = pawn.health;
                    Hediff             hediff;
                    if (health == null)
                    {
                        hediff = null;
                    }
                    else
                    {
                        HediffSet hediffSet = health.hediffSet;
                        hediff = ((hediffSet != null) ? hediffSet.GetFirstHediffOfDef(namedSilentFail, false) : null);
                    }
                    float statValue = pawn.GetStatValue(StatDefOf.ToxicSensitivity, true);
                    float num       = OPToxicDefGetValue.OPToxicGetSev(Gas.def);
                    if (num < 0.01f)
                    {
                        num = 0.01f;
                    }
                    float num2 = Rand.Range(0.01f * statValue, num * statValue);
                    if (hediff != null && num2 > 0f)
                    {
                        hediff.Severity += num2;
                        return;
                    }
                    Hediff hediff2 = HediffMaker.MakeHediff(namedSilentFail, pawn, null);
                    hediff2.Severity = num2;
                    pawn.health.AddHediff(hediff2, null, null, null);
                }
            }
        }
        // Token: 0x06003563 RID: 13667 RVA: 0x00123774 File Offset: 0x00121974
        protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested)
        {
            this.hediffDef = this.hediffDefs.RandomElement();
            Hediff hediff = HediffMaker.MakeHediff(this.hediffDef, pawn, null);
            float  num;

            if (this.severity > 0f)
            {
                num = this.severity;
            }
            else
            {
                num = this.hediffDef.initialSeverity;
            }
            if (this.divideByBodySize)
            {
                num /= pawn.BodySize;
            }
            AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, this.toleranceChemical, ref num);
            hediff.Severity = num;
            pawn.health.AddHediff(hediff, null, null, null);
        }
Example #19
0
        /// <summary>
        /// Updates the light sickness hediff.
        /// </summary>
        private void UpdateLightSickness()
        {
            if (adaptationComp.CanSee && !IgnoreLightLevel && LightLevel > adaptationComp.MaxLightLevel && CurStageIndex > 0 && !pawn.health.hediffSet.HasHediff(lightSickness))
            {
                Hediff hediff = HediffMaker.MakeHediff(lightSickness, pawn);
                hediff.Severity = this.Severity;

                if (!pawn.health.WouldDieAfterAddingHediff(hediff))
                {
                    pawn.health.AddHediff(hediff);
                }
            }
            else if (pawn.IsHashIntervalTick(480) && pawn.health.hediffSet.HasHediff(lightSickness)) // Check to see if we want to adjust lightSickness far less often than adding it.
            {
                Hediff_CuteboldLightSickness hediff = (Hediff_CuteboldLightSickness)pawn.health.hediffSet.GetFirstHediffOfDef(lightSickness);
                if (LightLevel > adaptationComp.MaxLightLevel && CurStageIndex != 0)
                {
                    hediff.Severity = this.Severity;
                    hediff.ResetTicksToDisappear();
                }
            }
        }
Example #20
0
        public override DamageResult Apply(DamageInfo dinfo, Thing thing)
        {
            if (thing is Pawn pawn && dinfo.Amount >= 15)
            {
                if (Rand.Chance(0.8f))
                {
                    List <BodyPartRecord> list = (from x in pawn.RaceProps.body.AllParts
                                                  where !pawn.health.hediffSet.PartIsMissing(x) &&
                                                  x.depth == BodyPartDepth.Outside &&
                                                  x.coverage > 0.1f
                                                  select x).ToList <BodyPartRecord>();

                    if (list.TryRandomElement <BodyPartRecord>(out var bodyPartRecord))
                    {
                        var missingBodyPart = HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn, bodyPartRecord);
                        pawn.health.AddHediff(missingBodyPart);
                    }
                }
            }

            return(base.Apply(dinfo, thing));
        }
        /// <summary>
        ///     Applies the pure mutagenic damage.
        /// </summary>
        /// this does not actually damage the pawn
        /// <param name="dInfo">The damage info.</param>
        /// <param name="pawn">The pawn.</param>
        /// <param name="mutationHediffDef">The mutation hediff definition.</param>
        /// <param name="severityPerDamage">The severity per damage.</param>
        /// <param name="mutagen">The mutagen.</param>
        public static void ApplyPureMutagenicDamage(DamageInfo dInfo, [NotNull] Pawn pawn,
                                                    HediffDef mutationHediffDef = null,
                                                    float severityPerDamage     = SEVERITY_PER_DAMAGE, MutagenDef mutagen = null)
        {
            mutagen = mutagen ?? MutagenDefOf.defaultMutagen;
            MutagenicDamageExtension ext = dInfo.Weapon?.GetModExtension <MutagenicDamageExtension>()
                                           ?? dInfo.Def?.GetModExtension <MutagenicDamageExtension>();

            mutationHediffDef = mutationHediffDef
                                ?? ext?.mutagenicBuildup
                                ?? MorphTransformationDefOf.MutagenicBuildup_Weapon;
            //first check if we're given a specific hediff to use
            //then use what's ever attached to the damage def
            //then use the default

            float severityToAdd = Mathf.Clamp(dInfo.Amount * severityPerDamage, 0, mutationHediffDef.maxSeverity);

            Hediff hediff = HediffMaker.MakeHediff(mutationHediffDef, pawn);

            hediff.Severity = severityToAdd;
            pawn.health.AddHediff(hediff);
        }
Example #22
0
        //咖喱技能2
        public static Command_CastSkill Skill2()
        {
            var ck = new Command_CastSkill
            {
                defaultLabel    = "MesaSkill2.name".Translate(),
                icon            = ContentFinder <Texture2D> .Get("Skills/MesaSkill2"),
                targetingParams = WarframeStaticMethods.OnlyPawn(),
                cooldownTime    = 1f,
                range           = 1f,
                hotKey          = KeyBindingDefOf.Misc8
            };

            ck.action = delegate(Pawn self)
            {
                foreach (var hef in self.health.hediffSet.hediffs)
                {
                    if (hef.def.defName != "WFMesa2Skill_Mesa")
                    {
                        continue;
                    }

                    Messages.Message("MesaSkillUsing".Translate(), MessageTypeDefOf.RejectInput, false);
                    return;
                }


                SoundDef.Named("Mesa_2Skill").PlayOneShot(self);
                var hediff = (Hediff_Mesa2Skill)HediffMaker.MakeHediff(HediffDef.Named("WFMesa2Skill_Mesa"), self);
                hediff.level = (int)self.GetLevel();
                self.health.AddHediff(hediff);


                WarframeStaticMethods.StartCooldown(self, ck.cooldownTime * (1 + (self.GetLevel() * 1f / 10f)), 2,
                                                    WarframeStaticMethods.GetArmor(self).TryGetComp <CompWarframeSkill>().Props.mana2);
            };


            return(ck);
        }
 private void CheckPropagateDamageToInnerSolidParts(DamageInfo dinfo, Pawn pawn, Hediff_Injury injury, bool involveArmor, int postArmorDamage, ref DamageWorker_AddInjuryCR.LocalInjuryResult result)
 {
     if (!dinfo.AllowDamagePropagation)
     {
         return;
     }
     if (Rand.Value >= HealthTunings.ChanceToAdditionallyDamageInnerSolidPart)
     {
         return;
     }
     if (dinfo.Def.hasChanceToAdditionallyDamageInnerSolidParts && !injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) && injury.Part.depth == BodyPartDepth.Outside)
     {
         IEnumerable <BodyPartRecord> enumerable = pawn.health.hediffSet.GetNotMissingParts(null, null).Where(x => x.parent == injury.Part && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside);
         BodyPartRecord part;
         if (DamageWorker_AddInjuryCR.cache0 == null)
         {
             DamageWorker_AddInjuryCR.cache0 = delegate(BodyPartRecord x) { return(x.absoluteFleshCoverage); };
         }
         if (enumerable.TryRandomElementByWeight(DamageWorker_AddInjuryCR.cache0, out part))
         {
             HediffDef     hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, part);
             Hediff_Injury hediff_Injury       = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
             hediff_Injury.Part   = part;
             hediff_Injury.source = injury.source;
             hediff_Injury.sourceBodyPartGroup = injury.sourceBodyPartGroup;
             hediff_Injury.Severity            = (float)(dinfo.Amount / 2);
             if (involveArmor)
             {
                 hediff_Injury.Severity = (float)postArmorDamage;
             }
             if (hediff_Injury.Severity <= 0f)
             {
                 return;
             }
             result.lastHitPart = hediff_Injury.Part;
             this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, ref result);
         }
     }
 }
Example #24
0
        public static void ChangePsylinkLevel(this Pawn pawn, int levelOffset, bool sendLetter = true)
        {
            Hediff_Psylink mainPsylinkSource = pawn.GetMainPsylinkSource();

            if (mainPsylinkSource == null)
            {
                mainPsylinkSource = (Hediff_Psylink)HediffMaker.MakeHediff(HediffDefOf.PsychicAmplifier, pawn);
                try
                {
                    mainPsylinkSource.suppressPostAddLetter = !sendLetter;
                    pawn.health.AddHediff(mainPsylinkSource, pawn.health.hediffSet.GetBrain());
                }
                finally
                {
                    mainPsylinkSource.suppressPostAddLetter = false;
                }
            }
            else
            {
                mainPsylinkSource.ChangeLevel(levelOffset, sendLetter);
            }
        }
        /// <summary>
        /// called when this instance impacts the specified thing.
        /// </summary>
        /// <param name="hitThing">The hit thing.</param>
        protected override void Impact(Thing hitThing)
        {
            base.Impact(hitThing);
            Pawn hitPawn;

            if (Def != null && hitThing != null && hitThing is Pawn)
            {
                hitPawn = (Pawn)hitThing; // Already checked above.

                if (!Def.CanAddHediffToPawn(hitPawn))
                {
                    return;                      //if the hediff can't be added to the hit pawn just abort
                }
                float rand = Rand.Value;         // This is a random percentage between 0% and 100%
                if (rand <= Def.AddHediffChance) // If the percentage falls under the chance, success!
                {
                    //This checks to see if the character has a heal differential, or hediff on them already.
                    Hediff etherOnPawn = hitPawn.health?.hediffSet?.GetFirstHediffOfDef(Def.HediffToAdd);

                    if (etherOnPawn == null)
                    {
                        //These three lines create a new health differential or Hediff,
                        //put them on the character, and increase its severity by a random amount.
                        Hediff hediff = HediffMaker.MakeHediff(Def.HediffToAdd, hitPawn);
                        hitPawn.health?.AddHediff(hediff);

                        //this should be an interface
                        var syringeHediff = hediff as SyringeRifleTf;

                        //hacky, want to figure out a better way to find the weapon that will allow turrets as well
                        var weapon = (launcher as Pawn)?.equipment?.Primary;

                        syringeHediff?.Initialize(weapon);

                        IntermittentMagicSprayer.ThrowMagicPuffDown(hitPawn.Position.ToVector3(), Map);
                    }
                }
            }
        }
Example #26
0
    public void DoUSTangleKillGasToxic(Thing Gas, Thing targ)
    {
        if (targ is not Pawn victim || !victim.health.capacities.CapableOf(PawnCapacityDefOf.Breathing))
        {
            return;
        }

        var    health = victim.health;
        Hediff hediff;

        if (health == null)
        {
            hediff = null;
        }
        else
        {
            var hediffSet = health.hediffSet;
            hediff = hediffSet?.GetFirstHediffOfDef(Globals.USTangleRootStrike);
        }

        var sensitivity = victim.GetStatValue(StatDefOf.ToxicSensitivity);
        var addsev      = Rand.Range(0.0249999985f * sensitivity * toxicRatio, 0.125f * sensitivity * toxicRatio);

        if (Globals.USVictimImmuneTo(victim, Globals.USTangleRootStrike))
        {
            return;
        }

        if (hediff != null && addsev > 0f)
        {
            hediff.Severity += addsev;
            return;
        }

        var addhediff = HediffMaker.MakeHediff(Globals.USTangleRootStrike, victim);

        addhediff.Severity = addsev;
        victim.health.AddHediff(addhediff);
    }
Example #27
0
        bool TryApply(Pawn pawn, BodyPartRecord recordToAdd, [NotNull] MutagenDef mutagen, HashSet <BodyPartRecord> nonMissingRecords)
        {
            if (!mutagen.CanInfect(pawn))
            {
                return(false);
            }
            if (!nonMissingRecords.Contains(recordToAdd))
            {
                return(false);
            }
            if (!hediff.IsValidFor(pawn))
            {
                return(false);
            }
            var hediffInst = HediffMaker.MakeHediff(hediff, pawn, recordToAdd);

            pawn.health.AddHediff(hediffInst, recordToAdd);
            DoMutationAddedEffects(pawn);
            AddMutationLogFor(pawn);

            return(true);
        }
        //
        // Static Methods
        //
        public static void GenerateRandomOldAgeInjuries(Pawn pawn, bool tryNotToKillPawn)
        {
            int num = 0;

            for (int i = 10; i < pawn.ageTracker.AgeBiologicalYears; i += 10)
            {
                if (Rand.Value < 0.15)
                {
                    num++;
                }
            }
            for (int j = 0; j < num; j++)
            {
                DamageDef dam  = AgeInjuryUtility.RandomOldInjuryDamageType();
                int       num2 = Rand.RangeInclusive(2, 6);
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)
                                                      where x.depth == BodyPartDepth.Outside && !Mathf.Approximately(x.def.oldInjuryBaseChance, 0) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x)
                                                      select x;
                if (source.Any <BodyPartRecord>())
                {
                    BodyPartRecord bodyPartRecord      = source.RandomElementByWeight((BodyPartRecord x) => x.absoluteFleshCoverage);
                    HediffDef      hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dam, pawn, bodyPartRecord);
                    if (bodyPartRecord.def.oldInjuryBaseChance > 0 && hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsOld)) != null)
                    {
                        Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
                        hediff_Injury.Severity = (float)num2;
                        hediff_Injury.TryGetComp <HediffComp_GetsOld>().IsOld = true;
                        pawn.health.AddHediff(hediff_Injury, bodyPartRecord, null);
                    }
                }
            }
            for (int k = 1; k < pawn.ageTracker.AgeBiologicalYears; k++)
            {
                foreach (HediffGiver_Birthday current in AgeInjuryUtility.RandomHediffsToGainOnBirthday(pawn, k))
                {
                    current.TryApplyAndSimulateSeverityChange(pawn, (float)k, tryNotToKillPawn);
                }
            }
        }
        protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested)
        {
            MilkThistleBenefit = HediffDef.Named("MilkThistleBenefit");

            List <Hediff> Hediffs = pawn.health.hediffSet.GetHediffs <Hediff>().ToList();

            foreach (Hediff hediffList in Hediffs)
            {
                if (hediffList.ToString().Contains("Cirrhosis"))
                {
                    Hediff hediff = HediffMaker.MakeHediff(this.hediffDef, pawn, null);
                    float  num    = (!(this.severity > 0f)) ? this.hediffDef.initialSeverity : this.severity;
                    if (this.divideByBodySize)
                    {
                        num /= pawn.BodySize;
                    }
                    AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, this.toleranceChemical, ref num);
                    hediff.Severity = num;
                    pawn.health.AddHediff(hediff, null, null);
                }
            }
        }
Example #30
0
 // Token: 0x06000064 RID: 100 RVA: 0x00005F24 File Offset: 0x00004124
 internal static bool HediffEffect(HediffDef hediffdef, float SeverityToApply, Pawn pawn, BodyPartRecord part, out bool immune)
 {
     immune = false;
     if (!pawn.RaceProps.IsMechanoid && hediffdef != null)
     {
         if (!MSHediffEffecter.ImmuneTo(pawn, hediffdef))
         {
             if (!pawn.health.WouldDieAfterAddingHediff(hediffdef, part, SeverityToApply))
             {
                 Pawn_HealthTracker health = pawn.health;
                 Hediff             hediff;
                 if (health == null)
                 {
                     hediff = null;
                 }
                 else
                 {
                     HediffSet hediffSet = health.hediffSet;
                     hediff = (hediffSet?.GetFirstHediffOfDef(hediffdef, false));
                 }
                 Hediff hashediff = hediff;
                 if (hashediff != null)
                 {
                     hashediff.Severity += SeverityToApply;
                     return(true);
                 }
                 Hediff addhediff = HediffMaker.MakeHediff(hediffdef, pawn, part);
                 addhediff.Severity = SeverityToApply;
                 pawn.health.AddHediff(addhediff, part, null, null);
                 return(true);
             }
         }
         else
         {
             immune = true;
         }
     }
     return(false);
 }