aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ExportBot/Commands/Movement/SitCommand.cs
blob: b9ef6be374c8356a3e4fcc4cbbf846516c2eba27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife;
using libsecondlife.Packets;

namespace libsecondlife.TestClient
{
    public class SitCommand: Command
    {
        public SitCommand(TestClient testClient)
		{
			Name = "sit";
			Description = "Attempt to sit on the closest prim";
		}
			
        public override string Execute(string[] args, LLUUID fromAgentID)
		{
            Primitive closest = null;
		    double closestDistance = Double.MaxValue;

		    lock (Client.SimPrims)
		    {
                if (Client.SimPrims.ContainsKey(Client.Network.CurrentSim))
                {
                    foreach (Primitive p in Client.SimPrims[Client.Network.CurrentSim].Values)
                    {
                        float distance = Helpers.VecDist(Client.Self.Position, p.Position);

                        if (closest == null || distance < closestDistance)
                        {
                            closest = p;
                            closestDistance = distance;
                        }
                    }
                }
		    }

            if (closest != null)
            {
                Client.Self.RequestSit(closest.ID, LLVector3.Zero);
                Client.Self.Sit();

                return "Sat on " + closest.ID + ". Distance: " + closestDistance;
            }
            else
            {
                return "Couldn't find a nearby prim to sit on";
            }
		}
    }
}