na most elvileg a grok fixálta de nem hinnem xd
This commit is contained in:
150
Main.cs
150
Main.cs
@@ -350,6 +350,47 @@ namespace KCM
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
FixedUpdateInterval++;
|
FixedUpdateInterval++;
|
||||||
|
|
||||||
|
// Force AI updates in multiplayer every few frames
|
||||||
|
if (KCClient.client.IsConnected && FixedUpdateInterval % 60 == 0 && Time.timeScale > 0)
|
||||||
|
{
|
||||||
|
ForceMultiplayerAIUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ForceMultiplayerAIUpdate()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var player in kCPlayers.Values)
|
||||||
|
{
|
||||||
|
if (player?.inst == null) continue;
|
||||||
|
|
||||||
|
// Force villager AI updates
|
||||||
|
for (int i = 0; i < player.inst.Workers.Count; i++)
|
||||||
|
{
|
||||||
|
Villager v = player.inst.Workers.data[i];
|
||||||
|
if (v != null && v.brain != null)
|
||||||
|
{
|
||||||
|
v.brain.Think();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force homeless to find jobs
|
||||||
|
for (int i = 0; i < player.inst.Homeless.Count; i++)
|
||||||
|
{
|
||||||
|
Villager v = player.inst.Homeless.data[i];
|
||||||
|
if (v != null && v.workerJob == null)
|
||||||
|
{
|
||||||
|
JobSystem.inst?.TryAssignJob(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
helper?.Log("Error in ForceMultiplayerAIUpdate: " + e.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region "TransitionTo"
|
#region "TransitionTo"
|
||||||
@@ -900,6 +941,86 @@ namespace KCM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Force AI system restart in multiplayer
|
||||||
|
[HarmonyPatch(typeof(VillagerSystem), "Update")]
|
||||||
|
public class VillagerSystemUpdateHook
|
||||||
|
{
|
||||||
|
public static void Postfix()
|
||||||
|
{
|
||||||
|
if (KCClient.client.IsConnected && Time.timeScale > 0)
|
||||||
|
{
|
||||||
|
// Force AI brain updates for all villagers in multiplayer
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Villager.villagers.Count; i++)
|
||||||
|
{
|
||||||
|
Villager v = Villager.villagers.data[i];
|
||||||
|
if (v != null && v.brain != null && v.workerJob != null)
|
||||||
|
{
|
||||||
|
// Force brain to think and update
|
||||||
|
v.brain.Think();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
helper?.Log("Error forcing AI update: " + e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force job system updates in multiplayer
|
||||||
|
[HarmonyPatch(typeof(JobSystem), "Update")]
|
||||||
|
public class JobSystemUpdateHook
|
||||||
|
{
|
||||||
|
public static void Postfix()
|
||||||
|
{
|
||||||
|
if (KCClient.client.IsConnected && Time.timeScale > 0)
|
||||||
|
{
|
||||||
|
// Force job assignments and updates
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Force homeless villagers to find jobs
|
||||||
|
if (Player.inst != null && Player.inst.Homeless != null)
|
||||||
|
{
|
||||||
|
for (int i = Player.inst.Homeless.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
Villager v = Player.inst.Homeless.data[i];
|
||||||
|
if (v != null && v.workerJob == null)
|
||||||
|
{
|
||||||
|
// Try to assign a job
|
||||||
|
JobSystem.inst.TryAssignJob(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
helper?.Log("Error forcing job assignment: " + e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force AI restart when game is unpaused
|
||||||
|
[HarmonyPatch(typeof(SpeedControlUI), "SetPaused")]
|
||||||
|
public class SpeedControlUISetPausedHook
|
||||||
|
{
|
||||||
|
public static void Postfix(bool paused)
|
||||||
|
{
|
||||||
|
if (!KCClient.client.IsConnected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!paused)
|
||||||
|
{
|
||||||
|
// Game is unpaused, force AI restart
|
||||||
|
helper.Log("Game unpaused, forcing AI restart");
|
||||||
|
ForceMultiplayerAIUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(VillagerSystem), "AddVillager")]
|
[HarmonyPatch(typeof(VillagerSystem), "AddVillager")]
|
||||||
public class PlayerAddVillagerHook
|
public class PlayerAddVillagerHook
|
||||||
{
|
{
|
||||||
@@ -1118,18 +1239,27 @@ namespace KCM
|
|||||||
[HarmonyPatch(typeof(SpeedControlUI), "SetSpeed")]
|
[HarmonyPatch(typeof(SpeedControlUI), "SetSpeed")]
|
||||||
public class SpeedControlUISetSpeedHook
|
public class SpeedControlUISetSpeedHook
|
||||||
{
|
{
|
||||||
private static long lastTime = 0;
|
public static void Postfix(int idx)
|
||||||
|
|
||||||
public static bool Prefix(ref bool __state)
|
|
||||||
{
|
{
|
||||||
__state = false;
|
if (!KCClient.client.IsConnected)
|
||||||
if (KCClient.client.IsConnected)
|
return;
|
||||||
|
|
||||||
|
helper.Log("SpeedControlUI.SetSpeed (local): " + idx);
|
||||||
|
|
||||||
|
// Force AI restart when speed changes from paused to playing
|
||||||
|
if (idx > 0)
|
||||||
{
|
{
|
||||||
bool calledFromPacket = false;
|
ForceMultiplayerAIUpdate();
|
||||||
try
|
}
|
||||||
{
|
|
||||||
calledFromPacket = new StackFrame(3).GetMethod().Name.Contains("HandlePacket");
|
bool isPaused = (idx == 0);
|
||||||
}
|
new SetSpeed()
|
||||||
|
{
|
||||||
|
speed = idx,
|
||||||
|
isPaused = isPaused
|
||||||
|
}.Send();
|
||||||
|
}
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user