コード例 #1
0
        private static void GiveRandomSurgeryInjuries(Pawn p, int totalDamage, BodyPartRecord operatedPart)
        {
            IEnumerable <BodyPartRecord> source = ((operatedPart != null) ? (from x in p.health.hediffSet.GetNotMissingParts()
                                                                             where !x.def.conceptual
                                                                             select x into pa
                                                                             where pa == operatedPart || pa.parent == operatedPart || (operatedPart != null && operatedPart.parent == pa)
                                                                             select pa) : (from x in p.health.hediffSet.GetNotMissingParts()
                                                                                           where !x.def.conceptual
                                                                                           select x));

            source = source.Where((BodyPartRecord x) => GetMinHealthOfPartsWeWantToAvoidDestroying(x, p) >= 2f);
            BodyPartRecord brain = p.health.hediffSet.GetBrain();

            if (brain != null)
            {
                float maxBrainHealth = brain.def.GetMaxHealth(p);
                source = source.Where((BodyPartRecord x) => x != brain || p.health.hediffSet.GetPartHealth(x) >= maxBrainHealth * 0.5f + 1f);
            }
            while (totalDamage > 0 && source.Any())
            {
                BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs);
                float          partHealth     = p.health.hediffSet.GetPartHealth(bodyPartRecord);
                int            num            = Mathf.Max(3, GenMath.RoundRandom(partHealth * Rand.Range(0.5f, 1f)));
                float          minHealthOfPartsWeWantToAvoidDestroying = GetMinHealthOfPartsWeWantToAvoidDestroying(bodyPartRecord, p);
                if (minHealthOfPartsWeWantToAvoidDestroying - (float)num < 1f)
                {
                    num = Mathf.RoundToInt(minHealthOfPartsWeWantToAvoidDestroying - 1f);
                }
                if (bodyPartRecord == brain && partHealth - (float)num < brain.def.GetMaxHealth(p) * 0.5f)
                {
                    num = Mathf.Max(Mathf.RoundToInt(partHealth - brain.def.GetMaxHealth(p) * 0.5f), 1);
                }
                if (num > 0)
                {
                    DamageDef  def   = Rand.Element(DamageDefOf.Cut, DamageDefOf.Scratch, DamageDefOf.Stab, DamageDefOf.Crush);
                    DamageInfo dinfo = new DamageInfo(def, num, 0f, -1f, null, bodyPartRecord);
                    dinfo.SetIgnoreArmor(ignoreArmor: true);
                    p.TakeDamage(dinfo);
                    totalDamage -= num;
                    continue;
                }
                break;
            }
        }
コード例 #2
0
        public virtual bool Allows(Thing t)
        {
            t = t.GetInnerIfMinified();
            bool result;

            if (!this.Allows(t.def))
            {
                result = false;
            }
            else
            {
                if (t.def.useHitPoints)
                {
                    float num = (float)t.HitPoints / (float)t.MaxHitPoints;
                    num = GenMath.RoundedHundredth(num);
                    if (!this.allowedHitPointsPercents.IncludesEpsilon(Mathf.Clamp01(num)))
                    {
                        return(false);
                    }
                }
                if (this.allowedQualities != QualityRange.All && t.def.FollowQualityThingFilter())
                {
                    QualityCategory p;
                    if (!t.TryGetQuality(out p))
                    {
                        p = QualityCategory.Normal;
                    }
                    if (!this.allowedQualities.Includes(p))
                    {
                        return(false);
                    }
                }
                for (int i = 0; i < this.disallowedSpecialFilters.Count; i++)
                {
                    if (this.disallowedSpecialFilters[i].Worker.Matches(t))
                    {
                        return(false);
                    }
                }
                result = true;
            }
            return(result);
        }
コード例 #3
0
 public static float FlatHill(float minY, float min, float lower, float upper, float max, float maxY, float x)
 {
     if (x < min)
     {
         return(minY);
     }
     if (x < lower)
     {
         return(GenMath.LerpDouble(min, lower, minY, 1f, x));
     }
     if (x < upper)
     {
         return(1f);
     }
     if (x < max)
     {
         return(GenMath.LerpDouble(upper, max, 1f, maxY, x));
     }
     return(maxY);
 }
コード例 #4
0
 public static Rot4 FromAngleFlat(float angle)
 {
     angle = GenMath.PositiveMod(angle, 360f);
     if (angle < 45f)
     {
         return(Rot4.North);
     }
     if (angle < 135f)
     {
         return(Rot4.East);
     }
     if (angle < 225f)
     {
         return(Rot4.South);
     }
     if (angle < 315f)
     {
         return(Rot4.West);
     }
     return(Rot4.North);
 }
コード例 #5
0
        private static object RoundToTicksRough(object[] args)
        {
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;
            int         num = Convert.ToInt32(args[0], invariantCulture);

            if (num <= 250)
            {
                return(250);
            }
            if (num < 5000)
            {
                return(GenMath.RoundTo(num, 250));
            }
            if (num < 60000)
            {
                return(GenMath.RoundTo(num, 2500));
            }
            if (num < 120000)
            {
                return(GenMath.RoundTo(num, 6000));
            }
            return(GenMath.RoundTo(num, 60000));
        }
