using QSB.EchoesOfTheEye.Ghosts.WorldObjects; using QSB.Messaging; using QSB.Utility; using QSB.WorldSync; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; namespace QSB.EchoesOfTheEye.Ghosts.Messages; internal class PathfindNodeMessage : QSBWorldObjectMessage { public PathfindNodeMessage(GhostNode node, float speed, float acceleration) : base(Process(node, speed, acceleration)) { } private static (int mapId, int nodeIndex, float speed, float acceleration) Process(GhostNode node, float speed, float acceleration) { (int mapId, int nodeId, float speed, float acceleration) ret = new(); ret.speed = speed; ret.acceleration = acceleration; var nodeMaps = QSBWorldSync.GetWorldObjects(); var owner = nodeMaps.First(x => x.AttachedObject._nodes.Contains(node)); ret.mapId = owner.ObjectId; ret.nodeId = Array.IndexOf(owner.AttachedObject._nodes, node); return ret; } public override void OnReceiveRemote() { if (QSBCore.IsHost) { DebugLog.ToConsole($"Error - Received PathfindNodeMessage on host. Something has gone horribly wrong!", OWML.Common.MessageType.Error); return; } DebugLog.DebugWrite($"{WorldObject.AttachedObject.name} Pathfind to node {Data.nodeIndex} on map {Data.mapId} with speed:{Data.speed}, acceleration:{Data.acceleration}"); var map = QSBWorldSync.GetWorldObject(Data.mapId); var node = map.AttachedObject._nodes[Data.nodeIndex]; WorldObject.AttachedObject.PathfindToNode(node, Data.speed, Data.acceleration); } }