Пример #1
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);
            bool flag = base.Pawn != null;

            if (flag)
            {
                if (initializing)
                {
                    initializing = false;
                    this.Initialize();
                }
            }
            bool flag4 = Find.TickManager.TicksGame % 600 == 0;

            if (flag4)
            {
                List <Need> needs = base.Pawn.needs.AllNeeds;
                for (int i = 0; i < needs.Count; i++)
                {
                    if (needs[i].def.defName != "Joy" && needs[i].def.defName != "Mood" && needs[i].def.defName != "TM_Mana" && needs[i].def.defName != "TM_Stamina" && needs[i].def.defName != "ROMV_Blood")
                    {
                        needs[i].CurLevel = needs[i].MaxLevel;
                    }
                }
                Pawn pawn = base.Pawn;
                int  num  = 1;
                int  num2 = 1;

                using (IEnumerator <BodyPartRecord> enumerator = pawn.health.hediffSet.GetInjuredParts().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        BodyPartRecord rec   = enumerator.Current;
                        bool           flag2 = num > 0;

                        if (flag2)
                        {
                            IEnumerable <Hediff_Injury> arg_BB_0 = pawn.health.hediffSet.GetHediffs <Hediff_Injury>();
                            Func <Hediff_Injury, bool>  arg_BB_1;

                            arg_BB_1 = ((Hediff_Injury injury) => injury.Part == rec);

                            foreach (Hediff_Injury current in arg_BB_0.Where(arg_BB_1))
                            {
                                bool flag3 = num2 > 0;
                                if (flag3)
                                {
                                    bool flag5 = current.CanHealNaturally() && !current.IsPermanent();
                                    if (flag5)
                                    {
                                        current.Heal(2.0f);
                                        num--;
                                        num2--;
                                    }
                                    else
                                    {
                                        current.Heal(1.0f);
                                        num--;
                                        num2--;
                                    }
                                }
                            }
                        }
                    }
                }

                using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffsTendable().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Hediff rec = enumerator.Current;
                        if (rec.TendableNow()) // && !currentTendable.IsPermanent()
                        {
                            rec.Tended(1, 1);
                        }
                    }
                }

                using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Hediff rec = enumerator.Current;
                        if (!rec.IsPermanent())
                        {
                            if (rec.def.defName == "Cataract" || rec.def.defName == "HearingLoss" || rec.def.defName.Contains("ToxicBuildup"))
                            {
                                pawn.health.RemoveHediff(rec);
                            }
                            if ((rec.def.defName == "Blindness" || rec.def.defName.Contains("Asthma") || rec.def.defName == "Cirrhosis" || rec.def.defName == "ChemicalDamageModerate"))
                            {
                                pawn.health.RemoveHediff(rec);
                            }
                            if ((rec.def.defName == "Frail" || rec.def.defName == "BadBack" || rec.def.defName.Contains("Carcinoma") || rec.def.defName == "ChemicalDamageSevere"))
                            {
                                pawn.health.RemoveHediff(rec);
                            }
                            if ((rec.def.defName.Contains("Alzheimers") || rec.def.defName == "Dementia" || rec.def.defName.Contains("HeartArteryBlockage") || rec.def.defName == "CatatonicBreakdown"))
                            {
                                pawn.health.RemoveHediff(rec);
                            }
                        }
                        if (rec.def.makesSickThought)
                        {
                            pawn.health.RemoveHediff(rec);
                        }
                    }
                }
            }
        }
Пример #2
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            if (base.Pawn != null & base.parent != null && !this.Pawn.Dead)
            {
                if (!initialized)
                {
                    initialized = true;
                    this.Initialize();
                }
                base.CompPostTick(ref severityAdjustment);

                if (Find.TickManager.TicksGame % 60 == 0 && initialized)
                {
                    DeterminePsionicHD();
                    severityAdjustment += (this.Pawn.GetStatValue(StatDefOf.PsychicSensitivity, false) * Rand.Range(.04f, .12f));
                    if (Find.Selector.FirstSelectedObject == this.Pawn)
                    {
                        HediffStage hediffStage = this.Pawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_PsionicHD"), false).CurStage;
                        hediffStage.label = this.parent.Severity.ToString("0.00") + "%";
                    }

                    Hediff hediff = this.Pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_Artifact_PsionicBoostHD);
                    float  maxSev = 100;
                    if (hediff != null)
                    {
                        maxSev += hediff.Severity;
                    }
                    this.parent.Severity = Mathf.Clamp(this.parent.Severity, 0, maxSev);
                }

                if (base.Pawn.Spawned && !this.Pawn.Downed && base.Pawn.Map != null && comp != null)
                {
                    if (this.doPsionicAttack)
                    {
                        this.ticksTillPsionicStrike--;
                        if (this.ticksTillPsionicStrike <= 0)
                        {
                            this.doPsionicAttack = false;
                            if (threat != null && !threat.Destroyed && !threat.Dead && !threat.Downed)
                            {
                                TM_MoteMaker.MakePowerBeamMotePsionic(threat.DrawPos.ToIntVec3(), threat.Map, 2f, 2f, .7f, .1f, .6f);
                                DamageInfo dinfo2 = new DamageInfo(TMDamageDefOf.DamageDefOf.TM_PsionicInjury, Rand.Range(6, 12) * this.Pawn.GetStatValue(StatDefOf.PsychicSensitivity, false) + (2 * VerVal), 0, -1, this.Pawn, null, null, DamageInfo.SourceCategory.ThingOrUnknown, this.threat);
                                this.threat.TakeDamage(dinfo2);
                            }
                        }
                    }

                    if (comp.usePsionicAugmentationToggle && this.Pawn.drafter != null && this.Pawn.CurJob != null)
                    {
                        if (Find.TickManager.TicksGame % 600 == 0 && !this.Pawn.Drafted)
                        {
                            if (this.parent.Severity >= 95 && this.Pawn.CurJob.targetA != null && this.Pawn.CurJob.targetA.Thing != null)
                            {
                                if ((this.Pawn.Position - this.Pawn.CurJob.targetA.Thing.Position).LengthHorizontal > 20 && (this.Pawn.Position - this.Pawn.CurJob.targetA.Thing.Position).LengthHorizontal < 300 && this.Pawn.CurJob.locomotionUrgency >= LocomotionUrgency.Jog && this.Pawn.CurJob.bill == null)
                                {
                                    this.parent.Severity -= 10f;
                                    if (this.EffVal == 0)
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicSpeedHD"), 1f + .02f * this.EffVal);
                                    }
                                    else if (this.EffVal == 1)
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicSpeedHD_I"), 1f + .02f * this.EffVal);
                                    }
                                    else if (this.EffVal == 2)
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicSpeedHD_II"), 1f + .02f * this.EffVal);
                                    }
                                    else
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicSpeedHD_III"), 1f + .02f * this.EffVal);
                                    }
                                    for (int i = 0; i < 12; i++)
                                    {
                                        float direction = Rand.Range(0, 360);
                                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Psi"), this.Pawn.DrawPos, this.Pawn.Map, Rand.Range(.1f, .4f), 0.2f, .02f, .1f, 0, Rand.Range(8, 10), direction, direction);
                                    }
                                    comp.MightUserXP += Rand.Range(10, 15);
                                }
                                if ((this.Pawn.Position - this.Pawn.CurJob.targetA.Thing.Position).LengthHorizontal < 2 && (this.Pawn.CurJob.bill != null || this.Pawn.CurJob.def.defName == "Sow" || this.Pawn.CurJob.def.defName == "FinishFrame" || this.Pawn.CurJob.def.defName == "Deconstruct" || this.Pawn.CurJob.def.defName == "Repair" || this.Pawn.CurJob.def.defName == "Clean" || this.Pawn.CurJob.def.defName == "Mine" || this.Pawn.CurJob.def.defName == "SmoothFloor" || this.Pawn.CurJob.def.defName == "SmoothWall" || this.Pawn.CurJob.def.defName == "Harvest" || this.Pawn.CurJob.def.defName == "HarvestDesignated" || this.Pawn.CurJob.def.defName == "CutPlant" || this.Pawn.CurJob.def.defName == "CutPlantDesignated"))
                                {
                                    this.parent.Severity -= 12f;
                                    if (this.PwrVal == 0)
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicManipulationHD"), 1f + .02f * this.PwrVal);
                                    }
                                    else if (this.PwrVal == 1)
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicManipulationHD_I"), 1f + .02f * this.PwrVal);
                                    }
                                    else if (this.PwrVal == 2)
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicManipulationHD_II"), 1f + .02f * this.PwrVal);
                                    }
                                    else
                                    {
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicManipulationHD_III"), 1f + .02f * this.PwrVal);
                                    }
                                    for (int i = 0; i < 12; i++)
                                    {
                                        float direction = Rand.Range(0, 360);
                                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Psi"), this.Pawn.DrawPos, this.Pawn.Map, Rand.Range(.1f, .4f), 0.2f, .02f, .1f, 0, Rand.Range(8, 10), direction, direction);
                                    }
                                    comp.MightUserXP += Rand.Range(10, 15);
                                }
                            }
                        }

                        if (this.parent.Severity >= 20)
                        {
                            if (Find.TickManager.TicksGame % 180 == 0 && (this.Pawn.Drafted || !this.Pawn.IsColonist) && ((this.Pawn.equipment.Primary != null && !this.Pawn.equipment.Primary.def.IsRangedWeapon) || this.Pawn.equipment.Primary == null))
                            {
                                if (this.Pawn.CurJob.targetA != null && this.Pawn.CurJob.targetA.Thing != null && this.Pawn.CurJob.targetA.Thing is Pawn)
                                {
                                    //Log.Message("performing psionic dash - curjob " + this.Pawn.CurJob);
                                    //Log.Message("curjob def " + this.Pawn.CurJob.def.defName);
                                    //Log.Message("target " + this.Pawn.CurJob.targetA.Thing);
                                    //Log.Message("target range " + (this.Pawn.CurJob.targetA.Thing.Position - this.Pawn.Position).LengthHorizontal);
                                    Pawn  targetPawn     = this.Pawn.CurJob.targetA.Thing as Pawn;
                                    float targetDistance = (this.Pawn.Position - targetPawn.Position).LengthHorizontal;
                                    if (targetDistance > 3 && targetDistance < (12 + EffVal) && targetPawn.Map != null && !targetPawn.Downed)
                                    {
                                        for (int i = 0; i < 12; i++)
                                        {
                                            float direction = Rand.Range(0, 360);
                                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Psi"), this.Pawn.DrawPos, this.Pawn.Map, Rand.Range(.1f, .4f), 0.2f, .02f, .1f, 0, Rand.Range(8, 10), direction, direction);
                                        }
                                        FlyingObject_PsionicLeap flyingObject = (FlyingObject_PsionicLeap)GenSpawn.Spawn(ThingDef.Named("FlyingObject_PsionicLeap"), this.Pawn.Position, this.Pawn.Map);
                                        flyingObject.Launch(this.Pawn, this.Pawn.CurJob.targetA.Thing, this.Pawn);
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicHD"), -3f);
                                        comp.Stamina.CurLevel -= .03f;
                                        comp.MightUserXP      += Rand.Range(20, 30);
                                    }
                                }
                            }

                            if (this.nextPsionicAttack < Find.TickManager.TicksGame && this.Pawn.Drafted && comp.usePsionicMindAttackToggle)
                            {
                                if (this.Pawn.CurJob.def != TorannMagicDefOf.JobDriver_PsionicBarrier && VerVal > 0)
                                {
                                    this.threat = TM_Calc.FindNearbyEnemy(this.Pawn, 20 + (2 * verVal)); // GetNearbyTarget(20 + (2 * VerVal));
                                    if (threat != null)
                                    {
                                        //start psionic attack; ends after delay
                                        SoundInfo info = SoundInfo.InMap(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false), MaintenanceType.None);
                                        TorannMagicDefOf.TM_Implosion.PlayOneShot(info);
                                        Effecter psionicAttack = TorannMagicDefOf.TM_GiantExplosion.Spawn();
                                        psionicAttack.Trigger(new TargetInfo(threat.Position, threat.Map, false), new TargetInfo(threat.Position, threat.Map, false));
                                        psionicAttack.Cleanup();
                                        for (int i = 0; i < 12; i++)
                                        {
                                            float direction = Rand.Range(0, 360);
                                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Psi"), this.Pawn.DrawPos, this.Pawn.Map, Rand.Range(.1f, .4f), 0.2f, .02f, .1f, 0, Rand.Range(8, 10), direction, direction);
                                        }
                                        float weaponModifier = 1;
                                        if (this.Pawn.equipment.Primary != null)
                                        {
                                            if (this.Pawn.equipment.Primary.def.IsRangedWeapon)
                                            {
                                                StatModifier wpnMass = this.Pawn.equipment.Primary.def.statBases.FirstOrDefault((StatModifier x) => x.stat.defName == "Mass");
                                                weaponModifier = Mathf.Clamp(wpnMass.value, .8f, 6);
                                            }
                                            else //assume melee weapon
                                            {
                                                StatModifier wpnMass = this.Pawn.equipment.Primary.def.statBases.FirstOrDefault((StatModifier x) => x.stat.defName == "Mass");
                                                weaponModifier = Mathf.Clamp(wpnMass.value, .6f, 4);
                                            }
                                        }
                                        else //unarmed
                                        {
                                            weaponModifier = .4f;
                                        }
                                        this.nextPsionicAttack = Find.TickManager.TicksGame + (int)(Mathf.Clamp((600 - (60 * verVal)) * weaponModifier, 120, 900));
                                        float energyCost = Mathf.Clamp((10f - VerVal) * weaponModifier, 2f, 12f);
                                        HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_PsionicHD"), -energyCost);
                                        comp.MightUserXP           += Rand.Range(8, 12);
                                        this.doPsionicAttack        = true;
                                        this.ticksTillPsionicStrike = 24;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
 protected override void Impact(Thing hitThing)
 {
     base.Impact(hitThing);
     if (hitThing != null)
     {
         Pawn victim = hitThing as Pawn;
         if (victim != null)
         {
             if (mpdef.IsMentalStateGiver)
             {
                 string str = "MentalStateByPsyker".Translate(new object[]
                 {
                     victim.NameStringShort,
                 });
                 if (mpdef.InducesMentalState == MentalStateDefOf.Berserk && victim.RaceProps.intelligence < Intelligence.Humanlike)
                 {
                     if (CanOverpowerMind(this.Caster, victim))
                     {
                         victim.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Manhunter, str, true);
                     }
                 }
                 else
                 {
                     if (CanOverpowerMind(this.Caster, victim))
                     {
                         victim.mindState.mentalStateHandler.TryStartMentalState(mpdef.InducesMentalState, str, true);
                     }
                 }
             }
             else if (mpdef.IsBuffGiver && victim.needs.TryGetNeed <Need_Soul>().PsykerPowerLevel != PsykerPowerLevel.Omega)
             {
                 if (mpdef.BuffDef.isBad)
                 {
                     if (CanOverpowerMind(this.Caster, victim))
                     {
                         victim.health.AddHediff(mpdef.BuffDef);
                     }
                 }
                 else
                 {
                     victim.health.AddHediff(mpdef.BuffDef);
                 }
             }
             else if (mpdef.IsHealer)
             {
                 List <Hediff> list = victim.health.hediffSet.hediffs.Where(x => x.def != HediffDefOf.PsychicShock && x.def != C_HediffDefOf.DemonicPossession).ToList <Hediff>();
                 if (Rand.Range(0f, 1f) > this.mpdef.HealFailChance && victim.health.hediffSet.hediffs.Count > 0)
                 {
                     for (int i = 0; i < mpdef.HealCapacity + 1; i++)
                     {
                         Hediff hediff = list.RandomElement();
                         hediff.Heal(this.def.projectile.damageAmountBase);
                     }
                 }
             }
             else
             {
                 int        damageAmountBase = this.def.projectile.damageAmountBase;
                 ThingDef   equipmentDef     = this.equipmentDef;
                 DamageInfo dinfo            = new DamageInfo(this.def.projectile.damageDef, damageAmountBase, this.ExactRotation.eulerAngles.y, this.launcher, null, equipmentDef);
                 hitThing.TakeDamage(dinfo);
             }
         }
     }
     else
     {
         SoundDefOf.PowerOffSmall.PlayOneShotOnCamera();
     }
 }
        /// <summary>
        /// Gets the first matching bodypart in each bodypart tree node.
        /// </summary>
        /// <param name="pawn">Pawn to look in.</param>
        /// <param name="startingPart">Initial bodypart to start from.</param>
        /// <param name="hediffDef">HediffDef to look for.</param>
        /// <param name="hediffExceptionDef">HediffDef to stop at. Returns no bodypart.</param>
        /// <returns>Matching bodyparts.</returns>
        public static IEnumerable <BodyPartRecord> GetFirstMatchingBodyparts(this Pawn pawn, BodyPartRecord startingPart, HediffDef hediffDef, HediffDef hediffExceptionDef)
        {
            //Hediff list from pawn.
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            //Working lists for recursive iteration.
            List <BodyPartRecord> currentSet = new List <BodyPartRecord>();
            List <BodyPartRecord> nextSet    = new List <BodyPartRecord>();

            //Seed part.
            nextSet.Add(startingPart);

            do
            {
                //Initialize current set.
                currentSet.AddRange(nextSet);
                nextSet.Clear();

                foreach (BodyPartRecord part in currentSet)
                {
                    bool matchingPart = false;

                    //Iterate through all Hediffs.
                    for (int i = hediffs.Count - 1; i >= 0; i--)
                    {
                        //Current Hediff to inspect.
                        Hediff hediff = hediffs[i];

                        //Matching BodyPartRecord and Hediff
                        if (hediff.Part == part)
                        {
                            if (hediff.def == hediffExceptionDef)
                            {
                                //Matching part. As an exception.
                                matchingPart = true;
                                break;
                            }
                            else if (hediff.def == hediffDef)
                            {
                                //Matching part.
                                matchingPart = true;

                                yield return(part);

                                break;
                            }
                        }
                    }

                    //If no matching parts found on this level, continue on next.
                    if (!matchingPart)
                    {
                        //Add next set.
                        for (int j = 0; j < part.parts.Count; j++)
                        {
                            nextSet.Add(part.parts[j]);
                        }
                    }
                }

                //Clear current set.
                currentSet.Clear();
            } while (nextSet.Count > 0); //Do while we got next set of parts to go through.
        }
Пример #5
0
 private void SetRecallHediffs()
 {
     comp.recallHediffList = new List <Hediff>();
     comp.recallHediffList.Clear();
     comp.recallHediffDefSeverityList = new List <float>();
     comp.recallHediffDefSeverityList.Clear();
     comp.recallHediffDefTicksRemainingList = new List <int>();
     comp.recallHediffDefTicksRemainingList.Clear();
     comp.recallInjuriesList = new List <Hediff_Injury>();
     comp.recallInjuriesList.Clear();
     for (int i = 0; i < this.CasterPawn.health.hediffSet.hediffs.Count; i++)
     {
         if (!this.CasterPawn.health.hediffSet.hediffs[i].IsPermanent() && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_MagicUserHD &&
             !this.CasterPawn.health.hediffSet.hediffs[i].def.defName.Contains("TM_HediffEnchantment") && !this.CasterPawn.health.hediffSet.hediffs[i].def.defName.Contains("TM_Artifact") &&
             this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_MightUserHD && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_BloodHD &&
             this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_ChiHD && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_PsionicHD)
         {
             if (this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_Injury)
             {
                 Hediff_Injury rhd    = this.CasterPawn.health.hediffSet.hediffs[i] as Hediff_Injury;
                 Hediff_Injury hediff = new Hediff_Injury();
                 //hediff = TM_Calc.Clone<Hediff>(this.CasterPawn.health.hediffSet.hediffs[i]);
                 hediff.def  = rhd.def;
                 hediff.Part = rhd.Part;
                 Traverse.Create(root: hediff).Field(name: "visible").SetValue(rhd.Visible);
                 Traverse.Create(root: hediff).Field(name: "severityInt").SetValue(rhd.Severity);
                 //hediff.Severity = rhd.Severity;
                 hediff.ageTicks = rhd.ageTicks;
                 comp.recallInjuriesList.Add(hediff);
             }
             else if (this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_MissingPart || this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_AddedPart || this.CasterPawn.health.hediffSet.hediffs[i].def.defName == "PsychicAmplifier")
             {
                 //do nothing
             }
             else if (this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_Addiction)
             {
                 //Hediff_Addiction rhd = this.CasterPawn.health.hediffSet.hediffs[i] as Hediff_Addiction;
             }
             else if (this.CasterPawn.health.hediffSet.hediffs[i].def.defName == "LuciferiumHigh")
             {
                 //do nothing
             }
             else
             {
                 Hediff rhd = this.CasterPawn.health.hediffSet.hediffs[i] as Hediff;
                 //Log.Message("sev def is " + rhd.def.defName);
                 if (rhd != null)
                 {
                     Hediff hediff = new Hediff();
                     //hediff = TM_Calc.Clone<Hediff>(this.CasterPawn.health.hediffSet.hediffs[i]);
                     hediff.def    = rhd.def;
                     hediff.loadID = rhd.loadID;
                     hediff.Part   = rhd.Part;
                     //foreach(HediffComp hdc in rhd.comps)
                     //{
                     //    if(hdc is HediffComp_Disappears)
                     //    {
                     //        HediffComp_Disappears rhd_comp = hdc as HediffComp_Disappears;
                     //        HediffComp_Disappears hdc_d = new HediffComp_Disappears();
                     //        hdc_d.ticksToDisappear = rhd_comp.ticksToDisappear;
                     //        hediff.comps.Add(hdc_d);
                     //    }
                     //    else
                     //    {
                     //        hediff.comps.Add(hdc);
                     //    }
                     //}
                     //Traverse.Create(root: hediff).Field(name: "visible").SetValue(rhd.Visible);
                     //Traverse.Create(root: hediff).Field(name: "severityInt").SetValue(rhd.Severity);
                     hediff.ageTicks = rhd.ageTicks;
                     //Log.Message("saving hediff " + hediff.def.defName + " with severity " + rhd.Severity);
                     comp.recallHediffList.Add(hediff);
                     comp.recallHediffDefSeverityList.Add(rhd.Severity);
                     HediffComp_Disappears hdc_d = rhd.TryGetComp <HediffComp_Disappears>();
                     if (hdc_d != null)
                     {
                         //Log.Message("hediff has disappears at ticks " + hdc_d.ticksToDisappear);
                         comp.recallHediffDefTicksRemainingList.Add(hdc_d.ticksToDisappear);
                     }
                     else
                     {
                         comp.recallHediffDefTicksRemainingList.Add(-1);
                     }
                 }
                 //else
                 //{
                 //    Hediff _rhd = this.CasterPawn.health.hediffSet.hediffs[i];
                 //    if(_rhd != null)
                 //    {
                 //        HediffWithComps hediff = new HediffWithComps();
                 //        hediff.def = rhd.def;
                 //        hediff.loadID = rhd.loadID;
                 //        hediff.Part = rhd.Part;
                 //        Traverse.Create(root: hediff).Field(name: "visible").SetValue(rhd.Visible);
                 //        Traverse.Create(root: hediff).Field(name: "severityInt").SetValue(rhd.Severity);
                 //        hediff.Severity = rhd.Severity;
                 //        hediff.ageTicks = rhd.ageTicks;
                 //        comp.recallHediffList.Add(hediff);
                 //    }
                 //}
             }
             //Log.Message("adding " + this.CasterPawn.health.hediffSet.hediffs[i].def + " at severity " + this.CasterPawn.health.hediffSet.hediffs[i].Severity);
         }
     }
     //Log.Message("hediffs set");
 }
Пример #6
0
 public override bool TryMergeWith(Hediff other)
 {
     return(false);
 }
Пример #7
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);
            bool flag = base.Pawn != null;

            if (flag)
            {
                if (initializing)
                {
                    initializing = false;
                    this.Initialize();
                }
            }
            bool flag4 = Find.TickManager.TicksGame % 600 == 0;

            if (flag4)
            {
                Pawn pawn = base.Pawn;
                CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
                Pawn soulPawn             = comp.soulBondPawn;
                bondedPawn = soulPawn;
                if (soulPawn != null)
                {
                    if (soulPawn.Dead || soulPawn.Destroyed)
                    {
                        this.soulPawnRemove = true;
                    }
                    else
                    {
                        bool soulPawnHasHediff = false;
                        using (IEnumerator <Hediff> enumerator = soulPawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                Hediff rec = enumerator.Current;
                                if (rec.def.defName == "TM_SoulBondPhysicalHD")
                                {
                                    soulPawnHasHediff = true;
                                    if (rec.Severity != .5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_ver").level)
                                    {
                                        HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondPhysicalHD"), -4f);
                                        HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondPhysicalHD"), 0.5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_ver").level);
                                    }
                                }
                                else if (rec.def.defName == "TM_SoulBondMentalHD")
                                {
                                    soulPawnHasHediff = true;
                                    if (rec.Severity != .5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_ver").level)
                                    {
                                        HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondMentalHD"), -4f);
                                        HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondMentalHD"), 0.5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_ver").level);
                                    }
                                }
                            }
                        }
                        if (!soulPawnHasHediff)
                        {
                            if (this.Pawn.gender == Gender.Female)
                            {
                                HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondPhysicalHD"), -4f);
                                HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondPhysicalHD"), 0.5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_ver").level);
                            }
                            else if (this.Pawn.gender == Gender.Male)
                            {
                                HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondMentalHD"), -4f);
                                HealthUtility.AdjustSeverity(soulPawn, HediffDef.Named("TM_SoulBondMentalHD"), 0.5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_ver").level);
                            }
                        }
                        if (this.parent.Severity != .5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_pwr").level)
                        {
                            if (this.parent.def.defName == "TM_SDSoulBondPhysicalHD")
                            {
                                HealthUtility.AdjustSeverity(pawn, HediffDef.Named("TM_SDSoulBondPhysicalHD"), -4f);
                                HealthUtility.AdjustSeverity(pawn, HediffDef.Named("TM_SDSoulBondPhysicalHD"), 0.5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_pwr").level);
                            }
                            else if (this.parent.def.defName == "TM_WDSoulBondMentalHD")
                            {
                                HealthUtility.AdjustSeverity(pawn, HediffDef.Named("TM_WDSoulBondMentalHD"), -4f);
                                HealthUtility.AdjustSeverity(pawn, HediffDef.Named("TM_WDSoulBondMentalHD"), 0.5f + comp.MagicData.MagicPowerSkill_SoulBond.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SoulBond_pwr").level);
                            }
                        }
                    }
                }
                else
                {
                    this.soulPawnRemove = true;
                }
            }
        }
