Esempio n. 1
0
 public PawnSkills(Pawn_SkillTracker pawnskills, Settings settings)
 {
     foreach (SkillRecord sr in pawnskills.skills)
     {
         skills.Add(new SkillData(sr, settings));
     }
 }
Esempio n. 2
0
        // Token: 0x06000005 RID: 5 RVA: 0x000020B4 File Offset: 0x000002B4
        public override void PawnDied(Corpse corpse)
        {
            float value  = (float)corpse.InnerPawn.ageTracker.AgeBiologicalYears;
            float value2 = (float)corpse.InnerPawn.ageTracker.AgeChronologicalYears;
            Name  name   = corpse.InnerPawn.Name;
            Pawn_PlayerSettings   playerSettings = corpse.InnerPawn.playerSettings;
            Pawn_TrainingTracker  training       = corpse.InnerPawn.training;
            Pawn_HealthTracker    health         = corpse.InnerPawn.health;
            Pawn_RecordsTracker   records        = corpse.InnerPawn.records;
            Pawn_RelationsTracker relations      = corpse.InnerPawn.relations;
            Pawn_SkillTracker     skills         = corpse.InnerPawn.skills;
            Faction       faction  = corpse.InnerPawn.Faction;
            Comp_TimeLord timeLord = corpse.InnerPawn.TryGetComp <Comp_TimeLord>();

            if (timeLord != null)
            {
                if (timeLord.TimesRegenerated < 13)
                {
                    int regens = timeLord.TimesRegenerated;
                    regens++;
                    Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(corpse.InnerPawn.kindDef, faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 0f, false, false, false, false, false, false, false, false, 0, null, 1, null, null, null));
                    pawn.TryGetComp <Comp_TimeLord>().TimesRegenerated = regens;
                    GenSpawn.Spawn(pawn, corpse.Position, corpse.Map, Rot4.Random);
                    pawn.Name           = name;
                    pawn.relations      = relations;
                    pawn.training       = training;
                    pawn.records        = records;
                    pawn.skills         = skills;
                    pawn.playerSettings = playerSettings;
                    corpse.Destroy(0);
                }
            }
        }
Esempio n. 3
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            //Kill all invalid spawns
            if (this.station == null)
            {
                this.Kill(null);
                return;
            }

            base.SpawnSetup(map, respawningAfterLoad);
            skills        = new Pawn_SkillTracker(this);
            skillSettings = station.def.GetModExtension <ModExtension_Skills>();
            station.GetDroneSkillsRecord = DroneSkills.UpdateSkills(skills, station.GetDroneSkillsRecord, skillSettings, true);

            story = new Pawn_StoryTracker(this)
            {
                bodyType  = BodyTypeDefOf.Thin,
                crownType = CrownType.Average,
                childhood = DroneBackstories.childhood,
                adulthood = DroneBackstories.adulthood
            };
            drafter   = new Pawn_DraftController(this);
            relations = new Pawn_RelationsTracker(this);
            Name      = new NameSingle("PRFDroneName".Translate());

            //Set the AreaRestriction. null means Unrestricted
            playerSettings.AreaRestriction = this.station.droneAllowedArea;
        }
Esempio n. 4
0
 static bool Prefix(Pawn_SkillTracker __instance, ref Pawn ___pawn)
 {
     if (___pawn.IsHacked())
     {
         return(false);
     }
     return(true);
 }
Esempio n. 5
0
 public static void GetSkill_Postfix(ref SkillRecord __result, Pawn_SkillTracker __instance, SkillDef skillDef, Pawn ___pawn)
 {
     if (___pawn.story.traits.HasTrait(SyrTraitDefOf.SYR_GreenThumb) && WorkGiver_GrowerSowPatch.greenThumb)
     {
         SkillRecord fakeRecord = new SkillRecord(___pawn, SkillDefOf.Plants);
         fakeRecord.Level = 20;
         __result         = fakeRecord;
     }
 }
        public static Thing MakeBrainScan(Pawn pawn, ThingDef genomeDef)
        {
            Thing             brainScanThing = ThingMaker.MakeThing(genomeDef);
            BrainScanTemplate brainScan      = brainScanThing as BrainScanTemplate;

            if (brainScan != null)
            {
                //Standard.
                brainScan.sourceName = pawn?.Name?.ToStringFull ?? null;

                //Backgrounds
                Pawn_StoryTracker story = pawn.story;
                if (story != null)
                {
                    brainScan.backStoryChild = story.childhood;
                    brainScan.backStoryAdult = story.adulthood;
                }

                //Skills
                Pawn_SkillTracker skillTracker = pawn.skills;
                if (skillTracker != null)
                {
                    foreach (SkillRecord skill in skillTracker.skills)
                    {
                        brainScan.skills.Add(new SkillRecord()
                        {
                            def     = skill.def,
                            Level   = skill.Level,
                            passion = skill.passion
                        });
                    }
                }

                //Animal
                brainScan.isAnimal = pawn.RaceProps.Animal;

                //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 learned)
                    {
                        brainScan.trainingLearned[item.Key] = item.Value;
                    }
                    foreach (var item in steps)
                    {
                        brainScan.trainingSteps[item.Key] = item.Value;
                    }
                }
            }

            return(brainScanThing);
        }
