2006-11-22 00:46:33 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using libsecondlife;
|
|
|
|
|
using libsecondlife.Packets;
|
|
|
|
|
|
2006-11-24 22:27:15 +00:00
|
|
|
namespace libsecondlife.TestClient
|
2006-11-22 00:46:33 +00:00
|
|
|
{
|
|
|
|
|
public class FollowCommand: Command
|
|
|
|
|
{
|
2006-12-21 08:53:08 +00:00
|
|
|
SecondLife Client;
|
|
|
|
|
|
|
|
|
|
public FollowCommand(TestClient testClient)
|
2006-11-22 00:46:33 +00:00
|
|
|
{
|
2006-12-21 08:53:08 +00:00
|
|
|
TestClient = testClient;
|
|
|
|
|
Client = (SecondLife)TestClient;
|
|
|
|
|
|
2006-11-22 00:46:33 +00:00
|
|
|
Name = "follow";
|
2006-11-29 06:54:12 +00:00
|
|
|
Description = "Follow another avatar. (usage: follow [FirstName LastName]) If no target is set then will follow master.";
|
2006-11-22 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-21 08:53:08 +00:00
|
|
|
public override string Execute(string[] args, LLUUID fromAgentID)
|
2006-11-22 00:46:33 +00:00
|
|
|
{
|
|
|
|
|
string target = String.Empty;
|
2006-11-29 20:05:19 +00:00
|
|
|
for (int ct = 0; ct < args.Length; ct++)
|
2006-11-22 00:46:33 +00:00
|
|
|
target = target + args[ct] + " ";
|
|
|
|
|
target = target.TrimEnd();
|
2006-11-29 06:54:12 +00:00
|
|
|
|
|
|
|
|
if (target.Length == 0)
|
|
|
|
|
target = TestClient.Master;
|
2006-11-29 20:05:19 +00:00
|
|
|
|
|
|
|
|
if (target.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
if (Follow(target))
|
|
|
|
|
return "Following " + target;
|
|
|
|
|
else
|
|
|
|
|
return "Unable to follow " + target + ". Client may not be able to see that avatar.";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "No target specified and no master is set. usage: follow [FirstName LastName])";
|
|
|
|
|
}
|
2006-11-22 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const float DISTANCE_BUFFER = 3.0f;
|
|
|
|
|
string followName;
|
2006-11-24 22:15:13 +00:00
|
|
|
Avatar followAvatar;
|
2006-11-22 00:46:33 +00:00
|
|
|
|
|
|
|
|
bool Follow(string name)
|
|
|
|
|
{
|
2006-12-19 04:16:34 +00:00
|
|
|
foreach (Avatar av in TestClient.AvatarList.Values)
|
2006-11-22 00:46:33 +00:00
|
|
|
{
|
2006-11-24 22:15:13 +00:00
|
|
|
if (av.Name == name)
|
|
|
|
|
{
|
|
|
|
|
followName = name;
|
|
|
|
|
followAvatar = av;
|
|
|
|
|
Active = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2006-11-22 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2006-11-24 22:15:13 +00:00
|
|
|
|
2006-11-28 07:48:43 +00:00
|
|
|
public override void Think(SecondLife Client)
|
2006-11-24 22:15:13 +00:00
|
|
|
{
|
2006-12-06 00:56:36 +00:00
|
|
|
if (Helpers.VecDist(followAvatar.Position, Client.Self.Position) > DISTANCE_BUFFER)
|
2006-11-24 22:15:13 +00:00
|
|
|
{
|
2006-11-29 06:54:12 +00:00
|
|
|
//move toward target
|
|
|
|
|
if (followAvatar.CurrentRegion.GridRegionData != null)
|
|
|
|
|
{
|
2006-12-13 21:15:49 +00:00
|
|
|
//ulong x = (ulong)(followAvatar.Position.X + (followAvatar.CurrentRegion.GridRegionData.X * 256));
|
|
|
|
|
//ulong y = (ulong)(followAvatar.Position.Y + (followAvatar.CurrentRegion.GridRegionData.Y * 256));
|
2006-11-29 06:54:12 +00:00
|
|
|
Client.Self.AutoPilotLocal(Convert.ToInt32(followAvatar.Position.X), Convert.ToInt32(followAvatar.Position.Y), followAvatar.Position.Z);
|
|
|
|
|
}
|
2006-11-24 22:15:13 +00:00
|
|
|
}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// //stop at current position
|
2006-11-29 09:18:34 +00:00
|
|
|
// LLVector3 myPos = client.Self.Position;
|
|
|
|
|
// client.Self.AutoPilot((ulong)myPos.x, (ulong)myPos.y, myPos.Z);
|
2006-11-24 22:15:13 +00:00
|
|
|
//}
|
|
|
|
|
|
2006-11-28 07:48:43 +00:00
|
|
|
base.Think(Client);
|
2006-11-24 22:15:13 +00:00
|
|
|
}
|
2006-11-22 00:46:33 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|