Search in sources :

Example 1 with IntegerHolder

use of delta.common.utils.misc.IntegerHolder in project lotro-tools by dmorcellet.

the class ItemsDbLoader method main.

/**
 * Main method.
 * @param args Not used.
 */
public static void main(String[] args) {
    LotroDataSource ds = LotroDataSource.getInstance("lotro");
    ObjectsManager<Item> itemsSource = ds.getManager(Item.class);
    ItemsManager mgr = ItemsManager.getInstance();
    File itemsDir = LotroCoreConfig.getInstance().getItemsDir();
    FileFilter fileFilter = new ExtensionPredicate("xml");
    File[] itemFiles = itemsDir.listFiles(fileFilter);
    if (itemFiles != null) {
        HashMap<String, IntegerHolder> other = new HashMap<String, IntegerHolder>();
        // HashMap<String,List<String>> itemsByCategory=new HashMap<String,List<String>>();
        for (File itemFile : itemFiles) {
            // if (nb==10000) break;
            String idStr = itemFile.getName();
            idStr = idStr.substring(0, idStr.length() - 4);
            int id = NumericTools.parseInt(idStr, -1);
            if (id != -1) {
                System.out.println(id);
                Item item = mgr.getItem(Integer.valueOf(id));
                // System.out.println(item.dump());
                BonusManager bonusMgr = item.getBonusManager();
                if (bonusMgr != null) {
                    // System.out.println(bonusMgr.dump());
                    int nbBonus = bonusMgr.getNumberOfBonus();
                    for (int i = 0; i < nbBonus; i++) {
                        Bonus bonus = bonusMgr.getBonusAt(i);
                        if (bonus.getBonusType() == BonusType.OTHER) {
                            String value = (String) bonus.getValue();
                            IntegerHolder holder = other.get(value);
                            if (holder == null) {
                                holder = new IntegerHolder();
                                other.put(value, holder);
                            }
                            holder.setInt(holder.getInt() + 1);
                        }
                    }
                }
                itemsSource.create(item);
            }
        // nb++;
        }
        List<String> others = new ArrayList<String>(other.keySet());
        Collections.sort(others);
        for (String value : others) {
            IntegerHolder counter = other.get(value);
            System.out.println(value + " -> " + counter);
        }
    /*
      for(Map.Entry<String,IntegerHolder> entry : other.entrySet())
      {
        System.out.println(entry.getKey()+" -> "+entry.getValue());
      }
      */
    }
}
Also used : ItemsManager(delta.games.lotro.lore.items.ItemsManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExtensionPredicate(delta.common.utils.files.filter.ExtensionPredicate) Bonus(delta.games.lotro.lore.items.bonus.Bonus) LotroDataSource(delta.games.lotro.lore.sql.LotroDataSource) Item(delta.games.lotro.lore.items.Item) IntegerHolder(delta.common.utils.misc.IntegerHolder) BonusManager(delta.games.lotro.lore.items.bonus.BonusManager) FileFilter(java.io.FileFilter) File(java.io.File)

Example 2 with IntegerHolder

use of delta.common.utils.misc.IntegerHolder in project lotro-tools by dmorcellet.

the class ItemStatistics method showStatistics.

private void showStatistics() {
    // Items
    System.out.println("Items: " + _itemsCount);
    // - qualities
    System.out.println("- by quality:");
    List<ItemQuality> itemQualities = new ArrayList<ItemQuality>(_itemsByQuality.keySet());
    Collections.sort(itemQualities, new ItemQualityComparator());
    for (ItemQuality itemQuality : itemQualities) {
        IntegerHolder count = _itemsByQuality.get(itemQuality);
        System.out.println("\t" + itemQuality + ": " + count);
    }
    // - sub-categories
    System.out.println("- by sub-category:");
    List<String> itemSubCategories = new ArrayList<String>(_itemsBySubCategory.keySet());
    Collections.sort(itemSubCategories);
    for (String itemSubCategory : itemSubCategories) {
        IntegerHolder count = _itemsBySubCategory.get(itemSubCategory);
        System.out.println("\t" + itemSubCategory + ": " + count);
    }
    // - slot
    System.out.println("- by slot:");
    List<EquipmentLocation> locations = new ArrayList<EquipmentLocation>(_itemsBySlot.keySet());
    Collections.sort(locations, new EquipmentLocationComparator());
    for (EquipmentLocation location : locations) {
        IntegerHolder count = _itemsBySlot.get(location);
        System.out.println("\t" + location + ": " + count);
        List<String> names = _itemNamesBySlot.get(location);
        if (location != null) {
            Collections.sort(names);
            for (String name : names) {
                System.out.println("\t\t" + name);
            }
        }
    }
    // - scaling rules
    System.out.println("- by scaling rules:");
    List<String> scalingRules = new ArrayList<String>(_scalingRules.keySet());
    Collections.sort(scalingRules);
    for (String scalingRule : scalingRules) {
        List<String> names = _scalingRules.get(scalingRule);
        System.out.println("\t" + scalingRule + ": " + names.size());
        if (names.size() < 300) {
            Collections.sort(names);
            for (String name : names) {
                System.out.println("\t\t" + name);
            }
        }
    }
    // Armours
    System.out.println("Armours: " + _armoursCount);
    List<ArmourType> armourTypes = new ArrayList<ArmourType>(_armoursByType.keySet());
    Collections.sort(armourTypes, new ArmourTypeComparator());
    for (ArmourType armourType : armourTypes) {
        IntegerHolder count = _armoursByType.get(armourType);
        System.out.println("\t" + armourType + ": " + count);
    }
    // Weapons
    System.out.println("Weapons: " + _weaponsCount);
    List<WeaponType> weaponTypes = new ArrayList<WeaponType>(_weaponsByType.keySet());
    Collections.sort(weaponTypes, new WeaponTypeComparator());
    for (WeaponType weaponType : weaponTypes) {
        IntegerHolder count = _weaponsByType.get(weaponType);
        System.out.println("\t" + weaponType + ": " + count);
    }
}
Also used : ArmourType(delta.games.lotro.lore.items.ArmourType) EquipmentLocationComparator(delta.games.lotro.lore.items.comparators.EquipmentLocationComparator) ArrayList(java.util.ArrayList) ItemQuality(delta.games.lotro.lore.items.ItemQuality) IntegerHolder(delta.common.utils.misc.IntegerHolder) EquipmentLocation(delta.games.lotro.lore.items.EquipmentLocation) ItemQualityComparator(delta.games.lotro.lore.items.comparators.ItemQualityComparator) WeaponType(delta.games.lotro.lore.items.WeaponType) ArmourTypeComparator(delta.games.lotro.lore.items.comparators.ArmourTypeComparator) WeaponTypeComparator(delta.games.lotro.lore.items.comparators.WeaponTypeComparator)

Example 3 with IntegerHolder

use of delta.common.utils.misc.IntegerHolder in project lotro-tools by dmorcellet.

the class MainMapsCleaner method cleanEmptyCategories.

private void cleanEmptyCategories(MapsManager mapsManager) {
    HashMap<Integer, IntegerHolder> markersByCategory = new HashMap<Integer, IntegerHolder>();
    List<MapBundle> mapBundles = mapsManager.getMaps();
    for (MapBundle mapBundle : mapBundles) {
        MarkersManager markersManager = mapBundle.getData();
        List<Marker> markers = markersManager.getAllMarkers();
        for (Marker marker : markers) {
            Category category = marker.getCategory();
            if (category != null) {
                Integer code = Integer.valueOf(category.getCode());
                IntegerHolder counter = markersByCategory.get(code);
                if (counter == null) {
                    counter = new IntegerHolder();
                    markersByCategory.put(code, counter);
                }
                counter.increment();
            }
        }
    }
    CategoriesManager categoriesManager = mapsManager.getCategories();
    List<Integer> sortedCodes = new ArrayList<Integer>(markersByCategory.keySet());
    Collections.sort(sortedCodes);
    int total = 0;
    for (Integer code : sortedCodes) {
        IntegerHolder counter = markersByCategory.get(code);
        Category category = categoriesManager.getByCode(code.intValue());
        System.out.println(category.getLabel() + ": " + counter);
        total += counter.getInt();
    }
    System.out.println("Total: " + total);
    // Prepare cleanup
    HashSet<Integer> codes2Remove = new HashSet<Integer>();
    List<Category> categories = categoriesManager.getAllSortedByCode();
    for (Category category : categories) {
        Integer key = Integer.valueOf(category.getCode());
        if (!sortedCodes.contains(key)) {
            codes2Remove.add(key);
        }
    }
    // Perform cleanup
    for (Integer code : codes2Remove) {
        System.out.println("Removing category: " + categoriesManager.getByCode(code.intValue()).getLabel());
        categoriesManager.removeCategory(code.intValue());
    }
    mapsManager.saveCategories();
}
Also used : Category(delta.games.lotro.maps.data.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Marker(delta.games.lotro.maps.data.Marker) IntegerHolder(delta.common.utils.misc.IntegerHolder) CategoriesManager(delta.games.lotro.maps.data.CategoriesManager) MapBundle(delta.games.lotro.maps.data.MapBundle) MarkersManager(delta.games.lotro.maps.data.MarkersManager) HashSet(java.util.HashSet)

Aggregations

IntegerHolder (delta.common.utils.misc.IntegerHolder)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 ExtensionPredicate (delta.common.utils.files.filter.ExtensionPredicate)1 ArmourType (delta.games.lotro.lore.items.ArmourType)1 EquipmentLocation (delta.games.lotro.lore.items.EquipmentLocation)1 Item (delta.games.lotro.lore.items.Item)1 ItemQuality (delta.games.lotro.lore.items.ItemQuality)1 ItemsManager (delta.games.lotro.lore.items.ItemsManager)1 WeaponType (delta.games.lotro.lore.items.WeaponType)1 Bonus (delta.games.lotro.lore.items.bonus.Bonus)1 BonusManager (delta.games.lotro.lore.items.bonus.BonusManager)1 ArmourTypeComparator (delta.games.lotro.lore.items.comparators.ArmourTypeComparator)1 EquipmentLocationComparator (delta.games.lotro.lore.items.comparators.EquipmentLocationComparator)1 ItemQualityComparator (delta.games.lotro.lore.items.comparators.ItemQualityComparator)1 WeaponTypeComparator (delta.games.lotro.lore.items.comparators.WeaponTypeComparator)1 LotroDataSource (delta.games.lotro.lore.sql.LotroDataSource)1 CategoriesManager (delta.games.lotro.maps.data.CategoriesManager)1 Category (delta.games.lotro.maps.data.Category)1 MapBundle (delta.games.lotro.maps.data.MapBundle)1