diff options
author | Teravus Ovares (Dan Olivares) | 2009-08-25 16:13:02 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2009-08-25 16:13:02 -0400 |
commit | a7917b428a6bc3c9e33da64879b9e473516540a3 (patch) | |
tree | 2c38d9c33c4977a3d0356912915082a8bd568a23 /OpenSim/Region/OptionalModules/World/NPC | |
parent | Patch from jhurliman to HttpServer (diff) | |
parent | Implemented osPenCap, that sets EndCap and StartCap to Pen. This allows using... (diff) | |
download | opensim-SC_OLD-a7917b428a6bc3c9e33da64879b9e473516540a3.zip opensim-SC_OLD-a7917b428a6bc3c9e33da64879b9e473516540a3.tar.gz opensim-SC_OLD-a7917b428a6bc3c9e33da64879b9e473516540a3.tar.bz2 opensim-SC_OLD-a7917b428a6bc3c9e33da64879b9e473516540a3.tar.xz |
Merge branch 'master' of ssh://MyConnection/var/git/opensim
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 148 |
1 files changed, 140 insertions, 8 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 8c9717c..b3bfe07 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -25,26 +25,158 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.Collections.Generic; | ||
29 | using System.Threading; | ||
28 | using OpenMetaverse; | 30 | using OpenMetaverse; |
29 | using Nini.Config; | 31 | using Nini.Config; |
30 | using OpenSim.Region.Framework.Interfaces; | 32 | using OpenSim.Region.Framework.Interfaces; |
31 | using OpenSim.Region.Framework.Scenes; | 33 | using OpenSim.Region.Framework.Scenes; |
34 | using OpenSim.Region.CoreModules.Avatar.NPC; | ||
35 | using OpenSim.Framework; | ||
36 | using Timer=System.Timers.Timer; | ||
32 | 37 | ||
33 | namespace OpenSim.Region.OptionalModules.World.NPC | 38 | namespace OpenSim.Region.OptionalModules.World.NPC |
34 | { | 39 | { |
35 | public class NPCModule : IRegionModule | 40 | public class NPCModule : IRegionModule, INPCModule |
36 | { | 41 | { |
37 | // private const bool m_enabled = false; | 42 | // private const bool m_enabled = false; |
38 | 43 | ||
44 | private Mutex m_createMutex = new Mutex(false); | ||
45 | |||
46 | private Timer m_timer = new Timer(500); | ||
47 | |||
48 | private Dictionary<UUID,NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); | ||
49 | |||
50 | private Dictionary<UUID,AvatarAppearance> m_appearanceCache = new Dictionary<UUID, AvatarAppearance>(); | ||
51 | |||
52 | // Timer vars. | ||
53 | private bool p_inUse = false; | ||
54 | private readonly object p_lock = new object(); | ||
55 | // Private Temporary Variables. | ||
56 | private string p_firstname; | ||
57 | private string p_lastname; | ||
58 | private Vector3 p_position; | ||
59 | private Scene p_scene; | ||
60 | private UUID p_cloneAppearanceFrom; | ||
61 | private UUID p_returnUuid; | ||
62 | |||
63 | private AvatarAppearance GetAppearance(UUID target, Scene scene) | ||
64 | { | ||
65 | if (m_appearanceCache.ContainsKey(target)) | ||
66 | return m_appearanceCache[target]; | ||
67 | |||
68 | AvatarAppearance x = scene.CommsManager.AvatarService.GetUserAppearance(target); | ||
69 | |||
70 | m_appearanceCache.Add(target, x); | ||
71 | |||
72 | return x; | ||
73 | } | ||
74 | |||
75 | public UUID CreateNPC(string firstname, string lastname,Vector3 position, Scene scene, UUID cloneAppearanceFrom) | ||
76 | { | ||
77 | // Block. | ||
78 | m_createMutex.WaitOne(); | ||
79 | |||
80 | // Copy Temp Variables for Timer to pick up. | ||
81 | lock (p_lock) | ||
82 | { | ||
83 | p_firstname = firstname; | ||
84 | p_lastname = lastname; | ||
85 | p_position = position; | ||
86 | p_scene = scene; | ||
87 | p_cloneAppearanceFrom = cloneAppearanceFrom; | ||
88 | p_inUse = true; | ||
89 | p_returnUuid = UUID.Zero; | ||
90 | } | ||
91 | |||
92 | while (p_returnUuid == UUID.Zero) | ||
93 | { | ||
94 | Thread.Sleep(250); | ||
95 | } | ||
96 | |||
97 | m_createMutex.ReleaseMutex(); | ||
98 | |||
99 | return p_returnUuid; | ||
100 | } | ||
101 | |||
102 | public void Autopilot(UUID agentID, Scene scene, Vector3 pos) | ||
103 | { | ||
104 | lock (m_avatars) | ||
105 | { | ||
106 | if (m_avatars.ContainsKey(agentID)) | ||
107 | { | ||
108 | ScenePresence sp; | ||
109 | scene.TryGetAvatar(agentID, out sp); | ||
110 | sp.DoAutoPilot(0, pos, m_avatars[agentID]); | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | |||
115 | public void Say(UUID agentID, Scene scene, string text) | ||
116 | { | ||
117 | lock (m_avatars) | ||
118 | { | ||
119 | if (m_avatars.ContainsKey(agentID)) | ||
120 | { | ||
121 | m_avatars[agentID].Say(text); | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | |||
126 | public void DeleteNPC(UUID agentID, Scene scene) | ||
127 | { | ||
128 | lock (m_avatars) | ||
129 | { | ||
130 | if (m_avatars.ContainsKey(agentID)) | ||
131 | { | ||
132 | scene.RemoveClient(agentID); | ||
133 | m_avatars.Remove(agentID); | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
138 | |||
39 | public void Initialise(Scene scene, IConfigSource source) | 139 | public void Initialise(Scene scene, IConfigSource source) |
40 | { | 140 | { |
41 | // if (m_enabled) | 141 | scene.RegisterModuleInterface<INPCModule>(this); |
42 | // { | 142 | |
43 | // NPCAvatar testAvatar = new NPCAvatar("Jack", "NPC", new Vector3(128, 128, 40), scene); | 143 | m_timer.Elapsed += m_timer_Elapsed; |
44 | // NPCAvatar testAvatar2 = new NPCAvatar("Jill", "NPC", new Vector3(136, 128, 40), scene); | 144 | m_timer.Start(); |
45 | // scene.AddNewClient(testAvatar); | 145 | } |
46 | // scene.AddNewClient(testAvatar2); | 146 | |
47 | // } | 147 | void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) |
148 | { | ||
149 | lock (p_lock) | ||
150 | { | ||
151 | if (p_inUse) | ||
152 | { | ||
153 | p_inUse = false; | ||
154 | |||
155 | NPCAvatar npcAvatar = new NPCAvatar(p_firstname, p_lastname, p_position, p_scene); | ||
156 | npcAvatar.CircuitCode = (uint) Util.RandomClass.Next(0, int.MaxValue); | ||
157 | |||
158 | p_scene.ClientManager.Add(npcAvatar.CircuitCode, npcAvatar); | ||
159 | p_scene.AddNewClient(npcAvatar); | ||
160 | |||
161 | ScenePresence sp; | ||
162 | if (p_scene.TryGetAvatar(npcAvatar.AgentId, out sp)) | ||
163 | { | ||
164 | AvatarAppearance x = GetAppearance(p_cloneAppearanceFrom, p_scene); | ||
165 | |||
166 | List<byte> wearbyte = new List<byte>(); | ||
167 | for (int i = 0; i < x.VisualParams.Length; i++) | ||
168 | { | ||
169 | wearbyte.Add(x.VisualParams[i]); | ||
170 | } | ||
171 | |||
172 | sp.SetAppearance(x.Texture.GetBytes(), wearbyte); | ||
173 | } | ||
174 | |||
175 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | ||
176 | |||
177 | p_returnUuid = npcAvatar.AgentId; | ||
178 | } | ||
179 | } | ||
48 | } | 180 | } |
49 | 181 | ||
50 | public void PostInitialise() | 182 | public void PostInitialise() |