Пример #1
0
 public static float ByCurve(SimpleCurve curve, int sampleCount = 100)
 {
     if (curve.PointsCount < 3)
     {
         throw new ArgumentException("curve has < 3 points");
     }
     if (!(curve[0].y > 0.0) && !(curve[curve.PointsCount - 1].y > 0.0))
     {
         float x    = curve[0].x;
         float x2   = curve[curve.PointsCount - 1].x;
         float num  = (x2 - x) / (float)sampleCount;
         float num2 = 0f;
         for (int i = 0; i < sampleCount; i++)
         {
             float x3   = (float)(x + ((float)i + 0.5) * num);
             float num3 = curve.Evaluate(x3);
             num2 += num3;
         }
         float num4 = Rand.Range(0f, num2);
         num2 = 0f;
         for (int j = 0; j < sampleCount; j++)
         {
             float num5 = (float)(x + ((float)j + 0.5) * num);
             float num6 = curve.Evaluate(num5);
             num2 += num6;
             if (num2 > num4)
             {
                 return(num5 + Rand.Range((float)((0.0 - num) / 2.0), (float)(num / 2.0)));
             }
         }
         throw new Exception("Reached end of Rand.ByCurve without choosing a point.");
     }
     throw new ArgumentException("curve has start/end point with y > 0");
 }
        public override void OnIntervalPassed(Pawn pawn, Hediff cause)
        {
            float      ambientTemperature = pawn.AmbientTemperature;
            FloatRange floatRange         = pawn.ComfortableTemperatureRange();
            FloatRange floatRange2        = pawn.SafeTemperatureRange();
            Hediff     firstHediffOfDef   = pawn.health.hediffSet.GetFirstHediffOfDef(hediff);

            if (ambientTemperature > floatRange2.max)
            {
                float x = ambientTemperature - floatRange2.max;
                x = TemperatureOverageAdjustmentCurve.Evaluate(x);
                float a = x * 6.45E-05f;
                a = Mathf.Max(a, 0.000375f);
                HealthUtility.AdjustSeverity(pawn, hediff, a);
            }
            else if (firstHediffOfDef != null && ambientTemperature < floatRange.max)
            {
                float value = firstHediffOfDef.Severity * 0.027f;
                value = Mathf.Clamp(value, 0.0015f, 0.015f);
                firstHediffOfDef.Severity -= value;
            }
            if (pawn.Dead || !pawn.IsNestedHashIntervalTick(60, 420))
            {
                return;
            }
            float num = floatRange.max + 150f;

            if (!(ambientTemperature > num))
            {
                return;
            }
            float x2 = ambientTemperature - num;

            x2 = TemperatureOverageAdjustmentCurve.Evaluate(x2);
            int        num2  = Mathf.Max(GenMath.RoundRandom(x2 * 0.06f), 3);
            DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, num2);

            dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
            pawn.TakeDamage(dinfo);
            if (pawn.Faction == Faction.OfPlayer)
            {
                Find.TickManager.slower.SignalForceNormalSpeed();
                if (MessagesRepeatAvoider.MessageShowAllowed("PawnBeingBurned", 60f))
                {
                    Messages.Message("MessagePawnBeingBurned".Translate(pawn.LabelShort, pawn), pawn, MessageTypeDefOf.ThreatSmall);
                }
            }
            pawn.GetLord()?.ReceiveMemo(MemoPawnBurnedByAir);
        }
