Moar Gamecraft commands!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9KB

  1. using System;
  2. using System.Collections.Generic;
  3. using RobocraftX.GUI.CommandLine;
  4. using RobocraftX.Multiplayer;
  5. using RobocraftX.StateSync;
  6. using RobocraftX.Character;
  7. using Svelto.ECS;
  8. using Unity.Entities;
  9. using uREPL;
  10. using Svelto.Context;
  11. using RobocraftX;
  12. using RobocraftX.Physics;
  13. using GamecraftModdingAPI.Commands;
  14. namespace ExtraCommands.Waypoints
  15. {
  16. [CustomCommand("Waypoints")]
  17. class TeleportWaypointCommandEngine : ICustomCommandEngine
  18. {
  19. private Dictionary<object, float[]> _waypoints = new Dictionary<object, float[]>();
  20. public string Description => "";
  21. public string Name => "Waypoints";
  22. public IEntitiesDB entitiesDB { set; private get; }
  23. public void Ready()
  24. {
  25. CommandRegistrationHelper.Register<object>("CreateWaypoint", CreateWaypointCommand, "Create a waypoint in your current location");
  26. CommandRegistrationHelper.Register<object>("TeleportPlayerWaypoint", TeleportToWaypointCommand, "Teleport to a waypoint");
  27. }
  28. private void CreateWaypointCommand(object name)
  29. {
  30. ref RigidBodyEntityStruct reference = ref entitiesDB.QueryEntity<RigidBodyEntityStruct>(0u, CharacterExclusiveGroups.CharacterGroup);
  31. _waypoints[name] = new float[3] { reference.position.x, reference.position.y, reference.position.z };
  32. uREPL.Log.Output("Saved " + name.ToString());
  33. }
  34. private void TeleportToWaypointCommand(object name)
  35. {
  36. if (!_waypoints.ContainsKey(name))
  37. {
  38. uREPL.Log.Error("Waypoint not found");
  39. return;
  40. }
  41. float[] loc = _waypoints[name];
  42. uREPL.RuntimeCommands.Call<float, float, float>("TeleportPlayerAbsolute", loc[0], loc[1], loc[2]);
  43. }
  44. public void Dispose()
  45. {
  46. CommandRegistrationHelper.Unregister("CreateWaypoint");
  47. CommandRegistrationHelper.Unregister("TeleportPlayerWaypoint");
  48. }
  49. }
  50. }