Пример #8
0
        private void PerformStraitJacketCheck()
        {
            if (map.mapPawns != null)
            {
                if (map.mapPawns.FreeColonists != null)
                {
                    HashSet <Pawn> colonists          = new HashSet <Pawn>(map.mapPawns.FreeColonists);
                    HashSet <Pawn> prisoners          = new HashSet <Pawn>(Prisoners(map));
                    HashSet <Pawn> others             = new HashSet <Pawn>(map.mapPawns.AllPawns.Where(x => (x?.RaceProps?.Humanlike ?? false) && x?.Faction != Faction.OfPlayer));
                    bool           giveThoughtToAll   = false;
                    Pawn           straightjackedPawn = null;
                    Hediff         pawnJacketHediff   = null;

                    //Check our prisoners first
                    foreach (Pawn p in prisoners.Concat(others))
                    {
                        if (p.apparel != null)
                        {
                            bool jacketOn = false;
                            foreach (Apparel apparel in p.apparel.WornApparel)
                            {
                                if (apparel.def == StraitjacketDefOf.ROM_Straitjacket)
                                {
                                    jacketOn = true;
                                    //Log.Message("Straitjacket Prisoner Check");

                                    straightjackedPawn = p;
                                    p.needs.mood.thoughts.memories.TryGainMemory(StraitjacketDefOf.ROM_WoreStraitjacket);

                                    pawnJacketHediff = p.health.hediffSet.GetFirstHediffOfDef(StraitjacketDefOf.ROM_RestainedByStraitjacket);
                                    if (pawnJacketHediff == null)
                                    {
                                        pawnJacketHediff = HediffMaker.MakeHediff(StraitjacketDefOf.ROM_RestainedByStraitjacket, p);
                                        p.health.AddHediff(pawnJacketHediff);
                                    }
                                }
                            }

                            if (!jacketOn)
                            {
                                pawnJacketHediff = p.health.hediffSet.GetFirstHediffOfDef(StraitjacketDefOf.ROM_RestainedByStraitjacket);
                                if (pawnJacketHediff != null)
                                {
                                    p.health.RemoveHediff(pawnJacketHediff);
                                }
                            }
                        }
                    }

                    //Check our colonists
                    foreach (Pawn p in colonists)
                    {
                        if (p.apparel != null)
                        {
                            bool jacketOn = false;

                            foreach (Apparel apparel in p.apparel.WornApparel)
                            {
                                if (apparel.def == StraitjacketDefOf.ROM_Straitjacket)
                                {
                                    straightjackedPawn = p;
                                    p.needs.mood.thoughts.memories.TryGainMemory(StraitjacketDefOf.ROM_WoreStraitjacket);
                                    jacketOn = true;

                                    if (pawnJacketHediff == null)
                                    {
                                        pawnJacketHediff = HediffMaker.MakeHediff(StraitjacketDefOf.ROM_RestainedByStraitjacket, p);
                                        p.health.AddHediff(pawnJacketHediff);
                                    }

                                    giveThoughtToAll = true; //Different than prisoners
                                }
                            }
                            if (!jacketOn)
                            {
                                pawnJacketHediff = p.health.hediffSet.GetFirstHediffOfDef(StraitjacketDefOf.ROM_RestainedByStraitjacket);
                                if (pawnJacketHediff != null)
                                {
                                    p.health.RemoveHediff(pawnJacketHediff);
                                }
                            }
                        }
                    }
                    if (giveThoughtToAll)
                    {
                        foreach (Pawn p in colonists)
                        {
                            if (p != straightjackedPawn)
                            {
                                p.needs.mood.thoughts.memories.TryGainMemory(StraitjacketDefOf.ROM_ColonistWoreStraitjacket);
                            }
                        }
                    }
                }
            }
        }
        private void ReverseHediff(Pawn pawn, int ticks)
        {
            float totalBleedRate = 0;
            int   totalHDremoved = 0;

            using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Hediff rec = enumerator.Current;
                    if (rec != null)
                    {
                        HediffComp_Immunizable immuneComp = rec.TryGetComp <HediffComp_Immunizable>();
                        if (immuneComp != null)
                        {
                            if (immuneComp.Def.CompProps <HediffCompProperties_Immunizable>() != null)
                            {
                                float immuneSevDay = immuneComp.Def.CompProps <HediffCompProperties_Immunizable>().severityPerDayNotImmune;
                                if (immuneSevDay != 0 && !rec.FullyImmune())
                                {
                                    rec.Severity -= immuneSevDay * ticks * this.parent.Severity / 2000;
                                }
                            }
                        }
                        HediffComp_SeverityPerDay sevDayComp = rec.TryGetComp <HediffComp_SeverityPerDay>();
                        if (sevDayComp != null)
                        {
                            if (sevDayComp.Def.CompProps <HediffCompProperties_SeverityPerDay>() != null)
                            {
                                float sevDay = sevDayComp.Def.CompProps <HediffCompProperties_SeverityPerDay>().severityPerDay;
                                if (sevDay != 0)
                                {
                                    bool drugTolerance = false;
                                    HediffComp_DrugEffectFactor drugEffectComp = rec.TryGetComp <HediffComp_DrugEffectFactor>();
                                    if (drugEffectComp != null)
                                    {
                                        if (drugEffectComp.Def.CompProps <HediffCompProperties_DrugEffectFactor>().chemical != null)
                                        {
                                            drugTolerance = true;
                                        }
                                    }
                                    if (!drugTolerance)
                                    {
                                        rec.Severity -= sevDay * ticks * this.parent.Severity / 800;
                                    }
                                }
                            }
                        }
                        HediffComp_Disappears tickComp = rec.TryGetComp <HediffComp_Disappears>();
                        if (tickComp != null)
                        {
                            int ticksToDisappear = Traverse.Create(root: tickComp).Field(name: "ticksToDisappear").GetValue <int>();
                            if (ticksToDisappear != 0)
                            {
                                Traverse.Create(root: tickComp).Field(name: "ticksToDisappear").SetValue(ticksToDisappear + Mathf.RoundToInt(ticks * this.parent.Severity));
                            }
                        }
                        if (rec.Bleeding)
                        {
                            totalBleedRate += rec.BleedRate;
                        }
                    }
                }
                if (totalBleedRate != 0)
                {
                    HealthUtility.AdjustSeverity(pawn, HediffDefOf.BloodLoss, -(totalBleedRate * ticks * this.parent.Severity) / (24 * 2500));
                }
            }
            IEnumerable <Hediff> hediffList = pawn.health.hediffSet.GetHediffs <Hediff>();

            foreach (Hediff rec in hediffList)
            {
                if (rec != null && rec != this.parent)
                {
                    if (rec.def.scenarioCanAdd || rec.def.isBad)
                    {
                        if ((rec.ageTicks - 1000) < 0)
                        {
                            if (rec.def.defName.Contains("TM_"))
                            {
                                if (rec.def.isBad && rec.def != TorannMagicDefOf.TM_ResurrectionHD && rec.def != TorannMagicDefOf.TM_DeathReversalHD)
                                {
                                    totalHDremoved++;
                                    this.Pawn.health.RemoveHediff(rec);
                                    break;
                                }
                            }
                            else
                            {
                                List <BodyPartRecord> bpList          = pawn.RaceProps.body.AllParts;
                                List <BodyPartRecord> replacementList = new List <BodyPartRecord>();
                                replacementList.Clear();
                                for (int j = 0; j < bpList.Count; j++)
                                {
                                    BodyPartRecord record = bpList[j];
                                    if (pawn.health.hediffSet.hediffs.Any((Hediff x) => x.Part == record) && (record.parent == null || pawn.health.hediffSet.GetNotMissingParts().Contains(record.parent)) && (!pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(record) || pawn.health.hediffSet.HasDirectlyAddedPartFor(record)))
                                    {
                                        replacementList.Add(record);
                                    }
                                }
                                Hediff_MissingPart mphd = rec as Hediff_MissingPart;
                                if (mphd != null && mphd.Part != null)
                                {
                                    if (replacementList.Contains(mphd.Part))
                                    {
                                        if (RemoveChildParts(mphd))
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            if (this.Pawn.needs != null && this.Pawn.needs.mood != null && this.Pawn.needs.mood.thoughts != null && this.Pawn.needs.mood.thoughts.memories != null)
                                            {
                                                this.Pawn.needs.mood.thoughts.memories.TryGainMemory(TorannMagicDefOf.TM_PhantomLimb);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        goto IgnoreHediff;
                                    }
                                }
                                totalHDremoved += 2;
                                this.Pawn.health.RemoveHediff(rec);
                                break;
                                IgnoreHediff :;
                            }
                        }
                        else
                        {
                            rec.ageTicks -= 1000;
                        }
                    }
                }
            }
            ReduceReverseTime(totalHDremoved);
            //using (IEnumerator<Hediff> enumerator = pawn.health.hediffSet.GetHediffs<Hediff>().GetEnumerator())
            //{
            //    while (enumerator.MoveNext())
            //    {
            //        Hediff rec = enumerator.Current;
            //        if (rec != null && rec != this.parent)
            //        {
            //            if ((rec.ageTicks - 2500) < 0)
            //            {
            //                if (rec.def.defName.Contains("TM_"))
            //                {
            //                    if (rec.def.isBad)
            //                    {
            //                        this.Pawn.health.RemoveHediff(rec);
            //                    }
            //                }
            //                else
            //                {
            //                    this.Pawn.health.RemoveHediff(rec);
            //                }
            //            }
            //            else
            //            {
            //                rec.ageTicks -= 2500;
            //            }
            //        }
            //    }
            //}
        }
        public static bool OnIntervalPassed(HediffGiver_Hypothermia __instance, Pawn pawn, Hediff cause)
        {
            float ambientTemperature = pawn.AmbientTemperature;
            //FloatRange floatRange = pawn.ComfortableTemperatureRange(); //REMOVED
            //FloatRange floatRange2 = pawn.SafeTemperatureRange(); //REMOVED
            float     comfortableTemperatureMin = pawn.GetStatValue(StatDefOf.ComfyTemperatureMin); //ADDED
            float     minTemp          = comfortableTemperatureMin - 10f;                           //ADDED
            HediffSet hediffSet        = pawn.health.hediffSet;
            HediffDef hediffDef        = pawn.RaceProps.FleshType == FleshTypeDefOf.Insectoid ? __instance.hediffInsectoid : __instance.hediff;
            Hediff    firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediffDef);

            //if (ambientTemperature < floatRange2.min) //REMOVED
            if (ambientTemperature < minTemp)             //ADDED
            {
                //float a = Mathf.Abs(ambientTemperature - floatRange2.min) * 6.45E-05f; //REMOVED
                float a = Mathf.Abs(ambientTemperature - minTemp) * 6.45E-05f;                 //ADDED
                a = Mathf.Max(a, 0.00075f);
                HealthUtility.AdjustSeverity(pawn, hediffDef, a);
                if (pawn.Dead)
                {
                    return(false);
                }
            }
            if (firstHediffOfDef == null)
            {
                return(false);
            }
            //if (ambientTemperature > floatRange.min) //REMOVED
            if (ambientTemperature > comfortableTemperatureMin)             //ADDED
            {
                float value = firstHediffOfDef.Severity * 0.027f;
                value = Mathf.Clamp(value, 0.0015f, 0.015f);
                firstHediffOfDef.Severity -= value;
            }
            else if (pawn.RaceProps.FleshType != FleshTypeDefOf.Insectoid && ambientTemperature < 0f && firstHediffOfDef.Severity > 0.37f)
            {
                float num = 0.025f * firstHediffOfDef.Severity;
                if (Rand.Value < num && pawn.RaceProps.body.AllPartsVulnerableToFrostbite.Where(x => !hediffSet.PartIsMissing(x)).TryRandomElementByWeight(x => x.def.frostbiteVulnerability, out BodyPartRecord result))
                {
                    int        num2  = Mathf.CeilToInt(result.def.hitPoints * 0.5f);
                    DamageInfo dinfo = new DamageInfo(DamageDefOf.Frostbite, num2, 0f, -1f, null, result);
                    pawn.TakeDamage(dinfo);
                }
            }
            return(false);
        }
