Search in sources :

Example 1 with LotroDataSource

use of delta.games.lotro.lore.sql.LotroDataSource 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)

Aggregations

ExtensionPredicate (delta.common.utils.files.filter.ExtensionPredicate)1 IntegerHolder (delta.common.utils.misc.IntegerHolder)1 Item (delta.games.lotro.lore.items.Item)1 ItemsManager (delta.games.lotro.lore.items.ItemsManager)1 Bonus (delta.games.lotro.lore.items.bonus.Bonus)1 BonusManager (delta.games.lotro.lore.items.bonus.BonusManager)1 LotroDataSource (delta.games.lotro.lore.sql.LotroDataSource)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1