aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Region/World.Scripting.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.Region/World.Scripting.cs')
-rw-r--r--OpenSim/OpenSim.Region/World.Scripting.cs157
1 files changed, 157 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Region/World.Scripting.cs b/OpenSim/OpenSim.Region/World.Scripting.cs
new file mode 100644
index 0000000..49a0fce
--- /dev/null
+++ b/OpenSim/OpenSim.Region/World.Scripting.cs
@@ -0,0 +1,157 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using System.Reflection;
6using OpenSim.Framework;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Framework.Types;
9using libsecondlife;
10
11namespace OpenSim.Region
12{
13 public partial class World
14 {
15 private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
16
17 /// <summary>
18 ///
19 /// </summary>
20 private void LoadScriptEngines()
21 {
22 this.LoadScriptPlugins();
23 }
24
25 /// <summary>
26 ///
27 /// </summary>
28 public void LoadScriptPlugins()
29 {
30 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
31 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
32
33
34 for (int i = 0; i < pluginFiles.Length; i++)
35 {
36 this.AddPlugin(pluginFiles[i]);
37 }
38 }
39
40 /// <summary>
41 ///
42 /// </summary>
43 /// <param name="FileName"></param>
44 private void AddPlugin(string FileName)
45 {
46 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
47
48 foreach (Type pluginType in pluginAssembly.GetTypes())
49 {
50 if (pluginType.IsPublic)
51 {
52 if (!pluginType.IsAbstract)
53 {
54 Type typeInterface = pluginType.GetInterface("IScriptEngine", true);
55
56 if (typeInterface != null)
57 {
58 IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
59 plug.Init(this);
60 this.scriptEngines.Add(plug.GetName(), plug);
61
62 }
63
64 typeInterface = null;
65 }
66 }
67 }
68
69 pluginAssembly = null;
70 }
71
72 /// <summary>
73 ///
74 /// </summary>
75 /// <param name="scriptType"></param>
76 /// <param name="scriptName"></param>
77 /// <param name="script"></param>
78 /// <param name="ent"></param>
79 public void LoadScript(string scriptType, string scriptName, string script, Entity ent)
80 {
81 if(this.scriptEngines.ContainsKey(scriptType))
82 {
83 this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid);
84 }
85 }
86
87 #region IScriptAPI Methods
88
89 /// <summary>
90 ///
91 /// </summary>
92 /// <param name="localID"></param>
93 /// <returns></returns>
94 public OSVector3 GetEntityPosition(uint localID)
95 {
96 OSVector3 res = new OSVector3();
97 // Console.WriteLine("script- getting entity " + localID + " position");
98 foreach (Entity entity in this.Entities.Values)
99 {
100 if (entity.localid == localID)
101 {
102 res.X = entity.Pos.X;
103 res.Y = entity.Pos.Y;
104 res.Z = entity.Pos.Z;
105 }
106 }
107 return res;
108 }
109
110 /// <summary>
111 ///
112 /// </summary>
113 /// <param name="localID"></param>
114 /// <param name="x"></param>
115 /// <param name="y"></param>
116 /// <param name="z"></param>
117 public void SetEntityPosition(uint localID, float x , float y, float z)
118 {
119 foreach (Entity entity in this.Entities.Values)
120 {
121 if (entity.localid == localID && entity is Primitive)
122 {
123 LLVector3 pos = entity.Pos;
124 pos.X = x;
125 pos.Y = y;
126 Primitive prim = entity as Primitive;
127 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
128 //prim.UpdatePosition(pos);
129 // Console.WriteLine("script- setting entity " + localID + " positon");
130 }
131 }
132
133 }
134
135 /// <summary>
136 ///
137 /// </summary>
138 /// <returns></returns>
139 public uint GetRandomAvatarID()
140 {
141 //Console.WriteLine("script- getting random avatar id");
142 uint res = 0;
143 foreach (Entity entity in this.Entities.Values)
144 {
145 if (entity is Avatar)
146 {
147 res = entity.localid;
148 }
149 }
150 return res;
151 }
152
153 #endregion
154
155
156 }
157}