Example #1
0
        private void newUser(UserData data)
        {
            AgentPrivate  agentPrivate  = ScenePrivate.FindAgent(data.User);
            ObjectPrivate objectPrivate = ScenePrivate.FindObject(agentPrivate.AgentInfo.ObjectId);

            reset(agentPrivate, objectPrivate);
        }
    private void OnChat(ChatData data)
    {
        // Try to parse the message as a chat command and ignore it if it is not a known command
        var tokens = data.Message.Split(new char[] { ' ' });

        if (CheckCommand(tokens, CommandAgentMediaUrl, 2))
        {
            string       url   = tokens[1];
            AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId);
            agent.OverrideMediaSource(url);
        }
        else if (CheckCommand(tokens, CommandAgentMediaSizeAndUrl, 4))
        {
            Int32        width  = Int32.Parse(tokens[1]);
            Int32        height = Int32.Parse(tokens[2]);
            string       url    = tokens[3];
            AgentPrivate agent  = ScenePrivate.FindAgent(data.SourceId);
            agent.OverrideMediaSource(url, width, height);
        }
        else if (CheckCommand(tokens, CommandSceneMediaUrl, 2))
        {
            string url = tokens[1];
            ScenePrivate.OverrideMediaSource(url);
        }
        else if (CheckCommand(tokens, CommandSceneMediaSizeAndUrl, 4))
        {
            Int32  width  = Int32.Parse(tokens[1]);
            Int32  height = Int32.Parse(tokens[2]);
            string url    = tokens[3];
            ScenePrivate.OverrideMediaSource(url, width, height);
        }
    }
Example #3
0
    private void PressedSpecial(AnimationData data, string key)
    {
        AgentPrivate agent = ScenePrivate.FindAgent(data.ComponentId.ObjectId);
        string       res   = "";

        if (agent == null)
        {
            Log.Write(LogLevel.Warning, GetType().Name, $"no agent");
            return;
        }
        string name = agent.AgentInfo.Name;

        //Log.Write(LogLevel.Warning, GetType().Name, $"{name} Pressed {key}");
        addKeys(name, key);

        if (isSecret(name))
        {
            players[name] = "";
            res           = do_dialog(agent, "You found the secret key combination!\nWould you like to teleport to the secret spot?");
            if (res == "Yes")
            {
                AnimationComponent comp;
                if (ScenePrivate.FindObject(data.ComponentId.ObjectId).TryGetFirstComponent <AnimationComponent>(out comp))
                {
                    comp.SetPosition(secretloc);
                }
            }
        }
    }
    private void onChat(ChatData data)
    {
        var cmds = data.Message.Split(new Char[] { ' ' });

        if (DebugLogging)
        {
            Log.Write("Chat command " + cmds[0]);
        }

        AgentPrivate agent  = ScenePrivate.FindAgent(data.SourceId);
        string       handle = agent.AgentInfo.Handle.ToLower();

        if (handle == ScenePrivate.SceneInfo.AvatarId.ToLower())
        {
            if (cmds[0] == _resetChatCommand)
            {
                onReset();
            }
        }
        else
        {
            if (DebugLogging)
            {
                Log.Write("You must be the owner of the scene");
            }
        }
    }
    private void getVRControllerInfo(ScriptEventData gotVRControllerInfo)
    {
        //Log.Write("getVRControllerInfo");
        if (gotVRControllerInfo.Data == null)
        {
            return;
        }

        VRControllerInfo sendVRControllerInfo = gotVRControllerInfo.Data.AsInterface <VRControllerInfo>();

        if (sendVRControllerInfo == null)
        {
            Log.Write(LogLevel.Error, Script.ID.ToString(), "Unable to create interface, check logs for missing member(s)");
            return;
        }

        AgentPrivate VRAgent      = sendVRControllerInfo.VRAgent;
        string       VRController = sendVRControllerInfo.VRController;
        Vector       VRControllerLocalPosition = sendVRControllerInfo.VRControllerLocalPosition;
        Vector       VRControllerWorldPosition = sendVRControllerInfo.VRControllerWorldPosition;

        Log.Write("Message Received VRAgent: " + VRAgent.AgentInfo.Name + " VRController: " + VRController + " LocalPos: " + VRControllerLocalPosition + " WorldPos: " + VRControllerWorldPosition);

        //Interact with hot spots calls go here
    }