Пример #3
0
        private void CheckMakeInfection()
        {
            if (base.Pawn.health.immunity.DiseaseContractChanceFactor(HediffDefOf.WoundInfection, parent.Part) <= 0.001f)
            {
                ticksUntilInfect = -3;
                return;
            }
            float num = 1f;
            HediffComp_TendDuration hediffComp_TendDuration = parent.TryGetComp <HediffComp_TendDuration>();

            if (hediffComp_TendDuration != null && hediffComp_TendDuration.IsTended)
            {
                num *= infectionChanceFactorFromTendRoom;
                num *= InfectionChanceFactorFromTendQualityCurve.Evaluate(hediffComp_TendDuration.tendQuality);
            }
            num *= InfectionChanceFactorFromSeverityCurve.Evaluate(parent.Severity);
            if (base.Pawn.Faction == Faction.OfPlayer)
            {
                num *= Find.Storyteller.difficultyValues.playerPawnInfectionChanceFactor;
            }
            if (Rand.Value < num)
            {
                ticksUntilInfect = -4;
                base.Pawn.health.AddHediff(HediffDefOf.WoundInfection, parent.Part);
            }
            else
            {
                ticksUntilInfect = -3;
            }
        }
        public static void StunChances()
        {
            Func <ThingDef, float, bool, string> bluntBodyStunChance = delegate(ThingDef d, float dam, bool onHead)
            {
                SimpleCurve obj   = (onHead ? DamageDefOf.Blunt.bluntStunChancePerDamagePctOfCorePartToHeadCurve : DamageDefOf.Blunt.bluntStunChancePerDamagePctOfCorePartToBodyCurve);
                Pawn        pawn2 = PawnGenerator.GeneratePawn(new PawnGenerationRequest(d.race.AnyPawnKind, Find.FactionManager.FirstFactionOfDef(d.race.AnyPawnKind.defaultFactionType), PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true));
                float       x     = dam / d.race.body.corePart.def.GetMaxHealth(pawn2);
                Find.WorldPawns.PassToWorld(pawn2, PawnDiscardDecideMode.Discard);
                return(Mathf.Clamp01(obj.Evaluate(x)).ToStringPercent());
            };
            List <TableDataGetter <ThingDef> > list = new List <TableDataGetter <ThingDef> >();

            list.Add(new TableDataGetter <ThingDef>("defName", (ThingDef d) => d.defName));
            list.Add(new TableDataGetter <ThingDef>("body size", (ThingDef d) => d.race.baseBodySize.ToString("F2")));
            list.Add(new TableDataGetter <ThingDef>("health scale", (ThingDef d) => d.race.baseHealthScale.ToString("F2")));
            list.Add(new TableDataGetter <ThingDef>("body size\n* health scale", (ThingDef d) => (d.race.baseHealthScale * d.race.baseBodySize).ToString("F2")));
            list.Add(new TableDataGetter <ThingDef>("core part\nhealth", delegate(ThingDef d)
            {
                Pawn pawn       = PawnGenerator.GeneratePawn(new PawnGenerationRequest(d.race.AnyPawnKind, Find.FactionManager.FirstFactionOfDef(d.race.AnyPawnKind.defaultFactionType), PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true));
                float maxHealth = d.race.body.corePart.def.GetMaxHealth(pawn);
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                return(maxHealth);
            }));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n5", (ThingDef d) => bluntBodyStunChance(d, 5f, arg3: false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n10", (ThingDef d) => bluntBodyStunChance(d, 10f, arg3: false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n15", (ThingDef d) => bluntBodyStunChance(d, 15f, arg3: false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n20", (ThingDef d) => bluntBodyStunChance(d, 20f, arg3: false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n5", (ThingDef d) => bluntBodyStunChance(d, 5f, arg3: true)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n10", (ThingDef d) => bluntBodyStunChance(d, 10f, arg3: true)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n15", (ThingDef d) => bluntBodyStunChance(d, 15f, arg3: true)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n20", (ThingDef d) => bluntBodyStunChance(d, 20f, arg3: true)));
            DebugTables.MakeTablesDialog(DefDatabase <ThingDef> .AllDefs.Where((ThingDef d) => d.category == ThingCategory.Pawn), list.ToArray());
        }
Пример #5
0
        private static int FinalLevelOfSkill(Pawn pawn, SkillDef sk)
        {
            float num = (!sk.usuallyDefinedInBackstories) ? Rand.ByCurve(LevelRandomCurve) : ((float)Rand.RangeInclusive(0, 4));

            foreach (Backstory item in from bs in pawn.story.AllBackstories
                     where bs != null
                     select bs)
            {
                foreach (KeyValuePair <SkillDef, int> item2 in item.skillGainsResolved)
                {
                    if (item2.Key == sk)
                    {
                        num += (float)item2.Value * Rand.Range(1f, 1.4f);
                    }
                }
            }
            for (int i = 0; i < pawn.story.traits.allTraits.Count; i++)
            {
                int value = 0;
                if (pawn.story.traits.allTraits[i].CurrentData.skillGains.TryGetValue(sk, out value))
                {
                    num += (float)value;
                }
            }
            float num2 = Rand.Range(1f, AgeSkillMaxFactorCurve.Evaluate((float)pawn.ageTracker.AgeBiologicalYears));

            num *= num2;
            num  = LevelFinalAdjustmentCurve.Evaluate(num);
            return(Mathf.Clamp(Mathf.RoundToInt(num), 0, 20));
        }
