public PlayerPosition(BLObject controller, BLObject pawn) { string rotation = controller["Rotation"] as string; if (rotation == null) return; var rotationMatch = RotationPattern.Value.Match(rotation); if (!rotationMatch.Success) return; string location = pawn["Location"] as string; if (location == null) return; var locationMatch = LocationPattern.Value.Match(location); if (!locationMatch.Success) return; X = double.Parse(locationMatch.Groups[1].Value); Y = double.Parse(locationMatch.Groups[2].Value); Z = double.Parse(locationMatch.Groups[3].Value); Pitch = double.Parse(rotationMatch.Groups[1].Value) / RadiansCoversion; Yaw = double.Parse(rotationMatch.Groups[2].Value) / RadiansCoversion; }
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 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 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"); }
// Temporary until full implementation. private static object Parse(string raw) { object value = BLObject.Parse(raw); if (value != null) return value; return raw; }
// Temporary until full implementation. private static object Parse(string raw) { object value = BLObject.Parse(raw); if (value != null) { return(value); } return(raw); }
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; }
public PlayerPosition(BLObject controller, BLObject pawn) { string rotation = controller["Rotation"] as string; if (rotation == null) { return; } var rotationMatch = RotationPattern.Value.Match(rotation); if (!rotationMatch.Success) { return; } string location = pawn["Location"] as string; if (location == null) { return; } var locationMatch = LocationPattern.Value.Match(location); if (!locationMatch.Success) { return; } X = double.Parse(locationMatch.Groups[1].Value, NumberStyles.AllowDecimalPoint, ci); Y = double.Parse(locationMatch.Groups[2].Value, NumberStyles.AllowDecimalPoint, ci); Z = double.Parse(locationMatch.Groups[3].Value, NumberStyles.AllowDecimalPoint, ci); Pitch = double.Parse(rotationMatch.Groups[1].Value, NumberStyles.AllowDecimalPoint, ci) / RadiansCoversion; // Removed "NumberStyles.AllowDecimalPoint" causes FormatException??? Yaw = double.Parse(rotationMatch.Groups[2].Value, ci) / RadiansCoversion; }
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"); }
/// <summary> /// Performs a getall command for a given class and property, and returns /// a dictionary with the property values keyed by their objects. /// </summary> /// <param name="className">The name of the class to retreive each object for.</param> /// <param name="property">The property to retreive for each object.</param> /// <returns> /// A dictionary in which objects of the class key their value for the /// specified property. If the property contains a singular value, the /// value is a string. If it contains an array, the value is an /// IReadOnlyList<string>. /// </returns> /// public static IReadOnlyDictionary <BLObject, object> GetAll(string className, string property) { // Create the dictionary we will return. var results = new Dictionary <BLObject, object>(); // Run the getall command. If this fails, return the empty results. var output = RunCommand("getall {0} {1}", className, property); if (output == null) { return(results); } // getall results should be in the following format: // <index>) <subclass> <object>.<property> = <value> // Or, if the result's property is an array: // <index>) <subclass> <object>.<property> = Regex objectPattern = new Regex($@"^\d+\) ([^ ]+) (.+)\.{Regex.Escape(property)} =( ?)(.*)$", RegexOptions.Compiled); // The current object and array we are working with. BLObject objectKey = null; List <object> arrayValue = null; // Iterate over each line of output. foreach (string line in output) { // The match for if we test a line for an object result. Match objectMatch; // If we are currently working with an array as an object's value, // we will test the current line for its membership. if (arrayValue != null) { // Check that the current line is of the format for a member of // an array value. var memberMatch = _MemberPattern.Value.Match(line); if (memberMatch.Success) { object value = BLIO.Parse(memberMatch.Groups[1].Value); // If it is, add the captured value to the array, and // proceed on to the next line. arrayValue.Add(value); continue; } // If the line is not a member of the array, check whether it is // of the format denoting a new object. objectMatch = objectPattern.Match(line); if (objectMatch.Success) { // If it is, this indicates the working array value was // complete, so associate with the working object, and null // it to indicate we're no longer working with an array. results[objectKey] = arrayValue; arrayValue = null; } } else { // If we are not currently working with an array, check whether // the line is of the format denoting a new object. If not, skip // this line and proceed to the next one. objectMatch = objectPattern.Match(line); if (!objectMatch.Success) { continue; } } // By now we have a match for an object declaration. Extract the // name and class name from it, and create a new object accordingly. string subclassName = objectMatch.Groups[1].Value; string objectName = objectMatch.Groups[2].Value; objectKey = new BLObject(objectName, subclassName); // If the value capture group for the match did capture, associate // the object with the value. if (objectMatch.Groups[3].Value.Length == 1) { results[objectKey] = BLIO.Parse(objectMatch.Groups[4].Value); } // Otherwise, we are to expect an array as the value, so create a // new list for indicating such and for storing the results. else { arrayValue = new List <object>(); } } // At the end of the results, if we had a working array value, // associate with the working object. if (arrayValue != null) { results[objectKey] = arrayValue; } return(results); }