/// <summary> /// Creates a new DamageModifier based on the specified input text. /// </summary> /// <param name="input">The input text to get a match for. For example, "+3(cold:both)".</param> /// <returns>Returns the new DamageModifier, or null if a no matches were found for the specified input.</returns> public static List <DamageModifier> Create(string input) { const string pattern = @"(?<operator>[+-x]?)(?<modifier>\d+)\((?<damageType>\w+):(?<modifierPart>(total)|(attack)|(damage)|(both))"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(input); if (matches.Count == 0) { return(null); } List <DamageModifier> damageModifiers = new List <DamageModifier>(); foreach (Match match in matches) { DamageModifier damageModifier = new DamageModifier(); damageModifier.@operator = RegexHelper.GetValue <string>(match, "operator"); damageModifier.modifier = RegexHelper.GetValue <double>(match, "modifier"); damageModifier.damageType = RegexHelper.GetValue <string>(match, "damageType"); damageModifier.modifierPart = RegexHelper.GetValue <string>(match, "modifierPart"); damageModifiers.Add(damageModifier); } return(damageModifiers); }
public ChangeWeatherCardEvent(object[] args) : base(args) { // TODO: Figure out an elegant way to map the parameter names to the arguments. if (args[2] != null) { damageModifier = DamageModifier.Create((string)args[2]); } }