Exemplo n.º 1
0
    private void TeleportAll(string persona, string experience, AgentPrivate initiator)
    {
        System.Collections.Generic.List <AgentPrivate> agents = new System.Collections.Generic.List <AgentPrivate>();

        foreach (AgentPrivate agent in ScenePrivate.GetAgents())
        {
            if (agent != initiator)
            {
                agents.Add(agent);
            }
        }
        agents.Add(initiator);

        foreach (AgentPrivate agent in agents)
        {
            try
            {
                if (agent.IsValid) // Agent left a few seconds ago, skip it.
                {
                    agent.Client.TeleportToLocation(persona, experience);
                    Wait(TimeSpan.FromSeconds(TP_Delay));
                }
                else
                {
                    Log.Write(LogLevel.Warning, "TeleportAll", $"Race 1, agent {agent.AgentInfo.Name} broken handle.");
                }
            }
            catch (NullReferenceException)
            {
                // Agent _just_ left, just skip it.
                Log.Write(LogLevel.Warning, "TeleportAll", $"Race 2, agent {agent.AgentInfo.Name} broken handle exception.");
            }
        }
    }
 private void LocalTeleport(ScriptEventData data)
 {
     Log.Write("A");
     foreach (AgentPrivate agent in ScenePrivate.GetAgents())
     {
         Log.Write(agent.AgentInfo.Name);
         if (agent.AgentInfo.Name == "GranddadGotMojo")
         {
             Log.Write("Camaeraman found");
             ObjectPrivate objectPrivate = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);
             if (objectPrivate != null)
             {
                 AnimationComponent anim = null;
                 if (objectPrivate.TryGetFirstComponent(out anim))
                 {
                     if (RelativeDestination)
                     {
                         anim.SetPosition(Destination + ObjectPrivate.Position);
                     }
                     else
                     {
                         anim.SetPosition(Destination);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
    // Logic!

    public override void Init()
    {
        // Write an error to the debug console if the object is not set to movable
        if (!ObjectPrivate.IsMovable)
        {
            Log.Write($"FollowArrow script can't move {ObjectPrivate.Name} because the 'Movable from Script' flag was not set!");
            return;
        }

        ScenePrivate.User.Subscribe(User.AddUser, (UserData data) =>
        {
            _followAgent = ScenePrivate.FindAgent(data.User);
        });

        ScenePrivate.User.Subscribe(User.RemoveUser, (UserData data) =>
        {
            if ((_followAgent != null) && (_followAgent.AgentInfo.SessionId == data.User))
            {
                _followAgent = null;
            }

            if (_followAgent == null)
            {
                _followAgent = ScenePrivate.GetAgents().FirstOrDefault();
            }
        });

        StartCoroutine(UpdateFollow);
    }
Exemplo n.º 4
0
 private void LocalTeleport(int MoveNumber, ScriptEventData data)
 {
     Log.Write("MoveNumber: " + MoveNumber);
     LastCameraMan = CameraMan;
     foreach (AgentPrivate agent in ScenePrivate.GetAgents())
     {
         Log.Write(agent.AgentInfo.Name);
         if (agent.AgentInfo.Name == CameraMan)
         {
             Log.Write("Camaeraman found");
             ObjectPrivate objectPrivate = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);
             if (objectPrivate != null)
             {
                 AnimationComponent anim = null;
                 if (objectPrivate.TryGetFirstComponent(out anim))
                 {
                     RigidBody.SetPosition(MoveVector[MoveNumber]);
                     Wait(TimeSpan.FromSeconds(0.05));
                     anim.SetPosition(MoveVector[MoveNumber]);
                     Wait(TimeSpan.FromSeconds(0.05));
                     Quaternion rotation = Quaternion.FromEulerAngles(Mathf.RadiansPerDegree * RotateVector[MoveNumber]);
                     RigidBody.SetOrientation(rotation);
                     //PlayMovement(MoveNumber, data);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
    public override void Init()
    {
        ScenePrivate.User.Subscribe(User.AddUser, OnAddUser);

        foreach (var visitor in ScenePrivate.GetAgents())
        {
            ScenePrivate.SetMegaphone(visitor, true);
        }
    }
Exemplo n.º 6
0
 private void MessageAllUsers(string message)
 {
     foreach (var Agent in ScenePrivate.GetAgents())
     {
         try
         {
             Agent.SendChat(message);
         }
         catch (Exception) { }
     }
 }
Exemplo n.º 7
0
    private void ParseCmd(string PrizeString)
    {
        //Log.Write("In Give Prize");
        List <string> PrizeArray = new List <string>();

        PrizeArray.Clear();
        PrizeArray = PrizeString.Split(',').ToList();

        string WinnerRaw    = PrizeArray[0];
        int    WinnerLength = WinnerRaw.Length;
        int    CmdLength    = PrizeCmd.Length;

        string Winner = WinnerRaw.Substring(CmdLength + 2, WinnerLength - CmdLength - 2);
        //Log.Write("Winner: " + Winner);
        string PrizeNumber = PrizeArray[1];
        int    PrizeIndex  = Int32.Parse(PrizeNumber) - 1;

        //Get Agent

        foreach (AgentPrivate agent in ScenePrivate.GetAgents())
        {
            //Log.Write("AgentName: " + agent.AgentInfo.Name);
            if (agent.AgentInfo.Name == Winner)
            {
                string ProductId = Prizes[PrizeIndex];
                if (!Guid.TryParse(ProductId, out ProductGuid))
                {
                    bool foundId = false;
                    // Find the ID from the store listing url. Very generic, will just find the first url segment or query arg it can convert to a UUID.
                    // https://store.sansar.com/listings/9eb72eb2-38c1-4cd3-a9eb-360e2f19e403/female-pirate-hat-r3d
                    string[] segments = ProductId.Split(new string[] { "/", "?", "&", "=" }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string segment in segments)
                    {
                        if (segment.Length >= 32 &&
                            Guid.TryParse(segment, out ProductGuid))
                        {
                            foundId = true;
                            break;
                        }
                    }

                    if (!foundId)
                    {
                        Log.Write("Not Found in Store");
                    }
                }
                //Log.Write("ProductID: " + ProductId);
                //Log.Write("Product GUID: " + ProductGuid);
                //Log.Write("agent: " + agent);
                agent.Client.OpenStoreListing(ProductGuid);
            }
        }
    }
 public void Detect(ScriptEventData data)
 {
     try
     {
         PeopleInRange         = 0;
         AgentInDetectionRange = false;
         foreach (AgentPrivate agent in ScenePrivate.GetAgents())
         {
             float agentDist = (ScenePrivate.FindObject(agent.AgentInfo.ObjectId).Position - ObjectPrivate.Position).Length();
             Log.Write("Agent: " + agent.AgentInfo.Name);
             Log.Write("agentDist: " + agentDist);
             Log.Write("DetectionRange: " + DetectionRange);
             if (agentDist <= DetectionRange)
             {
                 SimpleData sd = new SimpleData(this);
                 Log.Write("A");
                 sd.AgentInfo = agent.AgentInfo;
                 Log.Write("B");
                 sd.ObjectId = agent.AgentInfo.ObjectId;
                 Log.Write("C");
                 sd.SourceObjectId = ObjectPrivate.ObjectId;
                 Log.Write("D");
                 AgentInDetectionRange = true;
                 Log.Write("E");
                 SendToAll(OnDetection, sd);
                 Log.Write("In Range");
                 PeopleInRange++;
                 ObjectPrivate objectPrivate = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);
                 if (objectPrivate != null)
                 {
                     AnimationComponent anim = null;
                     if (objectPrivate.TryGetFirstComponent(out anim))
                     {
                         anim.SetPosition(Destination);
                     }
                 }
             }
         }
         if (PeopleInRange == 0)
         {
         }
     }
     catch (Exception ex)
     {
         if (__SimpleDebugging)
         {
             Log.Write(LogLevel.Error, __SimpleTag, "Proximity Detection Failed: " + ex.Message);
         }
     }
 }
Exemplo n.º 9
0
    void OnChat(ChatData data)
    {
        // Find the agent who wrote this chat message
        AgentPrivate owner = ScenePrivate.FindAgent(data.SourceId);

        // If the agent is the scene owner
        if ((owner != null) && (owner.AgentInfo.AvatarUuid == ScenePrivate.SceneInfo.AvatarUuid))
        {
            if (data.Message.StartsWith("/notify "))
            {
                // The message is everything after the "/notify " prefix
                var message = data.Message.Substring(8);
                if (string.IsNullOrWhiteSpace(message))
                {
                    return;
                }

                if (ModalNotifications)
                {
                    // Go through each agent in the scene
                    foreach (var agent in ScenePrivate.GetAgents())
                    {
                        // try/catch is usually a good idea when dealing with agents
                        try
                        {
                            // Display the message in a modal dialog
                            agent.Client.UI.ModalDialog.Show(message, "Ok", "");
                        }
                        catch {}
                    }
                }
                else
                {
                    // Just send a system message to chat instead
                    ScenePrivate.Chat.MessageAllUsers(message);
                }
            }
            else if (data.Message == "/help")
            {
                try
                {
                    // Let the owner know the notify chat command is available to them in the scene
                    owner.SendChat("/notify [message]");
                }
                catch {}
            }
        }
    }
    void Update()
    {
        List <string> names = new List <string>();

        foreach (AgentPrivate agent in ScenePrivate.GetAgents())
        {
            names.Add(agent.AgentInfo.Handle);
        }

        JsonSerializer.Serialize(names.ToArray(), (JsonSerializationData <string[]> data) => {
            if (data.Success)
            {
                ScenePrivate.OverrideMediaSource(url + "#" + data.JsonString);
            }
        });
    }
Exemplo n.º 11
0
        protected void Setup(OperationCompleteEvent data)
        {
            if (data != null && data.Success == false)
            {
                Log.Write("Error fetching QuestDefinition for QuestVisibility script for quest on object " + ObjectPrivate.Name);
                return;
            }

            foreach (var agent in ScenePrivate.GetAgents())
            {
                OnAddUser(agent);
            }

            ScenePrivate.User.Subscribe(User.AddUser, OnAddUser);
            ScenePrivate.User.Subscribe(User.RemoveUser, (userData) => VisibleToSessions.Remove(userData.User));
        }
Exemplo n.º 12
0
        protected override void SimpleInit()
        {
            Setup(Command1, Command1Event, Command1ReleaseEvent);
            Setup(Command2, Command2Event, Command2ReleaseEvent);
            Setup(Command3, Command3Event, Command3ReleaseEvent);
            AdvancedSetup();

            Enabled = StartEnabled;

            SubscribeToAll(EnableEvent, (data) => { Enabled = true; });
            SubscribeToAll(DisableEvent, (data) => { Enabled = false; });

            Action <SessionId> addUserAction = (SessionId userId) =>
            {
                if (OwnerOnly)
                {
                    var ap = ScenePrivate.FindAgent(userId);
                    if (ap == null || ap.AgentInfo.AvatarUuid != ScenePrivate.SceneInfo.AvatarUuid)
                    {
                        return; // early exit because they aren't the owner.
                    }
                }

                if (!HeldKeys.ContainsKey(userId))
                {
                    HeldKeys.Add(userId, 0);
                }
                Client client = ScenePrivate.FindAgent(userId)?.Client;
                if (client != null)
                {
                    Subscribe(client);
                }
            };

            ScenePrivate.User.Subscribe("AddUser", (UserData data) => addUserAction(data.User));

            // Catch any users already in the scene.
            foreach (AgentPrivate agent in ScenePrivate.GetAgents())
            {
                try
                {
                    addUserAction(agent.AgentInfo.SessionId);
                } catch { };
            }

            ScenePrivate.User.Subscribe("RemoveUser", Unsubscribe);
        }
Exemplo n.º 13
0
    public override void Init()
    {
        // Find each user as they enter the scene and list for commands from them
        ScenePrivate.User.Subscribe(User.AddUser, (UserData ud) =>
        {
            AgentPrivate agent = ScenePrivate.FindAgent(ud.User);
            if (agent != null)
            {
                ListenForCommand(agent);
            }
        });

        // Listen for commands from any users already in the scene
        foreach (var agent in ScenePrivate.GetAgents())
        {
            ListenForCommand(agent);
        }
    }
Exemplo n.º 14
0
        public override void Init()
        {
            MeshMap[State.OnlyActive]            = OnlyActive;
            MeshMap[State.OnlyAvailable]         = OnlyAvailable;
            MeshMap[State.OnlyCanTurnIn]         = OnlyCanTurnIn;
            MeshMap[State.ActiveAndAvailable]    = ActiveAndAvailable;
            MeshMap[State.ActiveAndCanTurnIn]    = ActiveAndCanTurnIn;
            MeshMap[State.AvailableAndCanTurnIn] = AvailableAndCanTurnIn;
            MeshMap[State.All]  = All;
            MeshMap[State.None] = None;

            ScenePrivate.User.Subscribe(User.RemoveUser, (userData) => OnRemoveUser(userData.User));
            ScenePrivate.User.Subscribe(User.AddUser, (userData) => OnAddUser(userData.User));
            foreach (var agent in ScenePrivate.GetAgents())
            {
                OnAddUser(agent.AgentInfo.SessionId);
            }
        }
Exemplo n.º 15
0
 private void UpdateLoop()
 {
     while (true)
     {
         //this is only one object, so we have it hard coded in to only follow the first agent., you could split this up later
         Boolean got1 = false;
         foreach (AgentPrivate agent in ScenePrivate.GetAgents())
         {
             if (got1 == false)
             {
                 ObjectPrivate      agentObejct = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);
                 AnimationComponent anim;
                 if (agentObejct.TryGetFirstComponent(out anim))
                 {
                     Sansar.Vector fwd = anim.GetVectorAnimationVariable("LLCameraForward");
                     //Builds a rotation from the fwd vector
                     Quaternion newRot = Quaternion.FromLook(fwd, Sansar.Vector.Up);
                     //This is a basic check to make sure the camera rotation isnt all 0s
                     if (fwd.LengthSquared() > 0)
                     {
                         try
                         {
                             RigidBody.SetAngularVelocity(Vector.Zero);
                             RigidBody.SetLinearVelocity(Vector.Zero);
                             RigidBody.SetPosition(agentObejct.Position + lightPositionOffset);
                             //Order of multiplication matters here I think, start with the base rotation,
                             //multiply by and base offset rotation for the light, then multiply by the rotation of the fwd
                             //Keep in mind that multiplying quad A by quad b will rotate quad A by quad b
                             RigidBody.SetOrientation(QuaternionToVector(startRot * lightOnObjectDirection * newRot).Normalized());
                         }
                         catch
                         {
                         }
                     }
                 }
                 got1 = true;
             }
         }
         Wait(TimeSpan.FromSeconds(.05));
     }
 }
Exemplo n.º 16
0
        protected override void SimpleInit()
        {
            var addUserSubscription = ScenePrivate.User.Subscribe(User.AddUser, OnAddUser);

            // for edge case where users can join scene before AddUser subscription is added
            foreach (var agent in ScenePrivate.GetAgents())
            {
                OnAddAgent(agent);
            }

            var removeUserSubscription = ScenePrivate.User.Subscribe(User.RemoveUser, (UserData data) =>
            {
                activeSessionIds.Remove(data.User);
            });

            if (!VerifyDefinition())
            {
                addUserSubscription.Unsubscribe();
                removeUserSubscription.Unsubscribe();
            }
        }
Exemplo n.º 17
0
        void DefinitionUpdate(OperationCompleteEvent data)
        {
            if (!data.Success || !ObjectiveDefinition.Ready)
            {
                QLog(LogLevel.Error, "Failed to update objective definition.");
                return;
            }

            InitObjective();

            ScenePrivate.User.Subscribe(User.AddUser, OnAddUser);
            ScenePrivate.User.Subscribe(User.RemoveUser, OnRemoveUser);

            // for edge case where users can join scene before AddUser subscription is added
            foreach (var agent in ScenePrivate.GetAgents())
            {
                try
                {
                    OnAddAgent(agent.AgentInfo.SessionId);
                }
                catch (Exception) { }
            }
        }
Exemplo n.º 18
0
        public void Detection()
        {
            while (true)
            {
                try
                {
                    if (enabled)
                    {
                        AgentInDetectionRange = false;
                        foreach (AgentPrivate agent in ScenePrivate.GetAgents())
                        {
                            float agentDist = (ScenePrivate.FindObject(agent.AgentInfo.ObjectId).Position - ObjectPrivate.Position).Length();
                            if (agentDist <= DetectionRange) // (DateTime.Now - LastDetectionTime).TotalSeconds >= SecondsToIgnore)
                            {
                                SimpleData sd = new SimpleData();
                                sd.AgentInfo = agent.AgentInfo;
                                //sd.ObjectId = sd.AgentInfo.ObjectId;
                                sd.ObjectId           = ObjectPrivate.ObjectId;
                                AgentInDetectionRange = true;
                                //Log.Write("sendMessageFlag: " + sendMessageFlag);
                                //Log.Write("Jammer: " + Jammer);
                                if (sendMessageFlag)
                                {
                                    if (Jammer == "None")
                                    {
                                        Log.Write("sending message");
                                        SendToAll(OnDetection, sd);
                                        sendMessageFlag = false;
                                        Jammer          = agent.AgentInfo.Name;
                                    }
                                    else
                                    {
                                        if (Jammer != agent.AgentInfo.Name)
                                        {
                                            SendToAll(OnDetection, sd);
                                            sendMessageFlag = false;
                                            Jammer          = agent.AgentInfo.Name;
                                        }
                                    }
                                }
                                else
                                {
                                    sendMessageFlag = false;
                                }

                                //LastDetectionTime = DateTime.Now;
                            }
                            else
                            {
                                if (!AgentInDetectionRange)
                                {
                                    sendMessageFlag = true;
                                    Jammer          = null;
                                }
                            }
                        }
                    }
                    Wait(TimeSpan.FromSeconds(ScanSeconds)); // check once per ScanSeconds
                }
                catch (Exception ex)
                {
                    Wait(TimeSpan.FromSeconds(ScanSeconds)); // ensure at least ScanSeconds on error
                    if (__SimpleDebugging)
                    {
                        Log.Write(LogLevel.Error, __SimpleTag, "Proximity Detection Failed: " + ex.Message);
                    }
                }
            }
        }
Exemplo n.º 19
0
    public override void Init()
    {
        // Displays all the registered chat commands
        ChatCommands[HelpCmd] = new ChatCommand
        {
            Action = (String s, AgentPrivate AgentPrivate) =>
            {
                StringBuilder builder = new StringBuilder();
                foreach (KeyValuePair <string, ChatCommand> handler in ChatCommands)
                {
                    builder.AppendFormat($"\n{handler.Key} : {handler.Value.Description}");
                }

                AgentPrivate.SendChat(builder.ToString());
            },
            Description = "Display this message."
        };


        // Displays the ExperienceInfo fields
        ChatCommands[ExpInfoCmd] = new ChatCommand
        {
            Action = (String s, AgentPrivate AgentPrivate) =>
            {
                StringBuilder builder = new StringBuilder();

                // Small action which only adds values that are not empty
                Action <string, object> append = (string name, object value) =>
                {
                    if (value != null && value.ToString().Length > 0)
                    {
                        builder.Append($"\n{name} {value.ToString()}");
                    }
                };

                // Add all the properties to the chat message
                SceneInfo info = ScenePrivate.SceneInfo;
                append("This experience is running build", info.BuildId);
                append("AvatarId", info.AvatarId);
                append("AccessGroup", info.AccessGroup);
                append("CompatVersion", info.CompatVersion);
                append("ProtoVersion", info.ProtoVersion);
                append("Configuration", info.Configuration);
                append("ExperienceId", info.ExperienceId);
                append("Experience", info.ExperienceName);
                append("LocationHandle", info.LocationHandle);
                append("InstanceId", info.InstanceId);
                append("LocationUri", info.SansarUri);
                append("Owner AvatarUuid", info.AvatarUuid);

                AgentPrivate.SendChat(builder.ToString());
            },
            Description = "Dumps the experience info object."
        };

        // Lists all agents currently in the scene
        ChatCommands[ListAgentsCmd] = new ChatCommand
        {
            Action = (String s, AgentPrivate AgentPrivate) =>
            {
                AgentPrivate.SendChat($"There are {ScenePrivate.AgentCount.ToString()} agents in the region.");

                // Build up a list of agents to send to the dialog.
                // The list is built up outside the coroutine as the dialog may be up for some
                // time and the list may change while it is being show.
                List <string> agents = new List <string>();
                foreach (var agent in ScenePrivate.GetAgents())
                {
                    agents.Add($"[{agent.AgentInfo.SessionId.ToString()}:{agent.AgentInfo.AvatarUuid}] {agent.AgentInfo.Name}");
                }

                StartCoroutine(ListAgents, agents, 10, AgentPrivate);
            },
            Description = "List all agents in the region."
        };

        // Report the current agent position
        ChatCommands[MyPosCmd] = new ChatCommand
        {
            Action = (String message, AgentPrivate AgentPrivate) =>
            {
                ObjectPrivate obj = ScenePrivate.FindObject(AgentPrivate.AgentInfo.ObjectId);
                if (obj != null)
                {
                    AgentPrivate.SendChat($"You are at {obj.Position}");
                }
                else
                {
                    AgentPrivate.SendChat($"Where are you? Can not find your avatar object.");
                }
            },
            Description = "Get your current position in world coordinates."
        };

        ScenePrivate.Chat.Subscribe(0, Chat.User, OnChat);
    }