2022-04-09 22:07:24 +01:00
using QSB.EchoesOfTheEye.Ghosts.WorldObjects ;
using QSB.Messaging ;
using QSB.Utility ;
using QSB.WorldSync ;
using System ;
2022-04-07 08:57:51 +01:00
using System.Collections.Generic ;
2022-04-09 22:07:24 +01:00
using System.Diagnostics ;
2022-04-07 08:57:51 +01:00
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
2022-04-09 22:07:24 +01:00
using UnityEngine ;
2022-04-07 08:57:51 +01:00
namespace QSB.EchoesOfTheEye.Ghosts.Messages ;
2022-04-09 22:07:24 +01:00
internal class PathfindNodeMessage : QSBWorldObjectMessage < QSBGhostController , ( int mapId , int nodeIndex , float speed , float acceleration ) >
2022-04-07 08:57:51 +01:00
{
2022-04-09 22:07:24 +01:00
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 < QSBGhostNodeMap > ( ) ;
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 < QSBGhostNodeMap > ( Data . mapId ) ;
var node = map . AttachedObject . _nodes [ Data . nodeIndex ] ;
WorldObject . AttachedObject . PathfindToNode ( node , Data . speed , Data . acceleration ) ;
}
2022-04-07 08:57:51 +01:00
}