Search in sources :

Example 31 with CharacterData

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;
}
Also used : SlotContents(delta.games.lotro.character.CharacterEquipment.SlotContents) CharacterEquipment(delta.games.lotro.character.CharacterEquipment) NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet) CharacterClass(delta.games.lotro.common.CharacterClass) STAT(delta.games.lotro.character.stats.STAT) CharacterData(delta.games.lotro.character.CharacterData) EQUIMENT_SLOT(delta.games.lotro.character.CharacterEquipment.EQUIMENT_SLOT) ByteArrayInputStream(java.io.ByteArrayInputStream) Race(delta.games.lotro.common.Race)

Aggregations

CharacterData (delta.games.lotro.character.CharacterData)31 CharacterGenerationTools (delta.games.lotro.character.stats.CharacterGenerationTools)8 JFrame (javax.swing.JFrame)7 CharacterFile (delta.games.lotro.character.CharacterFile)6 CharacterGeneratorMeva (delta.games.lotro.character.stats.CharacterGeneratorMeva)6 BasicStatsSet (delta.games.lotro.character.stats.BasicStatsSet)5 CharacterStatsComputer (delta.games.lotro.character.stats.CharacterStatsComputer)5 CharacterInfosManager (delta.games.lotro.character.CharacterInfosManager)4 CharacterEvent (delta.games.lotro.character.events.CharacterEvent)4 CharacterEventType (delta.games.lotro.character.events.CharacterEventType)4 DefaultWindowController (delta.common.ui.swing.windows.DefaultWindowController)3 EQUIMENT_SLOT (delta.games.lotro.character.CharacterEquipment.EQUIMENT_SLOT)3 CharacterClass (delta.games.lotro.common.CharacterClass)3 File (java.io.File)3 JPanel (javax.swing.JPanel)3 WindowController (delta.common.ui.swing.windows.WindowController)2 CharacterEquipment (delta.games.lotro.character.CharacterEquipment)2 CharactersManager (delta.games.lotro.character.CharactersManager)2 LotroTestUtils (delta.games.lotro.character.log.LotroTestUtils)2 CharacterGeneratorGiswald (delta.games.lotro.character.stats.CharacterGeneratorGiswald)2