public static ManuQuote calculateReverseEngineeringQuote(
      Blueprint t3Bpo,
      int runs,
      ManuQuote oldQuote,
      PriceDB pdb,
      BlueprintDB bdb,
      ItemDB idb,
      Preferences prefs,
      RevPriority rPrio,
      MatAcquirePriority mPrio) {
    // Combination list.
    ArrayList<ManuQuote> qL = new ArrayList<>();
    ManuQuote tmp = null;
    Blueprint cleanT3Bpo = bdb.getByBlueprintId(t3Bpo.getBlueprintItem().getTypeId());

    for (Relic rel : cleanT3Bpo.getRevRelics()) {

      // Only add quote if relic is available.
      if (MarketCalculator.isItemAvailable(rel.getRelic(), pdb, prefs)) {
        tmp =
            calculateQuote(
                calculateReverseEngineeringBPC(cleanT3Bpo, rel, idb, prefs),
                runs,
                oldQuote,
                pdb,
                bdb,
                prefs,
                mPrio);
        tmp.setRev(
            new ReverseEngineering(
                calculateReverseEngineeringChance(cleanT3Bpo, rel, idb, prefs),
                cleanT3Bpo.getRevDecryptor(),
                rel.getRevMaxRunModifier(),
                new Time(DEFAULT_REV_TIME),
                rPrio));
        qL.add(tmp);
      }
    }

    // Pick the best Quote according to priority.
    for (ManuQuote q : qL) {
      if (rPrio == RevPriority.PROFIT_MARGIN && q.getProfit() > tmp.getProfit()) {
        tmp = q;
      } else if (rPrio == RevPriority.PROFIT_PER_REV_H
          && q.getProfit()
                  / (q.getRev().getRevTime().toHours()
                      * q.getRev().getBpcRuns()
                      * q.getRev().getSuccessRate())
              > tmp.getProfit()
                  / (tmp.getRev().getRevTime().toHours()
                      * tmp.getRev().getBpcRuns()
                      * tmp.getRev().getSuccessRate())) {
        tmp = q;
      }
    }
    return tmp;
  }
  private static Blueprint calculateReverseEngineeringBPC(
      Blueprint t3Bpo, Relic rel, ItemDB idb, Preferences prefs) {

    double amountMod =
        1
            / (rel.getRevMaxRunModifier()
                * calculateReverseEngineeringChance(t3Bpo, rel, idb, prefs));

    Blueprint b = new Blueprint(t3Bpo);
    // Set Me/Pe.
    b.setMe(DEFAULT_REV_MEPE_LEVEL);
    b.setPe(DEFAULT_REV_MEPE_LEVEL);

    // Add materials.
    b.getExtraMaterials().add(new Material(rel.getRelic(), amountMod));
    b.getExtraMaterials().add(new Material(t3Bpo.getRevDecryptor(), amountMod));

    for (Material m : rel.getRevMaterials()) {
      b.getExtraMaterials().add(new Material(m.getItem(), m.getAmount() * amountMod));
    }
    return b;
  }