private static IEnumerable <Thing> RelevantGear(Pawn pawn, StatDef stat)
        {
            if (pawn.apparel != null)
            {
                foreach (Apparel item in pawn.apparel.WornApparel)
                {
                    if (StatWorker.GearAffectsStat(item.def, stat))
                    {
                        yield return((Thing)item);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
            }
            if (pawn.equipment != null)
            {
                foreach (ThingWithComps item2 in pawn.equipment.AllEquipmentListForReading)
                {
                    if (StatWorker.GearAffectsStat(item2.def, stat))
                    {
                        yield return((Thing)item2);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
            }
            yield break;
IL_01a0:
            /*Error near IL_01a1: Unexpected return in MoveNext()*/;
        }
        private string InfoTextLineFrom(Thing gear)
        {
            float statValue = gear.GetStatValue(apparelStat);

            statValue += StatWorker.StatOffsetFromGear(gear, apparelStat);
            if (subtract)
            {
                statValue = 0f - statValue;
            }
            return("    " + gear.LabelCap + ": " + statValue.ToStringByStyle(parentStat.toStringStyle, ToStringNumberSense.Offset));
        }
        public override void TransformValue(StatRequest req, ref float val)
        {
            if (!req.HasThing || req.Thing == null)
            {
                return;
            }
            Pawn pawn = req.Thing as Pawn;

            if (pawn == null)
            {
                return;
            }
            if (pawn.apparel != null)
            {
                for (int i = 0; i < pawn.apparel.WornApparel.Count; i++)
                {
                    float statValue = pawn.apparel.WornApparel[i].GetStatValue(apparelStat);
                    statValue += StatWorker.StatOffsetFromGear(pawn.apparel.WornApparel[i], apparelStat);
                    if (subtract)
                    {
                        val -= statValue;
                    }
                    else
                    {
                        val += statValue;
                    }
                }
            }
            if (includeWeapon && pawn.equipment != null && pawn.equipment.Primary != null)
            {
                float statValue2 = pawn.equipment.Primary.GetStatValue(apparelStat);
                statValue2 += StatWorker.StatOffsetFromGear(pawn.equipment.Primary, apparelStat);
                if (subtract)
                {
                    val -= statValue2;
                }
                else
                {
                    val += statValue2;
                }
            }
        }
示例#4
0
 private static IEnumerable <Thing> RelevantGear(Pawn pawn, StatDef stat)
 {
     if (pawn.apparel != null)
     {
         foreach (Apparel t in pawn.apparel.WornApparel)
         {
             if (StatWorker.GearAffectsStat(t.def, stat))
             {
                 yield return(t);
             }
         }
     }
     if (pawn.equipment != null)
     {
         foreach (ThingWithComps t2 in pawn.equipment.AllEquipmentListForReading)
         {
             if (StatWorker.GearAffectsStat(t2.def, stat))
             {
                 yield return(t2);
             }
         }
     }
 }
 private bool PawnWearingRelevantGear(Pawn pawn)
 {
     if (pawn.apparel != null)
     {
         for (int i = 0; i < pawn.apparel.WornApparel.Count; i++)
         {
             Apparel apparel = pawn.apparel.WornApparel[i];
             if (apparel.GetStatValue(apparelStat) != 0f)
             {
                 return(true);
             }
             if (StatWorker.StatOffsetFromGear(apparel, apparelStat) != 0f)
             {
                 return(true);
             }
         }
     }
     if (includeWeapon && pawn.equipment != null && pawn.equipment.Primary != null && StatWorker.StatOffsetFromGear(pawn.equipment.Primary, apparelStat) != 0f)
     {
         return(true);
     }
     return(false);
 }
示例#6
0
        private static string InfoTextLineFromGear(Thing gear, StatDef stat)
        {
            float f = StatWorker.StatOffsetFromGear(gear, stat);

            return("    " + gear.LabelCap + ": " + f.ToStringByStyle(stat.toStringStyle, ToStringNumberSense.Offset));
        }
示例#7
0
        public virtual float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true)
        {
            if (Prefs.DevMode && this.IsDisabledFor(req.Thing))
            {
                Log.ErrorOnce(string.Format("Attempted to calculate value for disabled stat {0}; this is meant as a consistency check, either set the stat to neverDisabled or ensure this pawn cannot accidentally use this stat (thing={1})", this.stat, req.Thing.ToStringSafe <Thing>()), 75193282 + (int)this.stat.index, false);
            }
            float num  = this.GetBaseValueFor(req.Def);
            Pawn  pawn = req.Thing as Pawn;

            if (pawn != null)
            {
                if (pawn.skills != null)
                {
                    if (this.stat.skillNeedOffsets != null)
                    {
                        for (int i = 0; i < this.stat.skillNeedOffsets.Count; i++)
                        {
                            num += this.stat.skillNeedOffsets[i].ValueFor(pawn);
                        }
                    }
                }
                else
                {
                    num += this.stat.noSkillOffset;
                }
                if (this.stat.capacityOffsets != null)
                {
                    for (int j = 0; j < this.stat.capacityOffsets.Count; j++)
                    {
                        PawnCapacityOffset pawnCapacityOffset = this.stat.capacityOffsets[j];
                        num += pawnCapacityOffset.GetOffset(pawn.health.capacities.GetLevel(pawnCapacityOffset.capacity));
                    }
                }
                if (pawn.story != null)
                {
                    for (int k = 0; k < pawn.story.traits.allTraits.Count; k++)
                    {
                        num += pawn.story.traits.allTraits[k].OffsetOfStat(this.stat);
                    }
                }
                List <Hediff> hediffs = pawn.health.hediffSet.hediffs;
                for (int l = 0; l < hediffs.Count; l++)
                {
                    HediffStage curStage = hediffs[l].CurStage;
                    if (curStage != null)
                    {
                        num += curStage.statOffsets.GetStatOffsetFromList(this.stat);
                    }
                }
                if (pawn.apparel != null)
                {
                    for (int m = 0; m < pawn.apparel.WornApparel.Count; m++)
                    {
                        num += StatWorker.StatOffsetFromGear(pawn.apparel.WornApparel[m], this.stat);
                    }
                }
                if (pawn.equipment != null && pawn.equipment.Primary != null)
                {
                    num += StatWorker.StatOffsetFromGear(pawn.equipment.Primary, this.stat);
                }
                if (pawn.story != null)
                {
                    for (int n = 0; n < pawn.story.traits.allTraits.Count; n++)
                    {
                        num *= pawn.story.traits.allTraits[n].MultiplierOfStat(this.stat);
                    }
                }
                num *= pawn.ageTracker.CurLifeStage.statFactors.GetStatFactorFromList(this.stat);
            }
            if (req.StuffDef != null)
            {
                if (num > 0f || this.stat.applyFactorsIfNegative)
                {
                    num *= req.StuffDef.stuffProps.statFactors.GetStatFactorFromList(this.stat);
                }
                num += req.StuffDef.stuffProps.statOffsets.GetStatOffsetFromList(this.stat);
            }
            if (req.HasThing)
            {
                CompAffectedByFacilities compAffectedByFacilities = req.Thing.TryGetComp <CompAffectedByFacilities>();
                if (compAffectedByFacilities != null)
                {
                    num += compAffectedByFacilities.GetStatOffset(this.stat);
                }
                if (this.stat.statFactors != null)
                {
                    for (int num2 = 0; num2 < this.stat.statFactors.Count; num2++)
                    {
                        num *= req.Thing.GetStatValue(this.stat.statFactors[num2], true);
                    }
                }
                if (pawn != null)
                {
                    if (pawn.skills != null)
                    {
                        if (this.stat.skillNeedFactors != null)
                        {
                            for (int num3 = 0; num3 < this.stat.skillNeedFactors.Count; num3++)
                            {
                                num *= this.stat.skillNeedFactors[num3].ValueFor(pawn);
                            }
                        }
                    }
                    else
                    {
                        num *= this.stat.noSkillFactor;
                    }
                    if (this.stat.capacityFactors != null)
                    {
                        for (int num4 = 0; num4 < this.stat.capacityFactors.Count; num4++)
                        {
                            PawnCapacityFactor pawnCapacityFactor = this.stat.capacityFactors[num4];
                            float factor = pawnCapacityFactor.GetFactor(pawn.health.capacities.GetLevel(pawnCapacityFactor.capacity));
                            num = Mathf.Lerp(num, num * factor, pawnCapacityFactor.weight);
                        }
                    }
                    if (pawn.Inspired)
                    {
                        num += pawn.InspirationDef.statOffsets.GetStatOffsetFromList(this.stat);
                        num *= pawn.InspirationDef.statFactors.GetStatFactorFromList(this.stat);
                    }
                }
            }
            return(num);
        }
示例#8
0
        public virtual string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense)
        {
            StringBuilder stringBuilder = new StringBuilder();
            float         baseValueFor  = this.GetBaseValueFor(req.Def);

            if (baseValueFor != 0f)
            {
                stringBuilder.AppendLine("StatsReport_BaseValue".Translate() + ": " + this.stat.ValueToString(baseValueFor, numberSense));
                stringBuilder.AppendLine();
            }
            Pawn pawn = req.Thing as Pawn;

            if (pawn != null)
            {
                if (pawn.skills != null)
                {
                    if (this.stat.skillNeedOffsets != null)
                    {
                        stringBuilder.AppendLine("StatsReport_Skills".Translate());
                        for (int i = 0; i < this.stat.skillNeedOffsets.Count; i++)
                        {
                            SkillNeed skillNeed = this.stat.skillNeedOffsets[i];
                            int       level     = pawn.skills.GetSkill(skillNeed.skill).Level;
                            float     val       = skillNeed.ValueFor(pawn);
                            stringBuilder.AppendLine(string.Concat(new object[]
                            {
                                "    ",
                                skillNeed.skill.LabelCap,
                                " (",
                                level,
                                "): ",
                                val.ToStringSign(),
                                this.ValueToString(val, false, ToStringNumberSense.Absolute)
                            }));
                        }
                        stringBuilder.AppendLine();
                    }
                }
                else if (this.stat.noSkillOffset != 0f)
                {
                    stringBuilder.AppendLine("StatsReport_Skills".Translate());
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        "    ",
                        "default".Translate().CapitalizeFirst(),
                        " : ",
                        this.stat.noSkillOffset.ToStringSign(),
                        this.ValueToString(this.stat.noSkillOffset, false, ToStringNumberSense.Absolute)
                    }));
                    stringBuilder.AppendLine();
                }
                if (this.stat.capacityOffsets != null)
                {
                    stringBuilder.AppendLine((!"StatsReport_Health".CanTranslate()) ? "StatsReport_HealthFactors".Translate() : "StatsReport_Health".Translate());
                    foreach (PawnCapacityOffset current in from hfa in this.stat.capacityOffsets
                             orderby hfa.capacity.listOrder
                             select hfa)
                    {
                        string text   = current.capacity.GetLabelFor(pawn).CapitalizeFirst();
                        float  level2 = pawn.health.capacities.GetLevel(current.capacity);
                        float  offset = current.GetOffset(pawn.health.capacities.GetLevel(current.capacity));
                        string text2  = this.ValueToString(offset, false, ToStringNumberSense.Absolute);
                        string text3  = Mathf.Min(level2, current.max).ToStringPercent() + ", " + "HealthOffsetScale".Translate(new object[]
                        {
                            current.scale.ToString() + "x"
                        });
                        if (current.max < 999f)
                        {
                            text3 = text3 + ", " + "HealthFactorMaxImpact".Translate(new object[]
                            {
                                current.max.ToStringPercent()
                            });
                        }
                        stringBuilder.AppendLine(string.Concat(new string[]
                        {
                            "    ",
                            text,
                            ": ",
                            offset.ToStringSign(),
                            text2,
                            " (",
                            text3,
                            ")"
                        }));
                    }
                    stringBuilder.AppendLine();
                }
                if (pawn.RaceProps.intelligence >= Intelligence.ToolUser)
                {
                    if (pawn.story != null && pawn.story.traits != null)
                    {
                        List <Trait> list = (from tr in pawn.story.traits.allTraits
                                             where tr.CurrentData.statOffsets != null && tr.CurrentData.statOffsets.Any((StatModifier se) => se.stat == this.stat)
                                             select tr).ToList <Trait>();
                        List <Trait> list2 = (from tr in pawn.story.traits.allTraits
                                              where tr.CurrentData.statFactors != null && tr.CurrentData.statFactors.Any((StatModifier se) => se.stat == this.stat)
                                              select tr).ToList <Trait>();
                        if (list.Count > 0 || list2.Count > 0)
                        {
                            stringBuilder.AppendLine("StatsReport_RelevantTraits".Translate());
                            for (int j = 0; j < list.Count; j++)
                            {
                                Trait  trait = list[j];
                                string valueToStringAsOffset = trait.CurrentData.statOffsets.First((StatModifier se) => se.stat == this.stat).ValueToStringAsOffset;
                                stringBuilder.AppendLine("    " + trait.LabelCap + ": " + valueToStringAsOffset);
                            }
                            for (int k = 0; k < list2.Count; k++)
                            {
                                Trait  trait2           = list2[k];
                                string toStringAsFactor = trait2.CurrentData.statFactors.First((StatModifier se) => se.stat == this.stat).ToStringAsFactor;
                                stringBuilder.AppendLine("    " + trait2.LabelCap + ": " + toStringAsFactor);
                            }
                            stringBuilder.AppendLine();
                        }
                    }
                    if (StatWorker.RelevantGear(pawn, this.stat).Any <Thing>())
                    {
                        stringBuilder.AppendLine("StatsReport_RelevantGear".Translate());
                        if (pawn.apparel != null)
                        {
                            for (int l = 0; l < pawn.apparel.WornApparel.Count; l++)
                            {
                                Apparel gear = pawn.apparel.WornApparel[l];
                                stringBuilder.AppendLine(StatWorker.InfoTextLineFromGear(gear, this.stat));
                            }
                        }
                        if (pawn.equipment != null && pawn.equipment.Primary != null)
                        {
                            stringBuilder.AppendLine(StatWorker.InfoTextLineFromGear(pawn.equipment.Primary, this.stat));
                        }
                        stringBuilder.AppendLine();
                    }
                }
                bool          flag    = false;
                List <Hediff> hediffs = pawn.health.hediffSet.hediffs;
                for (int m = 0; m < hediffs.Count; m++)
                {
                    HediffStage curStage = hediffs[m].CurStage;
                    if (curStage != null)
                    {
                        float statOffsetFromList = curStage.statOffsets.GetStatOffsetFromList(this.stat);
                        if (statOffsetFromList != 0f)
                        {
                            if (!flag)
                            {
                                stringBuilder.AppendLine("StatsReport_RelevantHediffs".Translate());
                                flag = true;
                            }
                            stringBuilder.AppendLine("    " + hediffs[m].LabelBase.CapitalizeFirst() + ": " + this.ValueToString(statOffsetFromList, false, ToStringNumberSense.Offset));
                            stringBuilder.AppendLine();
                        }
                    }
                }
                float statFactorFromList = pawn.ageTracker.CurLifeStage.statFactors.GetStatFactorFromList(this.stat);
                if (statFactorFromList != 1f)
                {
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        "StatsReport_LifeStage".Translate(),
                        " (",
                        pawn.ageTracker.CurLifeStage.label,
                        "): ",
                        statFactorFromList.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor)
                    }));
                    stringBuilder.AppendLine();
                }
            }
            if (req.StuffDef != null)
            {
                if (baseValueFor > 0f || this.stat.applyFactorsIfNegative)
                {
                    float statFactorFromList2 = req.StuffDef.stuffProps.statFactors.GetStatFactorFromList(this.stat);
                    if (statFactorFromList2 != 1f)
                    {
                        stringBuilder.AppendLine(string.Concat(new string[]
                        {
                            "StatsReport_Material".Translate(),
                            " (",
                            req.StuffDef.LabelCap,
                            "): ",
                            statFactorFromList2.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor)
                        }));
                        stringBuilder.AppendLine();
                    }
                }
                float statOffsetFromList2 = req.StuffDef.stuffProps.statOffsets.GetStatOffsetFromList(this.stat);
                if (statOffsetFromList2 != 0f)
                {
                    stringBuilder.AppendLine(string.Concat(new string[]
                    {
                        "StatsReport_Material".Translate(),
                        " (",
                        req.StuffDef.LabelCap,
                        "): ",
                        statOffsetFromList2.ToStringByStyle(this.stat.toStringStyle, ToStringNumberSense.Offset)
                    }));
                    stringBuilder.AppendLine();
                }
            }
            CompAffectedByFacilities compAffectedByFacilities = req.Thing.TryGetComp <CompAffectedByFacilities>();

            if (compAffectedByFacilities != null)
            {
                compAffectedByFacilities.GetStatsExplanation(this.stat, stringBuilder);
            }
            if (this.stat.statFactors != null)
            {
                stringBuilder.AppendLine("StatsReport_OtherStats".Translate());
                for (int n = 0; n < this.stat.statFactors.Count; n++)
                {
                    StatDef statDef = this.stat.statFactors[n];
                    stringBuilder.AppendLine("    " + statDef.LabelCap + ": x" + statDef.Worker.GetValue(req, true).ToStringPercent());
                }
                stringBuilder.AppendLine();
            }
            if (pawn != null)
            {
                if (pawn.skills != null)
                {
                    if (this.stat.skillNeedFactors != null)
                    {
                        stringBuilder.AppendLine("StatsReport_Skills".Translate());
                        for (int num = 0; num < this.stat.skillNeedFactors.Count; num++)
                        {
                            SkillNeed skillNeed2 = this.stat.skillNeedFactors[num];
                            int       level3     = pawn.skills.GetSkill(skillNeed2.skill).Level;
                            stringBuilder.AppendLine(string.Concat(new object[]
                            {
                                "    ",
                                skillNeed2.skill.LabelCap,
                                " (",
                                level3,
                                "): x",
                                skillNeed2.ValueFor(pawn).ToStringPercent()
                            }));
                        }
                        stringBuilder.AppendLine();
                    }
                }
                else if (this.stat.noSkillFactor != 1f)
                {
                    stringBuilder.AppendLine("StatsReport_Skills".Translate());
                    stringBuilder.AppendLine("    " + "default".Translate().CapitalizeFirst() + " : x" + this.stat.noSkillFactor.ToStringPercent());
                    stringBuilder.AppendLine();
                }
                if (this.stat.capacityFactors != null)
                {
                    stringBuilder.AppendLine((!"StatsReport_Health".CanTranslate()) ? "StatsReport_HealthFactors".Translate() : "StatsReport_Health".Translate());
                    if (this.stat.capacityFactors != null)
                    {
                        foreach (PawnCapacityFactor current2 in from hfa in this.stat.capacityFactors
                                 orderby hfa.capacity.listOrder
                                 select hfa)
                        {
                            string text4  = current2.capacity.GetLabelFor(pawn).CapitalizeFirst();
                            float  factor = current2.GetFactor(pawn.health.capacities.GetLevel(current2.capacity));
                            string text5  = factor.ToStringPercent();
                            string text6  = "HealthFactorPercentImpact".Translate(new object[]
                            {
                                current2.weight.ToStringPercent()
                            });
                            if (current2.max < 999f)
                            {
                                text6 = text6 + ", " + "HealthFactorMaxImpact".Translate(new object[]
                                {
                                    current2.max.ToStringPercent()
                                });
                            }
                            if (current2.allowedDefect != 0f)
                            {
                                text6 = text6 + ", " + "HealthFactorAllowedDefect".Translate(new object[]
                                {
                                    (1f - current2.allowedDefect).ToStringPercent()
                                });
                            }
                            stringBuilder.AppendLine(string.Concat(new string[]
                            {
                                "    ",
                                text4,
                                ": x",
                                text5,
                                " (",
                                text6,
                                ")"
                            }));
                        }
                    }
                    stringBuilder.AppendLine();
                }
                if (pawn.Inspired)
                {
                    float statOffsetFromList3 = pawn.InspirationDef.statOffsets.GetStatOffsetFromList(this.stat);
                    if (statOffsetFromList3 != 0f)
                    {
                        stringBuilder.AppendLine("StatsReport_Inspiration".Translate(new object[]
                        {
                            pawn.Inspiration.def.LabelCap
                        }) + ": " + this.ValueToString(statOffsetFromList3, false, ToStringNumberSense.Offset));
                        stringBuilder.AppendLine();
                    }
                    float statFactorFromList3 = pawn.InspirationDef.statFactors.GetStatFactorFromList(this.stat);
                    if (statFactorFromList3 != 1f)
                    {
                        stringBuilder.AppendLine("StatsReport_Inspiration".Translate(new object[]
                        {
                            pawn.Inspiration.def.LabelCap
                        }) + ": " + statFactorFromList3.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor));
                        stringBuilder.AppendLine();
                    }
                }
            }
            return(stringBuilder.ToString().TrimEndNewlines());
        }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    if (pawn.apparel == null)
                    {
                        goto IL_E5;
                    }
                    enumerator = pawn.apparel.WornApparel.GetEnumerator();
                    num        = 4294967293u;
                    break;

                case 1u:
                    break;

                case 2u:
