public void Consider(EvalBundle b) { if (b.dict == null) { return; } if (!b.dict.ContainsKey("purpose") || b.dict["purpose"] != "readyrolls") { return; } mainGrid.Children.Clear(); mainGrid.RowDefinitions.Clear(); var q = from el in b.dict.Keys orderby el select el; foreach (string k in q) { string v = b.dict[k]; if (k.Length < 3) { continue; } if (!k.StartsWith("\\")) { continue; } int n = k.IndexOf('\\', 1); if (n < 2) { continue; } string name = k.Substring(1, n - 1); string wpn = ""; int w = k.IndexOf("\\_wpn\\"); if (w > 0) { wpn = k.Substring(w + 6); w = wpn.IndexOf('\\'); if (w > 0) { wpn = wpn.Substring(0, w); } else { wpn = ""; } } int t = k.LastIndexOf('\\'); if (t < 0) { continue; } string tail = k.Substring(t + 1); if (k.EndsWith("\\parry") && wpn != "") { var parryStrip = new ParryStrip(); var apKey = k.Replace("\\parry", "\\ap"); if (!b.dict.ContainsKey(apKey)) { continue; } var parryAP = b.dict[apKey]; var parryPct = b.dict[k]; parryStrip.Init(name, parryChoice: wpn, ap: parryAP, parryPct: parryPct); AppendStripContents(name, parryStrip.Children, saveKey: k); } else if (k.EndsWith("\\attack") && wpn != "") { var srKey = k.Replace("\\attack", "\\sr"); if (!b.dict.ContainsKey(srKey)) { continue; } var dmgKey = k.Replace("\\attack", "\\dmg"); if (!b.dict.ContainsKey(dmgKey)) { continue; } var sr = b.dict[srKey]; var pct = v; var dmg = b.dict[dmgKey]; var attackStrip = new AttackStrip(); attackStrip.Init(name, weapon: wpn, sr: sr, pct: pct, damage: dmg, note: null); AppendStripContents(name, attackStrip.Children, saveKey: k); } else if (wpn == "") { switch (tail) { case "STR": case "CON": case "SIZ": case "INT": case "POW": case "DEX": case "APP": string stat = tail; var powStrip = new PowStrip(); powStrip.Init(name: name, stat: stat + " vs. " + stat, value: v); AppendStripContents(name, powStrip.Children, saveKey: k); break; default: string skill = tail; var skillStrip = new SkillStrip(); skillStrip.Init(name: name, skill: skill, sr: null, skillPct: v, note: null); AppendStripContents(name, skillStrip.Children, saveKey: k); break; } } } }
void Chargen_Parse_Click(object sender, RoutedEventArgs e) { var dlg = new ParseChargen(); dlg.Owner = mainWindow; dlg.HorizontalAlignment = HorizontalAlignment.Center; dlg.VerticalAlignment = VerticalAlignment.Center; if (dlg.ShowDialog() != true) { return; } var data = dlg.data.Text; var reader = new System.IO.StringReader(data); string line; // Number 43 An Average Experienced Dragon Kralorelan Samurai,Male T1: 9 TF: 20 Honor: 58 var r1 = new Regex("^[^0-9]+([0-9]+) ([0-9A-Za-z ,-]+).* T1: [0-9]+ TF: [0-9]+ .*Hit Loc: (.*)$"); var r2 = new Regex("^(........................). SR (...) (...)% (..................) ...% ..AP$"); var r3 = new Regex("^(........................). SR (...) (...)% (..................) (...)% (..)AP .*$"); var r4 = new Regex("^(........................). SR (...) (...)% ([0-9D+-]+) .*([0-9]+ Shots) .*"); var r5 = new Regex("^(........................). SR (...) (...)% ([0-9D+-]+) (.+)$"); var r6 = new Regex("^(........................). SR (...) (...)% ([0-9D+-]+)$"); var r7 = new Regex("^(........................). SR (...) (...)% (.+)$"); var r8 = new Regex("^Skills: "); var r9 = new Regex("STR .... CON .... SIZ (....) INT .... POW .... DEX .... APP .... SIZSRM .*"); var r10 = new Regex("Life.*:.* Movement: +([^ ]+) Mana:.* Damage:.*"); var name = ""; var number = ""; var hitloc = ""; int index = 0; while ((line = reader.ReadLine()) != null) { var match = r1.Match(line); if (match.Success) { number = match.Groups[1].ToString(); hitloc = match.Groups[3].ToString(); var longname = match.Groups[2].ToString(); longname = longname .Replace(",", " ") .Replace(" ", " ") .Replace(" ", " ") .Replace("An ", "") .Replace("A ", "") .Replace("Veteran ", "") .Replace("Experienced ", "") .Replace("Tough ", "") .Replace("Average ", ""); name = "#" + number + " " + longname; continue; } match = r2.Match(line); if (match.Success) { var wpn = match.Groups[1].ToString().Trim(); var sr = match.Groups[2].ToString().Trim(); var pct = match.Groups[3].ToString().Trim(); var dmg = match.Groups[4].ToString().Trim(); var attackStrip = new AttackStrip(); attackStrip.Init(name, weapon: wpn, sr: sr, pct: pct, damage: dmg, note: null); readyRolls.AppendStripContents(name, attackStrip.Children); continue; } match = r3.Match(line); if (match.Success) { var wpn = match.Groups[1].ToString().Trim(); var sr = match.Groups[2].ToString().Trim(); var pct = match.Groups[3].ToString().Trim(); var dmg = match.Groups[4].ToString().Trim(); var attackStrip = new AttackStrip(); attackStrip.Init(name, weapon: wpn, sr: sr, pct: pct, damage: dmg, note: null); readyRolls.AppendStripContents(name, attackStrip.Children); var parryPct = match.Groups[5].ToString().Trim(); var parryAP = match.Groups[6].ToString().Trim(); var parryStrip = new ParryStrip(); parryStrip.Init(name, parryChoice: wpn, ap: parryAP, parryPct: parryPct); readyRolls.AppendStripContents(name, parryStrip.Children); continue; } match = r4.Match(line); if (match.Success) { var wpn = match.Groups[1].ToString().Trim(); var sr = match.Groups[2].ToString().Trim(); var pct = match.Groups[3].ToString().Trim(); var dmg = match.Groups[4].ToString().Trim(); var note = match.Groups[5].ToString().Trim(); var attackStrip = new AttackStrip(); attackStrip.Init(name, weapon: wpn, sr: sr, pct: pct, damage: dmg, note: note); readyRolls.AppendStripContents(name, attackStrip.Children); continue; } match = r5.Match(line); if (match.Success) { var wpn = match.Groups[1].ToString().Trim(); var sr = match.Groups[2].ToString().Trim(); var pct = match.Groups[3].ToString().Trim(); var dmg = match.Groups[4].ToString().Trim(); var note = match.Groups[5].ToString().Trim(); var attackStrip = new AttackStrip(); attackStrip.Init(name, weapon: wpn, sr: sr, pct: pct, damage: dmg, note: note); readyRolls.AppendStripContents(name, attackStrip.Children); continue; } match = r6.Match(line); if (match.Success) { var wpn = match.Groups[1].ToString().Trim(); var sr = match.Groups[2].ToString().Trim(); var pct = match.Groups[3].ToString().Trim(); var dmg = match.Groups[4].ToString().Trim(); var attackStrip = new AttackStrip(); attackStrip.Init(name, weapon: wpn, sr: sr, pct: pct, damage: dmg, note: null); readyRolls.AppendStripContents(name, attackStrip.Children); continue; } match = r7.Match(line); if (match.Success) { var skill = match.Groups[1].ToString().Trim(); var sr = match.Groups[2].ToString().Trim(); var pct = match.Groups[3].ToString().Trim(); var note = match.Groups[4].ToString().Trim(); var skillStrip = new SkillStrip(); skillStrip.Init(name, skill, sr: sr, skillPct: pct, note: note); readyRolls.AppendStripContents(name, skillStrip.Children); continue; } match = r8.Match(line); if (match.Success) { var l = line.Substring("Skills: ".Length); while (l.Length > 0) { string car, ctr; Parse2Ex(l, out car, out ctr, ','); l = ctr; string skill, val; RParse2Ex(car, out skill, out val, ' '); skill = skill.Trim(); val = val.Trim(); bool special = skill.StartsWith("*"); if (special) { skill = skill.Substring(1); } if (skill == "Dodge" || special) { var skillStrip = new SkillStrip(); skillStrip.Init(name, skill, sr: null, skillPct: val, note: null); readyRolls.AppendStripContents(name, skillStrip.Children); } } continue; } match = r9.Match(line); if (match.Success) { var siz = match.Groups[1].ToString().Trim(); name = name + " (SIZ " + siz + ")"; if (dlg.ImageName != null) { map1.AcceptLibraryToken(hitloc, siz, number, dlg.ImageName, index++); } else if (dlg.fillBrush != null) { map1.AcceptGeneratedToken(hitloc, siz, number, dlg.fillBrush, index++); } continue; } match = r10.Match(line); if (match.Success) { var move = match.Groups[1].ToString().Trim(); name = name + " (Moves: " + move + ")"; continue; } } }