diff options
* Extended Script API with GetRandomAvatar
* The script will now get a IScriptEntity to it's host object with get/sets
* The script gets a IScriptReadnlyEntity interface to entities other than the host object.
* the test script now follows a random avatar.
Diffstat (limited to 'OpenSim.RegionServer/world/scripting/IScriptHandler.cs')
-rw-r--r-- | OpenSim.RegionServer/world/scripting/IScriptHandler.cs | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/OpenSim.RegionServer/world/scripting/IScriptHandler.cs b/OpenSim.RegionServer/world/scripting/IScriptHandler.cs index 5addb35..15efc49 100644 --- a/OpenSim.RegionServer/world/scripting/IScriptHandler.cs +++ b/OpenSim.RegionServer/world/scripting/IScriptHandler.cs | |||
@@ -4,18 +4,19 @@ using System.Text; | |||
4 | using libsecondlife; | 4 | using libsecondlife; |
5 | using OpenSim.Physics.Manager; | 5 | using OpenSim.Physics.Manager; |
6 | using OpenSim.world; | 6 | using OpenSim.world; |
7 | using Primitive=OpenSim.world.Primitive; | 7 | using Avatar=OpenSim.world.Avatar; |
8 | using Primitive = OpenSim.world.Primitive; | ||
8 | 9 | ||
9 | namespace OpenSim.RegionServer.world.scripting | 10 | namespace OpenSim.RegionServer.world.scripting |
10 | { | 11 | { |
11 | public delegate void ScriptEventHandler( IScriptContext context ); | 12 | public delegate void ScriptEventHandler(IScriptContext context); |
12 | 13 | ||
13 | public class ScriptHandler : IScriptContext | 14 | public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity |
14 | { | 15 | { |
15 | private World m_world; | 16 | private World m_world; |
16 | private Script m_script; | 17 | private Script m_script; |
17 | private Entity m_entity; | 18 | private Entity m_entity; |
18 | 19 | ||
19 | public LLUUID ScriptId | 20 | public LLUUID ScriptId |
20 | { | 21 | { |
21 | get | 22 | get |
@@ -23,13 +24,13 @@ namespace OpenSim.RegionServer.world.scripting | |||
23 | return m_script.ScriptId; | 24 | return m_script.ScriptId; |
24 | } | 25 | } |
25 | } | 26 | } |
26 | 27 | ||
27 | public void OnFrame() | 28 | public void OnFrame() |
28 | { | 29 | { |
29 | m_script.OnFrame(this); | 30 | m_script.OnFrame(this); |
30 | } | 31 | } |
31 | 32 | ||
32 | public ScriptHandler( Script script, Entity entity, World world ) | 33 | public ScriptHandler(Script script, Entity entity, World world) |
33 | { | 34 | { |
34 | m_script = script; | 35 | m_script = script; |
35 | m_entity = entity; | 36 | m_entity = entity; |
@@ -38,22 +39,57 @@ namespace OpenSim.RegionServer.world.scripting | |||
38 | 39 | ||
39 | #region IScriptContext Members | 40 | #region IScriptContext Members |
40 | 41 | ||
41 | bool IScriptContext.MoveTo(LLVector3 newPos) | 42 | IScriptEntity IScriptContext.Entity |
43 | { | ||
44 | get | ||
45 | { | ||
46 | return this; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar) | ||
42 | { | 51 | { |
43 | if (m_entity is Primitive) | 52 | foreach (Entity entity in m_world.Entities.Values ) |
44 | { | 53 | { |
45 | Primitive prim = m_entity as Primitive; | 54 | if( entity is Avatar ) |
46 | // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. | 55 | { |
47 | prim.UpdatePosition( newPos ); | 56 | avatar = entity; |
48 | return true; | 57 | return true; |
58 | } | ||
49 | } | 59 | } |
50 | 60 | ||
61 | avatar = null; | ||
51 | return false; | 62 | return false; |
52 | } | 63 | } |
53 | 64 | ||
54 | LLVector3 IScriptContext.GetPos() | 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 | ||
55 | { | 78 | { |
56 | return m_entity.position; | 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 | } | ||
57 | } | 93 | } |
58 | 94 | ||
59 | #endregion | 95 | #endregion |