osOwnerSaveAppearance() public method

Save the current appearance of the script owner permanently to the named notecard.
public osOwnerSaveAppearance ( string notecard ) : OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString
notecard string The name of the notecard to which to save the appearance.
return OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString
        public void TestOsNpcCreateUsingAppearanceFromNotecard()
        {
            TestHelpers.InMethod();

            // Store an avatar with a different height from default in a notecard.
            UUID userId = TestHelpers.ParseTail(0x1);
            float newHeight = 1.9f;

            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
            sp.Appearance.AvatarHeight = newHeight;
            SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
            SceneObjectPart part = so.RootPart;
            m_scene.AddSceneObject(so);

            OSSL_Api osslApi = new OSSL_Api();
            osslApi.Initialize(m_engine, part, null, null);

            string notecardName = "appearanceNc";
            osslApi.osOwnerSaveAppearance(notecardName);

            // Try creating a bot using the appearance in the notecard.
            string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName);
            Assert.That(npcRaw, Is.Not.Null);

            UUID npcId = new UUID(npcRaw);
            ScenePresence npc = m_scene.GetScenePresence(npcId);
            Assert.That(npc, Is.Not.Null);
            Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
        }
        public void TestOsNpcRemoveUnowned()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            // Store an avatar with a different height from default in a notecard.
            UUID userId = TestHelpers.ParseTail(0x1);
            float newHeight = 1.9f;

            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
            sp.Appearance.AvatarHeight = newHeight;
            SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
            SceneObjectPart part = so.RootPart;
            m_scene.AddSceneObject(so);

            OSSL_Api osslApi = new OSSL_Api();
            osslApi.Initialize(m_engine, part, null, null);

            string notecardName = "appearanceNc";
            osslApi.osOwnerSaveAppearance(notecardName);

            string npcRaw
                = osslApi.osNpcCreate(
                    "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_NOT_OWNED);
            
            osslApi.osNpcRemove(npcRaw);

            UUID npcId = new UUID(npcRaw);
            ScenePresence npc = m_scene.GetScenePresence(npcId);
            Assert.That(npc, Is.Null);
        }
        public void TestOsNpcLoadAppearanceNotExistingNotecard()
        {
            TestHelpers.InMethod();

            // Store an avatar with a different height from default in a notecard.
            UUID userId = TestHelpers.ParseTail(0x1);
            float firstHeight = 1.9f;
//            float secondHeight = 2.1f;
            string firstAppearanceNcName = "appearanceNc1";
            string secondAppearanceNcName = "appearanceNc2";

            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
            sp.Appearance.AvatarHeight = firstHeight;
            SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
            SceneObjectPart part = so.RootPart;
            m_scene.AddSceneObject(so);

            OSSL_Api osslApi = new OSSL_Api();
            osslApi.Initialize(m_engine, part, null, null);

            osslApi.osOwnerSaveAppearance(firstAppearanceNcName);

            string npcRaw
                = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName);

            bool gotExpectedException = false;
            try
            {
                osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName);
            }
            catch (ScriptException)
            {
                gotExpectedException = true;
            }

            Assert.That(gotExpectedException, Is.True);

            UUID npcId = new UUID(npcRaw);
            ScenePresence npc = m_scene.GetScenePresence(npcId);
            Assert.That(npc, Is.Not.Null);
            Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(firstHeight));
        }
        public void TestOsNpcRemoveOwned()
        {
            TestHelpers.InMethod();

            // Store an avatar with a different height from default in a notecard.
            UUID userId = TestHelpers.ParseTail(0x1);
            UUID otherUserId = TestHelpers.ParseTail(0x2);
            float newHeight = 1.9f;

            SceneHelpers.AddScenePresence(m_scene, otherUserId);

            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
            sp.Appearance.AvatarHeight = newHeight;

            SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
            SceneObjectPart part = so.RootPart;
            m_scene.AddSceneObject(so);

            SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId, 0x20);
            SceneObjectPart otherPart = otherSo.RootPart;
            m_scene.AddSceneObject(otherSo);

            OSSL_Api osslApi = new OSSL_Api();
            osslApi.Initialize(m_engine, part, null, null);

            OSSL_Api otherOsslApi = new OSSL_Api();
            otherOsslApi.Initialize(m_engine, otherPart, null, null);

            string notecardName = "appearanceNc";
            osslApi.osOwnerSaveAppearance(notecardName);

            string npcRaw
                = osslApi.osNpcCreate(
                    "Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName, ScriptBaseClass.OS_NPC_CREATOR_OWNED);
            
            otherOsslApi.osNpcRemove(npcRaw);

            // Should still be around
            UUID npcId = new UUID(npcRaw);
            ScenePresence npc = m_scene.GetScenePresence(npcId);
            Assert.That(npc, Is.Not.Null);

            osslApi.osNpcRemove(npcRaw);

            npc = m_scene.GetScenePresence(npcId);

            // Now the owner deleted it and it's gone
            Assert.That(npc, Is.Null);
        }
        public void TestOsOwnerSaveAppearance()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            UUID userId = TestHelpers.ParseTail(0x1);
            float newHeight = 1.9f;

            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
            sp.Appearance.AvatarHeight = newHeight;
            SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
            SceneObjectPart part = so.RootPart;
            m_scene.AddSceneObject(so);

            OSSL_Api osslApi = new OSSL_Api();
            osslApi.Initialize(m_engine, part, null, null);

            string notecardName = "appearanceNc";

            osslApi.osOwnerSaveAppearance(notecardName);

            IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
            Assert.That(items.Count, Is.EqualTo(1));

            TaskInventoryItem ncItem = items[0];
            Assert.That(ncItem.Name, Is.EqualTo(notecardName));

            AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
            Assert.That(ncAsset, Is.Not.Null);

            AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
            anc.Decode();
            OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
            AvatarAppearance savedAppearance = new AvatarAppearance();
            savedAppearance.Unpack(appearanceOsd);

            Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
        }