コード例 #6
0
        private static void ApplyArmor(ref float damAmount, float armorRating, Thing armorThing, DamageDef damageDef)
        {
            float num;
            float num2;

            if ((double)armorRating <= 0.5)
            {
                num  = armorRating;
                num2 = 0f;
            }
            else if (armorRating < 1.0)
            {
                num  = 0.5f;
                num2 = (float)(armorRating - 0.5);
            }
            else
            {
                num  = (float)(0.5 + (armorRating - 1.0) * 0.25);
                num2 = (float)(0.5 + (armorRating - 1.0) * 0.25);
            }
            if (num > 0.89999997615814209)
            {
                num = 0.9f;
            }
            if (num2 > 0.89999997615814209)
            {
                num2 = 0.9f;
            }
            float num3 = (!(Rand.Value < num2)) ? (damAmount * num) : damAmount;

            if (armorThing != null)
            {
                float f = (float)(damAmount * 0.25);
                armorThing.TakeDamage(new DamageInfo(damageDef, GenMath.RoundRandom(f), -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
            }
            damAmount -= num3;
        }
コード例 #7
0
 public virtual bool Allows(Thing t)
 {
     if (!this.Allows(t.def))
     {
         return(false);
     }
     if (t.def.useHitPoints)
     {
         float f = (float)t.HitPoints / (float)t.MaxHitPoints;
         f = GenMath.RoundedHundredth(f);
         if (!this.allowedHitPointsPercents.IncludesEpsilon(Mathf.Clamp01(f)))
         {
             return(false);
         }
     }
     if (this.allowedQualities != QualityRange.All && t.def.FollowQualityThingFilter())
     {
         QualityCategory p = default(QualityCategory);
         if (!t.TryGetQuality(out p))
         {
             p = QualityCategory.Normal;
         }
         if (!this.allowedQualities.Includes(p))
         {
             return(false);
         }
     }
     for (int i = 0; i < this.disallowedSpecialFilters.Count; i++)
     {
         if (this.disallowedSpecialFilters[i].Worker.Matches(t))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #8
0
 public virtual bool Allows(Thing t)
 {
     t = t.GetInnerIfMinified();
     if (!Allows(t.def))
     {
         return(false);
     }
     if (t.def.useHitPoints)
     {
         float f = (float)t.HitPoints / (float)t.MaxHitPoints;
         f = GenMath.RoundedHundredth(f);
         if (!allowedHitPointsPercents.IncludesEpsilon(Mathf.Clamp01(f)))
         {
             return(false);
         }
     }
     if (allowedQualities != QualityRange.All && t.def.FollowQualityThingFilter())
     {
         if (!t.TryGetQuality(out QualityCategory qc))
         {
             qc = QualityCategory.Normal;
         }
         if (!allowedQualities.Includes(qc))
         {
             return(false);
         }
     }
     for (int i = 0; i < disallowedSpecialFilters.Count; i++)
     {
         if (disallowedSpecialFilters[i].Worker.Matches(t) && t.def.IsWithinCategory(disallowedSpecialFilters[i].parentCategory))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #9
0
        public static void TestMathPerf()
        {
            IntVec3       intVec        = new IntVec3(72, 0, 65);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Math perf tests (" + 1E+07f + " tests each)");
            float     num       = 0f;
            Stopwatch stopwatch = Stopwatch.StartNew();
            int       num2      = 0;

            while ((float)num2 < 1E+07f)
            {
                num += (float)Math.Sqrt(101.20999908447266);
                num2++;
            }
            stringBuilder.AppendLine(string.Concat(new object[]
            {
                "(float)System.Math.Sqrt(",
                101.21f,
                "): ",
                stopwatch.ElapsedTicks
            }));
            Stopwatch stopwatch2 = Stopwatch.StartNew();
            int       num3       = 0;

            while ((float)num3 < 1E+07f)
            {
                num += Mathf.Sqrt(101.21f);
                num3++;
            }
            stringBuilder.AppendLine(string.Concat(new object[]
            {
                "UnityEngine.Mathf.Sqrt(",
                101.21f,
                "): ",
                stopwatch2.ElapsedTicks
            }));
            Stopwatch stopwatch3 = Stopwatch.StartNew();
            int       num4       = 0;

            while ((float)num4 < 1E+07f)
            {
                num += GenMath.Sqrt(101.21f);
                num4++;
            }
            stringBuilder.AppendLine(string.Concat(new object[]
            {
                "Verse.GenMath.Sqrt(",
                101.21f,
                "): ",
                stopwatch3.ElapsedTicks
            }));
            Stopwatch stopwatch4 = Stopwatch.StartNew();
            int       num5       = 0;

            while ((float)num5 < 1E+07f)
            {
                num += (float)intVec.LengthManhattan;
                num5++;
            }
            stringBuilder.AppendLine("Verse.IntVec3.LengthManhattan: " + stopwatch4.ElapsedTicks);
            Stopwatch stopwatch5 = Stopwatch.StartNew();
            int       num6       = 0;

            while ((float)num6 < 1E+07f)
            {
                num += intVec.LengthHorizontal;
                num6++;
            }
            stringBuilder.AppendLine("Verse.IntVec3.LengthHorizontal: " + stopwatch5.ElapsedTicks);
            Stopwatch stopwatch6 = Stopwatch.StartNew();
            int       num7       = 0;

            while ((float)num7 < 1E+07f)
            {
                num += (float)intVec.LengthHorizontalSquared;
                num7++;
            }
            stringBuilder.AppendLine("Verse.IntVec3.LengthHorizontalSquared: " + stopwatch6.ElapsedTicks);
            stringBuilder.AppendLine("total: " + num);
            Log.Message(stringBuilder.ToString(), false);
        }
コード例 #10
0
        public static void AnimalsBasics()
        {
            DebugTables.MakeTablesDialog(DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef d) => d.race != null && d.RaceProps.Animal), new TableDataGetter <PawnKindDef>("defName", (PawnKindDef d) => d.defName), new TableDataGetter <PawnKindDef>("dps", (PawnKindDef d) => dps(d).ToString("F2")), new TableDataGetter <PawnKindDef>("healthScale", (PawnKindDef d) => d.RaceProps.baseHealthScale.ToString("F2")), new TableDataGetter <PawnKindDef>("points", (PawnKindDef d) => d.combatPower.ToString("F0")), new TableDataGetter <PawnKindDef>("points guess", (PawnKindDef d) => pointsGuess(d).ToString("F0")), new TableDataGetter <PawnKindDef>("speed", (PawnKindDef d) => d.race.GetStatValueAbstract(StatDefOf.MoveSpeed).ToString("F2")), new TableDataGetter <PawnKindDef>("mktval", (PawnKindDef d) => d.race.GetStatValueAbstract(StatDefOf.MarketValue).ToString("F0")), new TableDataGetter <PawnKindDef>("mktval guess", (PawnKindDef d) => mktValGuess(d).ToString("F0")), new TableDataGetter <PawnKindDef>("bodySize", (PawnKindDef d) => d.RaceProps.baseBodySize.ToString("F2")), new TableDataGetter <PawnKindDef>("hunger", (PawnKindDef d) => d.RaceProps.baseHungerRate.ToString("F2")), new TableDataGetter <PawnKindDef>("wildness", (PawnKindDef d) => d.RaceProps.wildness.ToStringPercent()), new TableDataGetter <PawnKindDef>("lifespan", (PawnKindDef d) => d.RaceProps.lifeExpectancy.ToString("F1")), new TableDataGetter <PawnKindDef>("trainability", (PawnKindDef d) => (d.RaceProps.trainability == null) ? "null" : d.RaceProps.trainability.label), new TableDataGetter <PawnKindDef>("tempMin", (PawnKindDef d) => d.race.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin).ToString("F0")), new TableDataGetter <PawnKindDef>("tempMax", (PawnKindDef d) => d.race.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax).ToString("F0")), new TableDataGetter <PawnKindDef>("flammability", (PawnKindDef d) => d.race.GetStatValueAbstract(StatDefOf.Flammability).ToStringPercent()));
            float dps(PawnKindDef d)
            {
                return(RaceMeleeDpsEstimate(d.race));
            }

            float mktValGuess(PawnKindDef d)
            {
                float num = 18f;

                num += pointsGuess(d) * 2.7f;
                if (d.RaceProps.trainability == TrainabilityDefOf.None)
                {
                    num *= 0.5f;
                }
                else if (d.RaceProps.trainability == TrainabilityDefOf.Simple)
                {
                    num *= 0.8f;
                }
                else if (d.RaceProps.trainability == TrainabilityDefOf.Intermediate)
                {
                    num += 0f;
                }
                else
                {
                    if (d.RaceProps.trainability != TrainabilityDefOf.Advanced)
                    {
                        throw new InvalidOperationException();
                    }
                    num += 250f;
                }
                num += d.RaceProps.baseBodySize * 80f;
                if (d.race.HasComp(typeof(CompMilkable)))
                {
                    num += 125f;
                }
                if (d.race.HasComp(typeof(CompShearable)))
                {
                    num += 90f;
                }
                if (d.race.HasComp(typeof(CompEggLayer)))
                {
                    num += 90f;
                }
                num *= Mathf.Lerp(0.8f, 1.2f, d.RaceProps.wildness);
                return(num * 0.75f);
            }

            float pointsGuess(PawnKindDef d)
            {
                return((15f + dps(d) * 10f) * Mathf.Lerp(1f, d.race.GetStatValueAbstract(StatDefOf.MoveSpeed) / 3f, 0.25f) * d.RaceProps.baseHealthScale * GenMath.LerpDouble(0.25f, 1f, 1.65f, 1f, Mathf.Clamp(d.RaceProps.baseBodySize, 0.25f, 1f)) * 0.76f);
            }
        }
コード例 #11
0
 public static float LerpDoubleClamped(float inFrom, float inTo, float outFrom, float outTo, float x)
 {
     return(GenMath.LerpDouble(inFrom, inTo, outFrom, outTo, Mathf.Clamp(x, Mathf.Min(inFrom, inTo), Mathf.Max(inFrom, inTo))));
 }
コード例 #12
0
 static float pointsGuess(PawnKindDef d)
 {
     return((15f + dps(d) * 10f) * Mathf.Lerp(1f, d.race.GetStatValueAbstract(StatDefOf.MoveSpeed) / 3f, 0.25f) * d.RaceProps.baseHealthScale * GenMath.LerpDouble(0.25f, 1f, 1.65f, 1f, Mathf.Clamp(d.RaceProps.baseBodySize, 0.25f, 1f)) * 0.76f);
 }
コード例 #13
0
        private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings)
        {
            RoofDef roofDef = map.roofGrid.RoofAt(c);

            if (roofDef == null)
            {
                return;
            }
            if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable)
            {
                for (int i = 0; i < 2; i++)
                {
                    List <Thing> thingList = c.GetThingList(map);
                    for (int j = thingList.Count - 1; j >= 0; j--)
                    {
                        Thing thing = thingList[j];
                        RoofCollapserImmediate.TryAddToCrushedThingsList(thing, outCrushedThings);
                        Pawn       pawn = thing as Pawn;
                        DamageInfo dinfo;
                        if (pawn != null)
                        {
                            DamageDef      crush            = DamageDefOf.Crush;
                            float          amount           = 99999f;
                            float          armorPenetration = 999f;
                            BodyPartRecord brain            = pawn.health.hediffSet.GetBrain();
                            dinfo = new DamageInfo(crush, amount, armorPenetration, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse, null);
                        }
                        else
                        {
                            dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null);
                            dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                        }
                        BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
                        if (i == 0 && pawn != null)
                        {
                            battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling, null);
                            Find.BattleLog.Add(battleLogEntry_DamageTaken);
                        }
                        thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken);
                        if (!thing.Destroyed && thing.def.destroyable)
                        {
                            thing.Kill(new DamageInfo?(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null)), null);
                        }
                    }
                }
            }
            else
            {
                List <Thing> thingList2 = c.GetThingList(map);
                for (int k = thingList2.Count - 1; k >= 0; k--)
                {
                    Thing thing2 = thingList2[k];
                    if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn)
                    {
                        RoofCollapserImmediate.TryAddToCrushedThingsList(thing2, outCrushedThings);
                        float num = (float)RoofCollapserImmediate.ThinRoofCrushDamageRange.RandomInRange;
                        if (thing2.def.building != null)
                        {
                            num *= thing2.def.building.roofCollapseDamageMultiplier;
                        }
                        BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null;
                        if (thing2 is Pawn)
                        {
                            battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling, null);
                            Find.BattleLog.Add(battleLogEntry_DamageTaken2);
                        }
                        DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, (float)GenMath.RoundRandom(num), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null);
                        dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                        thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2);
                    }
                }
            }
            if (roofDef.collapseLeavingThingDef != null)
            {
                Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map, WipeMode.Vanish);
                if (thing3.def.rotatable)
                {
                    thing3.Rotation = Rot4.Random;
                }
            }
            for (int l = 0; l < 1; l++)
            {
                Vector3 vector = c.ToVector3Shifted();
                vector += Gen.RandomHorizontalVector(0.6f);
                MoteMaker.ThrowDustPuff(vector, map, 2f);
            }
        }
