本文整理汇总了C#中IActor.GetSubAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# IActor.GetSubAttributes方法的具体用法?C# IActor.GetSubAttributes怎么用?C# IActor.GetSubAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IActor
的用法示例。
在下文中一共展示了IActor.GetSubAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplaceStringWithNumber
/// <summary>
/// For this method to work correctly the Attribute names **MUST** be separated by a space at the start and end.
/// (Dexterity+Cunning) will not work it needs to be ( Dexterity + Cunning ) any other math symbols and numbers do not require
/// spaces.
/// </summary>
/// <param name="player"></param>
/// <returns></returns>
private string ReplaceStringWithNumber(IActor player, string calculation) {
//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 = calculation;
string[] operators = new string[] { "+", "-", "/", "*", "(", ")", "[", "]", "{", "}", "^", "SQRT", "POW", "." };
foreach (string operand in operators) {
temp = temp.Replace(operand, " ");
}
//need to get rid of repeats and empty spaces
string[] attributeList = temp.Split(' ');
temp = calculation;
foreach (string attributeName in attributeList) {
if (!string.IsNullOrEmpty(attributeName)) {
if (player.GetAttributes().Any(a => a.Name == attributeName.CamelCaseWord())) {
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());
}
}
}
return temp;
}
示例2: ReplaceStringWithNumber
//TODO:
//This method exists in the Skill class, should probably combine them into a math library or something
private static string ReplaceStringWithNumber(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().Any(a => a.Name == attributeName.CamelCaseWord())) {
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((BonusTypes)Enum.Parse(typeof(BonusTypes), bonusName));
temp = temp.Replace(attributeName, replacementValue.ToString());
}
}
}
return temp;
}