private int GetTypeIndex(Types.Attack attackType) { for (int i = 0; i < AttackTypes.Count; ++i) { if (AttackTypes[i] == Methods.GetAttackTypeString(attackType)) { return(i); } } return(0); }
private static Model.Attack GetAttack(string name, int attackMod, Types.Attack attackType, List <Model.Damage> damages) { Model.Attack attack = new Model.Attack(); attack.Name = name; attack.Modifier = attackMod; attack.Type = attackType; foreach (Model.Damage damage in damages) { attack.Damages.Add(damage); } return(attack); }
private static void ParseAttack(Model.CreatureAttributes attributes, string str, Types.Attack attackType) { Model.AttackSet attackSet = new Model.AttackSet { Name = "Full Attack", }; string attacksPattern = @"(?<NumAttacks>\d+)?\s?(?<Name>\D+)\s(?<HitMod>[+-]\d+)(\seach)?\s(\((?<Damage>[^\(]*)\))?"; Regex attacksRegex = new Regex(attacksPattern, RegexOptions.IgnoreCase); MatchCollection attackMatches = attacksRegex.Matches(str); foreach (Match attackMatch in attackMatches) { int numAttacks = 1; string name = attackMatch.Groups["Name"].Value; if (attackMatch.Groups["NumAttacks"].Value != "") { numAttacks = Convert.ToInt32(attackMatch.Groups["NumAttacks"].Value); PluralizationService ps = PluralizationService.CreateService(CultureInfo.GetCultureInfo("en-us")); name = ps.Singularize(name); } name = char.ToUpper(name[0]) + name.Substring(1); for (int i = 0; i < numAttacks; ++i) { Model.Attack attack = new Model.Attack(); attack.Name = name; attack.Modifier = Convert.ToInt32(attackMatch.Groups["HitMod"].Value); attack.Type = attackType; string damageStr = attackMatch.Groups["Damage"].Value; string damagePattern = @"(?<NumDice>\d+)(?<Die>d\d+)(?<DamageMod>[\+\-]?\d*)\s?(?<DamageType>(?!plus\b)\b\w+)?"; Regex damageRegex = new Regex(damagePattern, RegexOptions.IgnoreCase); MatchCollection damageMatches = damageRegex.Matches(damageStr); foreach (Match damageMatch in damageMatches) { Model.Damage damage = new Model.Damage(); damage.NumDice = Convert.ToInt32(damageMatch.Groups["NumDice"].Value); damage.Die = Methods.GetDieTypeFromString(damageMatch.Groups["Die"].Value); if (damageMatch.Groups["DamageMod"].Value != "") { damage.Modifier = Convert.ToInt32(damageMatch.Groups["DamageMod"].Value); } if (damageMatch.Groups["DamageType"].Value != "") { damage.DamageDescriptorSet.Add(Methods.GetDamageTypeFromString(damageMatch.Groups["DamageType"].Value)); } attack.Damages.Add(damage); } attackSet.Attacks.Add(attack); } } attributes.AttackSets.Add(attackSet); }