Search in sources :

Example 6 with CharacterLogItem

use of delta.games.lotro.character.log.CharacterLogItem in project lotro-companion by dmorcellet.

the class VirtuesStats method parseQuestItems.

private void parseQuestItems(List<CharacterLogItem> items) {
    QuestsManager qm = QuestsManager.getInstance();
    for (CharacterLogItem item : items) {
        Integer id = item.getResourceIdentifier();
        if (id != null) {
            QuestDescription quest = qm.getQuest(id.intValue());
            if (quest != null) {
                Rewards rewards = quest.getQuestRewards();
                handleRewards("Quest:" + id, rewards);
            }
        }
    }
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription) QuestsManager(delta.games.lotro.lore.quests.QuestsManager) Rewards(delta.games.lotro.common.Rewards) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem)

Example 7 with CharacterLogItem

use of delta.games.lotro.character.log.CharacterLogItem in project lotro-tools by dmorcellet.

the class CharacterLogPageParser method parseLogPage.

private boolean parseLogPage(CharacterLog log, String rootURL, int pageNumber, int retryNumber) {
    if (_logger.isInfoEnabled()) {
        _logger.info("Page #" + pageNumber + ((retryNumber > 0) ? " try #" + retryNumber : ""));
    }
    boolean ret;
    String url = rootURL + "=" + String.valueOf(pageNumber);
    try {
        DownloadService downloader = DownloadService.getInstance();
        String page = downloader.getPage(url);
        Source source = new Source(page);
        // <table class="gradient_table activitylog">
        Element logTable = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "gradient_table activitylog");
        if (logTable != null) {
            List<Element> trs = logTable.getAllElements(HTMLElementName.TR);
            if ((trs != null) && (trs.size() >= 1)) {
                // ignore first (table headers)
                trs.remove(0);
                for (Element tr : trs) {
                    CharacterLogItem item = parseLogItem(tr);
                    if (item != null) {
                        boolean addIt = true;
                        long date = item.getDate();
                        if (_stopDate != null) {
                            if (date < _stopDate.longValue()) {
                                addIt = false;
                                _stop = true;
                                break;
                            }
                        }
                        if (addIt) {
                            log.addLogItem(item);
                        }
                    }
                }
            }
        }
        ret = true;
    } catch (Exception e) {
        _logger.warn("Cannot parse character page [" + url + "]", e);
        ret = false;
    }
    return ret;
}
Also used : Element(net.htmlparser.jericho.Element) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) DownloadService(delta.games.lotro.utils.DownloadService) Source(net.htmlparser.jericho.Source)

Example 8 with CharacterLogItem

use of delta.games.lotro.character.log.CharacterLogItem in project lotro-tools by dmorcellet.

the class CharacterLogRepair method getDatesToUpdate.

