Example #1
0
        /// <summary>
        /// Stores a player's active dialog into the cache.
        /// </summary>
        /// <param name="playerId">The player's unique Id</param>
        /// <param name="dialog">The dialog to store.</param>
        private static void StorePlayerDialog(string playerId, PlayerDialog dialog)
        {
            if (dialog.DialogNumber <= 0)
            {
                for (var x = 1; x <= NumberOfDialogs; x++)
                {
                    var existingDialog = PlayerDialogs.SingleOrDefault(d => d.Value.DialogNumber == x);
                    if (!DialogFilesInUse[x] || existingDialog.Value == null)
                    {
                        DialogFilesInUse[x] = true;
                        dialog.DialogNumber = x;
                        break;
                    }
                }
            }

            // Couldn't find an open dialog file. Throw error.
            if (dialog.DialogNumber <= 0)
            {
                Console.WriteLine("ERROR: Unable to locate a free dialog. Add more dialog files, update their custom tokens, and update Dialog.cs");
                return;
            }

            PlayerDialogs[playerId] = dialog;
        }
Example #2
0
        /// <summary>
        /// Removes a player's dialog from the cache.
        /// </summary>
        /// <param name="playerId">The player's unique Id.</param>
        public static void RemovePlayerDialog(string playerId)
        {
            var dialog = PlayerDialogs[playerId];

            DialogFilesInUse[dialog.DialogNumber] = false;

            PlayerDialogs.Remove(playerId);
        }
Example #3
0
        /// <summary>
        /// Loads a specific player's cached dialog information.
        /// </summary>
        /// <param name="playerId">The player's unique Id</param>
        /// <returns>The cached player dialog object.</returns>
        public static PlayerDialog LoadPlayerDialog(string playerId)
        {
            if (!PlayerDialogs.ContainsKey(playerId))
            {
                throw new Exception(nameof(playerId) + " '" + playerId + "' could not be found. Be sure to call " + nameof(LoadConversation) + " first.");
            }

            return(PlayerDialogs[playerId]);
        }
Example #4
0
 /// <summary>
 /// Checks whether a player has an active dialog in cache.
 /// </summary>
 /// <param name="playerId">The player's unique Id.</param>
 /// <returns>true if the player has the dialog, false otherwise</returns>
 public static bool HasPlayerDialog(string playerId)
 {
     return(PlayerDialogs.ContainsKey(playerId));
 }