Search in sources :

Example 6 with ObjectItem

use of delta.games.lotro.common.objects.ObjectItem in project lotro-tools by dmorcellet.

the class RewardsHTMLParser method parseItemReward.

private void parseItemReward(Element rewardDiv, Rewards rewards) {
    ObjectsSet objects = null;
    // System.out.println("Item reward!");
    String key = "";
    List<Element> divs = rewardDiv.getAllElements(HTMLElementName.DIV);
    // remove reward div
    divs.remove(0);
    for (Element div : divs) {
        List<Element> strongs = div.getAllElements(HTMLElementName.STRONG);
        if (strongs.size() > 0) {
            Element strong = strongs.get(0);
            key = CharacterReference.decodeCollapseWhiteSpace(strong.getContent());
            key = cleanupFieldName(key);
            if (RECEIVE_KEY.equals(key)) {
                objects = rewards.getObjects();
            } else if (SELECT_ONE_OF_KEY.equals(key)) {
                objects = rewards.getSelectObjects();
            } else {
                _logger.warn(_objectId + ": unmanaged object selection key [" + key + "]");
            }
        } else {
            List<Element> as = div.getAllElements(HTMLElementName.A);
            if ((as != null) && (as.size() == 2)) {
                Element iconItem = as.get(0);
                String iconURL = null;
                List<Element> imgs = iconItem.getAllElements(HTMLElementName.IMG);
                if ((imgs != null) && (imgs.size() == 1)) {
                    Element img = imgs.get(0);
                    iconURL = img.getAttributeValue("src");
                // System.out.println("Icon: "+iconURL);
                }
                Element textItem = as.get(1);
                String itemName = CharacterReference.decodeCollapseWhiteSpace(textItem.getContent());
                String url = textItem.getAttributeValue("href");
                ObjectItem item = new ObjectItem(itemName);
                item.setObjectURL(url);
                item.setIconURL(iconURL);
                int quantity = 1;
                TextExtractor extractor = div.getTextExtractor();
                extractor.excludeElement(iconItem.getStartTag());
                extractor.excludeElement(textItem.getStartTag());
                String text = extractor.toString();
                int factorIndex = text.indexOf("(x");
                if (factorIndex != -1) {
                    int parenthesisIndex = text.indexOf(')', factorIndex + 2);
                    if (parenthesisIndex != -1) {
                        String factorStr = text.substring(factorIndex + 2, parenthesisIndex);
                        quantity = NumericTools.parseInt(factorStr, 1);
                    }
                }
                if (objects != null) {
                    objects.addObject(item, quantity);
                } else {
                    _logger.warn(_objectId + ": ignored object [" + item + "], quantity=" + quantity);
                }
            // System.out.println("Item: "+itemName+", URL: "+url);
            }
        }
    }
/*

<div class="questReward">
<div>
<strong>Receive:</strong>
</div>
<div>
<a href="/wiki/Item:Drownholt_Compass">
<img class="icon" rel="" src="http://content.turbine.com/sites/lorebook.lotro.com/images/icons/item/device/it_tracking_mom_book9_chapter5.png">
</a>
<a href="/wiki/Item:Drownholt_Compass">Drownholt Compass</a>
&nbsp;(x5)
</div>
</div>
     */
}
Also used : ObjectItem(delta.games.lotro.common.objects.ObjectItem) Element(net.htmlparser.jericho.Element) ObjectsSet(delta.games.lotro.common.objects.ObjectsSet) TextExtractor(net.htmlparser.jericho.TextExtractor)

Example 7 with ObjectItem

use of delta.games.lotro.common.objects.ObjectItem in project lotro-tools by dmorcellet.

the class LorebookDeedsDatabaseNormalization method normalizeDeed.

private void normalizeDeed(DeedDescription deed) {
    // Remove key
    deed.setKey(null);
    // Normalize EOL/LF
    // - description
    deed.setDescription(normalizeText(deed.getDescription()));
    // - objectives
    deed.setObjectives(normalizeText(deed.getObjectives()));
    // Find item IDs
    // TODO Use ItemsResolver
    Rewards rewards = deed.getRewards();
    ObjectsSet objects = rewards.getObjects();
    int nbItems = objects.getNbObjectItems();
    for (int i = 0; i < nbItems; i++) {
        ObjectItem objectItem = objects.getItem(i);
        String name = objectItem.getName();
        Item item = getItemByName(name);
        if (item != null) {
            objectItem.setItemId(item.getIdentifier());
            objectItem.setObjectURL(null);
            objectItem.setIconURL(null);
        } else {
            System.out.println("Item not found [" + name + "]");
        }
    }
}
Also used : ObjectItem(delta.games.lotro.common.objects.ObjectItem) Item(delta.games.lotro.lore.items.Item) ObjectItem(delta.games.lotro.common.objects.ObjectItem) Rewards(delta.games.lotro.common.Rewards) ObjectsSet(delta.games.lotro.common.objects.ObjectsSet)

