Ejemplo n.º 1
0
        /// <summary>
        /// Almost exactly like ParseGoPlayer
        /// </summary>
        /// <param name="Words"></param>
        /// <param name="Text"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        protected static ChatCommandCast ParseCast(string[] Words, string Text, DataController Data)
        {
            Tuple <int, int, string> quote   = null;
            ChatCommandCast          command = null;
            SpellObject        spell         = null;
            string             prefix        = null;
            List <SpellObject> list          = null;
            int num = 0;

            if (Words == null || Words.Length < 2)
            {
                return(null);
            }

            // extract quoted name if second word starts with "
            // this is necessary to not care about quoted text (t someone "yes yes")
            // but only for quoted names (t "mister x" hello!)
            if (Words[1].Length > 0 && Words[1][0] == QUOTECHAR)
            {
                quote = Text.GetQuote();
            }

            /********* QUOTED NAME *********/
            if (quote != null)
            {
                // try get exact match for quoted name
                spell = Data.SpellObjects.GetItemByName(quote.Item3, false);

                if (spell != null)
                {
                    command = new ChatCommandCast(spell);
                }

                // no player with that name
                else
                {
                    Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                              "No spell with name: " + quote.Item3));
                }
            }

            /********* UNQUOTED NAME *********/
            else
            {
                prefix = Words[1];
                list   = Data.SpellObjects.GetItemsByNamePrefix(prefix);

                // extend prefix with more words
                // until there is only one or zero matches found
                // or until there is only one more word left (supposed minimal text)
                num = 2;
                while (list.Count > 1 && num < Words.Length)
                {
                    prefix += DELIMITER + Words[num];
                    list    = Data.SpellObjects.GetItemsByNamePrefix(prefix);
                    num++;
                }

                if (list.Count == 1)
                {
                    command = new ChatCommandCast(list[0]);
                }

                // still more than one player with max. prefix
                else if (list.Count > 1)
                {
                    Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                              "More than one spell with prefix: " + prefix));
                }

                // no spell with that prefix
                else
                {
                    Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                              "No spell with prefix: " + prefix));
                }
            }

            return(command);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Words"></param>
        /// <param name="Text"></param>
        /// <param name="Data"></param>
        /// <returns></returns>
        protected static ChatCommandTell ParseTell(string[] Words, string Text, DataController Data)
        {
            Tuple <int, int, string> quote   = null;
            ChatCommandTell          command = null;
            OnlinePlayer             player  = null;
            string prefix            = null;
            List <OnlinePlayer> list = null;
            int num = 0;

            if (Words == null || Words.Length < 2)
            {
                return(null);
            }

            // extract quoted name if second word starts with "
            // this is necessary to not care about quoted text (t someone "yes yes")
            // but only for quoted names (t "mister x" hello!)
            if (Words[1].Length > 0 && Words[1][0] == QUOTECHAR)
            {
                quote = Text.GetQuote();
            }

            /********* QUOTED NAME *********/
            if (quote != null)
            {
                // try get exact match for quoted name
                player = Data.OnlinePlayers.GetItemByName(quote.Item3);

                if (player != null)
                {
                    // startindex of actual text
                    int idx = Words[0].Length + quote.Item2 + 2;

                    // correct tell
                    if (idx < Text.Length)
                    {
                        command = new ChatCommandTell(
                            player.ID, Text.Substring(idx, Text.Length - idx));
                    }

                    // empty text
                    else
                    {
                        Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                                  "Can't send empty message."));
                    }
                }

                // no player with that name
                else
                {
                    Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                              "No player with name: " + quote.Item3));
                }
            }

            /********* UNQUOTED NAME *********/
            else
            {
                prefix = Words[1];
                list   = Data.OnlinePlayers.GetItemsByNamePrefix(prefix);

                // extend prefix with more words
                // until there is only one or zero matches found
                // or until there is only one more word left (supposed minimal text)
                num = 2;
                while (list.Count > 1 && num < Words.Length - 1)
                {
                    prefix += DELIMITER + Words[num];
                    list    = Data.OnlinePlayers.GetItemsByNamePrefix(prefix);
                    num++;
                }

                if (list.Count == 1)
                {
                    // startindex of actual text
                    int idx = Words[0].Length + prefix.Length + 2;

                    if (idx < Text.Length)
                    {
                        command = new ChatCommandTell(
                            list[0].ID, Text.Substring(idx, Text.Length - idx));
                    }
                    else
                    {
                        // empty text
                        Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                                  "Can't send empty message."));
                    }
                }

                // still more than one player with max. prefix
                else if (list.Count > 1)
                {
                    Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                              "More than one player with prefix: " + prefix));
                }

                // no player with that prefix
                else
                {
                    Data.ChatMessages.Add(ChatMessage.GetChatMessageForString(
                                              "No player with prefix: " + prefix));
                }
            }

            return(command);
        }