2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2014, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Collections.Generic;
34 using System.Text.RegularExpressions;
35 using System.Windows.Forms;
39 namespace Radegast.Commands
41 public class GoCommand : RadegastCommand
44 RegexOptions regexOptions = RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase;
45 TabsConsole TC { get { return Instance.TabConsole; } }
46 ObjectsConsole Objects;
48 Vector3 targetPos = Vector3.Zero;
51 public GoCommand(RadegastInstance instance)
55 Description = "Moves avatar";
56 Usage = "go [tp] (distance|xyz|object|person|help) [additional args] (type \"" + CommandsManager.CmdPrefix + "go help\" for full usage)";
58 subCommand = new Regex(@"(?<subcmd>.*)\s*=\s*(?<subarg>.*)", regexOptions);
59 Chat = (ChatConsole)TC.Tabs["chat"].Control;
62 public override void Dispose()
71 wl("Wrong arguments for \"go\" command. For detailed description type: " + CommandsManager.CmdPrefix + "go help");
78 {0}go [tp] (distance|xyz|object|person|help) [additional args]
79 - tp is an optional parameter after go command. If speciefied use teleport instead of walking to reach the destination when parcel permits it.
82 Specifies distance in meters to move with optional direction. If direction is not specified we move forward.
84 {0}go 10 -- moves 10m forward
85 {0}go 15 e -- moves 15m to the east
86 {0}go tp 20 se -- teleports 20m to the southeast of our current position
89 Moves to X, Y and optionally Z coordinate
91 {0}go xyz 128,128 -- walks toward the center of the sim, using our current elevation (Z)
92 {0}go tp xyz 32,32,128 -- teleports to postion 32,32,128 within our current region
95 Moves towards a named object
97 {0}go object desk chair -- walk toward the closest object whose name begins with ""desk chair""
98 {0}go tp object dance floor -- teleports to the closest object whose name beings with ""dance floor""
101 Moves toward a person
103 {0}go person Latif -- walk toward the closest person whose name begins with Latif
104 {0}go tp person John -- teleports to the closest person whose name begins with John", CommandsManager.CmdPrefix);
107 public override void Execute(string name, string[] cmdArgs, ConsoleWriteLine WriteLine)
109 if (Chat.InvokeRequired)
111 if (!Instance.MonoRuntime || Chat.IsHandleCreated)
112 Chat.Invoke(new MethodInvoker(() => Execute(name, cmdArgs, WriteLine)));
117 string cmd = string.Join(" ", cmdArgs);
118 List<string> args = new List<string>(Regex.Split(cmd, @"\s", regexOptions));
120 if (args.Count == 0) { PrintUsage(); return; }
129 if (args.Count == 0) { PrintUsage(); return; }
131 string subcmd = args[0];
133 string subarg = string.Empty;
135 // Move certain distance
137 if (int.TryParse(subcmd, out distance))
139 if (distance < 1) return;
140 Quaternion heading = Client.Self.Movement.BodyRotation;
141 KnownHeading kh = null;
145 kh = StateManager.KnownHeadings.Find((KnownHeading h) => { return h.ID == args[0].ToUpper(); });
147 heading = kh.Heading;
150 targetPos = Client.Self.SimPosition + new Vector3((float)distance, 0f, 0f) * heading;
151 Client.Self.Movement.BodyRotation = Client.Self.Movement.HeadRotation = heading;
152 Client.Self.Movement.Camera.LookAt(Client.Self.SimPosition, targetPos);
153 Client.Self.Movement.SendUpdate(true);
154 WriteLine("Going {0} to {1:0},{2:0},{3:0}", kh == null ? string.Empty : kh.Name, targetPos.X, targetPos.Y, targetPos.Z);
155 Instance.State.MoveTo(targetPos, useTP);
159 if (subcmd == "help")
165 if (args.Count == 0) { PrintUsage(); return; }
166 subarg = string.Join(" ", args.ToArray());
172 string[] coords = Regex.Split(subarg, @"\D+");
173 if (coords.Length < 2) { PrintUsage(); return; }
174 int x = int.Parse(coords[0]);
175 int y = int.Parse(coords[1]);
176 int z = coords.Length > 2 ? int.Parse(coords[2]) : (int)Client.Self.SimPosition.Z;
177 targetPos = new Vector3(x, y, z);
178 WriteLine("Going to {0:0},{1:0},{2:0}", targetPos.X, targetPos.Y, targetPos.Z);
179 Instance.State.MoveTo(targetPos, useTP);
183 List<UUID> people = Chat.GetAvatarList();
184 UUID person = people.Find((UUID id) => { return Instance.Names.Get(id).ToLower().StartsWith(subarg.ToLower()); });
185 if (person == UUID.Zero)
187 WriteLine("Could not find {0}", subarg);
190 string pname = Instance.Names.Get(person);
192 targetPos = Vector3.Zero;
194 if (!Instance.State.TryFindAvatar(person, out targetPos))
196 WriteLine("Could not locate {0}", pname);
200 WriteLine("Going to {3} at {0:0},{1:0},{2:0}", targetPos.X, targetPos.Y, targetPos.Z, pname);
201 Instance.State.MoveTo(targetPos, useTP);
207 if (!TC.TabExists("objects"))
209 RadegastTab tab = TC.AddTab("objects", "Objects", new ObjectsConsole(Instance));
210 tab.AllowClose = true;
211 tab.AllowDetach = true;
213 tab.AllowHide = false;
214 ((ObjectsConsole)tab.Control).RefreshObjectList();
215 WriteLine("Objects list was not active. Started getting object names, please try again in a minute.");
216 TC.Tabs["chat"].Select();
220 Objects = (ObjectsConsole)TC.Tabs["objects"].Control;
221 List<Primitive> prims = Objects.GetObjectList();
223 Primitive target = prims.Find((Primitive prim) =>
225 return prim.Properties != null
226 && prim.Properties.Name.ToLower().Contains(subarg.ToLower());
231 WriteLine("Could not find '{0}' nearby", subarg);
235 targetPos = target.Position;
237 WriteLine("Going to object '{0}' at {1:0},{2:0},{3:0}", target.Properties.Name, targetPos.X, targetPos.Y, targetPos.Z);
238 Instance.State.MoveTo(targetPos, useTP);
242 WriteLine("Unrecognized go command {0}", subcmd);