Esempio n. 7
0
        static bool Prefix(Pawn_SkillTracker __instance)
        {
            Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();

            if (pawn.IsHacked())
            {
                return(false);
            }
            return(true);
        }
        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);
            }
        }
Esempio n. 9
0
        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)));
            }
        }
Esempio n. 10
0
        static GenLevelingInfo()
        {
            pawn = new Pawn()
            {
                Name = new NameSingle("Levelyn")
            };
            Pawn_SkillTracker skillTracker = new Pawn_SkillTracker(pawn);

            pawn.skills          = skillTracker;
            skillRecord          = skillTracker.skills.RandomElement();
            skillRecord.levelInt = Rand.RangeInclusive(SkillRecord.MinLevel, SkillRecord.MaxLevel - 1);
        }
Esempio n. 11
0
        static SkillRecord TryGetSkill([NotNull] Pawn_SkillTracker tracker, [NotNull] SkillDef def)
        {
            foreach (SkillRecord skillRecord in tracker.skills.MakeSafe())
            {
                if (skillRecord.def == def)
                {
                    return(skillRecord);
                }
            }

            return(null);
        }
Esempio n. 12
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            Pawn_SkillTracker skills = base.Pawn.skills;

            if (skills != null)
            {
                for (int i = 0; i < skills.skills.Count; i++)
                {
                    SkillRecord skillRecord = skills.skills[i];
                    float       num         = parent.Severity * Props.decayPerDayPercentageLevelCurve.Evaluate(skillRecord.Level);
                    float       num2        = skillRecord.XpRequiredForLevelUp * num / 60000f;
                    skillRecord.Learn(0f - num2);
                }
            }
        }
Esempio n. 13
0
        /// <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;
            }
        }
Esempio n. 14
0
        public static bool Pawn_SkillTracker_SkillsTick_Prefix(Pawn ___pawn, Pawn_SkillTracker __instance, ref int ___lastXpSinceMidnightResetTimestamp)
        {
            if (___pawn.IsHashIntervalTick(200))
            {
                var raceSettings = AutomataRaceSettingCache.Get(___pawn.def);
                if (raceSettings != null)
                {
                    if (!raceSettings.skillDecayActivated)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        // 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);
            }
        }
Esempio n. 16
0
        private Pawn getTanya()
        {
            PawnGenerationRequest request = new PawnGenerationRequest(DefDatabase <PawnKindDef> .GetNamed("ra2_AlliedTanya", true), Faction.OfPlayer, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, true, 1f, false, true, true, false, false, false, false, null, null, null, null, null, Gender.Female, null, null);
            Pawn item = PawnGenerator.GeneratePawn(request);

            Pawn_StoryTracker ps   = item.story;
            HairDef           hair = DefDatabase <HairDef> .GetNamed("Curly");

            ps.childhood        = null;
            ps.adulthood        = null;
            ps.traits.allTraits = new List <Trait>();
            ps.traits.GainTrait(new Trait(DefDatabase <TraitDef> .GetNamed("ra2_MakeSoldier", true)));
            ps.traits.GainTrait(new Trait(TraitDefOf.Psychopath));
            Pawn_WorkSettings pws = item.workSettings;

            pws.DisableAll();

            NameTriple triple = NameTriple.FromString(item.kindDef.label);

            triple.ResolveMissingPieces("Adams".Translate());
            item.Name = triple;

            Pawn_SkillTracker skt = item.skills;

            foreach (SkillRecord sr in skt.skills)
            {
                sr.Level = 20;
            }

            item.inventory.DestroyAll();
            ps.bodyType  = BodyTypeDefOf.Female;
            ps.hairDef   = hair;
            ps.hairColor = new UnityEngine.Color(1, 0.8f, 0);

            //st.SkinColor = new UnityEngine.Color(0.98f,0.76f,0.71f);
            ps.melanin = 0f;


            Pawn_EquipmentTracker pe = item.equipment;

            pe.Remove(pe.Primary);
            pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Gun_Tanya", true)));


            //item.story = st;
            return(item);
        }
Esempio n. 17
0
        // 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;
            }
        }