Пример #11
0
        private static void DrawHediffRow(Rect rect, Pawn pawn, IEnumerable <Hediff> diffs, ref float curY)
        {
            float          num   = (float)(rect.width * 0.375);
            float          width = (float)(rect.width - num - 20.0);
            BodyPartRecord part  = diffs.First().Part;
            float          a     = (part != null) ? Text.CalcHeight(part.def.LabelCap, num) : Text.CalcHeight("WholeBody".Translate(), num);
            float          num2  = 0f;
            float          num3  = curY;
            float          num4  = 0f;

            foreach (IGrouping <int, Hediff> item in from x in diffs
                     group x by x.UIGroupKey)
            {
                int    num5 = item.Count();
                string text = item.First().LabelCap;
                if (num5 != 1)
                {
                    text = text + " x" + num5.ToString();
                }
                num4 += Text.CalcHeight(text, width);
            }
            num2 = num4;
            Rect rect2 = new Rect(0f, curY, rect.width, Mathf.Max(a, num2));

            HealthCardUtility.DoRightRowHighlight(rect2);
            if (part != null)
            {
                GUI.color = HealthUtility.GetPartConditionLabel(pawn, part).Second;
                Widgets.Label(new Rect(0f, curY, num, 100f), part.def.LabelCap);
            }
            else
            {
                GUI.color = HealthUtility.DarkRedColor;
                Widgets.Label(new Rect(0f, curY, num, 100f), "WholeBody".Translate());
            }
            GUI.color = Color.white;
            foreach (IGrouping <int, Hediff> item2 in from x in diffs
                     group x by x.UIGroupKey)
            {
                int             num6            = 0;
                Hediff          hediff          = null;
                Texture2D       texture2D       = null;
                TextureAndColor textureAndColor = null;
                float           num7            = 0f;
                foreach (Hediff item3 in item2)
                {
                    if (num6 == 0)
                    {
                        hediff = item3;
                    }
                    textureAndColor = item3.StateIcon;
                    if (item3.Bleeding)
                    {
                        texture2D = HealthCardUtility.BleedingIcon;
                    }
                    num7 += item3.BleedRate;
                    num6++;
                }
                string text2 = hediff.LabelCap;
                if (num6 != 1)
                {
                    text2 = text2 + " x" + num6.ToStringCached();
                }
                GUI.color = hediff.LabelColor;
                float num8  = Text.CalcHeight(text2, width);
                Rect  rect3 = new Rect(num, curY, width, num8);
                Widgets.Label(rect3, text2);
                GUI.color = Color.white;
                Rect rect4 = new Rect((float)(rect2.xMax - 20.0), curY, 20f, 20f);
                if ((bool)texture2D)
                {
                    Rect position = rect4.ContractedBy(GenMath.LerpDouble(0f, 0.6f, 5f, 0f, Mathf.Min(num7, 1f)));
                    GUI.DrawTexture(position, texture2D);
                    rect4.x -= rect4.width;
                }
                if (textureAndColor.HasValue)
                {
                    GUI.color = textureAndColor.Color;
                    GUI.DrawTexture(rect4, textureAndColor.Texture);
                    GUI.color = Color.white;
                    rect4.x  -= rect4.width;
                }
                curY += num8;
            }
            GUI.color = Color.white;
            curY      = num3 + Mathf.Max(a, num2);
            TooltipHandler.TipRegion(rect2, new TipSignal(() => HealthCardUtility.GetTooltip(diffs, pawn, part), (int)curY + 7857));
        }
