* The world can not contain ScriptFactories that creates unique instances of scripts for entities.

* Created Scripts folder to house trusted Scripts
* The test script now lives in Scripts/FollowRandomAvatar.cs
0.1-prestable
lbsa71 2007-04-03 20:08:30 +00:00
parent 7169acc47e
commit f12ceff692
6 changed files with 74 additions and 60 deletions

View File

@ -10,6 +10,7 @@ using OpenSim.Framework.Inventory;
using libsecondlife;
using OpenSim.RegionServer.world.scripting;
using Avatar=libsecondlife.Avatar;
using OpenSim.RegionServer.world.scripting.Scripts;
namespace OpenSim.CAPS
{
@ -139,35 +140,6 @@ namespace OpenSim.CAPS
return responseString;
}
private class TestScript : Script
{
public TestScript()
: base(LLUUID.Random())
{
OnFrame += MyOnFrame;
}
private void MyOnFrame(IScriptContext context)
{
LLVector3 pos = context.Entity.Pos;
IScriptReadonlyEntity avatar;
if( context.TryGetRandomAvatar( out avatar ) )
{
LLVector3 avatarPos = avatar.Pos;
float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X))/2;
float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y))/2;
LLVector3 newPos = new LLVector3( x, y, pos.Z );
context.Entity.Pos = newPos;
}
}
}
private string AddTestScript(string request, string path)
{
int index = path.LastIndexOf('/');
@ -179,7 +151,7 @@ namespace OpenSim.CAPS
if( LLUUID.TryParse( lluidStr, out id ) )
{
// This is just here for concept purposes... Remove!
m_world.AddScript( m_world.Entities[id], new TestScript());
m_world.AddScript( m_world.Entities[id], new FollowRandomAvatar());
return String.Format("Added new script to object [{0}]", id);
}
else

View File

@ -196,6 +196,12 @@
<Compile Include="world\scripting\Script.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="world\scripting\ScriptFactory.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="world\scripting\Scripts\FollowRandomAvatar.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<PropertyGroup>

View File

@ -39,6 +39,8 @@
<include name="world/scripting/IScriptEntity.cs" />
<include name="world/scripting/IScriptHandler.cs" />
<include name="world/scripting/Script.cs" />
<include name="world/scripting/ScriptFactory.cs" />
<include name="world/scripting/Scripts/FollowRandomAvatar.cs" />
</sources>
<references basedir="${project::get-base-directory()}">
<lib>

View File

@ -13,6 +13,7 @@ using OpenSim.Framework.Inventory;
using OpenSim.Assets;
using OpenSim.world.scripting;
using OpenSim.RegionServer.world.scripting;
using OpenSim.RegionServer.world.scripting.Scripts;
namespace OpenSim.world
{
@ -32,20 +33,20 @@ namespace OpenSim.world
private int storageCount;
private Dictionary<uint, SimClient> m_clientThreads;
private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
private Dictionary<string, Script> m_scripts;
private Dictionary<string, ScriptFactory> m_scripts;
private ulong m_regionHandle;
private string m_regionName;
private InventoryCache _inventoryCache;
private AssetCache _assetCache;
public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName)
{
{
m_clientThreads = clientThreads;
m_regionHandle = regionHandle;
m_regionName = regionName;
m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
m_scripts = new Dictionary<string, Script>();
m_scripts = new Dictionary<string, ScriptFactory>();
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
@ -75,11 +76,17 @@ namespace OpenSim.world
scriptend = scriptData.LastIndexOf("</Script>");
substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8);
substring = substring.Trim();
Console.WriteLine("searching for script to add: " + substring);
if (this.m_scripts.ContainsKey(substring))
Console.WriteLine("searching for script to add: " + substring);
ScriptFactory scriptFactory;
if (this.m_scripts.TryGetValue(substring, out scriptFactory ))
{
Console.WriteLine("added script");
this.AddScript(entity, this.m_scripts[substring]);
this.AddScript(entity, scriptFactory());
}
/*string delimStr = " ";
char[] delimiter = delimStr.ToCharArray();
@ -357,7 +364,7 @@ namespace OpenSim.world
prim.PhysActor = this.phyScene.AddPrim(pVec, pSize);
}
}
this.Entities.Add(prim.uuid, prim);
this._primCount++;
}
@ -557,31 +564,13 @@ namespace OpenSim.world
public void SetDefaultScripts()
{
this.m_scripts.Add("Test", new TestScript1());
this.m_scripts.Add("FollowRandomAvatar", delegate()
{
return new FollowRandomAvatar();
});
}
#endregion
}
public class TestScript1 : Script
{
int toggle = 0;
public TestScript1()
: base(LLUUID.Random())
{
OnFrame += MyOnFrame;
}
private void MyOnFrame(IScriptContext context)
{
toggle = 2 - toggle;
LLVector3 pos = context.GetPos();
pos.X += (toggle - 1);
context.MoveTo(pos);
}
}
}

View File

@ -0,0 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.RegionServer.world.scripting
{
public delegate Script ScriptFactory();
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife;
namespace OpenSim.RegionServer.world.scripting.Scripts
{
public class FollowRandomAvatar : Script
{
public FollowRandomAvatar()
: base(LLUUID.Random())
{
OnFrame += MyOnFrame;
}
private void MyOnFrame(IScriptContext context)
{
LLVector3 pos = context.Entity.Pos;
IScriptReadonlyEntity avatar;
if (context.TryGetRandomAvatar(out avatar))
{
LLVector3 avatarPos = avatar.Pos;
float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
LLVector3 newPos = new LLVector3(x, y, pos.Z);
context.Entity.Pos = newPos;
}
}
}
}