Example 8 with ObjectItem

use of delta.games.lotro.common.objects.ObjectItem in project lotro-tools by dmorcellet.

the class LotroWikiDeedPageParser method handleItemRewards.

private void handleItemRewards(DeedDescription deed, String[] itemRewards, Integer[] itemRewardCounts) {
    ObjectsSet objects = deed.getRewards().getObjects();
    for (int i = 0; i < itemRewards.length; i++) {
        String itemName = itemRewards[i];
        Integer count = null;
        if (itemRewardCounts != null) {
            count = itemRewardCounts[i];
        }
        if (itemName != null) {
            if (count == null) {
                count = Integer.valueOf(1);
            }
            ObjectItem item = new ObjectItem(itemName);
            objects.addObject(item, count.intValue());
        }
    }
}
Also used : ObjectItem(delta.games.lotro.common.objects.ObjectItem) ObjectsSet(delta.games.lotro.common.objects.ObjectsSet)

Example 9 with ObjectItem

use of delta.games.lotro.common.objects.ObjectItem in project lotro-tools by dmorcellet.

the class LotroCompendiumDeedsLoader method handleItem.

private void handleItem(Rewards rewards, Map<String, Object> itemMap) {
    Object idObject = itemMap.get("id");
    String idStr = "0";
    if (idObject instanceof String)
        idStr = (String) idObject;
    if (idObject instanceof Double) {
        idStr = String.valueOf(((Double) idObject).intValue());
    }
    int id = Integer.parseInt(idStr, 16);
    String quantityStr = (String) itemMap.get("q");
    int quantity = 1;
    if ((quantityStr != null) && (quantityStr.startsWith("(x")) && (quantityStr.endsWith(")"))) {
        quantityStr = quantityStr.substring(2, quantityStr.length() - 1);
        quantity = Integer.parseInt(quantityStr);
    }
    String itemName = (String) itemMap.get("val");
    if ("Skirmish Mark".equals(itemName)) {
        itemName = "Mark";
        id = 1879224343;
    }
    if (("AnnĂºminas Mark".equals(itemName)) || ("Helegrod Mark".equals(itemName)) || ("Great Barrow Mark".equals(itemName)) || ("Eregion Mark".equals(itemName))) {
        itemName = "Mark";
        id = 1879224343;
        quantity = quantity * 100;
    }
    if ("Yule Festival Token".equals(itemName)) {
        id = 1879256449;
    }
    ObjectItem item = new ObjectItem(itemName);
    item.setItemId(id);
    rewards.getObjects().addObject(item, quantity);
}
Also used : ObjectItem(delta.games.lotro.common.objects.ObjectItem)

Example 10 with ObjectItem

use of delta.games.lotro.common.objects.ObjectItem in project lotro-tools by dmorcellet.

the class CheckItemRewardsInDeeds method handleDeed.

private void handleDeed(DeedDescription deed) {
    Rewards rewards = deed.getRewards();
    ObjectsSet objects = rewards.getObjects();
    int nbItems = objects.getNbObjectItems();
    for (int i = 0; i < nbItems; i++) {
        ObjectItem objectItem = objects.getItem(i);
        int id = objectItem.getItemId();
        String name = objectItem.getName();
        Item item = ItemsManager.getInstance().getItem(id);
        if (item == null) {
            System.out.println("Item not found: id=" + id + ", name=" + name);
        } else {
            String itemName = item.getName();
            if (!Objects.equals(name, itemName)) {
                System.out.println("Fix item reward name from [" + name + "] to [" + itemName + "]");
                objectItem.setName(itemName);
            }
        }
    }
}
Also used : ObjectItem(delta.games.lotro.common.objects.ObjectItem) Item(delta.games.lotro.lore.items.Item) ObjectItem(delta.games.lotro.common.objects.ObjectItem) Rewards(delta.games.lotro.common.Rewards) ObjectsSet(delta.games.lotro.common.objects.ObjectsSet)

Aggregations

ObjectItem (delta.games.lotro.common.objects.ObjectItem)11 ObjectsSet (delta.games.lotro.common.objects.ObjectsSet)6 Rewards (delta.games.lotro.common.Rewards)4 Item (delta.games.lotro.lore.items.Item)4 DeedDescription (delta.games.lotro.lore.deeds.DeedDescription)2 DeedProxy (delta.games.lotro.lore.deeds.DeedProxy)2 ReputationItem (delta.games.lotro.common.ReputationItem)1 Title (delta.games.lotro.common.Title)1 Virtue (delta.games.lotro.common.Virtue)1 VirtueId (delta.games.lotro.common.VirtueId)1 Faction (delta.games.lotro.lore.reputation.Faction)1 ArrayList (java.util.ArrayList)1 Element (net.htmlparser.jericho.Element)1 TextExtractor (net.htmlparser.jericho.TextExtractor)1