Пример #12
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            if (!pawn.DestroyedOrNull() && !pawn.Dead)
            {
                CompAbilityUserMagic compMagic = pawn.GetComp <CompAbilityUserMagic>();
                CompAbilityUserMight compMight = pawn.GetComp <CompAbilityUserMight>();

                bool   isMage      = compMagic.IsMagicUser && !pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless);
                bool   isFighter   = compMight.IsMightUser;
                bool   isPsionic   = pawn.health.hediffSet.HasHediff(HediffDef.Named("TM_PsionicHD"), false);
                bool   isBloodMage = pawn.health.hediffSet.HasHediff(HediffDef.Named("TM_BloodHD"), false);
                Hediff hediff      = null;
                for (int h = 0; h < pawn.health.hediffSet.hediffs.Count; h++)
                {
                    if (pawn.health.hediffSet.hediffs[h].def.defName.Contains("TM_HateHD"))
                    {
                        hediff = pawn.health.hediffSet.hediffs[h];
                    }
                }
                bool isDeathKnight = hediff != null;
                //bool isLich = pawn.story.traits.HasTrait(TorannMagicDefOf.Lich);
                float barCount = 1;
                float boostSev = 100;
                if (isFighter)
                {
                    barCount++;
                }
                if (isMage)
                {
                    barCount++;
                }
                if (isPsionic)
                {
                    barCount++;
                    Hediff hediffBoost = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_Artifact_PsionicBoostHD);
                    if (hediffBoost != null)
                    {
                        boostSev += hediffBoost.Severity;
                    }
                }
                if (isDeathKnight)
                {
                    barCount++;
                    Hediff hediffBoost = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_Artifact_HateBoostHD);
                    if (hediffBoost != null)
                    {
                        boostSev += hediffBoost.Severity;
                    }
                }
                if (isBloodMage)
                {
                    barCount++;
                    Hediff hediffBoost = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_Artifact_BloodBoostHD);
                    if (hediffBoost != null)
                    {
                        boostSev += hediffBoost.Severity;
                    }
                }
                float barHeight;
                float initialShift = 0;
                if (barCount == 2)
                {
                    initialShift = 14f;
                }
                else if (barCount >= 3)
                {
                    initialShift = 6f;
                }
                if (barCount > 1 && ((isFighter && compMight.Stamina != null) || (isMage && compMagic.Mana != null)))
                {
                    Rect overRect = new Rect(topLeft.x + 2, topLeft.y, this.GetWidth(100), 75); //overall rect size (shell)
                    Find.WindowStack.ImmediateWindow(984698, overRect, WindowLayer.GameUI, delegate
                    {
                        barHeight         = ((75 - 5) / barCount);
                        Rect rect         = overRect.AtZero().ContractedBy(6f); //inner, smaller rect
                        rect.height       = barHeight;
                        Rect rect2        = rect;                               //label rect, starts at top
                        Text.Font         = GameFont.Tiny;
                        float fillPercent = 0;
                        float yShift      = initialShift;
                        Text.Anchor       = TextAnchor.MiddleCenter;
                        if (isPsionic)
                        {
                            rect2.y += yShift;
                            try
                            {
                                fillPercent = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_PsionicHD"), false).Severity / (boostSev);
                                Widgets.FillableBar(rect2, fillPercent, Gizmo_EnergyStatus.FullPsionicTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect2, "" + (pawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_PsionicHD"), false).Severity).ToString("F0") + " / " + boostSev.ToString("F0"));
                            }
                            catch
                            {
                                fillPercent = 0f;
                                Widgets.FillableBar(rect2, fillPercent, Gizmo_EnergyStatus.FullPsionicTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect2, "");
                            }
                            yShift += (barHeight) + 5f;
                        }
                        if (isDeathKnight)
                        {
                            rect2.y += yShift;
                            try
                            {
                                fillPercent = hediff.Severity / boostSev;
                                Widgets.FillableBar(rect2, fillPercent, Gizmo_EnergyStatus.FullDeathKnightTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect2, "" + hediff.Severity.ToString("F0") + " / " + boostSev.ToString("F0"));
                            }
                            catch
                            {
                                fillPercent = 0f;
                                Widgets.FillableBar(rect2, fillPercent, Gizmo_EnergyStatus.FullDeathKnightTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect2, "");
                            }
                            yShift += (barHeight) + 5f;
                        }
                        if (isBloodMage)
                        {
                            rect2.y += yShift;
                            try
                            {
                                fillPercent = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_BloodHD"), false).Severity / boostSev;
                                Widgets.FillableBar(rect2, fillPercent, Gizmo_EnergyStatus.FullBloodMageTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect2, "" + (pawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("TM_BloodHD"), false).Severity).ToString("F0") + " / " + boostSev.ToString("F0"));
                            }
                            catch
                            {
                                fillPercent = 0f;
                                Widgets.FillableBar(rect2, fillPercent, Gizmo_EnergyStatus.FullBloodMageTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect2, "");
                            }
                            yShift += (barHeight) + 5f;
                        }
                        Rect rect3 = rect; // bar rect, starts at bottom of label rect
                        if (isFighter)
                        {
                            rect3.y += yShift; //shift downward without changing height
                            try
                            {
                                fillPercent = compMight.Stamina.CurInstantLevel / compMight.maxSP;
                                Widgets.FillableBar(rect3, fillPercent, Gizmo_EnergyStatus.FullStaminaTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect3, "" + (compMight.Stamina.CurInstantLevel * 100).ToString("F0") + " / " + (compMight.maxSP * 100).ToString("F0"));
                            }
                            catch
                            {
                                fillPercent = 0f;
                                Widgets.FillableBar(rect3, fillPercent, Gizmo_EnergyStatus.FullStaminaTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect3, "");
                            }

                            yShift += (barHeight) + 5f;
                        }
                        Rect rect4 = rect; // bar rect, starts at bottom of label rect
                        if (isMage)
                        {
                            rect4.y += yShift; //shift downward without changing height
                            try
                            {
                                fillPercent = compMagic.Mana.CurInstantLevel / compMagic.maxMP;
                                Widgets.FillableBar(rect4, fillPercent, Gizmo_EnergyStatus.FullManaTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect4, "" + (compMagic.Mana.CurInstantLevel * 100).ToString("F0") + " / " + (compMagic.maxMP * 100).ToString("F0"));
                            }
                            catch
                            {
                                fillPercent = 0f;
                                Widgets.FillableBar(rect4, fillPercent, Gizmo_EnergyStatus.FullManaTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                                Widgets.Label(rect4, "");
                            }
                        }
                        Text.Font   = GameFont.Small;
                        Text.Anchor = TextAnchor.UpperLeft;
                    }, true, false, 1f);
                }
            }
            else
            {
                Rect  overRect = new Rect(topLeft.x + 2, topLeft.y, this.GetWidth(100), 75); //overall rect size (shell)
                float barHeight;
                float initialShift = 0;
                Find.WindowStack.ImmediateWindow(984698, overRect, WindowLayer.GameUI, delegate
                {
                    barHeight         = ((75 - 5) / 1);
                    Rect rect         = overRect.AtZero().ContractedBy(6f); //inner, smaller rect
                    rect.height       = barHeight;
                    Rect rect2        = rect;                               //label rect, starts at top
                    Text.Font         = GameFont.Tiny;
                    float fillPercent = 0;
                    float yShift      = initialShift;
                    Text.Anchor       = TextAnchor.MiddleCenter;
                    rect2.y          += yShift;
                    fillPercent       = 0f;
                    Widgets.FillableBar(rect2, fillPercent, Gizmo_EnergyStatus.FullPsionicTex, Gizmo_EnergyStatus.EmptyShieldBarTex, false);
                    Widgets.Label(rect2, "");
                    yShift += (barHeight) + 5f;
                }, true, false, 1f);
            }
            return(new GizmoResult(GizmoState.Clear));
        }
Пример #13
0
 // don't do anythin exciting when killed - just disappear:
 public override void Kill(DamageInfo?dinfo, Hediff exactCulprit = null)
 {
     // don't call base.Kill
     this.Destroy();
 }
Пример #14
0
 /// <summary>
 /// called when the other is merged into this instance's parent
 /// </summary>
 /// <param name="other">The other.</param>
 public override void CompPostMerged(Hediff other)
 {
     _velocity = Props.V0;
     base.CompPostMerged(other);
 }
Пример #15
0
        protected override bool TryCastShot()
        {
            // power affects enumerator
            // DamageWorker.DamageResult result = DamageWorker.DamageResult.MakeNew();
            Pawn caster = this.CasterPawn;
            CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>();
            MagicPowerSkill      pwr  = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_AdvancedHeal.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_AdvancedHeal_pwr");
            MagicPowerSkill      ver  = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_AdvancedHeal.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_AdvancedHeal_ver");

            pwrVal = pwr.level;
            verVal = ver.level;
            if (caster.story.traits.HasTrait(TorannMagicDefOf.Faceless))
            {
                MightPowerSkill mpwr = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                MightPowerSkill mver = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                pwrVal = mpwr.level;
                verVal = mver.level;
            }

            Pawn pawn       = (Pawn)this.currentTarget;
            bool flag       = pawn != null && !pawn.Dead && !TM_Calc.IsUndead(pawn);
            bool undeadFlag = pawn != null && !pawn.Dead && TM_Calc.IsUndead(pawn);

            if (flag)
            {
                int num = 3 + verVal;
                using (IEnumerator <BodyPartRecord> enumerator = pawn.health.hediffSet.GetInjuredParts().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        BodyPartRecord rec   = enumerator.Current;
                        bool           flag2 = num > 0;

                        if (flag2)
                        {
                            int num2 = 1 + verVal;
                            ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                            if (!this.CasterPawn.IsColonist && settingsRef.AIHardMode)
                            {
                                num2 = 5;
                            }
                            IEnumerable <Hediff_Injury> arg_BB_0 = pawn.health.hediffSet.GetHediffs <Hediff_Injury>();
                            Func <Hediff_Injury, bool>  arg_BB_1;

                            arg_BB_1 = ((Hediff_Injury injury) => injury.Part == rec);

                            foreach (Hediff_Injury current in arg_BB_0.Where(arg_BB_1))
                            {
                                bool flag4 = num2 > 0;
                                if (flag4)
                                {
                                    bool flag5 = current.CanHealNaturally() && !current.IsPermanent();
                                    if (flag5)
                                    {
                                        //current.Heal((float)((int)current.Severity + 1));
                                        if (!this.CasterPawn.IsColonist)
                                        {
                                            current.Heal(30.0f + (float)pwrVal * 3f); // power affects how much to heal
                                        }
                                        else
                                        {
                                            current.Heal((14.0f + (float)pwrVal * 3f) * comp.arcaneDmg); // power affects how much to heal
                                        }
                                        TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, 1f + .2f * pwrVal);
                                        TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .8f + .1f * pwrVal);
                                        num--;
                                        num2--;
                                    }
                                }
                            }
                            using (IEnumerator <Hediff> enumerator1 = pawn.health.hediffSet.GetHediffsTendable().GetEnumerator())
                            {
                                while (enumerator1.MoveNext())
                                {
                                    if (num > 0)
                                    {
                                        Hediff rec1 = enumerator1.Current;
                                        if (rec1.TendableNow() && rec1.Bleeding && rec1 is Hediff_MissingPart)
                                        {
                                            Traverse.Create(root: rec1).Field(name: "isFreshInt").SetValue(false);
                                            num--;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (undeadFlag)
            {
                for (int i = 0; i < 2 + verVal; i++)
                {
                    TM_Action.DamageUndead(pawn, (8.0f + (float)pwrVal * 5f) * comp.arcaneDmg, this.CasterPawn);
                }
            }
            return(true);
        }
Пример #16
0
        private static void DrawHediffRow(Rect rect, Pawn pawn, IEnumerable <Hediff> diffs, ref float curY)
        {
            float          num   = rect.width * 0.375f;
            float          width = rect.width - num - lastMaxIconsTotalWidth;
            BodyPartRecord part  = diffs.First().Part;
            float          a     = ((part != null) ? Text.CalcHeight(part.LabelCap, num) : Text.CalcHeight("WholeBody".Translate(), num));
            float          num2  = 0f;
            float          num3  = curY;
            float          num4  = 0f;

            foreach (IGrouping <int, Hediff> item in from x in diffs
                     group x by x.UIGroupKey)
            {
                int    num5 = item.Count();
                string text = item.First().LabelCap;
                if (num5 != 1)
                {
                    text = text + " x" + num5;
                }
                num4 += Text.CalcHeight(text, width);
            }
            num2 = num4;
            Rect rect2 = new Rect(0f, curY, rect.width, Mathf.Max(a, num2));

            DoRightRowHighlight(rect2);
            if (part != null)
            {
                GUI.color = HealthUtility.GetPartConditionLabel(pawn, part).Second;
                Widgets.Label(new Rect(0f, curY, num, 100f), part.LabelCap);
            }
            else
            {
                GUI.color = HealthUtility.RedColor;
                Widgets.Label(new Rect(0f, curY, num, 100f), "WholeBody".Translate());
            }
            GUI.color = Color.white;
            foreach (IGrouping <int, Hediff> item2 in from x in diffs
                     group x by x.UIGroupKey)
            {
                int             num6           = 0;
                Hediff          hediff         = null;
                Texture2D       bleedingIcon   = null;
                TextureAndColor stateIcon      = null;
                float           totalBleedRate = 0f;
                foreach (Hediff item3 in item2)
                {
                    if (num6 == 0)
                    {
                        hediff = item3;
                    }
                    stateIcon = item3.StateIcon;
                    if (item3.Bleeding)
                    {
                        bleedingIcon = BleedingIcon;
                    }
                    totalBleedRate += item3.BleedRate;
                    num6++;
                }
                string text2 = hediff.LabelCap;
                if (num6 != 1)
                {
                    text2 = text2 + " x" + num6.ToStringCached();
                }
                GUI.color = hediff.LabelColor;
                float num7  = Text.CalcHeight(text2, width);
                Rect  rect3 = new Rect(num, curY, width, num7);
                Widgets.Label(rect3, text2);
                GUI.color = Color.white;
                Rect iconsRect = new Rect(rect3.x + 10f, rect3.y, rect.width - num - 10f, rect3.height);
                List <GenUI.AnonymousStackElement> list = new List <GenUI.AnonymousStackElement>();
                foreach (HediffDef item4 in item2.Select((Hediff h) => h.def).Distinct())
                {
                    HediffDef localHediffDef = item4;
                    list.Add(new GenUI.AnonymousStackElement
                    {
                        drawer = delegate(Rect r)
                        {
                            float num10 = iconsRect.width - (r.x - iconsRect.x) - 20f;
                            r           = new Rect(iconsRect.x + num10, r.y, 20f, 20f);
                            Widgets.InfoCardButton(r.x, r.y, localHediffDef);
                        },
                        width = 20f
                    });
                }
                if ((bool)bleedingIcon)
                {
                    list.Add(new GenUI.AnonymousStackElement
                    {
                        drawer = delegate(Rect r)
                        {
                            float num9 = iconsRect.width - (r.x - iconsRect.x) - 20f;
                            r          = new Rect(iconsRect.x + num9, r.y, 20f, 20f);
                            GUI.DrawTexture(r.ContractedBy(GenMath.LerpDouble(0f, 0.6f, 5f, 0f, Mathf.Min(totalBleedRate, 1f))), bleedingIcon);
                        },
                        width = 20f
                    });
                }
                if (stateIcon.HasValue)
                {
                    list.Add(new GenUI.AnonymousStackElement
                    {
                        drawer = delegate(Rect r)
                        {
                            float num8 = iconsRect.width - (r.x - iconsRect.x) - 20f;
                            r          = new Rect(iconsRect.x + num8, r.y, 20f, 20f);
                            GUI.color  = stateIcon.Color;
                            GUI.DrawTexture(r, stateIcon.Texture);
                            GUI.color = Color.white;
                        },
                        width = 20f
                    });
                }
                GenUI.DrawElementStack(iconsRect, num7, list, delegate(Rect r, GenUI.AnonymousStackElement obj)
                {
                    obj.drawer(r);
                }, (GenUI.AnonymousStackElement obj) => obj.width);
                lastMaxIconsTotalWidth = Mathf.Max(lastMaxIconsTotalWidth, list.Sum((GenUI.AnonymousStackElement x) => x.width + 5f) - 5f);
                curY += num7;
            }
            GUI.color = Color.white;
            curY      = num3 + Mathf.Max(a, num2);
            if (Widgets.ButtonInvisible(rect2, CanEntryBeClicked(diffs, pawn)))
            {
                EntryClicked(diffs, pawn);
            }
            if (Mouse.IsOver(rect2))
            {
                TooltipHandler.TipRegion(rect2, new TipSignal(() => GetTooltip(diffs, pawn, part), (int)curY + 7857));
            }
        }
Пример #17
0
        public override float GetPriority(Pawn pawn)
        {
            Hediff chiHD = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD);
            CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();

            if (chiHD == null)
            {
                return(0f);
            }
            if (comp == null)
            {
                return(0f);
            }
            if ((int)chiHD.Severity > 80)
            {
                return(0f);
            }
            if (Find.TickManager.TicksGame < comp.allowMeditateTick)
            {
                return(0f);
            }
            TimeAssignmentDef timeAssignmentDef;

            if (pawn.RaceProps.Humanlike)
            {
                timeAssignmentDef = ((pawn.timetable != null) ? pawn.timetable.CurrentAssignment : TimeAssignmentDefOf.Anything);
            }
            else
            {
                int num = GenLocalDate.HourOfDay(pawn);
                timeAssignmentDef = ((num >= 7 && num <= 21) ? TimeAssignmentDefOf.Anything : TimeAssignmentDefOf.Sleep);
            }
            float curLevel = chiHD.Severity;

            if (timeAssignmentDef == TimeAssignmentDefOf.Anything)
            {
                if (curLevel < 30.0f)
                {
                    return(8f);
                }
                else if (curLevel < 70.0f)
                {
                    return(4f);
                }
                return(0f);
            }
            if (timeAssignmentDef == TimeAssignmentDefOf.Work)
            {
                return(0f);
            }
            if (timeAssignmentDef == TimeAssignmentDefOf.Joy)
            {
                if (curLevel < 70f)
                {
                    return(8f);
                }
                return(0f);
            }
            if (timeAssignmentDef == TimeAssignmentDefOf.Sleep)
            {
                if (curLevel < 50 && verVal >= 3)
                {
                    return(8f);
                }
                else if (curLevel < 70 && verVal >= 2)
                {
                    return(6f);
                }
                return(0f);
            }
            throw new NotImplementedException();
        }
Пример #18
0
        public static void GiveVitaeEffects(Pawn receiver, Pawn donor)
        {
            var pawn = receiver;

            //Give Vitae High Effect
            Hediff vitaeHighHediff = HediffMaker.MakeHediff(VampDefOf.ROMV_VitaeHigh, pawn, null);
            float  numHigh         = 0.75f;

            AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, VampDefOf.ROMV_VitaeChemical, ref numHigh);
            vitaeHighHediff.Severity = numHigh;
            pawn.health.AddHediff(vitaeHighHediff, null, null);

            //Give Vitae Tolerance Effect
            Hediff vitaeToleranceHediff = HediffMaker.MakeHediff(VampDefOf.ROMV_VitaeTolerance, pawn, null);
            float  numTol = 0.035f;

            numTol /= receiver.BodySize;
            AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, VampDefOf.ROMV_VitaeChemical, ref numTol);
            vitaeToleranceHediff.Severity = numTol;
            pawn.health.AddHediff(vitaeToleranceHediff, null, null);

            const float addictiveness                   = 1.0f;
            const float minToleranceToAddict            = 0.01f;
            const float existingAddictionSeverityOffset = 0.2f;

            var needLevelOffset        = 1f;
            var overdoseSeverityOffset = new FloatRange(0.18f, 0.35f);
            var chemical = VampDefOf.ROMV_VitaeChemical;

            var addictionHediffDef = VampDefOf.ROMV_VitaeAddiction;
            var lookTarget         = receiver;
            var hediff             = AddictionUtility.FindToleranceHediff(lookTarget, VampDefOf.ROMV_VitaeChemical);
            var num             = hediff?.Severity ?? 0f;
            var hediffAddiction = AddictionUtility.FindAddictionHediff(lookTarget, VampDefOf.ROMV_VitaeChemical);

            if (hediffAddiction != null)
            {
                hediffAddiction.Severity += existingAddictionSeverityOffset;
            }
            else if (Rand.Value < addictiveness && num >= minToleranceToAddict)
            {
                lookTarget.health.AddHediff(addictionHediffDef, null, null);
                if (PawnUtility.ShouldSendNotificationAbout(lookTarget))
                {
                    Find.LetterStack.ReceiveLetter("LetterLabelNewlyAddicted".Translate(new object[]
                    {
                        chemical.label
                    }).CapitalizeFirst(), "LetterNewlyAddicted".Translate(new object[]
                    {
                        lookTarget.LabelShort,
                        chemical.label
                    }).AdjustedFor(lookTarget).CapitalizeFirst(), LetterDefOf.NegativeEvent, lookTarget, null);
                }
                AddictionUtility.CheckDrugAddictionTeachOpportunity(lookTarget);
            }

            if (addictionHediffDef.causesNeed != null)
            {
                var need = lookTarget.needs.AllNeeds.Find((Need x) => x.def == addictionHediffDef.causesNeed);
                if (need != null)
                {
                    AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(lookTarget, chemical,
                                                                                 ref needLevelOffset);
                    need.CurLevel += needLevelOffset;
                }
            }
//            var firstHediffOfDef = lookTarget.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose, false);
//            var num2 = firstHediffOfDef?.Severity ?? 0f;
//            if (num2 < 0.9f && Rand.Value < largeOverdoseChance)
//            {
//                var num3 = Rand.Range(0.85f, 0.99f);
//                HealthUtility.AdjustSeverity(lookTarget, HediffDefOf.DrugOverdose, num3 - num2);
//                if (lookTarget.Faction == Faction.OfPlayer)
//                {
//                    Messages.Message("MessageAccidentalOverdose".Translate(new object[]
//                    {
//                        lookTarget.LabelIndefinite(),
//                        chemical.LabelCap
//                    }).CapitalizeFirst(), MessageTypeDefOf.NegativeHealthEvent);
//                }
//            }
//            else
//            {
//                var num4 = overdoseSeverityOffset.RandomInRange / lookTarget.BodySize;
//                if (num4 > 0f)
//                {
//                    HealthUtility.AdjustSeverity(lookTarget, HediffDefOf.DrugOverdose, num4);
//                }
//            }
        }
Пример #19
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn != null && pawn.Map != null && pawn.health != null && pawn.health.hediffSet != null && pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_ChiHD) && !pawn.Drafted)
            {
                if (pawn.InBed() || HealthAIUtility.ShouldSeekMedicalRest(pawn) || !(pawn.GetPosture() == PawnPosture.Standing))
                {
                    return(null);
                }
                Need_Joy curJoy = pawn.needs.joy;
                if (curJoy == null)
                {
                    return(null);
                }
                if (curJoy.CurLevel >= .8f)
                {
                    return(null);
                }
                if (pawn.CurJob != null && pawn.CurJob.playerForced)
                {
                    return(null);
                }
                if (pawn.timetable != null && !(pawn.timetable.CurrentAssignment.allowJoy && pawn.timetable.CurrentAssignment.allowRest))
                {
                    return(null);
                }
                CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();
                if (comp != null)
                {
                    MightPower mightPower = comp.MightData.MightPowersM.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_Meditate);

                    if (mightPower == null)
                    {
                        return(null);
                    }

                    if (!mightPower.AutoCast)
                    {
                        return(null);
                    }

                    Hediff      hediff  = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD);
                    PawnAbility ability = pawn.GetComp <CompAbilityUserMight>().AbilityData.Powers.FirstOrDefault((PawnAbility x) => x.Def == TorannMagicDefOf.TM_Meditate);

                    if (ability.CooldownTicksLeft > 0 || hediff.Severity >= 70)
                    {
                        return(null);
                    }

                    Building_Bed building_Bed = pawn.ownership.OwnedBed;
                    if (building_Bed != null)
                    {
                        if (building_Bed.GetRoom() != null && !building_Bed.GetRoom().PsychologicallyOutdoors)
                        {
                            List <IntVec3> roomCells = building_Bed.GetRoom().Cells.ToList();
                            for (int i = 0; i < roomCells.Count; i++)
                            {
                                if (roomCells[i].IsValid && roomCells[i].Walkable(pawn.Map) && roomCells[i].GetFirstBuilding(pawn.Map) == null)
                                {
                                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, roomCells[i]));
                                }
                            }
                        }
                    }
                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, pawn.Position));
                }
            }
            return(null);
        }
