Exemple #1
0
        public static void RemoveCommUnit(X2_AIRobot pawn)
        {
            // Do not remove, if one of the following work types:
            if (pawn.workSettings.GetPriority(WorkTypeDefOf.Doctor) > 0 ||
                pawn.workSettings.GetPriority(WorkTypeDefOf.Handling) > 0 ||
                pawn.workSettings.GetPriority(WorkTypeDefOf.Warden) > 0)
            {
                return;
            }

            PawnCapacityDef activity = PawnCapacityDefOf.Talking;

            if (pawn.health.capacities.CapableOf(activity))
            {
                HediffSet hediffSet = pawn.health.hediffSet;
                IEnumerable <BodyPartRecord> notMissingParts = hediffSet.GetNotMissingParts();

                BodyPartRecord bodyPart = notMissingParts.Where(p => p.def.defName == "AIRobot_CommUnit").FirstOrDefault();

                if (bodyPart != null)
                {
                    DamageInfo damageInfo = new DamageInfo(DamageDefOf.EMP, Mathf.RoundToInt(hediffSet.GetPartHealth(bodyPart)), 0f, -1f, null, bodyPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null);
                    //pawn.TakeDamage(damageInfo);


                    Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn, null);
                    hediff_MissingPart.IsFresh    = false;
                    hediff_MissingPart.lastInjury = null;
                    pawn.health.AddHediff(hediff_MissingPart, bodyPart, damageInfo);
                    pawn.health.Notify_HediffChanged(hediff_MissingPart);

                    pawn.apparel.Notify_LostBodyPart();
                }
            }
        }
 private static IEnumerable <BodyPartRecord> HittablePartsViolence(HediffSet bodyModel)
 {
     return(bodyModel.GetNotMissingParts()
            .Where(x => x.depth == BodyPartDepth.Outside ||
                   x.depth == BodyPartDepth.Inside &&
                   x.def.IsSolid(x, bodyModel.hediffs)));
 }
        protected override DamageWorker.DamageResult ApplyMeleeDamageToTarget(LocalTargetInfo target)
        {
            DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult();
            if (tool == null)
            {
                Log.ErrorOnce("Attempted to apply melee hediff without a tool", 38381735);
                return(damageResult);
            }
            Pawn pawn = target.Thing as Pawn;

            if (pawn == null)
            {
                Log.ErrorOnce("Attempted to apply melee hediff without pawn target", 78330053);
                return(damageResult);
            }
            HediffSet      hediffSet         = pawn.health.hediffSet;
            BodyPartTagDef bodypartTagTarget = verbProps.bodypartTagTarget;

            foreach (BodyPartRecord notMissingPart in hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, bodypartTagTarget))
            {
                damageResult.AddHediff(pawn.health.AddHediff(tool.hediff, notMissingPart));
                damageResult.AddPart(pawn, notMissingPart);
                damageResult.wounded = true;
            }
            return(damageResult);
        }
 private static IEnumerable <BodyPartRecord> HittablePartsViolence(HediffSet bodyModel)
 {
     return
         (from x in bodyModel.GetNotMissingParts(null, null)
          where x.depth == BodyPartDepth.Outside || (x.depth == BodyPartDepth.Inside && x.def.IsSolid(x, bodyModel.hediffs))
          select x);
 }
 public static BodyPartRecord GetSpine(this HediffSet hediffSet)
 {
     foreach (BodyPartRecord notMissingPart in hediffSet.GetNotMissingParts())
     {
         if (notMissingPart.def.tags.Contains(BodyPartTagDefOf.Spine))
         {
             return(notMissingPart);
         }
     }
     return(null);
 }
 public static BodyPartRecord GetBodyPartRecord(this HediffSet hediffSet, BodyPartDef bodyPartDef)
 {
     foreach (BodyPartRecord bodyPartRecord in hediffSet.GetNotMissingParts(new BodyPartHeight?(), new BodyPartDepth?()))
     {
         if (bodyPartRecord.def == bodyPartDef)
         {
             return(bodyPartRecord);
         }
     }
     return((BodyPartRecord)null);
 }
