예제 #1
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());
        }