Example #1
0
        //TODO:
        //This method exists in the Skill class, should probably combine them into a math library or something
        private static string ReplaceStringWithNumber(Character.Iactor player, string expression)
        {
            //would like to make this a bit more generic so if new attributes are inserted we don't have to change this method
            //I think easiest way is to have the expression be separated by spaces, but just so it works with anything let's get rid of
            //any mathematical signs and then we should just have the name of the attributes we want.
            string temp = expression;
            string[] operators = new string[] { "+", "-", "/", "*", "(", ")", "[", "]", "{", "}", "^", "SQRT", "POW", "MAX" };
            foreach (string operand in operators) {
                temp = temp.Replace(operand, " ");
            }

            //need to get rid of repeats and empty spaces
            string[] attributeList = temp.Split(' ');

            //if you cocked your head to the side at this assignment, read over the code again.
            temp = expression;

            foreach (string attributeName in attributeList) {
                if (!string.IsNullOrEmpty(attributeName)) {
                    if (player.GetAttributes().ContainsKey(attributeName)) {
                        temp = temp.Replace(attributeName, player.GetAttributeValue("attributeName").ToString());
                    }
                    else if (player.GetSubAttributes().ContainsKey(attributeName)) {
                        temp = temp.Replace(attributeName, player.GetSubAttributes()[attributeName].ToString());
                    }
                    else if (attributeName.Contains("Rank")) {
                        temp = temp.Replace(attributeName, player.GetAttributeRank(attributeName.Substring(0, attributeName.Length - 4)).ToString());
                    }
                    else if (attributeName.Contains("Bonus")){ //this part does not exist in the Skill class method
                        string bonusName = attributeName.Replace("Bonus", "");
                        double replacementValue = player.GetBonus((CharacterEnums.BonusTypes)Enum.Parse(typeof(CharacterEnums.BonusTypes), bonusName));
                        temp = temp.Replace(attributeName, replacementValue.ToString());
                    }
                }
            }

            return temp;
        }