Esempio n. 18
0
 public static void HandleSkillTick(Pawn_SkillTracker pst, Pawn pawn)
 {
     if (!pawn.IsColonist)
     {
         return;
     }
     if (interestList.tickHandlers.Count == 0)
     {
         return;
     }
     if (pawn.IsHashIntervalTick(200))
     {
         List <SkillRecord> handleSkills = pst.skills.Where(x => interestList.tickHandlers.ContainsKey((int)x.passion)).ToList();
         foreach (SkillRecord sr in handleSkills)
         {
             interestList[(int)sr.passion].HandleTick(sr, pawn);
         }
     }
     return;
 }
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     skills = new Pawn_SkillTracker(this);
     foreach (SkillRecord record in skills.skills)
     {
         record.levelInt = 20;
         record.passion  = Passion.None;
     }
     story = new Pawn_StoryTracker(this)
     {
         bodyType  = BodyTypeDefOf.Thin,
         crownType = CrownType.Average,
         childhood = DroneBackstories.childhood,
         adulthood = DroneBackstories.adulthood
     };
     drafter   = new Pawn_DraftController(this);
     relations = new Pawn_RelationsTracker(this);
     Name      = new NameSingle("PRFDroneName".Translate());
 }
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     skills = new Pawn_SkillTracker(this);
     foreach (SkillRecord record in skills.skills)
     {
         record.levelInt = station.ConstructSkillLevel();
         record.passion  = Passion.None;
     }
     story = new Pawn_StoryTracker(this)
     {
         bodyType  = BodyTypeDefOf.Thin,
         crownType = CrownType.Average,
         childhood = ConstructBackstories.childhood,
         adulthood = ConstructBackstories.adulthood
     };
     drafter   = new Pawn_DraftController(this);
     relations = new Pawn_RelationsTracker(this);
     Name      = new NameSingle(ConstructDefOf.CanoptekScarab.label);
 }
        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 Pawn getTanya(IncidentParms parms)
        {
            PawnGenerationRequest request = new PawnGenerationRequest(DefDatabase <PawnKindDef> .GetNamed("ra2_AlliedTanya", true), parms.faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, true, 1f, false, true, true, false, false, false, false, null, null, null, null, null, Gender.Female, null, null);
            Pawn item = PawnGenerator.GeneratePawn(request);

            Pawn_StoryTracker st   = item.story;
            HairDef           hair = DefDatabase <HairDef> .GetNamed("Curly");

            Dictionary <String, Backstory> bsdb = BackstoryDatabase.allBackstories;
            Backstory child = bsdb.TryGetValue("YouthSoldier99");
            Backstory old   = bsdb.TryGetValue("VeteranSoldier2");

            st.adulthood = old;
            st.childhood = child;

            NameTriple triple = NameTriple.FromString(item.kindDef.label);

            triple.ResolveMissingPieces("Adams".Translate());
            item.Name = triple;

            Pawn_SkillTracker skt = item.skills;

            foreach (SkillRecord sr in skt.skills)
            {
                sr.Level = 20;
            }


            st.bodyType  = BodyTypeDefOf.Female;
            st.hairDef   = hair;
            st.hairColor = new UnityEngine.Color(1, 0.8f, 0);

            //st.SkinColor = new UnityEngine.Color(0.98f,0.76f,0.71f);
            st.melanin = 0f;



            //item.story = st;
            return(item);
        }
Esempio n. 23
0
        // runs every 100 ticks, postfix to stub StartInspirationMTBDays patch
        public static void HandleInspirationMTB(ref float result, InspirationHandler ih)
        {
            if (interestList.inspirers.Count == 0)
            {
                return;
            }

            if (ih.pawn.needs.mood == null)             // result = -1, no mood value yet, so return
            {
                return;
            }

            // go through each skill this pawn has, see if they have an inspiring passion
            Pawn_SkillTracker pst = ih.pawn.skills;

            if (pst == null)
            {
                return;
            }
            if (pst.skills == null)
            {
                return;
            }

            // find any inspiring interests this pawn has and get their indices
            List <int> inspiringList = pst.skills.Select(s => (int)s.passion).Where(x => interestList[x].inspires).ToList();

            if (inspiringList.Count < 1)             // no pawn skill with inspiring passion
            {
                return;
            }

            InterestDef interest = getBestInspirer(inspiringList);

            result = interest.MTBDays(ih);
        }
        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);
        }
Esempio n. 25
0
 static bool Prefix(ref Pawn_SkillTracker __instance, ref float xp)
 {
     xp *= RefcellRespeedConfig.currentTimeMultiplier;
     return(true);
 }
