/// <summary>Gets the total weight.</summary>
            /// the higher the weight the more likely this interaction is going to be picked
            /// <param name="pawn">The pawn.</param>
            /// <returns></returns>
            public float GetTotalWeight(Pawn pawn)
            {
                IEnumerable <HediffDef> hediffs = pawn.health.hediffSet.hediffs.Select(h => h.def);

                float total       = 0;
                var   hasMutation = false;

                foreach (HediffDef hediffDef in hediffs)
                {
                    if (mutationWeights.TryGetValue(hediffDef, out float v))
                    {
                        hasMutation = true;
                        total      += v;
                    }
                }

                bool isMorph = RaceGenerator.TryGetMorphOfRace(pawn.def, out MorphDef morph);

                if (isMorph)
                {
                    isMorph = morphWeights.TryGetValue(morph, out float w);
                    total  += w;
                }

                if (requiresBoth && !isMorph && !hasMutation)
                {
                    total = 0;
                }

                return(total);
            }
示例#2
0
        private static bool PrepareToIngestToilsPrefix(JobDriver __instance, Toil chewToil, ref IEnumerable <Toil> __result) //TODO figure out how to turn this into a transpiler patch
        {
            Thing thing = __instance.job.targetA.Thing;

            if (RaceGenerator.TryGetMorphOfRace(__instance.pawn.def, out MorphDef def))
            {
                if (thing.def.ingestible == null)
                {
                    return(true);
                }

                FoodTypeFlags flg = thing.def.ingestible.foodType & (FoodTypeFlags.Tree | FoodTypeFlags.Plant);
                if (flg != 0)
                {
                    __result = new[]
                    {
                        ReserveFoodIfWillIngestWholeStack(__instance),
                        Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch)
                    };

                    return(false);
                }
            }
            else if (__instance.pawn.IsSapientFormerHuman())
            {
                if (thing.def.ingestible == null)
                {
                    return(true);
                }
            }

            return(true);
        }
示例#3
0
        private void FisExplicitRaceGraphics()
        {
            //work around for the portraits of explicit hybrid races not updating correctly after load for some reason
            //should be removed when that is fixed

            MorphDef morph;

            if (RaceGenerator.TryGetMorphOfRace(Pawn.def, out morph))
            {
                if (Pawn.def == morph.ExplicitHybridRace)
                {
                    Pawn.RefreshGraphics();
                }
            }
        }
        private static void ApplyMorphFoodThoughts(Pawn ingester, Thing foodSource, List <ThoughtDef> foodThoughts)
        {
            if (RaceGenerator.TryGetMorphOfRace(ingester.def, out MorphDef morphDef))
            {
                AteThought cannibalThought = morphDef.raceSettings?.thoughtSettings?.ateAnimalThought;
                if (cannibalThought == null)
                {
                    return;
                }
                if (ingester?.story?.traits == null)
                {
                    return;
                }
                bool cannibal = ingester.story.traits.HasTrait(TraitDefOf.Cannibal);

                if (foodSource.def == morphDef.race.race.meatDef && !cannibal)
                {
                    foodThoughts.Add(cannibalThought.thought);
                    return;
                }

                ThingDef comp = foodSource.TryGetComp <CompIngredients>()
                                ?.ingredients?.FirstOrDefault(def => def == morphDef.race.race.meatDef);
                if (comp != null && !cannibal)
                {
                    foodThoughts.Add(cannibalThought.ingredientThought);
                }
            }
            else
            {
                var fHStatus = ingester.GetQuantizedSapienceLevel();
                if (fHStatus == null || fHStatus == SapienceLevel.PermanentlyFeral)
                {
                    return;
                }

                ThoughtDef thought = GetCannibalThought(ingester, foodSource);
                if (thought != null)
                {
                    foodThoughts.Add(thought);
                }
            }
        }