diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 103 |
1 files changed, 91 insertions, 12 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 3cdd06d..4f21d9d 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -44,14 +44,75 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
44 | { | 44 | { |
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 const bool m_enabled = false; | 47 | private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); |
48 | 48 | private Dictionary<UUID, AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); | |
49 | private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); | ||
50 | private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); | ||
51 | 49 | ||
52 | public void Initialise(Scene scene, IConfigSource source) | 50 | public void Initialise(Scene scene, IConfigSource source) |
53 | { | 51 | { |
54 | scene.RegisterModuleInterface<INPCModule>(this); | 52 | IConfig config = source.Configs["NPC"]; |
53 | |||
54 | if (config != null && config.GetBoolean("Enabled", false)) | ||
55 | { | ||
56 | scene.RegisterModuleInterface<INPCModule>(this); | ||
57 | scene.EventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | public void HandleOnSignificantClientMovement(ScenePresence presence) | ||
62 | { | ||
63 | lock (m_avatars) | ||
64 | { | ||
65 | if (m_avatars.ContainsKey(presence.UUID) && presence.MovingToTarget) | ||
66 | { | ||
67 | double distanceToTarget = Util.GetDistanceTo(presence.AbsolutePosition, presence.MoveToPositionTarget); | ||
68 | // m_log.DebugFormat( | ||
69 | // "[NPC MODULE]: Abs pos of {0} is {1}, target {2}, distance {3}", | ||
70 | // presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget); | ||
71 | |||
72 | // Check the error term of the current position in relation to the target position | ||
73 | if (distanceToTarget <= ScenePresence.SIGNIFICANT_MOVEMENT) | ||
74 | { | ||
75 | // We are close enough to the target | ||
76 | m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name); | ||
77 | |||
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; | ||
89 | presence.AbsolutePosition = presence.MoveToPositionTarget; | ||
90 | presence.ResetMoveToTarget(); | ||
91 | |||
92 | // FIXME: This doesn't work | ||
93 | if (presence.PhysicsActor.Flying) | ||
94 | presence.Animator.TrySetMovementAnimation("HOVER"); | ||
95 | else | ||
96 | presence.Animator.TrySetMovementAnimation("STAND"); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | m_log.DebugFormat( | ||
101 | "[NPC MODULE]: Updating npc {0} at {1} for next movement to {2}", | ||
102 | presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget); | ||
103 | |||
104 | Vector3 agent_control_v3 = new Vector3(); | ||
105 | presence.HandleMoveToTargetUpdate(ref agent_control_v3, presence.Rotation); | ||
106 | presence.AddNewMovement(agent_control_v3, presence.Rotation); | ||
107 | } | ||
108 | // | ||
109 | //// presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null); | ||
110 | |||
111 | // | ||
112 | // | ||
113 | |||
114 | } | ||
115 | } | ||
55 | } | 116 | } |
56 | 117 | ||
57 | private AvatarAppearance GetAppearance(UUID target, Scene scene) | 118 | private AvatarAppearance GetAppearance(UUID target, Scene scene) |
@@ -59,14 +120,21 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
59 | if (m_appearanceCache.ContainsKey(target)) | 120 | if (m_appearanceCache.ContainsKey(target)) |
60 | return m_appearanceCache[target]; | 121 | return m_appearanceCache[target]; |
61 | 122 | ||
62 | AvatarAppearance appearance = scene.AvatarService.GetAppearance(target); | 123 | ScenePresence originalPresence = scene.GetScenePresence(target); |
63 | if (appearance != null) | 124 | |
125 | if (originalPresence != null) | ||
64 | { | 126 | { |
65 | m_appearanceCache.Add(target, appearance); | 127 | AvatarAppearance originalAppearance = originalPresence.Appearance; |
66 | return appearance; | 128 | m_appearanceCache.Add(target, originalAppearance); |
129 | return originalAppearance; | ||
67 | } | 130 | } |
131 | else | ||
132 | { | ||
133 | m_log.DebugFormat( | ||
134 | "[NPC MODULE]: Avatar {0} is not in the scene for us to grab baked textures from them. Using defaults.", target); | ||
68 | 135 | ||
69 | return new AvatarAppearance(); | 136 | return new AvatarAppearance(); |
137 | } | ||
70 | } | 138 | } |
71 | 139 | ||
72 | public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom) | 140 | public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom) |
@@ -88,6 +156,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
88 | AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true); | 156 | AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true); |
89 | acd.Appearance = npcAppearance; | 157 | acd.Appearance = npcAppearance; |
90 | 158 | ||
159 | // for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) | ||
160 | // { | ||
161 | // m_log.DebugFormat( | ||
162 | // "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", | ||
163 | // acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); | ||
164 | // } | ||
165 | |||
91 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); | 166 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); |
92 | scene.AddNewClient(npcAvatar); | 167 | scene.AddNewClient(npcAvatar); |
93 | 168 | ||
@@ -118,7 +193,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
118 | return npcAvatar.AgentId; | 193 | return npcAvatar.AgentId; |
119 | } | 194 | } |
120 | 195 | ||
121 | public void Autopilot(UUID agentID, Scene scene, Vector3 pos) | 196 | public void MoveToTarget(UUID agentID, Scene scene, Vector3 pos) |
122 | { | 197 | { |
123 | lock (m_avatars) | 198 | lock (m_avatars) |
124 | { | 199 | { |
@@ -126,7 +201,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
126 | { | 201 | { |
127 | ScenePresence sp; | 202 | ScenePresence sp; |
128 | scene.TryGetScenePresence(agentID, out sp); | 203 | scene.TryGetScenePresence(agentID, out sp); |
129 | sp.DoAutoPilot(0, pos, m_avatars[agentID]); | 204 | |
205 | m_log.DebugFormat( | ||
206 | "[NPC MODULE]: Moving {0} to {1} in {2}", sp.Name, pos, scene.RegionInfo.RegionName); | ||
207 | |||
208 | sp.MoveToTarget(pos); | ||
130 | } | 209 | } |
131 | } | 210 | } |
132 | } | 211 | } |