Search in sources :

Example 11 with Race

use of delta.games.lotro.common.Race in project lotro-companion by dmorcellet.

the class NewToonDialogController method buildNewToonPanel.

private JPanel buildNewToonPanel() {
    JPanel panel = GuiFactory.buildPanel(new GridBagLayout());
    // Toon name
    _toonName = GuiFactory.buildTextField("");
    _toonName.setColumns(TOON_NAME_SIZE);
    // Server
    _server = CharacterUiUtils.buildServerCombo();
    TypedProperties props = Config.getInstance().getParameters();
    String defaultServer = props.getStringProperty("default.server", null);
    if (defaultServer != null) {
        _server.selectItem(defaultServer);
    }
    // Class
    _class = new CharacterClassController();
    // Race
    _race = CharacterUiUtils.buildRaceCombo(false);
    ItemSelectionListener<Race> listener = new ItemSelectionListener<Race>() {

        @Override
        public void itemSelected(Race race) {
            _class.setRace(race);
        }
    };
    _race.addListener(listener);
    // Sex
    _sex = CharacterUiUtils.buildSexCombo();
    Insets insets = new Insets(5, 5, 5, 5);
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, insets, 0, 0);
    panel.add(GuiFactory.buildLabel("Name:"), gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    panel.add(GuiFactory.buildLabel("Server:"), gbc);
    gbc.gridx = 0;
    gbc.gridy = 2;
    panel.add(GuiFactory.buildLabel("Race:"), gbc);
    gbc.gridx = 0;
    gbc.gridy = 3;
    panel.add(GuiFactory.buildLabel("Class:"), gbc);
    gbc.gridx = 0;
    gbc.gridy = 4;
    panel.add(GuiFactory.buildLabel("Sex:"), gbc);
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(_toonName, gbc);
    gbc.gridx = 1;
    gbc.gridy = 1;
    panel.add(_server.getComboBox(), gbc);
    gbc.gridx = 1;
    gbc.gridy = 2;
    panel.add(_race.getComboBox(), gbc);
    gbc.gridx = 1;
    gbc.gridy = 3;
    panel.add(_class.getComboBoxController().getComboBox(), gbc);
    gbc.gridx = 1;
    gbc.gridy = 4;
    panel.add(_sex.getComboBox(), gbc);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ItemSelectionListener(delta.common.ui.swing.combobox.ItemSelectionListener) Race(delta.games.lotro.common.Race) TypedProperties(delta.common.utils.misc.TypedProperties)

Example 12 with Race

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

the class CharacterPageParser method parseCharacterDescription.

private void parseCharacterDescription(Element charPanel) {
    // Character name
    // <div class="char_name header_color">Glumlug of Elendilmir</div>
    String charName = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_name header_color");
    if (charName != null) {
        int indexOf = charName.indexOf(OF);
        if (indexOf != -1) {
            String server = charName.substring(indexOf + OF.length());
            _character.setServer(server);
            charName = charName.substring(0, indexOf);
        }
        _character.setName(charName);
    }
    // System.out.println("Char name ["+charName+"]");
    // Character core:
    // <div class="char_core">
    Element charCore = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(charPanel, HTMLElementName.DIV, "class", "char_core");
    if (charCore != null) {
        // <div class="char_class header_color">Hunter</div>
        String charClassName = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_class header_color");
        CharacterClass cClass = CharacterClass.getByName(charClassName);
        _character.setCharacterClass(cClass);
        // <div class="char_race header_color">Dwarf</div>
        String charRace = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_race header_color");
        Race race = Race.getByLabel(charRace);
        _character.setRace(race);
        // <div class="char_nat header_color">Grey Mountains</div>
        String charNation = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_nat header_color");
        _character.setRegion(charNation);
        // <div class="char_level header_color">66</div>
        String charLevelStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "char_level header_color");
        int charLevel = NumericTools.parseInt(charLevelStr, 0);
        _character.setLevel(charLevel);
    // System.out.println("Class ["+charClassName+"], Race ["+charRace+"], Nation ["+charNation+"], Level="+charLevel);
    }
    // Character main stats:
    // <div class="core_stats header_color">
    Element charStats = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(charPanel, HTMLElementName.DIV, "class", "core_stats header_color");
    if (charStats != null) {
        // <div class="morale">4839</div>
        String moraleStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "morale");
        int morale = NumericTools.parseInt(moraleStr, 0);
        BasicStatsSet stats = _character.getStats();
        stats.setStat(STAT.MORALE, morale);
        // <div class="power">2243</div>
        String powerStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "power");
        int power = NumericTools.parseInt(powerStr, 0);
        stats.setStat(STAT.POWER, power);
        // <div class="armour">3213</div>
        String armourStr = JerichoHtmlUtils.getTagContents(charPanel, HTMLElementName.DIV, "class", "armour");
        int armour = NumericTools.parseInt(armourStr, 0);
        stats.setStat(STAT.ARMOUR, armour);
    // System.out.println("Morale="+morale+", Power="+power+", Armour="+armour);
    }
    CharacterEquipment equipment = _character.getEquipment();
    // Object slots:
    // <a class="equipment_icon" href="http://lorebook.lotro.com/wiki/Special:LotroResource?id=1879205751">
    // <img class="slot_2" src="http://lorebook.lotro.com/icon.php?id=1879205751&type=item">
    // </a>
    List<Element> objectSlots = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(charPanel, HTMLElementName.A, "class", "equipment_icon");
    for (Element objectSlot : objectSlots) {
        String objectPageURL = objectSlot.getAttributeValue("href");
        // System.out.println("Object ["+objectPageURL+"]");
        Element img = objectSlot.getFirstElement(HTMLElementName.IMG);
        if (img != null) {
            String slotName = img.getAttributeValue("class");
            Integer slotNumber = null;
            if ((slotName != null) && (slotName.startsWith(SLOT_SEED))) {
                slotName = slotName.substring(SLOT_SEED.length());
                slotNumber = NumericTools.parseInteger(slotName);
                if (slotNumber != null) {
                    // String iconURL=img.getAttributeValue("src");
                    EQUIMENT_SLOT slot = CharacterEquipment.getSlotByIndex(slotNumber.intValue());
                    SlotContents contents = equipment.getSlotContents(slot, true);
                    Integer itemId = CharacterXMLParser.idFromURL(objectPageURL);
                    contents.setItemId(itemId);
                // System.out.println("Slot ["+slotNumber+"], Icon URL ["+iconURL+"]");
                }
            }
        }
    }
}
Also used : SlotContents(delta.games.lotro.character.CharacterEquipment.SlotContents) CharacterEquipment(delta.games.lotro.character.CharacterEquipment) EQUIMENT_SLOT(delta.games.lotro.character.CharacterEquipment.EQUIMENT_SLOT) Element(net.htmlparser.jericho.Element) Race(delta.games.lotro.common.Race) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet) CharacterClass(delta.games.lotro.common.CharacterClass)

