Exemplo n.º 1
0
        /// <summary>
        /// Draw stuff names and info icon buttons as headers for stat table.
        /// </summary>
        /// <param name="startRect"> Rect for drawing stats. </param>
        /// <param name="start"> Start index from which <paramref name="pairListToDraw"/> should begin to read. </param>
        /// <param name="end"> End index which is one greater than the index at which <paramref name="pairListToDraw"/> should stop reading. </param>
        /// <param name="pairListToDraw"> A working set of <see cref="TSPWQuality"/>. </param>
        private static void DrawStatTableHeader(Rect startRect, int start, int end, List <TSPWQuality> pairListToDraw)
        {
            Text.Anchor   = TextAnchor.MiddleCenter;
            Text.WordWrap = false;
            for (int i = start; i < pairListToDraw.Count && i < end; i++)
            {
                TSPWQuality pair       = pairListToDraw[i];
                Rect        buttonRect = startRect.ReplaceWidth(GenUI.SmallIconSize);
                if (Widgets.ButtonImage(buttonRect, TexResource.Info))
                {
                    Thing thing = pair.MakeThingWithoutID();
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }

                Rect labelRect = startRect.ReplacexMin(buttonRect.xMax + GenUI.GapTiny);

                string text = pair.stuff != null?pair.stuff.LabelAsStuff.CapitalizeFirst().ColorizeByQuality(pair.Quality) : pair.thing.LabelCap.ToString();

                labelRect.width -= GenUI.GapTiny;
                if (text.StripTags().GetWidthCached() > labelRect.width)
                {
                    Text.Anchor = TextAnchor.MiddleLeft;
                }

                Widgets.Label(labelRect, text);
                startRect = startRect.ReplaceX(startRect.xMax);
            }

            Text.Anchor   = TextAnchor.UpperLeft;
            Text.WordWrap = true;
        }
Exemplo n.º 2
0
        private static void DrawRangedStatRows(List <TSPWQuality> pairList, Rect startRect, int from, int to)
        {
            List <List <StatDrawInfo> > listHolder      = new List <List <StatDrawInfo> >();
            List <List <StatDrawInfo> > transposedLists = new List <List <StatDrawInfo> >();

            // listHolder[0]  listHolder[1]
            // | stuff1 |     | stuff2 |
            // | Damage |     | Damage |
            // | AP     |     | AP     |

            /*                       stuff1   stuff2
             * transposedLists[0]    Damage   Damage
             * transposedLists[1]    AP       AP
             */

            for (int i = from; i < to && i < pairList.Count; i++)
            {
                TSPWQuality         pair     = pairList[i];
                List <StatDrawInfo> infoList = new List <StatDrawInfo>();

                infoList.AddRange(pair.thing.SpecialDisplayStats(StatRequest.For(pair.thing, pair.stuff, pair.Quality))
                                  .Where(r => _rangedWeaponStats.Any(s => s.label.CapitalizeFirst() == r.LabelCap))
                                  .Select(r => (StatDrawInfo)r)
                                  .ToList());
                listHolder.Add(infoList);
            }

            // Transpose lists
            for (int i = 0; i < _rangedWeaponStats.Count; i++)
            {
                List <StatDrawInfo> newList = new List <StatDrawInfo>();
                foreach (List <StatDrawInfo> list in listHolder)
                {
                    newList.Add(
                        list.Find(s => s.LabelCap == _rangedWeaponStats[i].label.CapitalizeFirst())
                        ?? new StatDrawInfo()
                    {
                        ValueString = "-", Tip = string.Empty,
                    });
                }

                if (newList.Count > 1)
                {
                    List <StatDrawInfo> orderedList = newList.OrderByDescending(t => t.Value).ToList();
                    foreach (StatDrawInfo statDrawInfo in orderedList)
                    {
                        if (statDrawInfo.Value == orderedList[0].Value)
                        {
                            statDrawInfo.Color = Color.green;
                        }
                    }
                }

                transposedLists.Add(newList);
            }

            DrawStatRows(_rangedWeaponStats, null, startRect, from, to, out _, transposedLists, true);
        }
