|
- 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;
- using RobocraftX.Physics;
-
- using GamecraftModdingAPI.Commands;
-
- namespace ExtraCommands.Waypoints
- {
- [CustomCommand("Waypoints")]
- class TeleportWaypointCommandEngine : ICustomCommandEngine
- {
- private Dictionary<object, float[]> _waypoints = new Dictionary<object, float[]>();
-
- public string Description => "";
-
- public string Name => "Waypoints";
-
- public IEntitiesDB entitiesDB { set; private get; }
-
- public void Ready()
- {
- CommandRegistrationHelper.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location");
- CommandRegistrationHelper.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint");
- }
-
- private void CreateWaypointCommand(object name)
- {
- RigidBodyEntityStruct reference;
- if (entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.OnFootGroup, out uint index,
- out RigidBodyEntityStruct[] array)
- || entitiesDB.TryQueryEntitiesAndIndex(0u, CharacterExclusiveGroups.InPilotSeatGroup, out index,
- out array))
- reference = array[index];
- else
- {
- Log.Output("Player not found!");
- return;
- }
- _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;
- }
-
- if (entitiesDB.Exists<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.InPilotSeatGroup))
- {
- Log.Error("Cannot teleport from a pilot seat");
- return;
- }
- float[] loc = _waypoints[name];
- uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
- }
-
- public void Dispose()
- {
- CommandRegistrationHelper.Unregister("CreateWaypoint");
- CommandRegistrationHelper.Unregister("TeleportPlayerWaypoint");
- }
- }
- }
|