Ejemplo n.º 1
0
 @Override
 public double getProductionTime() {
   if (mode.equals(RepairFactoryMode.REPAIR)) {
     return rfp.getRepairTime();
   } else {
     return rfp.getProductionTime();
   }
 }
Ejemplo n.º 2
0
 @Override
 public ItemList<NamedItemStack> getRepairs() {
   if (mode.equals(RepairFactoryMode.REPAIR)) {
     return rfp.getRepairMaterials();
   } else {
     return new ItemList<NamedItemStack>();
   }
 }
Ejemplo n.º 3
0
 @Override
 public ItemList<NamedItemStack> getInputs() {
   if (mode.equals(RepairFactoryMode.RESET_ITEMS)) {
     return rfp.getRecipeMaterials();
   } else {
     return new ItemList<NamedItemStack>();
   }
 }
Ejemplo n.º 4
0
  @Override
  public List<InteractionResponse> getChestResponse() {
    List<InteractionResponse> responses = new ArrayList<InteractionResponse>();
    String status = active ? "On" : "Off";
    // double time = 0;
    int maxRepair = getMaxRepair();
    boolean maintenanceActive = maxRepair != 0;
    String response = "Current costs are : "; // the response specific to the mode.
    if (mode.equals(RepairFactoryMode.REPAIR)) {
      response += getRepairs().toString();
    } else if (mode.equals(RepairFactoryMode.RESET_ITEMS)) {
      response += getInputs().toString();
    }

    String percentDone =
        status.equals("On")
            ? " - " + Math.round(currentProductionTimer * 100 / getProductionTime()) + "% done."
            : "";
    int health =
        (!maintenanceActive) ? 100 : (int) Math.round(100 * (1 - currentRepair / (maxRepair)));
    responses.add(
        new InteractionResponse(
            InteractionResult.SUCCESS,
            rfp.getName() + ": " + status + " with " + String.valueOf(health) + "% health."));
    responses.add(
        new InteractionResponse(
            InteractionResult.SUCCESS, "Current mode: " + mode.getDescription()));
    responses.add(new InteractionResponse(InteractionResult.SUCCESS, response));
    responses.add(new InteractionResponse(InteractionResult.SUCCESS, percentDone));

    if (!getRepairs().isEmpty() && maintenanceActive && mode == RepairFactoryMode.REPAIR) {
      // amountAvailable() is pretty broken, so addressing it in config for now.
      int amountAvailable = getRepairs().amountAvailable(getInventory());
      int amountRepaired =
          amountAvailable > currentRepair ? (int) Math.ceil(currentRepair) : amountAvailable;
      int percentRepaired = (int) (((double) amountRepaired) / maxRepair * 100);
      log.finer(
          String.format(
              "Repair mode: available %d repaired %d maxrepair %d percentRepaired %d",
              amountAvailable, amountRepaired, maxRepair, percentRepaired));
      responses.add(
          new InteractionResponse(
              InteractionResult.SUCCESS,
              "Will repair "
                  + String.valueOf(percentRepaired)
                  + "% of the factory with "
                  + getRepairs().getMultiple(amountRepaired).toString()
                  + "."));
    }

    return responses;
  }
Ejemplo n.º 5
0
 @Override
 protected void recipeFinished() {
   log.finer("Recipe Finished");
   // getInputs().removeOneFrom(getInventory()); // Don't double dip! Parent consume already ate
   // recipe costs.
   org.bukkit.inventory.ItemStack[] contents = getInventory().getContents();
   for (int x = 0; x < contents.length; x++) {
     org.bukkit.inventory.ItemStack stack = contents[x];
     if (stack == null) {
       continue;
     }
     if (repairable(stack)) {
       log.fine("Found repairable: " + stack.getType());
       ItemStack s = CraftItemStack.asNMSCopy(stack);
       s.setRepairCost(rfp.getResetLevel());
       getInventory().setItem(x, CraftItemStack.asBukkitCopy(s));
     } else {
       log.fine("Found non-repairable: " + stack.getType());
     }
   }
 }
Ejemplo n.º 6
0
 @Override
 public ItemList<NamedItemStack> getFuel() {
   return rfp.getFuel();
 }
Ejemplo n.º 7
0
 @Override
 public int getMaxRepair() {
   return rfp.getRepair();
 }
Ejemplo n.º 8
0
 private boolean repairable(org.bukkit.inventory.ItemStack stack) {
   return rfp.getAllowedRepairable().contains(stack.getType());
 }
Ejemplo n.º 9
0
 @Override
 public double getEnergyTime() {
   return rfp.getEnergyTime();
 }
Ejemplo n.º 10
0
  @Override
  public List<InteractionResponse> togglePower() {
    log.info("Repair factory at " + this.factoryLocation.toString() + " power toggle attempt");
    List<InteractionResponse> response = new ArrayList<InteractionResponse>();
    // if the factory is turned off
    if (!active) {
      // if the factory isn't broken or the current recipe can repair it
      if (!isBroken() || isRepairing()) {
        // is there fuel enough for at least once energy cycle?
        if (isFuelAvailable()) {
          // are there enough materials for the current recipe in the chest?
          if (checkHasMaterials()) {
            // turn the factory on
            powerOn();
            // return a success message
            response.add(new InteractionResponse(InteractionResult.SUCCESS, "Factory activated!"));
            return response;
          } else { // there are not enough materials for the recipe!
            // return a failure message, containing which materials are needed for the recipe
            // [Requires the following: Amount Name, Amount Name.]
            // [Requires one of the following: Amount Name, Amount Name.]

            ItemList<NamedItemStack> needAll = new ItemList<NamedItemStack>();
            ItemList<NamedItemStack> allInputs = null;

            if (mode.equals(RepairFactoryMode.REPAIR)) {
              allInputs = rfp.getRepairMaterials();
            } else if (mode.equals(RepairFactoryMode.RESET_ITEMS)) {
              allInputs = rfp.getRecipeMaterials();
            }

            needAll.addAll(allInputs.getDifference(getInventory()));
            if (!needAll.isEmpty()) {
              response.add(
                  new InteractionResponse(
                      InteractionResult.FAILURE,
                      "You need all of the following: " + needAll.toString() + "."));
            } else if (allInputs == null || allInputs.isEmpty()) {
              System.out.println(
                  "getAllInputs() returned null or empty; recipe is returning no expectation of input!");
            }
            return response;
          }
        } else { // if there isn't enough fuel for at least one energy cycle
          // return a error message
          int multiplesRequired = (int) Math.ceil(getProductionTime() / (double) getEnergyTime());
          response.add(
              new InteractionResponse(
                  InteractionResult.FAILURE,
                  "Factory is missing fuel! ("
                      + getFuel().getMultiple(multiplesRequired).toString()
                      + ")"));
          return response;
        }
      } else {
        response.add(
            new InteractionResponse(InteractionResult.FAILURE, "Factory is in disrepair!"));
        return response;
      }
    } else { // if the factory is on already
      // turn the factory off
      powerOff();
      // return success message
      response.add(
          new InteractionResponse(InteractionResult.FAILURE, "Factory has been deactivated!"));
      return response;
    }
  }