Пример #20
0
        /// <summary>
        /// Does the effect.
        /// </summary>
        /// <param name="usedBy">the pawn that used this instance</param>
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);
            var mutagen = parent.def.GetModExtension <MutagenExtension>()?.mutagen;

            Hediff hediff = FindLifeThreateningHediff(usedBy);

            if (hediff != null)
            {
                Cure(hediff);
                return;
            }

            if (HealthUtility.TicksUntilDeathDueToBloodLoss(usedBy) < 2500)
            {
                Hediff hediff2 = FindMostBleedingHediff(usedBy);
                if (hediff2 != null)
                {
                    Cure(hediff2);
                    return;
                }
            }

            if (usedBy.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury hediff_Injury = FindPermanentInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                if (hediff_Injury != null)
                {
                    Cure(hediff_Injury);
                    return;
                }
            }

            BodyPartRecord bodyPartRecord = FindBiggestMissingBodyPart(usedBy, HandCoverageAbsWithChildren);

            if (bodyPartRecord != null)
            {
                Cure(bodyPartRecord, usedBy);
                return;
            }

            Hediff_Injury hediff_Injury2 = FindPermanentInjury(usedBy, from x in usedBy.health.hediffSet.GetNotMissingParts()
                                                               where x.def == BodyPartDefOf.Eye
                                                               select x);

            if (hediff_Injury2 != null)
            {
                Cure(hediff_Injury2);

                if (hediff_Injury2.Part != null)
                {
                    AddMutationToPart(hediff_Injury2.Part, usedBy, usedBy.GetMutationTracker()?.HighestInfluence, mutagen: mutagen);
                }


                return;
            }

            Hediff hediff3 = FindImmunizableHediffWhichCanKill(usedBy);

            if (hediff3 != null)
            {
                Cure(hediff3);
                return;
            }

            Hediff hediff4 = FindNonInjuryMiscBadHediff(usedBy, true);

            if (hediff4 != null)
            {
                Cure(hediff4);
                return;
            }

            Hediff hediff5 = FindNonInjuryMiscBadHediff(usedBy, false);

            if (hediff5 != null)
            {
                Cure(hediff5);
                return;
            }

            if (usedBy.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury hediff_Injury3 = FindInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                if (hediff_Injury3 != null)
                {
                    Cure(hediff_Injury3);
                    return;
                }
            }

            BodyPartRecord bodyPartRecord2 = FindBiggestMissingBodyPart(usedBy);

            if (bodyPartRecord2 != null)
            {
                Cure(bodyPartRecord2, usedBy);
                return;
            }

            Hediff_Addiction hediff_Addiction = FindAddiction(usedBy);

            if (hediff_Addiction != null)
            {
                Cure(hediff_Addiction);
                return;
            }

            Hediff_Injury hediff_Injury4 = FindPermanentInjury(usedBy);

            if (hediff_Injury4 != null)
            {
                Cure(hediff_Injury4);
                return;
            }

            Hediff_Injury hediff_Injury5 = FindInjury(usedBy);

            if (hediff_Injury5 != null)
            {
                Cure(hediff_Injury5);
            }

            var tracker = usedBy.GetAspectTracker();
            var bAspect = FindBadAspectToRemove(usedBy);

            if (tracker != null && bAspect != null)
            {
                tracker.Remove(bAspect);
                ApplyMutagen(usedBy);
            }
        }
