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 static bool TryInteractRandomly(this Source _this) { var pawn = (Pawn) typeof(Source).GetField("pawn", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_this); if (!IsInteractable(pawn)) { return(false); } var workingList = (List <Pawn>) typeof(Source).GetField("workingList", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); // Had to add // BASE if (_this.InteractedTooRecentlyToInteract()) { return(false); } if (!InteractionUtility.CanInitiateRandomInteraction(pawn)) { return(false); } var collection = pawn.MapHeld.mapPawns.AllPawnsSpawned.Where(IsInteractable).InRandomOrder(); // Added workingList.Clear(); workingList.AddRange(collection); workingList.Shuffle <Pawn>(); List <InteractionDef> allDefsListForReading = DefDatabase <InteractionDef> .AllDefsListForReading; for (int i = 0; i < workingList.Count; i++) { Pawn p = workingList[i]; if (p != pawn && CanInteractNowWith(pawn, p) && InteractionUtility.CanReceiveRandomInteraction(p) && !pawn.HostileTo(p)) { InteractionDef intDef; if (allDefsListForReading.TryRandomElementByWeight((InteractionDef x) => x.Worker.RandomSelectionWeight(pawn, p), out intDef)) { if (_this.TryInteractWith(p, intDef)) { return(true); } Log.Error(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, 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); }