コード例 #14
0
 public static T MaxByRandomIfEqual <T>(T elem1, float by1, T elem2, float by2, T elem3, float by3, T elem4, float by4, T elem5, float by5, T elem6, float by6, T elem7, float by7, T elem8, float by8, float eps = 0.0001f)
 {
     return(GenMath.MaxBy <T>(elem1, by1 + Rand.Range(0f, eps), elem2, by2 + Rand.Range(0f, eps), elem3, by3 + Rand.Range(0f, eps), elem4, by4 + Rand.Range(0f, eps), elem5, by5 + Rand.Range(0f, eps), elem6, by6 + Rand.Range(0f, eps), elem7, by7 + Rand.Range(0f, eps), elem8, by8 + Rand.Range(0f, eps)));
 }
コード例 #15
0
 public static T MinBy <T>(T elem1, float by1, T elem2, float by2, T elem3, float by3, T elem4, float by4, T elem5, float by5)
 {
     return(GenMath.MaxBy <T>(elem1, -by1, elem2, -by2, elem3, -by3, elem4, -by4, elem5, -by5));
 }
コード例 #16
0
 public override void Draw()
 {
     base.Draw((!this.front) ? this.def.altitudeLayer.AltitudeFor() : (this.def.altitudeLayer.AltitudeFor() + 0.1f * GenMath.InverseLerp(0f, this.treeHeight, this.currentSpatialPosition.y) * 2f));
 }
