public void EnableAndInitialize() { if (priorities == null) { priorities = new DefMap <WorkTypeDef, int>(); } priorities.SetAll(0); int num = 0; foreach (WorkTypeDef item in from w in DefDatabase <WorkTypeDef> .AllDefs where !w.alwaysStartActive && !pawn.story.WorkTypeIsDisabled(w) orderby pawn.skills.AverageOfRelevantSkillsFor(w) descending select w) { SetPriority(item, 3); num++; if (num >= 6) { break; } } foreach (WorkTypeDef item2 in from w in DefDatabase <WorkTypeDef> .AllDefs where w.alwaysStartActive select w) { if (!pawn.story.WorkTypeIsDisabled(item2)) { SetPriority(item2, 3); } } foreach (WorkTypeDef disabledWorkType in pawn.story.DisabledWorkTypes) { Disable(disabledWorkType); } }
public void EnableAndInitialize() { if (priorities == null) { priorities = new DefMap <WorkTypeDef, int>(); } priorities.SetAll(0); int num = 0; foreach (WorkTypeDef item in from w in DefDatabase <WorkTypeDef> .AllDefs where !w.alwaysStartActive && !pawn.WorkTypeIsDisabled(w) orderby pawn.skills.AverageOfRelevantSkillsFor(w) descending select w) { SetPriority(item, 3); num++; if (num >= 6) { break; } } foreach (WorkTypeDef item2 in DefDatabase <WorkTypeDef> .AllDefs.Where((WorkTypeDef w) => w.alwaysStartActive)) { if (!pawn.WorkTypeIsDisabled(item2)) { SetPriority(item2, 3); } } List <WorkTypeDef> disabledWorkTypes = pawn.GetDisabledWorkTypes(); for (int i = 0; i < disabledWorkTypes.Count; i++) { Disable(disabledWorkTypes[i]); } }
public override void SpawnMyPawn() { base.SpawnMyPawn(); if (myPawn.story == null) { myPawn.story = new Pawn_StoryTracker(myPawn); } if (myPawn.skills == null) { myPawn.skills = new Pawn_SkillTracker(myPawn); } if (myPawn.workSettings == null) { myPawn.workSettings = new Pawn_WorkSettings(myPawn); } if (myPawn.relations == null) { myPawn.relations = new Pawn_RelationsTracker(myPawn); } DefMap <WorkTypeDef, int> priorities = new DefMap <WorkTypeDef, int>(); priorities.SetAll(0); typeof(Pawn_WorkSettings).GetField("priorities", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(myPawn.workSettings, priorities); foreach (WorkTypeDef workType in Props.allowedWorkTypes) { foreach (SkillDef skill in workType.relevantSkills) { SkillRecord record = myPawn.skills.skills.Find(rec => rec.def == skill); record.levelInt = Props.skillLevel; } myPawn.workSettings.SetPriority(workType, 1); } if (myPawn.TryGetComp <CompMachine>().Props.violent) { if (myPawn.drafter == null) { myPawn.drafter = new Pawn_DraftController(myPawn); } if (Props.spawnWithWeapon != null) { ThingWithComps thing = (ThingWithComps)ThingMaker.MakeThing(Props.spawnWithWeapon); myPawn.equipment.AddEquipment(thing); } } if (myPawn.needs.TryGetNeed <Need_Power>() == null) { typeof(Pawn_NeedsTracker).GetMethod("AddNeed", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(myPawn.needs, new object[] { DefDatabase <NeedDef> .GetNamed("VFE_Mechanoids_Power") }); } myPawn.needs.TryGetNeed <Need_Power>().CurLevel = 0; if (myPawn.playerSettings != null) { myPawn.playerSettings.AreaRestriction = allowedArea; } wantsRespawn = false; }
protected override void ResolveSubnodes() { dutyDefToSubNode = new DefMap <DutyDef, int>(); dutyDefToSubNode.SetAll(-1); foreach (DutyDef allDef in DefDatabase <DutyDef> .AllDefs) { if (allDef.constantThinkNode != null) { dutyDefToSubNode[allDef] = subNodes.Count; allDef.constantThinkNode.ResolveSubnodesAndRecur(); subNodes.Add(allDef.constantThinkNode.DeepCopy()); } } }
public static Pawn PolymorphPawn(Pawn caster, Pawn original, Pawn polymorphFactionPawn, SpawnThings spawnables, IntVec3 position, bool temporary, int duration, Faction fac = null) { Pawn polymorphPawn = null; bool flag = spawnables.def != null; if (flag) { Faction faction = TM_Action.ResolveFaction(polymorphFactionPawn, spawnables, fac); bool flag2 = spawnables.def.race != null; if (flag2) { bool flag3 = spawnables.kindDef == null; if (flag3) { Log.Error("Missing kinddef"); } else { try { if (ModCheck.Validate.GiddyUp.Core_IsInitialized()) { ModCheck.GiddyUp.ForceDismount(original); } } catch { } Pawn newPawn = new Pawn(); newPawn = (Pawn)PawnGenerator.GeneratePawn(spawnables.kindDef, faction); newPawn.AllComps.Add(new CompPolymorph()); CompPolymorph compPoly = newPawn.GetComp <CompPolymorph>(); //CompProperties_Polymorph props = new CompProperties_Polymorph(); //compPoly.Initialize(props); if (compPoly != null) { compPoly.ParentPawn = newPawn; compPoly.Spawner = caster; compPoly.Temporary = temporary; compPoly.TicksToDestroy = duration; compPoly.Original = original; } else { Log.Message("CompPolymorph was null."); } try { GenSpawn.Spawn(newPawn, position, original.Map); polymorphPawn = newPawn; polymorphPawn.drafter = new Pawn_DraftController(polymorphPawn); polymorphPawn.equipment = new Pawn_EquipmentTracker(polymorphPawn); polymorphPawn.story = new Pawn_StoryTracker(polymorphPawn); if (original.workSettings != null) { polymorphPawn.workSettings = new Pawn_WorkSettings(polymorphPawn); DefMap <WorkTypeDef, int> priorities = Traverse.Create(root: original.workSettings).Field(name: "priorities").GetValue <DefMap <WorkTypeDef, int> >(); priorities = new DefMap <WorkTypeDef, int>(); priorities.SetAll(0); Traverse.Create(root: polymorphPawn.workSettings).Field(name: "priorities").SetValue(priorities); } //polymorphPawn.apparel = new Pawn_ApparelTracker(polymorphPawn); //polymorphPawn.mindState = new Pawn_MindState(polymorphPawn); //polymorphPawn.thinker = new Pawn_Thinker(polymorphPawn); //polymorphPawn.jobs = new Pawn_JobTracker(polymorphPawn); //polymorphPawn.records = new Pawn_RecordsTracker(polymorphPawn); //polymorphPawn.skills = new Pawn_SkillTracker(polymorphPawn); //PawnComponentsUtility.AddAndRemoveDynamicComponents(polymorphPawn, true); polymorphPawn.Name = original.Name; polymorphPawn.gender = original.gender; if (original.health.hediffSet.HasHediff(HediffDef.Named("TM_SoulBondPhysicalHD")) || original.health.hediffSet.HasHediff(HediffDef.Named("TM_SoulBondMentalHD"))) { TM_Action.TransferSoulBond(original, polymorphPawn); } } catch (NullReferenceException ex) { Log.Message("TM_Exception".Translate( caster.LabelShort, ex.ToString() )); polymorphPawn = null; } if (polymorphPawn != null && newPawn.Faction != null && newPawn.Faction != Faction.OfPlayer) { Lord lord = null; if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn)) { Predicate <Thing> validator = (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null; Pawn p2 = (Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, validator, null); lord = p2.GetLord(); } bool flag4 = lord == null; if (flag4) { LordJob_DefendPoint lordJob = new LordJob_DefendPoint(newPawn.Position); lord = LordMaker.MakeNewLord(faction, lordJob, original.Map, null); } try { lord.AddPawn(newPawn); } catch (NullReferenceException ex) { if (lord != null) { LordJob_AssaultColony lordJob = new LordJob_AssaultColony(faction, false, false, false, false); lord = LordMaker.MakeNewLord(faction, lordJob, original.Map, null); } } } } } else { Log.Message("Missing race"); } } return(polymorphPawn); }