- Add LogSync() helper method in Main.cs for consistent sync logging - Log all packet send/receive events in PacketHandler and Packet classes - Add detailed building placement logging in WorldPlace.cs (all properties, final state) - Add building state update logging in BuildingStatePacket.cs - Add building state send logging in BuildingStateManager.cs All sync logs are prefixed with [SYNC] for easy filtering. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66 lines
2.6 KiB
C#
66 lines
2.6 KiB
C#
using KCM.Packets;
|
|
using KCM.Packets.State;
|
|
using KCM.StateManagement.Observers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static KCM.StateManagement.Observers.Observer;
|
|
|
|
namespace KCM.StateManagement.BuildingState
|
|
{
|
|
public class BuildingStateManager
|
|
{
|
|
|
|
public static void BuildingStateChanged(object sender, StateUpdateEventArgs args)
|
|
{
|
|
|
|
}
|
|
|
|
public static void SendBuildingUpdate(object sender, StateUpdateEventArgs args)
|
|
{
|
|
try
|
|
{
|
|
Observer observer = (Observer)sender;
|
|
|
|
Building building = (Building)observer.state;
|
|
|
|
Main.LogSync($"SENDING building state update for: {building.UniqueName} guid={building.guid}");
|
|
Main.LogSync($" position={building.transform.position}");
|
|
if (building.transform.childCount > 0)
|
|
{
|
|
Main.LogSync($" rotation={building.transform.GetChild(0).rotation} (euler={building.transform.GetChild(0).rotation.eulerAngles})");
|
|
}
|
|
|
|
new BuildingStatePacket()
|
|
{
|
|
customName = building.customName,
|
|
guid = building.guid,
|
|
uniqueName = building.UniqueName,
|
|
rotation = building.transform.GetChild(0).rotation,
|
|
globalPosition = building.transform.position,
|
|
localPosition = building.transform.GetChild(0).localPosition,
|
|
built = building.IsBuilt(),
|
|
placed = building.IsPlaced(),
|
|
open = building.Open,
|
|
doBuildAnimation = building.doBuildAnimation,
|
|
constructionPaused = building.constructionPaused,
|
|
constructionProgress = building.constructionProgress,
|
|
resourceProgress = (float)building.GetType().GetField("resourceProgress", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(building),
|
|
life = building.Life,
|
|
ModifiedMaxLife = building.ModifiedMaxLife,
|
|
yearBuilt = building.YearBuilt,
|
|
decayProtection = building.decayProtection,
|
|
seenByPlayer = building.seenByPlayer
|
|
}.Send();
|
|
} catch (Exception e)
|
|
{
|
|
Main.helper.Log("ERror sending building state packet");
|
|
Main.helper.Log(e.Message);
|
|
Main.helper.Log(e.StackTrace);
|
|
}
|
|
}
|
|
}
|
|
}
|