Example #1
0
 // Add in any AbilityUser Components, if the Pawn is accepting
 public static void InternalAddInAbilityUsers(Pawn pawn)
 {
     if (pawn != null && pawn.RaceProps != null && pawn.RaceProps.Humanlike)
     {
         AbilityUserUtility.TransformPawn(pawn);
     }
 }
        public static bool TransformPawn(Pawn p)
        {
            bool retval = false;

            if (AbilityUserUtility.abilityUserChildren == null)
            {
                AbilityUserUtility.abilityUserChildren = AbilityUserUtility.GetAllChildrenOf(typeof(CompAbilityUser));
            }

            foreach (Type t in AbilityUserUtility.abilityUserChildren)
            {
                bool st = true;

                /*
                 * // this code does a check, but since there is no good way to create triggers when specific events occur to
                 * // add the CompAbilityUser to a Pawn, this just adds them and then checks them on each CompTick.
                 */
                if (st)
                {
                    retval = true;
                    ThingComp thingComp = (ThingComp)Activator.CreateInstance((t));
                    thingComp.parent = p;
                    object comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(p);
                    if (comps != null)
                    {
                        ((List <ThingComp>)comps).Add(thingComp);
                    }
                    thingComp.Initialize(null);
                }
            }
            return(retval);
        }
Example #3
0
        //// Catches loading of Pawns
        //public static void ExposeData_PostFix(Pawn __instance)
        //{ HarmonyPatches.internalAddInAbilityUsers(__instance); }

        //// Catches generation of Pawns
        //public static void GeneratePawn_PostFix(PawnGenerationRequest request, Pawn __result)
        //{ HarmonyPatches.internalAddInAbilityUsers(__result); }

        // Add in any AbilityUser Components, if the Pawn is accepting
        public static void InternalAddInAbilityUsers(Pawn pawn)
        {
            //            Log.Message("Trying to add AbilityUsers to Pawn");
            if (pawn != null && pawn.RaceProps != null && pawn.RaceProps.Humanlike)
            {
                AbilityUserUtility.TransformPawn(pawn);
            }
        }
Example #4
0
        public static bool TransformPawn(Pawn p)
        {
            bool retval = false;

            //            Log.Message("AbilityUserUtility.TransformPawn(p)");

            // init... grab all child classes
            if (AbilityUserUtility.abilityUserChildren == null)
            {
                //                Log.Message("initializing all abilityUserChlildren");
                AbilityUserUtility.abilityUserChildren = AbilityUserUtility.GetAllChildrenOf(typeof(CompAbilityUser));
                //                Log.Message("initializing CompAbilityUser children: found "+AbilityUserUtility.abilityUserChildren.Count+" classes");
            }

            foreach (Type t in AbilityUserUtility.abilityUserChildren)
            {
                bool st = true;

                /*
                 * // this code does a check, but since there is no good way to create triggers when specific events occur to
                 * // add the CompAbilityUser to a Pawn, this just adds them and then checks them on each CompTick.
                 * bool st = false;
                 * object shouldtransform = t.GetMethod("TryTransformPawn").Invoke(null,new object[]{p}); // call static method of child class
                 * if ( shouldtransform is bool ) st = (bool) shouldtransform;
                 */
                if (st)
                {
                    //                    Log.Message(" YES: actually adding in AbilityUser");
                    retval = true;
                    ThingComp thingComp = (ThingComp)Activator.CreateInstance((t));
                    thingComp.parent = p;
                    object comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(p);
                    if (comps != null)
                    {
                        ((List <ThingComp>)comps).Add(thingComp);
                    }
                    thingComp.Initialize(null);
                }
            }
            return(retval);
        }