public bool CheckSocialFightStart(InteractionDef interaction, Pawn initiator) { bool result; if (!DebugSettings.enableRandomMentalStates) { result = false; } else if (this.pawn.needs.mood == null || TutorSystem.TutorialMode) { result = false; } else if (!InteractionUtility.HasAnySocialFightProvokingThought(this.pawn, initiator)) { result = false; } else if (DebugSettings.alwaysSocialFight || Rand.Value < this.SocialFightChance(interaction, initiator)) { this.StartSocialFight(initiator); result = true; } else { result = false; } return(result); }
private bool TryInteractRandomly() { if (this.InteractedTooRecentlyToInteract()) { return(false); } if (!InteractionUtility.CanInitiateRandomInteraction(this.pawn)) { return(false); } List <Pawn> collection = this.pawn.Map.mapPawns.SpawnedPawnsInFaction(this.pawn.Faction); Pawn_InteractionsTracker.workingList.Clear(); Pawn_InteractionsTracker.workingList.AddRange(collection); Pawn_InteractionsTracker.workingList.Shuffle(); List <InteractionDef> allDefsListForReading = DefDatabase <InteractionDef> .AllDefsListForReading; for (int i = 0; i < Pawn_InteractionsTracker.workingList.Count; i++) { Pawn p = Pawn_InteractionsTracker.workingList[i]; InteractionDef intDef = default(InteractionDef); if (p != this.pawn && this.CanInteractNowWith(p) && InteractionUtility.CanReceiveRandomInteraction(p) && !this.pawn.HostileTo(p) && ((IEnumerable <InteractionDef>)allDefsListForReading).TryRandomElementByWeight <InteractionDef>((Func <InteractionDef, float>)((InteractionDef x) => x.Worker.RandomSelectionWeight(this.pawn, p)), out intDef)) { if (this.TryInteractWith(p, intDef)) { return(true); } Log.Error(this.pawn + " failed to interact with " + p); } } return(false); }
public bool TryInteractWith(Pawn recipient, InteractionDef intDef) { if (DebugSettings.alwaysSocialFight) { intDef = InteractionDefOf.Insult; } if (this.pawn == recipient) { Log.Warning(this.pawn + " tried to interact with self, interaction=" + intDef.defName); return(false); } if (!this.CanInteractNowWith(recipient)) { return(false); } if (this.InteractedTooRecentlyToInteract()) { Log.Error(this.pawn + " tried to do interaction " + intDef + " to " + recipient + " only " + (Find.TickManager.TicksGame - this.lastInteractionTime) + " ticks since last interaction (min is " + 120 + ")."); return(false); } List <RulePackDef> list = new List <RulePackDef>(); if (intDef.initiatorThought != null) { Pawn_InteractionsTracker.AddInteractionThought(this.pawn, recipient, intDef.initiatorThought); } if (intDef.recipientThought != null && recipient.needs.mood != null) { Pawn_InteractionsTracker.AddInteractionThought(recipient, this.pawn, intDef.recipientThought); } if (intDef.initiatorXpGainSkill != null) { this.pawn.skills.Learn(intDef.initiatorXpGainSkill, (float)intDef.initiatorXpGainAmount, false); } if (intDef.recipientXpGainSkill != null && recipient.RaceProps.Humanlike) { recipient.skills.Learn(intDef.recipientXpGainSkill, (float)intDef.recipientXpGainAmount, false); } bool flag = false; if (recipient.RaceProps.Humanlike) { flag = recipient.interactions.CheckSocialFightStart(intDef, this.pawn); } if (!flag) { intDef.Worker.Interacted(this.pawn, recipient, list); } MoteMaker.MakeInteractionBubble(this.pawn, recipient, intDef.interactionMote, intDef.Symbol); this.lastInteractionTime = Find.TickManager.TicksGame; if (flag) { list.Add(RulePackDefOf.Sentence_SocialFightStarted); } Find.PlayLog.Add(new PlayLogEntry_Interaction(intDef, this.pawn, recipient, list)); return(true); }
public float SocialFightChance(InteractionDef interaction, Pawn initiator) { if (!pawn.RaceProps.Humanlike || !initiator.RaceProps.Humanlike) { return(0f); } if (!InteractionUtility.HasAnyVerbForSocialFight(pawn) || !InteractionUtility.HasAnyVerbForSocialFight(initiator)) { return(0f); } if (pawn.WorkTagIsDisabled(WorkTags.Violent)) { return(0f); } if (initiator.Downed || pawn.Downed) { return(0f); } float socialFightBaseChance = interaction.socialFightBaseChance; socialFightBaseChance *= Mathf.InverseLerp(0.3f, 1f, pawn.health.capacities.GetLevel(PawnCapacityDefOf.Manipulation)); socialFightBaseChance *= Mathf.InverseLerp(0.3f, 1f, pawn.health.capacities.GetLevel(PawnCapacityDefOf.Moving)); List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i].CurStage != null) { socialFightBaseChance *= hediffs[i].CurStage.socialFightChanceFactor; } } float num = pawn.relations.OpinionOf(initiator); socialFightBaseChance = ((!(num < 0f)) ? (socialFightBaseChance * GenMath.LerpDouble(0f, 100f, 1f, 0.6f, num)) : (socialFightBaseChance * GenMath.LerpDouble(-100f, 0f, 4f, 1f, num))); if (pawn.RaceProps.Humanlike) { List <Trait> allTraits = pawn.story.traits.allTraits; for (int j = 0; j < allTraits.Count; j++) { socialFightBaseChance *= allTraits[j].CurrentData.socialFightChanceFactor; } } int num2 = Mathf.Abs(pawn.ageTracker.AgeBiologicalYears - initiator.ageTracker.AgeBiologicalYears); if (num2 > 10) { if (num2 > 50) { num2 = 50; } socialFightBaseChance *= GenMath.LerpDouble(10f, 50f, 1f, 0.25f, num2); } return(Mathf.Clamp01(socialFightBaseChance)); }
public static bool CanReceiveInteraction(Pawn pawn, InteractionDef interactionDef = null) { if (!pawn.Awake()) { return(false); } if (pawn.IsBurning()) { return(false); } if (pawn.IsInteractionBlocked(interactionDef, isInitiator: false, isRandom: false)) { return(false); } return(true); }
public bool CanInteractNowWith(Pawn recipient, InteractionDef interactionDef = null) { if (!recipient.Spawned) { return(false); } if (!InteractionUtility.IsGoodPositionForInteraction(pawn, recipient)) { return(false); } if (!InteractionUtility.CanInitiateInteraction(pawn, interactionDef) || !InteractionUtility.CanReceiveInteraction(recipient, interactionDef)) { return(false); } return(true); }
public bool CheckSocialFightStart(InteractionDef interaction, Pawn initiator) { if (this.pawn.needs.mood == null || TutorSystem.TutorialMode) { return(false); } if (!InteractionUtility.HasAnySocialFightProvokingThought(this.pawn, initiator)) { return(false); } if (DebugSettings.alwaysSocialFight || Rand.Value < this.SocialFightChance(interaction, initiator)) { this.StartSocialFight(initiator); return(true); } return(false); }
public bool CheckSocialFightStart(InteractionDef interaction, Pawn initiator) { if (!DebugSettings.enableRandomMentalStates) { return(false); } if (this.pawn.needs.mood == null || TutorSystem.TutorialMode) { return(false); } if (DebugSettings.alwaysSocialFight || Rand.Value < this.SocialFightChance(interaction, initiator)) { this.StartSocialFight(initiator); return(true); } return(false); }
public static Toil Interact(TargetIndex otherPawnInd, InteractionDef interaction) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Pawn pawn = (Pawn)actor.jobs.curJob.GetTarget(otherPawnInd).Thing; if (pawn.Spawned) { actor.interactions.TryInteractWith(pawn, interaction); } }; toil.socialMode = RandomSocialMode.Off; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 60; return(toil); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDespawnedNullOrForbidden(TargetIndex.A); this.FailOn(() => !this.Patient.InBed() || !this.Patient.Awake()); if (this.Chair != null) { this.FailOnDespawnedNullOrForbidden(TargetIndex.B); } if (this.Chair != null) { yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell)); } else { yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell)); } yield return(Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn)); yield return(new Toil { tickAction = delegate() { this.Patient.needs.joy.GainJoy(this.job.def.joyGainRate * 0.000144f, this.job.def.joyKind); if (this.pawn.IsHashIntervalTick(320)) { InteractionDef intDef = (Rand.Value >= 0.8f) ? InteractionDefOf.DeepTalk : InteractionDefOf.Chitchat; this.pawn.interactions.TryInteractWith(this.Patient, intDef); } this.pawn.rotationTracker.FaceCell(this.Patient.Position); this.pawn.GainComfortFromCellIfPossible(); JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.None, 1f, null); if (this.pawn.needs.joy.CurLevelPercentage > 0.9999f && this.Patient.needs.joy.CurLevelPercentage > 0.9999f) { this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded, true); } }, handlingFacing = true, socialMode = RandomSocialMode.Off, defaultCompleteMode = ToilCompleteMode.Delay, defaultDuration = this.job.def.joyDuration }); yield break; }
public static Toil TryRecruit(TargetIndex recruiteeInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Pawn pawn = (Pawn)actor.jobs.curJob.GetTarget(recruiteeInd).Thing; if (pawn.Spawned && pawn.Awake()) { InteractionDef intDef = pawn.AnimalOrWildMan() ? InteractionDefOf.TameAttempt : InteractionDefOf.RecruitAttempt; actor.interactions.TryInteractWith(pawn, intDef); } }; toil.socialMode = RandomSocialMode.Off; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 350; return(toil); }
public static bool IsInteractionBlocked(this Pawn pawn, InteractionDef interaction, bool isInitiator, bool isRandom) { MentalStateDef mentalStateDef = pawn.MentalStateDef; if (mentalStateDef != null) { if (isRandom) { return(mentalStateDef.blockRandomInteraction); } if (interaction == null) { return(false); } List <InteractionDef> list = isInitiator ? mentalStateDef.blockInteractionInitiationExcept : mentalStateDef.blockInteractionRecipientExcept; if (list != null) { return(!list.Contains(interaction)); } return(false); } return(false); }
public static bool CanInitiateInteraction(Pawn pawn, InteractionDef interactionDef = null) { if (pawn.interactions == null) { return(false); } if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Talking)) { return(false); } if (!pawn.Awake()) { return(false); } if (pawn.IsBurning()) { return(false); } if (pawn.IsInteractionBlocked(interactionDef, isInitiator: true, isRandom: false)) { return(false); } return(true); }
public bool TryInteractWith(Pawn recipient, InteractionDef intDef) { if (DebugSettings.alwaysSocialFight) { intDef = InteractionDefOf.Insult; } if (this.pawn == recipient) { Log.Warning(this.pawn + " tried to interact with self, interaction=" + intDef.defName, false); return(false); } if (!this.CanInteractNowWith(recipient)) { return(false); } if (this.InteractedTooRecentlyToInteract()) { Log.Error(string.Concat(new object[] { this.pawn, " tried to do interaction ", intDef, " to ", recipient, " only ", Find.TickManager.TicksGame - this.lastInteractionTime, " ticks since last interaction (min is ", 120, ")." }), false); return(false); } List <RulePackDef> list = new List <RulePackDef>(); if (intDef.initiatorThought != null) { Pawn_InteractionsTracker.AddInteractionThought(this.pawn, recipient, intDef.initiatorThought); } if (intDef.recipientThought != null && recipient.needs.mood != null) { Pawn_InteractionsTracker.AddInteractionThought(recipient, this.pawn, intDef.recipientThought); } if (intDef.initiatorXpGainSkill != null) { this.pawn.skills.Learn(intDef.initiatorXpGainSkill, (float)intDef.initiatorXpGainAmount, false); } if (intDef.recipientXpGainSkill != null && recipient.RaceProps.Humanlike) { recipient.skills.Learn(intDef.recipientXpGainSkill, (float)intDef.recipientXpGainAmount, false); } bool flag = false; if (recipient.RaceProps.Humanlike) { flag = recipient.interactions.CheckSocialFightStart(intDef, this.pawn); } string text; string label; LetterDef letterDef; if (!flag) { intDef.Worker.Interacted(this.pawn, recipient, list, out text, out label, out letterDef); } else { text = null; label = null; letterDef = null; } MoteMaker.MakeInteractionBubble(this.pawn, recipient, intDef.interactionMote, intDef.Symbol); this.lastInteractionTime = Find.TickManager.TicksGame; if (flag) { list.Add(RulePackDefOf.Sentence_SocialFightStarted); } PlayLogEntry_Interaction playLogEntry_Interaction = new PlayLogEntry_Interaction(intDef, this.pawn, recipient, list); Find.PlayLog.Add(playLogEntry_Interaction); if (letterDef != null) { string text2 = playLogEntry_Interaction.ToGameStringFromPOV(this.pawn, false); if (!text.NullOrEmpty()) { text2 = text2 + "\n\n" + text; } Find.LetterStack.ReceiveLetter(label, text2, letterDef, this.pawn, null, null); } return(true); }
internal float <> m__0(InteractionDef x) { return(x.Worker.RandomSelectionWeight(this.$this.pawn, this.p)); }
public float SocialFightChance(InteractionDef interaction, Pawn initiator) { float result; if (!this.pawn.RaceProps.Humanlike || !initiator.RaceProps.Humanlike) { result = 0f; } else if (!InteractionUtility.HasAnyVerbForSocialFight(this.pawn) || !InteractionUtility.HasAnyVerbForSocialFight(initiator)) { result = 0f; } else if (this.pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { result = 0f; } else if (initiator.Downed || this.pawn.Downed) { result = 0f; } else { float num = interaction.socialFightBaseChance; num *= Mathf.InverseLerp(0.3f, 1f, this.pawn.health.capacities.GetLevel(PawnCapacityDefOf.Manipulation)); num *= Mathf.InverseLerp(0.3f, 1f, this.pawn.health.capacities.GetLevel(PawnCapacityDefOf.Moving)); List <Hediff> hediffs = this.pawn.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i].CurStage != null) { num *= hediffs[i].CurStage.socialFightChanceFactor; } } float num2 = (float)this.pawn.relations.OpinionOf(initiator); if (num2 < 0f) { num *= GenMath.LerpDouble(-100f, 0f, 4f, 1f, num2); } else { num *= GenMath.LerpDouble(0f, 100f, 1f, 0.6f, num2); } if (this.pawn.RaceProps.Humanlike) { List <Trait> allTraits = this.pawn.story.traits.allTraits; for (int j = 0; j < allTraits.Count; j++) { num *= allTraits[j].CurrentData.socialFightChanceFactor; } } int num3 = Mathf.Abs(this.pawn.ageTracker.AgeBiologicalYears - initiator.ageTracker.AgeBiologicalYears); if (num3 > 10) { if (num3 > 50) { num3 = 50; } num *= GenMath.LerpDouble(10f, 50f, 1f, 0.25f, (float)num3); } result = Mathf.Clamp01(num); } return(result); }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDespawnedNullOrForbidden(TargetIndex.A); this.FailOn(() => !base.Patient.InBed() || !base.Patient.Awake()); if (base.Chair != null) { this.FailOnDespawnedNullOrForbidden(TargetIndex.B); } if (base.Chair != null) { this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell); if (!this.$disposing) { this.$PC = 1; } return(true); } this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell); if (!this.$disposing) { this.$PC = 2; } return(true); case 1u: break; case 2u: break; case 3u: { Toil waitAndTalk = new Toil(); waitAndTalk.tickAction = delegate() { base.Patient.needs.joy.GainJoy(this.job.def.joyGainRate * 0.000144f, this.job.def.joyKind); if (this.pawn.IsHashIntervalTick(320)) { InteractionDef intDef = (Rand.Value >= 0.8f) ? InteractionDefOf.DeepTalk : InteractionDefOf.Chitchat; this.pawn.interactions.TryInteractWith(base.Patient, intDef); } this.pawn.rotationTracker.FaceCell(base.Patient.Position); this.pawn.GainComfortFromCellIfPossible(); JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.None, 1f, null); if (this.pawn.needs.joy.CurLevelPercentage > 0.9999f && base.Patient.needs.joy.CurLevelPercentage > 0.9999f) { this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded, true); } }; waitAndTalk.handlingFacing = true; waitAndTalk.socialMode = RandomSocialMode.Off; waitAndTalk.defaultCompleteMode = ToilCompleteMode.Delay; waitAndTalk.defaultDuration = this.job.def.joyDuration; this.$current = waitAndTalk; if (!this.$disposing) { this.$PC = 4; } return(true); } case 4u: this.$PC = -1; return(false); default: return(false); } this.$current = Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn); if (!this.$disposing) { this.$PC = 3; } return(true); }
public bool TryInteractWith(Pawn recipient, InteractionDef intDef) { if (DebugSettings.alwaysSocialFight) { intDef = InteractionDefOf.Insult; } if (pawn == recipient) { Log.Warning(pawn + " tried to interact with self, interaction=" + intDef.defName); return(false); } if (!CanInteractNowWith(recipient, intDef)) { return(false); } if (InteractedTooRecentlyToInteract()) { Log.Error(pawn + " tried to do interaction " + intDef + " to " + recipient + " only " + (Find.TickManager.TicksGame - lastInteractionTime) + " ticks since last interaction (min is " + 120 + ")."); return(false); } List <RulePackDef> list = new List <RulePackDef>(); if (intDef.initiatorThought != null) { AddInteractionThought(pawn, recipient, intDef.initiatorThought); } if (intDef.recipientThought != null && recipient.needs.mood != null) { AddInteractionThought(recipient, pawn, intDef.recipientThought); } if (intDef.initiatorXpGainSkill != null) { pawn.skills.Learn(intDef.initiatorXpGainSkill, intDef.initiatorXpGainAmount); } if (intDef.recipientXpGainSkill != null && recipient.RaceProps.Humanlike) { recipient.skills.Learn(intDef.recipientXpGainSkill, intDef.recipientXpGainAmount); } bool flag = false; if (recipient.RaceProps.Humanlike) { flag = recipient.interactions.CheckSocialFightStart(intDef, pawn); } string letterText; string letterLabel; LetterDef letterDef; LookTargets lookTargets; if (!flag) { intDef.Worker.Interacted(pawn, recipient, list, out letterText, out letterLabel, out letterDef, out lookTargets); } else { letterText = null; letterLabel = null; letterDef = null; lookTargets = null; } MoteMaker.MakeInteractionBubble(pawn, recipient, intDef.interactionMote, intDef.Symbol); lastInteractionTime = Find.TickManager.TicksGame; if (flag) { list.Add(RulePackDefOf.Sentence_SocialFightStarted); } PlayLogEntry_Interaction playLogEntry_Interaction = new PlayLogEntry_Interaction(intDef, pawn, recipient, list); Find.PlayLog.Add(playLogEntry_Interaction); if (letterDef != null) { string text = playLogEntry_Interaction.ToGameStringFromPOV(pawn); if (!letterText.NullOrEmpty()) { text = text + "\n\n" + letterText; } Find.LetterStack.ReceiveLetter(letterLabel, text, letterDef, lookTargets ?? ((LookTargets)pawn)); } return(true); }