示例#1
0
        public virtual IEnumerable <string> ConfigErrors(LootAffixDef parentDef, LootAffixModifier modifier)
        {
            // min/max sanity checks
            if (setValue == null && addValue == 0 && multiplier == 1 && preMinValue == -9999999f && minValue == -9999999f && maxValue == 9999999f)
            {
                yield return("This modifier doesn't actually change anything");
            }

            if (setValue != null && (addValue != 0 && multiplier != 1 && preMinValue != -9999999f && minValue != -9999999f && maxValue != 9999999f))
            {
                yield return("The setValue option is mutually exclusive to all other value modifier options");
            }

            if (multiplier == 0)
            {
                yield return("A multiplier=0 is better displayed as setValue=0");
            }

            if (preMinValue != -9999999f)
            {
                if (preMinValue > maxValue)
                {
                    yield return(string.Format("The preMinValue is higher than the maxValue: {0} > {1}", preMinValue, maxValue));
                }
            }
            if (minValue != -9999999f)
            {
                if (minValue > maxValue)
                {
                    yield return(string.Format("The minValue is higher than the maxValue: {0} > {1}", minValue, maxValue));
                }
            }
        }
示例#2
0
 public void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, string preLabel, ThingWithComps parentThing, LootAffixModifier parentModifier, bool curValue)
 {
     SpecialDisplayStatsInjectors(
         statDrawEntry:  statDrawEntry,
         preLabel:       preLabel,
         parentThing:    parentThing,
         parentModifier: parentModifier,
         finalString:    GetModifierChangeString(curValue)
         );
 }
示例#3
0
        // Install our own affix stat data
        public void SpecialDisplayStatsInjectors(StatDrawEntry statDrawEntry, string preLabel, ThingWithComps parentThing, LootAffixModifier parentModifier, string finalString, string baseString = null)
        {
            if (statDrawEntry.LabelCap == GetModifierChangeStat())
            {
                // [Reflection] string reportText = statDrawEntry.overrideReportText
                string    reportText;
                FieldInfo reportTextField = AccessTools.Field(typeof(StatDrawEntry), "overrideReportText");
                reportText = (string)reportTextField.GetValue(statDrawEntry);

                int finalValuePos = reportText.IndexOf("StatsReport_FinalValue".Translate() + ": ");

                string affixValueStr = "RimLoot_AffixStatExplanationPart".Translate(preLabel) + ": " + parentModifier.ModifierChangeString + "\n";

                // Already has a stats report
                if (finalValuePos >= 0)
                {
                    reportText = reportText.Substring(0, finalValuePos) + affixValueStr + reportText.Substring(finalValuePos);
                }
                // No stats report; make our own
                else
                {
                    reportText += "\n\n";
                    if (baseString != null)
                    {
                        string baseValueStr  = "StatsReport_BaseValue".Translate() + ": " + baseString + "\n\n";
                        string finalValueStr = "StatsReport_FinalValue".Translate() + ": " + finalString + "\n";
                        reportText += baseValueStr + affixValueStr + finalValueStr;
                    }
                    else
                    {
                        reportText += affixValueStr;
                    }
                }

                reportTextField.SetValue(statDrawEntry, reportText);
            }
        }
        public override IEnumerable <string> ConfigErrors()
        {
            foreach (string configError in base.ConfigErrors())
            {
                yield return(configError);
            }

            if (groupName == null)
            {
                yield return("No groupName defined");
            }
            if (modifiers.Count == 0)
            {
                yield return("No modifiers defined");
            }
            if (Mathf.Clamp(affixCost, -6f, 6f) != affixCost)
            {
                yield return("affixCost is out-of-bounds; should be between -6 and 6");
            }

            // affixRulePack checks
            var namerDef = DefDatabase <LootAffixNamerRulePackDef> .GetNamed("RimLoot_LootAffixNamer");

            if (namerDef == null)
            {
                Log.ErrorOnce("No LootAffixNamerConfigDef called 'RimLoot_LootAffixNamer_Config' to check!", 47764624);
                yield break;
            }
            Dictionary <string, int> maxWordClasses = namerDef.maxWordClasses;
            List <Rule> fullRules = affixRulePack.Rules;

            // Find a word class rule from the list of affixes
            int wordClassRuleCount = fullRules.Where(r => maxWordClasses.ContainsKey(r.keyword)).Count();

            if (wordClassRuleCount == 1)
            {
                yield return("affixRulePack has only 1 rule that matches a word class");
            }
            else if (wordClassRuleCount == 0)
            {
                yield return("affixRulePack has no rules that matches a word class");
            }
            foreach (Rule rule in fullRules)
            {
                if (rule.keyword.StartsWith("AFFIX"))
                {
                    yield return("affixRulePack should not have an AFFIX prefix: " + rule.keyword);
                }
                if (rgxDigit.IsMatch(rule.keyword))
                {
                    yield return("affixRulePack should not have any digits: " + rule.keyword);
                }
            }

            // Recurse through the modifiers
            for (int i = 0; i < modifiers.Count; i++)
            {
                LootAffixModifier modifier = modifiers[i];

                // ModifierChangeStat might be bugged, due to missing XML properties
                string modifierName;
                try   { modifierName = modifier.ModifierChangeStat; }
                catch { modifierName = string.Format("Modifier {0} ({1})", i + 1, modifier.ToStringSafe()); }

                foreach (string configError in modifier.ConfigErrors(this))
                {
                    yield return(modifierName + ": " + configError);
                }
            }
        }