public void LessonTick() { if (currentState == State.lesson) { switch (currentLessonState) { case LessonState.started: case LessonState.gathering: if (TeachingUtility.IsActorAvailable(this.teacher)) { if (this.teacher.CurJob.def.defName != "TeachLesson") { TeachingUtility.AbortLesson(this, "TeacherUnavailable".Translate()); return; } } return; case LessonState.finishing: if (!TeachingUtility.IsActorAvailable(this.teacher)) { TeachingUtility.AbortLesson(this, "TeacherUnavailable".Translate()); } return; case LessonState.finished: case LessonState.off: currentState = State.notinuse; return; } } }
public bool setupSkills(Pawn teacher) { String leaderType = TeachingUtility.getLeaderType(teacher); if (leaderType == "leader1") { if (teacher.skills.GetSkill(SkillDefOf.Growing).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Growing); } if (teacher.skills.GetSkill(SkillDefOf.Medicine).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Medicine); } if (teacher.skills.GetSkill(SkillDefOf.Animals).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Animals); } } else if (leaderType == "leader2") { if (teacher.skills.GetSkill(SkillDefOf.Shooting).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Shooting); } if (teacher.skills.GetSkill(SkillDefOf.Melee).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Melee); } } else if (leaderType == "leader3") { if (teacher.skills.GetSkill(SkillDefOf.Construction).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Construction); } if (teacher.skills.GetSkill(SkillDefOf.Crafting).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Crafting); } if (teacher.skills.GetSkill(SkillDefOf.Artistic).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Artistic); } } else if (leaderType == "leader4") { if (teacher.skills.GetSkill(SkillDefOf.Intellectual).Level >= TeachingUtility.minSkill) { this.skillPool.Add(SkillDefOf.Intellectual); } } if (this.skillPool.NullOrEmpty()) { return(false); } return(true); }
private bool CanGatherToLessonNow(out String skills) { skills = ""; if (Find.TickManager.TicksGame < lastTryTick + (GenDate.TicksPerHour / 3)) { return(false); } lastTryTick = Find.TickManager.TicksGame; if (Find.TickManager.TicksGame < lastLessonTick + GenDate.TicksPerDay - 1000) { return(RejectMessage("MustWaitForLesson".Translate())); } GameComponent_ColonyLeadership comp = Utility.getCLComp(); if (comp != null && Find.TickManager.TicksGame < comp.lastLessonTick + GenDate.TicksPerDay - 1000) { return(RejectMessage("MustWaitForLesson".Translate())); } if (tempTeacher == null) { return(RejectMessage("NoTeacherSelected".Translate())); } String report = ""; bool hasSkill = TeachingUtility.leaderHasAnySkill(tempTeacher, out report, out skills); if (hasSkill && report != "") { // Messages.Message(report, TargetInfo.Invalid, nullSound); Messages.Message(report, TargetInfo.Invalid, MessageTypeDefOf.NeutralEvent); } if (!hasSkill) { return(RejectMessage(report)); } if (tempTeacher.Drafted) { return(RejectMessage("TeacherDrafted".Translate())); } if (tempTeacher.Dead || this.tempTeacher.Downed) { return(RejectMessage("TeacherDownedDead".Translate(), this.tempTeacher)); } if (!tempTeacher.CanReserve(this)) { return(RejectMessage("TeacherTableReserved".Translate())); } return(true); }
public static void listPawns(int index, Building_TeachingSpot spot) { List <FloatMenuOption> list = new List <FloatMenuOption>(); List <Pawn> tpawns = new List <Pawn>(); foreach (Pawn current in IncidentWorker_LeaderElection.getAllColonists()) { Hediff h1 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader1")); Hediff h2 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader2")); Hediff h3 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader3")); Hediff h4 = current.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("leader4")); if (h1 != null || h2 != null || h3 != null || h4 != null) { if (!spot.teachers.Contains(current)) { tpawns.Add(current); } } } list.Add(new FloatMenuOption("-None-", delegate { spot.teachers[index] = null; }, MenuOptionPriority.Default, null, null, 0f, null, null)); foreach (Pawn p in tpawns) { list.Add(new FloatMenuOption(p.Name.ToStringShort, delegate { String report = ""; String skills = ""; bool hasSkill = TeachingUtility.leaderHasAnySkill(p, out report, out skills); if (hasSkill) { spot.teachers[index] = p; if (report != "") { Messages.Message(report, TargetInfo.Invalid, MessageSound.Standard); } } else { spot.teachers[index] = null; Messages.Message(report, TargetInfo.Invalid, MessageSound.RejectInput); } }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(list)); }
public static void doElect(Pawn pawn, Hediff hediff, bool forced = false) { hediff.Severity = 0.1f; pawn.health.AddHediff(hediff, null, null); pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("ElectedLeader")); StringBuilder stringBuilder = new StringBuilder(); if (forced) { stringBuilder.AppendLine("LeaderChosen".Translate(new object[] { pawn.Name.ToStringFull, hediff.LabelBase })); } else { stringBuilder.AppendLine("LeaderElected".Translate(new object[] { pawn.Name.ToStringFull, hediff.LabelBase })); } if (Prefs.DevMode) { stringBuilder.AppendLine(""); stringBuilder.AppendLine("--DEBUG-DEV---"); stringBuilder.AppendLine("Botanist Score: " + getBotanistScore(pawn)); stringBuilder.AppendLine("Warrior Score: " + getWarriorScore(pawn)); stringBuilder.AppendLine("Carpenter Score: " + getCarpenterScore(pawn)); stringBuilder.AppendLine("Scientist Score: " + getScientistScore(pawn)); } if (Utility.getGov() != null) { Find.LetterStack.ReceiveLetter("NewLeaderLetterTitle".Translate(new object[] { Utility.getGov().nameMale }), stringBuilder.ToString(), LetterDefOf.Good, pawn, null); } else { Find.LetterStack.ReceiveLetter("New Leader", stringBuilder.ToString(), LetterDefOf.Good, pawn, null); } foreach (Pawn p in getAllColonists()) { if (p != pawn) { int num2 = p.relations.OpinionOf(pawn); if (num2 <= -20) { p.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("RivalLeader"), null); } if (p.story.traits.HasTrait(TraitDef.Named("Jealous")) && TeachingUtility.leaderH(p) == null) { p.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("ElectedLeaderJealous"), null); } } } }
private void TryTimedLesson() { int teacherInt = seasonSchedule[GenLocalDate.DayOfSeason(this.Map)]; if (teacherInt >= 3) { tempTeacher = TeachingUtility.DetermineTeacher(this.Map); } else { tempTeacher = teachers[teacherInt - 1]; } TryLesson(); }
public static void GetLessonGroup(Building_TeachingSpot spot, Map map, bool forced = false) { Room room = spot.GetRoom(); if (room.Role != RoomRoleDefOf.PrisonBarracks && room.Role != RoomRoleDefOf.PrisonCell) { List <Pawn> listeners = new List <Pawn>(); if (forced) { listeners = map.mapPawns.AllPawnsSpawned.FindAll(x => x.RaceProps.intelligence == Intelligence.Humanlike && !x.Downed && !x.Dead && x.CurJob.def.defName != "AttendLesson" && x.CurJob.def != JobDefOf.ExtinguishSelf && x.CurJob.def != JobDefOf.Rescue && x.CurJob.def != JobDefOf.TendPatient && x.CurJob.def != JobDefOf.BeatFire && !spot.ignored.Contains(x) && x.CurJob.def != JobDefOf.FleeAndCower && (x.GetCaravan() == null || x.GetCaravan().IsPlayerControlled == true) && !x.InAggroMentalState && !x.InMentalState); } else { listeners = map.mapPawns.AllPawnsSpawned.FindAll(x => x.RaceProps.intelligence == Intelligence.Humanlike && !x.Downed && !x.Dead && x.CurJob.def.defName != "AttendLesson" && x.CurJob.def != JobDefOf.ExtinguishSelf && x.CurJob.def != JobDefOf.Rescue && x.CurJob.def != JobDefOf.TendPatient && x.CurJob.def != JobDefOf.BeatFire && x.CurJob.def != JobDefOf.Lovin && x.CurJob.def != JobDefOf.LayDown && !spot.ignored.Contains(x) && (x.GetCaravan() == null || x.GetCaravan().IsPlayerControlled == true) && x.CurJob.def != JobDefOf.FleeAndCower && !x.InAggroMentalState && !x.InMentalState); } bool[] flag = new bool[listeners.Count]; for (int i = 0; i < listeners.Count; i++) { if (!flag[i] && TeachingUtility.ShouldAttendLesson(listeners[i], spot)) { GiveAttendLessonJob(spot, listeners[i]); flag[i] = true; } } } }
public void StartLesson(bool forced = false, String skills = "") { teacher = tempTeacher; if (this.Destroyed || !this.Spawned) { TeachingUtility.AbortLesson(null, "The spot is unavailable."); return; } if (!TeachingUtility.IsActorAvailable(this.teacher)) { TeachingUtility.AbortLesson(this, "TeacherUnavailableNamed".Translate(new object[] { this.teacher.LabelShort })); this.teacher = null; return; } //FactionBase factionBase = (FactionBase)this.Map.info.parent; //Messages.Message("LessonGathering".Translate(new object[] { factionBase.label, teacher.LabelShort }) + skills, TargetInfo.Invalid, nullSound); Settlement factionBase = (Settlement)this.Map.info.parent; Messages.Message("LessonGathering".Translate(new object[] { factionBase.Label, teacher.LabelShort }) + skills, TargetInfo.Invalid, MessageTypeDefOf.NeutralEvent); ChangeState(State.lesson, LessonState.started); //this.currentState = State.started; Job job = new Job(DefDatabase <JobDef> .GetNamed("TeachLesson"), this); teacher.jobs.jobQueue.EnqueueLast(job); teacher.jobs.EndCurrentJob(JobCondition.InterruptForced); TeachingUtility.GetLessonGroup(this, Map, forced); lastLessonTick = Find.TickManager.TicksGame; // HediffLeader hediff = TeachingUtility.leaderH(teacher); // if (hediff != null) hediff.lastLessonTick = Find.TickManager.TicksGame; GameComponent_ColonyLeadership comp = Utility.getCLComp(); if (comp != null) { comp.lastLessonTick = Find.TickManager.TicksGame; } }
public void LessonRareTick() { if (currentState == State.lesson) { switch (currentLessonState) { case LessonState.started: case LessonState.gathering: case LessonState.teaching: if (!TeachingUtility.IsActorAvailable(this.teacher)) { TeachingUtility.AbortLesson(this, "TeacherUnavailable".Translate()); return; } if (this.teacher.CurJob.def.defName != "TeachLesson") { TeachingUtility.AbortLesson(this, "TeacherUnavailable".Translate()); return; } TeachingUtility.GetLessonGroup(this, Map); return; case LessonState.finishing: if (!TeachingUtility.IsActorAvailable(this.teacher)) { TeachingUtility.AbortLesson(this, "TeacherUnavailable".Translate()); return; } /*if (this.teacher.CurJob.def != CultDefOfs.ReflectOnWorship) * return;*/ TeachingUtility.GetLessonGroup(this, Map); return; case LessonState.finished: case LessonState.off: currentState = State.notinuse; return; } } }
public static bool leaderHasAnySkill(Pawn teacher, out String report, out String skills) { String leaderType = TeachingUtility.getLeaderType(teacher); List <SkillDef> teachable = new List <SkillDef>(); String missing = ""; skills = ""; bool flag = false; if (leaderType == "leader1") { if (teacher.skills.GetSkill(SkillDefOf.Plants).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Plants); } if (teacher.skills.GetSkill(SkillDefOf.Medicine).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Medicine); } if (teacher.skills.GetSkill(SkillDefOf.Animals).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Animals); } if (teachable.Count < 3) { flag = true; } missing = "SkillSet1"; } else if (leaderType == "leader2") { if (teacher.skills.GetSkill(SkillDefOf.Shooting).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Shooting); } if (teacher.skills.GetSkill(SkillDefOf.Melee).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Melee); } if (teachable.Count < 2) { flag = true; } missing = "SkillSet2"; } else if (leaderType == "leader3") { if (teacher.skills.GetSkill(SkillDefOf.Construction).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Construction); } if (teacher.skills.GetSkill(SkillDefOf.Crafting).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Crafting); } if (teacher.skills.GetSkill(SkillDefOf.Artistic).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Artistic); } if (teachable.Count < 3) { flag = true; } missing = "SkillSet3"; } else if (leaderType == "leader4") { if (teacher.skills.GetSkill(SkillDefOf.Intellectual).Level >= TeachingUtility.minSkill) { teachable.Add(SkillDefOf.Intellectual); } if (teachable.Count < 1) { flag = true; } missing = "SkillSet4"; } if (teachable.NullOrEmpty()) { report = "MustHaveSkill" + TeachingUtility.minSkill + " " + missing; return(false); } else if (flag) { report = "OnlyTeachIfSkill" + TeachingUtility.minSkill + " " + missing; return(true); } report = ""; skills = missing.ReplaceFirst(" or ", " and "); return(true); }
public void DrawIconsModded(Rect rect, Pawn colonist) { if (colonist.Dead) { return; } float num = 20f * this.ColonistBar.Scale; Vector2 vector = new Vector2(rect.x + 1f, rect.yMax - num - 1f); bool flag = false; if (colonist.CurJob != null) { JobDef def = colonist.CurJob.def; if (def == JobDefOf.AttackMelee || def == JobDefOf.AttackStatic) { flag = true; } else if (def == JobDefOf.WaitCombat) { Stance_Busy stance_Busy = colonist.stances.curStance as Stance_Busy; if (stance_Busy != null && stance_Busy.focusTarg.IsValid) { flag = true; } } } Hediff Leader = TeachingUtility.leaderH(colonist); if (colonist.InAggroMentalState) { this.DrawIcon(Icon_MentalStateAggro, ref vector, colonist.MentalStateDef.LabelCap); } else if (colonist.InMentalState) { this.DrawIcon(Icon_MentalStateNonAggro, ref vector, colonist.MentalStateDef.LabelCap); } else if (colonist.InBed() && colonist.CurrentBed().Medical) { this.DrawIcon(Icon_MedicalRest, ref vector, "ActivityIconMedicalRest".Translate()); } else if (colonist.CurJob != null && colonist.jobs.curDriver.asleep) { this.DrawIcon(Icon_Sleeping, ref vector, "ActivityIconSleeping".Translate()); } else if (colonist.CurJob != null && colonist.CurJob.def == JobDefOf.FleeAndCower) { this.DrawIcon(Icon_Fleeing, ref vector, "ActivityIconFleeing".Translate()); } else if (flag) { this.DrawIcon(Icon_Attacking, ref vector, "ActivityIconAttacking".Translate()); } else if (colonist.mindState.IsIdle && GenDate.DaysPassed >= 1) { this.DrawIcon(Icon_Idle, ref vector, "ActivityIconIdle".Translate()); } else if (Leader != null) { this.DrawIcon(Icon_Star, ref vector, Leader.LabelBase); } if (colonist.IsBurning()) { this.DrawIcon(Icon_Burning, ref vector, "ActivityIconBurning".Translate()); } }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); yield return(Toils_Reserve.Reserve(SpotIndex, 1, -1, null)); yield return(new Toil { initAction = delegate { Spot.ChangeState(Building_TeachingSpot.State.lesson, Building_TeachingSpot.LessonState.gathering); } }); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell)); Toil waitingTime = new Toil(); waitingTime.defaultCompleteMode = ToilCompleteMode.Delay; TeachingUtility.remainingDuration = TeachingUtility.ritualDuration; waitingTime.defaultDuration = TeachingUtility.remainingDuration - 360; waitingTime.initAction = delegate { // Spot.lastLessonTick = Find.TickManager.TicksGame; // HediffLeader hediff = TeachingUtility.leaderH(this.pawn); //if (hediff != null) hediff.lastLessonTick = Find.TickManager.TicksGame; report = "WaitingDesc".Translate(); MoteMaker.MakeInteractionBubble(this.pawn, null, ThingDefOf.Mote_Speech, ModTextures.waiting); Spot.ChangeState(Building_TeachingSpot.State.lesson, Building_TeachingSpot.LessonState.teaching); List <Thing> list = GenRadial.RadialDistinctThingsAround(this.pawn.Position, this.pawn.Map, 10f, true).ToList <Thing>(); foreach (Thing current in list) { Building_Chalkboard chalk = current as Building_Chalkboard; bool flag2 = chalk != null; if (flag2) { if (current.def.defName == "ChalkboardCL" && current.Faction == this.pawn.Faction) { if (current.GetRoom() == this.pawn.GetRoom()) { string s = TeachingUtility.getLeaderType(this.pawn); chalkboards.Add(chalk); chalk.frame = -1; this.Map.mapDrawer.MapMeshDirty(chalk.Position, MapMeshFlag.Things, true, false); } } } } }; yield return(waitingTime); for (int i = 0; i < 3; i++) { Toil teachingTime = new Toil(); teachingTime.defaultCompleteMode = ToilCompleteMode.Delay; TeachingUtility.remainingDuration = TeachingUtility.ritualDuration; teachingTime.defaultDuration = TeachingUtility.remainingDuration - 120; teachingTime.initAction = delegate { string s = TeachingUtility.getLeaderType(this.pawn); foreach (Building_Chalkboard chalk in chalkboards) { if (chalk != null) { if (s == "leader1") { chalk.state = 1; } else if (s == "leader2") { chalk.state = 2; } else if (s == "leader3") { chalk.state = 3; } else if (s == "leader4") { chalk.state = 4; } chalk.frame++; this.Map.mapDrawer.MapMeshDirty(chalk.Position, MapMeshFlag.Things, true, false); } } report = "TeachingDesc".Translate(); MoteMaker.MakeInteractionBubble(this.pawn, null, ThingDefOf.Mote_Speech, iconList(this.pawn).RandomElement()); }; teachingTime.tickAction = delegate { Pawn actor = this.pawn; actor.skills.Learn(SkillDefOf.Social, 0.25f); actor.GainComfortFromCellIfPossible(); }; yield return(teachingTime); } Toil finishingTime = new Toil(); finishingTime.defaultCompleteMode = ToilCompleteMode.Delay; TeachingUtility.remainingDuration = TeachingUtility.ritualDuration; finishingTime.defaultDuration = TeachingUtility.remainingDuration - 360; finishingTime.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f); finishingTime.initAction = delegate { report = "FinishLessonDesc".Translate(); MoteMaker.MakeInteractionBubble(this.pawn, null, ThingDefOf.Mote_Speech, iconList(this.pawn).RandomElement()); }; finishingTime.tickAction = delegate { if (tickC == 120 || tickC == 240 || tickC == 360) { foreach (Building_Chalkboard chalk in chalkboards) { if (chalk != null) { if (chalk.frame > -1) { chalk.frame--; } this.Map.mapDrawer.MapMeshDirty(chalk.Position, MapMeshFlag.Things, true, false); } } } Pawn actor = this.pawn; actor.skills.Learn(SkillDefOf.Social, 0.25f); actor.GainComfortFromCellIfPossible(); tickC++; }; yield return(finishingTime); yield return(new Toil { initAction = delegate { tickC = 0; TeachingUtility.TeachingComplete(this.pawn, Spot); }, defaultCompleteMode = ToilCompleteMode.Instant }); yield return(new Toil { initAction = delegate { if (Spot != null) { if (Spot.currentLessonState != Building_TeachingSpot.LessonState.finished) { Spot.ChangeState(Building_TeachingSpot.State.lesson, Building_TeachingSpot.LessonState.finished); //Map.GetComponent<MapComponent_SacrificeTracker>().ClearVariables(); } } }, defaultCompleteMode = ToilCompleteMode.Instant }); this.AddFinishAction(() => { foreach (Building_Chalkboard chalk in chalkboards) { if (chalk != null) { chalk.frame = 0; chalk.state = 0; this.Map.mapDrawer.MapMeshDirty(chalk.Position, MapMeshFlag.Things, true, false); } } if (Spot.currentLessonState == Building_TeachingSpot.LessonState.finishing || Spot.currentLessonState == Building_TeachingSpot.LessonState.finished) { this.pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDef.Named("TaughtCL"), null); } }); yield break; }