use of delta.games.lotro.common.objects.ObjectsSet in project lotro-tools by dmorcellet.
the class LotroWikiDeedPageParser method parseDeed.
private DeedDescription parseDeed(int startIndex, String[] lines, String deedName) {
DeedDescription deed = new DeedDescription();
deed.setName(deedName);
deed.setType(null);
Rewards rewards = deed.getRewards();
// Reputation
Faction faction = null;
Integer reputation = null;
// Virtues
VirtueId virtueId = null;
Integer virtueCount = null;
// Item rewards
String[] itemRewards = null;
Integer[] itemRewardCounts = null;
// Categories
String deedType = null;
String deedSubtype = null;
String regionalSub = null;
// Deeds chain
List<String> deedsChain = new ArrayList<String>();
for (int index = startIndex + 1; index < lines.length; index++) {
String line = lines[index].trim();
if (line.contains("{{Deed"))
break;
String lineKey = fetchLineKey(line);
// System.out.println(line);
if ("name".equals(lineKey)) {
// String name=getLineValue(line);
// deed.setName(name);
} else if ("Lore-text".equals(lineKey)) {
String description = getLineValue(line);
description = normalize(description);
deed.setDescription(description);
} else if ("Objective".equals(lineKey)) {
StringBuilder sb = new StringBuilder();
String firstLine = getLineValue(line);
sb.append(firstLine);
while (true) {
String nextLine = lines[index + 1].trim();
if (nextLine.startsWith("|")) {
break;
}
sb.append('\n').append(nextLine);
index++;
}
String objectives = sb.toString().trim();
objectives = normalize(objectives);
deed.setObjectives(objectives);
} else if ("Faction".equals(lineKey)) {
faction = extractFaction(line);
} else if ("Reputation".equals(lineKey)) {
String repValue = getLineValue(line).replace(",", "");
reputation = NumericTools.parseInteger(repValue);
} else if ("Title".equals(lineKey)) {
Title title = extractTitle(line);
if (title != null) {
rewards.addTitle(title);
}
} else if ("Virtue".equals(lineKey)) {
virtueId = extractVirtue(line);
} else if ("Virtue-value".equals(lineKey)) {
virtueCount = NumericTools.parseInteger(getLineValue(line));
} else if ("TP-reward".equals(lineKey)) {
String tpStr = getLineValue(line);
if ((!tpStr.isEmpty()) && (!"???".equals(tpStr))) {
Integer tp = NumericTools.parseInteger(tpStr, false);
if (tp != null) {
rewards.setLotroPoints(tp.intValue());
} else {
_logger.warn("Bad LOTRO points value in file " + _currentFile + ": [" + tpStr + "]");
}
}
} else if ("SM-reward".equals(lineKey)) {
String smStr = getLineValue(line);
if (!smStr.isEmpty()) {
Integer marks = NumericTools.parseInteger(smStr, false);
if (marks != null) {
ObjectsSet objects = deed.getRewards().getObjects();
ObjectItem item = new ObjectItem("Mark");
item.setItemId(1879224343);
objects.addObject(item, marks.intValue());
} else {
_logger.warn("Bad SM value in file " + _currentFile + ": [" + smStr + "]");
}
}
} else if ("CTP-reward".equals(lineKey)) {
String value = getLineValue(line);
if ("Y".equals(value)) {
// TODO Class Trait Point
}
} else if ("Trait-reward".equals(lineKey)) {
String traitStr = getLineValue(line);
if (!traitStr.isEmpty()) {
handleTraitReward(rewards, traitStr);
}
} else if ("Emote-reward".equals(lineKey)) {
String emoteStr = getLineValue(line);
if (!emoteStr.isEmpty()) {
handleEmoteReward(rewards, emoteStr);
}
} else if ("Skill-reward".equals(lineKey)) {
String skillStr = getLineValue(line);
if (!skillStr.isEmpty()) {
handleSkillReward(rewards, skillStr);
}
} else if ("Level".equals(lineKey)) {
String levelStr = getLineValue(line);
if ("?".equals(levelStr))
levelStr = "";
if ("???".equals(levelStr))
levelStr = "";
if (!levelStr.isEmpty()) {
levelStr = levelStr.replace("<", "<");
if (levelStr.startsWith("<="))
levelStr = levelStr.substring(2);
if (levelStr.equals("{{Level Cap}}"))
levelStr = "1000";
if (levelStr.endsWith("+"))
levelStr = levelStr.substring(0, levelStr.length() - 1);
levelStr = removeXmlComments(levelStr);
Integer level = NumericTools.parseInteger(levelStr, false);
if (level != null) {
deed.setMinLevel(level);
} else {
_logger.warn("Bad level value in file " + _currentFile + ": [" + levelStr + "]");
}
}
} else if ("Deed-type".equals(lineKey)) {
deedType = getLineValue(line);
} else if ("Deed-subtype".equals(lineKey)) {
deedSubtype = getLineValue(line);
} else if ("Regional-sub".equals(lineKey)) {
regionalSub = getLineValue(line);
} else if ((lineKey != null) && (lineKey.startsWith(DEED_CHAIN_SEED))) {
Integer deedIndex = NumericTools.parseInteger(lineKey.substring(DEED_CHAIN_SEED.length()));
if (deedIndex != null) {
// Add missing entries
int nbMissingEntries = deedIndex.intValue() - deedsChain.size();
for (int i = 0; i < nbMissingEntries; i++) {
deedsChain.add(null);
}
// Set deed name in chain
String deedNameInChain = getLineValue(line);
deedsChain.set(deedIndex.intValue() - 1, deedNameInChain);
}
} else if ("Parent-deed".equals(lineKey)) {
String parentDeed = getLineValue(line);
if (!parentDeed.isEmpty()) {
if (useParentDeedInfo(parentDeed, deedName)) {
parentDeed = fixParentDeedInfo(parentDeed, deedName);
DeedProxy parentProxy = new DeedProxy();
parentProxy.setName(parentDeed);
deed.getParentDeedProxies().add(parentProxy);
}
}
}
for (int i = 1; i <= 3; i++) {
String suffix = (i != 1) ? String.valueOf(i) : "";
if (("Item-reward" + suffix).equals(lineKey)) {
String itemName = getLineValue(line);
if (!itemName.isEmpty()) {
if (itemRewards == null) {
itemRewards = new String[3];
}
itemRewards[i - 1] = itemName;
}
}
if (("Item-amount" + suffix).equals(lineKey)) {
String itemCountStr = getLineValue(line);
if (!itemCountStr.isEmpty()) {
if (itemRewardCounts == null) {
itemRewardCounts = new Integer[3];
}
itemRewardCounts[i - 1] = NumericTools.parseInteger(itemCountStr);
}
}
}
/*
| DP-reward =
| Hidden =
| Meta-deed =
| Extra =
*/
}
if ((faction != null) && (reputation != null)) {
ReputationItem item = new ReputationItem(faction);
item.setAmount(reputation.intValue());
rewards.getReputation().add(item);
}
if (virtueId != null) {
int count = (virtueCount != null) ? virtueCount.intValue() : 1;
Virtue virtue = new Virtue(virtueId, count);
rewards.addVirtue(virtue);
}
if (itemRewards != null) {
handleItemRewards(deed, itemRewards, itemRewardCounts);
}
// Categories
handleCategories(deed, deedType, deedSubtype, regionalSub);
// Deeds chain
handleDeedsChain(deed, deedsChain);
return deed;
}
use of delta.games.lotro.common.objects.ObjectsSet in project lotro-companion by dmorcellet.
the class MainTestRewardsDisplay method main.
/**
* Main method for this test.
* @param args Not used.
*/
public static void main(String[] args) {
DeedsManager deedsManager = DeedsManager.getInstance();
List<DeedDescription> deeds = deedsManager.getAll();
for (int i = 0; i < 50; i++) {
DeedDescription deed = deeds.get(i);
Rewards rewards = deed.getRewards();
ObjectsSet objects = rewards.getObjects();
int lotroPoints = rewards.getLotroPoints();
if ((objects.getNbObjectItems() > 0) || (lotroPoints > 0)) {
RewardsPanelController panelCtrl = new RewardsPanelController(rewards);
JPanel panel = panelCtrl.getPanel();
JFrame frame = new JFrame();
JPanel background = GuiFactory.buildBackgroundPanel(new BorderLayout());
background.add(panel, BorderLayout.CENTER);
frame.add(background);
frame.pack();
frame.setVisible(true);
}
}
}
use of delta.games.lotro.common.objects.ObjectsSet 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.ObjectsSet 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.ObjectsSet 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());
}
}
}
Aggregations