예제 #1
0
        public UUID CreateNPC(string firstname, string lastname,
                              Vector3 position, UUID agentID, UUID owner, bool senseAsAgent, Scene scene,
                              AvatarAppearance appearance)
        {
            NPCAvatar npcAvatar = null;

            try
            {
                if (agentID == UUID.Zero)
                {
                    npcAvatar = new NPCAvatar(firstname, lastname, position,
                                              owner, senseAsAgent, scene);
                }
                else
                {
                    npcAvatar = new NPCAvatar(firstname, lastname, agentID, position,
                                              owner, senseAsAgent, scene);
                }
            }
            catch (Exception e)
            {
                m_log.Info("[NPC MODULE]: exception creating NPC avatar: " + e.ToString());
                return(UUID.Zero);
            }

            npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
                                                                int.MaxValue);

            m_log.DebugFormat(
                "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
                firstname, lastname, npcAvatar.AgentId, owner,
                senseAsAgent, position, scene.RegionInfo.RegionName);

            AgentCircuitData acd = new AgentCircuitData();

            acd.AgentID     = npcAvatar.AgentId;
            acd.firstname   = firstname;
            acd.lastname    = lastname;
            acd.ServiceURLs = new Dictionary <string, object>();

            AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
                                                                  true);

            acd.Appearance = npcAppearance;

            /*
             * for (int i = 0;
             *      i < acd.Appearance.Texture.FaceTextures.Length; i++)
             * {
             *  m_log.DebugFormat(
             *          "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
             *          acd.AgentID, i,
             *          acd.Appearance.Texture.FaceTextures[i]);
             * }
             */

            lock (m_avatars)
            {
                scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
                                                        acd);
                scene.AddNewAgent(npcAvatar, PresenceType.Npc);

                ScenePresence sp;
                if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
                {
                    /*
                     * m_log.DebugFormat(
                     *      "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
                     *      sp.Name, sp.UUID);
                     */

                    sp.CompleteMovement(npcAvatar, false);
                    m_avatars.Add(npcAvatar.AgentId, npcAvatar);
                    m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);

                    return(npcAvatar.AgentId);
                }
                else
                {
                    m_log.WarnFormat(
                        "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
                        sp.Name, sp.UUID);

                    return(UUID.Zero);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Check if the caller has permission to manipulate the given NPC.
 /// </summary>
 /// <param name="av"></param>
 /// <param name="callerID"></param>
 /// <returns>true if they do, false if they don't.</returns>
 private bool CheckPermissions(NPCAvatar av, UUID callerID)
 {
     return(callerID == UUID.Zero || av.OwnerID == UUID.Zero ||
            av.OwnerID == callerID);
 }