Example #6
0
    private void OnOwnerJoined(SessionId userId)
    {
        AgentPrivate agent = ScenePrivate.FindAgent(userId);

        // Lookup the scene object for this agent
        ObjectPrivate agentObejct = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);

        if (agentObejct == null)
        {
            Log.Write($"Unable to find a ObjectPrivate component for user {userId}");
            return;
        }

        // Lookup the animation component. There should be just one, so grab the first
        AnimationComponent animationComponent = null;

        if (!agentObejct.TryGetFirstComponent(out animationComponent))
        {
            Log.Write($"Unable to find an animation component on user {userId}");
            return;
        }

        animationComponent.Subscribe(StartKey, StartSound);
        animationComponent.Subscribe(StopKey, StopSound);
    }
Example #7
0
        public List <string> GetAvailableQuests(AgentPrivate Quester)
        {
            List <string> QuestIds = new List <string>();

            HttpRequestOptions options = new HttpRequestOptions();

            options.Method = HttpRequestMethod.GET;

            Guid   PersonaId          = Quester.AgentInfo.AvatarUuid;
            string availableQuestsUrl = $"{BaseUrl}/players/{PersonaId}/characters/{CharacterId}/quest-definitions";

            Quester.SendChat($"{availableQuestsUrl}");
            var result = WaitFor(ScenePrivate.HttpClient.Request, availableQuestsUrl, options) as HttpClient.RequestData;

            if (!result.Success || result.Response.Status != 200)
            {
                return(QuestIds);
            }

            string jsonResponse = result.Response.Body;

            Quester.SendChat($"{jsonResponse}");
            StorylineResponse parsed = ((JsonSerializationData <StorylineResponse>)(WaitFor(JsonSerializer.Deserialize <StorylineResponse>, jsonResponse))).Object;

            Quester.SendChat(parsed.ToString());
            foreach (QuestData d in parsed.data)
            {
                QuestIds.Add(d.id);
            }
            return(QuestIds);
        }
Example #8
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.");
            }
        }
    }
Example #9
0
        void OnDrop(HeldObjectData data)
        {
            try
            {
                unsubscribe();
                unsubscribe = null;
                AgentPrivate user = ScenePrivate.FindAgent(holdingAgent.SessionId);

                // Do this after we get the user but before trying to use the user for chat in case they have left.
                holdingAgent         = null;
                simpleData.AgentInfo = null;
                simpleData.ObjectId  = ObjectId.Invalid;

                float accuracy = 0;
                if (shotsHit > 0)
                {
                    accuracy = 100.0f * (float)shotsHit / (float)shotsFired;
                }

                if (KeepScore)
                {
                    user.SendChat($"Final score: {score}. You hit {shotsHit} out of {shotsFired}, a hit accuracy of {accuracy.ToString("00.0")}%");
                }
            }
            catch (System.Exception) { }
        }
Example #10
0
        protected void OnAddAgent(SessionId agentId)
        {
            if (agentId == SessionId.Invalid)
            {
                QLog(LogLevel.Error, "Invalid session id");
                return;
            }

            if (activeSessionIds.ContainsKey(agentId))
            {
                QLog(LogLevel.Error, "Already tracking this user", agentId);
                return;
            }

            AgentPrivate agent = ScenePrivate.FindAgent(agentId);

            if (agent == null || !agent.IsValid)
            {
                QLog(LogLevel.Warning, "Invalid or missing agent.");
                return;
            }

            ObjectiveDefinition.GetObjective(agentId, (data) =>
            {
                if (!data.Success || data.Objective == null)
                {
                    QLog(LogLevel.Error, "Failed to get Objective for user.", agentId);
                    return;
                }

                OnAddAgentData(data.Objective, agentId);
            });
        }