private List<Long> getDatesToUpdate(CharacterLog log) {
    List<Long> ret = new ArrayList<Long>();
    List<Long> dates = log.getDates();
    for (Long date : dates) {
        boolean useIt = false;
        List<CharacterLogItem> items = log.getItemsOfDay(date.longValue());
        for (CharacterLogItem item : items) {
            String label = item.getLabel();
            if (("Completed a deed".equals(label)) || ("Completed a quest".equals(label))) {
                useIt = true;
                break;
            }
        }
        if (useIt) {
            ret.add(date);
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem)

Example 9 with CharacterLogItem

use of delta.games.lotro.character.log.CharacterLogItem in project lotro-companion by dmorcellet.

the class WarbandsStats method getWarbandItems.

private List<CharacterLogItem> getWarbandItems(CharacterLog log) {
    List<CharacterLogItem> ret = new ArrayList<CharacterLogItem>();
    int nb = log.getNbItems();
    for (int i = 0; i < nb; i++) {
        CharacterLogItem item = log.getLogItem(i);
        if (item != null) {
            LogItemType type = item.getLogItemType();
            if (type == LogItemType.QUEST) {
                String label = item.getLabel();
                if (label.startsWith(WARBAND_SEED)) {
                    ret.add(item);
                }
            }
        }
    }
    Collections.reverse(ret);
    return ret;
}
Also used : ArrayList(java.util.ArrayList) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType)

Example 10 with CharacterLogItem

use of delta.games.lotro.character.log.CharacterLogItem in project lotro-tools by dmorcellet.

the class CharacterLogPageParser method parseLogItem.

private CharacterLogItem parseLogItem(Element tr) {
    /*
<td class="char">
<a href="/home/character/2427907/146366987891794854">Glumlug</a>
</td>
<td class="date">2011/11/24</td>
<td class="details">
<img src="http://content.turbine.com/sites/playerportal/modules/lotro-base/images/icons/log/icon_levelup.png">
Reached level 70
</td>
 */
    /*
<td class="char">
<a href="/home/character/2427907/146366987891794854">Glumlug</a>
</td>
<td class="date">2011/11/24</td>
<td class="details">
<a href="http://lorebook.lotro.com/wiki/Special:LotroResource?id=1879208735">
<img src="http://content.turbine.com/sites/playerportal/modules/lotro-base/images/icons/log/icon_quest.png">
Completed 'The Practiced Arm'
</a>
</td>
 */
    CharacterLogItem ret = null;
    List<Element> tds = tr.getAllElements(HTMLElementName.TD);
    if ((tds != null) && (tds.size() == 3)) {
        if (_characterName == null) {
            Element charName = tds.get(0);
            _characterName = JerichoHtmlUtils.getTagContents(charName, HTMLElementName.A);
        }
        Element tdDate = tds.get(1);
        String dateStr = CharacterReference.decodeCollapseWhiteSpace(tdDate.getContent());
        LogItemType type = null;
        Element tdDetails = tds.get(2);
        List<Element> imgs = tdDetails.getAllElements(HTMLElementName.IMG);
        Element img = null;
        if ((imgs != null) && (imgs.size() == 1)) {
            img = imgs.get(0);
            String imgSrc = img.getAttributeValue("src");
            type = findType(imgSrc);
        }
        String url = null;
        Element a = tdDetails.getFirstElement(HTMLElementName.A);
        if (a != null) {
            url = a.getAttributeValue("href");
        }
        TextExtractor extractor = tdDetails.getTextExtractor();
        if (img != null)
            extractor.excludeElement(img.getStartTag());
        if (a != null)
            extractor.excludeElement(a.getStartTag());
        String label = extractor.toString().trim();
        if ((dateStr != null) && (type != null) && (label != null)) {
            try {
                Calendar c = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
                String[] items = dateStr.split("/");
                int year = Integer.parseInt(items[0]);
                int month = Integer.parseInt(items[1]);
                int day = Integer.parseInt(items[2]);
                label = tuneLabel(label);
                if (url != null) {
                    url = url.trim();
                }
                c.setTimeInMillis(0);
                c.set(year, month - 1, day);
                long date = c.getTimeInMillis();
                ret = new CharacterLogItem(date, type, label, url);
            } catch (Exception e) {
                _logger.error("Cannot parse LOTRO character log item!", e);
            }
        }
    }
    return ret;
}
Also used : Element(net.htmlparser.jericho.Element) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) TextExtractor(net.htmlparser.jericho.TextExtractor) CharacterLogItem(delta.games.lotro.character.log.CharacterLogItem) LogItemType(delta.games.lotro.character.log.CharacterLogItem.LogItemType)

Aggregations

CharacterLogItem (delta.games.lotro.character.log.CharacterLogItem)10 ArrayList (java.util.ArrayList)4 LogItemType (delta.games.lotro.character.log.CharacterLogItem.LogItemType)3 Rewards (delta.games.lotro.common.Rewards)2 Element (net.htmlparser.jericho.Element)2 CellDataProvider (delta.common.ui.swing.tables.CellDataProvider)1 DataProvider (delta.common.ui.swing.tables.DataProvider)1 GenericTableController (delta.common.ui.swing.tables.GenericTableController)1 DateRenderer (delta.common.ui.swing.tables.GenericTableController.DateRenderer)1 TableColumnController (delta.common.ui.swing.tables.TableColumnController)1 DeedDescription (delta.games.lotro.lore.deeds.DeedDescription)1 DeedsManager (delta.games.lotro.lore.deeds.DeedsManager)1 QuestDescription (delta.games.lotro.lore.quests.QuestDescription)1 QuestsManager (delta.games.lotro.lore.quests.QuestsManager)1 DownloadService (delta.games.lotro.utils.DownloadService)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 Source (net.htmlparser.jericho.Source)1 TextExtractor (net.htmlparser.jericho.TextExtractor)1