From 7169acc47e8bb56581bd28c3bd921ca9236ba3c3 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 3 Apr 2007 19:12:07 +0000 Subject: * 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. --- .../world/scripting/IScriptHandler.cs | 66 +++++++++++++++++----- 1 file changed, 51 insertions(+), 15 deletions(-) (limited to 'OpenSim.RegionServer/world/scripting/IScriptHandler.cs') 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; using libsecondlife; using OpenSim.Physics.Manager; using OpenSim.world; -using Primitive=OpenSim.world.Primitive; +using Avatar=OpenSim.world.Avatar; +using Primitive = OpenSim.world.Primitive; namespace OpenSim.RegionServer.world.scripting { - public delegate void ScriptEventHandler( IScriptContext context ); - - public class ScriptHandler : IScriptContext + public delegate void ScriptEventHandler(IScriptContext context); + + public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity { private World m_world; private Script m_script; private Entity m_entity; - + public LLUUID ScriptId { get @@ -23,13 +24,13 @@ namespace OpenSim.RegionServer.world.scripting return m_script.ScriptId; } } - + public void OnFrame() { m_script.OnFrame(this); } - public ScriptHandler( Script script, Entity entity, World world ) + public ScriptHandler(Script script, Entity entity, World world) { m_script = script; m_entity = entity; @@ -38,22 +39,57 @@ namespace OpenSim.RegionServer.world.scripting #region IScriptContext Members - bool IScriptContext.MoveTo(LLVector3 newPos) + IScriptEntity IScriptContext.Entity + { + get + { + return this; + } + } + + bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar) { - if (m_entity is Primitive) + foreach (Entity entity in m_world.Entities.Values ) { - Primitive prim = m_entity as Primitive; - // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. - prim.UpdatePosition( newPos ); - return true; + if( entity is Avatar ) + { + avatar = entity; + return true; + } } + avatar = null; return false; } - LLVector3 IScriptContext.GetPos() + #endregion + + #region IScriptEntity and IScriptReadonlyEntity Members + + public string Name + { + get + { + return m_entity.Name; + } + } + + public LLVector3 Pos { - return m_entity.position; + get + { + return m_entity.Pos; + } + + set + { + if (m_entity is Primitive) + { + Primitive prim = m_entity as Primitive; + // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. + prim.UpdatePosition( value ); + } + } } #endregion -- cgit v1.1