Пример #6
0
 private void DoDestroyEffects(Map map)
 {
     if (def.building.destroyEffecter != null)
     {
         Effecter effecter = def.building.destroyEffecter.Spawn(base.Position, map);
         effecter.Trigger(new TargetInfo(base.Position, map), TargetInfo.Invalid);
         effecter.Cleanup();
     }
     else
     {
         if (!def.IsEdifice())
         {
             return;
         }
         GetDestroySound()?.PlayOneShot(new TargetInfo(base.Position, map));
         foreach (IntVec3 item in this.OccupiedRect())
         {
             int num = (def.building.isNaturalRock ? 1 : Rand.RangeInclusive(3, 5));
             for (int i = 0; i < num; i++)
             {
                 MoteMaker.ThrowDustPuffThick(item.ToVector3Shifted(), map, Rand.Range(1.5f, 2f), Color.white);
             }
         }
         if (Find.CurrentMap == map)
         {
             float num2 = def.building.destroyShakeAmount;
             if (num2 < 0f)
             {
                 num2 = ShakeAmountPerAreaCurve.Evaluate(def.Size.Area);
             }
             Find.CameraDriver.shaker.DoShake(num2);
         }
     }
 }
 public float EvaluateSetMax(Pawn pawn)
 {
     if (setMaxCurveOverride == null || setMaxCurveEvaluateStat == null)
     {
         return(setMax);
     }
     return(setMaxCurveOverride.Evaluate(pawn.GetStatValue(setMaxCurveEvaluateStat)));
 }