Example #11
0
    private void GetChatCommand(ChatData Data)
    {
        Log.Write("Chat From: " + Data.SourceId);
        Log.Write("Chat person: " + ScenePrivate.FindAgent(Data.SourceId).AgentInfo.Name);
        AgentPrivate agent = ScenePrivate.FindAgent(Data.SourceId);

        ValidUsers.Clear();
        ValidUsers = UsersToListenTo.Split(',').ToList();
        if (UsersToListenTo.Contains("ALL"))
        {
            string DataCmd = Data.Message;
            Log.Write("DataCmd: " + DataCmd);
            ParseCommands(DataCmd);
        }
        else
        {
            foreach (string ValidUser in ValidUsers)
            {
                Log.Write("ValidUser: " + ValidUser);
                if (ScenePrivate.FindAgent(Data.SourceId).AgentInfo.Name == ValidUser.Trim())
                {
                    string DataCmd = Data.Message;
                    ParseCommands(DataCmd);
                }
            }
        }
    }
Example #12
0
        public override void OnAddUser(AgentPrivate agent)
        {
            try
            {
                if (!PerUserStatus.ContainsKey(agent.AgentInfo.SessionId))
                {
                    PerUserStatus[agent.AgentInfo.SessionId] = new Status();
                }

                for (int i = 0; i < Definitions.Count; ++i)
                {
                    ObjectiveDefinition def = Definitions[i];
                    if (!def.IsValid || !def.Ready)
                    {
                        Log.Write(LogLevel.Warning, "Error getting quest state for quest for user " + agent.AgentInfo.Name + " : " + agent.AgentInfo.AvatarUuid);
                    }
                    int Index = i;
                    if (agent != null && agent.IsValid)
                    {
                        def.GetObjective(agent, (data) => HandleObjective(data, Index));
                    }
                }
            }
            catch (Exception)
            {
                if (agent != null)
                {   // The following are cached and okay to access as long as agent itself isn't null
                    Log.Write(LogLevel.Warning, "Error getting quest state for quest for user " + agent.AgentInfo.Name + " : " + agent.AgentInfo.AvatarUuid);
                }
                else
                {
                    Log.Write(LogLevel.Warning, "Error getting quest state for quest agent is null");
                }
            }
        }
Example #13
0
        public ScenePrivate.CreateClusterData SpawnGlobalObjective(ObjectiveEntity entity)
        {
            Vector location      = new Vector(entity.definition.p.x, entity.definition.p.y, entity.definition.p.z);
            Vector eulerRotation = new Vector(entity.definition.r.x, entity.definition.r.y, entity.definition.r.z);

            Quaternion rotation = Quaternion.FromEulerAngles(eulerRotation);

            ScenePrivate.CreateClusterData createData = null;

            createData = (ScenePrivate.CreateClusterData)WaitFor(ScenePrivate.CreateCluster, objectiveCluster, location, rotation, Vector.Zero);
            ObjectPrivate.AddInteractionData addData = (ObjectPrivate.AddInteractionData)WaitFor(createData.ClusterReference.GetObjectPrivate(0).AddInteraction, entity.prompt, true);
            addData.Interaction.Subscribe((InteractionData data) =>
            {
                AgentPrivate Quester = ScenePrivate.FindAgent(data.AgentId);
                if (Quester == null || !Quester.IsValid)
                {
                    return;
                }
                HttpRequestOptions options = new HttpRequestOptions();
                options.Method             = HttpRequestMethod.PATCH;
                options.Headers            = new Dictionary <string, string>()
                {
                    { "content-type", "application/json" }
                };
                options.Body   = $"{{\"data\": {{\"state\":\"COMPLETED\"}} }}";
                Guid PersonaId = Quester.AgentInfo.AvatarUuid;
                string completeObjectiveUrl = $"{BaseUrl}/players/{PersonaId}/storylines/{entity.storylineId}/objectives/{entity.handle}";
                Quester.SendChat(completeObjectiveUrl);

                var result = WaitFor(ScenePrivate.HttpClient.Request, completeObjectiveUrl, options) as HttpClient.RequestData;
            });

            return(createData);
        }