Exemplo n.º 3
0
        private static float GetMaxValueWithMaxMass(ThingStuffPairWithQuality t, float massSoFar, float maxMass, Func <ThingStuffPairWithQuality, float> getMinValue, Func <ThingStuffPairWithQuality, float> getMaxValue)
        {
            if (maxMass == 3.40282347E+38f)
            {
                return(getMaxValue(t));
            }
            int num = Mathf.Clamp(Mathf.FloorToInt((maxMass - massSoFar) / t.GetStatValue(StatDefOf.Mass)), 1, t.thing.stackLimit);

            return(getMinValue(t) * (float)num);
        }
Exemplo n.º 4
0
 public static IEnumerable <GenUI.AnonymousStackElement> GetRewardStackElementsForThings(IEnumerable <Reward_Items.RememberedItem> thingDefs)
 {
     tmpThingDefs.Clear();
     foreach (Reward_Items.RememberedItem thingDef in thingDefs)
     {
         bool flag = false;
         for (int j = 0; j < tmpThingDefs.Count; j++)
         {
             if (tmpThingDefs[j].thing == thingDef.thing && tmpThingDefs[j].label == thingDef.label)
             {
                 tmpThingDefs[j] = new Reward_Items.RememberedItem(tmpThingDefs[j].thing, tmpThingDefs[j].stackCount + thingDef.stackCount, tmpThingDefs[j].label);
                 flag            = true;
                 break;
             }
         }
         if (!flag)
         {
             tmpThingDefs.Add(thingDef);
         }
     }
     for (int i = 0; i < tmpThingDefs.Count; i++)
     {
         ThingStuffPairWithQuality thing = tmpThingDefs[i].thing;
         int    stackCount = tmpThingDefs[i].stackCount;
         string label      = tmpThingDefs[i].label.CapitalizeFirst() + ((stackCount > 1) ? (" x" + stackCount) : "");
         yield return(new GenUI.AnonymousStackElement
         {
             drawer = delegate(Rect rect)
             {
                 Widgets.DrawHighlight(rect);
                 Rect rect2 = new Rect(rect.x + 6f, rect.y + 1f, rect.width - 12f, rect.height - 2f);
                 if (Mouse.IsOver(rect))
                 {
                     Widgets.DrawHighlight(rect);
                     TooltipHandler.TipRegion(rect, thing.thing.DescriptionDetailed + "\n\n" + "ClickForMoreInfo".Translate());
                 }
                 Widgets.ThingIcon(new Rect(rect2.x, rect2.y, 22f, 22f), thing.thing, thing.stuff);
                 Rect rect3 = rect2;
                 rect3.xMin += 24f;
                 Widgets.Label(rect3, label);
                 if (Widgets.ButtonInvisible(rect))
                 {
                     Find.WindowStack.Add(new Dialog_InfoCard(thing.thing, thing.stuff));
                 }
             },
             width = Text.CalcSize(label).x + 12f + 22f + 2f
         });
     }
 }
Exemplo n.º 5
0
        private static Thing MakeThingSimple(TSP pair)
        {
            ThingWithComps thing       = new ThingWithComps();
            CompQuality    compQuality = new CompQuality
            {
                parent = thing
            };

            Traverse.Create(thing).Field("comps").SetValue(new List <ThingComp>()).Method("Add", compQuality).GetValue();
            Trace.WriteLine(thing.AllComps.Count);
            thing.def = pair.thing;
            thing.SetStuffDirect(pair.stuff);
            if (thing.TryGetComp <CompQuality>() == null)
            {
                Trace.WriteLine(thing.AllComps[0].GetType());
                Trace.WriteLine(thing.AllComps[0] as CompQuality == null ? "null" : "no");
                Trace.WriteLine(typeof(CompQuality));
                Trace.WriteLine("quality is null");
            }
            thing.TryGetComp <CompQuality>().SetQuality(pair.Quality, ArtGenerationContext.Outsider);
            return(thing);
        }
 private float GetMinValue(ThingStuffPairWithQuality thingStuffPair)
 {
     return(thingStuffPair.GetStatValue(StatDefOf.MarketValue) * (float)thingStuffPair.thing.minRewardCount);
 }