Example 13 with Race

use of delta.games.lotro.common.Race 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

Race (delta.games.lotro.common.Race)13 CharacterClass (delta.games.lotro.common.CharacterClass)9 CharacterSex (delta.games.lotro.common.CharacterSex)6 ImageIcon (javax.swing.ImageIcon)3 ItemSelectionListener (delta.common.ui.swing.combobox.ItemSelectionListener)2 CharacterData (delta.games.lotro.character.CharacterData)2 CharacterEquipment (delta.games.lotro.character.CharacterEquipment)2 EQUIMENT_SLOT (delta.games.lotro.character.CharacterEquipment.EQUIMENT_SLOT)2 SlotContents (delta.games.lotro.character.CharacterEquipment.SlotContents)2 BasicStatsSet (delta.games.lotro.character.stats.BasicStatsSet)2 DeedRaceRequirementFilter (delta.games.lotro.lore.deeds.filters.DeedRaceRequirementFilter)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 JPanel (javax.swing.JPanel)2 TypedProperties (delta.common.utils.misc.TypedProperties)1 CharacterFile (delta.games.lotro.character.CharacterFile)1 CharactersManager (delta.games.lotro.character.CharactersManager)1 CharacterStatsComputer (delta.games.lotro.character.stats.CharacterStatsComputer)1 STAT (delta.games.lotro.character.stats.STAT)1