public float GetLevel(PawnCapacityDef capacity)
        {
            if (this.pawn.health.Dead)
            {
                return(0f);
            }
            if (this.cachedCapacityLevels == null)
            {
                this.Notify_CapacityLevelsDirty();
            }
            CacheElement cacheElement = this.cachedCapacityLevels[capacity];

            if (cacheElement.status == CacheStatus.Caching)
            {
                Log.Error(string.Format("Detected infinite stat recursion when evaluating {0}", capacity));
                return(0f);
            }
            if (cacheElement.status == CacheStatus.Uncached)
            {
                cacheElement.status = CacheStatus.Caching;
                cacheElement.value  = PawnCapacityUtility.CalculateCapacityLevel(this.pawn.health.hediffSet, capacity, null);
                cacheElement.status = CacheStatus.Cached;
            }
            return(cacheElement.value);
        }
Example #2
0
        public float GetLevel(PawnCapacityDef capacity)
        {
            if (pawn.health.Dead)
            {
                return(0f);
            }
            if (cachedCapacityLevels == null)
            {
                Notify_CapacityLevelsDirty();
            }
            CacheElement cacheElement = cachedCapacityLevels[capacity];

            if (cacheElement.status == CacheStatus.Caching)
            {
                Log.Error($"Detected infinite stat recursion when evaluating {capacity}");
                return(0f);
            }
            if (cacheElement.status == CacheStatus.Uncached)
            {
                cacheElement.status = CacheStatus.Caching;
                try
                {
                    cacheElement.value = PawnCapacityUtility.CalculateCapacityLevel(pawn.health.hediffSet, capacity);
                }
                finally
                {
                    cacheElement.status = CacheStatus.Cached;
                }
            }
            return(cacheElement.value);
        }
