use of delta.games.lotro.character.CharacterData in project lotro-tools by dmorcellet.
the class DataLotroCharacterPageParser method parseCharacter.
private CharacterData parseCharacter(byte[] xmlBuffer) {
CharacterData ret = null;
if (xmlBuffer != null) {
ByteArrayInputStream bis = new ByteArrayInputStream(xmlBuffer);
Element root = DOMParsingTools.parse(bis);
if (root != null) {
Element characterTag = DOMParsingTools.getChildTagByName(root, "character");
if (characterTag != null) {
ret = new CharacterData();
// Character name
NamedNodeMap attrs = characterTag.getAttributes();
String charName = DOMParsingTools.getStringAttribute(attrs, "name", null);
ret.setName(charName);
// World/server
String server = DOMParsingTools.getStringAttribute(attrs, "world", null);
ret.setServer(server);
// Class
String charClassName = DOMParsingTools.getStringAttribute(attrs, "class", null);
CharacterClass cClass = CharacterClass.getByName(charClassName);
ret.setCharacterClass(cClass);
// Race
String charRace = DOMParsingTools.getStringAttribute(attrs, "race", null);
Race race = Race.getByLabel(charRace);
ret.setRace(race);
// Nation/origin
String charNation = DOMParsingTools.getStringAttribute(attrs, "origin", null);
if (charNation != null) {
charNation = charNation.replace('_', ' ');
}
ret.setRegion(charNation);
// Level
String charLevelStr = DOMParsingTools.getStringAttribute(attrs, "level", null);
int charLevel = NumericTools.parseInt(charLevelStr, 0);
ret.setLevel(charLevel);
// System.out.println("Class ["+charClassName+"], Race ["+charRace+"], Nation ["+charNation+"], Level="+charLevel);
Element statsTag = DOMParsingTools.getChildTagByName(characterTag, "stats");
if (statsTag != null) {
BasicStatsSet stats = ret.getStats();
List<Element> statTags = DOMParsingTools.getChildTagsByName(statsTag, "stat");
for (Element statTag : statTags) {
NamedNodeMap statAttrs = statTag.getAttributes();
String statName = DOMParsingTools.getStringAttribute(statAttrs, "name", null);
String statValue = DOMParsingTools.getStringAttribute(statAttrs, "value", null);
Integer value = null;
if ((!"N/A".equals(statValue)) && (!("??".equals(statValue)))) {
value = NumericTools.parseInteger(statValue);
}
if (value != null) {
STAT stat = getStatByName(statName);
if (stat != null) {
stats.setStat(stat, value.intValue());
}
}
}
}
// Equipment
Element equipmentTag = DOMParsingTools.getChildTagByName(characterTag, "equipment");
if (equipmentTag != null) {
CharacterEquipment equipment = ret.getEquipment();
List<Element> itemTags = DOMParsingTools.getChildTagsByName(equipmentTag, "item");
for (Element itemTag : itemTags) {
NamedNodeMap itemAttrs = itemTag.getAttributes();
// Identifier
int itemId = DOMParsingTools.getIntAttribute(itemAttrs, "item_id", 0);
// String objectPageURL=DOMParsingTools.getStringAttribute(itemAttrs,"lorebookEntry",null);
String slotName = DOMParsingTools.getStringAttribute(itemAttrs, "slot", null);
EQUIMENT_SLOT slot = getSlotByName(slotName);
if (slot != null) {
SlotContents contents = equipment.getSlotContents(slot, true);
if (itemId != 0) {
contents.setItemId(Integer.valueOf(itemId));
}
}
}
}
}
}
}
return ret;
}
Aggregations