public MonsterWrapper(Monster monster) { this.monster = monster; }
private bool ParsePuce(string rawBloc, Monster monster) { var match = pucemSnippet.Match(rawBloc); if (!match.Success) { Warning("Impossible de détecter la balise pucem"); return true; } monster.Type = ParseType(match.Groups["type"].Value); monster.Environment = ParseEnvironment(match.Groups["environment"].Value); monster.Climate = ParseClimate(match.Groups["climate"].Value); return true; }
private Monster Parse(WikiPage page, string rawBloc) { sources = null; this.page = page; var monster = new Monster(); var blocSources = ParseSources(rawBloc); if (blocSources != null && sources == null) { sources = blocSources; } if (!ParseNameAndCR(rawBloc, monster)) { return null; } if (!ParsePuce(rawBloc, monster)) return null; if (blocSources != null) { monster.Sources = blocSources; } monster.Id = Ids.Normalize(monster.Name); return monster; }
private bool ParseNameAndCR(string rawBloc, Monster monster) { var bdTitre = bdTitreSnippet.Match(rawBloc); if (!bdTitre.Success) { // On va vérifier si ça n'est pas un objet magique if (bdTextMagicalItemSnippet.IsMatch(rawBloc)) { return false; } throw new InvalidOperationException("Impossible de détecter la balise titre"); } monster.Name = bdTitre.Groups["Name"].Value; if (monster.Name == string.Empty) { // Impossible de lire le nom return false; } var i = monster.Name.IndexOf('('); if (i != -1) { monster.Name = monster.Name.Substring(0, i).TrimEnd(); } var fpText = bdTitre.Groups["FP"].Value; if (fpText == string.Empty || !fpText.StartsWith("fp", StringComparison.OrdinalIgnoreCase)) { // Impossible de lire le FP return false; } fpText = fpText.Substring(2).TrimStart(); if (fpText == "1/2") { fpText = "0.5"; } else if (fpText == "1/4") { fpText = "0.25"; } else if (fpText == "1/3") { fpText = "0.33"; } else if (fpText == "1/8") { fpText = "0.125"; } else if (fpText == "1/6") { fpText = "0.16"; } try { monster.CR = decimal.Parse(fpText, NumberStyles.None | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); } catch (Exception ex) { throw new InvalidOperationException(string.Format("Impossible de lire le FP {0}", fpText), ex); } return true; }