Example #3
0
        public static void Prosthetics()
        {
            PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDefOf.Colonist, Faction.OfPlayer, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, inhabitant: false, certainlyBeenInCryptosleep: false, forceRedressWorldPawnIfFormerColonist: false, worldPawnFactionDoesntMatter: false, 0f, null, 1f, (Pawn p) => p.health.hediffSet.hediffs.Count == 0);
            Pawn   pawn        = PawnGenerator.GeneratePawn(request);
            Action refreshPawn = delegate
            {
                while (pawn.health.hediffSet.hediffs.Count > 0)
                {
                    pawn.health.RemoveHediff(pawn.health.hediffSet.hediffs[0]);
                }
            };
            Func <RecipeDef, BodyPartRecord>    getApplicationPoint = (RecipeDef recipe) => recipe.appliedOnFixedBodyParts.SelectMany((BodyPartDef bpd) => pawn.def.race.body.GetPartsWithDef(bpd)).Concat(recipe.appliedOnFixedBodyPartGroups.SelectMany((BodyPartGroupDef g) => pawn.def.race.body.AllParts.Where((BodyPartRecord r) => r.groups != null && r.groups.Contains(g)))).FirstOrDefault();
            Func <RecipeDef, ThingDef>          getProstheticItem   = (RecipeDef recipe) => recipe.ingredients.Select((IngredientCount ic) => ic.filter.AnyAllowedDef).FirstOrDefault((ThingDef td) => !td.IsMedicine);
            List <TableDataGetter <RecipeDef> > list = new List <TableDataGetter <RecipeDef> >();

            list.Add(new TableDataGetter <RecipeDef>("defName", (RecipeDef r) => r.defName));
            list.Add(new TableDataGetter <RecipeDef>("price", (RecipeDef r) => getProstheticItem(r)?.BaseMarketValue ?? 0f));
            list.Add(new TableDataGetter <RecipeDef>("install time", (RecipeDef r) => r.workAmount));
            list.Add(new TableDataGetter <RecipeDef>("install total cost", delegate(RecipeDef r)
            {
                float num2 = r.ingredients.Sum((IngredientCount ic) => ic.filter.AnyAllowedDef.BaseMarketValue * ic.GetBaseCount());
                float num3 = r.workAmount * 0.0036f;
                return(num2 + num3);
            }));
            list.Add(new TableDataGetter <RecipeDef>("install skill", (RecipeDef r) => r.skillRequirements.Select((SkillRequirement sr) => sr.minLevel).Max()));
            foreach (PawnCapacityDef cap in DefDatabase <PawnCapacityDef> .AllDefs.OrderBy((PawnCapacityDef pc) => pc.listOrder))
            {
                list.Add(new TableDataGetter <RecipeDef>(cap.defName, delegate(RecipeDef r)
                {
                    refreshPawn();
                    r.Worker.ApplyOnPawn(pawn, getApplicationPoint(r), null, null, null);
                    float num = pawn.health.capacities.GetLevel(cap) - 1f;
                    if ((double)Math.Abs(num) > 0.001)
                    {
                        return(num.ToStringPercent());
                    }
                    refreshPawn();
                    BodyPartRecord bodyPartRecord = getApplicationPoint(r);
                    pawn.TakeDamage(new DamageInfo(DamageDefOf.ExecutionCut, pawn.health.hediffSet.GetPartHealth(bodyPartRecord) / 2f, 999f, -1f, null, bodyPartRecord));
                    List <PawnCapacityUtility.CapacityImpactor> list2 = new List <PawnCapacityUtility.CapacityImpactor>();
                    PawnCapacityUtility.CalculateCapacityLevel(pawn.health.hediffSet, cap, list2);
                    return(list2.Any((PawnCapacityUtility.CapacityImpactor imp) => imp.IsDirect) ? 0f.ToStringPercent() : "");
                }));
            }
            list.Add(new TableDataGetter <RecipeDef>("tech level", (RecipeDef r) => (getProstheticItem(r) != null) ? getProstheticItem(r).techLevel.ToStringHuman() : ""));
            list.Add(new TableDataGetter <RecipeDef>("thingSetMakerTags", (RecipeDef r) => (getProstheticItem(r) != null) ? getProstheticItem(r).thingSetMakerTags.ToCommaList() : ""));
            list.Add(new TableDataGetter <RecipeDef>("techHediffsTags", (RecipeDef r) => (getProstheticItem(r) != null) ? getProstheticItem(r).techHediffsTags.ToCommaList() : ""));
            DebugTables.MakeTablesDialog(ThingDefOf.Human.AllRecipes.Where((RecipeDef r) => r.workerClass == typeof(Recipe_InstallArtificialBodyPart) || r.workerClass == typeof(Recipe_InstallNaturalBodyPart)), list.ToArray());
            Messages.Clear();
        }
Example #4
0
        public float GetLevel(PawnCapacityDef capacity)
        {
            float result;

            if (this.pawn.health.Dead)
            {
                result = 0f;
            }
            else
            {
                if (this.cachedCapacityLevels == null)
                {
                    this.Notify_CapacityLevelsDirty();
                }
                PawnCapacitiesHandler.CacheElement cacheElement = this.cachedCapacityLevels[capacity];
                if (cacheElement.status == PawnCapacitiesHandler.CacheStatus.Caching)
                {
                    Log.Error(string.Format("Detected infinite stat recursion when evaluating {0}", capacity), false);
                    result = 0f;
                }
                else
                {
                    if (cacheElement.status == PawnCapacitiesHandler.CacheStatus.Uncached)
                    {
                        cacheElement.status = PawnCapacitiesHandler.CacheStatus.Caching;
                        try
                        {
                            cacheElement.value = PawnCapacityUtility.CalculateCapacityLevel(this.pawn.health.hediffSet, capacity, null);
                        }
                        finally
                        {
                            cacheElement.status = PawnCapacitiesHandler.CacheStatus.Cached;
                        }
                    }
                    result = cacheElement.value;
                }
            }
            return(result);
        }