Block_5:
                    try
                    {
                        switch (num)
                        {
                        case 2u:
IL_175:
                            break;
                        }
                        if (enumerator2.MoveNext())
                        {
                            t2 = enumerator2.Current;
                            if (StatWorker.GearAffectsStat(t2.def, stat))
                            {
                                this.$current = t2;
                                if (!this.$disposing)
                                {
                                    this.$PC = 2;
                                }
                                flag = true;
                                return(true);
                            }
                            goto IL_175;
                        }
                    }
                    finally
                    {
                        if (!flag)
                        {
                            ((IDisposable)enumerator2).Dispose();
                        }
                    }
                    goto IL_1A2;

                default:
                    return(false);
                }
                try
                {
                    switch (num)
                    {
                    case 1u:
IL_B8:
                        break;
                    }
                    if (enumerator.MoveNext())
                    {
                        t = enumerator.Current;
                        if (StatWorker.GearAffectsStat(t.def, stat))
                        {
                            this.$current = t;
                            if (!this.$disposing)
                            {
                                this.$PC = 1;
                            }
                            flag = true;
                            return(true);
                        }
                        goto IL_B8;
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        ((IDisposable)enumerator).Dispose();
                    }
                }
IL_E5:
                if (pawn.equipment != null)
                {
                    enumerator2 = pawn.equipment.AllEquipmentListForReading.GetEnumerator();
                    num         = 4294967293u;
                    goto Block_5;
                }
IL_1A2:
                this.$PC = -1;
                return(false);
            }