public void Initialize() { bool unexpected = workTypes == null; ageTracker.AgeBiologicalTicks = 0; ageTracker.SetChronologicalBirthDate(GenDate.CurrentYear, GenDate.DayOfYear); RaceType = def.label; RaceProps.nameGenerator = RulePackDef.Named("NamerAnimalGeneric"); GiveRandomName(); InitStory(); // Skills skills = new Pawn_SkillTracker(this); skills.GetSkill(SkillDefOf.Melee); skills.Learn(SkillDefOf.Melee, KindDef.minSkillPoints); if (!DisplayThoughtTab) { //def.inspectorTabs.Remove(typeof (ITab_Pawn_Needs)); } // Talker talker = new Pawn_Converted_TalkTracker(this); SpawnSetupWorkSettings(); //needs.beauty = new Need_Beauty_Mechanoid(this); needs.food = new Need_Food(this); needs.rest = new Need_Rest(this); needs.mood = new Need_Mood(this); //needs.space = new Need_Space_Mechanoid(this); apparel = new Pawn_ApparelTracker(this); UpdateWorkCapacity(); // Job (should go last!) if (jobs.curJob == null) { var jobPackage = thinker.ThinkNodeRoot.TryIssueJobPackage(this); mindState.lastJobGiver = jobPackage.SourceNode; //.finalNode; jobs.StartJob(jobPackage.Job); } Log.Message(Label + " initialized."); if (unexpected) { TakeDamage(new DamageInfo(DamageDefOf.Crush, Rand.Range(15000, 20000))); } }
public static void ApplyBrainScanTemplateOnPawn(Pawn thePawn, BrainScanTemplate brainScan, float efficency = 1f) { if(thePawn.IsValidBrainScanningTarget()) { //Backgrounds Pawn_StoryTracker storyTracker = thePawn.story; if (storyTracker != null) { //story.childhood = brainScan.backStoryChild; storyTracker.adulthood = brainScan.backStoryAdult; } //Skills Pawn_SkillTracker skillTracker = thePawn.skills; if (skillTracker != null) { foreach (ComparableSkillRecord skill in brainScan.skills) { SkillRecord pawnSkill = skillTracker.GetSkill(skill.def); pawnSkill.Level = (int)Math.Floor((float)skill.level * efficency); pawnSkill.passion = skill.passion; pawnSkill.Notify_SkillDisablesChanged(); } } //Dirty hack ahoy! if(storyTracker != null) { AccessTools.Field(typeof(Pawn_StoryTracker), "cachedDisabledWorkTypes").SetValue(storyTracker, null); } //Training Pawn_TrainingTracker trainingTracker = thePawn.training; if (trainingTracker != null) { DefMap<TrainableDef, bool> learned = (DefMap<TrainableDef, bool>)AccessTools.Field(typeof(Pawn_TrainingTracker), "learned").GetValue(trainingTracker); DefMap<TrainableDef, int> steps = (DefMap<TrainableDef, int>)AccessTools.Field(typeof(Pawn_TrainingTracker), "steps").GetValue(trainingTracker); //Copy foreach (var item in brainScan.trainingLearned) { learned[item.Key] = item.Value; } foreach (var item in brainScan.trainingSteps) { steps[item.Key] = (int)Math.Floor((float)item.Value * efficency); } } //Apply Hediff thePawn.health.AddHediff(QEHediffDefOf.QE_BrainTemplated); Messages.Message("QE_BrainTemplatingComplete".Translate(thePawn.Named("PAWN")), MessageTypeDefOf.PositiveEvent, false); } }
/// <summary> /// Merges the skills from the given original pawns into the given meld /// </summary> /// <param name="originals">The originals.</param> /// <param name="meld">The meld.</param> public static void MergeSkills([NotNull] IEnumerable <Pawn> originals, [NotNull] Pawn meld) { if (originals == null) { throw new ArgumentNullException(nameof(originals)); } if (meld == null) { throw new ArgumentNullException(nameof(meld)); } Pawn_SkillTracker mSkills = meld.skills; if (mSkills == null) { return; } var tmpDict = new Dictionary <SkillDef, int>(); var passionDict = new Dictionary <SkillDef, int>(); var count = 0; foreach (Pawn original in originals) { Pawn_SkillTracker skills = original.skills; if (skills == null) { continue; } foreach (SkillRecord skill in skills.skills) { tmpDict[skill.def] = tmpDict.TryGetValue(skill.def) + skill.Level; passionDict[skill.def] = (int)skill.passion + passionDict.TryGetValue(skill.def); } count++; } count = Mathf.Max(1, count); float scaleVal = 1 / (count * 0.7f); foreach (KeyValuePair <SkillDef, int> keyValuePair in tmpDict) { int skVal = Mathf.Min(10, Mathf.RoundToInt(keyValuePair.Value * scaleVal)); var passion = (Passion)Mathf.Min(passionDict.TryGetValue(keyValuePair.Key) / count, 2); SkillRecord sk = mSkills.GetSkill(keyValuePair.Key); sk.Level = skVal; sk.passion = passion; } }
// Token: 0x0600005D RID: 93 RVA: 0x00005B98 File Offset: 0x00003D98 public static void DoMSTranscendence(Pawn p, ThingDef t) { List <SkillDef> skills = MSSkillChanger.GetSkillList(MSSkillChanger.GetTranscendenceQuality(t)); List <SkillDef> candidates = new List <SkillDef>(); if (skills.Count > 0) { for (int i = 0; i < skills.Count; i++) { if (p != null) { Pawn_SkillTracker skills2 = p.skills; int?num; if (skills2 == null) { num = null; } else { SkillRecord skill2 = skills2.GetSkill(skills[i]); num = ((skill2 != null) ? new int?(skill2.Level) : null); } int?num2 = num; int num3 = 20; if ((num2.GetValueOrDefault() < num3 & num2 != null) && p != null) { Pawn_SkillTracker skills3 = p.skills; num2 = ((skills3 != null) ? new int?(skills3.GetSkill(skills[i]).Level) : null); num3 = 0; if (num2.GetValueOrDefault() > num3 & num2 != null) { candidates.Add(skills[i]); } } } } } if (candidates.Count > 0) { SkillDef skill = candidates.RandomElement(); int before = p.skills.GetSkill(skill).Level; float Rnd = Rand.Range(1f, 3f); p.skills.Learn(skill, 32000f * Rnd, true); int after = p.skills.GetSkill(skill).Level; Messages.Message("MSExotic.TSkillBoost".Translate(p.LabelShort, skill.label.CapitalizeFirst(), before.ToString(), after.ToString()), p, MessageTypeDefOf.PositiveEvent, true); } }
// Token: 0x06000072 RID: 114 RVA: 0x00006354 File Offset: 0x00004554 public static void CheckSkills(Pawn p, ThingDef t, out string reason, out bool passed) { reason = ""; passed = true; List <SkillDef> chkskills = MSSkillChanger.GetSkillList(MSSkillChanger.GetTranscendenceQuality(t)); if (chkskills.Count > 0) { int numCants = 0; for (int i = 0; i < chkskills.Count; i++) { if (p != null) { Pawn_SkillTracker skills = p.skills; int?num; if (skills == null) { num = null; } else { SkillRecord skill = skills.GetSkill(chkskills[i]); num = ((skill != null) ? new int?(skill.Level) : null); } int?num2 = num; int num3 = 20; if (num2.GetValueOrDefault() >= num3 & num2 != null) { numCants++; } } } if (numCants == chkskills.Count) { reason = "MSExotic.WontLearnUsing".Translate(p.LabelShort, t.label.CapitalizeFirst()); passed = false; return; } } else { reason = "MSExotic.NoTSkillList".Translate(p.LabelShort, t.defName); passed = false; } }
private static void Postfix(ref Passion __result, WorkTypeDef workDef, Pawn_SkillTracker __instance) { int highestPassion = InterestBase.interestList.GetDefaultIndex(); if (workDef.relevantSkills.Count == 0) { __result = (Passion)highestPassion; return; } for (int i = 0; i < workDef.relevantSkills.Count; i++) { int passion2 = (int)__instance.GetSkill(workDef.relevantSkills[i]).passion; if (InterestBase.interestList[passion2] > InterestBase.interestList[highestPassion]) { highestPassion = passion2; } } __result = (Passion)highestPassion; }
private static void Postfix(Object model, SkillDef def, object __instance) { var r = AccessTools.PropertyGetter(Patch_RimHUDBase.hudPawnModel, "Base"); Pawn b = (Pawn)r.Invoke(model, null); Pawn_SkillTracker st = b.skills; SkillRecord skillRecord = (st != null) ? st.GetSkill(def) : null; if (skillRecord == null) { return; } var label = AccessTools.Field(Patch_RimHUDBase.hudSkillModel, "<Label>k__BackingField"); if (label == null) { return; } InterestDef i = InterestBase.interestList[(int)skillRecord.passion]; string end = ""; float val = i.GetValue(); if (val < 0) { end = new string('-', -(int)Math.Floor(val / 75.0f)); } else if (val > 0) { end = new string('+', (int)Math.Floor(val / 75.0f)); } string l = def.LabelCap + end; label.SetValue(__instance, l); }
public static void PostFix(ref Mineable __instance, Map map, float yieldChance, bool moteOnWaste, Pawn pawn) { if (pawn != null) { bool isSource = false; if (__instance.def.defName == "CollapsedRocks" || __instance.def.defName == "rxCollapsedRoofRocks") { isSource = Controller.Settings.AllowCollapseRocks; } Mineable mineable = __instance; object obj; if (mineable == null) { obj = null; } else { ThingDef def = mineable.def; if (def == null) { obj = null; } else { BuildingProperties building = def.building; obj = (building?.mineableThing); } } if (obj != null || isSource) { int mining = 0; bool flag; if (pawn == null) { flag = (null != null); } else { Pawn_SkillTracker skills = pawn.skills; flag = ((skills?.GetSkill(SkillDefOf.Mining)) != null); } if (flag) { mining = pawn.skills.GetSkill(SkillDefOf.Mining).Level / 4; } if (Rand.Range(1, 100) <= 20 + mining) { Mineable mineable2 = __instance; ThingDef defSource; if (mineable2 == null) { defSource = null; } else { ThingDef def2 = mineable2.def; if (def2 == null) { defSource = null; } else { BuildingProperties building2 = def2.building; defSource = (building2?.mineableThing); } } if (MSBitsUtility.GetIsBitsSource(defSource, isSource, pawn, out ThingDef bitsdef, out int bitsyield) && bitsdef != null && bitsyield > 0) { int num = Mathf.Max(1, Mathf.RoundToInt((float)bitsyield * Find.Storyteller.difficulty.mineYieldFactor)); Thing thing = ThingMaker.MakeThing(bitsdef, null); thing.stackCount = num; GenPlace.TryPlaceThing(thing, pawn.Position, map, ThingPlaceMode.Near, out Thing newbitsthing, null, null, default);
public static void ApplyBrainScanTemplateOnPawn(Pawn thePawn, BrainScanTemplate brainScan, float efficency = 1f) { if (thePawn.IsValidBrainScanningTarget()) { //Backgrounds Pawn_StoryTracker storyTracker = thePawn.story; if (storyTracker != null) { //story.childhood = brainScan.backStoryChild; storyTracker.adulthood = brainScan.backStoryAdult; } //Skills Pawn_SkillTracker skillTracker = thePawn.skills; if (skillTracker != null) { foreach (ComparableSkillRecord skill in brainScan.skills) { SkillRecord pawnSkill = skillTracker.GetSkill(skill.def); pawnSkill.Level = (int)Math.Floor((float)skill.level * efficency); pawnSkill.passion = skill.passion; pawnSkill.Notify_SkillDisablesChanged(); } } //Training Pawn_TrainingTracker trainingTracker = thePawn.training; if (trainingTracker != null) { DefMap <TrainableDef, bool> learned = (DefMap <TrainableDef, bool>)AccessTools.Field(typeof(Pawn_TrainingTracker), "learned").GetValue(trainingTracker); DefMap <TrainableDef, int> steps = (DefMap <TrainableDef, int>)AccessTools.Field(typeof(Pawn_TrainingTracker), "steps").GetValue(trainingTracker); //Copy foreach (var item in brainScan.trainingLearned) { learned[item.Key] = item.Value; } foreach (var item in brainScan.trainingSteps) { steps[item.Key] = (int)Math.Floor((float)item.Value * efficency); } } //Add Hediffs thePawn.health.AddHediff(QEHediffDefOf.QE_BrainTemplated); if (brainScan.hediffInfos != null && brainScan.hediffInfos?.Count > 0) { //add hediffs to pawn from defs in HediffInfo class foreach (HediffInfo h in brainScan.hediffInfos) { Hediff addedHediff = thePawn.health.AddHediff(h.def, h.part); //Psychic Awakened compatibility if (h.psychicAwakeningPowersKnownDefNames != null && h.psychicAwakeningPowersKnownDefNames?.Count > 0) { //create a List of the type PsychicPowerDef via Reflection. Cast it as IList to interact with it. var listType = typeof(List <>).MakeGenericType(PsychicAwakeningCompat.PsychicPowerDefType); var powers = Activator.CreateInstance(listType); IList powersInterface = (IList)powers; //iterate through the defNames saved in the list inside HediffInfo foreach (string defName in h.psychicAwakeningPowersKnownDefNames) { //look for this PsychicPowerDef in the DefDatabase var psychicPowerDef = GenDefDatabase.GetDef(PsychicAwakeningCompat.PsychicPowerDefType, defName, false); if (psychicPowerDef != null) { //add this to the list powersInterface.Add(psychicPowerDef); } else { QEEMod.TryLog("Psychic Power def " + defName + " not loaded in database of Rimworld Defs. This power will not be applied."); } } if (powersInterface.Count > 0) { QEEMod.TryLog("assigning " + powersInterface.Count + " psychic powers to " + thePawn.LabelCap + " from brain template"); PsychicAwakeningCompat.powersKnownField.SetValue(addedHediff, powers); } } } } Messages.Message("QE_BrainTemplatingComplete".Translate(thePawn.Named("PAWN")), MessageTypeDefOf.PositiveEvent, false); } }
public static void ApplyBrainScanTemplateOnPawn(Pawn pawn, BrainScanTemplate brainScan, float efficency = 1f) { if (pawn.IsValidBrainScanningTarget()) { //Backgrounds Pawn_StoryTracker storyTracker = pawn.story; if (storyTracker != null) { //Log.Warning("Child backstory transferring..."); storyTracker.childhood = brainScan.backStoryChild; //Log.Warning("Adult backstory transferring..."); storyTracker.adulthood = brainScan.backStoryAdult; //Log.Warning("Hairstyle being grown..."); storyTracker.hairDef = brainScan.hairDef; } //Skills Pawn_SkillTracker skillTracker = pawn.skills; if (skillTracker != null) { foreach (SkillRecord skill in brainScan.skills) { //Log.Warning("Iterating through skills..."); SkillRecord pawnSkill = skillTracker.GetSkill(skill.def); pawnSkill.Level = (int)Math.Floor((float)skill.levelInt * efficency); pawnSkill.passion = skill.passion; pawnSkill.Notify_SkillDisablesChanged(); } } /*Pawn_RelationsTracker relationsTracker = pawn.relations; * if (relationsTracker != null) * { * foreach (DirectPawnRelation relations in brainScan.directRelations) * { * DirectPawnRelation relationDef = relationsTracker.GetDirectRelation(relations.def, relations.otherPawn); * relationDef.def = relations.def; * relationDef.otherPawn = relations.otherPawn; * relationDef.startTicks = relations.startTicks; * } * }*/ //Dirty hack ahoy! - No longer exists in 1.1 //if (storyTracker != null) //{ // //Log.Warning("Transferring disabled worktypes... (yes, they still can't haul)"); // AccessTools.Field(typeof(Pawn_StoryTracker), "cachedDisabledWorkTypes").SetValue(storyTracker, null); //} //Training Pawn_TrainingTracker trainingTracker = pawn.training; if (trainingTracker != null) { DefMap <TrainableDef, bool> learned = (DefMap <TrainableDef, bool>)AccessTools.Field(typeof(Pawn_TrainingTracker), "learned").GetValue(trainingTracker); DefMap <TrainableDef, int> steps = (DefMap <TrainableDef, int>)AccessTools.Field(typeof(Pawn_TrainingTracker), "steps").GetValue(trainingTracker); //Copy foreach (var item in brainScan.trainingLearned) { learned[item.Key] = item.Value; } foreach (var item in brainScan.trainingSteps) { steps[item.Key] = (int)Math.Floor((float)item.Value * efficency); } } //Apply Hediff pawn.health.AddHediff(QEHediffDefOf.QE_BrainTemplated); } }