@Override
 protected List<List<String>> loadRecipes() {
   final String filename = parametersFile();
   @SuppressWarnings("unchecked")
   List<List<String>> recipes =
       (List<List<String>>) Resources.getResource("PARSED_RECIPE: " + filename);
   if (recipes == null) {
     final StringBuffer str =
         new CMFile(Resources.buildResourcePath("skills") + filename, null, CMFile.FLAG_LOGERRORS)
             .text();
     recipes = loadList(str);
     if (recipes.size() == 0) Log.errOut("LeatherWorking", "Recipes not found!");
     else {
       final List<List<String>> newRecipes = new Vector<List<String>>();
       for (int r = 0; r < recipes.size(); r++) {
         final List<String> V = recipes.get(r);
         if (V.size() > 0) {
           final String name = V.get(RCP_FINALNAME);
           final int baseLevel = CMath.s_int(V.get(RCP_LEVEL)) + 2;
           for (final Stage s : Stage.values()) {
             final List<String> V1 = new XVector<String>(V);
             V1.set(RCP_FINALNAME, s.name() + " " + name);
             final int level = baseLevel + s.recipeLevel;
             V1.set(RCP_LEVEL, "" + level);
             for (int i = 0; i <= newRecipes.size(); i++) {
               if (newRecipes.size() == i) {
                 newRecipes.add(V1);
                 break;
               } else if (CMath.s_int(newRecipes.get(i).get(RCP_LEVEL)) > level) {
                 newRecipes.add(i, V1);
                 break;
               }
             }
           }
         }
       }
       recipes.clear();
       recipes = newRecipes;
     }
     Resources.submitResource("PARSED_RECIPE: " + filename, recipes);
   }
   return recipes;
 }
Exemplo n.º 2
0
 public static boolean doRentalProperty(Area A, String ID, String owner, int rent) {
   if (!CMProps.getBoolVar(CMProps.Bool.MUDSTARTED)) return false;
   final int month = A.getTimeObj().getMonth();
   final int day = A.getTimeObj().getDayOfMonth();
   final int year = A.getTimeObj().getYear();
   final Object O = Resources.getResource("RENTAL INFO/" + owner);
   List<PlayerData> pDataV = null;
   if (O instanceof List) pDataV = (List<PlayerData>) O;
   else pDataV = CMLib.database().DBReadData(owner, "RENTAL INFO");
   if (pDataV == null) pDataV = new Vector();
   DatabaseEngine.PlayerData pData = null;
   if (pDataV.size() == 0) {
     pData = new DatabaseEngine.PlayerData();
     pData.who = owner;
     pData.section = "RENTAL INFO";
     pData.key = "RENTAL INFO/" + owner;
     pData.xml = ID + "|~>|" + day + " " + month + " " + year + "|~;|";
     CMLib.database().DBCreateData(owner, "RENTAL INFO", "RENTAL INFO/" + owner, pData.xml);
     pDataV.add(pData);
     Resources.submitResource("RENTAL INFO/" + owner, pDataV);
     return false;
   } else if (pDataV.get(0) != null) {
     pData = pDataV.get(0);
     String parse = pData.xml;
     int x = parse.indexOf("|~;|");
     final StringBuffer reparse = new StringBuffer("");
     boolean changesMade = false;
     boolean needsToPay = false;
     while (x >= 0) {
       String thisOne = parse.substring(0, x);
       if (thisOne.startsWith(ID + "|~>|")) {
         thisOne = thisOne.substring((ID + "|~>|").length());
         final Vector dateV = CMParms.parse(thisOne);
         if (dateV.size() == 3) {
           int lastYear = CMath.s_int((String) dateV.lastElement());
           int lastMonth = CMath.s_int((String) dateV.elementAt(1));
           final int lastDay = CMath.s_int((String) dateV.firstElement());
           while (!needsToPay) {
             if (lastYear < year) needsToPay = true;
             else if ((lastYear == year) && (lastMonth < month) && (day >= lastDay))
               needsToPay = true;
             if (needsToPay) {
               if (CMLib.beanCounter()
                   .modifyLocalBankGold(
                       A,
                       owner,
                       CMLib.utensils().getFormattedDate(A)
                           + ":Withdrawal of "
                           + rent
                           + ": Rent for "
                           + ID,
                       CMLib.beanCounter().getCurrency(A),
                       (-rent))) {
                 lastMonth++;
                 if (lastMonth > A.getTimeObj().getMonthsInYear()) {
                   lastMonth = 1;
                   lastYear++;
                 }
                 changesMade = true;
                 needsToPay = false;
               }
             } else break;
           }
           if (changesMade)
             reparse.append(ID + "|~>|" + lastDay + " " + lastMonth + " " + lastYear + "|~;|");
           if (needsToPay && (!changesMade)) return true;
         }
       } else reparse.append(thisOne + "|~;|");
       parse = parse.substring(x + 4);
       x = parse.indexOf("|~;|");
     }
     if (changesMade) {
       CMLib.database()
           .DBReCreateData(owner, "RENTAL INFO", "RENTAL INFO/" + owner, reparse.toString());
       pData = new DatabaseEngine.PlayerData();
       pData.who = owner;
       pData.section = "RENTAL INFO";
       pData.key = "RENTAL INFO/" + owner;
       pData.xml = reparse.toString();
       pDataV.set(0, pData);
       Resources.removeResource("RENTAL INFO/" + owner);
       Resources.submitResource("RENTAL INFO/" + owner, pDataV);
     }
     return needsToPay;
   }
   return false;
 }