Exemplo n.º 7
0
 internal bool <> m__0(ThingStuffPairWithQuality x)
 {
     return(this.getMaxValue(x) < this.trashThreshold);
 }
Exemplo n.º 8
0
        private static void DrawStatRows(List <StatDef> stats, List <TSPWQuality> pairs, Rect startRect, int from, int to,
                                         out float rollingY, List <List <StatDrawInfo> > listHolder = null,
                                         bool specialStats = false)
        {
            float startX = startRect.x;

            for (int i = 0; i < stats.Count; i++)
            {
                List <StatDrawInfo> statInfoList = new List <StatDrawInfo>();
                if (!specialStats)
                {
                    statInfoList = new List <StatDrawInfo>();

                    // Retrieve stat value and create a view model, StatDrawInfo, for drawing.
                    for (int j = from; j < to && j < pairs.Count; j++)
                    {
                        TSPWQuality  pair        = pairs[j];
                        StatDrawInfo drawInfo    = new StatDrawInfo();
                        Thing        tempThing   = pair.MakeThingWithoutID();
                        StatRequest  statRequest = StatRequest.For(tempThing);
                        if ((stats[i].Worker.ShouldShowFor(statRequest) && !stats[i].Worker.IsDisabledFor(tempThing)) || stats[i] == StatDefOf.MaxHitPoints || stats[i] == StatDefOf.MeleeWeapon_CooldownMultiplier)
                        {
                            drawInfo.StatRequest = statRequest;
                            drawInfo.Value       = GetCachedValue(_statCache, () => stats[i].Worker.GetValue(drawInfo.StatRequest), pair, stats[i]);
                            drawInfo.Tip         = GetCachedValue(_statTipCache, () => stats[i].Worker.GetExplanationFull(drawInfo.StatRequest, stats[i].toStringNumberSense, drawInfo.Value), pair, stats[i]);
                        }
                        else
                        {
                            drawInfo.Value = -1;
                            drawInfo.Tip   = string.Empty;
                        }

                        statInfoList.Add(drawInfo);
                    }

                    if (statInfoList.Count > 1)
                    {
                        // Highlight highest stat value.
                        List <StatDrawInfo> orderedList = statInfoList.OrderByDescending(t => t.Value).ToList();
                        foreach (StatDrawInfo statDrawInfo in orderedList)
                        {
                            if (statDrawInfo.Value == orderedList[0].Value)
                            {
                                statDrawInfo.Color = Color.green;
                            }
                        }
                    }
                }
                else
                {
                    statInfoList = listHolder[i];
                }

#pragma warning disable SA1118 // Parameter should not span multiple lines

                // Draw stat for each stuff choice.
                Text.Anchor = TextAnchor.MiddleCenter;
                foreach (StatDrawInfo info in statInfoList)
                {
                    GUI.color = info.Color;
                    Widgets.Label(
                        startRect,
                        specialStats
                        ? info.ValueString
                        : info.Value == -1
                            ? "-"
                            : stats[i].Worker.ValueToString(info.Value, true, stats[i].toStringNumberSense));
                    Widgets.DrawHighlightIfMouseover(startRect);
                    Text.Anchor = TextAnchor.MiddleLeft;
                    TooltipHandler.TipRegion(startRect, info.Tip);
                    Text.Anchor = TextAnchor.MiddleCenter;
                    startRect   = startRect.ReplaceX(startRect.xMax);
                }
#pragma warning restore SA1118 // Parameter should not span multiple lines

                startRect = new Rect(startX, startRect.yMax, startRect.width, startRect.height);
            }

            rollingY    = startRect.y;
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }
Exemplo n.º 9
0
        private static float GetNonTrashMass(ThingStuffPairWithQuality t, float trashThreshold, Func <ThingStuffPairWithQuality, float> getMinValue)
        {
            int num = Mathf.Clamp(Mathf.CeilToInt(trashThreshold / getMinValue(t)), 1, t.thing.stackLimit);

            return(t.GetStatValue(StatDefOf.Mass) * (float)num);
        }
 private float GetMaxValue(ThingStuffPairWithQuality thingStuffPair)
 {
     return(this.GetMinValue(thingStuffPair) * (float)thingStuffPair.thing.stackLimit);
 }
 private float GetMinValue(ThingStuffPairWithQuality thingStuffPair)
 {
     return(thingStuffPair.GetStatValue(StatDefOf.MarketValue));
 }
