using System; using System.Collections.Generic; using RobocraftX.GUI.CommandLine; using RobocraftX.Multiplayer; using RobocraftX.StateSync; using RobocraftX.Character; using Svelto.ECS; using Unity.Entities; using uREPL; using Svelto.Context; using RobocraftX; namespace ExtraCommands.Waypoints { [CustomCommand("CreateWaypoint", "Create a waypoint in your current location")] [CustomCommand("TeleportPlayerWaypoint", "Teleport to a waypoint")] class TeleportWaypointCommandEngine : CustomCommandEngine { private Dictionary _waypoints = new Dictionary(); public TeleportWaypointCommandEngine(UnityContext ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams) { } public override void Ready() { uREPL.RuntimeCommands.Register("CreateWaypoint", CreateWaypointCommand); uREPL.RuntimeCommands.Register("TeleportPlayerWaypoint", TeleportToWaypointCommand); } private void CreateWaypointCommand(object name) { ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity(0u, CharacterExclusiveGroups.CharacterGroup); _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z }; uREPL.Log.Output("Saved " + name.ToString()); } private void TeleportToWaypointCommand(object name) { if (!_waypoints.ContainsKey(name)) { uREPL.Log.Error("Waypoint not found"); return; } float[] loc = _waypoints[name]; uREPL.RuntimeCommands.Call("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]); } public override void Dispose() { uREPL.RuntimeCommands.Unregister("CreateWaypoint"); uREPL.RuntimeCommands.Unregister("TeleportPlayerWaypoint"); } } }