aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim.RegionServer/CAPS/AdminWebFront.cs32
-rw-r--r--OpenSim.RegionServer/OpenSim.RegionServer.csproj6
-rw-r--r--OpenSim.RegionServer/OpenSim.RegionServer.dll.build2
-rw-r--r--OpenSim.RegionServer/world/World.cs49
-rw-r--r--OpenSim.RegionServer/world/scripting/ScriptFactory.cs8
-rw-r--r--OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs37
6 files changed, 74 insertions, 60 deletions
diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
index 0d03a57..d4519e8 100644
--- a/OpenSim.RegionServer/CAPS/AdminWebFront.cs
+++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
@@ -10,6 +10,7 @@ using OpenSim.Framework.Inventory;
10using libsecondlife; 10using libsecondlife;
11using OpenSim.RegionServer.world.scripting; 11using OpenSim.RegionServer.world.scripting;
12using Avatar=libsecondlife.Avatar; 12using Avatar=libsecondlife.Avatar;
13using OpenSim.RegionServer.world.scripting.Scripts;
13 14
14namespace OpenSim.CAPS 15namespace OpenSim.CAPS
15{ 16{
@@ -139,35 +140,6 @@ namespace OpenSim.CAPS
139 return responseString; 140 return responseString;
140 } 141 }
141 142
142
143 private class TestScript : Script
144 {
145 public TestScript()
146 : base(LLUUID.Random())
147 {
148 OnFrame += MyOnFrame;
149 }
150
151 private void MyOnFrame(IScriptContext context)
152 {
153 LLVector3 pos = context.Entity.Pos;
154
155 IScriptReadonlyEntity avatar;
156
157 if( context.TryGetRandomAvatar( out avatar ) )
158 {
159 LLVector3 avatarPos = avatar.Pos;
160
161 float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X))/2;
162 float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y))/2;
163
164 LLVector3 newPos = new LLVector3( x, y, pos.Z );
165
166 context.Entity.Pos = newPos;
167 }
168 }
169 }
170
171 private string AddTestScript(string request, string path) 143 private string AddTestScript(string request, string path)
172 { 144 {
173 int index = path.LastIndexOf('/'); 145 int index = path.LastIndexOf('/');
@@ -179,7 +151,7 @@ namespace OpenSim.CAPS
179 if( LLUUID.TryParse( lluidStr, out id ) ) 151 if( LLUUID.TryParse( lluidStr, out id ) )
180 { 152 {
181 // This is just here for concept purposes... Remove! 153 // This is just here for concept purposes... Remove!
182 m_world.AddScript( m_world.Entities[id], new TestScript()); 154 m_world.AddScript( m_world.Entities[id], new FollowRandomAvatar());
183 return String.Format("Added new script to object [{0}]", id); 155 return String.Format("Added new script to object [{0}]", id);
184 } 156 }
185 else 157 else
diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
index 165b123..6c0f2da 100644
--- a/OpenSim.RegionServer/OpenSim.RegionServer.csproj
+++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
@@ -196,6 +196,12 @@
196 <Compile Include="world\scripting\Script.cs"> 196 <Compile Include="world\scripting\Script.cs">
197 <SubType>Code</SubType> 197 <SubType>Code</SubType>
198 </Compile> 198 </Compile>
199 <Compile Include="world\scripting\ScriptFactory.cs">
200 <SubType>Code</SubType>
201 </Compile>
202 <Compile Include="world\scripting\Scripts\FollowRandomAvatar.cs">
203 <SubType>Code</SubType>
204 </Compile>
199 </ItemGroup> 205 </ItemGroup>
200 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> 206 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
201 <PropertyGroup> 207 <PropertyGroup>
diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
index 47a983b..4a08551 100644
--- a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
+++ b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
@@ -39,6 +39,8 @@
39 <include name="world/scripting/IScriptEntity.cs" /> 39 <include name="world/scripting/IScriptEntity.cs" />
40 <include name="world/scripting/IScriptHandler.cs" /> 40 <include name="world/scripting/IScriptHandler.cs" />
41 <include name="world/scripting/Script.cs" /> 41 <include name="world/scripting/Script.cs" />
42 <include name="world/scripting/ScriptFactory.cs" />
43 <include name="world/scripting/Scripts/FollowRandomAvatar.cs" />
42 </sources> 44 </sources>
43 <references basedir="${project::get-base-directory()}"> 45 <references basedir="${project::get-base-directory()}">
44 <lib> 46 <lib>
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs
index c775429..0799e38 100644
--- a/OpenSim.RegionServer/world/World.cs
+++ b/OpenSim.RegionServer/world/World.cs
@@ -13,6 +13,7 @@ using OpenSim.Framework.Inventory;
13using OpenSim.Assets; 13using OpenSim.Assets;
14using OpenSim.world.scripting; 14using OpenSim.world.scripting;
15using OpenSim.RegionServer.world.scripting; 15using OpenSim.RegionServer.world.scripting;
16using OpenSim.RegionServer.world.scripting.Scripts;
16 17
17namespace OpenSim.world 18namespace OpenSim.world
18{ 19{
@@ -32,20 +33,20 @@ namespace OpenSim.world
32 private int storageCount; 33 private int storageCount;
33 private Dictionary<uint, SimClient> m_clientThreads; 34 private Dictionary<uint, SimClient> m_clientThreads;
34 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; 35 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
35 private Dictionary<string, Script> m_scripts; 36 private Dictionary<string, ScriptFactory> m_scripts;
36 private ulong m_regionHandle; 37 private ulong m_regionHandle;
37 private string m_regionName; 38 private string m_regionName;
38 private InventoryCache _inventoryCache; 39 private InventoryCache _inventoryCache;
39 private AssetCache _assetCache; 40 private AssetCache _assetCache;
40 41
41 public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName) 42 public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName)
42 { 43 {
43 m_clientThreads = clientThreads; 44 m_clientThreads = clientThreads;
44 m_regionHandle = regionHandle; 45 m_regionHandle = regionHandle;
45 m_regionName = regionName; 46 m_regionName = regionName;
46 47
47 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); 48 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
48 m_scripts = new Dictionary<string, Script>(); 49 m_scripts = new Dictionary<string, ScriptFactory>();
49 50
50 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); 51 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
51 Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); 52 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
@@ -75,11 +76,17 @@ namespace OpenSim.world
75 scriptend = scriptData.LastIndexOf("</Script>"); 76 scriptend = scriptData.LastIndexOf("</Script>");
76 substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8); 77 substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8);
77 substring = substring.Trim(); 78 substring = substring.Trim();
78 Console.WriteLine("searching for script to add: " + substring); 79 Console.WriteLine("searching for script to add: " + substring);
79 if (this.m_scripts.ContainsKey(substring)) 80
81 ScriptFactory scriptFactory;
82
83 if (this.m_scripts.TryGetValue(substring, out scriptFactory ))
80 { 84 {
81 Console.WriteLine("added script"); 85 Console.WriteLine("added script");
82 this.AddScript(entity, this.m_scripts[substring]); 86
87
88
89 this.AddScript(entity, scriptFactory());
83 } 90 }
84 /*string delimStr = " "; 91 /*string delimStr = " ";
85 char[] delimiter = delimStr.ToCharArray(); 92 char[] delimiter = delimStr.ToCharArray();
@@ -357,7 +364,7 @@ namespace OpenSim.world
357 prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); 364 prim.PhysActor = this.phyScene.AddPrim(pVec, pSize);
358 } 365 }
359 } 366 }
360 367
361 this.Entities.Add(prim.uuid, prim); 368 this.Entities.Add(prim.uuid, prim);
362 this._primCount++; 369 this._primCount++;
363 } 370 }
@@ -557,31 +564,13 @@ namespace OpenSim.world
557 564
558 public void SetDefaultScripts() 565 public void SetDefaultScripts()
559 { 566 {
560 this.m_scripts.Add("Test", new TestScript1()); 567 this.m_scripts.Add("FollowRandomAvatar", delegate()
561 } 568 {
562 569 return new FollowRandomAvatar();
563 #endregion 570 });
564 }
565
566 public class TestScript1 : Script
567 {
568 int toggle = 0;
569
570 public TestScript1()
571 : base(LLUUID.Random())
572 {
573 OnFrame += MyOnFrame;
574 } 571 }
575 572
576 private void MyOnFrame(IScriptContext context)
577 {
578 toggle = 2 - toggle;
579 573
580 LLVector3 pos = context.GetPos(); 574 #endregion
581
582 pos.X += (toggle - 1);
583
584 context.MoveTo(pos);
585 }
586 } 575 }
587} 576}
diff --git a/OpenSim.RegionServer/world/scripting/ScriptFactory.cs b/OpenSim.RegionServer/world/scripting/ScriptFactory.cs
new file mode 100644
index 0000000..4c6d373
--- /dev/null
+++ b/OpenSim.RegionServer/world/scripting/ScriptFactory.cs
@@ -0,0 +1,8 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.RegionServer.world.scripting
6{
7 public delegate Script ScriptFactory();
8}
diff --git a/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs
new file mode 100644
index 0000000..388a95c
--- /dev/null
+++ b/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs
@@ -0,0 +1,37 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.RegionServer.world.scripting.Scripts
7{
8 public class FollowRandomAvatar : Script
9 {
10 public FollowRandomAvatar()
11 : base(LLUUID.Random())
12 {
13 OnFrame += MyOnFrame;
14 }
15
16 private void MyOnFrame(IScriptContext context)
17 {
18 LLVector3 pos = context.Entity.Pos;
19
20 IScriptReadonlyEntity avatar;
21
22 if (context.TryGetRandomAvatar(out avatar))
23 {
24 LLVector3 avatarPos = avatar.Pos;
25
26 float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
27 float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
28
29 LLVector3 newPos = new LLVector3(x, y, pos.Z);
30
31 context.Entity.Pos = newPos;
32 }
33 }
34 }
35
36
37}