コード例 #17
0
        public void HealthTick()
        {
            if (this.Dead)
            {
                return;
            }
            for (int i = this.hediffSet.hediffs.Count - 1; i >= 0; i--)
            {
                Hediff hediff = this.hediffSet.hediffs[i];
                hediff.Tick();
                hediff.PostTick();
            }
            bool flag = false;

            for (int j = this.hediffSet.hediffs.Count - 1; j >= 0; j--)
            {
                Hediff hediff2 = this.hediffSet.hediffs[j];
                if (hediff2.ShouldRemove)
                {
                    this.hediffSet.hediffs.RemoveAt(j);
                    hediff2.PostRemoved();
                    flag = true;
                }
            }
            if (flag)
            {
                this.Notify_HediffChanged(null);
            }
            if (this.Dead)
            {
                return;
            }
            this.immunity.ImmunityHandlerTick();
            if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
            {
                bool flag2 = false;
                if (this.hediffSet.HasNaturallyHealingInjury())
                {
                    float num = 8f;
                    if (this.pawn.GetPosture() != PawnPosture.Standing)
                    {
                        num += 4f;
                        Building_Bed building_Bed = this.pawn.CurrentBed();
                        if (building_Bed != null)
                        {
                            num += building_Bed.def.building.bed_healPerDay;
                        }
                    }
                    Hediff_Injury hediff_Injury = this.hediffSet.GetHediffs <Hediff_Injury>().Where(new Func <Hediff_Injury, bool>(HediffUtility.CanHealNaturally)).RandomElement <Hediff_Injury>();
                    hediff_Injury.Heal(num * this.pawn.HealthScale * 0.01f);
                    flag2 = true;
                }
                if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                {
                    Hediff_Injury hediff_Injury2 = this.hediffSet.GetHediffs <Hediff_Injury>().Where(new Func <Hediff_Injury, bool>(HediffUtility.CanHealFromTending)).RandomElement <Hediff_Injury>();
                    float         tendQuality    = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                    float         num2           = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                    hediff_Injury2.Heal(22f * num2 * this.pawn.HealthScale * 0.01f);
                    flag2 = true;
                }
                if (flag2 && !this.HasHediffsNeedingTendByColony(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                {
                    Messages.Message("MessageFullyHealed".Translate(new object[]
                    {
                        this.pawn.LabelCap
                    }), this.pawn, MessageTypeDefOf.PositiveEvent);
                }
            }
            if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.1f)
            {
                float num3 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                if (this.pawn.GetPosture() == PawnPosture.Standing)
                {
                    num3 *= 0.008f;
                }
                else
                {
                    num3 *= 0.0008f;
                }
                if (Rand.Value < num3)
                {
                    this.TryDropBloodFilth();
                }
            }
            List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;

            if (hediffGiverSets != null && this.pawn.IsHashIntervalTick(60))
            {
                for (int k = 0; k < hediffGiverSets.Count; k++)
                {
                    List <HediffGiver> hediffGivers = hediffGiverSets[k].hediffGivers;
                    for (int l = 0; l < hediffGivers.Count; l++)
                    {
                        hediffGivers[l].OnIntervalPassed(this.pawn, null);
                        if (this.pawn.Dead)
                        {
                            return;
                        }
                    }
                }
            }
        }
コード例 #18
0
ファイル: DebugAutotests.cs プロジェクト: KraigXu/GameProject
        private static void TestTimeToDown()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef kindDef in DefDatabase <PawnKindDef> .AllDefs.OrderBy((PawnKindDef kd) => kd.defName))
            {
                list.Add(new DebugMenuOption(kindDef.label, DebugMenuOptionMode.Action, delegate
                {
                    if (kindDef == PawnKindDefOf.Colonist)
                    {
                        Log.Message("Current colonist TTD reference point: 22.3 seconds, stddev 8.35 seconds");
                    }
                    List <float> results     = new List <float>();
                    List <PawnKindDef> list2 = new List <PawnKindDef>();
                    List <PawnKindDef> list3 = new List <PawnKindDef>();
                    list2.Add(kindDef);
                    list3.Add(kindDef);
                    ArenaUtility.BeginArenaFightSet(1000, list2, list3, delegate(ArenaUtility.ArenaResult result)
                    {
                        if (result.winner != 0)
                        {
                            results.Add(result.tickDuration.TicksToSeconds());
                        }
                    }, delegate
                    {
                        Log.Message($"Finished {results.Count} tests; time-to-down {results.Average()}, stddev {GenMath.Stddev(results)}\n\nraw: {results.Select((float res) => res.ToString()).ToLineList()}");
                    });
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
コード例 #19
0
ファイル: Pawn_HealthTracker.cs プロジェクト: potsh/RimWorld
 public void HealthTick()
 {
     if (!Dead)
     {
         for (int num = hediffSet.hediffs.Count - 1; num >= 0; num--)
         {
             Hediff hediff = hediffSet.hediffs[num];
             try
             {
                 hediff.Tick();
                 hediff.PostTick();
             }
             catch (Exception ex)
             {
                 Log.Error("Exception ticking hediff " + hediff.ToStringSafe() + " for pawn " + pawn.ToStringSafe() + ". Removing hediff... Exception: " + ex);
                 try
                 {
                     RemoveHediff(hediff);
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error while removing hediff: " + arg);
                 }
             }
         }
         bool flag = false;
         for (int num2 = hediffSet.hediffs.Count - 1; num2 >= 0; num2--)
         {
             Hediff hediff2 = hediffSet.hediffs[num2];
             if (hediff2.ShouldRemove)
             {
                 hediffSet.hediffs.RemoveAt(num2);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             Notify_HediffChanged(null);
         }
         if (!Dead)
         {
             immunity.ImmunityHandlerTick();
             if (pawn.RaceProps.IsFlesh && pawn.IsHashIntervalTick(600) && (pawn.needs.food == null || !pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (hediffSet.HasNaturallyHealingInjury())
                 {
                     float num3 = 8f;
                     if (pawn.GetPosture() != 0)
                     {
                         num3 += 4f;
                         Building_Bed building_Bed = pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num3 += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealNaturally).RandomElement();
                     hediff_Injury.Heal(num3 * pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (hediffSet.HasTendedAndHealingInjury() && (pawn.needs.food == null || !pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealFromTending).RandomElement();
                     float         tendQuality    = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float         num4           = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal(8f * num4 * pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (flag2 && !HasHediffsNeedingTendByPlayer() && !HealthAIUtility.ShouldSeekMedicalRest(pawn) && !hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(pawn.LabelCap, pawn), pawn, MessageTypeDefOf.PositiveEvent);
                 }
             }
             if (pawn.RaceProps.IsFlesh && hediffSet.BleedRateTotal >= 0.1f)
             {
                 float num5 = hediffSet.BleedRateTotal * pawn.BodySize;
                 num5 = ((pawn.GetPosture() != 0) ? (num5 * 0.0004f) : (num5 * 0.004f));
                 if (Rand.Value < num5)
                 {
                     DropBloodFilth();
                 }
             }
             if (pawn.IsHashIntervalTick(60))
             {
                 List <HediffGiverSetDef> hediffGiverSets = pawn.RaceProps.hediffGiverSets;
                 if (hediffGiverSets != null)
                 {
                     for (int i = 0; i < hediffGiverSets.Count; i++)
                     {
                         List <HediffGiver> hediffGivers = hediffGiverSets[i].hediffGivers;
                         for (int j = 0; j < hediffGivers.Count; j++)
                         {
                             hediffGivers[j].OnIntervalPassed(pawn, null);
                             if (pawn.Dead)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 if (pawn.story != null)
                 {
                     List <Trait> allTraits = pawn.story.traits.allTraits;
                     for (int k = 0; k < allTraits.Count; k++)
                     {
                         TraitDegreeData currentData = allTraits[k].CurrentData;
                         if (currentData.randomDiseaseMtbDays > 0f && Rand.MTBEventOccurs(currentData.randomDiseaseMtbDays, 60000f, 60f))
                         {
                             BiomeDef biome;
                             if (pawn.Tile != -1)
                             {
                                 biome = Find.WorldGrid[pawn.Tile].biome;
                             }
                             else
                             {
                                 biome = DefDatabase <BiomeDef> .GetRandom();
                             }
                             IncidentDef incidentDef = (from d in DefDatabase <IncidentDef> .AllDefs
                                                        where d.category == IncidentCategoryDefOf.DiseaseHuman
                                                        select d).RandomElementByWeightWithFallback((IncidentDef d) => biome.CommonalityOfDisease(d));
                             if (incidentDef != null)
                             {
                                 string      blockedInfo;
                                 List <Pawn> list = ((IncidentWorker_Disease)incidentDef.Worker).ApplyToPawns(Gen.YieldSingle(pawn), out blockedInfo);
                                 if (PawnUtility.ShouldSendNotificationAbout(pawn))
                                 {
                                     if (list.Contains(pawn))
                                     {
                                         Find.LetterStack.ReceiveLetter("LetterLabelTraitDisease".Translate(incidentDef.diseaseIncident.label), "LetterTraitDisease".Translate(pawn.LabelCap, incidentDef.diseaseIncident.label, pawn.Named("PAWN")).AdjustedFor(pawn), LetterDefOf.NegativeEvent, pawn);
                                     }
                                     else if (!blockedInfo.NullOrEmpty())
                                     {
                                         Messages.Message(blockedInfo, pawn, MessageTypeDefOf.NeutralEvent);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #20
0
ファイル: GenExplosion.cs プロジェクト: KraigXu/GameProject
        private static void CalculateNeededLOSToCells(IntVec3 position, Map map, float direction, out IntVec3?needLOSToCell1, out IntVec3?needLOSToCell2)
        {
            needLOSToCell1 = null;
            needLOSToCell2 = null;
            if (position.CanBeSeenOverFast(map))
            {
                return;
            }
            direction = GenMath.PositiveMod(direction, 360f);
            IntVec3 intVec = position;

            intVec.z++;
            IntVec3 intVec2 = position;

            intVec2.z--;
            IntVec3 intVec3 = position;

            intVec3.x--;
            IntVec3 intVec4 = position;

            intVec4.x++;
            if (direction < 90f)
            {
                if (intVec3.InBounds(map) && intVec3.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec3;
                }
                if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec;
                }
            }
            else if (direction < 180f)
            {
                if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec;
                }
                if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec4;
                }
            }
            else if (direction < 270f)
            {
                if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec4;
                }
                if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec2;
                }
            }
            else
            {
                if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map))
                {
                    needLOSToCell1 = intVec2;
                }
                if (intVec3.InBounds(map) && intVec3.CanBeSeenOverFast(map))
                {
                    needLOSToCell2 = intVec3;
                }
            }
        }
コード例 #21
0
 public static Vector3 BezierCubicEvaluate(float t, GenMath.BezierCubicControls bcc)
 {
     return(GenMath.BezierCubicEvaluate(t, bcc.w0, bcc.w1, bcc.w2, bcc.w3));
 }
コード例 #22
0
 public void HealthTick()
 {
     if (!this.Dead)
     {
         for (int num = this.hediffSet.hediffs.Count - 1; num >= 0; num--)
         {
             Hediff hediff = this.hediffSet.hediffs[num];
             hediff.Tick();
             hediff.PostTick();
         }
         bool flag = false;
         for (int num2 = this.hediffSet.hediffs.Count - 1; num2 >= 0; num2--)
         {
             Hediff hediff2 = this.hediffSet.hediffs[num2];
             if (hediff2.ShouldRemove)
             {
                 this.hediffSet.hediffs.RemoveAt(num2);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             this.Notify_HediffChanged(null);
         }
         if (!this.Dead)
         {
             this.immunity.ImmunityHandlerTick();
             if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (this.hediffSet.HasNaturallyHealingInjury())
                 {
                     float num3 = 8f;
                     if (this.pawn.GetPosture() != 0)
                     {
                         num3 = (float)(num3 + 4.0);
                         Building_Bed building_Bed = this.pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num3 += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = this.hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealNaturally).RandomElement();
                     hediff_Injury.Heal((float)(num3 * this.pawn.HealthScale * 0.0099999997764825821));
                     flag2 = true;
                 }
                 if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = this.hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealFromTending).RandomElement();
                     float         tendQuality    = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float         num4           = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal((float)(22.0 * num4 * this.pawn.HealthScale * 0.0099999997764825821));
                     flag2 = true;
                 }
                 if (flag2 && !this.HasHediffsNeedingTendByColony(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(this.pawn.LabelCap), this.pawn, MessageTypeDefOf.PositiveEvent);
                 }
             }
             if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.10000000149011612)
             {
                 float num5 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                 num5 = (float)((this.pawn.GetPosture() != 0) ? (num5 * 0.00079999997979030013) : (num5 * 0.00800000037997961));
                 if (Rand.Value < num5)
                 {
                     this.TryDropBloodFilth();
                 }
             }
             List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;
             if (hediffGiverSets != null && this.pawn.IsHashIntervalTick(60))
             {
                 for (int i = 0; i < hediffGiverSets.Count; i++)
                 {
                     List <HediffGiver> hediffGivers = hediffGiverSets[i].hediffGivers;
                     int num6 = 0;
                     while (num6 < hediffGivers.Count)
                     {
                         hediffGivers[num6].OnIntervalPassed(this.pawn, null);
                         if (!this.pawn.Dead)
                         {
                             num6++;
                             continue;
                         }
                         return;
                     }
                 }
             }
         }
     }
 }
コード例 #23
0
 public static T MinBy <T>(T elem1, float by1, T elem2, float by2, T elem3, float by3)
 {
     return(GenMath.MaxBy <T>(elem1, -by1, elem2, -by2, elem3, -by3));
 }
コード例 #24
0
        private static object RoundRandom(object[] args)
        {
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            return((double)GenMath.RoundRandom(Convert.ToSingle(args[0], invariantCulture)));
        }
コード例 #25
0
 public static T MinBy <T>(T elem1, float by1, T elem2, float by2, T elem3, float by3, T elem4, float by4, T elem5, float by5, T elem6, float by6, T elem7, float by7, T elem8, float by8)
 {
     return(GenMath.MaxBy <T>(elem1, -by1, elem2, -by2, elem3, -by3, elem4, -by4, elem5, -by5, elem6, -by6, elem7, -by7, elem8, -by8));
 }
コード例 #26
0
 private static Material MatFromColorPct(float colorPct, bool transparent)
 {
     return(DebugMatsSpectrum.Mat(GenMath.PositiveMod(Mathf.RoundToInt(colorPct * 100f), 100), transparent));
 }
コード例 #27
0
        private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings)
        {
            RoofDef roofDef = map.roofGrid.RoofAt(c);

            if (roofDef == null)
            {
                return;
            }
            if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable)
            {
                for (int i = 0; i < 2; i++)
                {
                    List <Thing> thingList = c.GetThingList(map);
                    for (int num = thingList.Count - 1; num >= 0; num--)
                    {
                        Thing thing = thingList[num];
                        TryAddToCrushedThingsList(thing, outCrushedThings);
                        Pawn       pawn = thing as Pawn;
                        DamageInfo dinfo;
                        if (pawn != null)
                        {
                            dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, pawn.health.hediffSet.GetBrain(), null, DamageInfo.SourceCategory.Collapse);
                        }
                        else
                        {
                            dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                            dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                        }
                        BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
                        if (i == 0 && pawn != null)
                        {
                            battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling);
                            Find.BattleLog.Add(battleLogEntry_DamageTaken);
                        }
                        thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken);
                        if (!thing.Destroyed && thing.def.destroyable)
                        {
                            thing.Kill(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse));
                        }
                    }
                }
            }
            else
            {
                List <Thing> thingList2 = c.GetThingList(map);
                for (int num2 = thingList2.Count - 1; num2 >= 0; num2--)
                {
                    Thing thing2 = thingList2[num2];
                    if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn)
                    {
                        TryAddToCrushedThingsList(thing2, outCrushedThings);
                        float num3 = ThinRoofCrushDamageRange.RandomInRange;
                        if (thing2.def.building != null)
                        {
                            num3 *= thing2.def.building.roofCollapseDamageMultiplier;
                        }
                        BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null;
                        if (thing2 is Pawn)
                        {
                            battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling);
                            Find.BattleLog.Add(battleLogEntry_DamageTaken2);
                        }
                        DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, GenMath.RoundRandom(num3), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                        dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                        thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2);
                    }
                }
            }
            if (roofDef.collapseLeavingThingDef != null)
            {
                Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map);
                if (thing3.def.rotatable)
                {
                    thing3.Rotation = Rot4.Random;
                }
            }
            for (int j = 0; j < 1; j++)
            {
                MoteMaker.ThrowDustPuff(c.ToVector3Shifted() + Gen.RandomHorizontalVector(0.6f), map, 2f);
            }
        }
コード例 #28
0
        public static void PerformBattleRoyale(IEnumerable <PawnKindDef> kindsEnumerable)
        {
            if (!ArenaUtility.ValidateArenaCapability())
            {
                return;
            }
            List <PawnKindDef> kinds = kindsEnumerable.ToList <PawnKindDef>();
            Dictionary <PawnKindDef, float> ratings = new Dictionary <PawnKindDef, float>();

            foreach (PawnKindDef pawnKindDef in kinds)
            {
                ratings[pawnKindDef] = EloUtility.CalculateRating(pawnKindDef.combatPower, 1500f, 60f);
            }
            int currentFights  = 0;
            int completeFights = 0;

            Current.Game.GetComponent <GameComponent_DebugTools>().AddPerFrameCallback(delegate
            {
                if (currentFights >= 15)
                {
                    return(false);
                }
                PawnKindDef lhsDef = kinds.RandomElement <PawnKindDef>();
                PawnKindDef rhsDef = kinds.RandomElement <PawnKindDef>();
                float num          = EloUtility.CalculateExpectation(ratings[lhsDef], ratings[rhsDef]);
                float num2         = 1f - num;
                float num3         = num;
                float num4         = Mathf.Min(num2, num3);
                num2      /= num4;
                num3      /= num4;
                float num5 = Mathf.Max(num2, num3);
                if (num5 > 40f)
                {
                    return(false);
                }
                float num6             = 40f / num5;
                float num7             = (float)Math.Exp((double)Rand.Range(0f, (float)Math.Log((double)num6)));
                num2                  *= num7;
                num3                  *= num7;
                List <PawnKindDef> lhs = Enumerable.Repeat <PawnKindDef>(lhsDef, GenMath.RoundRandom(num2)).ToList <PawnKindDef>();
                List <PawnKindDef> rhs = Enumerable.Repeat <PawnKindDef>(rhsDef, GenMath.RoundRandom(num3)).ToList <PawnKindDef>();
                currentFights++;
                ArenaUtility.BeginArenaFight(lhs, rhs, delegate(ArenaUtility.ArenaResult result)
                {
                    currentFights--;
                    completeFights++;
                    if (result.winner != ArenaUtility.ArenaResult.Winner.Other)
                    {
                        float value   = ratings[lhsDef];
                        float value2  = ratings[rhsDef];
                        float kfactor = 8f * Mathf.Pow(0.5f, Time.realtimeSinceStartup / 900f);
                        EloUtility.Update(ref value, ref value2, 0.5f, (float)((result.winner != ArenaUtility.ArenaResult.Winner.Lhs) ? 0 : 1), kfactor);
                        ratings[lhsDef] = value;
                        ratings[rhsDef] = value2;
                        Log.Message(string.Format("Scores after {0} trials:\n\n{1}", completeFights, (from v in ratings
                                                                                                      orderby v.Value
                                                                                                      select string.Format("  {0}: {1}->{2} (rating {2})", new object[]
                        {
                            v.Key.label,
                            v.Key.combatPower,
                            EloUtility.CalculateLinearScore(v.Value, 1500f, 60f).ToString("F0"),
                            v.Value.ToString("F0")
                        })).ToLineList(null)), false);
                    }
                });
                return(false);
            });
        }
コード例 #29
0
 public void HealthTick()
 {
     if (!this.Dead)
     {
         for (int i = this.hediffSet.hediffs.Count - 1; i >= 0; i--)
         {
             Hediff hediff = this.hediffSet.hediffs[i];
             try
             {
                 hediff.Tick();
                 hediff.PostTick();
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Exception ticking hediff ",
                     hediff.ToStringSafe <Hediff>(),
                     " for pawn ",
                     this.pawn.ToStringSafe <Pawn>(),
                     ". Removing hediff... Exception: ",
                     ex
                 }), false);
                 try
                 {
                     this.RemoveHediff(hediff);
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error while removing hediff: " + arg, false);
                 }
             }
         }
         bool flag = false;
         for (int j = this.hediffSet.hediffs.Count - 1; j >= 0; j--)
         {
             Hediff hediff2 = this.hediffSet.hediffs[j];
             if (hediff2.ShouldRemove)
             {
                 this.hediffSet.hediffs.RemoveAt(j);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             this.Notify_HediffChanged(null);
         }
         if (!this.Dead)
         {
             this.immunity.ImmunityHandlerTick();
             if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (this.hediffSet.HasNaturallyHealingInjury())
                 {
                     float num = 8f;
                     if (this.pawn.GetPosture() != PawnPosture.Standing)
                     {
                         num += 4f;
                         Building_Bed building_Bed = this.pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                    where x.CanHealNaturally()
                                                    select x).RandomElement <Hediff_Injury>();
                     hediff_Injury.Heal(num * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                     where x.CanHealFromTending()
                                                     select x).RandomElement <Hediff_Injury>();
                     float tendQuality = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float num2        = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal(22f * num2 * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (flag2 && !this.HasHediffsNeedingTendByPlayer(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(new object[]
                     {
                         this.pawn.LabelCap
                     }), this.pawn, MessageTypeDefOf.PositiveEvent, true);
                 }
             }
             if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.1f)
             {
                 float num3 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                 if (this.pawn.GetPosture() == PawnPosture.Standing)
                 {
                     num3 *= 0.004f;
                 }
                 else
                 {
                     num3 *= 0.0004f;
                 }
                 if (Rand.Value < num3)
                 {
                     this.DropBloodFilth();
                 }
             }
             if (this.pawn.IsHashIntervalTick(60))
             {
                 List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;
                 if (hediffGiverSets != null)
                 {
                     for (int k = 0; k < hediffGiverSets.Count; k++)
                     {
                         List <HediffGiver> hediffGivers = hediffGiverSets[k].hediffGivers;
                         for (int l = 0; l < hediffGivers.Count; l++)
                         {
                             hediffGivers[l].OnIntervalPassed(this.pawn, null);
                             if (this.pawn.Dead)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 if (this.pawn.story != null)
                 {
                     List <Trait> allTraits = this.pawn.story.traits.allTraits;
                     for (int m = 0; m < allTraits.Count; m++)
                     {
                         TraitDegreeData currentData = allTraits[m].CurrentData;
                         if (currentData.randomDiseaseMtbDays > 0f && Rand.MTBEventOccurs(currentData.randomDiseaseMtbDays, 60000f, 60f))
                         {
                             BiomeDef biome;
                             if (this.pawn.Tile != -1)
                             {
                                 biome = Find.WorldGrid[this.pawn.Tile].biome;
                             }
                             else
                             {
                                 biome = DefDatabase <BiomeDef> .GetRandom();
                             }
                             IncidentDef incidentDef = (from d in DefDatabase <IncidentDef> .AllDefs
                                                        where d.category == IncidentCategoryDefOf.DiseaseHuman
                                                        select d).RandomElementByWeightWithFallback((IncidentDef d) => biome.CommonalityOfDisease(d), null);
                             if (incidentDef != null)
                             {
                                 ((IncidentWorker_Disease)incidentDef.Worker).ApplyToPawns(Gen.YieldSingle <Pawn>(this.pawn));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #30
0
        private static void DropRoofInCellPhaseOne(IntVec3 c, Map map)
        {
            RoofDef roofDef = map.roofGrid.RoofAt(c);

            if (roofDef != null)
            {
                if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        List <Thing> thingList = c.GetThingList(map);
                        for (int num = thingList.Count - 1; num >= 0; num--)
                        {
                            Thing thing = thingList[num];
                            map.roofCollapseBuffer.Notify_Crushed(thing);
                            Pawn       pawn  = thing as Pawn;
                            DamageInfo dinfo = default(DamageInfo);
                            if (pawn != null)
                            {
                                DamageDef      crush  = DamageDefOf.Crush;
                                int            amount = 99999;
                                BodyPartRecord brain  = pawn.health.hediffSet.GetBrain();
                                dinfo = new DamageInfo(crush, amount, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse);
                            }
                            else
                            {
                                dinfo = new DamageInfo(DamageDefOf.Crush, 99999, -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                                dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
                            if (i == 0 && pawn != null)
                            {
                                battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling, null);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken);
                            }
                            thing.TakeDamage(dinfo).InsertIntoLog(battleLogEntry_DamageTaken);
                            if (!thing.Destroyed && thing.def.destroyable)
                            {
                                thing.Destroy(DestroyMode.Vanish);
                            }
                        }
                    }
                }
                else
                {
                    List <Thing> thingList2 = c.GetThingList(map);
                    for (int num2 = thingList2.Count - 1; num2 >= 0; num2--)
                    {
                        Thing thing2 = thingList2[num2];
                        if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn)
                        {
                            map.roofCollapseBuffer.Notify_Crushed(thing2);
                            float num3 = (float)RoofCollapserImmediate.ThinRoofCrushDamageRange.RandomInRange;
                            if (thing2.def.building != null)
                            {
                                num3 *= thing2.def.building.roofCollapseDamageMultiplier;
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null;
                            if (thing2 is Pawn)
                            {
                                battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken(thing2 as Pawn, RulePackDefOf.DamageEvent_Ceiling, null);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken2);
                            }
                            DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, GenMath.RoundRandom(num3), -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                            dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            thing2.TakeDamage(dinfo2).InsertIntoLog(battleLogEntry_DamageTaken2);
                        }
                    }
                }
                if (roofDef.collapseLeavingThingDef != null)
                {
                    Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map);
                    if (thing3.def.rotatable)
                    {
                        thing3.Rotation = Rot4.Random;
                    }
                }
                for (int j = 0; j < 1; j++)
                {
                    Vector3 a = c.ToVector3Shifted();
                    a += Gen.RandomHorizontalVector(0.6f);
                    MoteMaker.ThrowDustPuff(a, map, 2f);
                }
            }
        }