コード例 #1
0
        /// <summary>
        /// add the correct reversion thought at the correct stage
        /// </summary>
        /// <param name="spawned">The spawned.</param>
        private void AddReversionThought(Pawn spawned)
        {
            TraitSet   traits = spawned.story.traits;
            ThoughtDef thoughtDef;
            var        hasPrimalWish = spawned.GetAspectTracker()?.Contains(AspectDefOf.PrimalWish) == true;

            if (hasPrimalWish)
            {
                thoughtDef = def.revertedPrimalWish ?? def.revertedThoughtBad; //substitute with the bad thought if null
            }
            else if (traits.HasTrait(PMTraitDefOf.MutationAffinity))
            {
                thoughtDef = def.revertedThoughtGood;
            }
            else if (traits.HasTrait(TraitDefOf.BodyPurist))
            {
                thoughtDef = def.revertedThoughtBad;
            }
            else
            {
                thoughtDef = Rand.Value > 0.5f ? def.revertedThoughtGood : def.revertedThoughtBad;
            }

            if (thoughtDef != null)
            {
                //TODO fix this with special memory for animalistic pawns
                Thought_Memory mem = ThoughtMaker.MakeThought(thoughtDef, 0);
                spawned.TryGainMemory(mem);
            }
        }
コード例 #2
0
        /// <summary>
        ///     add the correct reversion thought at the correct stage
        /// </summary>
        /// <param name="spawned"></param>
        /// <param name="curStageIndex"></param>
        private void AddReversionThought(Pawn spawned, int curStageIndex)
        {
            TraitSet   traits = spawned.story.traits;
            ThoughtDef thoughtDef;
            var        hasPrimalWish = spawned.GetAspectTracker()?.Contains(AspectDefOf.PrimalWish) == true;

            if (hasPrimalWish)
            {
                thoughtDef = def.revertedPrimalWish ?? def.revertedThoughtBad; //substitute with the bad thought if null
            }
            else if (traits.HasTrait(PMTraitDefOf.MutationAffinity))
            {
                thoughtDef = def.revertedThoughtGood;
            }
            else if (traits.HasTrait(TraitDefOf.BodyPurist))
            {
                thoughtDef = def.revertedThoughtBad;
            }
            else
            {
                thoughtDef = Rand.Value > 0.5f ? def.revertedThoughtGood : def.revertedThoughtBad;
            }

            if (thoughtDef != null)
            {
                curStageIndex = Mathf.Min(curStageIndex, thoughtDef.stages.Count - 1); //avoid index out of bounds issues
                Thought_Memory mem = ThoughtMaker.MakeThought(thoughtDef, curStageIndex);
                spawned.TryGainMemory(mem);
            }
        }
コード例 #3
0
        // RimWorld.TraitSet
        public void LoseTrait(TraitSet traits, Trait trait)
        {
            if (!traits.HasTrait(trait.def))
            {
                Log.Warning(this.AbilityUser + " doesn't have trait " + trait.def);
                return;
            }

            traits.allTraits.Remove(trait);
            if (this.AbilityUser.workSettings != null)
            {
                this.AbilityUser.workSettings.EnableAndInitializeIfNotAlreadyInitialized();
            }

            // this.AbilityUser.story.Notify_TraitChanged();
            if (this.AbilityUser.skills != null)
            {
                this.AbilityUser.skills.Notify_SkillDisablesChanged();
            }

            if (!this.AbilityUser.Dead && this.AbilityUser.RaceProps.Humanlike)
            {
                this.AbilityUser.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
            }
        }
コード例 #4
0
        /// <summary>
        /// Checks if the pawn has any traits that block the given aspect
        /// </summary>
        /// <param name="traitSet">The trait set.</param>
        /// <param name="testAspect">The test aspect.</param>
        /// <returns>if given trait set is valid for the given aspect</returns>
        protected bool CheckPawnTraits([NotNull] TraitSet traitSet, [NotNull] AspectDef testAspect)
        {
            foreach (TraitDef traitDef in testAspect.requiredTraits.MakeSafe())
            {
                if (!traitSet.HasTrait(traitDef))
                {
                    return(false);
                }
            }

            foreach (var traitDef in testAspect.conflictingTraits.MakeSafe())
            {
                if (traitSet.HasTrait(traitDef))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #5
0
        public static void LoseTrait(this TraitSet traitSet, Trait trait)
        {
            Pawn pawn = (Pawn)typeof(TraitSet).GetField("pawn", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(traitSet);

            if (!traitSet.HasTrait(trait.def))
            {
                Log.Warning(pawn + " does not have trait " + trait.def);
                return;
            }
            traitSet.allTraits.Remove(trait);
            traitSet.ForceUpdate();
        }
        // Token: 0x06000011 RID: 17 RVA: 0x00002878 File Offset: 0x00000A78
        public static void Postfix(TraitSet __instance, Trait trait, HashSet <string> TraitsForced, HashSet <string> TraitsBlocked)
        {
            string item  = string.Format("{0}_{1}", trait.def.defName, trait.Degree);
            bool   flag  = TraitsForced != null && TraitsForced.Contains(item);
            bool   flag2 = TraitsBlocked != null && TraitsBlocked.Contains(item);
            bool   flag3 = (flag || flag2) && __instance.HasTrait(trait.def);

            if (flag3)
            {
                __instance.allTraits.Remove(trait);
            }
        }
コード例 #7
0
        // Must be a Prefix because we need to not do anything if the trait is already present
        public static bool Prefix(TraitSet __instance, Trait trait)
        {
            if (__instance.HasTrait(trait.def))
            {
                return(true);
            }
            var collection = trait.def.GetModExtension <GMT_Trait_ModExtension>()?.appliedHediffs ?? null;

            if (collection != null)
            {
                foreach (HediffDef def in collection)
                {
                    if (fieldinfo_pawn == null)
                    {
                        fieldinfo_pawn = typeof(TraitSet).GetField("pawn", BindingFlags.Instance | BindingFlags.NonPublic);
                    }
                    (fieldinfo_pawn.GetValue(__instance) as Pawn).health.AddHediff(def);
                }
            }
            return(true);
        }
コード例 #8
0
        private bool GordenValidator(Pawn obj)
        {
            TraitSet storyTraits = obj?.story?.traits;

            return(storyTraits?.HasTrait(TraitDefOf.Abrasive) == true && storyTraits.HasTrait(TraitDef.Named("Gourmand")));
        }