Search in sources :

Example 31 with BasicStatsSet

use of delta.games.lotro.character.stats.BasicStatsSet in project lotro-tools by dmorcellet.

the class MergeWithLotroPlanDb method mergeItems.

private Item mergeItems(Item source, Item lotroplan) {
    int id = source.getIdentifier();
    Item result = source;
    // Check types
    if (source.getClass() != lotroplan.getClass()) {
        // System.out.println("ID: " + id+": type conflict: lotroplan=" + lotroplan.getClass() + ", source=" + source.getClass());
        if (source.getClass() == Item.class) {
            if (lotroplan instanceof Armour) {
                Armour armour = new Armour();
                Armour lotroplanArmour = (Armour) lotroplan;
                result = armour;
                armour.copyFrom(source);
                armour.setArmourValue(lotroplanArmour.getArmourValue());
                armour.setArmourType(lotroplanArmour.getArmourType());
            } else {
                System.out.println("ID: " + id + ": type conflict: lotroplan=" + lotroplan.getClass() + ", source=" + source.getClass());
            }
        }
        if (source.getClass() == Weapon.class) {
            if (lotroplan.getClass() == Item.class) {
                result = source;
            } else {
                System.out.println("ID: " + id + ": type conflict: lotroplan=" + lotroplan.getClass() + ", source=" + source.getClass());
            }
        }
    } else {
        result = source;
    }
    // Name
    {
        String sourceName = source.getName();
        /*
      String lotroplanName=lotroplan.getName();
      if (!lotroplanName.equals(sourceName))
      {
        System.out.println("ID: " + id+": name conflict: lotroplan=" + lotroplanName + ", source=" + sourceName);
        if (lotroplanName!=null)
        {
          result.setProperty(ItemPropertyNames.LOTRO_PLAN_NAME, lotroplanName);
        }
      }
      */
        result.setName(sourceName);
    }
    // Armour
    {
        if (lotroplan instanceof Armour) {
            Armour lotroplanArmour = (Armour) lotroplan;
            Armour resultArmour = (Armour) result;
            // Check values
            {
                int lotroplanArmourValue = lotroplanArmour.getArmourValue();
                /*
          int resultArmourValue=resultArmour.getArmourValue();
          if (lotroplanArmourValue!=resultArmourValue)
          {
            System.out.println("ID: " + id+": armour value conflict: lotroplan=" + lotroplanArmourValue + ", source=" + resultArmourValue);
          }
          */
                resultArmour.setArmourValue(lotroplanArmourValue);
            }
        }
    }
    // Item level
    {
        Integer sourceItemLevel = source.getItemLevel();
        Integer lotroPlanItemLevel = lotroplan.getItemLevel();
        boolean conflict = false;
        if (lotroPlanItemLevel != null) {
            if (sourceItemLevel == null) {
                conflict = true;
            // result.setMinLevel(tulkasMinLevel);
            } else {
                if (lotroPlanItemLevel.intValue() != sourceItemLevel.intValue()) {
                    conflict = true;
                // result.setMinLevel(tulkasMinLevel);
                }
            }
        } else {
            if (sourceItemLevel != null) {
                conflict = true;
            // result.setMinLevel(sourceMinLevel);
            }
        }
        if (conflict) {
        // System.out.println("ID: " + id+": item level conflict: lotroplan=" + lotroPlanItemLevel + ", source=" + sourceItemLevel);
        }
        result.setItemLevel(lotroplan.getItemLevel());
    }
    // Stats
    {
        BasicStatsSet resultStats = result.getStats();
        FixedDecimalsInteger stealth = resultStats.getStat(STAT.STEALTH_LEVEL);
        FixedDecimalsInteger tacticalCritMultiplier = resultStats.getStat(STAT.TACTICAL_CRITICAL_MULTIPLIER);
        resultStats.clear();
        resultStats.setStats(lotroplan.getStats());
        if (stealth != null) {
            resultStats.setStat(STAT.STEALTH_LEVEL, stealth);
        }
        if (tacticalCritMultiplier != null) {
            resultStats.setStat(STAT.TACTICAL_CRITICAL_MULTIPLIER, tacticalCritMultiplier);
        }
    }
    // Essence slots
    result.setEssenceSlots(lotroplan.getEssenceSlots());
    // Slot
    EquipmentLocation lpLocation = lotroplan.getEquipmentLocation();
    if (lpLocation != null) {
        EquipmentLocation location = result.getEquipmentLocation();
        boolean conflict = false;
        if ((location != null) && (location != lpLocation)) {
            conflict = true;
        }
        if (conflict) {
            System.out.println("ID: " + id + ": slot conflict: lotroplan=" + lpLocation + ", source=" + location);
        }
        result.setEquipmentLocation(lpLocation);
    }
    // Sub-category
    String lpSubCategory = lotroplan.getSubCategory();
    if ((lpSubCategory != null) && (lpSubCategory.length() > 0)) {
        /*
      String subCategory=result.getSubCategory();
      boolean conflict=false;
      if ((subCategory!=null) && (!subCategory.equals(lpSubCategory)))
      {
        conflict=true;
      }
      if (conflict)
      {
        System.out.println("ID: " + id+": category conflict: lotroplan=" + lpSubCategory + ", source=" + subCategory);
      }
      */
        result.setSubCategory("LP:" + lpSubCategory);
    }
    // Class requirement
    CharacterClass lpClass = lotroplan.getRequiredClass();
    if (lpClass != null) {
        CharacterClass cClass = result.getRequiredClass();
        boolean conflict = false;
        if ((cClass != null) && (cClass != lpClass)) {
            conflict = true;
        }
        if (conflict) {
            System.out.println("ID: " + id + ": class conflict: lotroplan=" + lpClass + ", source=" + cClass);
        }
        result.setRequiredClass(lpClass);
    }
    // Properties
    result.getProperties().putAll(lotroplan.getProperties());
    return result;
}
Also used : FixedDecimalsInteger(delta.games.lotro.utils.FixedDecimalsInteger) Item(delta.games.lotro.lore.items.Item) Armour(delta.games.lotro.lore.items.Armour) FixedDecimalsInteger(delta.games.lotro.utils.FixedDecimalsInteger) EquipmentLocation(delta.games.lotro.lore.items.EquipmentLocation) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet) CharacterClass(delta.games.lotro.common.CharacterClass)