Example #14
0
        private void OnCollide(CollisionData data, RigidBodyComponent trigger)
        {
            if (data.Phase == CollisionEventPhase.TriggerEnter)
            {
                AgentPrivate agent = ScenePrivate.FindAgent(data.HitComponentId.ObjectId);
                if (agent != null)
                {
                    try
                    {
                        CancelHideTimer(agent.AgentInfo.SessionId);

                        CollisionSimpleData.SourceObjectId = trigger.ComponentId.ObjectId;
                        if (isInVr(agent))
                        {
                            agent.Client.UI.HintText = GenerateHintText(m_vrTextString, agent.AgentInfo, CollisionSimpleData);
                        }
                        else
                        {
                            agent.Client.UI.HintText = GenerateHintText(m_textString, agent.AgentInfo, CollisionSimpleData);
                        }
                    }
                    catch (Exception) { }
                }
            }
            else if (data.Phase == CollisionEventPhase.TriggerExit)
            {
                AgentPrivate agent = ScenePrivate.FindAgent(data.HitComponentId.ObjectId);
                if (agent != null)
                {
                    HideForSessionId(agent.AgentInfo.SessionId);
                }
            }
        }
Example #15
0
        public override void Init()
        {
            if (Grid.Equals("production"))
            {
                Grid = "";
            }
            else
            {
                Grid = $".{Grid}";
            }
            BaseUrl = $"https://profiles-api{Grid}.sansar.com";
            GiveQuest.Subscribe((InteractionData idata) =>
            {
                GiveQuest.SetPrompt(GreetingText);
                AgentPrivate Quester = ScenePrivate.FindAgent(idata.AgentId);

                List <string> CompletedQuestIds = CompleteAnyQuests(Quester);
                if (CompletedQuestIds.Count > 0)
                {
                    return;
                }

                List <string> AvailableQuestIds = GetAvailableQuests(Quester);
                if (AvailableQuestIds.Count > 0)
                {
                    string firstQuestId = AvailableQuestIds[0];
                    OfferQuest(Quester, firstQuestId);

                    return;
                }

                Quester.SendChat(GreetingText);
            });
        }
Example #16
0
    void onStream(AgentPrivate agent, string medialUrl)
    {
        bool throttled = false;

        try
        {
            ScenePrivate.OverrideAudioStream(medialUrl);
            agent.SendChat("Audio Stream URL successfully updated to " + medialUrl);
            if (DebugLogging)
            {
                Log.Write("New audio stream URL: " + medialUrl);
            }
        } catch
        {
            throttled = true;
            if (DebugLogging)
            {
                Log.Write("Throttled: Unable to update audio stream URL.");
            }
        }

        if (throttled)
        {
            try
            {
                agent.SendChat("Audio stream URL update was throttled.  Try again.");
            }
            catch
            {
                // Agent left
            }
        }
    }
Example #17
0
    private void ShowStats(AgentPrivate agent)
    {
        ModalDialog            modalDialog = agent.Client.UI.ModalDialog;
        OperationCompleteEvent result      = (OperationCompleteEvent)WaitFor(modalDialog.Show, getVisitorMessage(), "OK", "Reset");

        if (result.Success && modalDialog.Response == "Reset")
        {
            WaitFor(modalDialog.Show, "Are you sure you want to reset visitor counts?", "Yes!", "Cancel");
            if (modalDialog.Response == "Yes!")
            {
                // Make a new dictionary of everyone still here to replace the current tracking info.
                Dictionary <string, Visitor> stillHere = Visitors;
                Visitors = new Dictionary <string, Visitor>();

                foreach (var visitor in stillHere)
                {
                    Visitor v = new Visitor();
                    v.TotalTime           = TimeSpan.Zero;
                    v.VisitStarted        = Stopwatch.GetTimestamp();
                    v.Here                = true;
                    Visitors[visitor.Key] = v;
                }

                WaitFor(modalDialog.Show, "Visitor times reset.", "", "Ok");
            }
        }
    }