Exemple #7
0
 public static BodyPartRecord GetHeart(HediffSet set)
 {
     foreach (BodyPartRecord current in set.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
     {
         for (int i = 0; i < current.def.tags.Count; i++)
         {
             if (current.def.tags[i] == "BloodPumpingSource")
             {
                 return(current);
             }
         }
     }
     return(null);
 }
 private static bool Prefix(HediffSet __instance, bool?___cachedHasHead, ref bool __result)
 {
     if (__instance.pawn.def is RaceAddonThingDef thingDef)
     {
         bool?flag = ___cachedHasHead;
         if (!flag.HasValue)
         {
             ___cachedHasHead = new bool?(__instance.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).Any((BodyPartRecord x) => x.def == thingDef.raceAddonSettings.basicSetting.raceHeadDef));
         }
         __result = ___cachedHasHead.Value;
         return(false);
     }
     return(true);
 }
        public static BodyPartRecord GetHeart(HediffSet set)
        {
            foreach (var current in set.GetNotMissingParts())
            {
                foreach (var bodyPartTagDef in current.def.tags)
                {
                    if (bodyPartTagDef.defName == "BloodPumpingSource")
                    {
                        return(current);
                    }
                }
            }

            return(null);
        }
        public static BodyPartRecord GetNose(HediffSet set)
        {
            foreach (var current in set.GetNotMissingParts())
            {
                for (var i = 0; i < current.def.tags.Count; i++)
                {
                    if (current.def.defName == "Nose")
                    {
                        return(current);
                    }
                }
            }

            return(null);
        }
            public static bool PreFix(ref float __result, HediffSet diffSet, BodyPartRecord part, List <PawnCapacityUtility.CapacityImpactor> impactors)
            {
                // if the part is missing
                if (!diffSet.GetNotMissingParts().Contains(part))
                {
                    __result = 0f; // it has 0 efficiency

                    // if possible add it to the list of things affecting the stat
                    if (impactors != null)
                    {
                        if (part.parent == null || diffSet.GetNotMissingParts().Contains(part.parent))
                        {
                            var imp = new PawnCapacityUtility.CapacityImpactorBodyPartHealth {
                                bodyPart = part
                            };

                            impactors.Add(imp);
                        }
                    }

                    return(false);
                }
                return(true);
            }
Exemple #12
0
        /// <summary>
        /// Gets all non missing without prosthetics.
        /// </summary>
        /// <param name="hSet">The h set.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">hSet</exception>
        public static IEnumerable <BodyPartRecord> GetAllNonMissingWithoutProsthetics([NotNull] this HediffSet hSet)
        {
            if (hSet == null)
            {
                throw new ArgumentNullException(nameof(hSet));
            }

            foreach (BodyPartRecord notMissingPart in hSet.GetNotMissingParts().MakeSafe())
            {
                if (hSet.hediffs.Any(h => h.Part == notMissingPart && h.IsProsthetic()))
                {
                    continue;
                }
                yield return(notMissingPart);
            }
        }
Exemple #13
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);



            {
                Pawn_EquipmentTracker pe = base.Pawn.equipment;
                Pawn_ApparelTracker   pa = base.Pawn.apparel;
                if (base.Pawn.Faction == Faction.OfPlayer)
                {
                    if (base.Pawn.kindDef.defName == "ra2_AlliedTanya")
                    {
                    }
                    else if (pe.Primary == null || pe.Primary.def != getDefaultGun(base.Pawn.kindDef.defName))
                    {
                        pe.Remove(pe.Primary);
                        pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(getDefaultGun(base.Pawn.kindDef.defName)));
                    }

                    if (base.Pawn.kindDef.defName == "ra2_AlliedChrono")
                    {
                        bool hasHat = false;
                        foreach (Apparel ap in base.Pawn.apparel.WornApparel)
                        {
                            if (ap.def.defName == "ra2_Hat_Chrono")
                            {
                                hasHat = true;
                                break;
                            }
                        }
                        if (!hasHat)
                        {
                            base.Pawn.apparel.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Hat_Chrono", true)));
                        }
                    }

                    if (pa.WornApparel == null)
                    {
                        pa.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Belt", true)));
                    }

                    bool hasBelt = false;
                    foreach (Apparel ap in pa.WornApparel)
                    {
                        if (ap.def.defName.Equals("ra2_Belt"))
                        {
                            hasBelt = true;
                            break;
                        }
                    }
                    if (!hasBelt)
                    {
                        pa.Wear((Apparel)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Belt", true)));
                    }
                }
            }

            if (base.Pawn.apparel.WornApparel.Find(x => x.TryGetComp <CompDownToDie>() != null) == null)
            {
                base.Pawn.health.RemoveHediff(base.parent);
            }


            if ((base.Pawn.Downed && !base.Pawn.Dead) || base.Pawn.IsPrisoner)
            {
                //Apparel ap = base.Pawn.apparel.WornApparel.Find(x => x.TryGetComp<CompDownToDie>() != null);
                //ap.Destroy(DestroyMode.Vanish);
                //base.Pawn.apparel.Remove(ap);
                DamageInfo dinfo    = new DamageInfo(DamageDefOf.Crush, 100, 0, 0, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown);
                HediffSet  bodypart = base.Pawn.health.hediffSet;
                foreach (BodyPartRecord record in bodypart.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
                {
                    if (record.def.tags.Contains(BodyPartTagDefOf.BloodPumpingSource))
                    {
                        dinfo.SetHitPart(record);
                        break;
                    }
                }

                base.Pawn.TakeDamage(dinfo);
            }
        }
 private static IEnumerable<BodyPartRecord> HittablePartsViolence(HediffSet bodyModel)
 {
     return
         from x in bodyModel.GetNotMissingParts(null, null)
         where x.depth == BodyPartDepth.Outside || (x.depth == BodyPartDepth.Inside && x.def.IsSolid(x, bodyModel.hediffs))
         select x;
 }
 // Token: 0x06000017 RID: 23 RVA: 0x00003614 File Offset: 0x00001814
 private static IEnumerable <BodyPartRecord> HittablePartsViolence(HediffSet bodyModel)
 {
     return(from x in bodyModel.GetNotMissingParts(0, 0, null, null)
            where (int)x.depth == 2 || ((int)x.depth == 1 && x.def.IsSolid(x, bodyModel.hediffs))
            select x);
 }