Example 32 with BasicStatsSet

use of delta.games.lotro.character.stats.BasicStatsSet in project lotro-tools by dmorcellet.

the class ScalableItemsSamplesLoader method buildItemFromLine.

private Item buildItemFromLine(String line) {
    String[] fields = StringSplitter.split(line, '\t');
    // Stats
    BasicStatsSet stats = new BasicStatsSet();
    int nbStats = STATS.length;
    for (int i = 0; i < nbStats; i++) {
        if ((STATS[i] != null) && (fields.length > i)) {
            String valueStr = fields[i];
            FixedDecimalsInteger value = StatValueParser.parseStatValue(valueStr);
            if (value != null) {
                stats.addStat(STATS[i], value);
            }
        }
    }
    // Item level
    Integer itemLevel = NumericTools.parseInteger(fields[ITEM_LEVEL_INDEX]);
    // Build item
    FixedDecimalsInteger armorStat = stats.getStat(STAT.ARMOUR);
    Item item = null;
    Armour armour = null;
    if (armorStat != null) {
        armour = new Armour();
        item = armour;
        armour.setArmourValue(armorStat.intValue());
        stats.removeStat(STAT.ARMOUR);
    } else {
        item = new Item();
    }
    // Item level
    item.setItemLevel(itemLevel);
    // Name
    String name = fields[NAME_INDEX];
    name = name.trim();
    item.setName(name);
    // Slots
    String slotStr = fields[SLOTS_INDEX];
    int nbSlots = NumericTools.parseInt(slotStr, 0);
    item.setEssenceSlots(nbSlots);
    // Min level
    String requiredLevelStr = fields[REQUIRED_LEVEL_INDEX];
    Integer requiredLevel = NumericTools.parseInteger(requiredLevelStr);
    if (requiredLevelStr != null) {
        item.setMinLevel(requiredLevel);
    }
    // Stats
    item.getStats().setStats(stats);
    return item;
}
Also used : FixedDecimalsInteger(delta.games.lotro.utils.FixedDecimalsInteger) Item(delta.games.lotro.lore.items.Item) Armour(delta.games.lotro.lore.items.Armour) FixedDecimalsInteger(delta.games.lotro.utils.FixedDecimalsInteger) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet)