Example #18
0
    private void TeleportToNext(CommandData data)
    {
        // Find the index of the current experience in the list
        int index = Experiences.IndexOf(ScenePrivate.SceneInfo.LocationHandle);

        // Get the next index, wrapping around. If the current location is not in the list
        // IndexOf returns -1, so the destination will be the first item in the list.
        index = (index + 1) % Experiences.Count;

        if (TP_Everyone == false)
        {
            // Lookup the agent
            AgentPrivate agent = ScenePrivate.FindAgent(data.SessionId);
            if (agent == null)
            {
                Log.Write("Unable to find user who pressed the key.");
                return;
            }

            // Actually do the teleport
            agent.Client.TeleportToLocation(PersonaHandle, Experiences[index]);
        }
        else
        {
            AgentPrivate agent = ScenePrivate.FindAgent(data.SessionId);
            StartCoroutine(TeleportAll, PersonaHandle, Experiences[index], agent);
        }
    }
Example #19
0
    private void OnChat(ChatData data)
    {
        // ignore any messages that are not from an agent
        if (data.SourceId != SessionId.Invalid)
        {
            AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId);
            if (agent == null)
            {
                Log.Write(LogLevel.Warning, "Unable to find the agent who was talking.");
                return;
            }
            if (data.Message.StartsWith(Trigger))
            {
                string command = data.Message.Substring(Trigger.Length).Trim();

                if (chatHandlers.ContainsKey(command))
                {
                    chatHandlers[command](agent);
                }
                else
                {
                    chatHandlers["help"](agent);
                }
            }
        }
    }
    }//UnhandledException

    private void OnCollide(CollisionData Data)
    {
        hitter = Data.HitComponentId.ObjectId;
        AgentPrivate hit = ScenePrivate.FindAgent(Data.HitComponentId.ObjectId);

        if (Data.Phase == CollisionEventPhase.TriggerEnter)
        {
            SceneInfo    info = ScenePrivate.SceneInfo;
            ModalDialog  Dlg;
            AgentPrivate agent = ScenePrivate.FindAgent(hitter);
            if (agent == null)
            {
                return;
            }

            Dlg = agent.Client.UI.ModalDialog;
            WaitFor(Dlg.Show, ModalMessage, "OK", "Help");
            if (Dlg.Response == "Help")
            {
                StartCoroutine(() =>
                {
                    ScenePrivate.Chat.MessageAllUsers(HelpMessage);
                    Wait(TimeSpan.FromSeconds(1));
                });
            }
        }
    }
Example #21
0
    private void msgId(SessionId sourceId, string Text)
    {
        AgentPrivate agent = ScenePrivate.FindAgent(sourceId);

        agent.SendChat($"{Text}");
        //agent.SendChat($"{ScenePrivate.SceneInfo.ExperienceName} scene!");
    }
Example #22
0
        public void RecordPickupTimed(AgentPrivate collectorAgent, Guid collectedItemId)
        {
            Guid     personaId = collectorAgent.AgentInfo.AvatarUuid;
            TimedRun timedRun;

            if (!TimedCollectorProgress.TryGetValue(personaId, out timedRun))
            {
                timedRun = new TimedRun(Collectibles);
            }
            bool isNew = timedRun.CollectItem(collectedItemId);

            TimedCollectorProgress[personaId] = timedRun;

            if (!isNew)
            {
                return;
            }
            if (timedRun.IsFinished())
            {
                collectorAgent.SendChat($"Congratulations, you collected all {Collectibles.Count} items, taking {timedRun.ElapsedTime().TotalSeconds}.{timedRun.ElapsedTime().Milliseconds} seconds!");
                PostResults(personaId, timedRun.ElapsedTime());
            }
            else
            {
                collectorAgent.SendChat($"You've collected {timedRun.Collected()} / {Collectibles.Count}, time: {timedRun.ElapsedTime().TotalSeconds}.{timedRun.ElapsedTime().Milliseconds} seconds");
            }
        }