Exemple #16
0
        public static bool AddDirect(HediffSet __instance, Hediff hediff, DamageInfo?dinfo = null, DamageWorker.DamageResult damageResult = null)
        {
            if (hediff.def == null)
            {
                Log.Error("Tried to add health diff with null def. Canceling.");
                return(false);
            }

            if (hediff.Part != null && !__instance.GetNotMissingParts().Contains(hediff.Part))
            {
                Log.Error("Tried to add health diff to missing part " + hediff.Part);
                return(false);
            }

            hediff.ageTicks = 0;
            hediff.pawn     = __instance.pawn;
            bool flag = false;

            for (int i = 0; i < __instance.hediffs.Count; i++)
            {
                if (__instance.hediffs[i].TryMergeWith(hediff))
                {
                    flag = true;
                }
            }

            if (!flag)
            {
                lock (__instance)
                {
                    //List<Hediff> newHediffs = new List<Hediff>(__instance.hediffs) { hediff };
                    //__instance.hediffs = newHediffs;
                    __instance.hediffs.Add(hediff);
                }
                hediff.PostAdd(dinfo);
                if (__instance.pawn.needs != null && __instance.pawn.needs.mood != null)
                {
                    __instance.pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
                }
            }

            bool flag2 = hediff is Hediff_MissingPart;

            if (!(hediff is Hediff_MissingPart) && hediff.Part != null && hediff.Part != __instance.pawn.RaceProps.body.corePart && __instance.GetPartHealth(hediff.Part) == 0f && hediff.Part != __instance.pawn.RaceProps.body.corePart)
            {
                bool flag3 = __instance.HasDirectlyAddedPartFor(hediff.Part);
                Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, __instance.pawn);
                hediff_MissingPart.IsFresh    = !flag3;
                hediff_MissingPart.lastInjury = hediff.def;
                __instance.pawn.health.AddHediff(hediff_MissingPart, hediff.Part, dinfo);
                damageResult?.AddHediff(hediff_MissingPart);
                if (flag3)
                {
                    if (dinfo.HasValue)
                    {
                        hediff_MissingPart.lastInjury = HealthUtility.GetHediffDefFromDamage(dinfo.Value.Def, __instance.pawn, hediff.Part);
                    }
                    else
                    {
                        hediff_MissingPart.lastInjury = null;
                    }
                }

                flag2 = true;
            }

            __instance.DirtyCache();
            if (flag2 && __instance.pawn.apparel != null)
            {
                __instance.pawn.apparel.Notify_LostBodyPart();
            }

            if (hediff.def.causesNeed != null && !__instance.pawn.Dead)
            {
                __instance.pawn.needs.AddOrRemoveNeedsAsAppropriate();
            }
            return(false);
        }