public void PowersSetup() { CompForceUser forcePowers = this.GetComp <CompForceUser>(); if (forcePowers == null) { ThingComp thingComp = (ThingComp)Activator.CreateInstance(typeof(CompForceUser)); thingComp.parent = this; var comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(this); if (comps != null) { ((List <ThingComp>)comps).Add(thingComp); } thingComp.Initialize(null); } forcePowers = this.GetComp <CompForceUser>(); if (forcePowers != null) { forcePowers.AlignmentValue = 0.99f; for (int o = 0; o < 10; o++) { forcePowers.ForceUserLevel += 1; forcePowers.ForceData.Skills.InRandomOrder <ForceSkill>().First((ForceSkill x) => x.level < 4).level++; forcePowers.ForceData.AbilityPoints -= 1; } for (int i = 0; i < 8; i++) { forcePowers.ForceUserLevel += 1; forcePowers.LevelUpPower(forcePowers.ForceData.PowersLight.InRandomOrder <ForcePower>().First((ForcePower x) => x.level < 2)); forcePowers.ForceData.AbilityPoints -= 1; } } }
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); }
public static void Postfix(ThingWithComps __instance) { if (__instance.Stuff != null && __instance.Stuff.comps != null) { CompProperties_AddedThing compProperties_AddedThing = __instance.Stuff.comps.Where(x => x is CompProperties_AddedThing).FirstOrDefault() as CompProperties_AddedThing; if (compProperties_AddedThing != null) { if (!compProperties_AddedThing.ForApparel && __instance is Apparel) { return; } if (!compProperties_AddedThing.ForWeapons && __instance.def.equipmentType == EquipmentType.Primary) { return; } FieldInfo compsField = (typeof(ThingWithComps).GetField("comps", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)); List <ThingComp> comps = compsField.GetValue(__instance) as List <ThingComp>; if (comps == null) { comps = new List <ThingComp>(); } ThingComp thingComp = (ThingComp)Activator.CreateInstance(compProperties_AddedThing.Comp); thingComp.parent = __instance; comps.Add(thingComp); thingComp.Initialize(compProperties_AddedThing); compsField.SetValue(__instance, comps); } } }
public static void InitializeTMComps(Pawn p, bool initMagic = false, bool initMight = false) { if (p.def.comps.Any()) { List <ThingComp> comps = Traverse.Create(root: p).Field(name: "comps").GetValue <List <ThingComp> >(); for (int i = 0; i < comps.Count; i++) { ThingComp thingComp = null; if (initMagic && comps[i].ToString().Contains("CompAbilityUserMagic")) { try { //thingComp = (ThingComp)Activator.CreateInstance(comps[i]); thingComp.parent = p; comps.Add(thingComp); thingComp.Initialize(p.def.comps[i]); } catch (Exception arg) { Log.Error("Could not instantiate or initialize a ThingComp: " + arg); comps.Remove(thingComp); } } if (initMight && p.def.comps[i].compClass.ToString().Contains("CompAbilityUserMight")) { try { thingComp = (ThingComp)Activator.CreateInstance(p.def.comps[i].compClass); thingComp.parent = p; comps.Add(thingComp); thingComp.Initialize(p.def.comps[i]); } catch (Exception arg) { Log.Error("Could not instantiate or initialize a ThingComp: " + arg); comps.Remove(thingComp); } } } Traverse.Create(root: p).Field(name: "comps").SetValue(comps); } }
// Verse.ThingWithComps public static void InitializeWWComps(ThingWithComps __instance) { if (__instance.def.IsRangedWeapon) { var comps = (List <ThingComp>)AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(__instance); ThingComp thingComp = (ThingComp)Activator.CreateInstance(typeof(CompSilverTreated)); thingComp.parent = __instance; comps.Add(thingComp); thingComp.Initialize(null); } }
public void InitializePawnComps(Pawn parent) { // Log.Message("Initializng Pawn Comps"); // Log.Message(parent.ToString()); for (int i = 0; i < this.def.comps.Count; i++) { ThingComp thingComp = (ThingComp)Activator.CreateInstance(this.def.comps[i].compClass); // if (thingComp == null) Log.Message("NoTHingComp"); thingComp.parent = parent; // if (this.comps == null) Log.Message("NoCompslist"); thingComp.Initialize(this.def.comps[i]); this.comps.Add(thingComp); } }
public static void MakeThingPostfix(ref Thing __result, ref ThingDef stuff) { if (stuff != null && __result is ThingWithComps twc) { CompsToAddWhenStuff ext = stuff.GetModExtension <CompsToAddWhenStuff>(); if (ext != null && ext.comps != null && ext.comps.Count > 0) { for (int i = 0; i < ext.comps.Count; i++) { ThingComp comp = (ThingComp)Activator.CreateInstance(ext.comps[i].compClass); comp.parent = twc; twc.AllComps.Add(comp); comp.Initialize(ext.comps[i]); } } } }
public static void ForceAddComp(this ThingWithComps thing, ThingComp comp, CompProperties prop) { var field = typeof(ThingWithComps).GetField("comps", BindingFlags.NonPublic | BindingFlags.Instance); List <ThingComp> list = field.GetValue(thing) as List <ThingComp>; list.Add(comp); field.SetValue(thing, list); comp.parent = thing; //Need to manually resolve references (Any better solution here???) if (prop is CompProperties_Refuelable f**k) { var filter = f**k.fuelFilter; filter.ResolveReferences(); } comp.Initialize(prop); }
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); }
public static void InitializeComps_PostFix(ThingWithComps __instance) { //Log.Message("1"); if (__instance != null) { Pawn p = __instance as Pawn; if (p != null) { if (p.RaceProps != null && p.RaceProps.Humanlike) { ThingComp thingComp = (ThingComp)Activator.CreateInstance(typeof(CompForceUser)); thingComp.parent = __instance; var comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(__instance); if (comps != null) { ((List <ThingComp>)comps).Add(thingComp); } thingComp.Initialize(null); } } } }
public static void InitializeComps_PostFix(ThingWithComps __instance) { if (!(__instance is Pawn p)) { return; } if (p.RaceProps == null || (!p.RaceProps.Animal)) { return; } ThingComp thingComp = (ThingComp)Activator.CreateInstance(typeof(CompTransmogrified)); thingComp.parent = __instance; var comps = AccessTools.Field(typeof(ThingWithComps), "comps").GetValue(__instance); if (comps != null) { ((List <ThingComp>)comps).Add(thingComp); } thingComp.Initialize(null); }
public void FixedUpdate() { try { if (Find.TickManager != null) { if (Find.TickManager.TicksGame > lastTicks + 200) { lastTicks = Find.TickManager.TicksGame; reinjectTime -= Time.fixedDeltaTime; if (reinjectTime <= 0) { reinjectTime = 0; if (Find.Maps != null) { Find.Maps.ForEach(delegate(Map map) { List <Pawn> pawns = map.mapPawns.AllPawnsSpawned.Where((Pawn p) => p.story != null).ToList(); pawns.Where((Pawn p) => p.Name != null && p.TryGetComp <CompForceUser>() == null && (p.story.traits.HasTrait(ProjectJediDefOf.PJ_JediTrait) || p.story.traits.HasTrait(ProjectJediDefOf.PJ_SithTrait))).ToList().ForEach( delegate(Pawn p) { Log.Message("CompForceUser Added"); //CompForceUser pca = new CompForceUser(); ThingComp pca = (ThingComp)Activator.CreateInstance(typeof(CompForceUser)); pca.parent = p; p.AllComps.Add(pca); pca.Initialize(null); }); }); } } } } } catch (Exception) { } }
private ThingComp CurrentShow() { int cur = _show; _show = _showWorker.GetShow(); if (cur == _show && _child != null && _childProp != null) { return(_child); } _childProp = _props?.shows[_show]; if (_childProp == null) { Log.ErrorOnce("No show", 1700709); return(null); } _child = (ThingComp)Activator.CreateInstance(_childProp.compClass); if (_child is CompAnimatedOver over) { over.xOffset = TVProps.xOffset; over.yOffset = TVProps.yOffset; over.xScale = TVProps.xScale; over.yScale = TVProps.yScale; } _child.parent = parent; _child.Initialize(_childProp); #if DEBUG Log.Message("Show Changed to : " + _show + " > " + _child); #endif return(_child); }