Exemplo n.º 1
0
        private bool Allows(Thing t, ThingDef expectedDef, QualityRange qualityRange, FloatRange hpRange, ThingFilter filter)
        {
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Warning("StoredApparel.Allows Begin [" + t.Label + "]");
#endif
            if (t.def != expectedDef)
            {
#if DEBUG || DEBUG_DO_UNTIL_X
                Log.Warning("StoredApparel.Allows End Def Does Not Match [False]");
#endif
                return(false);
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Message("    def uses HP: " + expectedDef.useHitPoints + " filter: " + hpRange.min + " " + hpRange.max);
#endif
            if (expectedDef.useHitPoints &&
                hpRange != null &&
                hpRange.min != 0f && hpRange.max != 100f)
            {
                float num = (float)t.HitPoints / (float)t.MaxHitPoints;
                num = GenMath.RoundedHundredth(num);
                if (!hpRange.IncludesEpsilon(Mathf.Clamp01(num)))
                {
#if DEBUG || DEBUG_DO_UNTIL_X
                    Log.Warning("StoredApparel.Allows End Hit Points [False - HP]");
#endif
                    return(false);
                }
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Message("    def follows quality: " + t.def.FollowQualityThingFilter() + " filter quality levels: " + qualityRange.min + " " + qualityRange.max);
#endif
            if (qualityRange != null && qualityRange != QualityRange.All && t.def.FollowQualityThingFilter())
            {
                QualityCategory p;
                if (!t.TryGetQuality(out p))
                {
                    p = QualityCategory.Normal;
                }
                if (!qualityRange.Includes(p))
                {
#if DEBUG || DEBUG_DO_UNTIL_X
                    Log.Warning("StoredApparel.Allows End Quality [False - Quality]");
#endif
                    return(false);
                }
            }

            if (filter != null && !filter.Allows(t.Stuff))
            {
#if DEBUG || DEBUG_DO_UNTIL_X
                Log.Warning("StoredApparel.Allows End Quality [False - filters.Allows]");
#endif
                return(false);
            }
#if DEBUG || DEBUG_DO_UNTIL_X
            Log.Warning("    StoredApparel.Allows End [True]");
#endif
            return(true);
        }
Exemplo n.º 2
0
        // Very similar to `ThingFilter:Allows`
        public bool Allows(Thing thing)
        {
            thing = thing.GetInnerIfMinified();
            // Check the thing is equal to `forThing`
            if (thing.def != forThing)
            {
                return(false);
            }
            // is it made from the correct stuff
            if (!stuffs.EnumerableNullOrEmpty() && !stuffs.Contains(thing.Stuff))
            {
                return(false);
            }
            // does it have the correct number of hit points
            if (!allowedHpRange.IncludesEpsilon(Mathf.Clamp01(thing.HitPoints / (float)thing.MaxHitPoints)))
            {
                return(false);
            }
            // does it fall within the quality range?
            if (allowedQualities != QualityRange.All && !allowedQualities.Includes(GetQuality(thing)))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
 public virtual bool Allows(Thing t)
 {
     t = t.GetInnerIfMinified();
     if (!Allows(t.def))
     {
         return(false);
     }
     if (t.def.useHitPoints)
     {
         float f = (float)t.HitPoints / (float)t.MaxHitPoints;
         f = GenMath.RoundedHundredth(f);
         if (!allowedHitPointsPercents.IncludesEpsilon(Mathf.Clamp01(f)))
         {
             return(false);
         }
     }
     if (allowedQualities != QualityRange.All && t.def.FollowQualityThingFilter())
     {
         if (!t.TryGetQuality(out QualityCategory qc))
         {
             qc = QualityCategory.Normal;
         }
         if (!allowedQualities.Includes(qc))
         {
             return(false);
         }
     }
     for (int i = 0; i < disallowedSpecialFilters.Count; i++)
     {
         if (disallowedSpecialFilters[i].Worker.Matches(t) && t.def.IsWithinCategory(disallowedSpecialFilters[i].parentCategory))
         {
             return(false);
         }
     }
     return(true);
 }
            public static bool ProductMeetsQualityRequirement(Thing product, QualityRange qualityRange)
            {
                var qualityComp = product.GetInnerIfMinified().TryGetComp <CompQuality>();

                return(qualityComp == null || qualityRange.Includes(qualityComp.Quality));
            }