1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-11-01 16:05:42 +00:00

Monstres VO

This commit is contained in:
Yan Maniez 2018-05-23 21:52:38 +02:00
parent 9028860878
commit df542b3108
2 changed files with 87 additions and 61 deletions

View file

@ -22,35 +22,40 @@ namespace AideDeJeuCmd
var pack = new HtmlDocument(); var pack = new HtmlDocument();
var client = new HttpClient(); var client = new HttpClient();
var spells = LoadJSon<IEnumerable<Spell>>("spells.json"); //var spells = LoadJSon<IEnumerable<Spell>>("spells.json");
//var spellsVO = new List<Spell>();
//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<IEnumerable<Spell>>("spells_vf.json", spells);
//SaveJSon<IEnumerable<Spell>>("spells_vo.json", spellsVO);
var monsters = LoadJSon<IEnumerable<Monster>>("monsters.json"); var monsters = LoadJSon<IEnumerable<Monster>>("monsters.json");
var spellsVO = new List<Spell>(); var monstersVO = new List<Monster>();
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) foreach (var monster in monsters)
{ {
monster.ParseHtml(); 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<IEnumerable<Monster>>("monsters_vf.json", monsters); SaveJSon<IEnumerable<Monster>>("monsters_vf.json", monsters);
SaveJSon<IEnumerable<Spell>>("spells_vf.json", spells); SaveJSon<IEnumerable<Monster>>("monsters_vo.json", monstersVO);
//SaveJSon<IEnumerable<Monster>>("monsters_fr.json", monsters);
SaveJSon<IEnumerable<Spell>>("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();
Console.WriteLine("Hello World!"); Console.WriteLine("Hello World!");
} }

View file

@ -50,27 +50,31 @@ namespace AideDeJeuLib.Monsters
} }
} }
public List<string> SpecialFeatures { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
public List<HtmlNode> SpecialFeatures { get; set; } public List<HtmlNode> SpecialFeaturesNodes
//public List<string> SpecialFeaturesPersist {
//{ get
// get {
// { var doc = new HtmlDocument();
// return SpecialFeatures.Select(node => node.OuterHtml).ToList(); var nodes = new List<HtmlNode>();
// } foreach(var specialFeature in SpecialFeatures)
// set {
// { doc.LoadHtml(specialFeature);
// List<HtmlNode> nodes = new List<HtmlNode>(); nodes.Add(doc.DocumentNode);
// foreach (var str in value) }
// { return nodes;
// HtmlDocument doc = new HtmlDocument(); }
// doc.LoadHtml(str); set
// nodes.Add(doc.DocumentNode); {
// } var specialFeatures = new List<string>();
// SpecialFeatures = nodes; foreach(var node in value)
// } {
//} specialFeatures.Add(node.OuterHtml);
}
SpecialFeatures = specialFeatures;
}
}
[IgnoreDataMember] [IgnoreDataMember]
public List<HtmlNode> Actions { get; set; } public List<HtmlNode> Actions { get; set; }
[IgnoreDataMember] [IgnoreDataMember]
@ -93,7 +97,16 @@ namespace AideDeJeuLib.Monsters
var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]"); var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]");
this.Name = divMonster?.SelectSingleNode("h1").InnerText; 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=(?<idvf>.*)").Match(linkVO);
this.IdVF = matchIdVF?.Groups["idvf"]?.Value;
var matchIdVO = new Regex(@"\?vo=(?<idvo>.*)").Match(linkVO);
this.IdVO = matchIdVO?.Groups["idvo"]?.Value;
var altNames = divTrad?.InnerText;
if (altNames != null) if (altNames != null)
{ {
var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames); var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames);
@ -113,31 +126,39 @@ namespace AideDeJeuLib.Monsters
this.Type = matchesTypeSizeAlignment?.Groups["type"]?.Value?.Trim(); this.Type = matchesTypeSizeAlignment?.Groups["type"]?.Value?.Trim();
this.Size = matchesTypeSizeAlignment?.Groups["size"]?.Value?.Trim(); this.Size = matchesTypeSizeAlignment?.Groups["size"]?.Value?.Trim();
this.Alignment = matchesTypeSizeAlignment?.Groups["alignment"]?.Value?.Trim(); this.Alignment = matchesTypeSizeAlignment?.Groups["alignment"]?.Value?.Trim();
if (string.IsNullOrEmpty(this.Type))
{
matchesTypeSizeAlignment = new Regex("(?<size>.*) (?<type>.*), (?<alignment>.*)").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')]"); var divRed = divSansSerif?.SelectSingleNode("div[contains(@class,'red')]");
this.ArmorClass = divRed?.SelectSingleNode("strong[contains(text(),'armure')]")?.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')]")?.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')]")?.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.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.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.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.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.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')]")?.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.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')]")?.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')]")?.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')]")?.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.Senses = divRed?.SelectSingleNode("strong[contains(text(),'Sens') or contains(text(),'Senses')]")?.NextSibling?.InnerText;
this.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues')]")?.NextSibling?.InnerText; this.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues') or contains(text(),'Languages')]")?.NextSibling?.InnerText;
this.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance')]")?.NextSibling?.InnerText; this.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance') or contains(text(),'Challenge')]")?.NextSibling?.InnerText;
List<HtmlNode> nodes = new List<HtmlNode>(); List<HtmlNode> nodes = new List<HtmlNode>();
List<HtmlNode> specialFeatures = null; List<HtmlNode> specialFeatures = null;
@ -153,7 +174,7 @@ namespace AideDeJeuLib.Monsters
specialFeatures = nodes; specialFeatures = nodes;
nodes = new List<HtmlNode>(); nodes = new List<HtmlNode>();
} }
else if (node.InnerText == "ACTIONS LÉGENDAIRES") else if (node.InnerText == "ACTIONS LÉGENDAIRES" || node.InnerText == "LEGENDARY ACTIONS")
{ {
actions = nodes; actions = nodes;
nodes = new List<HtmlNode>(); nodes = new List<HtmlNode>();
@ -181,7 +202,7 @@ namespace AideDeJeuLib.Monsters
legendaryActions = nodes; legendaryActions = nodes;
} }
this.SpecialFeatures = specialFeatures; this.SpecialFeaturesNodes = specialFeatures;
this.Actions = actions; this.Actions = actions;
this.LegendaryActions = legendaryActions; this.LegendaryActions = legendaryActions;