Example #23
0
        private void Subscribe(ScriptEventData data)
        {
            unsubscribes = SubscribeToAll(ShowPromptEvent, (ScriptEventData subdata) =>
            {
                try
                {
                    ISimpleData simpledata = subdata.Data?.AsInterface <ISimpleData>();
                    if (simpledata != null)
                    {
                        AgentPrivate agent = ScenePrivate.FindAgent(simpledata.AgentInfo.SessionId);

                        if (agent != null && agent.IsValid)
                        {
                            agent.Client.UI.ModalDialog.Show(MessagePrompt, LeftButtonText, RightButtonText, (opc) =>
                            {
                                OnDialogResponse(agent.Client.UI.ModalDialog.Response, agent.AgentInfo.SessionId);
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    // Agent left.
                }
            });
        }
Example #24
0
        private void OnChat(ChatData data)
        {
            AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId);

            string[] argv = data.Message.Split(' ');

            if (agent == null)
            {
                return;
            }

            if (argv[0] == "/register")
            {
                RegisterSG(agent, true);
            }
            else if (argv[0] == "/deregister")
            {
                RegisterSG(agent, false);
            }
            else if (argv[0] == "/dial")
            {
                if (argv.Length < 2)
                {
                    ScenePrivate.Chat.MessageAllUsers("Error - need a valid address.");
                    return;
                }
                Dial(argv[1]);
            }
            else if (argv[0] == "/disconnect")
            {
                Disconnect();
            }
        }
Example #25
0
        public void RecordPickup(AgentPrivate collectorAgent, Guid collectedItemId)
        {
            Guid           personaId = collectorAgent.AgentInfo.AvatarUuid;
            HashSet <Guid> collectedItems;

            if (!CollectorProgress.TryGetValue(personaId, out collectedItems))
            {
                collectedItems = new HashSet <Guid>();
            }
            collectedItems.Add(collectedItemId);
            CollectorProgress[personaId] = collectedItems;

            Log.Write(LogLevel.Info, $"You've collected {collectedItems.Count} / {Collectibles.Count} items!");
            if (collectedItems.SetEquals(Collectibles))
            {
                Log.Write(LogLevel.Info, $"Congratulations, you collected all {Collectibles.Count} items!");
            }

            if (collectedItems.SetEquals(Collectibles))
            {
                collectorAgent.SendChat($"Congratulations, you collected all {Collectibles.Count} items!");
            }
            else
            {
                collectorAgent.SendChat($"You've collected {collectedItems.Count} / {Collectibles.Count} items!");
            }
        }
Example #26
0
 private void Bannish(AgentPrivate agent)
 {
     if (!IsAdmin(agent))
     {
         try
         {
             agent.Client.TeleportToUri(BannedDestination);
             if (DebugLogging)
             {
                 Log.Write("Say goodbye to " + agent.AgentInfo.Name);
             }
             return;
         }
         catch (NullReferenceException nre) { if (DebugLogging)
                                              {
                                                  Log.Write("Bannish", nre.Message);
                                              }
         }                                                                                           // User Gone.
         catch (System.Exception e) { if (DebugLogging)
                                      {
                                          Log.Write("Bannish", e.ToString());
                                      }
         }
     }
     else
     {
         if (DebugLogging)
         {
             Log.Write("You can't ban " + agent.AgentInfo.Name + "they're an admin!");
         }
     }
 }
Example #27
0
        void AddUser(UserData data)
        {
            try
            {
                AgentPrivate newUser = ScenePrivate.FindAgent(data.User);
                if (IsBanned(newUser))
                {
                    Wait(TimeSpan.FromSeconds(2));
                    bool admin = IsAdmin(newUser);
                    IEventSubscription timerEvent = Timer.Create(TimeSpan.FromSeconds(admin? 300 : 10), () => { Bannish(newUser); });
                    WaitFor(newUser.Client.UI.ModalDialog.Show, "You are banned." + (admin ? "\n( ;) )" : ""), admin ? "You can't ban me!" : "Okay", "Bye");

                    if (timerEvent.Active)
                    {
                        timerEvent.Unsubscribe();
                    }
                    if (newUser.Client.UI.ModalDialog.Response == "You can't ban me!")
                    {
                        Banned.Remove(newUser.AgentInfo.Handle.ToLower());
                        return;
                    }
                    Bannish(newUser);
                }
            }
            catch (NullReferenceException nre) { if (DebugSpam)
                                                 {
                                                     Log.Write("AddUser", nre.Message);
                                                 }
            }                                                                                        // ignore exceptions for not found agents.
            catch (Exception e) { if (DebugSpam)
                                  {
                                      Log.Write("AddUser", e.ToString());
                                  }
            }
        }
Example #28
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);
    }
    private void SubscribeToHotkey(SessionId userId)
    {
        AgentPrivate agent = ScenePrivate.FindAgent(userId);

        // Lookup the scene object for this agent
        ObjectPrivate agentObejct = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);

        if (agentObejct == null)
        {
            Log.Write($"Unable to find a ObjectPrivate component for user {userId}");
            return;
        }

        // Lookup the animation component. There should be just one, so grab the first
        AnimationComponent animationComponent = null;

        if (!agentObejct.TryGetFirstComponent(out animationComponent))
        {
            Log.Write($"Unable to find an animation component on user {userId}");
            return;
        }

        // Listen for a key press. Since the agent will be teleporting away, do no request a persistent subscription
        animationComponent.Subscribe(TeleportHotkey, TeleportToNext, false);
    }
    private void OnCollision(CollisionData data)
    {
        // Check to see if any agent has control
        // If no agent has control, the agent that has just entered the trigger volume is now in control
        // When leaving the agent loses control

        if (data.Phase == CollisionEventPhase.TriggerEnter)
        {
            //Log.Write("Trigger Enter");
            if (!UserIn)
            {
                //Log.Write("CollisionData Data: " + data);
                ObjId = data.HitComponentId.ObjectId;
                agent = ScenePrivate.FindAgent(ObjId);
                agent.Client.SubscribeToCommand("Trigger", CommandAction.Pressed, TriggerCommandPressed, CommandCanceled);
                agent.Client.SubscribeToCommand("Trigger", CommandAction.Released, TriggerCommandReleased, CommandCanceled);

                //Log.Write("Agent: " + agent);
                //Log.Write("Name: " + agent.AgentInfo.Name);
                UserIn = true;
                // Check to See if wearing VR Headset
                if (agent.GetControlPointEnabled(ControlPointType.GazeTarget) || agent.GetControlPointEnabled(ControlPointType.LeftTool))
                {
                    Log.Write("VR");
                    VR = true;
                    sendSimpleMessage("VR");
                }
                else
                {
                    Log.Write("NoVR");
                    VR = false;
                    //sendSimpleMessage("NoVR");
                }
            }
        }
        else if (data.Phase == CollisionEventPhase.TriggerExit)
        {
            ObjectId     exitObjId = data.HitComponentId.ObjectId;
            AgentPrivate exitAgent = ScenePrivate.FindAgent(ObjId);
            //Log.Write("agent: " + agent);
            //Log.Write("exitObjId  " + exitObjId);
            //Log.Write("exitAgent: " + exitAgent);
            if (agent == exitAgent)
            {
                Log.Write("User has Left: " + agent.AgentInfo.Name);
                UserIn = false;
            }
            else
            {
                Log.Write("Another User had Control: " + agent.AgentInfo.Name);
            }
        }

        if (UserIn && VR) //Active User and they are wearing VR Headset
        {
            //Log.Write("User in Conrol Has VR - Left Tool: " + agent.GetControlPointEnabled(ControlPointType.LeftTool) + " - Right Tool: " + agent.GetControlPointEnabled(ControlPointType.RightTool));
            //UpdatePosition();
        }
    }