public static bool Replacement(Pawn_InteractionsTracker __instance, ref bool __result) { // Added var pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>(); if (!IsInteractable(pawn)) { __result = false; return(false); } var workingList = Traverse.Create(__instance).Field("workingList").GetValue <List <Pawn> >(); // Had to add if (InteractedTooRecentlyToInteract(__instance)) // Changed to own { __result = false; return(false); } // BASE if (!InteractionUtility.CanInitiateRandomInteraction(pawn)) { __result = false; return(false); } var collection = pawn.MapHeld.mapPawns.AllPawnsSpawned.Where(IsInteractable); // 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 (__instance.TryInteractWith(p, intDef)) { __result = true; return(false); } Log.Error(pawn + " failed to interact with " + p); } } } __result = false; return(false); }
public static bool Replacement(Pawn_InteractionsTracker __instance, ref bool __result, Pawn ___pawn, List <Pawn> ___workingList, int ___lastInteractionTime) { // Added if (!IsInteractable(___pawn)) { __result = false; return(false); } if (InteractedTooRecentlyToInteract(___lastInteractionTime)) // Changed to own { __result = false; return(false); } // BASE if (!InteractionUtility.CanInitiateRandomInteraction(___pawn)) { __result = false; return(false); } var collection = ___pawn.MapHeld.mapPawns.AllPawnsSpawned.Where(IsInteractable); // Added ___workingList.Clear(); ___workingList.AddRange(collection); ___workingList.Shuffle(); List <InteractionDef> allDefsListForReading = DefDatabase <InteractionDef> .AllDefsListForReading; foreach (var p in ___workingList) { if (p != ___pawn && CanInteractNowWith(___pawn, p) && InteractionUtility.CanReceiveRandomInteraction(p) && !___pawn.HostileTo(p)) { var p1 = p; if ( allDefsListForReading.TryRandomElementByWeight( x => x.Worker.RandomSelectionWeight(___pawn, p1), out var intDef)) { if (__instance.TryInteractWith(p, intDef)) { __result = true; return(false); } Log.Warning($"{___pawn} failed to interact with {p}."); } } } __result = false; return(false); }
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 static bool TryInteractRandomly(Pawn_InteractionsTracker __instance, ref bool __result) { if (__instance.InteractedTooRecentlyToInteract()) { __result = false; return(false); } if (!InteractionUtility.CanInitiateRandomInteraction(pawn(__instance))) { __result = false; return(false); } List <Pawn> collection = pawn(__instance).Map.mapPawns.SpawnedPawnsInFaction(pawn(__instance).Faction); //Pawn_InteractionsTracker.workingList.Clear(); List <Pawn> workingList = getWorkingList(); //ADDED workingList.AddRange(collection); //REPLACED workingList with local workingList.Shuffle(); //REPLACED workingList with local List <InteractionDef> allDefsListForReading = DefDatabase <InteractionDef> .AllDefsListForReading; for (int i = 0; i < workingList.Count; i++) //REPLACED workingList with local { Pawn p = workingList[i]; //REPLACED workingList with local InteractionDef intDef; if (p != pawn(__instance) && __instance.CanInteractNowWith(p, null) && InteractionUtility.CanReceiveRandomInteraction(p) && !pawn(__instance).HostileTo(p) && allDefsListForReading.TryRandomElementByWeight(delegate(InteractionDef x) { if (!__instance.CanInteractNowWith(p, x)) { return(0f); } return(x.Worker.RandomSelectionWeight(pawn(__instance), p)); }, out intDef)) { if (__instance.TryInteractWith(p, intDef)) { workingList.Clear(); //REPLACED workingList with local __result = true; return(false); } Log.Error(pawn(__instance) + " failed to interact with " + p, false); } } //Pawn_InteractionsTracker.workingList.Clear(); __result = false; return(false); }