Skip to content

Commit

Permalink
tick updater, verb control
Browse files Browse the repository at this point in the history
  • Loading branch information
Cn-mjt44 committed Aug 12, 2023
1 parent eed4366 commit bffda7c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 176 deletions.
69 changes: 1 addition & 68 deletions RW_NodeTree/CompChildNodeProccesser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,74 +112,6 @@ public override bool AllowStackWith(Thing other)
public override void CompTick()
{
ChildNodes.ThingOwnerTick();
IList<Thing> 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<Thing> 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<Thing> 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();
}

Expand Down Expand Up @@ -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;
Expand Down
50 changes: 0 additions & 50 deletions RW_NodeTree/Patch/Pawn_ApparelTracker_Patcher.cs

This file was deleted.

58 changes: 2 additions & 56 deletions RW_NodeTree/Patch/Pawn_EquipmentTracker_Patcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using Mono.Unix.Native;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -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<Gizmo> __result)
Expand Down
80 changes: 80 additions & 0 deletions RW_NodeTree/Patch/ThingOwner_Patcher.cs
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
}

}
}
2 changes: 1 addition & 1 deletion RW_NodeTree/Patch/VerbTracker_AllVerbs_Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal List<Verb> PostVerbTracker_AllVerbs(Type ownerType, List<Verb> 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++)
{
Expand Down
2 changes: 1 addition & 1 deletion RW_NodeTree/RW_NodeTree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<Compile Include="Patch\Widgets_ThingIcon_Patcher.cs" />
<Compile Include="Patch\GenRecipe_Patcher.cs" />
<Compile Include="Patch\Graphic_RandomRotated_Patcher.cs" />
<Compile Include="Patch\Pawn_ApparelTracker_Patcher.cs" />
<Compile Include="Patch\ThingOwner_Patcher.cs" />
<Compile Include="Patch\StatDrawEntry_Patcher.cs" />
<Compile Include="Patch\Pawn_EquipmentTracker_Patcher.cs" />
<Compile Include="Patch\Pawn_TryGetAttackVerb_Patcher.cs" />
Expand Down

0 comments on commit bffda7c

Please sign in to comment.