Exemple #1
0
        // Get the text to display for the event
        virtual public string GetText()
        {
            string text = qEvent.text.Translate(true);

            // Find and replace {q:element with the name of the
            // element

            text = ReplaceComponentText(text);

            // Find and replace rnd:hero with a hero
            // replaces all occurances with the one hero

            Quest.Hero h = game.quest.GetRandomHero();
            if (text.Contains("{rnd:hero"))
            {
                h.selected = true;
            }
            text = text.Replace("{rnd:hero}", h.heroData.name.Translate());

            // Random heroes can have custom lookups
            if (text.StartsWith("{rnd:hero:"))
            {
                HeroData hero  = h.heroData;
                int      start = "{rnd:hero:".Length;
                if (!hero.ContainsTrait("male"))
                {
                    if (text[start] == '{')
                    {
                        start = text.IndexOf("}", start);
                    }
                    start = text.IndexOf(":{", start) + 1;
                    if (text[start] == '{')
                    {
                        start = text.IndexOf("}", start);
                    }
                    start = text.IndexOf(":", start) + 1;
                }
                int next = start;
                if (text[next] == '{')
                {
                    next = text.IndexOf("}", next);
                }
                next = text.IndexOf(":{", next) + 1;
                int end = next;
                if (text[end] == '{')
                {
                    end = text.IndexOf("}", end);
                }
                end = text.IndexOf(":", end);
                if (end < 0)
                {
                    end = text.Length - 1;
                }
                string toReplace = text.Substring(next, end - next);
                text = new StringKey(text.Substring(start, (next - start) - 1)).Translate();
                text = text.Replace(toReplace, hero.name.Translate());
            }

            // Fix new lines and replace symbol text with special characters
            return(OutputSymbolReplace(text).Replace("\\n", "\n"));
        }
        // Get the text to display for the event
        virtual public string GetText()
        {
            string text = qEvent.text.Translate(true);

            // Find and replace rnd:hero with a hero
            // replaces all occurances with the one hero
            text = text.Replace("{rnd:hero}", game.quest.GetRandomHero().heroData.name.Translate());

            // Random heroes can have custom lookups
            if (text.StartsWith("{rnd:hero:"))
            {
                HeroData hero  = game.quest.GetRandomHero().heroData;
                int      start = "{rnd:hero:".Length;
                if (!hero.ContainsTrait("male"))
                {
                    if (text[start] == '{')
                    {
                        start = text.IndexOf("}", start);
                    }
                    start = text.IndexOf(":", start) + 1;
                    if (text[start] == '{')
                    {
                        start = text.IndexOf("}", start);
                    }
                    start = text.IndexOf(":", start) + 1;
                }
                int next = start;
                if (text[next] == '{')
                {
                    next = text.IndexOf("}", next);
                }
                next = text.IndexOf(":", next) + 1;
                int end = next;
                if (text[end] == '{')
                {
                    end = text.IndexOf("}", end);
                }
                end = text.IndexOf(":", end);
                if (end < 0)
                {
                    end = text.Length - 1;
                }
                string toReplace = text.Substring(next, end - next);
                text = new StringKey(text.Substring(start, (next - start) - 1)).Translate();
                text = text.Replace(toReplace, hero.name.Translate());
            }

            // Random numbers in events (depreciated)
            try
            {
                // Find first random number tag
                int index = text.IndexOf("{rnd:");
                // loop through event text
                while (index != -1)
                {
                    // find end of tag
                    string rand = text.Substring(index, text.IndexOf("}", index) + 1 - index);
                    // find separator
                    int separator = rand.IndexOf(":", 5);
                    // Parse min and max
                    int min, max;
                    int.TryParse(rand.Substring(5, separator - 5), out min);
                    int.TryParse(rand.Substring(separator + 1, rand.Length - separator - 2), out max);
                    // Replace with random number
                    text = text.Replace(rand, Random.Range(min, max + 1).ToString());
                    //find next random tag
                    index = text.IndexOf("{rnd:");
                }
            }
            catch (System.Exception)
            {
                game.quest.log.Add(new Quest.LogEntry("Warning: Invalid random clause in event dialog: " + text, true));
            }

            // Fix new lines and replace symbol text with special characters
            return(SymbolReplace(text).Replace("\\n", "\n"));
        }
Exemple #3
0
        // Get the text to display for the event
        virtual public string GetText()
        {
            string text = qEvent.text.Translate(true);

            // Find and replace {q:element with the name of the
            // element

            if (text.Contains("{c:"))
            {
                Regex  questItemRegex = new Regex("{c:(((?!{).)*?)}");
                string replaceFrom;
                string componentName;
                string componentText;
                foreach (Match oneVar in questItemRegex.Matches(text))
                {
                    replaceFrom   = oneVar.Value;
                    componentName = oneVar.Groups[1].Value;
                    QuestData.QuestComponent component;
                    if (game.quest.qd.components.TryGetValue(componentName, out component))
                    {
                        componentText = getComponentText(component);
                        text          = text.Replace(replaceFrom, componentText);
                    }
                }
            }

            // Find and replace rnd:hero with a hero
            // replaces all occurances with the one hero

            Quest.Hero h = game.quest.GetRandomHero();
            if (text.Contains("{rnd:hero"))
            {
                h.selected = true;
            }
            text = text.Replace("{rnd:hero}", h.heroData.name.Translate());

            // Random heroes can have custom lookups
            if (text.StartsWith("{rnd:hero:"))
            {
                HeroData hero  = h.heroData;
                int      start = "{rnd:hero:".Length;
                if (!hero.ContainsTrait("male"))
                {
                    if (text[start] == '{')
                    {
                        start = text.IndexOf("}", start);
                    }
                    start = text.IndexOf(":", start) + 1;
                    if (text[start] == '{')
                    {
                        start = text.IndexOf("}", start);
                    }
                    start = text.IndexOf(":", start) + 1;
                }
                int next = start;
                if (text[next] == '{')
                {
                    next = text.IndexOf("}", next);
                }
                next = text.IndexOf(":", next) + 1;
                int end = next;
                if (text[end] == '{')
                {
                    end = text.IndexOf("}", end);
                }
                end = text.IndexOf(":", end);
                if (end < 0)
                {
                    end = text.Length - 1;
                }
                string toReplace = text.Substring(next, end - next);
                text = new StringKey(text.Substring(start, (next - start) - 1)).Translate();
                text = text.Replace(toReplace, hero.name.Translate());
            }

            // Fix new lines and replace symbol text with special characters
            return(OutputSymbolReplace(text).Replace("\\n", "\n"));
        }