protected override ThoughtState CurrentStateInternal(Pawn p) { SkillDef active = InterestBase.GetActiveSkill(p); if (active == null) { return(ThoughtState.Inactive); } SkillRecord skill = p.skills.GetSkill(active); if (skill == null) { return(ThoughtState.Inactive); } int passion = (int)skill.passion; // these could return -1 but passion won't be -1 var minorAversion = InterestBase.interestList["DMinorAversion"]; if (passion == minorAversion) { return(ThoughtState.ActiveAtStage(0)); } var majorAversion = InterestBase.interestList["DMajorAversion"]; if (passion == majorAversion) { return(ThoughtState.ActiveAtStage(1)); } return(ThoughtState.Inactive); }
public override void HandleTick(SkillRecord sk, Pawn pawn) { SkillDef sd = InterestBase.GetActiveSkill(pawn); if (sd == null) { return; } SkillRecord skill = pawn.skills.GetSkill(sd); if (skill != sk) { return; } Need_Rest restNeed = pawn.needs.TryGetNeed(NeedDefOf.Rest) as Need_Rest; if (restNeed == null) { Log.Error("Got null rest need, wat"); return; } // Rest fall per 150 ticks is 150f*1.58333332E-05f * RestFallFactor * (modifier based on tiredness level); // Perfect equilibrium is 200f* 1.58333332E-05f RestCategory rc = restNeed.CurCategory; float factor; switch (rc) { case RestCategory.Rested: factor = 1.0f; break; case RestCategory.Tired: factor = 0.7f; break; case RestCategory.VeryTired: factor = 0.3f; break; case RestCategory.Exhausted: factor = 0.6f; break; default: factor = 999f; break; } float restGain = (200f / 2.0f) * 1.58333332E-05f * factor; restNeed.CurLevel += restGain; }
public override void MapComponentTick() { // get interests that give joy, or return if none if (InterestBase.interestList.mapwideWorkers.Count == 0) { return; } updateTicks++; if (updateTicks % 200 != 0) { return; } updateTicks = 0; // find all skills for which a colonist with a skillaffector exists List <Pawn> colonists = map.mapPawns.FreeColonistsSpawned; skillsAffected.Clear(); List <int> passions = InterestBase.interestList.mapwideWorkers.Keys.ToList(); skillsAffected = colonists.SelectMany(x => x.skills.skills, (colonist, skillrecord) => new KeyValuePair <SkillRecord, Pawn>(skillrecord, colonist)).ToDictionary(x => x.Key, x => x.Value); //skillsAffected = colonists.SelectMany(c => c.skills.skills).Where(s => passions.Contains((int)s.passion)).ToList(); // go through every colonist, see if they're working on the affected skill, and affect them foreach (Pawn colonist in colonists) { SkillDef active = InterestBase.GetActiveSkill(colonist); if (active == null) { continue; } //IEnumerable<SkillRecord> activeInterests = skillsAffected.Where(s => s.def == active); IEnumerable <KeyValuePair <SkillRecord, Pawn> > activeInterests = skillsAffected.Where(s => s.Key.def == active); foreach (var skill in activeInterests ?? Enumerable.Empty <KeyValuePair <SkillRecord, Pawn> > ()) { InterestBase.UpdateMapwideEffect(colonist, (int)skill.Key.passion, skill.Value); } } }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { if (!pawn.IsColonist) { return; } var active = InterestBase.GetActiveSkill(pawn); if (active == null) { DecreaseAllergy(pawn); return; } SkillRecord skill = pawn.skills.GetSkill(active); if (skill == null) { return; } int passion = (int)skill.passion; int allergic = InterestBase.interestList["DAllergic"]; HediffSet hediffSet = pawn.health.hediffSet; Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(this.hediff, false); if (passion != allergic && firstHediffOfDef != null) // pawn's active skill isn't causing an allergy, but they have the allergic hediff { DecreaseAllergy(pawn); //firstHediffOfDef.Severity -= gainRate; } else if (passion == allergic) // pawn's active skill is allergy causing { IncreaseAllergy(pawn); } base.OnIntervalPassed(pawn, cause); }