+++ /dev/null
-using System;\r
-using System.Collections.Generic;\r
-using System.Text;\r
-using System.Timers;\r
-using libsecondlife;\r
-using libsecondlife.Packets;\r
-using SLNetworkComm;\r
-\r
-namespace SLeek\r
-{\r
- public class StateManager\r
- {\r
- private SleekInstance instance;\r
- private SecondLife client;\r
- private SLNetCom netcom;\r
-\r
- private bool typing = false;\r
- private bool away = false;\r
- private bool busy = false;\r
- private bool flying = false;\r
- private bool alwaysrun = false;\r
- private bool sitting = false;\r
- \r
- private bool pointing = false;\r
- private LLUUID pointID;\r
- private LLUUID beamID;\r
-\r
- private bool following = false;\r
- private string followName = string.Empty;\r
- private float followDistance = 3.0f;\r
-\r
- private Timer agentUpdateTicker;\r
-\r
- private LLUUID awayAnimationID = new LLUUID("fd037134-85d4-f241-72c6-4f42164fedee");\r
- private LLUUID busyAnimationID = new LLUUID("efcf670c2d188128973a034ebc806b67");\r
- private LLUUID typingAnimationID = new LLUUID("c541c47f-e0c0-058b-ad1a-d6ae3a4584d9");\r
-\r
- public StateManager(SleekInstance instance)\r
- {\r
- this.instance = instance;\r
- netcom = this.instance.Netcom;\r
- client = this.instance.Client;\r
-\r
- AddNetcomEvents();\r
- AddClientEvents();\r
- InitializeAgentUpdateTimer();\r
- }\r
-\r
- private void AddNetcomEvents()\r
- {\r
- netcom.ClientLoginStatus += new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);\r
- netcom.ClientLoggedOut += new EventHandler(netcom_ClientLoggedOut);\r
- }\r
-\r
- private void netcom_ClientLoggedOut(object sender, EventArgs e)\r
- {\r
- agentUpdateTicker.Enabled = false;\r
- typing = away = busy = false;\r
- }\r
-\r
- private void netcom_ClientLoginStatus(object sender, ClientLoginEventArgs e)\r
- {\r
- if (e.Status == LoginStatus.Success)\r
- agentUpdateTicker.Enabled = true;\r
- }\r
-\r
- private void AddClientEvents()\r
- {\r
- client.Objects.OnObjectUpdated += new ObjectManager.ObjectUpdatedCallback(Objects_OnObjectUpdated);\r
- }\r
-\r
- private void Objects_OnObjectUpdated(Simulator simulator, ObjectUpdate update, ulong regionHandle, ushort timeDilation)\r
- {\r
- if (!update.Avatar) return;\r
- if (!following) return;\r
-\r
- Avatar av;\r
- client.Network.CurrentSim.ObjectsAvatars.TryGetValue(update.LocalID, out av);\r
- if (av == null) return;\r
-\r
- if (av.Name == followName)\r
- {\r
- LLVector3 pos;\r
-\r
- if (av.SittingOn == 0)\r
- {\r
- pos = av.Position;\r
- }\r
- else\r
- {\r
- Primitive prim;\r
- client.Network.CurrentSim.ObjectsPrimitives.TryGetValue(av.SittingOn, out prim);\r
- \r
- if (prim == null)\r
- pos = client.Self.SimPosition;\r
- else\r
- pos = prim.Position + av.Position;\r
- }\r
-\r
- if (LLVector3.Dist(pos, client.Self.SimPosition) > followDistance)\r
- {\r
- int followRegionX = (int)(regionHandle >> 32);\r
- int followRegionY = (int)(regionHandle & 0xFFFFFFFF);\r
- ulong x = (ulong)(pos.X + followRegionX);\r
- ulong y = (ulong)(pos.Y + followRegionY);\r
-\r
- client.Self.AutoPilotCancel();\r
- client.Self.AutoPilot(x, y, pos.Z);\r
- }\r
- }\r
- }\r
-\r
- private void InitializeAgentUpdateTimer()\r
- {\r
- agentUpdateTicker = new Timer(500);\r
- agentUpdateTicker.Elapsed += new ElapsedEventHandler(agentUpdateTicker_Elapsed);\r
- }\r
-\r
- private void agentUpdateTicker_Elapsed(object sender, ElapsedEventArgs e)\r
- {\r
- UpdateStatus();\r
- }\r
-\r
- private void UpdateStatus()\r
- {\r
- //client.Self.Status.Camera.BodyRotation = LLQuaternion.Identity;\r
- //client.Self.Status.Camera.HeadRotation = LLQuaternion.Identity;\r
- //client.Self.Status.Camera.CameraCenter = client.Self.SimPosition;\r
- //client.Self.Status.Camera.CameraAtAxis = new LLVector3(0, 0.9999f, 0);\r
- //client.Self.Status.Camera.CameraLeftAxis = new LLVector3(0.9999f, 0, 0);\r
- //client.Self.Status.Camera.CameraUpAxis = new LLVector3(0, 0, 0.9999f);\r
- client.Self.Movement.Camera.Far = 128.0f;\r
- \r
- client.Self.Movement.Away = away;\r
- client.Self.Movement.Fly = flying;\r
-\r
- //client.Self.Status.SendUpdate();\r
- }\r
-\r
- public void Follow(string name)\r
- {\r
- followName = name;\r
- following = !string.IsNullOrEmpty(followName);\r
- }\r
-\r
- public void SetTyping(bool typing)\r
- {\r
- Dictionary<LLUUID, bool> typingAnim = new Dictionary<LLUUID, bool>();\r
- typingAnim.Add(typingAnimationID, typing);\r
-\r
- client.Self.Animate(typingAnim, true);\r
-\r
- if (typing)\r
- client.Self.Chat(string.Empty, 0, ChatType.StartTyping);\r
- else\r
- client.Self.Chat(string.Empty, 0, ChatType.StopTyping);\r
-\r
- this.typing = typing;\r
- }\r
-\r
- public void SetAway(bool away)\r
- {\r
- Dictionary<LLUUID, bool> awayAnim = new Dictionary<LLUUID, bool>();\r
- awayAnim.Add(awayAnimationID, away);\r
-\r
- client.Self.Animate(awayAnim, false);\r
- this.away = away;\r
- }\r
-\r
- public void SetBusy(bool busy)\r
- {\r
- Dictionary<LLUUID, bool> busyAnim = new Dictionary<LLUUID, bool>();\r
- busyAnim.Add(busyAnimationID, busy);\r
-\r
- client.Self.Animate(busyAnim, false);\r
- this.busy = busy;\r
- }\r
-\r
- public void SetFlying(bool flying)\r
- {\r
- this.flying = flying;\r
- }\r
-\r
- public void SetAlwaysRun(bool alwaysrun)\r
- {\r
- client.Self.Movement.AlwaysRun = alwaysrun;\r
- this.alwaysrun = alwaysrun;\r
- }\r
-\r
- public void SetSitting(bool sitting, LLUUID target)\r
- {\r
- this.sitting = sitting;\r
-\r
- if (sitting)\r
- {\r
- client.Self.RequestSit(target, LLVector3.Zero);\r
- client.Self.Sit();\r
- }\r
- else\r
- {\r
- client.Self.Stand();\r
- }\r
- }\r
-\r
- public void SetPointing(bool pointing, LLUUID target)\r
- {\r
- this.pointing = pointing;\r
-\r
- if (pointing)\r
- {\r
- pointID = LLUUID.Random();\r
- beamID = LLUUID.Random();\r
- client.Self.PointAtEffect(client.Self.SessionID, target, LLVector3d.Zero, PointAtType.Select, pointID);\r
- client.Self.BeamEffect(client.Self.SessionID, target, LLVector3d.Zero, new LLColor(255, 255, 255, 0), 60.0f, beamID);\r
- }\r
- else\r
- {\r
- if (pointID == null || beamID == null) return;\r
-\r
- client.Self.PointAtEffect(LLUUID.Zero, LLUUID.Zero, LLVector3d.Zero, PointAtType.Select, pointID);\r
- client.Self.BeamEffect(LLUUID.Zero, LLUUID.Zero, LLVector3d.Zero, new LLColor(255, 255, 255, 0), 0, beamID);\r
- pointID = null;\r
- beamID = null;\r
- }\r
- }\r
-\r
- public LLUUID TypingAnimationID\r
- {\r
- get { return typingAnimationID; }\r
- set { typingAnimationID = value; }\r
- }\r
- \r
- public LLUUID AwayAnimationID\r
- {\r
- get { return awayAnimationID; }\r
- set { awayAnimationID = value; }\r
- }\r
-\r
- public LLUUID BusyAnimationID\r
- {\r
- get { return busyAnimationID; }\r
- set { busyAnimationID = value; }\r
- }\r
-\r
- public bool IsTyping\r
- {\r
- get { return typing; }\r
- }\r
-\r
- public bool IsAway\r
- {\r
- get { return away; }\r
- }\r
-\r
- public bool IsBusy\r
- {\r
- get { return busy; }\r
- }\r
-\r
- public bool IsFlying\r
- {\r
- get { return flying; }\r
- }\r
-\r
- public bool IsSitting\r
- {\r
- get { return sitting; }\r
- }\r
-\r
- public bool IsPointing\r
- {\r
- get { return pointing; }\r
- }\r
-\r
- public bool IsFollowing\r
- {\r
- get { return following; }\r
- }\r
-\r
- public string FollowName\r
- {\r
- get { return followName; }\r
- set { followName = value; }\r
- }\r
-\r
- public float FollowDistance\r
- {\r
- get { return followDistance; }\r
- set { followDistance = value; }\r
- }\r
- }\r
-}\r