Esempio n. 26
0
        public static Thing MakeBrainScan(Pawn pawn, ThingDef genomeDef)
        {
            Thing             brainScanThing = ThingMaker.MakeThing(genomeDef);
            BrainScanTemplate brainScan      = brainScanThing as BrainScanTemplate;

            if (brainScan != null)
            {
                //Standard.
                brainScan.sourceName = pawn?.Name?.ToStringFull ?? null;
                brainScan.kindDef    = pawn?.kindDef ?? null;

                //Backgrounds
                Pawn_StoryTracker story = pawn.story;
                if (story != null)
                {
                    brainScan.backStoryChild = story.childhood;
                    brainScan.backStoryAdult = story.adulthood;
                }

                //Skills
                Pawn_SkillTracker skillTracker = pawn.skills;
                if (skillTracker != null)
                {
                    foreach (SkillRecord skill in skillTracker.skills)
                    {
                        brainScan.skills.Add(new ComparableSkillRecord()
                        {
                            def     = skill.def,
                            level   = skill.Level,
                            passion = skill.passion
                        });
                    }
                }

                //Animal
                brainScan.isAnimal = pawn.RaceProps.Animal;

                //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 learned)
                    {
                        brainScan.trainingLearned[item.Key] = item.Value;
                    }
                    foreach (var item in steps)
                    {
                        brainScan.trainingSteps[item.Key] = item.Value;
                    }
                }

                //Hediffs
                if (pawn?.health?.hediffSet?.hediffs != null)
                {
                    List <Hediff> pawnHediffs = pawn.health.hediffSet.hediffs;
                    if (pawnHediffs.Count > 0)
                    {
                        foreach (Hediff h in pawnHediffs)
                        {
                            if (GeneralCompatibility.includedBrainTemplateHediffs.Any(hediffDef => h.def.defName == hediffDef.defName))
                            {
                                QEEMod.TryLog("Hediff " + h.def.defName + " will be added to brain template");

                                brainScan.hediffInfos.Add(new HediffInfo(h));
                            }
                        }
                    }
                }
            }

            return(brainScanThing);
        }
 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);
        /// <summary>
        ///
        /// </summary>
        /// <param name="skill">Pawn_SkillTracker To Set</param>
        /// <param name="skillRecords">Skill Record Cache</param>
        /// <param name="modExtension_Skills">Optional ModExtension_Skills</param>
        /// <param name="forceUpdate">Enforce a reload of the Skills</param>
        /// <returns>Cache Output</returns>
        public static List <SkillRecord> UpdateSkills(Pawn_SkillTracker skill, List <SkillRecord> skillRecords, ModExtension_Skills modExtension_Skills = null, bool forceUpdate = false)
        {
            if (skillRecords.Count == 0 || forceUpdate)
            {
                foreach (SkillRecord record in skill.skills)
                {
                    if (modExtension_Skills != null)
                    {
                        //Additional Logic
                        switch (modExtension_Skills.SkillUsage)
                        {
                        case ModExtension_Skills.enum_ModExtension_SkillsskillUsage.ThisOverrides:
                        {
                            record.levelInt = modExtension_Skills.GetSkillLevel(record.def);
                            break;
                        }

                        case ModExtension_Skills.enum_ModExtension_SkillsskillUsage.ReserchIsCapping:
                        {
                            record.levelInt = Mathf.Clamp(modExtension_Skills.GetSkillLevel(record.def), 0, ReserchSkillModifier.GetResechSkillLevel());
                            break;
                        }

                        case ModExtension_Skills.enum_ModExtension_SkillsskillUsage.ThisIsCapping:
                        {
                            record.levelInt = Mathf.Clamp(ReserchSkillModifier.GetResechSkillLevel(), 0, modExtension_Skills.GetSkillLevel(record.def));
                            break;
                        }

                        case ModExtension_Skills.enum_ModExtension_SkillsskillUsage.ReserchOverrides:
                        {
                            record.levelInt = ReserchSkillModifier.GetResechSkillLevel();
                            break;
                        }

                        default:
                        {
                            record.levelInt = modExtension_Skills.GetSkillLevel(record.def);
                            break;
                        }
                        }
                    }
                    else
                    {
                        record.levelInt = ReserchSkillModifier.GetResechSkillLevel(); //No Settings Found use the Reserch Directly
                    }


                    record.passion = Passion.None;
                    if (record.xpSinceLastLevel > 1f)
                    {
                        record.xpSinceMidnight  = 100f;
                        record.xpSinceLastLevel = 100f;
                    }
                }
            }
            else
            {
                skill.skills = skillRecords;
            }

            return(skill.skills);
        }
        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);
            }
        }
 private static void Postfix(Pawn_SkillTracker __instance, Pawn ___pawn)
 {
     InterestBase.HandleSkillTick(__instance, ___pawn);
 }