Exemplo n.º 12
0
        public static List <ThingStuffPairWithQuality> GenerateDefsWithPossibleTotalValue_NewTmp3(IntRange countRange, float totalValue, IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator, Func <ThingStuffPairWithQuality, float> getMinValue, Func <ThingStuffPairWithQuality, float> getMaxValue, Func <ThingStuffPairWithQuality, float> getSingleThingValue, Func <ThingDef, float> weightSelector = null, int tries = 100, float maxMass = float.MaxValue, bool allowNonStackableDuplicates = true, float minSingleItemValue = 0f)
        {
            minValuesTmp.Clear();
            maxValuesTmp.Clear();
            List <ThingStuffPairWithQuality> chosen = new List <ThingStuffPairWithQuality>();

            if (countRange.max <= 0)
            {
                return(chosen);
            }
            if (countRange.min < 1)
            {
                countRange.min = 1;
            }
            CalculateAllowedThingStuffPairs(allowed, techLevel, qualityGenerator);
            float trashThreshold = Mathf.Max(GetTrashThreshold(countRange, totalValue, MaxValue), minSingleItemValue);

            allowedThingStuffPairs.RemoveAll((ThingStuffPairWithQuality x) => MaxValue(x) < trashThreshold);
            if (!allowedThingStuffPairs.Any())
            {
                return(chosen);
            }
            float a    = float.MaxValue;
            float num  = float.MinValue;
            float num2 = float.MaxValue;

            foreach (ThingStuffPairWithQuality allowedThingStuffPair in allowedThingStuffPairs)
            {
                a   = Mathf.Min(a, MinValue(allowedThingStuffPair));
                num = Mathf.Max(num, MaxValue(allowedThingStuffPair));
                if (allowedThingStuffPair.thing.category != ThingCategory.Pawn)
                {
                    num2 = Mathf.Min(num2, GetNonTrashMass(allowedThingStuffPair, trashThreshold, MinValue));
                }
            }
            a = Mathf.Max(a, trashThreshold);
            float totalMinValueSoFar = 0f;
            float totalMaxValueSoFar = 0f;
            float minMassSoFar       = 0f;
            int   num3 = 0;

            do
            {
                num3++;
                if (num3 > 10000)
                {
                    Log.Error("Too many iterations.");
                    break;
                }
                candidatesTmp.Clear();
                for (int i = 0; i < allowedThingStuffPairs.Count; i++)
                {
                    ThingStuffPairWithQuality candidate = allowedThingStuffPairs[i];
                    if (!allowNonStackableDuplicates && candidate.thing.stackLimit == 1 && chosen.Any((ThingStuffPairWithQuality c) => c.thing == candidate.thing))
                    {
                        continue;
                    }
                    if (maxMass != float.MaxValue && candidate.thing.category != ThingCategory.Pawn)
                    {
                        float nonTrashMass = GetNonTrashMass(candidate, trashThreshold, MinValue);
                        if (minMassSoFar + nonTrashMass > maxMass || (chosen.Count < countRange.min && minMassSoFar + num2 * (float)(countRange.min - chosen.Count - 1) + nonTrashMass > maxMass))
                        {
                            continue;
                        }
                    }
                    if (!(totalMinValueSoFar + Mathf.Max(MinValue(candidate), trashThreshold) > totalValue) && (chosen.Count >= countRange.min || !(totalMinValueSoFar + a * (float)(countRange.min - chosen.Count - 1) + Mathf.Max(MinValue(candidate), trashThreshold) > totalValue)))
                    {
                        candidatesTmp.Add(candidate);
                    }
                }
                if (countRange.max != int.MaxValue && totalMaxValueSoFar < totalValue * 0.5f)
                {
                    candidatesTmpNew.Clear();
                    for (int j = 0; j < candidatesTmp.Count; j++)
                    {
                        ThingStuffPairWithQuality thingStuffPairWithQuality = candidatesTmp[j];
                        if (totalMaxValueSoFar + num * (float)(countRange.max - chosen.Count - 1) + MaxValue(thingStuffPairWithQuality) >= totalValue * 0.5f)
                        {
                            candidatesTmpNew.Add(thingStuffPairWithQuality);
                        }
                    }
                    if (candidatesTmpNew.Any())
                    {
                        candidatesTmp.Clear();
                        candidatesTmp.AddRange(candidatesTmpNew);
                    }
                }
                float maxCandidateMinValue = float.MinValue;
                for (int k = 0; k < candidatesTmp.Count; k++)
                {
                    ThingStuffPairWithQuality t2 = candidatesTmp[k];
                    maxCandidateMinValue = Mathf.Max(maxCandidateMinValue, Mathf.Max(MinValue(t2), trashThreshold));
                }
                if (!candidatesTmp.TryRandomElementByWeight(delegate(ThingStuffPairWithQuality x)
                {
                    float a2 = 1f;
                    if (countRange.max != int.MaxValue && chosen.Count < countRange.max && totalValue >= totalMaxValueSoFar)
                    {
                        int num4 = countRange.max - chosen.Count;
                        float b = (totalValue - totalMaxValueSoFar) / (float)num4;
                        a2 = Mathf.InverseLerp(0f, b, MaxValue(x));
                    }
                    float b2 = 1f;
                    if (chosen.Count < countRange.min && totalValue >= totalMinValueSoFar)
                    {
                        int num5 = countRange.min - chosen.Count;
                        float num6 = (totalValue - totalMinValueSoFar) / (float)num5;
                        float num7 = Mathf.Max(MinValue(x), trashThreshold);
                        if (num7 > num6)
                        {
                            b2 = num6 / num7;
                        }
                    }
                    float num8 = Mathf.Max(Mathf.Min(a2, b2), 1E-05f);
                    if (weightSelector != null)
                    {
                        num8 *= weightSelector(x.thing);
                    }
                    if (totalValue > totalMaxValueSoFar)
                    {
                        int num9 = Mathf.Max(countRange.min - chosen.Count, 1);
                        float num10 = Mathf.InverseLerp(0f, maxCandidateMinValue * 0.85f, GetMaxValueWithMaxMass(x, minMassSoFar, maxMass, MinValue, MaxValue) * (float)num9);
                        num8 *= num10 * num10;
                    }
                    if (PawnWeaponGenerator.IsDerpWeapon(x.thing, x.stuff))
                    {
                        num8 *= 0.1f;
                    }
                    if (techLevel != 0)
                    {
                        TechLevel techLevel2 = x.thing.techLevel;
                        if ((int)techLevel2 < (int)techLevel && (int)techLevel2 <= 2 && (x.thing.IsApparel || x.thing.IsWeapon))
                        {
                            num8 *= 0.1f;
                        }
                    }
                    return(num8);
                }, out var result))
                {
                    break;
                }
                chosen.Add(result);
                totalMinValueSoFar += Mathf.Max(MinValue(result), trashThreshold);
                totalMaxValueSoFar += MaxValue(result);
                if (result.thing.category != ThingCategory.Pawn)
                {
                    minMassSoFar += GetNonTrashMass(result, trashThreshold, MinValue);
                }
            }while (chosen.Count < countRange.max && (chosen.Count < countRange.min || !(totalMaxValueSoFar >= totalValue * 0.9f)));
            return(chosen);

            float MaxValue(ThingStuffPairWithQuality t)
            {
                if (!maxValuesTmp.TryGetValue(t, out var value2))
                {
                    value2          = getMaxValue(t);
                    maxValuesTmp[t] = value2;
                }
                return(value2);
            }

            float MinValue(ThingStuffPairWithQuality t)
            {
                if (!minValuesTmp.TryGetValue(t, out var value))
                {
                    value           = getMinValue(t);
                    minValuesTmp[t] = value;
                }
                return(value);
            }
        }
 private float GetMaxValue(ThingStuffPairWithQuality thingStuffPair)
 {
     return(thingStuffPair.GetStatValue(StatDefOf.MarketValue) * (float)thingStuffPair.thing.stackLimit);
 }
