aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Reg/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.Reg/scripting')
-rw-r--r--OpenSim/OpenSim.Reg/scripting/IScriptContext.cs13
-rw-r--r--OpenSim/OpenSim.Reg/scripting/IScriptEntity.cs19
-rw-r--r--OpenSim/OpenSim.Reg/scripting/IScriptHandler.cs98
-rw-r--r--OpenSim/OpenSim.Reg/scripting/Script.cs26
-rw-r--r--OpenSim/OpenSim.Reg/scripting/ScriptFactory.cs8
-rw-r--r--OpenSim/OpenSim.Reg/scripting/Scripts/FollowRandomAvatar.cs37
6 files changed, 201 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Reg/scripting/IScriptContext.cs b/OpenSim/OpenSim.Reg/scripting/IScriptContext.cs
new file mode 100644
index 0000000..3dc7dab
--- /dev/null
+++ b/OpenSim/OpenSim.Reg/scripting/IScriptContext.cs
@@ -0,0 +1,13 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.Region.Scripting
7{
8 public interface IScriptContext
9 {
10 IScriptEntity Entity { get; }
11 bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
12 }
13}
diff --git a/OpenSim/OpenSim.Reg/scripting/IScriptEntity.cs b/OpenSim/OpenSim.Reg/scripting/IScriptEntity.cs
new file mode 100644
index 0000000..abb789f
--- /dev/null
+++ b/OpenSim/OpenSim.Reg/scripting/IScriptEntity.cs
@@ -0,0 +1,19 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.Region.Scripting
7{
8 public interface IScriptReadonlyEntity
9 {
10 LLVector3 Pos { get; }
11 string Name { get; }
12 }
13
14 public interface IScriptEntity
15 {
16 LLVector3 Pos { get; set; }
17 string Name { get; }
18 }
19}
diff --git a/OpenSim/OpenSim.Reg/scripting/IScriptHandler.cs b/OpenSim/OpenSim.Reg/scripting/IScriptHandler.cs
new file mode 100644
index 0000000..6644649
--- /dev/null
+++ b/OpenSim/OpenSim.Reg/scripting/IScriptHandler.cs
@@ -0,0 +1,98 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using OpenSim.Physics.Manager;
6using OpenSim.Region;
7using Avatar=OpenSim.Region.Avatar;
8using Primitive = OpenSim.Region.Primitive;
9
10namespace OpenSim.Region.Scripting
11{
12 public delegate void ScriptEventHandler(IScriptContext context);
13
14 public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
15 {
16 private World m_world;
17 private Script m_script;
18 private Entity m_entity;
19
20 public LLUUID ScriptId
21 {
22 get
23 {
24 return m_script.ScriptId;
25 }
26 }
27
28 public void OnFrame()
29 {
30 m_script.OnFrame(this);
31 }
32
33 public ScriptHandler(Script script, Entity entity, World world)
34 {
35 m_script = script;
36 m_entity = entity;
37 m_world = world;
38 }
39
40 #region IScriptContext Members
41
42 IScriptEntity IScriptContext.Entity
43 {
44 get
45 {
46 return this;
47 }
48 }
49
50 bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
51 {
52 foreach (Entity entity in m_world.Entities.Values )
53 {
54 if( entity is Avatar )
55 {
56 avatar = entity;
57 return true;
58 }
59 }
60
61 avatar = null;
62 return false;
63 }
64
65 #endregion
66
67 #region IScriptEntity and IScriptReadonlyEntity Members
68
69 public string Name
70 {
71 get
72 {
73 return m_entity.Name;
74 }
75 }
76
77 public LLVector3 Pos
78 {
79 get
80 {
81 return m_entity.Pos;
82 }
83
84 set
85 {
86 if (m_entity is Primitive)
87 {
88 Primitive prim = m_entity as Primitive;
89 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
90 // prim.UpdatePosition( value );
91 }
92 }
93 }
94
95 #endregion
96 }
97
98}
diff --git a/OpenSim/OpenSim.Reg/scripting/Script.cs b/OpenSim/OpenSim.Reg/scripting/Script.cs
new file mode 100644
index 0000000..c0c2c0c
--- /dev/null
+++ b/OpenSim/OpenSim.Reg/scripting/Script.cs
@@ -0,0 +1,26 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.Region.Scripting
7{
8 public class Script
9 {
10 private LLUUID m_scriptId;
11 public virtual LLUUID ScriptId
12 {
13 get
14 {
15 return m_scriptId;
16 }
17 }
18
19 public Script( LLUUID scriptId )
20 {
21 m_scriptId = scriptId;
22 }
23
24 public ScriptEventHandler OnFrame;
25 }
26}
diff --git a/OpenSim/OpenSim.Reg/scripting/ScriptFactory.cs b/OpenSim/OpenSim.Reg/scripting/ScriptFactory.cs
new file mode 100644
index 0000000..6f2e5f0
--- /dev/null
+++ b/OpenSim/OpenSim.Reg/scripting/ScriptFactory.cs
@@ -0,0 +1,8 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting
6{
7 public delegate Script ScriptFactory();
8}
diff --git a/OpenSim/OpenSim.Reg/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim/OpenSim.Reg/scripting/Scripts/FollowRandomAvatar.cs
new file mode 100644
index 0000000..9c0146b
--- /dev/null
+++ b/OpenSim/OpenSim.Reg/scripting/Scripts/FollowRandomAvatar.cs
@@ -0,0 +1,37 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.Region.Scripting
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}