PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/Aurora/BotManager/BotPrimController.cs

https://bitbucket.org/VirtualReality/software-testing
C# | 157 lines | 132 code | 23 blank | 2 comment | 12 complexity | f23a559062333a8e24122355a6df4dc7 MD5 | raw file
  1using Aurora.Framework;
  2using Aurora.Framework.ClientInterfaces;
  3using Aurora.Framework.Modules;
  4using Aurora.Framework.Physics;
  5using Aurora.Framework.SceneInfo;
  6using Aurora.Framework.SceneInfo.Entities;
  7using OpenMetaverse;
  8
  9namespace Aurora.BotManager
 10{
 11    public class BotPrimController : IBotController
 12    {
 13        private ISceneEntity m_object;
 14        private Bot m_bot;
 15        private bool m_run;
 16        private float m_speed = 1;
 17        private bool m_hasStoppedMoving = false;
 18
 19        public BotPrimController(ISceneEntity obj, Bot bot)
 20        {
 21            m_object = obj;
 22            m_bot = bot;
 23        }
 24
 25        public string Name
 26        {
 27            get { return m_object.Name; }
 28        }
 29
 30        public UUID UUID
 31        {
 32            get { return m_object.UUID; }
 33        }
 34
 35        public bool SetAlwaysRun
 36        {
 37            get { return m_run; }
 38            set { m_run = value; }
 39        }
 40
 41        public bool ForceFly
 42        {
 43            get { return false; }
 44            set { }
 45        }
 46
 47        public PhysicsActor PhysicsActor
 48        {
 49            get { return m_object.RootChild.PhysActor; }
 50        }
 51
 52        public bool CanMove
 53        {
 54            get { return true; }
 55        }
 56
 57        public Vector3 AbsolutePosition
 58        {
 59            get { return m_object.AbsolutePosition; }
 60        }
 61
 62        public void SendChatMessage(int sayType, string message, int channel)
 63        {
 64            IChatModule chatModule = m_object.Scene.RequestModuleInterface<IChatModule>();
 65            if (chatModule != null)
 66                chatModule.SimChat(message, (ChatTypeEnum) sayType, channel,
 67                                   m_object.RootChild.AbsolutePosition, m_object.Name, m_object.UUID, false,
 68                                   m_object.Scene);
 69        }
 70
 71        public void SendInstantMessage(GridInstantMessage im)
 72        {
 73            IMessageTransferModule m_TransferModule =
 74                m_object.Scene.RequestModuleInterface<IMessageTransferModule>();
 75            if (m_TransferModule != null)
 76                m_TransferModule.SendInstantMessage(im);
 77        }
 78
 79        public void Close()
 80        {
 81        }
 82
 83        public void OnBotAgentUpdate(Vector3 toward, uint controlFlag, Quaternion bodyRotation)
 84        {
 85            OnBotAgentUpdate(toward, controlFlag, bodyRotation, true);
 86        }
 87
 88        public void OnBotAgentUpdate(Vector3 toward, uint controlFlag, Quaternion bodyRotation, bool isMoving)
 89        {
 90            if (isMoving)
 91                m_hasStoppedMoving = false;
 92            m_object.AbsolutePosition += toward*(m_speed*(1f/45f));
 93            m_object.ScheduleGroupTerseUpdate();
 94        }
 95
 96        public void UpdateMovementAnimations(bool sendTerseUpdate)
 97        {
 98            if (sendTerseUpdate)
 99                m_object.ScheduleGroupTerseUpdate();
100        }
101
102        public void Teleport(OpenMetaverse.Vector3 pos)
103        {
104            m_object.AbsolutePosition = pos;
105        }
106
107        public IScene GetScene()
108        {
109            return m_object.Scene;
110        }
111
112        public void StopMoving(bool fly, bool clearPath)
113        {
114            if (m_hasStoppedMoving)
115                return;
116            m_hasStoppedMoving = true;
117            m_bot.State = BotState.Idle;
118            //Clear out any nodes
119            if (clearPath)
120                m_bot.m_nodeGraph.Clear();
121            //Send the stop message
122            m_bot.m_movementFlag = (uint) AgentManager.ControlFlags.NONE;
123            if (fly)
124                m_bot.m_movementFlag |= (uint) AgentManager.ControlFlags.AGENT_CONTROL_FLY;
125            OnBotAgentUpdate(Vector3.Zero, m_bot.m_movementFlag, m_bot.m_bodyDirection, false);
126
127            if (m_object.RootChild.PhysActor != null)
128                m_object.RootChild.PhysActor.ForceSetVelocity(Vector3.Zero);
129        }
130
131        public void SetSpeedModifier(float speed)
132        {
133            if (speed > 4)
134                speed = 4;
135            m_speed = speed;
136        }
137
138        public void SetDrawDistance(float draw)
139        {
140        }
141
142        public void StandUp()
143        {
144        }
145
146        public void Jump()
147        {
148            m_bot.m_nodeGraph.Clear();
149            m_bot.m_nodeGraph.FollowIndefinitely = false;
150            m_bot.m_nodeGraph.Add(m_object.AbsolutePosition + new Vector3(0, 0, 1.5f), TravelMode.Walk);
151            m_bot.m_nodeGraph.Add(m_object.AbsolutePosition, TravelMode.Walk);
152            m_bot.ForceCloseToPoint = true;
153            m_bot.m_closeToPoint = 0.1f;
154            m_bot.GetNextDestination();
155        }
156    }
157}