Exemplo n.º 14
0
        private static T GetCachedValue <T>(Dictionary <TSPWQuality, Dictionary <StatDef, T> > cache, Func <T> valueGetter, TSPWQuality pair, StatDef statDef)
        {
            if (cache.TryGetValue(pair, out Dictionary <StatDef, T> cachedValues))
            {
                if (cachedValues.TryGetValue(statDef, out T cacheValue))
                {
                    return(cacheValue);
                }
                else
                {
                    cacheValue            = valueGetter();
                    cachedValues[statDef] = cacheValue;
                    return(cacheValue);
                }
            }
            else
            {
                T statValue = valueGetter();
                cachedValues = new Dictionary <StatDef, T>();

                cache[pair]           = cachedValues;
                cachedValues[statDef] = statValue;

                return(statValue);
            }
        }
 private static float <GeneratePossibleDefs> m__4(ThingStuffPairWithQuality x)
 {
     return(x.GetStatValue(StatDefOf.Nutrition) * (float)x.thing.stackLimit);
 }
 private static float <GeneratePossibleDefs> m__3(ThingStuffPairWithQuality x)
 {
     return(x.GetStatValue(StatDefOf.Nutrition));
 }
        public static List <ThingStuffPairWithQuality> GenerateDefsWithPossibleTotalValue(IntRange countRange, float totalValue, IEnumerable <ThingDef> allowed, TechLevel techLevel, QualityGenerator qualityGenerator, Func <ThingStuffPairWithQuality, float> getMinValue, Func <ThingStuffPairWithQuality, float> getMaxValue, Func <ThingDef, float> weightSelector = null, int tries = 100, float maxMass = float.MaxValue)
        {
            List <ThingStuffPairWithQuality> chosen = new List <ThingStuffPairWithQuality>();

            if (countRange.max <= 0)
            {
                return(chosen);
            }
            if (countRange.min < 1)
            {
                countRange.min = 1;
            }
            CalculateAllowedThingStuffPairs(allowed, techLevel, qualityGenerator);
            float trashThreshold = GetTrashThreshold(countRange, totalValue, getMaxValue);

            allowedThingStuffPairs.RemoveAll((ThingStuffPairWithQuality x) => getMaxValue(x) < trashThreshold);
            if (!allowedThingStuffPairs.Any())
            {
                return(chosen);
            }
            float minCandidateValueEver = 3.40282347E+38f;
            float maxCandidateValueEver = -3.40282347E+38f;
            float minMassEver           = 3.40282347E+38f;

            foreach (ThingStuffPairWithQuality allowedThingStuffPair in allowedThingStuffPairs)
            {
                ThingStuffPairWithQuality current = allowedThingStuffPair;
                minCandidateValueEver = Mathf.Min(minCandidateValueEver, getMinValue(current));
                maxCandidateValueEver = Mathf.Max(maxCandidateValueEver, getMaxValue(current));
                if (current.thing.category != ThingCategory.Pawn)
                {
                    minMassEver = Mathf.Min(minMassEver, GetNonTrashMass(current, trashThreshold, getMinValue));
                }
            }
            minCandidateValueEver = Mathf.Max(minCandidateValueEver, trashThreshold);
            float totalMinValueSoFar = 0f;
            float totalMaxValueSoFar = 0f;
            float minMassSoFar       = 0f;
            int   num = 0;

            do
            {
                num++;
                if (num > 10000)
                {
                    Log.Error("Too many iterations.");
                    break;
                }
                IEnumerable <ThingStuffPairWithQuality> enumerable = allowedThingStuffPairs.Where(delegate(ThingStuffPairWithQuality x)
                {
                    if (maxMass != 3.40282347E+38f && x.thing.category != ThingCategory.Pawn)
                    {
                        float nonTrashMass = GetNonTrashMass(x, trashThreshold, getMinValue);
                        if (minMassSoFar + nonTrashMass > maxMass)
                        {
                            return(false);
                        }
                        if (chosen.Count < countRange.min && minMassSoFar + minMassEver * (float)(countRange.min - chosen.Count - 1) + nonTrashMass > maxMass)
                        {
                            return(false);
                        }
                    }
                    if (totalMinValueSoFar + Mathf.Max(getMinValue(x), trashThreshold) > totalValue)
                    {
                        return(false);
                    }
                    if (chosen.Count < countRange.min && totalMinValueSoFar + minCandidateValueEver * (float)(countRange.min - chosen.Count - 1) + Mathf.Max(getMinValue(x), trashThreshold) > totalValue)
                    {
                        return(false);
                    }
                    return(true);
                });
                if (countRange.max != 2147483647 && totalMaxValueSoFar < totalValue * 0.5f)
                {
                    IEnumerable <ThingStuffPairWithQuality> enumerable2 = enumerable;
                    enumerable = from x in enumerable
                                 where totalMaxValueSoFar + maxCandidateValueEver * (float)(countRange.max - chosen.Count - 1) + getMaxValue(x) >= totalValue * 0.5f
                                 select x;
                    if (!enumerable.Any())
                    {
                        enumerable = enumerable2;
                    }
                }
                float maxCandidateMinValue = -3.40282347E+38f;
                foreach (ThingStuffPairWithQuality item in enumerable)
                {
                    maxCandidateMinValue = Mathf.Max(maxCandidateMinValue, Mathf.Max(getMinValue(item), trashThreshold));
                }
                if (!enumerable.TryRandomElementByWeight(delegate(ThingStuffPairWithQuality x)
                {
                    float a = 1f;
                    if (countRange.max != 2147483647 && chosen.Count < countRange.max && totalValue >= totalMaxValueSoFar)
                    {
                        int num2 = countRange.max - chosen.Count;
                        float b = (totalValue - totalMaxValueSoFar) / (float)num2;
                        a = Mathf.InverseLerp(0f, b, getMaxValue(x));
                    }
                    float b2 = 1f;
                    if (chosen.Count < countRange.min && totalValue >= totalMinValueSoFar)
                    {
                        int num3 = countRange.min - chosen.Count;
                        float num4 = (totalValue - totalMinValueSoFar) / (float)num3;
                        float num5 = Mathf.Max(getMinValue(x), trashThreshold);
                        if (num5 > num4)
                        {
                            b2 = num4 / num5;
                        }
                    }
                    float num6 = Mathf.Max(Mathf.Min(a, b2), 1E-05f);
                    if (weightSelector != null)
                    {
                        num6 *= weightSelector(x.thing);
                    }
                    if (totalValue > totalMaxValueSoFar)
                    {
                        int num7 = Mathf.Max(countRange.min - chosen.Count, 1);
                        float num8 = Mathf.InverseLerp(0f, maxCandidateMinValue * 0.85f, GetMaxValueWithMaxMass(x, minMassSoFar, maxMass, getMinValue, getMaxValue) * (float)num7);
                        num6 *= num8 * num8;
                    }
                    if (PawnWeaponGenerator.IsDerpWeapon(x.thing, x.stuff))
                    {
                        num6 *= 0.1f;
                    }
                    if (techLevel != 0)
                    {
                        TechLevel techLevel2 = x.thing.techLevel;
                        if ((int)techLevel2 < (int)techLevel && (int)techLevel2 <= 2 && (x.thing.IsApparel || x.thing.IsWeapon))
                        {
                            num6 *= 0.1f;
                        }
                    }
                    return(num6);
                }, out ThingStuffPairWithQuality result))
                {
                    break;
                }
                chosen.Add(result);
                totalMinValueSoFar += Mathf.Max(getMinValue(result), trashThreshold);
                totalMaxValueSoFar += getMaxValue(result);
                if (result.thing.category != ThingCategory.Pawn)
                {
                    minMassSoFar += GetNonTrashMass(result, trashThreshold, getMinValue);
                }
            }while (chosen.Count < countRange.max && (chosen.Count < countRange.min || !(totalMaxValueSoFar >= totalValue * 0.9f)));
            return(chosen);
        }
Exemplo n.º 18
0
 public RememberedItem(ThingStuffPairWithQuality thing, int stackCount, string label)
 {
     this.thing      = thing;
     this.stackCount = stackCount;
     this.label      = label;
 }