public static void SavePosition() { // Get the object for the local player controller. var controller = BLObject.GetPlayerController(); // If we could not, stop and present an error. if (controller == null) goto Failed; // Get the object for the pawn from the player controller. var pawn = controller["Pawn"] as BLObject; // If we could not, stop and present an error. if (pawn == null || pawn.Class != "WillowPlayerPawn") goto Failed; pawn.UsePropertyMode = BLObject.PropertyMode.GetAll; // Save the rotation and location for our controller and pawn. SavedRotation = controller["Rotation"] as string; SavedLocation = pawn["Location"] as string; // Provide feedback to the player. if (ShowFeedback) BLIO.RunCommand("say Saved position"); return; Failed: RunCommand("say Failed to save position"); }
public static void RestorePosition() { // If we have not previously saved a location and position, stop // and present an error. if (SavedRotation == null || SavedLocation == null) goto Failed; // Get the object for the local player controller. var controller = BLObject.GetPlayerController(); // If we could not, stop and present an error. if (controller == null) goto Failed; // Get the object for the pawn from the player controller. var pawn = controller["Pawn"] as BLObject; // If we could not, stop and present an error. if (pawn == null || pawn.Class != "WillowPlayerPawn") goto Failed; // Format the command to set the controller's rotation and pawn's // location. string command = $"set {controller.Name} Rotation {SavedRotation}|set {pawn.Name} Location {SavedLocation}"; PerformAction(command, "Restored position"); return; Failed: RunCommand("say Failed to restore position"); }
public static void MoveLeftRight(double distance) { var controller = BLObject.GetPlayerController(); if (controller == null) { goto Failed; } var pawn = controller["Pawn"] as BLObject; if (pawn == null || pawn.Class != "WillowPlayerPawn") { goto Failed; } var position = new PlayerPosition(controller, pawn); if (position == null) { goto Failed; } position.Yaw += Math.PI / 2; position.X += Math.Cos(position.Yaw) * distance; position.Y += Math.Sin(position.Yaw) * distance; PerformAction($"set {pawn.Name} Location {position.FormatLocation()}", null); return; Failed: RunCommand("say Failed to move position"); }
public static void SavePosition() { // Get the object for the local player controller. var controller = BLObject.GetPlayerController(); // If we could not, stop and present an error. if (controller == null) { goto Failed; } // Get the object for the pawn from the player controller. var pawn = controller["Pawn"] as BLObject; // If we could not, stop and present an error. if (pawn == null || pawn.Class != "WillowPlayerPawn") { goto Failed; } pawn.UsePropertyMode = BLObject.PropertyMode.GetAll; // Save the rotation and location for our controller and pawn. SavedRotation = controller["Rotation"] as string; SavedLocation = pawn["Location"] as string; // Traverse object tree... var info = pawn["WorldInfo"] as BLObject; info.UsePropertyMode = BLObject.PropertyMode.GetAll; var mapLevel = info["CommittedPersistentLevel"] as BLObject; // ... until we can get the map name SavedPositionMap = mapLevel.Name; // Provide feedback to the player. if (ShowFeedback) { BLIO.RunCommand("say Saved position"); } return; Failed: RunCommand("say Failed to save position"); SavedPositionMap = null; }
void SendMapName() { var controller = BLObject.GetPlayerController(); // If we could not, stop and present an error. if (controller == null) { return; } var pawn = controller["Pawn"] as BLObject; if (pawn == null) { return; } pawn.UsePropertyMode = BLObject.PropertyMode.GetAll; var info = pawn["WorldInfo"] as BLObject; if (info == null) { return; } info.UsePropertyMode = BLObject.PropertyMode.GetAll; var mapLevel = info["CommittedPersistentLevel"] as BLObject; var mapMatch = MapNamePattern.Value.Match(mapLevel.Name); if (!mapMatch.Success) { return; } var mapName = mapMatch.Groups[1]; SendUDP(String.Format("MapName Map:{0}", mapName)); }
void RestorePosition(string posData) { var restoreMatch = RestorePosPattern.Value.Match(posData); if (!restoreMatch.Success) { return; } var controller = BLObject.GetPlayerController(); if (controller == null) { return; } // Get the object for the pawn from the player controller. var pawn = controller["Pawn"] as BLObject; // If we could not, stop and present an error. if (pawn == null || pawn.Class != "WillowPlayerPawn") { return; } string mapname = restoreMatch.Groups[1].Value; string location = restoreMatch.Groups[2].Value; string rotation = restoreMatch.Groups[3].Value; //TODO compare Map Names string command = $"set {controller.Name} Rotation {rotation}|set {pawn.Name} Location {location}"; App.PerformAction(command, "Set position"); SendUDP("OK RESTOREPOS"); }