Search in sources :

Example 1 with LotroPlanTable

use of delta.games.lotro.tools.lore.items.lotroplan.LotroPlanTable in project lotro-tools by dmorcellet.

the class EssenceStatsInjector method handleTier.

private void handleTier(int tier, HashMap<Integer, Item> essences) {
    URL url = URLTools.getFromClassPath("tier" + tier + ".txt", EssenceStatsInjector.class.getPackage());
    if (url != null) {
        TextFileReader reader = new TextFileReader(url, EncodingNames.UTF_8);
        List<String> lines = TextUtils.readAsLines(reader);
        boolean hasId = lines.get(0).startsWith("ID");
        lines.remove(0);
        HashSet<Integer> unmanaged = new HashSet<Integer>();
        unmanaged.addAll(essences.keySet());
        LotroPlanTable table = new LotroPlanTable(STATS);
        for (String line : lines) {
            String[] fields = StringSplitter.split(line, '\t');
            if (fields.length > 2) {
                List<Item> items = findEssences(fields, hasId, essences);
                for (Item item : items) {
                    if (hasId) {
                        String[] newFields = new String[fields.length - 1];
                        for (int i = 1; i < fields.length; i++) {
                            newFields[i - 1] = fields[i];
                            if (newFields[i - 1].equals(CELLS[i])) {
                                newFields[i - 1] = "";
                            }
                        }
                        fields = newFields;
                    }
                    unmanaged.remove(Integer.valueOf(item.getIdentifier()));
                    // Item level
                    int itemLevel = NumericTools.parseInt(fields[ITEM_LEVEL_INDEX], -1);
                    if (itemLevel != -1) {
                        item.setItemLevel(Integer.valueOf(itemLevel));
                    }
                    // Notes
                    if (fields.length > NOTES_INDEX) {
                        String notes = fields[NOTES_INDEX].trim();
                        if (notes.length() > 0) {
                            item.getBonus().add(notes);
                        }
                    }
                    // Tier
                    item.setSubCategory("Essence:Tier" + tier);
                    // Stats
                    ItemStatsProvider provider = table.loadStats(fields);
                    BasicStatsSet stats = item.getStats();
                    stats.setStats(provider.getStats(itemLevel));
                }
                if (items.size() == 0) {
                    System.out.println("Essence not found: " + fields[0]);
                }
            } else {
                if (!line.startsWith("#")) {
                    System.err.println("Bad fields count: " + line);
                }
            }
        }
        if (unmanaged.size() > 0) {
            System.out.println(unmanaged + " unmanaged essences:");
            for (Integer id : unmanaged) {
                Item essence = essences.get(id);
                System.out.println("\t" + essence);
            }
        }
    }
}
Also used : LotroPlanTable(delta.games.lotro.tools.lore.items.lotroplan.LotroPlanTable) BasicStatsSet(delta.games.lotro.character.stats.BasicStatsSet) URL(java.net.URL) TextFileReader(delta.common.utils.files.TextFileReader) ItemStatsProvider(delta.games.lotro.lore.items.stats.ItemStatsProvider) Item(delta.games.lotro.lore.items.Item) HashSet(java.util.HashSet)

Aggregations

TextFileReader (delta.common.utils.files.TextFileReader)1 BasicStatsSet (delta.games.lotro.character.stats.BasicStatsSet)1 Item (delta.games.lotro.lore.items.Item)1 ItemStatsProvider (delta.games.lotro.lore.items.stats.ItemStatsProvider)1 LotroPlanTable (delta.games.lotro.tools.lore.items.lotroplan.LotroPlanTable)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1