当前位置: 首页>>代码示例>>C#>>正文


C# IActor.GetAttributes方法代码示例

本文整理汇总了C#中IActor.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# IActor.GetAttributes方法的具体用法?C# IActor.GetAttributes怎么用?C# IActor.GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IActor的用法示例。


在下文中一共展示了IActor.GetAttributes方法的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;
		}
开发者ID:jandar78,项目名称:Novus,代码行数:38,代码来源:ScriptMethods.cs

示例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;
        }
开发者ID:jandar78,项目名称:Novus,代码行数:39,代码来源:Combat.cs


注:本文中的IActor.GetAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。