Exemplo n.º 1
0
        private string FixStringValuePars(string str, int[] Pars)
        {
            string result = str;
            string tstr   = "";
            int    i      = 0;
            int    c      = result.Length;

            while (i < c)
            {
                if (result[i] != '{')
                {
                    tstr += result[i];
                    i++;
                }
                else
                {
                    i++;
                    string tstr1 = "";
                    while ((i < c) && (result[i] != '}'))
                    {
                        tstr1 += result[i];
                        i++;
                    }
                    if (tstr1 != "")
                    {
                        var parse = new QuestCalcParse();
                        parse.Clear();
                        string tmp = parse.AssignAndPreprocess(tstr1, 1);
                        if (!(parse.error || parse.default_expression))
                        {
                            parse.Parse(tmp, Pars);
                            if (!parse.error)
                            {
                                tstr += parse.answer.ToString();
                            }
                            else
                            {
                                tstr += '{' + tstr1;
                            }
                        }
                        else
                        {
                            tstr += '{' + tstr1;
                        }
                    }
                    i++;
                }
            }
            result = tstr;
            for (int p = 0; p < Quest.maxparameters; p++)
            {
                result = result.Replace("[p" + p.ToString() + "]",
                                        Pars[p].ToString());
            }
            return(result);
        }
Exemplo n.º 2
0
        // Changes state of the Location
        public string FindLocationDescription(int[] playerPars)
        {
            var found = false;
            var text  = "";

            if (RandomShowLocationDescriptions)
            {
                var    flag  = true;
                var    parse = new QuestCalcParse();
                string str   = parse.AssignAndPreprocess(LocDescrExprOrder, 1);
                if (parse.error || parse.default_expression)
                {
                    flag = false;
                }

                if (flag)
                {
                    parse.Parse(str, playerPars);
                    if (parse.calc_error)
                    {
                        flag = false;
                    }
                }

                if (flag)
                {
                    if ((parse.answer > 10) || (parse.answer < 1))
                    {
                        flag = false;
                    }
                }

                if (flag)
                {
                    string tmp = LocationDescriptions[parse.answer - 1];
                    tmp = string.IsNullOrEmpty(tmp) ? "" : tmp.Trim();
                    if (string.IsNullOrEmpty(tmp))
                    {
                        flag = false;
                    }
                }

                if (flag)
                {
                    text = LocationDescriptions[parse.answer - 1].Trim();
                }


                if (!flag)
                {
                    int c = 0;
                    while (!found)
                    {
                        int i = QuestRandom.Get("E", 10);// Random(10) + 1;
                        text = LocationDescriptions[i].Trim();
                        if (text != "")
                        {
                            found = true;
                            LocationDescription = text;
                        }
                        else
                        {
                            c++;
                        }
                        if (c > MaxLocationDescriptions * 2)
                        {
                            text  = "";
                            found = true;
                        }
                    }
                }
            }
            else
            {
                var i = LocDescrOrder;
                var c = 0;
                while (!found)
                {
                    text = LocationDescriptions[i - 1];
                    if (string.IsNullOrEmpty(text) == false)
                    {
                        found = true;
                        LocationDescription = text.Trim();
                        LocDescrOrder       = i + 1;
                    }
                    else
                    {
                        ++c;
                    }

                    ++i;
                    if (i > MaxLocationDescriptions)
                    {
                        i = 1;
                    }
                    if (c > MaxLocationDescriptions)
                    {
                        text          = "";
                        found         = true;
                        LocDescrOrder = i;
                    }
                }
            }

            //!! LocationDescription = Quest.ProcessString(text);
            return(text);
        }