Esempio n. 1
0
        public CollectTask CollectTask(Character giver, Character taker, Motivation motivation)
        {
            var fetch       = id.GetRandomItem();
            var fetchNumber = rand.Next(19) + 1;

            var reward       = id.GetRandomReward(fetch);
            var rewardNumber = rand.Next(19) + 1;

            var task = new CollectTask
            {
                Title       = "Retrieve a " + fetch.Name,
                Description = "{{collect task}}",

                Giver      = giver,
                Taker      = taker,
                Motivation = motivation,

                Item        = fetch,
                Count       = fetchNumber,
                Reward      = reward,
                RewardCount = rewardNumber
            };

            return(task);
        }
Esempio n. 2
0
        public void MakeCollectText(CollectTask task)
        {
            int depth = 0;

            MatchCollection matches;

            do
            {
                matches = Regex.Matches(task.Description, @"\{\{(.+?)\}\}");

                foreach (Match match in matches)
                {
                    var matchString = match.Groups[1].ToString();

                    if (matchString.StartsWith("#"))
                    {
                        ReplacePronouns(task, matchString);
                    }
                    else if (matchString.StartsWith("$"))
                    {
                        ReplaceSubjectObject(task, matchString);
                    }
                    else if (!ReplaceFetchReward(task, matchString))
                    {
                        // dict replace
                        var options = pd.Get(matchString);
                        if (options.Count == 0)
                        {
                            throw new Exception("No results found for {{" + matchString + "}}");
                        }

                        var replace = options[rand.Next(options.Count)];

                        task.Description = ReplaceToken(task.Description, matchString, replace);
                    }
                }

                depth++;

                if (depth > 50)
                {
                    throw new Exception("Text building went to deep!");
                }
            } while (matches.Count > 0);

            task.Description = SentenceCaseIt(task.Description);
        }
Esempio n. 3
0
        private bool ReplaceFetchReward(CollectTask task, string matchString)
        {
            var split = matchString.Split('_');

            if (split.Length != 2)
            {
                return(false);
            }

            Item item   = null;
            int  number = -1;

            if (split[1] == "fetch")
            {
                item   = task.Item;
                number = task.Count;
            }
            else if (split[1] == "reward")
            {
                item   = task.Reward;
                number = task.RewardCount;
            }

            string replace = null;

            if (item != null)
            {
                if (split[0] == "noun")
                {
                    replace = AttachArticle(item, number);
                }
                else if (split[0] == "pronoun")
                {
                    replace = PronounFor(item, number);
                }
            }

            if (replace != null)
            {
                task.Description = ReplaceToken(task.Description, matchString, replace);
                return(true);
            }

            return(false);
        }