Search in sources :

Example 6 with QuestDescription

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!");
        }
    }
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription)

Example 7 with QuestDescription

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;
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription) Element(net.htmlparser.jericho.Element) DownloadService(delta.games.lotro.utils.DownloadService) InputSource(org.xml.sax.InputSource) Source(net.htmlparser.jericho.Source)

Example 8 with QuestDescription

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);
        }
    }
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription) QuestsManager(delta.games.lotro.lore.quests.QuestsManager)

Example 9 with QuestDescription

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();
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription) QuestXMLWriter(delta.games.lotro.lore.quests.io.xml.QuestXMLWriter) File(java.io.File)

Example 10 with QuestDescription

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;
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription) Element(net.htmlparser.jericho.Element)

Aggregations

QuestDescription (delta.games.lotro.lore.quests.QuestDescription)10 QuestsManager (delta.games.lotro.lore.quests.QuestsManager)4 QuestsIndex (delta.games.lotro.lore.quests.index.QuestsIndex)3 File (java.io.File)3 QuestCategory (delta.games.lotro.lore.quests.index.QuestCategory)2 QuestSummary (delta.games.lotro.lore.quests.index.QuestSummary)2 QuestXMLWriter (delta.games.lotro.lore.quests.io.xml.QuestXMLWriter)2 Element (net.htmlparser.jericho.Element)2 ExtensionPredicate (delta.common.utils.files.filter.ExtensionPredicate)1 CharacterLogItem (delta.games.lotro.character.log.CharacterLogItem)1 CharacterClass (delta.games.lotro.common.CharacterClass)1 Race (delta.games.lotro.common.Race)1 Rewards (delta.games.lotro.common.Rewards)1 QuestsIndexWriter (delta.games.lotro.lore.quests.index.io.xml.QuestsIndexWriter)1 QuestXMLParser (delta.games.lotro.lore.quests.io.xml.QuestXMLParser)1 DownloadService (delta.games.lotro.utils.DownloadService)1 ArrayList (java.util.ArrayList)1 Source (net.htmlparser.jericho.Source)1 InputSource (org.xml.sax.InputSource)1