aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs158
1 files changed, 107 insertions, 51 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 4f21d9d..c1da803 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -45,7 +45,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 47 private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>();
48 private Dictionary<UUID, AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>();
49 48
50 public void Initialise(Scene scene, IConfigSource source) 49 public void Initialise(Scene scene, IConfigSource source)
51 { 50 {
@@ -75,35 +74,44 @@ namespace OpenSim.Region.OptionalModules.World.NPC
75 // We are close enough to the target 74 // We are close enough to the target
76 m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name); 75 m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name);
77 76
78 if (presence.PhysicsActor.Flying)
79 {
80 Vector3 targetPos = presence.MoveToPositionTarget;
81 float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
82 if (targetPos.Z - terrainHeight < 0.2)
83 {
84 presence.PhysicsActor.Flying = false;
85 }
86 }
87
88 presence.Velocity = Vector3.Zero; 77 presence.Velocity = Vector3.Zero;
89 presence.AbsolutePosition = presence.MoveToPositionTarget; 78 presence.AbsolutePosition = presence.MoveToPositionTarget;
90 presence.ResetMoveToTarget(); 79 presence.ResetMoveToTarget();
91 80
92 // FIXME: This doesn't work
93 if (presence.PhysicsActor.Flying) 81 if (presence.PhysicsActor.Flying)
94 presence.Animator.TrySetMovementAnimation("HOVER"); 82 {
95 else 83 // A horrible hack to stop the NPC dead in its tracks rather than having them overshoot
96 presence.Animator.TrySetMovementAnimation("STAND"); 84 // the target if flying.
85 // We really need to be more subtle (slow the avatar as it approaches the target) or at
86 // least be able to set collision status once, rather than 5 times to give it enough
87 // weighting so that that PhysicsActor thinks it really is colliding.
88 for (int i = 0; i < 5; i++)
89 presence.PhysicsActor.IsColliding = true;
90
91// Vector3 targetPos = presence.MoveToPositionTarget;
92 if (m_avatars[presence.UUID].LandAtTarget)
93 presence.PhysicsActor.Flying = false;
94
95// float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
96// if (targetPos.Z - terrainHeight < 0.2)
97// {
98// presence.PhysicsActor.Flying = false;
99// }
100 }
101
102// m_log.DebugFormat(
103// "[NPC MODULE]: AgentControlFlags {0}, MovementFlag {1} for {2}",
104// presence.AgentControlFlags, presence.MovementFlag, presence.Name);
97 } 105 }
98 else 106 else
99 { 107 {
100 m_log.DebugFormat( 108// m_log.DebugFormat(
101 "[NPC MODULE]: Updating npc {0} at {1} for next movement to {2}", 109// "[NPC MODULE]: Updating npc {0} at {1} for next movement to {2}",
102 presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget); 110// presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget);
103 111
104 Vector3 agent_control_v3 = new Vector3(); 112 Vector3 agent_control_v3 = new Vector3();
105 presence.HandleMoveToTargetUpdate(ref agent_control_v3, presence.Rotation); 113 presence.HandleMoveToTargetUpdate(ref agent_control_v3);
106 presence.AddNewMovement(agent_control_v3, presence.Rotation); 114 presence.AddNewMovement(agent_control_v3);
107 } 115 }
108// 116//
109//// presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null); 117//// presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null);
@@ -115,29 +123,48 @@ namespace OpenSim.Region.OptionalModules.World.NPC
115 } 123 }
116 } 124 }
117 125
118 private AvatarAppearance GetAppearance(UUID target, Scene scene) 126 public bool IsNPC(UUID agentId, Scene scene)
127 {
128 ScenePresence sp = scene.GetScenePresence(agentId);
129 if (sp == null || sp.IsChildAgent)
130 return false;
131
132 lock (m_avatars)
133 return m_avatars.ContainsKey(agentId);
134 }
135
136 public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene)
119 { 137 {
120 if (m_appearanceCache.ContainsKey(target)) 138 ScenePresence sp = scene.GetScenePresence(agentId);
121 return m_appearanceCache[target]; 139 if (sp == null || sp.IsChildAgent)
140 return false;
122 141
123 ScenePresence originalPresence = scene.GetScenePresence(target); 142 lock (m_avatars)
143 if (!m_avatars.ContainsKey(agentId))
144 return false;
124 145
125 if (originalPresence != null) 146 // FIXME: An extremely bad bit of code that reaches directly into the attachments list and manipulates it
126 { 147 List<SceneObjectGroup> attachments = sp.Attachments;
127 AvatarAppearance originalAppearance = originalPresence.Appearance; 148 lock (attachments)
128 m_appearanceCache.Add(target, originalAppearance);
129 return originalAppearance;
130 }
131 else
132 { 149 {
133 m_log.DebugFormat( 150 foreach (SceneObjectGroup att in attachments)
134 "[NPC MODULE]: Avatar {0} is not in the scene for us to grab baked textures from them. Using defaults.", target); 151 scene.DeleteSceneObject(att, false);
135 152
136 return new AvatarAppearance(); 153 attachments.Clear();
137 } 154 }
155
156 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
157 sp.Appearance = npcAppearance;
158 sp.RezAttachments();
159
160 IAvatarFactory module = scene.RequestModuleInterface<IAvatarFactory>();
161 module.SendAppearance(sp.UUID);
162
163 return true;
138 } 164 }
139 165
140 public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom) 166 public UUID CreateNPC(
167 string firstname, string lastname, Vector3 position, Scene scene, AvatarAppearance appearance)
141 { 168 {
142 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene); 169 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, scene);
143 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); 170 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue);
@@ -152,8 +179,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
152 acd.lastname = lastname; 179 acd.lastname = lastname;
153 acd.ServiceURLs = new Dictionary<string, object>(); 180 acd.ServiceURLs = new Dictionary<string, object>();
154 181
155 AvatarAppearance originalAppearance = GetAppearance(cloneAppearanceFrom, scene); 182 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true);
156 AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true);
157 acd.Appearance = npcAppearance; 183 acd.Appearance = npcAppearance;
158 184
159// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) 185// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++)
@@ -164,7 +190,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
164// } 190// }
165 191
166 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); 192 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
167 scene.AddNewClient(npcAvatar); 193 scene.AddNewClient(npcAvatar, PresenceType.Npc);
168 194
169 ScenePresence sp; 195 ScenePresence sp;
170 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 196 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
@@ -172,13 +198,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
172 m_log.DebugFormat( 198 m_log.DebugFormat(
173 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); 199 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID);
174 200
175 // Shouldn't call this - temporary. 201 sp.CompleteMovement(npcAvatar, false);
176 sp.CompleteMovement(npcAvatar);
177
178// sp.SendAppearanceToAllOtherAgents();
179//
180// // Send animations back to the avatar as well
181// sp.Animator.SendAnimPack();
182 } 202 }
183 else 203 else
184 { 204 {
@@ -193,7 +213,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
193 return npcAvatar.AgentId; 213 return npcAvatar.AgentId;
194 } 214 }
195 215
196 public void MoveToTarget(UUID agentID, Scene scene, Vector3 pos) 216 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget)
197 { 217 {
198 lock (m_avatars) 218 lock (m_avatars)
199 { 219 {
@@ -203,34 +223,70 @@ namespace OpenSim.Region.OptionalModules.World.NPC
203 scene.TryGetScenePresence(agentID, out sp); 223 scene.TryGetScenePresence(agentID, out sp);
204 224
205 m_log.DebugFormat( 225 m_log.DebugFormat(
206 "[NPC MODULE]: Moving {0} to {1} in {2}", sp.Name, pos, scene.RegionInfo.RegionName); 226 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
227 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
228
229 m_avatars[agentID].LandAtTarget = landAtTarget;
230 sp.MoveToTarget(pos, noFly);
231
232 return true;
233 }
234 }
235
236 return false;
237 }
238
239 public bool StopMoveToTarget(UUID agentID, Scene scene)
240 {
241 lock (m_avatars)
242 {
243 if (m_avatars.ContainsKey(agentID))
244 {
245 ScenePresence sp;
246 scene.TryGetScenePresence(agentID, out sp);
207 247
208 sp.MoveToTarget(pos); 248 sp.Velocity = Vector3.Zero;
249 sp.ResetMoveToTarget();
250
251 return true;
209 } 252 }
210 } 253 }
254
255 return false;
211 } 256 }
212 257
213 public void Say(UUID agentID, Scene scene, string text) 258 public bool Say(UUID agentID, Scene scene, string text)
214 { 259 {
215 lock (m_avatars) 260 lock (m_avatars)
216 { 261 {
217 if (m_avatars.ContainsKey(agentID)) 262 if (m_avatars.ContainsKey(agentID))
218 { 263 {
264 ScenePresence sp;
265 scene.TryGetScenePresence(agentID, out sp);
266
219 m_avatars[agentID].Say(text); 267 m_avatars[agentID].Say(text);
268
269 return true;
220 } 270 }
221 } 271 }
272
273 return false;
222 } 274 }
223 275
224 public void DeleteNPC(UUID agentID, Scene scene) 276 public bool DeleteNPC(UUID agentID, Scene scene)
225 { 277 {
226 lock (m_avatars) 278 lock (m_avatars)
227 { 279 {
228 if (m_avatars.ContainsKey(agentID)) 280 if (m_avatars.ContainsKey(agentID))
229 { 281 {
230 scene.RemoveClient(agentID); 282 scene.RemoveClient(agentID, false);
231 m_avatars.Remove(agentID); 283 m_avatars.Remove(agentID);
284
285 return true;
232 } 286 }
233 } 287 }
288
289 return false;
234 } 290 }
235 291
236 public void PostInitialise() 292 public void PostInitialise()