Example 33 with BasicStatsSet

use of delta.games.lotro.character.stats.BasicStatsSet in project lotro-tools by dmorcellet.

the class CharacterPageParser method parseStats.

private void parseStats(Element charPanel) {
    BasicStatsSet stats = _character.getStats();
    // <table class="stat_list">
    List<Element> statsTables = JerichoHtmlUtils.findElementsByTagNameAndAttributeValue(charPanel, HTMLElementName.TABLE, "class", "stat_list");
    for (Element statsTable : statsTables) {
        List<Element> rows = statsTable.getAllElements(HTMLElementName.TR);
        for (Element row : rows) {
            String statName = JerichoHtmlUtils.getTagContents(row, HTMLElementName.TH);
            if (statName != null) {
                statName = statName.trim();
                if (statName.length() > 0) {
                    String statValue = JerichoHtmlUtils.getTagContents(row, HTMLElementName.TD);
                    STAT stat = getStatByName(statName);
                    if (stat != null) {
                        Integer value = null;
                        if (!"N/A".equals(statValue)) {
                            value = NumericTools.parseInteger(statValue);
                        }
                        if (value != null) {
                            stats.setStat(stat, value.intValue());
                        }
                    // System.out.println("Stat : name=["+statName+"], value=["+value+"]");
                    }
                }
            }
        }
    }
}
Also used : STAT(delta.games.lotro.character.stats.STAT) Element(net.htmlparser.jericho.Element) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet)

Example 34 with BasicStatsSet

use of delta.games.lotro.character.stats.BasicStatsSet 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 35 with BasicStatsSet

use of delta.games.lotro.character.stats.BasicStatsSet 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

BasicStatsSet (delta.games.lotro.character.stats.BasicStatsSet)38 FixedDecimalsInteger (delta.games.lotro.utils.FixedDecimalsInteger)13 STAT (delta.games.lotro.character.stats.STAT)12 Item (delta.games.lotro.lore.items.Item)11 Armour (delta.games.lotro.lore.items.Armour)9 CharacterClass (delta.games.lotro.common.CharacterClass)7 EquipmentLocation (delta.games.lotro.lore.items.EquipmentLocation)6 CharacterData (delta.games.lotro.character.CharacterData)5 CharacterStatsComputer (delta.games.lotro.character.stats.CharacterStatsComputer)4 SlicesBasedItemStatsProvider (delta.games.lotro.lore.items.stats.SlicesBasedItemStatsProvider)4 JPanel (javax.swing.JPanel)4 CharacterEquipment (delta.games.lotro.character.CharacterEquipment)3 EQUIMENT_SLOT (delta.games.lotro.character.CharacterEquipment.EQUIMENT_SLOT)3 ArmourType (delta.games.lotro.lore.items.ArmourType)3 ItemQuality (delta.games.lotro.lore.items.ItemQuality)3 Weapon (delta.games.lotro.lore.items.Weapon)3 ArrayList (java.util.ArrayList)3 JFrame (javax.swing.JFrame)3 Element (net.htmlparser.jericho.Element)3 DefaultWindowController (delta.common.ui.swing.windows.DefaultWindowController)2