Exemplo n.º 1
0
        public XmlNodeList Condition_Check(XmlNodeList option_XmlList, out bool input_Available, out bool roll_Available)
        {
            input_Available = false;
            roll_Available  = false;
            XmlNodeList option_ReturnList = option_XmlList;

            for (int i = 0; i < option_ReturnList.Count; i++)
            {
                XmlNode option_SingleNode = option_ReturnList[i];

                if (option_SingleNode.SelectSingleNode("Conditions") != null)
                {
                    bool     option_Validate   = false;
                    string[] option_Conditions = option_SingleNode.SelectSingleNode("Conditions").
                                                 InnerText.Split(splitCharacters,
                                                                 StringSplitOptions.RemoveEmptyEntries);

                    foreach (string condition in option_Conditions)
                    {
                        //solve
                        string pCondition = GetProperty(condition.Trim());
                        pCondition = link_InfoCheck.Invoke(pCondition);

                        // check list if condition is valid this time
                        if (option_Validate)
                        {
                            option_Validate = StringCalculator.Compare(pCondition);
                        }

                        //Removes invalid option and breaks condition checking
                        if (!option_Validate)
                        {
                            option_ReturnList[i].ParentNode.RemoveChild(option_ReturnList[i]);
                            break;
                        }
                    }
                }
                // checks if Roll and Input are in the option
                if (option_SingleNode.SelectSingleNode("Input") != null)
                {
                    input_Available = true;
                }
                if (option_SingleNode.SelectSingleNode("Roll") != null)
                {
                    roll_Available = true;
                }
            }
            return(option_ReturnList);
        }
Exemplo n.º 2
0
        public XmlNodeList Roll_Solve(XmlNodeList option_XmlList, out string Result_Info)
        {
            Result_Info = ""; // Set + index info; if single: set = N
            int         diceRoll          = -1;
            int         returnIndex       = -1;
            XmlNodeList option_ReturnList = option_XmlList;

            for (int k = 0; k < option_XmlList.Count; k++)
            {
                XmlNode option_SingleNode = option_XmlList[k];

                XmlNodeList option_Roll = option_SingleNode.SelectSingleNode("Roll").ChildNodes;
                string[]    Roll_Set    = null;
                int         set_Index   = -1;

                #region Multiple-Rollset
                if (option_Roll[0].Name == "SetCondition")
                {
                    // Check which set is to be loaded
                    string[] set_Conditions = option_Roll[0].InnerText.Trim().Split(splitCharacters, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < set_Conditions.Count(); i++)
                    {
                        //solve
                        string pCondition = GetProperty(set_Conditions[i].Trim());
                        pCondition = link_InfoCheck(pCondition);

                        bool Valid = StringCalculator.Compare(pCondition);

                        // returns first valid set
                        if (Valid)
                        {
                            set_Index = i + 1;
                            break;
                        }
                    }
                    // if any set is valid; solve conditions
                    if (set_Index != -1)
                    {
                        // check if set_Index points to a pre-set
                        if (option_Roll[set_Index].Name.Contains("S_"))
                        {
                            string p_Name  = option_Roll[set_Index].Name;
                            string raw_Set = BranchPresets.SelectSingleNode("/Game/Roll/" + p_Name).InnerText.Replace(" ", "");
                            Roll_Set = raw_Set.Split(splitCharacters, StringSplitOptions.RemoveEmptyEntries);
                        }
                        else
                        {
                            string raw_Set = option_Roll[set_Index].InnerText.Replace(" ", "");
                            Roll_Set = raw_Set.Split(splitCharacters, StringSplitOptions.RemoveEmptyEntries);
                        }


                        bool   firstTime = true;
                        string rString   = "";
                        // Check conditions in Roll_Set
                        for (int j = 0; j < Roll_Set.Count(); j++)
                        {
                            string condition = Roll_Set[j].Trim();

                            // solve condition

                            while (condition.Contains("D("))
                            {
                                int first  = condition.IndexOf("D(") + 2;
                                int length = condition.IndexOf(")", first) - first;
                                int eyeMax = int.Parse(condition.Substring(first, length));
                                diceRoll  = dice.Next(1, eyeMax + 1);
                                condition = condition.Replace("D(" + eyeMax + ")", diceRoll + "");
                            }

                            condition = GetProperty(condition);

                            if (StringCalculator.Compare(condition))
                            {
                                if (firstTime)
                                {
                                    firstTime = false;
                                    rString  += option_Roll[set_Index].Name;
                                }
                                rString += ("-" + j);
                            }
                        }
                        // if any result is valid stop foreach
                        if (rString != "")
                        {
                            Result_Info = rString;
                            returnIndex = k;
                            break;
                        }
                    }
                }
                #endregion

                #region Single-Rollset
                else
                {
                    bool   firstTime = true;
                    string rString   = "";
                    for (int j = 0; j < option_Roll.Count; j++)
                    {
                        string condition = option_Roll[j].InnerText.Trim();

                        // solve condition

                        if (condition.Contains("Dice"))
                        {
                            condition = condition.Replace("Dice", diceRoll + "");
                        }

                        condition = GetProperty(condition);

                        if (StringCalculator.Compare(condition))
                        {
                            if (firstTime)
                            {
                                firstTime = false;
                                rString  += "N";
                            }
                            rString += ("-" + j);
                        }
                    }
                    // if any result is valid stop foreach
                    if (rString != "")
                    {
                        Result_Info = rString;
                        returnIndex = k;
                        break;
                    }
                }
                #endregion
            }
            // remove unuses/false options
            for (int i = 0; i < option_ReturnList.Count; i++)
            {
                if (i != returnIndex)
                {
                    option_ReturnList[i].ParentNode.RemoveChild(option_ReturnList[i]);
                }
            }
            return(option_ReturnList);
        }