Пример #21
0
        protected override bool TryCastShot()
        {
            //    Log.Message("Try Cast Shot Called");
            //Log.Message("Cast");
            bool          GetsHot                    = this.UseAbilityProps.GetsHot;
            bool          Jams                       = this.UseAbilityProps.Jams;
            bool          GetsHotCrit                = this.UseAbilityProps.GetsHotCrit;
            float         GetsHotCritChance          = this.UseAbilityProps.GetsHotCritChance;
            bool          GetsHotCritExplosion       = this.UseAbilityProps.GetsHotCritExplosion;
            float         GetsHotCritExplosionChance = this.UseAbilityProps.GetsHotCritExplosionChance;
            bool          canDamageWeapon            = this.UseAbilityProps.HotDamageWeapon || this.UseAbilityProps.JamsDamageWeapon;
            float         extraWeaponDamage          = (Jams && this.UseAbilityProps.JamsDamageWeapon) ? this.UseAbilityProps.JamDamage : (GetsHot && this.UseAbilityProps.HotDamageWeapon) ? this.UseAbilityProps.HotDamage : 0f;
            bool          TwinLinked                 = this.UseAbilityProps.TwinLinked;
            bool          Multishot                  = this.UseAbilityProps.Multishot;
            int           ScattershotCount           = this.UseAbilityProps.ScattershotCount;
            bool          UserEffect                 = this.UseAbilityProps.EffectsUser;
            HediffDef     UserHediff                 = this.UseAbilityProps.UserEffect;
            float         AddHediffChance            = this.UseAbilityProps.EffectsUserChance;
            List <string> Immunitylist               = this.UseAbilityProps.UserEffectImmuneList;
            var           result                     = false;

            TargetsAoE.Clear();
            UpdateTargets();
            var burstShots = ShotsPerBurst;

            if (UseAbilityProps.AbilityTargetCategory != AbilityTargetCategory.TargetAoE && TargetsAoE.Count > 1)
            {
                TargetsAoE.RemoveRange(0, TargetsAoE.Count - 1);
            }
            if (UseAbilityProps.mustHaveTarget && TargetsAoE.Count == 0)
            {
                Messages.Message("AU_NoTargets".Translate(), MessageTypeDefOf.RejectInput);
                Ability.Notify_AbilityFailed(true);
                return(false);
            }

            for (var i = 0; i < TargetsAoE.Count; i++)
            {
                //                for (int j = 0; j < burstshots; j++)
                //                {
                if (verbProps.defaultProjectile != null) //ranged attacks WILL have projectiles
                {
                    if ((GetsHot && AMASettings.Instance.AllowGetsHot) || (Jams && AMASettings.Instance.AllowJams))
                    {
                        string msg = string.Format("");
                        string reliabilityString;
                        float  failChance;
                        StatPart_Reliability.GetReliability(this.UseAbilityProps, out reliabilityString, out failChance);
                        failChance = GetsHot ? (failChance / 10) : (failChance / 100);
                        if (Rand.Chance(failChance))
                        {
                            if (GetsHot)
                            {
                                DamageDef damageDef        = this.Projectile.projectile.damageDef;
                                HediffDef HediffToAdd      = damageDef.hediff;
                                float     ArmorPenetration = this.Projectile.projectile.GetArmorPenetration(this.EquipmentSource, null);
                                float     DamageAmount     = 0;
                                Pawn      launcherPawn     = this.caster as Pawn;
                                if (Rand.Chance(GetsHotCritChance))
                                {
                                    DamageAmount = this.Projectile.projectile.GetDamageAmount(this.EquipmentSource, null);
                                    msg          = string.Format("{0}'s {1} critically overheated. ({2} chance) causing {3} damage", this.caster.LabelCap, this.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                                    if (GetsHotCritExplosion && Rand.Chance(GetsHotCritExplosionChance))
                                    {
                                        CriticalOverheatExplosion();
                                    }
                                }
                                else
                                {
                                    DamageAmount = this.Projectile.projectile.GetDamageAmount(this.EquipmentSource, null);
                                    msg          = string.Format("{0}'s {1} overheated. ({2} chance) causing {3} damage", this.caster.LabelCap, this.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                                }
                                float maxburndmg = DamageAmount / 10;
                                while (DamageAmount > 0f)
                                {
                                    List <BodyPartRecord> list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Finger") || x.def.defName.Contains("Hand")).ToList <BodyPartRecord>();
                                    if (list.NullOrEmpty())
                                    {
                                        list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Arm") || x.def.defName.Contains("Shoulder")).ToList <BodyPartRecord>();
                                    }
                                    if (list.NullOrEmpty())
                                    {
                                        list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbCore) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbSegment) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbDigit)).ToList <BodyPartRecord>();
                                    }
                                    if (list.NullOrEmpty())
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        BodyPartRecord part = list.RandomElement();
                                        Hediff         hediff;
                                        float          severity = Rand.Range(Math.Min(0.1f, DamageAmount), Math.Min(DamageAmount, maxburndmg));
                                        hediff          = HediffMaker.MakeHediff(HediffToAdd, launcherPawn, null);
                                        hediff.Severity = severity;
                                        launcherPawn.health.AddHediff(hediff, part, null);
                                        DamageAmount -= severity;
                                    }
                                }
                                Messages.Message(msg, MessageTypeDefOf.NegativeHealthEvent);
                            }
                            else
                            {
                                msg = string.Format("{0}'s {1} had a weapon jam. ({2} chance)", this.caster.LabelCap, this.EquipmentSource.LabelCap, failChance.ToStringPercent());
                                Messages.Message(msg, MessageTypeDefOf.SilentInput);
                            }
                            float defaultCooldownTime = this.verbProps.defaultCooldownTime * 2;
                            this.verbProps.defaultCooldownTime = defaultCooldownTime;
                            if (canDamageWeapon)
                            {
                                if (extraWeaponDamage != 0f)
                                {
                                    if (this.EquipmentSource != null)
                                    {
                                        if (this.EquipmentSource.HitPoints - (int)extraWeaponDamage >= 0)
                                        {
                                            this.EquipmentSource.HitPoints = this.EquipmentSource.HitPoints - (int)extraWeaponDamage;
                                        }
                                        else if (this.EquipmentSource.HitPoints - (int)extraWeaponDamage < 0)
                                        {
                                            this.EquipmentSource.HitPoints = 0;
                                            this.EquipmentSource.Destroy();
                                        }
                                    }
                                    if (this.HediffCompSource != null)
                                    {
                                        /*
                                         * if (__instance.HediffCompSource.parent.Part..HitPoints - (int)extraWeaponDamage >= 0)
                                         * {
                                         *  __instance.HediffCompSource.HitPoints = __instance.HediffCompSource.HitPoints - (int)extraWeaponDamage;
                                         * }
                                         * else if (__instance.HediffCompSource.HitPoints - (int)extraWeaponDamage < 0)
                                         * {
                                         *  __instance.HediffCompSource.HitPoints = 0;
                                         *  __instance.HediffCompSource.Destroy();
                                         * }
                                         */
                                    }
                                }
                                else
                                {
                                    if (this.EquipmentSource != null)
                                    {
                                        if (this.EquipmentSource.HitPoints > 0)
                                        {
                                            this.EquipmentSource.HitPoints--;
                                        }
                                    }
                                }
                            }
                            if (Jams)
                            {
                                if (this.EquipmentSource != null)
                                {
                                    SpinningLaserGun spinner = (SpinningLaserGun)this.EquipmentSource;
                                    if (spinner != null)
                                    {
                                        spinner.state = SpinningLaserGunBase.State.Idle;
                                        spinner.ReachRotationSpeed(0, 0);
                                    }
                                }
                                return(false);
                            }
                        }
                    }

                    var attempt = TryLaunchProjectile(verbProps.defaultProjectile, TargetsAoE[i]);

                    if (ScattershotCount > 0 && Multishot && AMASettings.Instance.AllowMultiShot)
                    {
                        //    Log.Message(string.Format("AllowMultiShot: {0} Projectile Count: {1}", AMASettings.Instance.AllowMultiShot && Multishot, ScattershotCount));
                        for (int ii = 0; ii < ScattershotCount; ii++)
                        {
                            //    Log.Message(string.Format("Launching extra projectile {0} / {1}", i+1, ScattershotCount));
                            //    AccessTools.Method(typeof(Verb_Shoot).BaseType, "TryCastShot", null, null).Invoke(__instance, null);
                            TryLaunchProjectile(verbProps.defaultProjectile, TargetsAoE[i]);
                        }
                    }
                    else
                    if (TwinLinked)
                    {
                        TryLaunchProjectile(verbProps.defaultProjectile, TargetsAoE[i]);
                    }
                    if (UserEffect && AMASettings.Instance.AllowUserEffects)
                    {
                        if (caster.def.category == ThingCategory.Pawn)
                        {
                            bool Immunityflag = false;
                            Pawn launcherPawn = this.caster as Pawn;
                            if (!Immunitylist.NullOrEmpty())
                            {
                                foreach (var item in Immunitylist)
                                {
                                    Immunityflag = launcherPawn.def.defName.Contains(item);
                                    if (Immunityflag)
                                    {
                                        //    Log.Message(string.Format("{0} is immune to their {1}'s UseEffect", launcherPawn.LabelShortCap, __instance.EquipmentSource.LabelShortCap));
                                    }
                                }

                                /*
                                 * List<string> list = GunExt.UserEffectImmuneList.Where(x => DefDatabase<ThingDef>.GetNamedSilentFail(x) != null).ToList();
                                 * bool Immunityflag = list.Contains(launcherPawn.def.defName);
                                 * if (Immunityflag)
                                 * {
                                 *  return;
                                 * }
                                 */
                            }
                            if (!Immunityflag)
                            {
                                var rand = Rand.Value;       // This is a random percentage between 0% and 100%
                                                             //    Log.Message(string.Format("GunExt.EffectsUser Effect: {0}, Chance: {1}, Roll: {2}, Result: {3}" + GunExt.ResistEffectStat != null ? ", Resist Stat: "+GunExt.ResistEffectStat.LabelCap+", Resist Amount"+ __instance.caster.GetStatValue(GunExt.ResistEffectStat, true) : null, GunExt.UserEffect.LabelCap, AddHediffChance, rand, rand <= AddHediffChance));
                                if (rand <= AddHediffChance) // If the percentage falls under the chance, success!
                                {
                                    var randomSeverity = Rand.Range(0.05f, 0.15f);
                                    var effectOnPawn   = launcherPawn?.health?.hediffSet?.GetFirstHediffOfDef(UserHediff);
                                    if (effectOnPawn != null)
                                    {
                                        effectOnPawn.Severity += randomSeverity;
                                    }
                                    else
                                    {
                                        Hediff hediff = HediffMaker.MakeHediff(UserHediff, launcherPawn, null);
                                        hediff.Severity = randomSeverity;
                                        launcherPawn.health.AddHediff(hediff, null, null);
                                    }
                                }
                            }
                        }
                    }
                    ////Log.Message(TargetsAoE[i].ToString());
                    if (attempt != null)
                    {
                        if (attempt == true)
                        {
                            result = true;
                        }
                        if (attempt == false)
                        {
                            result = false;
                        }
                    }
                }
                else //melee attacks WON'T have projectiles
                {
                    //    Log.Message("No Projectile");
                    var victim = TargetsAoE[i].Thing;
                    if (victim != null)
                    {
                        //    Log.Message("Yes victim");
                        if (victim is Pawn pawnVictim)
                        {
                            //    Log.Message("Yes victim is pawn");
                            AbilityEffectUtility.ApplyMentalStates(pawnVictim, CasterPawn, UseAbilityProps.mentalStatesToApply, UseAbilityProps.abilityDef, null);
                            AbilityEffectUtility.ApplyHediffs(pawnVictim, CasterPawn, UseAbilityProps.hediffsToApply, null);
                            AbilityEffectUtility.SpawnSpawnables(UseAbilityProps.thingsToSpawn, pawnVictim, victim.MapHeld, victim.PositionHeld);
                        }
                    }
                    else
                    {
                        //    Log.Message("Victim is null");
                        AbilityEffectUtility.SpawnSpawnables(UseAbilityProps.thingsToSpawn, CasterPawn, CasterPawn.MapHeld, CasterPawn.PositionHeld);
                    }
                }
                //                }
            }

            PostCastShot(result, out result);
            if (result == false)
            {
                Ability.Notify_AbilityFailed(UseAbilityProps.refundsPointsAfterFailing);
            }
            return(result);
        }
Пример #22
0
        protected override bool TryCastShot()
        {
            Pawn caster = base.CasterPawn;
            Pawn pawn   = this.currentTarget.Thing as Pawn;

            MagicPowerSkill pwr = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Purify.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Purify_pwr");
            MagicPowerSkill ver = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Purify.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Purify_ver");

            pwrVal = pwr.level;
            verVal = ver.level;
            if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless))
            {
                MightPowerSkill mpwr = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                MightPowerSkill mver = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                pwrVal = mpwr.level;
                verVal = mver.level;
            }
            bool flag = pawn != null && !pawn.Dead;

            if (flag)
            {
                int num = Mathf.RoundToInt(1f + (.4f * verVal));
                using (IEnumerator <BodyPartRecord> enumerator = pawn.health.hediffSet.GetInjuredParts().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        BodyPartRecord rec   = enumerator.Current;
                        bool           flag2 = num > 0;
                        if (flag2)
                        {
                            int num2 = 1 + verVal;
                            IEnumerable <Hediff_Injury> arg_BB_0 = pawn.health.hediffSet.GetHediffs <Hediff_Injury>();
                            Func <Hediff_Injury, bool>  arg_BB_1;

                            arg_BB_1 = ((Hediff_Injury injury) => injury.Part == rec);

                            foreach (Hediff_Injury current in arg_BB_0.Where(arg_BB_1))
                            {
                                bool flag4 = num2 > 0;
                                if (flag4)
                                {
                                    bool flag5 = !current.CanHealNaturally() && current.IsOld();
                                    if (flag5)
                                    {
                                        if (rec.def.tags.Contains("ConsciousnessSource"))
                                        {
                                            if (pwrVal >= 1)
                                            {
                                                current.Heal(pwrVal);
                                                num--;
                                                num2--;
                                            }
                                        }
                                        else
                                        {
                                            current.Heal(2f + pwrVal * 2);
                                            //current.Heal(5.0f + (float)pwrVal * 3f); // power affects how much to heal
                                            num--;
                                            num2--;
                                        }
                                        TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .6f);
                                        TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .4f);
                                    }
                                }
                            }
                        }
                    }
                }
                using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Hediff rec   = enumerator.Current;
                        bool   flag2 = num > 0;
                        if (flag2)
                        {
                            if (rec.def.defName == "Cataract" || rec.def.defName == "HearingLoss" || rec.def.defName.Contains("ToxicBuildup"))
                            {
                                rec.Heal(.4f + .3f * pwrVal);
                                num--;
                            }
                            if ((rec.def.defName == "Blindness" || rec.def.defName.Contains("Asthma") || rec.def.defName == "Cirrhosis" || rec.def.defName == "ChemicalDamageModerate") && verVal >= 1)
                            {
                                rec.Heal(.3f + .2f * pwrVal);
                                if (rec.def.defName.Contains("Asthma"))
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                                num--;
                            }
                            if ((rec.def.defName == "Frail" || rec.def.defName == "BadBack" || rec.def.defName.Contains("Carcinoma") || rec.def.defName == "ChemicalDamageSevere") && verVal >= 2)
                            {
                                rec.Heal(.2f + .15f * pwrVal);
                                num--;
                            }
                            if ((rec.def.defName.Contains("Alzheimers") || rec.def.defName == "Dementia" || rec.def.defName.Contains("HeartArteryBlockage") || rec.def.defName == "PsychicShock" || rec.def.defName == "CatatonicBreakdown") && verVal >= 3)
                            {
                                rec.Heal(.1f + .1f * pwrVal);
                                num--;
                            }
                            TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .6f);
                            TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .4f);
                        }
                    }
                }
                using (IEnumerator <Hediff_Addiction> enumerator = pawn.health.hediffSet.GetHediffs <Hediff_Addiction>().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Hediff_Addiction rec   = enumerator.Current;
                        bool             flag2 = num > 0;
                        if (flag2)
                        {
                            if (rec.Chemical.defName == "Alcohol" || rec.Chemical.defName == "Smokeleaf")
                            {
                                rec.Severity -= (.3f + .3f * pwrVal);
                                num--;
                            }
                            if ((rec.Chemical.defName == "GoJuice" || rec.Chemical.defName == "WakeUp") && verVal >= 1)
                            {
                                rec.Severity -= (.25f + .25f * pwrVal);
                                num--;
                            }
                            if (rec.Chemical.defName == "Psychite" && verVal >= 2)
                            {
                                rec.Severity -= (.25f + .25f * pwrVal);
                                num--;
                            }
                            if (verVal >= 3)
                            {
                                rec.Severity -= (.15f + .15f * pwrVal);
                                num--;
                            }
                            TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .6f);
                            TM_MoteMaker.ThrowRegenMote(pawn.Position.ToVector3Shifted(), pawn.Map, .4f);
                        }
                    }
                }
            }
            return(true);
        }
Пример #23
0
		public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
		{
			base.Apply(target, dest);
			Hediff psychicBreakdown = HediffMaker.MakeHediff(DefDatabase<HediffDef>.GetNamed("PsychicBreakdown"), parent.pawn);
			psychicBreakdown.Severity = 15;
			parent.pawn.health.AddHediff(psychicBreakdown);
			if (target.Thing == null||!(target.Thing is Corpse)) { return; }
			Pawn pawn = ((Corpse)target.Thing).InnerPawn;
			float x2 = ((pawn.Corpse == null) ? 0f : (pawn.Corpse.GetComp<CompRottable>().RotProgress / 60000f));
			ResurrectionUtility.Resurrect(pawn);
			Hediff psychicRessurection = HediffMaker.MakeHediff(DefDatabase<HediffDef>.GetNamed("MorePsycasts_PsychicRessurection"), pawn);
			if (!pawn.health.WouldDieAfterAddingHediff(psychicRessurection))
			{
				pawn.health.AddHediff(psychicRessurection);
			}
			x2 = (x2*(float)MorePsycasts_Mod.settings.reviving_touch_max_proportial_damage)+(float)MorePsycasts_Mod.settings.reviving_touch_min_proportial_damage;
			float toBeDealt = pawn.health.LethalDamageThreshold * x2;
			for (int i=0; i<toBeDealt;i++)
            {
				BodyPartRecord part = pawn.health.hediffSet.GetRandomNotMissingPart(DefDatabase<DamageDef>.GetNamed("Rotting"));
				Hediff hediff = HediffMaker.MakeHediff(DefDatabase<HediffDef>.GetNamed("MorePsycasts_PsychicBurn"), pawn, part);
				hediff.Severity = Rand.Value;
				if (!pawn.health.WouldDieAfterAddingHediff(hediff))
				{
					pawn.health.AddHediff(hediff);
				}
			}

			BodyPartRecord brain = pawn.health.hediffSet.GetBrain();
			if (Rand.Chance(Utilities.DementiaChancePerRotDaysCurve.Evaluate(x2)) && brain != null)
			{
				Hediff hediff2 = HediffMaker.MakeHediff(RimWorld.HediffDefOf.Dementia, pawn, brain);
				if (!pawn.health.WouldDieAfterAddingHediff(hediff2))
				{
					pawn.health.AddHediff(hediff2);
				}
			}
			if (Rand.Chance(Utilities.BlindnessChancePerRotDaysCurve.Evaluate(x2)))
			{
				foreach (BodyPartRecord item in from x in pawn.health.hediffSet.GetNotMissingParts()
												where x.def == BodyPartDefOf.Eye
												select x)
				{
					if (!pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(item))
					{
						Hediff hediff3 = HediffMaker.MakeHediff(RimWorld.HediffDefOf.Blindness, pawn, item);
						pawn.health.AddHediff(hediff3);
					}
				}
			}
			if (brain != null && Rand.Chance(Utilities.ResurrectionPsychosisChancePerRotDaysCurve.Evaluate(x2)))
			{
				Hediff hediff4 = HediffMaker.MakeHediff(RimWorld.HediffDefOf.ResurrectionPsychosis, pawn, brain);
				if (!pawn.health.WouldDieAfterAddingHediff(hediff4))
				{
					pawn.health.AddHediff(hediff4);
				}
			}
			if (pawn.Dead)
			{
				Log.Error("The pawn has died while being resurrected.");
				return;
			}
			Messages.Message("MessagePawnResurrected".Translate(pawn), pawn, MessageTypeDefOf.PositiveEvent);
		}
