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>
(x5)
</div>
</div>
*/
}
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 + "]");
}
}
}
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());
}
}
}
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);
}
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);
}
}
}
}
Aggregations