Пример #8
0
        public override void OnIntervalPassed(Pawn pawn, Hediff cause)
        {
            float x = (float)pawn.ageTracker.AgeBiologicalYears / pawn.RaceProps.lifeExpectancy;

            if (Rand.MTBEventOccurs(ageFractionMtbDaysCurve.Evaluate(x), 60000f, 60f) && (minPlayerPopulation <= 0 || pawn.Faction != Faction.OfPlayer || PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists_NoCryptosleep.Count() >= minPlayerPopulation) && TryApply(pawn))
            {
                SendLetter(pawn, cause);
            }
        }
        private static string <StunChances> m__1(ThingDef d, float dam, bool onHead)
        {
            SimpleCurve           simpleCurve = (!onHead) ? DamageDefOf.Blunt.bluntStunChancePerDamagePctOfCorePartToBodyCurve : DamageDefOf.Blunt.bluntStunChancePerDamagePctOfCorePartToHeadCurve;
            PawnGenerationRequest request     = new PawnGenerationRequest(d.race.AnyPawnKind, Find.FactionManager.FirstFactionOfDef(d.race.AnyPawnKind.defaultFactionType), PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
            Pawn  pawn = PawnGenerator.GeneratePawn(request);
            float x    = dam / d.race.body.corePart.def.GetMaxHealth(pawn);

            Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
            return(Mathf.Clamp01(simpleCurve.Evaluate(x)).ToStringPercent());
        }
Пример #10
0
        public float DebugChanceToHaveAtAge(Pawn pawn, int age)
        {
            float num = 1f;

            for (int i = 1; i <= age; i++)
            {
                float x = (float)i / pawn.RaceProps.lifeExpectancy;
                num *= 1f - ageFractionChanceCurve.Evaluate(x);
            }
            return(1f - num);
        }
        protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result)
        {
            bool       flag     = Rand.Chance(this.def.bluntInnerHitChance);
            float      num      = (!flag) ? 0f : this.def.bluntInnerHitDamageFractionToConvert.RandomInRange;
            float      num2     = totalDamage * (1f - num);
            DamageInfo lastInfo = dinfo;

            for (;;)
            {
                num2 -= base.FinalizeAndAddInjury(pawn, num2, lastInfo, result);
                if (!pawn.health.hediffSet.PartIsMissing(lastInfo.HitPart))
                {
                    break;
                }
                if (num2 <= 1f)
                {
                    break;
                }
                BodyPartRecord parent = lastInfo.HitPart.parent;
                if (parent == null)
                {
                    break;
                }
                lastInfo.SetHitPart(parent);
            }
            if (flag && !lastInfo.HitPart.def.IsSolid(lastInfo.HitPart, pawn.health.hediffSet.hediffs) && lastInfo.HitPart.depth == BodyPartDepth.Outside)
            {
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null)
                                                      where x.parent == lastInfo.HitPart && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside
                                                      select x;
                BodyPartRecord hitPart;
                if (source.TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out hitPart))
                {
                    DamageInfo lastInfo2 = lastInfo;
                    lastInfo2.SetHitPart(hitPart);
                    float totalDamage2 = totalDamage * num + totalDamage * this.def.bluntInnerHitDamageFractionToAdd.RandomInRange;
                    base.FinalizeAndAddInjury(pawn, totalDamage2, lastInfo2, result);
                }
            }
            if (!pawn.Dead)
            {
                SimpleCurve simpleCurve = null;
                if (lastInfo.HitPart.parent == null)
                {
                    simpleCurve = this.def.bluntStunChancePerDamagePctOfCorePartToBodyCurve;
                }
                else
                {
                    foreach (BodyPartRecord lhs in pawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource))
                    {
                        if (this.InSameBranch(lhs, lastInfo.HitPart))
                        {
                            simpleCurve = this.def.bluntStunChancePerDamagePctOfCorePartToHeadCurve;
                            break;
                        }
                    }
                }
                if (simpleCurve != null)
                {
                    float x2 = totalDamage / pawn.def.race.body.corePart.def.GetMaxHealth(pawn);
                    if (Rand.Chance(simpleCurve.Evaluate(x2)))
                    {
                        DamageInfo dinfo2 = dinfo;
                        dinfo2.Def = DamageDefOf.Stun;
                        dinfo2.SetAmount((float)3.5f.SecondsToTicks() / 30f);
                        pawn.TakeDamage(dinfo2);
                    }
                }
            }
        }
        private static void RoyalFavorAvailability()
        {
            StorytellerCompProperties_OnOffCycle storytellerCompProperties_OnOffCycle = (StorytellerCompProperties_OnOffCycle)StorytellerDefOf.Cassandra.comps.Find(delegate(StorytellerCompProperties x)
            {
                StorytellerCompProperties_OnOffCycle storytellerCompProperties_OnOffCycle2 = x as StorytellerCompProperties_OnOffCycle;
                if (storytellerCompProperties_OnOffCycle2 == null)
                {
                    return(false);
                }
                if (storytellerCompProperties_OnOffCycle2.IncidentCategory != IncidentCategoryDefOf.GiveQuest)
                {
                    return(false);
                }
                return((storytellerCompProperties_OnOffCycle2.enableIfAnyModActive != null && storytellerCompProperties_OnOffCycle2.enableIfAnyModActive.Any((string m) => m.ToLower() == ModContentPack.RoyaltyModPackageId)) ? true : false);
            });
            float       onDays      = storytellerCompProperties_OnOffCycle.onDays;
            float       average     = storytellerCompProperties_OnOffCycle.numIncidentsRange.Average;
            float       num         = average / onDays;
            SimpleCurve simpleCurve = new SimpleCurve
            {
                new CurvePoint(0f, 35f),
                new CurvePoint(15f, 150f),
                new CurvePoint(150f, 5000f)
            };
            int num2 = 0;
            List <RoyalTitleDef> royalTitlesAwardableInSeniorityOrderForReading = FactionDefOf.Empire.RoyalTitlesAwardableInSeniorityOrderForReading;

            for (int i = 0; i < royalTitlesAwardableInSeniorityOrderForReading.Count; i++)
            {
                num2 += royalTitlesAwardableInSeniorityOrderForReading[i].favorCost;
                if (royalTitlesAwardableInSeniorityOrderForReading[i] == RoyalTitleDefOf.Count)
                {
                    break;
                }
            }
            float      num3       = 0f;
            int        num4       = 0;
            int        num5       = 0;
            int        num6       = 0;
            int        num7       = 0;
            int        num8       = -1;
            int        num9       = -1;
            int        num10      = -1;
            int        ticksGame  = Find.TickManager.TicksGame;
            StoryState storyState = new StoryState(Find.World);

            for (int j = 0; j < 200; j++)
            {
                Find.TickManager.DebugSetTicksGame(j * 60000);
                num3 += num * storytellerCompProperties_OnOffCycle.acceptFractionByDaysPassedCurve.Evaluate(j);
                while (num3 >= 1f)
                {
                    num3 -= 1f;
                    num4++;
                    float points = simpleCurve.Evaluate(j);
                    Slate slate  = new Slate();
                    slate.Set("points", points);
                    QuestScriptDef questScriptDef = DefDatabase <QuestScriptDef> .AllDefsListForReading.Where((QuestScriptDef x) => x.IsRootRandomSelected && x.CanRun(slate)).RandomElementByWeight((QuestScriptDef x) => NaturalRandomQuestChooser.GetNaturalRandomSelectionWeight(x, points, storyState));

                    Quest quest = QuestGen.Generate(questScriptDef, slate);
                    if (quest.InvolvedFactions.Contains(Faction.Empire))
                    {
                        num7++;
                    }
                    QuestPart_GiveRoyalFavor questPart_GiveRoyalFavor = (QuestPart_GiveRoyalFavor)quest.PartsListForReading.Find((QuestPart x) => x is QuestPart_GiveRoyalFavor);
                    if (questPart_GiveRoyalFavor != null)
                    {
                        num5 += questPart_GiveRoyalFavor.amount;
                        num6++;
                        if (num5 >= num2 && num8 < 0)
                        {
                            num8 = j;
                        }
                        if (num9 < 0 || questPart_GiveRoyalFavor.amount < num9)
                        {
                            num9 = questPart_GiveRoyalFavor.amount;
                        }
                        if (num10 < 0 || questPart_GiveRoyalFavor.amount > num10)
                        {
                            num10 = questPart_GiveRoyalFavor.amount;
                        }
                    }
                    storyState.RecordRandomQuestFired(questScriptDef);
                    quest.CleanupQuestParts();
                }
            }
            Find.TickManager.DebugSetTicksGame(ticksGame);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Results for: Days=" + 200 + ", intervalDays=" + onDays + ", questsPerInterval=" + average + ":");
            stringBuilder.AppendLine("Quests: " + num4);
            stringBuilder.AppendLine("Quests with honor: " + num6);
            stringBuilder.AppendLine("Quests from Empire: " + num7);
            stringBuilder.AppendLine("Min honor reward: " + num9);
            stringBuilder.AppendLine("Max honor reward: " + num10);
            stringBuilder.AppendLine("Total honor: " + num5);
            stringBuilder.AppendLine("Honor required for Count: " + num2);
            stringBuilder.AppendLine("Count title possible on day: " + num8);
            Log.Message(stringBuilder.ToString());
        }
        protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageResult result)
        {
            bool       flag     = Rand.Chance(def.bluntInnerHitChance);
            float      num      = (flag ? def.bluntInnerHitDamageFractionToConvert.RandomInRange : 0f);
            float      num2     = totalDamage * (1f - num);
            DamageInfo lastInfo = dinfo;

            while (true)
            {
                num2 -= FinalizeAndAddInjury(pawn, num2, lastInfo, result);
                if (!pawn.health.hediffSet.PartIsMissing(lastInfo.HitPart) || num2 <= 1f)
                {
                    break;
                }
                BodyPartRecord parent = lastInfo.HitPart.parent;
                if (parent == null)
                {
                    break;
                }
                lastInfo.SetHitPart(parent);
            }
            if (flag && !lastInfo.HitPart.def.IsSolid(lastInfo.HitPart, pawn.health.hediffSet.hediffs) && lastInfo.HitPart.depth == BodyPartDepth.Outside && (from x in pawn.health.hediffSet.GetNotMissingParts()
                                                                                                                                                              where x.parent == lastInfo.HitPart && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside
                                                                                                                                                              select x).TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out var result2))
            {
                DamageInfo dinfo2 = lastInfo;
                dinfo2.SetHitPart(result2);
                float totalDamage2 = totalDamage * num + totalDamage * def.bluntInnerHitDamageFractionToAdd.RandomInRange;
                FinalizeAndAddInjury(pawn, totalDamage2, dinfo2, result);
            }
            if (pawn.Dead)
            {
                return;
            }
            SimpleCurve simpleCurve = null;

            if (lastInfo.HitPart.parent == null)
            {
                simpleCurve = def.bluntStunChancePerDamagePctOfCorePartToBodyCurve;
            }
            else
            {
                foreach (BodyPartRecord item in pawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource))
                {
                    if (InSameBranch(item, lastInfo.HitPart))
                    {
                        simpleCurve = def.bluntStunChancePerDamagePctOfCorePartToHeadCurve;
                        break;
                    }
                }
            }
            if (simpleCurve != null)
            {
                float x2 = totalDamage / pawn.def.race.body.corePart.def.GetMaxHealth(pawn);
                if (Rand.Chance(simpleCurve.Evaluate(x2)))
                {
                    DamageInfo dinfo3 = dinfo;
                    dinfo3.Def = DamageDefOf.Stun;
                    dinfo3.SetAmount((float)def.bluntStunDuration.SecondsToTicks() / 30f);
                    pawn.TakeDamage(dinfo3);
                }
            }
        }