use of delta.games.lotro.lore.quests.QuestDescription in project lotro-tools by dmorcellet.
the class MainTestQuestParsing method main.
/**
* Basic main method for test.
* @param args Not used.
*/
public static void main(String[] args) {
String url0 = "http://lorebook.lotro.com/wiki/Quest:Disrupting_the_Ritual";
String url1 = "http://lorebook.lotro.com/wiki/Special:LotroResource?id=1879157116";
// String url2="http://lorebook.lotro.com/wiki/Quest:Return_to_the_Elders";
// String url3="http://lorebook.lotro.com/wiki/Quest:A_Visit_to_the_Warren";
// String url4="http://lorebook.lotro.com/wiki/Quest:Ending_the_Nightmare";
String url5 = "http://lorebook.lotro.com/wiki/Quest:Vol._II,_Book_8,_Chapter_4:_A_Relic_in_Nal%C3%A2-d%C3%BBm";
// repeatable
String url6 = "http://lorebook.lotro.com/wiki/Quest:Quelling_the_Riot";
// String url7="http://lorebook.lotro.com/wiki/Quest:Set_the_Trap"; // Fellowship
// Skirmish
String url8 = "http://lorebook.lotro.com/wiki/Quest:Assault_on_the_Ringwraiths%27_Lair_--_Daily";
// crafting / receive&select objects
String url9 = "http://lorebook.lotro.com/wiki/Quest:Crafting%3A_Gems_for_Guleneth";
// required classes
String url10 = "http://lorebook.lotro.com/wiki/Quest:A_Song_for_the_Company";
// maximum level
String url11 = "http://lorebook.lotro.com/wiki/Quest:Task:_Mossy_Carapaces";
// String url12="http://lorebook.lotro.com/wiki/Quest:The_Heart_of_the_Wood%2C_Part_III"; // traits
// titles
String url13 = "http://lorebook.lotro.com/wiki/Quest:A_Bounder_of_Great_Merit";
// passive skill
String url14 = "http://lorebook.lotro.com/wiki/Quest:A_Secret_Club";
// required races / multiple definition
String url15 = "http://lorebook.lotro.com/wiki/Quest:A_Feminine_Curve_to_the_Steel";
// multiple definition
String url16 = "http://lorebook.lotro.com/wiki/Quest:Task%3A_Coarse_Fur_%28Repeatable%29";
// destiny points
String url17 = "http://lorebook.lotro.com/wiki/Quest:A_Cauldron_of_Iron";
// monster play
String url18 = "http://lorebook.lotro.com/wiki/Quest:An_Iron_Belly";
// instanced
String url19 = "http://lorebook.lotro.com/wiki/Quest:Behind_Bars_--_Instance";
// null faction
String url20 = "http://lorebook.lotro.com/wiki/Quest:Agarochir%2C_Keeper_of_Tirband";
// String singleUrl="http://lorebook.lotro.com/wiki/Quest:Vol._I,_Book_11,_Chapter_10:_A_Pouch_of_Gems_for_a_Box_of_Keys";
String[] urls = { url0, url1, /*url2, url3, url4,*/
url5, url6, /*url7,*/
url8, url9, url10, url11, /*url12,*/
url13, url14, url15, url16, url17, url18, url19, url20 };
// String[] urls={ url16 };
QuestPageParser parser = new QuestPageParser();
for (String url : urls) {
List<QuestDescription> quests = parser.parseQuestPage(url);
if (quests != null) {
for (QuestDescription quest : quests) {
System.out.println(quest.dump());
}
} else {
System.out.println("Quest list for URL [" + url + "] is null!");
}
}
}
use of delta.games.lotro.lore.quests.QuestDescription in project lotro-tools by dmorcellet.
the class QuestPageParser method parseQuestPage.
/**
* Parse the quest page at the given URL.
* @param url URL of quest page.
* @return A list of quests or <code>null</code> if an error occurred.
*/
public List<QuestDescription> parseQuestPage(String url) {
List<QuestDescription> quests = null;
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
// <div id="lorebookNoedit">
Element lorebook = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.DIV, "id", "lorebookNoedit");
if (lorebook != null) {
// identifier
// <a id="ca-nstab-quest" class="lorebook_action_link" href="/wiki/Quest:A_Feminine_Curve_to_the_Steel">Article</a>
_key = null;
Element articleLink = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.A, "id", "ca-nstab-quest");
if (articleLink != null) {
String thisURL = articleLink.getAttributeValue("href");
if ((thisURL != null) && (thisURL.startsWith(QUEST_URL_SEED))) {
_key = thisURL.substring(QUEST_URL_SEED.length()).trim();
}
}
quests = new ArrayList<QuestDescription>();
List<Element> questSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(lorebook, HTMLElementName.DIV, "class", "lorebookquest");
if ((questSections != null) && (questSections.size() > 0)) {
for (Element questSection : questSections) {
QuestDescription quest = parseQuestSection(questSection);
if (quest != null) {
// System.out.println(quest.dump());
quests.add(quest);
quest.setKey(_key);
}
}
}
findIdentifiers(quests);
}
} catch (Exception e) {
quests = null;
_logger.error("Cannot parse quest page [" + url + "]", e);
}
return quests;
}
use of delta.games.lotro.lore.quests.QuestDescription in project lotro-companion by dmorcellet.
the class QuestsCompletionStats method dump.
/**
* Dump the contents of this object to the given stream.
* @param ps Output stream to use.
* @param verbose Verbose output or not.
*/
public void dump(PrintStream ps, boolean verbose) {
ps.println("Quest completion for [" + _name + "], category [" + _category + "]");
ps.println("Nb quests: expected=" + _nbExpectedQuests + ", done=" + _nbQuestsDone + ": " + getPercentage() + "%");
if (verbose) {
QuestsManager qm = QuestsManager.getInstance();
for (Integer id : _expectedIds) {
int nb = 0;
Integer n = _nbTimesPerQuest.get(id);
if (n != null) {
nb = n.intValue();
}
QuestDescription q = qm.getQuest(id.intValue());
String name = null;
if (q != null) {
name = q.getKey();
}
ps.println(nb + ": " + name);
}
}
}
use of delta.games.lotro.lore.quests.QuestDescription in project lotro-tools by dmorcellet.
the class QuestsItemsLoader method writeQuestsDatabase.
private void writeQuestsDatabase(List<QuestDescription> quests) {
QuestsDatabaseGenerator dbBuilder = new QuestsDatabaseGenerator();
File questsDir = dbBuilder.getQuestsDir();
questsDir.mkdirs();
QuestXMLWriter writer = new QuestXMLWriter();
for (QuestDescription quest : quests) {
int id = quest.getIdentifier();
String fileName = String.valueOf(id) + ".xml";
File questFile = new File(questsDir, fileName);
writer.write(questFile, quest, EncodingNames.UTF_8);
}
dbBuilder.writeDatabase();
}
use of delta.games.lotro.lore.quests.QuestDescription in project lotro-tools by dmorcellet.
the class QuestPageParser method parseQuestSection.
private QuestDescription parseQuestSection(Element questSection) {
QuestDescription ret = null;
try {
_quest = new QuestDescription();
Element officialSection = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(questSection, HTMLElementName.DIV, "class", "officialsection");
if (officialSection != null) {
parseQuestDescription(officialSection);
}
// Texts
StringBuilder description = new StringBuilder();
StringBuilder bestower = new StringBuilder();
StringBuilder bestowerText = new StringBuilder();
StringBuilder objectives = new StringBuilder();
List<Element> textSections = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(questSection, HTMLElementName.DIV, "class", "iteminfosection widget ui-corner-all");
for (Element textSection : textSections) {
Element titleSection = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(textSection, HTMLElementName.DIV, "class", "widget-head ui-widget-header ui-corner-top");
if (titleSection != null) {
String textSectionTitle = CharacterReference.decodeCollapseWhiteSpace(titleSection.getContent());
Element contentsSection = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(textSection, HTMLElementName.DIV, "class", "widget-body ui-widget-content ui-corner-bottom");
if (contentsSection != null) {
StringBuilder link = null;
StringBuilder text = null;
if ("Description".equals(textSectionTitle)) {
text = description;
} else if ("Bestower".equals(textSectionTitle)) {
link = bestower;
text = bestowerText;
} else if ("Objectives".equals(textSectionTitle)) {
text = objectives;
}
if (text != null) {
Element bestowerTag = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(contentsSection, HTMLElementName.DIV, "class", "bestowertext");
if (bestowerTag != null) {
String contents = JerichoHtmlUtils.getTextFromTag(bestowerTag);
text.append(contents);
}
}
if (link != null) {
Element bestowerLink = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(contentsSection, HTMLElementName.DIV, "class", "bestowerlink");
if (bestowerLink != null) {
String contents = JerichoHtmlUtils.getTextFromTag(bestowerLink);
link.append(contents);
}
}
}
}
}
_quest.setDescription(description.toString().trim());
_quest.setBestower(bestower.toString().trim());
_quest.setBestowerText(bestowerText.toString().trim());
_quest.setObjectives(objectives.toString().trim());
ret = _quest;
_quest = null;
} catch (Exception e) {
ret = null;
_logger.error("Quest [" + _key + "]. Cannot parse quest section!", e);
}
return ret;
}
Aggregations