Пример #24
0
        //bool validTarg;

        //public override bool CanHitTargetFrom(IntVec3 root, LocalTargetInfo targ)
        //{
        //    if (targ.IsValid && targ.CenterVector3.InBounds(base.CasterPawn.Map) && !targ.Cell.Fogged(base.CasterPawn.Map) && targ.Cell.Walkable(base.CasterPawn.Map))
        //    {
        //        if ((root - targ.Cell).LengthHorizontal < this.verbProps.range)
        //        {
        //            //out of range
        //            validTarg = true;
        //        }
        //        else
        //        {
        //            validTarg = false;
        //        }
        //    }
        //    else
        //    {
        //        validTarg = false;
        //    }
        //    return validTarg;
        //}

        protected override bool TryCastShot()
        {
            bool result = false;
            Pawn p      = this.CasterPawn;
            CompAbilityUserMagic comp = this.CasterPawn.GetComp <CompAbilityUserMagic>();

            if (this.currentTarget != null && base.CasterPawn != null)
            {
                Map map = this.CasterPawn.Map;
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (this.currentTarget.Thing != null && this.currentTarget.Thing == base.CasterPawn)
                {
                    if (comp.mageLightActive == true)
                    {
                        comp.mageLightActive = false;
                        if (comp.mageLightThing != null)
                        {
                            comp.mageLightThing.Destroy(DestroyMode.Vanish);
                            comp.mageLightThing = null;
                        }
                        comp.mageLightSet = false;
                        Hediff hediff = base.CasterPawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_MageLightHD);
                        if (hediff != null)
                        {
                            base.CasterPawn.health.RemoveHediff(hediff);
                        }
                    }
                    //if (base.CasterPawn.health != null && base.CasterPawn.health.hediffSet != null && base.CasterPawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_MageLightHD))
                    //{
                    //    Hediff hediff = base.CasterPawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_MageLightHD);
                    //    if (hediff != null)
                    //    {
                    //        base.CasterPawn.health.RemoveHediff(hediff);
                    //    }
                    //    comp.mageLightActive = false;
                    //    comp.mageLightSet = false;
                    //}
                    else
                    {
                        if (comp.maxMP >= TorannMagicDefOf.TM_MageLight.upkeepEnergyCost)
                        {
                            comp.mageLightActive = true;
                            HealthUtility.AdjustSeverity(base.CasterPawn, TorannMagicDefOf.TM_MageLightHD, .5f);
                        }
                        else
                        {
                            Messages.Message("TM_NotEnoughManaToSustain".Translate(
                                                 this.CasterPawn.LabelShort,
                                                 TorannMagicDefOf.TM_MageLight.label
                                                 ), MessageTypeDefOf.RejectInput);
                        }
                    }
                }
                else
                {
                    Messages.Message("InvalidSummon".Translate(), MessageTypeDefOf.RejectInput);
                }

                result = true;
            }

            this.burstShotsLeft = 0;
            //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60;
            return(result);
        }
Пример #25
0
 static void Postfix(Pawn __instance, DamageInfo?dinfo, Hediff exactCulprit = null)
 {
     TechAdvancing.Event.OnKill(__instance);
 }
Пример #26
0
        public static bool GetOptimalHediffsToTendWithSingleTreatment(
            Pawn patient,
            bool usingMedicine,
            List <Hediff> outHediffsToTend,
            List <Hediff> tendableHediffsInTendPriorityOrder = null)
        {
            outHediffsToTend.Clear();
            //TendUtility.tmpHediffs.Clear();
            List <Hediff> tmpHediffs = new List <Hediff>();

            if (tendableHediffsInTendPriorityOrder != null)
            {
                tmpHediffs.AddRange(tendableHediffsInTendPriorityOrder);
            }
            else
            {
                List <Hediff> hediffs = patient.health.hediffSet.hediffs;
                for (int index = 0; index < hediffs.Count; ++index)
                {
                    if (hediffs[index].TendableNow(false))
                    {
                        tmpHediffs.Add(hediffs[index]);
                    }
                }
                TendUtility.SortByTendPriority(tmpHediffs);
            }
            if (!tmpHediffs.Any())
            {
                return(false);
            }
            Hediff tmpHediff1 = tmpHediffs[0];

            outHediffsToTend.Add(tmpHediff1);
            HediffCompProperties_TendDuration propertiesTendDuration = tmpHediff1.def.CompProps <HediffCompProperties_TendDuration>();

            if (propertiesTendDuration != null && propertiesTendDuration.tendAllAtOnce)
            {
                for (int index = 0; index < tmpHediffs.Count; ++index)
                {
                    if (tmpHediffs[index] != tmpHediff1 && tmpHediffs[index].def == tmpHediff1.def)
                    {
                        outHediffsToTend.Add(tmpHediffs[index]);
                    }
                }
            }
            else if (tmpHediff1 is Hediff_Injury & usingMedicine)
            {
                float severity1 = tmpHediff1.Severity;
                for (int index = 0; index < tmpHediffs.Count; ++index)
                {
                    if (tmpHediffs[index] != tmpHediff1 && tmpHediffs[index] is Hediff_Injury tmpHediff2)
                    {
                        float severity2 = tmpHediff2.Severity;
                        if (severity1 + (double)severity2 <= 20.0)
                        {
                            severity1 += severity2;
                            outHediffsToTend.Add(tmpHediff2);
                        }
                    }
                }
            }
            //TendUtility.tmpHediffs.Clear();
            return(false);
        }
Пример #27
0
        public static bool Prefix(ref Verb_Shoot __instance)
        {
            //    Log.Warning("TryCastShot");
            IAdvancedVerb entry = __instance.SpecialRules();

            if (entry == null)
            {
                //    Log.Message("no SpecialRules detected");
                return(true);
            }
            bool          UserEffect      = entry.EffectsUser;
            HediffDef     UserHediff      = entry.UserEffect;
            float         AddHediffChance = entry.EffectsUserChance;
            List <string> Immunitylist    = entry.UserEffectImmuneList;
            string        msg             = string.Format("");
            float         failChance      = entry.FailChance(__instance.EquipmentSource, out string reliabilityString);

            bool failed = false;

            if (failChance > 0f)
            {
                if (entry.Debug)
                {
                    Log.Message("failChance: " + failChance);
                }
                Rand.PushState();
                failed = Rand.Chance(failChance);
                Rand.PopState();
                if (entry.Debug)
                {
                    Log.Message((entry.GetsHot ? "Overheat" : "Jam") + " Chance: " + failChance + "% Result: " + (failed ? (entry.GetsHot ? "Overheated" : "Jamed") : "Passed"));
                }
                //    Log.Message("failed: "+failed);
            }
            if (failed)
            {
                bool           stillFire         = true;
                bool           canDamageWeapon   = entry.HotDamageWeapon || entry.JamsDamageWeapon;
                MessageTypeDef msgDef            = entry.GetsHot ? MessageTypeDefOf.NegativeHealthEvent : MessageTypeDefOf.SilentInput;
                float          extraWeaponDamage = entry.HotDamageWeapon ? entry.HotDamage : entry.JamDamage;
                if (entry.GetsHot)
                {
                    string    overheat     = "overheated";
                    string    causing      = "causing";
                    DamageDef damageDef    = __instance.Projectile.projectile.damageDef;
                    HediffDef HediffToAdd  = damageDef.hediff;
                    Pawn      launcherPawn = __instance.caster as Pawn;
                    Rand.PushState();
                    bool crit = Rand.Chance(entry.GetsHotCritChance);
                    Rand.PopState();
                    bool critExplode = false;
                    if (crit)
                    {
                        overheat = "critically overheated";
                        if (entry.GetsHotCritExplosion)
                        {
                            critExplode = Rand.Chance(entry.GetsHotCritExplosionChance);
                            if (critExplode)
                            {
                                causing = "causing an explosion";
                                CriticalOverheatExplosion(__instance);
                            }
                        }
                    }
                    float ArmorPenetration = __instance.Projectile.projectile.GetArmorPenetration(__instance.EquipmentSource, null) * (crit ? 1f : 0.25f);
                    float DamageAmount     = __instance.Projectile.projectile.GetDamageAmount(__instance.EquipmentSource, null) * (crit ? 1f : 0.25f);
                    msg = string.Format("{0}'s {1} " + overheat + ". ({2} chance) " + causing + " {3} damage", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent(), DamageAmount);
                    float damageLeft = DamageAmount;
                    List <BodyPartTagDef> tagDefs = new List <BodyPartTagDef>()
                    {
                        BodyPartTagDefOf.ManipulationLimbDigit, BodyPartTagDefOf.ManipulationLimbSegment
                    };
                    List <BodyPartRecord> list = launcherPawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Outside, tagDefs).ToList <BodyPartRecord>();
                    if (list.NullOrEmpty())
                    {
                        list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.defName.Contains("Arm") || x.parent.def.defName.Contains("Arm")).ToList <BodyPartRecord>();
                    }
                    if (list.NullOrEmpty())
                    {
                        list = launcherPawn.health.hediffSet.GetNotMissingParts().Where(x => x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbCore) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbSegment) || x.def.tags.Contains(BodyPartTagDefOf.ManipulationLimbDigit)).ToList <BodyPartRecord>();
                    }
                    if (!list.NullOrEmpty())
                    {
                        while (damageLeft > 0f && !list.NullOrEmpty())
                        {
                            Rand.PushState();
                            BodyPartRecord part = list.RandomElement();
                            list.Remove(part);
                            float maxPartDamage = Math.Min(damageLeft, launcherPawn.health.hediffSet.GetPartHealth(part));
                            float amount        = Rand.Range(1f, Math.Min(damageLeft, maxPartDamage));
                            Rand.PopState();
                            if (amount > 0)
                            {
                                /*
                                 * Hediff hediff = HediffMaker.MakeHediff(HediffToAdd, launcherPawn, part);
                                 * hediff.Severity = severity;
                                 * launcherPawn.health.AddHediff(hediff, part, null);
                                 */
                                DamageInfo info = new DamageInfo(damageDef, amount, ArmorPenetration, -1, __instance.EquipmentSource, part, __instance.EquipmentSource.def, DamageInfo.SourceCategory.ThingOrUnknown, __instance.CurrentTarget.Thing ?? null);
                                launcherPawn.TakeDamage(info);
                                damageLeft -= amount;
                            }
                        }
                    }
                    else
                    {
                    }
                    Messages.Message(msg, MessageTypeDefOf.NegativeHealthEvent);
                }
                if (entry.Jams)
                {
                    if (!__instance.GetsHot())
                    {
                        msg = string.Format("{0}'s {1} had a weapon jam. ({2} chance)", __instance.caster.LabelCap, __instance.EquipmentSource.LabelCap, failChance.ToStringPercent());
                        Messages.Message(msg, MessageTypeDefOf.SilentInput);
                    }
                    float defaultCooldownTime = __instance.verbProps.defaultCooldownTime * 2;
                    __instance.verbProps.defaultCooldownTime = defaultCooldownTime;
                    if (canDamageWeapon)
                    {
                        if (extraWeaponDamage != 0f)
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage >= 0)
                                {
                                    __instance.EquipmentSource.HitPoints = __instance.EquipmentSource.HitPoints - (int)extraWeaponDamage;
                                }
                                else if (__instance.EquipmentSource.HitPoints - (int)extraWeaponDamage < 0)
                                {
                                    __instance.EquipmentSource.HitPoints = 0;
                                    __instance.EquipmentSource.Destroy();
                                }
                            }
                            if (__instance.HediffCompSource != null)
                            {
                                /*
                                 * if (__instance.HediffCompSource.parent.Part.HitPoints - (int)extraWeaponDamage >= 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = __instance.HediffCompSource.HitPoints - (int)extraWeaponDamage;
                                 * }
                                 * else if (__instance.HediffCompSource.HitPoints - (int)extraWeaponDamage < 0)
                                 * {
                                 *  __instance.HediffCompSource.HitPoints = 0;
                                 *  __instance.HediffCompSource.Destroy();
                                 * }
                                 */
                            }
                        }
                        else
                        {
                            if (__instance.EquipmentSource != null)
                            {
                                if (__instance.EquipmentSource.HitPoints > 0)
                                {
                                    __instance.EquipmentSource.HitPoints--;
                                }
                            }
                        }
                    }
                    if (__instance.EquipmentSource != null)
                    {
                        SpinningLaserGun spinner = __instance.EquipmentSource as SpinningLaserGun;
                        if (spinner != null)
                        {
                            spinner.state = SpinningLaserGunBase.State.Idle;
                            spinner.ReachRotationSpeed(0, 0);
                        }
                    }
                    return(false);
                }
            }
            if (__instance.UserEffect(out float Chance, out HediffDef Effect, out StatDef ResistStat, out List <string> ImmuneList))
            {
                bool Immunityflag = false;
                Pawn launcherPawn = __instance.caster as Pawn;
                if (!Immunitylist.NullOrEmpty())
                {
                    foreach (var item in Immunitylist)
                    {
                        Immunityflag = launcherPawn.def.defName.Contains(item);
                        if (Immunityflag)
                        {
                            //    Log.Message(string.Format("{0} is immune to their {1}'s UseEffect", launcherPawn.LabelShortCap, __instance.EquipmentSource.LabelShortCap));
                        }
                    }

                    /*
                     * List<string> list = GunExt.UserEffectImmuneList.Where(x => DefDatabase<ThingDef>.GetNamedSilentFail(x) != null).ToList();
                     * bool Immunityflag = list.Contains(launcherPawn.def.defName);
                     * if (Immunityflag)
                     * {
                     *  return;
                     * }
                     */
                }
                if (!Immunityflag)
                {
                    Rand.PushState();
                    var rand = Rand.Value; // This is a random percentage between 0% and 100%
                    Rand.PopState();
                    //    Log.Message(string.Format("GunExt.EffectsUser Effect: {0}, Chance: {1}, Roll: {2}, Result: {3}" + GunExt.ResistEffectStat != null ? ", Resist Stat: "+GunExt.ResistEffectStat.LabelCap+", Resist Amount"+ __instance.caster.GetStatValue(GunExt.ResistEffectStat, true) : null, GunExt.UserEffect.LabelCap, AddHediffChance, rand, rand <= AddHediffChance));
                    if (rand <= AddHediffChance) // If the percentage falls under the chance, success!
                    {
                        Rand.PushState();
                        var randomSeverity = Rand.Range(0.05f, 0.15f);
                        Rand.PopState();
                        var effectOnPawn = launcherPawn?.health?.hediffSet?.GetFirstHediffOfDef(UserHediff);
                        if (effectOnPawn != null)
                        {
                            effectOnPawn.Severity += randomSeverity;
                        }
                        else
                        {
                            Hediff hediff = HediffMaker.MakeHediff(UserHediff, launcherPawn, null);
                            hediff.Severity = randomSeverity;
                            launcherPawn.health.AddHediff(hediff, null, null);
                        }
                    }
                }
            }
            return(true);
        }
