Ejemplo n.º 1
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);
                }
            }
        }
    }
Ejemplo n.º 2
0
    // There will be one instance of this coroutine per active user in the scene
    private void TrackUser(SessionId userId)
    {
        // Lookup the name of the agent. This is looked up now since the agent cannot be retrieved after they
        // leave the scene.
        string  name = ScenePrivate.FindAgent(userId).AgentInfo.Name;
        Visitor visitor;

        if (Visitors.TryGetValue(name, out visitor))
        {
            visitor.VisitStarted = Stopwatch.GetTimestamp();
            visitor.Here         = true;
        }
        else
        {
            visitor              = new Visitor();
            visitor.TotalTime    = TimeSpan.Zero;
            visitor.VisitStarted = Stopwatch.GetTimestamp();
            visitor.Here         = true;
            Visitors[name]       = visitor;
        }

        // Block until the agent leaves the scene
        WaitFor(ScenePrivate.User.Subscribe, User.RemoveUser, userId);

        // This should succeed unless the data has been reset.
        // Even then it _should_ succeed as we re-build it with anyone still in the region.
        if (Visitors.TryGetValue(name, out visitor))
        {
            visitor.TotalTime += visitor.ThisVisitSoFar;
            visitor.Here       = false;
        }
    }
Ejemplo n.º 3
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);
    }
Ejemplo n.º 4
0
 protected void QLog(LogLevel level, string message, SessionId sessionId, [CallerMemberName] string caller = "<???>")
 {
     try
     {
         if (DebugSpam || level == LogLevel.Error)
         {
             string    agentString = "<user-unknown>";
             AgentInfo agent       = ScenePrivate.FindAgent(sessionId)?.AgentInfo;
             if (agent != null)
             {
                 agentString = agent.Handle + ":" + agent.AvatarUuid;
             }
             string definitionString = "<objective-unknown>";
             if (ObjectiveDefinition == null)
             {
                 definitionString = "<objective-null>";
             }
             else if (!ObjectiveDefinition.Ready)
             {
                 definitionString = "<objective-not-ready>";
             }
             else
             {
                 definitionString = ObjectiveDefinition.Title;
             }
             Log.Write(level, ObjectPrivate.Name + ":" + GetType().Name + " > '" + definitionString + "' for user " + agentString);
             Log.Write(level, caller + " > " + message);
         }
     }
     catch (Exception ex)
     {
         Log.Write("Exception logging quest objective details: " + ex.GetType().Name);
         Log.Write(ex.ToString());
     }
 }
Ejemplo n.º 5
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);
            });
        }
Ejemplo n.º 6
0
    void NewUser(UserData newUser)
    {
        Client client = ScenePrivate.FindAgent(newUser.User).Client;

        // CommandReceived will be called every time the command it triggered on the client
        // CommandCanceled will be called if the subscription fails
        if (SubscribeCommand != "")
        {
            client.SubscribeToCommand(SubscribeCommand, CommandAction.Pressed, (data) =>
            {
                if (subscription == null)
                {
                    Log.Write(GetType().Name, $"[{SubscribeCommand}] Subscribing to {ActionCommand}.");
                    subscription = client.SubscribeToCommand(ActionCommand, CommandAction.All, CommandReceived, CommandCanceled);
                }
            }, CommandCanceled);
        }

        if (UnsubscribeCommand != "")
        {
            client.SubscribeToCommand(UnsubscribeCommand, CommandAction.Pressed, (data) =>
            {
                if (subscription != null)
                {
                    Log.Write(GetType().Name, $"[{UnsubscribeCommand}] Unsubscribing to {ActionCommand}.");
                    subscription.Unsubscribe();
                    subscription = null;
                }
            }, CommandCanceled);
        }
    }
Ejemplo n.º 7
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);
            });
        }
Ejemplo n.º 8
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) { }
        }
Ejemplo n.º 9
0
    // Logic!

    public override void Init()
    {
        // Subscribe to the interaction, meaning this next block of code will be executed when the object is clicked on
        MyInteraction.Subscribe((InteractionData data) =>
        {
            // Get the agent that clicked on this object
            var agent = ScenePrivate.FindAgent(data.AgentId);

            if (agent != null)
            {
                if (ObjectPrivate.IsMovable)
                {
                    // Calculate the XY difference from the agent to the object
                    Vector toObject = ObjectPrivate.Position - ScenePrivate.FindObject(agent.AgentInfo.ObjectId).Position;
                    toObject.Z      = 0.0f;

                    // If there is an XY difference in position
                    if (toObject.LengthSquared() > 0.0f)
                    {
                        // Normalize the direction vector
                        toObject = toObject.Normalized();

                        // Smoothly move the object away from the agent by the specified distance
                        ObjectPrivate.Mover.AddTranslate(ObjectPrivate.Position + toObject * Distance, Seconds, MoveMode.Smoothstep);
                    }
                }
                else
                {
                    ShowNotMovableReason(agent);
                }
            }
        });
    }
Ejemplo n.º 10
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);
                }
            }
        }
    }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        protected override void SimpleInit()
        {
            Setup(Command1, Command1Event, Command1ReleaseEvent);
            Setup(Command2, Command2Event, Command2ReleaseEvent);
            Setup(Command3, Command3Event, Command3ReleaseEvent);

            Enabled = StartEnabled;

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

            ScenePrivate.User.Subscribe("AddUser", (UserData data) =>
            {
                if (OwnerOnly)
                {
                    var ap = ScenePrivate.FindAgent(data.User);
                    if (ap == null || ap.AgentInfo.AvatarUuid != ScenePrivate.SceneInfo.AvatarUuid)
                    {
                        return; // early exit because they aren't the owner.
                    }
                }

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

            ScenePrivate.User.Subscribe("RemoveUser", Unsubscribe);
        }
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
0
    private void msgId(SessionId sourceId, string Text)
    {
        AgentPrivate agent = ScenePrivate.FindAgent(sourceId);

        agent.SendChat($"{Text}");
        //agent.SendChat($"{ScenePrivate.SceneInfo.ExperienceName} scene!");
    }