public static Toil TryTrain(TargetIndex traineeInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Pawn pawn = (Pawn)actor.jobs.curJob.GetTarget(traineeInd).Thing; if (pawn.Spawned && pawn.Awake() && actor.interactions.TryInteractWith(pawn, InteractionDefOf.TrainAttempt)) { float num = actor.GetStatValue(StatDefOf.TrainAnimalChance, true); num *= GenMath.LerpDouble(0f, 1f, 1.5f, 0.5f, pawn.RaceProps.wildness); if (actor.relations.DirectRelationExists(PawnRelationDefOf.Bond, pawn)) { num *= 5f; } num = Mathf.Clamp01(num); TrainableDef trainableDef = pawn.training.NextTrainableToTrain(); if (trainableDef == null) { Log.ErrorOnce("Attempted to train untrainable animal", 7842936, false); return; } string text; if (Rand.Value < num) { pawn.training.Train(trainableDef, actor, false); if (pawn.caller != null) { pawn.caller.DoCall(); } text = "TextMote_TrainSuccess".Translate(trainableDef.LabelCap, num.ToStringPercent()); RelationsUtility.TryDevelopBondRelation(actor, pawn, 0.007f); TaleRecorder.RecordTale(TaleDefOf.TrainedAnimal, new object[] { actor, pawn, trainableDef }); } else { text = "TextMote_TrainFail".Translate(trainableDef.LabelCap, num.ToStringPercent()); } string text2 = text; text = string.Concat(new object[] { text2, "\n", pawn.training.GetSteps(trainableDef), " / ", trainableDef.steps }); MoteMaker.ThrowText((actor.DrawPos + pawn.DrawPos) / 2f, actor.Map, text, 5f); } }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 100; return(toil); }
public static void DoRecruit(Pawn recruiter, Pawn recruitee, float recruitChance, bool useAudiovisualEffects = true) { string text = recruitee.LabelIndefinite(); if (recruitee.guest != null) { recruitee.guest.SetGuestStatus(null, false); } bool flag = recruitee.Name != null; if (recruitee.Faction != recruiter.Faction) { recruitee.SetFaction(recruiter.Faction, recruiter); } if (recruitee.RaceProps.Humanlike) { if (useAudiovisualEffects) { Find.LetterStack.ReceiveLetter("LetterLabelMessageRecruitSuccess".Translate(), "MessageRecruitSuccess".Translate(recruiter, recruitee, recruitChance.ToStringPercent()), LetterDefOf.PositiveEvent, recruitee, null); } TaleRecorder.RecordTale(TaleDefOf.Recruited, recruiter, recruitee); recruiter.records.Increment(RecordDefOf.PrisonersRecruited); recruitee.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.RecruitedMe, recruiter); } else { if (useAudiovisualEffects) { if (!flag) { Messages.Message("MessageTameAndNameSuccess".Translate(recruiter.LabelShort, text, recruitChance.ToStringPercent(), recruitee.Name.ToStringFull).AdjustedFor(recruitee), recruitee, MessageTypeDefOf.PositiveEvent); } else { Messages.Message("MessageTameSuccess".Translate(recruiter.LabelShort, text, recruitChance.ToStringPercent()), recruitee, MessageTypeDefOf.PositiveEvent); } MoteMaker.ThrowText((recruiter.DrawPos + recruitee.DrawPos) / 2f, recruiter.Map, "TextMote_TameSuccess".Translate(recruitChance.ToStringPercent()), 8f); } recruiter.records.Increment(RecordDefOf.AnimalsTamed); RelationsUtility.TryDevelopBondRelation(recruiter, recruitee, 0.01f); float chance = Mathf.Lerp(0.02f, 1f, recruitee.RaceProps.wildness); if (Rand.Chance(chance) || recruitee.IsWildMan()) { TaleRecorder.RecordTale(TaleDefOf.TamedAnimal, recruiter, recruitee); } if (PawnsFinder.AllMapsWorldAndTemporary_Alive.Count((Pawn p) => p.playerSettings != null && p.playerSettings.master == recruiter) >= 10) { TaleRecorder.RecordTale(TaleDefOf.IncreasedMenagerie, recruiter, recruitee); } } if (recruitee.caller != null) { recruitee.caller.DoCall(); } }
private void Tick_CheckDevelopBondRelation() { if (this.pawn.Spawned && this.pawn.RaceProps.Animal && this.pawn.Faction == Faction.OfPlayer && this.pawn.playerSettings.RespectedMaster != null) { Pawn respectedMaster = this.pawn.playerSettings.RespectedMaster; if (this.pawn.IsHashIntervalTick(2500) && this.pawn.Position.InHorDistOf(respectedMaster.Position, 12f) && GenSight.LineOfSight(this.pawn.Position, respectedMaster.Position, this.pawn.Map, false, null, 0, 0)) { RelationsUtility.TryDevelopBondRelation(respectedMaster, this.pawn, 0.001f); } } }
public static Toil TryTrain(TargetIndex traineeInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Pawn pawn = (Pawn)actor.jobs.curJob.GetTarget(traineeInd).Thing; if (pawn.Spawned && pawn.Awake() && actor.interactions.TryInteractWith(pawn, InteractionDefOf.TrainAttempt)) { float statValue = actor.GetStatValue(StatDefOf.TrainAnimalChance, true); statValue *= Mathf.Max(0.05f, GenMath.LerpDouble(0f, 1f, 2f, 0f, pawn.RaceProps.wildness)); if (actor.relations.DirectRelationExists(PawnRelationDefOf.Bond, pawn)) { statValue = (float)(statValue * 1.5); } statValue = Mathf.Clamp01(statValue); TrainableDef trainableDef = pawn.training.NextTrainableToTrain(); string text; if (Rand.Value < statValue) { pawn.training.Train(trainableDef, actor); if (pawn.caller != null) { pawn.caller.DoCall(); } text = "TextMote_TrainSuccess".Translate(trainableDef.LabelCap, statValue.ToStringPercent()); RelationsUtility.TryDevelopBondRelation(actor, pawn, 0.007f); TaleRecorder.RecordTale(TaleDefOf.TrainedAnimal, actor, pawn, trainableDef); } else { text = "TextMote_TrainFail".Translate(trainableDef.LabelCap, statValue.ToStringPercent()); } string text2 = text; text = text2 + "\n" + pawn.training.GetSteps(trainableDef) + " / " + trainableDef.steps; MoteMaker.ThrowText((actor.DrawPos + pawn.DrawPos) / 2f, actor.Map, text, 5f); } }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 100; return(toil); }
public static void DoTend(Pawn doctor, Pawn patient, Medicine medicine) { if (patient.health.HasHediffsNeedingTend(false)) { if (medicine != null && medicine.Destroyed) { Log.Warning("Tried to use destroyed medicine."); medicine = null; } float num = (float)((medicine == null) ? 0.30000001192092896 : medicine.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null)); float num2 = (float)((doctor == null) ? 0.75 : doctor.GetStatValue(StatDefOf.MedicalTendQuality, true)); num2 *= num; Building_Bed building_Bed = patient.CurrentBed(); if (building_Bed != null) { num2 += building_Bed.GetStatValue(StatDefOf.MedicalTendQualityOffset, true); } if (doctor == patient) { num2 = (float)(num2 * 0.699999988079071); } num2 = Mathf.Clamp01(num2); TendUtility.GetOptimalHediffsToTendWithSingleTreatment(patient, medicine != null, TendUtility.tmpHediffsToTend, null); for (int i = 0; i < TendUtility.tmpHediffsToTend.Count; i++) { TendUtility.tmpHediffsToTend[i].Tended(num2, i); } if (doctor != null && doctor.Faction != null && patient.HostFaction == null && patient.Faction != null && patient.Faction != doctor.Faction) { patient.Faction.AffectGoodwillWith(doctor.Faction, 0.3f); } if (doctor != null && doctor.IsColonistPlayerControlled) { patient.records.AccumulateStoryEvent(StoryEventDefOf.TendedByPlayer); } if (doctor != null && doctor.RaceProps.Humanlike && patient.RaceProps.Animal && RelationsUtility.TryDevelopBondRelation(doctor, patient, 0.004f) && doctor.Faction != null && doctor.Faction != patient.Faction) { InteractionWorker_RecruitAttempt.DoRecruit(doctor, patient, 1f, false); } patient.records.Increment(RecordDefOf.TimesTendedTo); if (doctor != null) { doctor.records.Increment(RecordDefOf.TimesTendedOther); } if (medicine != null) { if ((patient.Spawned || (doctor != null && doctor.Spawned)) && num > ThingDefOf.Medicine.GetStatValueAbstract(StatDefOf.MedicalPotency, null)) { SoundDefOf.TechMedicineUsed.PlayOneShot(new TargetInfo(patient.Position, patient.Map, false)); } if (medicine.stackCount > 1) { medicine.stackCount--; } else if (!medicine.Destroyed) { medicine.Destroy(DestroyMode.Vanish); } } } }
public static void DoTend(Pawn doctor, Pawn patient, Medicine medicine) { if (!patient.health.HasHediffsNeedingTend(false)) { return; } if (medicine != null && medicine.Destroyed) { Log.Warning("Tried to use destroyed medicine.", false); medicine = null; } float quality = TendUtility.CalculateBaseTendQuality(doctor, patient, (medicine == null) ? null : medicine.def); TendUtility.GetOptimalHediffsToTendWithSingleTreatment(patient, medicine != null, TendUtility.tmpHediffsToTend, null); for (int i = 0; i < TendUtility.tmpHediffsToTend.Count; i++) { TendUtility.tmpHediffsToTend[i].Tended(quality, i); } if (doctor != null && doctor.Faction == Faction.OfPlayer && patient.Faction != doctor.Faction && !patient.IsPrisoner && patient.Faction != null) { patient.mindState.timesGuestTendedToByPlayer++; } if (doctor != null && doctor.IsColonistPlayerControlled) { patient.records.AccumulateStoryEvent(StoryEventDefOf.TendedByPlayer); } if (doctor != null && doctor.RaceProps.Humanlike && patient.RaceProps.Animal && RelationsUtility.TryDevelopBondRelation(doctor, patient, 0.004f) && doctor.Faction != null && doctor.Faction != patient.Faction) { InteractionWorker_RecruitAttempt.DoRecruit(doctor, patient, 1f, false); } patient.records.Increment(RecordDefOf.TimesTendedTo); if (doctor != null) { doctor.records.Increment(RecordDefOf.TimesTendedOther); } if (doctor == patient && !doctor.Dead) { doctor.mindState.Notify_SelfTended(); } if (medicine != null) { if ((patient.Spawned || (doctor != null && doctor.Spawned)) && medicine != null && medicine.GetStatValue(StatDefOf.MedicalPotency, true) > ThingDefOf.MedicineIndustrial.GetStatValueAbstract(StatDefOf.MedicalPotency, null)) { SoundDefOf.TechMedicineUsed.PlayOneShot(new TargetInfo(patient.Position, patient.Map, false)); } if (medicine.stackCount > 1) { medicine.stackCount--; } else if (!medicine.Destroyed) { medicine.Destroy(DestroyMode.Vanish); } } }
public static void DoRecruit(Pawn recruiter, Pawn recruitee, float recruitChance, out string letterLabel, out string letter, bool useAudiovisualEffects = true, bool sendLetter = true) { letterLabel = null; letter = null; recruitChance = Mathf.Clamp01(recruitChance); string value = recruitee.LabelIndefinite(); if (recruitee.apparel != null && recruitee.apparel.LockedApparel != null) { List<Apparel> lockedApparel = recruitee.apparel.LockedApparel; for (int num = lockedApparel.Count - 1; num >= 0; num--) { recruitee.apparel.Unlock(lockedApparel[num]); } } if (recruitee.royalty != null) { foreach (RoyalTitle item in recruitee.royalty.AllTitlesForReading) { if (item.def.replaceOnRecruited != null) { recruitee.royalty.SetTitle(item.faction, item.def.replaceOnRecruited, grantRewards: false, rewardsOnlyForNewestTitle: false, sendLetter: false); } } } if (recruitee.guest != null) { recruitee.guest.SetGuestStatus(null); } bool flag = recruitee.Name != null; if (recruitee.Faction != recruiter.Faction) { recruitee.SetFaction(recruiter.Faction, recruiter); } if (recruitee.RaceProps.Humanlike) { if (useAudiovisualEffects) { letterLabel = "LetterLabelMessageRecruitSuccess".Translate() + ": " + recruitee.LabelShortCap; if (sendLetter) { Find.LetterStack.ReceiveLetter(letterLabel, "MessageRecruitSuccess".Translate(recruiter, recruitee, recruitChance.ToStringPercent(), recruiter.Named("RECRUITER"), recruitee.Named("RECRUITEE")), LetterDefOf.PositiveEvent, recruitee); } } TaleRecorder.RecordTale(TaleDefOf.Recruited, recruiter, recruitee); recruiter.records.Increment(RecordDefOf.PrisonersRecruited); if (recruitee.needs.mood != null) { recruitee.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.RecruitedMe, recruiter); } QuestUtility.SendQuestTargetSignals(recruitee.questTags, "Recruited", recruitee.Named("SUBJECT")); } else { if (useAudiovisualEffects) { if (!flag) { Messages.Message("MessageTameAndNameSuccess".Translate(recruiter.LabelShort, value, recruitChance.ToStringPercent(), recruitee.Name.ToStringFull, recruiter.Named("RECRUITER"), recruitee.Named("RECRUITEE")).AdjustedFor(recruitee), recruitee, MessageTypeDefOf.PositiveEvent); } else { Messages.Message("MessageTameSuccess".Translate(recruiter.LabelShort, value, recruitChance.ToStringPercent(), recruiter.Named("RECRUITER")), recruitee, MessageTypeDefOf.PositiveEvent); } if (recruiter.Spawned && recruitee.Spawned) { MoteMaker.ThrowText((recruiter.DrawPos + recruitee.DrawPos) / 2f, recruiter.Map, "TextMote_TameSuccess".Translate(recruitChance.ToStringPercent()), 8f); } } recruiter.records.Increment(RecordDefOf.AnimalsTamed); RelationsUtility.TryDevelopBondRelation(recruiter, recruitee, 0.01f); if (Rand.Chance(Mathf.Lerp(0.02f, 1f, recruitee.RaceProps.wildness)) || recruitee.IsWildMan()) { TaleRecorder.RecordTale(TaleDefOf.TamedAnimal, recruiter, recruitee); } if (PawnsFinder.AllMapsWorldAndTemporary_Alive.Count((Pawn p) => p.playerSettings != null && p.playerSettings.Master == recruiter) >= 5) { TaleRecorder.RecordTale(TaleDefOf.IncreasedMenagerie, recruiter, recruitee); } } if (recruitee.caller != null) { recruitee.caller.DoCall(); } }