Beispiel #1
0
        /// <summary>
        /// This is the outlet function that Exit will call
        /// </summary>
        private void Outlet(User user, UserStateResult result, UserFormSubmission input)
        {
            if (this.FirstUser)
            {
                lock (this.FirstUserLock)
                {
                    if (this.FirstUser)
                    {
                        foreach (var listener in this.StateEndingListeners)
                        {
                            listener?.Invoke();
                        }
                        this.FirstUser = false;
                    }
                }
            }

            lock (user)
            {
                foreach (var listener in this.PerUserStateEndingListeners)
                {
                    listener?.Invoke(user);
                }
            }

            if (this.UserOutletOverrides.TryGetValue(user, out Connector connector))
            {
                connector(user, result, input);
            }
            else
            {
                this.InternalOutlet(user, result, input);
            }
        }
Beispiel #2
0
 public void Inlet(User user, UserStateResult result, UserFormSubmission formSubmission)
 {
     if (!this.UsersInLobby.ContainsKey(user.Id))
     {
         throw new Exception("User not registered for this lobby");
     }
     this.WaitForLobbyStart.Inlet(user, result, formSubmission);
 }
Beispiel #3
0
 /// <summary>
 /// The inlet to the transition.
 /// </summary>
 /// <param name="user">The user to move into the transition.</param>
 /// <param name="stateResult">The state result of the last node (this transition doesnt care).</param>
 /// <param name="formSubmission">The user input of the last node (this transition doesnt care).</param>
 public override void Inlet(User user, UserStateResult stateResult, UserFormSubmission formSubmission)
 {
     base.Inlet(user, stateResult, formSubmission);
     if (firstUser)
     {
         lock (firstUserLock)
         {
             if (firstUser)
             {
                 this.delayTriggerTask = DelayedTrigger(this.Delay);
                 firstUser             = false;
             }
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// The inlet to the transition.
        /// </summary>
        /// <param name="user">The user to move into the transition.</param>
        /// <param name="stateResult">The state result of the last node (this transition doesnt care).</param>
        /// <param name="formSubmission">The user input of the last node (this transition doesnt care).</param>
        public override void Inlet(User user, UserStateResult stateResult, UserFormSubmission formSubmission)
        {
            base.Inlet(user, stateResult, formSubmission);
            this.UsersWaiting.Add(user);

            // TODO: locks in this flow almost certainly have race conditions.

            // Will recalculate active users on each submission. Slight "bug" if last user becomes inactive we still wait out the timer.

            // Hurry users once all active have submitted. IFF that is the selected mode
            if (this.UsersToWaitForType == WaitForUsersType.Active &&
                !this.Hurried &&
                this.GetUsers(WaitForUsersType.Active).IsSubsetOf(this.UsersWaiting))
            {
                lock (this.TriggeredLock)
                {
                    // UsersToWaitForType cannot change.
                    if (!this.Hurried &&
                        this.GetUsers(WaitForUsersType.Active).IsSubsetOf(this.UsersWaiting))
                    {
                        this.Hurried = true;
                        this.ParentState.HurryUsers();
                    }
                }
            }

            // Proceed to next state once we have all users.
            if (!this.Triggered && this.GetUsers(WaitForUsersType.All).IsSubsetOf(this.UsersWaiting))
            {
                bool triggeringThread = false;
                lock (this.TriggeredLock)
                {
                    if (!this.Triggered && this.GetUsers(WaitForUsersType.All).IsSubsetOf(this.UsersWaiting))
                    {
                        this.Triggered   = true;
                        triggeringThread = true;
                    }
                }

                // Cannot call this from within a lock, can only be called by one thread. Other threads will just go into
                // waiting mode :)
                if (triggeringThread)
                {
                    this.Trigger();
                }
            }
        }
Beispiel #5
0
        public void Inlet(User user, UserStateResult stateResult, UserFormSubmission formSubmission)
        {
            // If there is no submit button the user is not meant to answer prompts or hurry through.
            if (!AwaitingInput(user))
            {
                return;
            }

            // Set user to answering prompts state if they arent being hurried and their current prompt has a submit button.
            if (user.StatesTellingMeToHurry.Count == 0)
            {
                user.Status = UserStatus.AnsweringPrompts;
            }
            else
            {
                // TODO: May need to pass in prompt rather than getting from user.UserState but should be okay for now.
                HandleUserTimeout(user, UserFormSubmission.WithNulls(user.UserState?.UserRequestingCurrentPrompt(user)));
            }
        }
Beispiel #6
0
 public override void Inlet(User user, UserStateResult stateResult, UserFormSubmission formSubmission)
 {
     this.WaitingState.Inlet(user, stateResult, formSubmission);
 }
Beispiel #7
0
 public virtual void Inlet(User user, UserStateResult stateResult, UserFormSubmission formSubmission)
 {
     this.InvokeEntranceListeners(user);
     this.InternalOutletConnector(user, stateResult, formSubmission);
 }
Beispiel #8
0
 public void Inlet(User user, UserStateResult stateResult, UserFormSubmission formSubmission)
 {
     this.InternalConnector?.Invoke(user, stateResult, formSubmission);
 }
Beispiel #9
0
 public void Inlet(User user, UserStateResult stateResult, UserFormSubmission formSubmission)
 {
     this.Exit.Inlet(user, stateResult, formSubmission);
 }
Beispiel #10
0
 /// <summary>
 /// Game doesn't care about your feelings, please transition all users to the next state.
 /// </summary>
 public void ForceChangeOfUserStates(UserStateResult userStateResult)
 {
     this.ApplySpecialCallbackToAllUsersInState((User user) => this.Exit.Inlet(user, userStateResult, null));
 }