Allow the osNpcCreate() function to accept a notecard name or asset for initial appearance

bulletsim
Justin Clark-Casey (justincc) 2011-08-12 00:14:06 +01:00
parent d23d37d2aa
commit 0a1bbc27d2
2 changed files with 26 additions and 6 deletions

View File

@ -2130,20 +2130,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom) public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
{ {
CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
//QueueUserWorkItem
INPCModule module = World.RequestModuleInterface<INPCModule>(); INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null) if (module != null)
{ {
ScenePresence clonePresence = World.GetScenePresence(new UUID(cloneFrom.m_string)); AvatarAppearance appearance = null;
if (clonePresence == null)
UUID cloneId;
if (UUID.TryParse(cloneFrom, out cloneId))
{
ScenePresence clonePresence = World.GetScenePresence(new UUID(cloneFrom.m_string));
if (clonePresence != null)
appearance = clonePresence.Appearance;
}
if (appearance == null)
{
string appearanceSerialized = LoadNotecard(cloneFrom.m_string);
if (appearanceSerialized != null)
{
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
appearance = new AvatarAppearance();
appearance.Unpack(appearanceOsd);
}
}
if (appearance == null)
return new LSL_Key(UUID.Zero.ToString()); return new LSL_Key(UUID.Zero.ToString());
UUID x = module.CreateNPC(firstname, UUID x = module.CreateNPC(firstname,
lastname, lastname,
new Vector3((float) position.x, (float) position.y, (float) position.z), new Vector3((float) position.x, (float) position.y, (float) position.z),
World, World,
clonePresence.Appearance); appearance);
return new LSL_Key(x.ToString()); return new LSL_Key(x.ToString());
} }

View File

@ -78,11 +78,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
/// <summary> /// <summary>
/// Test creation of an NPC where the appearance data comes from a notecard /// Test creation of an NPC where the appearance data comes from a notecard
/// </summary> /// </summary>
//[Test] [Test]
public void TestOsNpcCreateFromNotecard() public void TestOsNpcCreateFromNotecard()
{ {
TestHelpers.InMethod(); TestHelpers.InMethod();
log4net.Config.XmlConfigurator.Configure(); // log4net.Config.XmlConfigurator.Configure();
// Store an avatar with a different height from default in a notecard. // Store an avatar with a different height from default in a notecard.
UUID userId = TestHelpers.ParseTail(0x1); UUID userId = TestHelpers.ParseTail(0x1);