Пример #28
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);
            bool flag = base.Pawn != null;

            if (flag)
            {
                if (!initialized)
                {
                    initialized = true;
                    this.Initialize();
                }
            }

            if (Find.TickManager.TicksGame % 16 == 0)
            {
                IEnumerable <Hediff> hdEnum = this.Pawn.health.hediffSet.GetHediffs <Hediff>();
                foreach (Hediff hd in hdEnum)
                {
                    if (hd.def.defName == "SpaceHypoxia")
                    {
                        this.Pawn.health.RemoveHediff(hd);
                        break;
                    }
                }
            }

            if (Find.TickManager.TicksGame % 6000 == 0)
            {
                if (base.Pawn.RaceProps.Animal)
                {
                    if (base.Pawn.training.CanAssignToTrain(TrainableDefOf.Tameness).Accepted)
                    {
                        while (!base.Pawn.training.HasLearned(TrainableDefOf.Tameness))
                        {
                            base.Pawn.training.Train(TrainableDefOf.Tameness, null);
                        }
                    }

                    if (base.Pawn.training.CanAssignToTrain(TrainableDefOf.Obedience).Accepted)
                    {
                        while (!base.Pawn.training.HasLearned(TrainableDefOf.Obedience))
                        {
                            base.Pawn.training.Train(TrainableDefOf.Obedience, null);
                        }
                    }

                    if (base.Pawn.training.CanAssignToTrain(TrainableDefOf.Release).Accepted)
                    {
                        while (!base.Pawn.training.HasLearned(TrainableDefOf.Release))
                        {
                            base.Pawn.training.Train(TrainableDefOf.Release, null);
                        }
                    }

                    if (base.Pawn.training.CanAssignToTrain(TorannMagicDefOf.Haul).Accepted)
                    {
                        while (!base.Pawn.training.HasLearned(TorannMagicDefOf.Haul))
                        {
                            base.Pawn.training.Train(TorannMagicDefOf.Haul, null);
                        }
                    }

                    if (base.Pawn.training.CanAssignToTrain(TorannMagicDefOf.Rescue).Accepted)
                    {
                        while (!base.Pawn.training.HasLearned(TorannMagicDefOf.Rescue))
                        {
                            base.Pawn.training.Train(TorannMagicDefOf.Rescue, null);
                        }
                    }
                }
            }
            bool flag4 = Find.TickManager.TicksGame % 600 == 0 && this.Pawn.def != TorannMagicDefOf.TM_SkeletonR && this.Pawn.def != TorannMagicDefOf.TM_GiantSkeletonR;

            if (flag4)
            {
                UpdateHediff();
                necroValid = false;
                if (base.Pawn != null && !linkedPawn.DestroyedOrNull())
                {
                    necroValid = true;
                    lichStrike = 0;
                }
                else
                {
                    lichStrike++;
                }

                if (!necroValid && lichStrike > 2)
                {
                    if (base.Pawn.Map != null)
                    {
                        TM_MoteMaker.ThrowScreamMote(base.Pawn.Position.ToVector3(), base.Pawn.Map, .8f, 255, 255, 255);
                        base.Pawn.Kill(null, null);
                    }
                    else
                    {
                        base.Pawn.Kill(null, null);
                    }
                }
                else
                {
                    List <Need> needs = base.Pawn.needs.AllNeeds;
                    for (int i = 0; i < needs.Count; i++)
                    {
                        if (needs[i].def == NeedDefOf.Food || needs[i].def == NeedDefOf.Joy || needs[i].def == NeedDefOf.Rest || needs[i].def.defName == "Mood" || needs[i].def.defName == "Beauty" ||
                            needs[i].def.defName == "Comfort" || needs[i].def.defName == "Outdoors" || needs[i].def.defName == "RoomSize")
                        {
                            needs[i].CurLevel = needs[i].MaxLevel;
                        }
                    }
                    //if (base.Pawn.needs.food != null)
                    //{
                    //    base.Pawn.needs.food.CurLevel = base.Pawn.needs.food.MaxLevel;
                    //}
                    //if (base.Pawn.needs.rest != null)
                    //{
                    //    base.Pawn.needs.rest.CurLevel = base.Pawn.needs.rest.MaxLevel;
                    //}

                    //if (base.Pawn.IsColonist)
                    //{
                    //    base.Pawn.needs.beauty.CurLevel = .5f;
                    //    base.Pawn.needs.comfort.CurLevel = .5f;
                    //    base.Pawn.needs.joy.CurLevel = .5f;
                    //    base.Pawn.needs.mood.CurLevel = .5f;
                    //    base.Pawn.needs.space.CurLevel = .5f;
                    //}
                    Pawn pawn = base.Pawn;
                    int  num  = 1;
                    int  num2 = 1;

                    using (IEnumerator <BodyPartRecord> enumerator = pawn.health.hediffSet.GetInjuredParts().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BodyPartRecord rec   = enumerator.Current;
                            bool           flag2 = num > 0;

                            if (flag2)
                            {
                                IEnumerable <Hediff_Injury> arg_BB_0 = pawn.health.hediffSet.GetHediffs <Hediff_Injury>();
                                Func <Hediff_Injury, bool>  arg_BB_1;

                                arg_BB_1 = ((Hediff_Injury injury) => injury.Part == rec);

                                foreach (Hediff_Injury current in arg_BB_0.Where(arg_BB_1))
                                {
                                    bool flag3 = num2 > 0;
                                    if (flag3)
                                    {
                                        bool flag5 = current.CanHealNaturally() && !current.IsPermanent();
                                        if (flag5)
                                        {
                                            current.Heal(2.0f);
                                            num--;
                                            num2--;
                                        }
                                        else
                                        {
                                            current.Heal(1.0f);
                                            num--;
                                            num2--;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffsTendable().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Hediff rec = enumerator.Current;
                            if (rec.TendableNow()) // && !currentTendable.IsPermanent()
                            {
                                rec.Tended(1, 1);
                            }
                        }
                    }

                    using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Hediff rec = enumerator.Current;
                            if (!rec.IsPermanent())
                            {
                                if (rec.def.defName == "Cataract" || rec.def.defName == "HearingLoss" || rec.def.defName.Contains("ToxicBuildup") || rec.def.defName == "Abasia" || rec.def.defName == "BloodRot")
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                                if ((rec.def.defName == "Blindness" || rec.def.defName.Contains("Asthma") || rec.def.defName == "Cirrhosis" || rec.def.defName == "ChemicalDamageModerate") || rec.def.defName == "Scaria")
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                                if ((rec.def.defName == "Frail" || rec.def.defName == "BadBack" || rec.def.defName.Contains("Carcinoma") || rec.def.defName == "ChemicalDamageSevere"))
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                                if ((rec.def.defName.Contains("Alzheimers") || rec.def.defName == "Dementia" || rec.def.defName.Contains("HeartArteryBlockage") || rec.def.defName == "CatatonicBreakdown"))
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                            }
                            if (rec.def.makesSickThought)
                            {
                                pawn.health.RemoveHediff(rec);
                            }
                        }
                    }
                }
            }
        }
 public override void OnIntervalPassed(Pawn pawn, Hediff cause)
 {
     HealthUtility.AdjustSeverity(pawn, hediff, 1f);
 }
        public override void Tick()
        {
            base.Tick();
            if(OwnerPawn != null && OwnerPawn.Position != this.InteractionCell)
            {
                OwnerPawn = null;
                count = 0;
                foundInj = null;
                oldCount = 0;
            }
            if (JobPawn != null)
            {
                if (OwnerPawn != null)
                {
                    string messageText1;
                    messageText1 = "Dermal Regenerator in use.";
                    Messages.Message(messageText1, MessageSound.Benefit);
                    JobPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    JobPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    JobPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    JobPawn = null;
                    return;
                }
                else
                {
                    if (this.UsableNow)
                    {
                        if (JobPawn.Position == this.InteractionCell)
                        {
                            OwnerPawn = JobPawn;
                            JobPawn = null;
                            return;
                        }
                    }
                    else if (OwnerPawn == null && !this.UsableNow)
                    {
                        string messageText2;
                        messageText2 = "Dermal Regenerator doesnt have power.";
                        Messages.Message(messageText2, MessageSound.Benefit);
                        JobPawn.jobs.jobQueue.Clear();
                        JobPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        JobPawn.jobs.EndCurrentJob(JobCondition.InterruptForced); 
                        JobPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        JobPawn = null;
                        return;
                    }
                }
            }
            if (OwnerPawn != null && !this.UsableNow)
            {
                string messageText3;
                messageText3 = "Dermal Regenerator power interupted.";
                Messages.Message(messageText3, MessageSound.Benefit);
                OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                OwnerPawn.health.AddHediff(HediffDef.Named("DermalRegeneratorSickness"), null, null);
                OwnerPawn = null;
                count = 0;
                foundInj = null;
                oldCount = 0;
                return;
            }
            if (OwnerPawn != null && OwnerPawn.Position == this.InteractionCell && this.UsableNow)
            {
                Find.GlowGrid.VisualGlowAt(Position);
                if (count < 9000)
                {
                    if (count % 90 == 0)
                    {
                        ThrowMicroSparksBlue(Position.ToVector3());
                    }
                    if (count % 200 == 0)
                    {
                        ThrowLightningGlowBlue(Position.ToVector3(), 1f);
                    }
                }
                else if (count > 9000)
                {
                    if (count % 90 == 0)
                    {
                        ThrowMicroSparksGreen(Position.ToVector3());
                    }
                    if (count % 200 == 0)
                    {
                        ThrowLightningGlowGreen(Position.ToVector3(), 1f);
                    }
                }

                count++;

                foreach (Hediff current in OwnerPawn.health.hediffSet.GetHediffs<Hediff>())
                {
                    if (current is Hediff_Injury && current.IsOld() && current.Label.Contains("scar"))
                    {
                        oldCount++;
                        foundInj = current;
                    }
                }

                if (count >= 18000)
                {
                    OwnerPawn.health.hediffSet.hediffs.Remove(foundInj);
                    OwnerPawn.health.Notify_HediffChanged(foundInj);
                    foundInj = null;
                    if (!OwnerPawn.health.ShouldBeTreatedNow)
                    {
                        string messageText4;
                        messageText4 = "Treatment complete.";
                        Messages.Message(messageText4, MessageSound.Benefit);
                        OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        OwnerPawn.health.AddHediff(HediffDef.Named("DermalRegeneratorSickness"), null, null);
                        count = 0;
                        foundInj = null;
                        oldCount = 0;
                        OwnerPawn = null;
                    }
                }

                if (count == 9000)
                {
                    if (foundInj == null)
                    {
                        string messageText5;
                        messageText5 = "No surface injuries discovered.";
                        Messages.Message(messageText5, MessageSound.Benefit);
                        OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        OwnerPawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                        OwnerPawn.health.AddHediff(HediffDef.Named("DermalRegeneratorSickness"), null, null);
                        OwnerPawn = null;
                        count = 0;
                        foundInj = null;
                        oldCount = 0;
                        return;
                    }
                }
            }
        }
Пример #31
0
        public override void Tick()
        {
            base.Tick();

            if (this.StoredEnergy > 0)
            {
                this.StoredEnergy -= 0.01f;
            }
            else
            {
                if (!this.Downed)
                {
                    Hediff hediff = HediffMaker.MakeHediff(ProfSchmilvsPokemon.DefOfs.HediffDefOf.OutOfPower, this);
                    this.health.AddHediff(hediff);
                }
            }

            if (closestCompPower == null && this.StoredEnergy >= this.storedEnergyMax * 0.21f && this.Faction != null)
            {
                if (this.repairJob == null)
                {
                    List <Thing> toRepair = base.Map.listerBuildingsRepairable.RepairableBuildings(this.Faction);

                    if (!toRepair.NullOrEmpty())
                    {
                        this.repairJob = toRepair[0];
                        this.jobs.ClearQueuedJobs();
                        this.pather.StartPath(new LocalTargetInfo(this.repairJob.Position), Verse.AI.PathEndMode.Touch);
                    }
                }
                else
                {
                    if (this.repairJob.MaxHitPoints == this.repairJob.HitPoints)
                    {
                        base.Map.listerBuildingsRepairable.Notify_BuildingRepaired((Building)this.repairJob);
                        this.repairJob = null;
                        this.jobs.ClearQueuedJobs();
                    }
                    else
                    {
                        if (this.Position.AdjacentTo8WayOrInside(this.repairJob.Position))
                        {
                            this.repairing();
                        }
                        else if (this.pather.Destination != new LocalTargetInfo(this.repairJob.Position))
                        {
                            this.pather.StartPath(new LocalTargetInfo(this.repairJob.Position), Verse.AI.PathEndMode.Touch);
                        }
                    }
                }
            }

            if (closestCompPower != null && this.StoredEnergy >= this.storedEnergyMax)
            {
                closestCompPower = null;
                this.jobs.ClearQueuedJobs();
            }

            if (this.Downed)
            {
                if (this.StoredEnergy < this.storedEnergyMax * 0.2f)
                {
                    List <CompPower> dummylist = Spawner.spawnerPokemon.PowerComps;

                    if (!dummylist.NullOrEmpty())
                    {
                        float distance = 999999f;

                        foreach (CompPower cp in dummylist)
                        {
                            float compareDistance = this.Position.DistanceTo(cp.parent.Position);

                            if (compareDistance < distance)
                            {
                                distance         = compareDistance;
                                closestCompPower = cp;
                            }
                        }
                    }
                }

                if (this.Position.AdjacentTo8WayOrInside(this.closestCompPower.parent.Position))
                {
                    PowerNet pn = this.closestCompPower.PowerNet;
                    if (pn != null)
                    {
                        float currentEnergy = pn.CurrentStoredEnergy();
                        if (currentEnergy >= 0.5f)
                        {
                            List <CompPowerBattery> cpb = pn.batteryComps;
                            CompPowerBattery        bat = null;
                            foreach (CompPowerBattery c in cpb)
                            {
                                if (c.StoredEnergy >= 0.5f)
                                {
                                    bat = c;
                                    break;
                                }
                            }
                            if (bat != null)
                            {
                                this.StoredEnergy += 0.5f;
                                bat.DrawPower(0.5f);
                            }
                        }
                    }
                }

                if (this.StoredEnergy > this.storedEnergyMax * 0.2f)
                {
                    List <Hediff> heds = this.health.hediffSet.hediffs;
                    if (!heds.NullOrEmpty())
                    {
                        Hediff oop = null;
                        foreach (Hediff h in heds)
                        {
                            if (h.def.Equals(ProfSchmilvsPokemon.DefOfs.HediffDefOf.OutOfPower))
                            {
                                oop = h;
                            }
                        }
                        if (oop != null)
                        {
                            this.health.RemoveHediff(oop);
                        }
                    }
                }
            }
            else
            {
                if (closestCompPower == null)
                {
                    if (this.StoredEnergy > 0 && this.StoredEnergy < this.storedEnergyMax * 0.2f)
                    {
                        List <CompPower> dummylist = Spawner.spawnerPokemon.PowerComps;

                        if (!dummylist.NullOrEmpty())
                        {
                            float distance = 999999f;

                            foreach (CompPower cp in dummylist)
                            {
                                float compareDistance = this.Position.DistanceTo(cp.parent.Position);

                                if (compareDistance < distance)
                                {
                                    distance         = compareDistance;
                                    closestCompPower = cp;
                                }
                            }

                            this.pather.StartPath(new LocalTargetInfo(this.closestCompPower.parent.Position), Verse.AI.PathEndMode.OnCell);
                        }
                    }
                }
                else
                {
                    if (this.Position.AdjacentTo8WayOrInside(this.closestCompPower.parent.Position))
                    {
                        PowerNet pn = this.closestCompPower.PowerNet;
                        if (pn != null)
                        {
                            float currentEnergy = pn.CurrentStoredEnergy();
                            if (currentEnergy >= 0.5f)
                            {
                                List <CompPowerBattery> cpb = pn.batteryComps;
                                CompPowerBattery        bat = null;
                                foreach (CompPowerBattery c in cpb)
                                {
                                    if (c.StoredEnergy >= 0.5f)
                                    {
                                        bat = c;
                                        break;
                                    }
                                }
                                if (bat != null)
                                {
                                    this.StoredEnergy += 0.5f;
                                    bat.DrawPower(0.5f);

                                    this.evolve();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (this.pather.Destination != new LocalTargetInfo(this.closestCompPower.parent.Position))
                        {
                            this.jobs.ClearQueuedJobs();
                            this.pather.StartPath(new LocalTargetInfo(this.closestCompPower.parent.Position), Verse.AI.PathEndMode.Touch);
                        }
                    }
                }
            }
        }