diff --git a/RW_NodeTree/CompChildNodeProccesser.cs b/RW_NodeTree/CompChildNodeProccesser.cs index e2c0952..2666c0a 100644 --- a/RW_NodeTree/CompChildNodeProccesser.cs +++ b/RW_NodeTree/CompChildNodeProccesser.cs @@ -112,74 +112,6 @@ public override bool AllowStackWith(Thing other) public override void CompTick() { ChildNodes.ThingOwnerTick(); - IList list = ChildNodes; - for (int i = list.Count - 1; i >= 0; i--) - { - Thing t = list[i]; - if (t.def.tickerType == TickerType.Never) - { - if ((t is IVerbOwner) || (t as ThingWithComps)?.AllComps.Find(x => x is IVerbOwner) != null || (CompChildNodeProccesser)t != null) - { - t.Tick(); - if (t.Destroyed) - { - NeedUpdate = true; - } - } - } - } - UpdateNode(); - if (Find.TickManager.TicksGame % 250 == 0) - { - CompTickRare(); - } - } - - public override void CompTickRare() - { - ChildNodes.ThingOwnerTickRare(); - IList list = ChildNodes; - for (int i = list.Count - 1; i >= 0; i--) - { - Thing t = list[i]; - if (t.def.tickerType == TickerType.Never) - { - if ((t is IVerbOwner) || (t as ThingWithComps)?.AllComps.Find(x => x is IVerbOwner) != null || (CompChildNodeProccesser)t != null) - { - t.TickRare(); - if (t.Destroyed) - { - NeedUpdate = true; - } - } - } - } - UpdateNode(); - if (Find.TickManager.TicksGame % 2000 < 250) - { - CompTickLong(); - } - } - - public override void CompTickLong() - { - ChildNodes.ThingOwnerTickLong(); - IList list = ChildNodes; - for (int i = list.Count - 1; i >= 0; i--) - { - Thing t = list[i]; - if (t.def.tickerType == TickerType.Never) - { - if ((t is IVerbOwner) || (t as ThingWithComps)?.AllComps.Find(x => x is IVerbOwner) != null || (CompChildNodeProccesser)t != null) - { - t.TickLong(); - if (t.Destroyed) - { - NeedUpdate = true; - } - } - } - } UpdateNode(); } @@ -867,6 +799,7 @@ public override void ResolveReferences(ThingDef parentDef) public bool VerbDirectOwnerRedictory = false; public bool VerbEquipmentSourceRedictory = true; + public bool VerbTrackerAllVerbRedictory = false; public bool VerbIconVerbInstanceSource = false; public bool NodeIdAutoInsertByRegiested = true; public float ExceedanceFactor = 1f; diff --git a/RW_NodeTree/Patch/Pawn_ApparelTracker_Patcher.cs b/RW_NodeTree/Patch/Pawn_ApparelTracker_Patcher.cs deleted file mode 100644 index b402c08..0000000 --- a/RW_NodeTree/Patch/Pawn_ApparelTracker_Patcher.cs +++ /dev/null @@ -1,50 +0,0 @@ -using HarmonyLib; -using RimWorld; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Verse; - -namespace RW_NodeTree.Patch -{ - - [HarmonyPatch(typeof(Pawn_ApparelTracker))] - internal static partial class Pawn_ApparelTracker_Patcher - { - - [HarmonyPostfix] - [HarmonyPatch( - typeof(Pawn_ApparelTracker), - "ApparelTrackerTick" - )] - private static void PostPawn_ApparelTracker_ApparelTrackerTick(Pawn_ApparelTracker __instance) - { - ThingOwner list = __instance.GetDirectlyHeldThings(); - for (int i = list.Count - 1; i >= 0; i--) - { - Thing t = list[i]; - if (t.def.tickerType != TickerType.Normal) - { - if ((t is IVerbOwner) || (t as ThingWithComps)?.AllComps.Find(x => x is IVerbOwner) != null || (CompChildNodeProccesser)t != null) - { - try - { - t.Tick(); - if (t.Destroyed) - { - list.Remove(t); - } - } - catch(Exception ex) - { - Log.Error(ex.ToString()); - } - } - } - } - } - - } -} diff --git a/RW_NodeTree/Patch/Pawn_EquipmentTracker_Patcher.cs b/RW_NodeTree/Patch/Pawn_EquipmentTracker_Patcher.cs index b98084e..a919bef 100644 --- a/RW_NodeTree/Patch/Pawn_EquipmentTracker_Patcher.cs +++ b/RW_NodeTree/Patch/Pawn_EquipmentTracker_Patcher.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using Mono.Unix.Native; using System; using System.Collections.Generic; using System.Linq; @@ -20,65 +21,10 @@ internal static partial class Pawn_EquipmentTracker_Patcher )] private static bool PrePawn_EquipmentTracker_EquipmentTrackerTick(Pawn_EquipmentTracker __instance) { - ThingOwner list = __instance.GetDirectlyHeldThings(); - list.ThingOwnerTick(); - for (int i = list.Count - 1; i >= 0; i--) - { - Thing t = list[i]; - if (t.def.tickerType != TickerType.Normal) - { - if ((t is IVerbOwner) || (t as ThingWithComps)?.AllComps.Find(x => x is IVerbOwner) != null || (CompChildNodeProccesser)t != null) - { - try - { - t.Tick(); - if (t.Destroyed) - { - list.Remove(t); - } - } - catch(Exception ex) - { - Log.Error(ex.ToString()); - } - } - } - } + __instance.GetDirectlyHeldThings()?.ThingOwnerTick(); return false; } - [HarmonyPostfix] - [HarmonyPatch( - typeof(Pawn_EquipmentTracker), - "EquipmentTrackerTickRare" - )] - private static void PostPawn_EquipmentTracker_EquipmentTrackerTickRare(Pawn_EquipmentTracker __instance) - { - ThingOwner list = __instance.GetDirectlyHeldThings(); - for (int i = list.Count - 1; i >= 0; i--) - { - Thing t = list[i]; - if (t.def.tickerType != TickerType.Rare) - { - if ((t is IVerbOwner) || (t as ThingWithComps)?.AllComps.Find(x => x is IVerbOwner) != null || (CompChildNodeProccesser)t != null) - { - try - { - t.TickRare(); - if (t.Destroyed) - { - list.Remove(t); - } - } - catch(Exception ex) - { - Log.Error(ex.ToString()); - } - } - } - } - } - [HarmonyPostfix] [HarmonyPatch(typeof(Pawn_EquipmentTracker), "GetGizmos")] private static void PostPawn_EquipmentTracker_GetGizmosPostfix(Pawn_EquipmentTracker __instance, ref IEnumerable __result) diff --git a/RW_NodeTree/Patch/ThingOwner_Patcher.cs b/RW_NodeTree/Patch/ThingOwner_Patcher.cs new file mode 100644 index 0000000..0c9485f --- /dev/null +++ b/RW_NodeTree/Patch/ThingOwner_Patcher.cs @@ -0,0 +1,80 @@ +using HarmonyLib; +using Mono.Unix.Native; +using RimWorld; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace RW_NodeTree.Patch +{ + + [HarmonyPatch(typeof(ThingOwner))] + internal static partial class ThingOwner_Patcher + { + + [HarmonyPostfix] + [HarmonyPatch( + typeof(ThingOwner), + "ThingOwnerTick" + )] + private static void PostThingOwner_ThingOwnerTick(ThingOwner __instance, bool removeIfDestroyed) + { + for (int i = __instance.Count - 1; i >= 0; i--) + { + Thing t = __instance[i]; + if ((t is IVerbOwner) || (t as ThingWithComps)?.AllComps.Find(x => x is IVerbOwner) != null || (CompChildNodeProccesser)t != null) + { + try + { + if (t.def.tickerType != TickerType.Normal) + { + t.Tick(); + if (removeIfDestroyed && t.Destroyed) + { + __instance.Remove(t); + } + } + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + } + try + { + if (t.def.tickerType != TickerType.Rare && Find.TickManager.TicksGame % 250 == t.thingIDNumber % 250) + { + t.TickRare(); + if (removeIfDestroyed && t.Destroyed) + { + __instance.Remove(t); + } + } + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + } + try + { + if (t.def.tickerType != TickerType.Long && Find.TickManager.TicksGame % 2000 == t.thingIDNumber % 2000) + { + t.TickLong(); + if (removeIfDestroyed && t.Destroyed) + { + __instance.Remove(t); + } + } + } + catch (Exception ex) + { + Log.Error(ex.ToString()); + } + } + } + } + + } +} diff --git a/RW_NodeTree/Patch/VerbTracker_AllVerbs_Patcher.cs b/RW_NodeTree/Patch/VerbTracker_AllVerbs_Patcher.cs index 1ee8f33..e687c6d 100644 --- a/RW_NodeTree/Patch/VerbTracker_AllVerbs_Patcher.cs +++ b/RW_NodeTree/Patch/VerbTracker_AllVerbs_Patcher.cs @@ -133,7 +133,7 @@ internal List PostVerbTracker_AllVerbs(Type ownerType, List result) //StackTrace stackTrace = new StackTrace(); //StackFrame[] stackFrame = stackTrace.GetFrames(); //if (Prefs.DevMode) Log.Message($"{stackFrame[0].GetMethod()}\n{stackFrame[1].GetMethod()}\n{stackFrame[2].GetMethod()}\n{stackFrame[3].GetMethod()}\n{stackFrame[4].GetMethod()}\n{stackFrame[5].GetMethod()}\n{stackFrame[6].GetMethod()}\n"); - if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType) && !GetOriginalVerb) + if (Props.VerbTrackerAllVerbRedictory && ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType) && !GetOriginalVerb) { for (int i = 0; i < result.Count; i++) { diff --git a/RW_NodeTree/RW_NodeTree.csproj b/RW_NodeTree/RW_NodeTree.csproj index 4687c12..1e78904 100644 --- a/RW_NodeTree/RW_NodeTree.csproj +++ b/RW_NodeTree/RW_NodeTree.csproj @@ -57,7 +57,7 @@ - +