diff --git a/AideDeJeu/AideDeJeuCmd/Program.cs b/AideDeJeu/AideDeJeuCmd/Program.cs index 92dd6601..0c044d15 100644 --- a/AideDeJeu/AideDeJeuCmd/Program.cs +++ b/AideDeJeu/AideDeJeuCmd/Program.cs @@ -22,35 +22,40 @@ namespace AideDeJeuCmd var pack = new HtmlDocument(); var client = new HttpClient(); - var spells = LoadJSon>("spells.json"); + //var spells = LoadJSon>("spells.json"); + //var spellsVO = new List(); + //foreach(var spell in spells) + //{ + // spell.ParseHtml(); + // var htmlVO = await client.GetStringAsync(string.Format("https://www.aidedd.org/dnd/sorts.php?vo={0}", spell.IdVO)); + // pack.LoadHtml(htmlVO); + // var spellVO = Spell.FromHtml(pack.DocumentNode.SelectSingleNode("//div[contains(@class,'bloc')]")); + // spellVO.IdVO = spell.IdVO; + // spell.IdVF = spellVO.IdVF; + // spellsVO.Add(spellVO); + + // Console.WriteLine(string.Format("{0} : {1} / {2} : {3}", spell.IdVF, spell.NamePHB, spellVO.IdVO, spellVO.NamePHB)); + //} + //SaveJSon>("spells_vf.json", spells); + //SaveJSon>("spells_vo.json", spellsVO); + var monsters = LoadJSon>("monsters.json"); - var spellsVO = new List(); - foreach(var spell in spells) - { - spell.ParseHtml(); - var htmlVO = await client.GetStringAsync(string.Format("https://www.aidedd.org/dnd/sorts.php?vo={0}", spell.IdVO)); - pack.LoadHtml(htmlVO); - var spellVO = Spell.FromHtml(pack.DocumentNode.SelectSingleNode("//div[contains(@class,'bloc')]")); - spellVO.IdVO = spell.IdVO; - spell.IdVF = spellVO.IdVF; - spellsVO.Add(spellVO); - - Console.WriteLine(string.Format("{0} : {1} / {2} : {3}", spell.IdVF, spell.NamePHB, spellVO.IdVO, spellVO.NameVO)); - } - - foreach(var monster in monsters) + var monstersVO = new List(); + foreach (var monster in monsters) { monster.ParseHtml(); + var htmlVO = await client.GetStringAsync(string.Format("https://www.aidedd.org/dnd/monstres.php?vo={0}", monster.IdVO)); + pack.LoadHtml(htmlVO); + var monsterVO = Monster.FromHtml(pack.DocumentNode.SelectSingleNode("//div[contains(@class,'bloc')]")); + monsterVO.IdVO = monster.IdVO; + monster.IdVF = monsterVO.IdVF; + monstersVO.Add(monsterVO); + + Console.WriteLine(string.Format("{0} : {1} / {2} : {3}", monster.IdVF, monster.NamePHB, monsterVO.IdVO, monsterVO.NamePHB)); } SaveJSon>("monsters_vf.json", monsters); - SaveJSon>("spells_vf.json", spells); - //SaveJSon>("monsters_fr.json", monsters); - SaveJSon>("spells_vo.json", spellsVO); - //DataContractJsonSerializer serializer = new DataContractJsonSerializer(items.GetType()); - //MemoryStream stream = new MemoryStream(); - //serializer.WriteObject(stream, items); - //stream.Seek(0, SeekOrigin.Begin); - //string text = await new StreamReader(stream).ReadToEndAsync(); + SaveJSon>("monsters_vo.json", monstersVO); + Console.WriteLine("Hello World!"); } diff --git a/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs b/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs index 65d62cf8..54156460 100644 --- a/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs +++ b/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs @@ -50,27 +50,31 @@ namespace AideDeJeuLib.Monsters } } + public List SpecialFeatures { get; set; } [IgnoreDataMember] - public List SpecialFeatures { get; set; } - //public List SpecialFeaturesPersist - //{ - // get - // { - // return SpecialFeatures.Select(node => node.OuterHtml).ToList(); - // } - // set - // { - // List nodes = new List(); - // foreach (var str in value) - // { - // HtmlDocument doc = new HtmlDocument(); - // doc.LoadHtml(str); - // nodes.Add(doc.DocumentNode); - // } - // SpecialFeatures = nodes; - // } - //} - + public List SpecialFeaturesNodes + { + get + { + var doc = new HtmlDocument(); + var nodes = new List(); + foreach(var specialFeature in SpecialFeatures) + { + doc.LoadHtml(specialFeature); + nodes.Add(doc.DocumentNode); + } + return nodes; + } + set + { + var specialFeatures = new List(); + foreach(var node in value) + { + specialFeatures.Add(node.OuterHtml); + } + SpecialFeatures = specialFeatures; + } + } [IgnoreDataMember] public List Actions { get; set; } [IgnoreDataMember] @@ -93,7 +97,16 @@ namespace AideDeJeuLib.Monsters var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]"); this.Name = divMonster?.SelectSingleNode("h1").InnerText; - var altNames = divMonster.SelectSingleNode("div[@class='trad']")?.InnerText; + var divTrad = divMonster.SelectSingleNode("div[@class='trad']"); + + var linkVO = divTrad.SelectSingleNode("a").GetAttributeValue("href", ""); + var matchIdVF = new Regex(@"\?vf=(?.*)").Match(linkVO); + this.IdVF = matchIdVF?.Groups["idvf"]?.Value; + var matchIdVO = new Regex(@"\?vo=(?.*)").Match(linkVO); + this.IdVO = matchIdVO?.Groups["idvo"]?.Value; + + + var altNames = divTrad?.InnerText; if (altNames != null) { var matchNames = new Regex(@"\[ (?.*?) \](?: \[ (?.*?) \])?").Match(altNames); @@ -113,31 +126,39 @@ namespace AideDeJeuLib.Monsters this.Type = matchesTypeSizeAlignment?.Groups["type"]?.Value?.Trim(); this.Size = matchesTypeSizeAlignment?.Groups["size"]?.Value?.Trim(); this.Alignment = matchesTypeSizeAlignment?.Groups["alignment"]?.Value?.Trim(); + + if (string.IsNullOrEmpty(this.Type)) + { + matchesTypeSizeAlignment = new Regex("(?.*) (?.*), (?.*)").Match(typeSizeAlignment); + this.Type = matchesTypeSizeAlignment?.Groups["type"]?.Value?.Trim(); + this.Size = matchesTypeSizeAlignment?.Groups["size"]?.Value?.Trim(); + this.Alignment = matchesTypeSizeAlignment?.Groups["alignment"]?.Value?.Trim(); + } } var divRed = divSansSerif?.SelectSingleNode("div[contains(@class,'red')]"); - this.ArmorClass = divRed?.SelectSingleNode("strong[contains(text(),'armure')]")?.NextSibling?.InnerText; - this.HitPoints = divRed?.SelectSingleNode("strong[contains(text(),'Points de vie')]")?.NextSibling?.InnerText; - this.Speed = divRed?.SelectSingleNode("strong[contains(text(),'Vitesse')]")?.NextSibling?.InnerText; + this.ArmorClass = divRed?.SelectSingleNode("strong[contains(text(),'armure') or contains(text(),'Armor Class')]")?.NextSibling?.InnerText; + this.HitPoints = divRed?.SelectSingleNode("strong[contains(text(),'Points de vie') or contains(text(),'Hit Points')]")?.NextSibling?.InnerText; + this.Speed = divRed?.SelectSingleNode("strong[contains(text(),'Vitesse') or contains(text(),'Speed')]")?.NextSibling?.InnerText; - this.Strength = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'FOR')]")?.NextSibling?.NextSibling?.InnerText; + this.Strength = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'FOR') or contains(text(),'STR')]")?.NextSibling?.NextSibling?.InnerText; this.Dexterity = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'DEX')]")?.NextSibling?.NextSibling?.InnerText; this.Constitution = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CON')]")?.NextSibling?.NextSibling?.InnerText; this.Intelligence = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'INT')]")?.NextSibling?.NextSibling?.InnerText; - this.Wisdom = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'SAG')]")?.NextSibling?.NextSibling?.InnerText; + this.Wisdom = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'SAG') or contains(text(),'WIS')]")?.NextSibling?.NextSibling?.InnerText; this.Charisma = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CHA')]")?.NextSibling?.NextSibling?.InnerText; - this.SavingThrows = divRed?.SelectSingleNode("strong[contains(text(),'Jets de sauvegarde')]")?.NextSibling?.InnerText; - this.Skills = divRed?.SelectSingleNode("strong[contains(text(),'Compétences')]")?.NextSibling?.InnerText; + this.SavingThrows = divRed?.SelectSingleNode("strong[contains(text(),'Jets de sauvegarde') or contains(text(),'Saving Throws')]")?.NextSibling?.InnerText; + this.Skills = divRed?.SelectSingleNode("strong[contains(text(),'Compétences') or contains(text(),'Skills')]")?.NextSibling?.InnerText; - this.DamageVulnerabilities = divRed?.SelectSingleNode("strong[contains(text(),'Vulnérabilités aux dégâts')]")?.NextSibling?.InnerText; - this.DamageResistances = divRed?.SelectSingleNode("strong[contains(text(),'Résistances aux dégâts')]")?.NextSibling?.InnerText; - this.DamageImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux dégâts')]")?.NextSibling?.InnerText; - this.ConditionImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux conditions')]")?.NextSibling?.InnerText; + this.DamageVulnerabilities = divRed?.SelectSingleNode("strong[contains(text(),'Vulnérabilités aux dégâts') or contains(text(),'Damage vulnerabilities')]")?.NextSibling?.InnerText; + this.DamageResistances = divRed?.SelectSingleNode("strong[contains(text(),'Résistances aux dégâts') or contains(text(),'Damage Resistances')]")?.NextSibling?.InnerText; + this.DamageImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux dégâts') or contains(text(),'Damage Immunities')]")?.NextSibling?.InnerText; + this.ConditionImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux conditions') or contains(text(),'Conditions Immunities')]")?.NextSibling?.InnerText; - this.Senses = divRed?.SelectSingleNode("strong[contains(text(),'Sens')]")?.NextSibling?.InnerText; - this.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues')]")?.NextSibling?.InnerText; - this.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance')]")?.NextSibling?.InnerText; + this.Senses = divRed?.SelectSingleNode("strong[contains(text(),'Sens') or contains(text(),'Senses')]")?.NextSibling?.InnerText; + this.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues') or contains(text(),'Languages')]")?.NextSibling?.InnerText; + this.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance') or contains(text(),'Challenge')]")?.NextSibling?.InnerText; List nodes = new List(); List specialFeatures = null; @@ -153,7 +174,7 @@ namespace AideDeJeuLib.Monsters specialFeatures = nodes; nodes = new List(); } - else if (node.InnerText == "ACTIONS LÉGENDAIRES") + else if (node.InnerText == "ACTIONS LÉGENDAIRES" || node.InnerText == "LEGENDARY ACTIONS") { actions = nodes; nodes = new List(); @@ -181,7 +202,7 @@ namespace AideDeJeuLib.Monsters legendaryActions = nodes; } - this.SpecialFeatures = specialFeatures; + this.SpecialFeaturesNodes = specialFeatures; this.Actions = actions; this.LegendaryActions = legendaryActions;