@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; }
@Override public ItemList<NamedItemStack> getRepairs() { if (mode.equals(RepairFactoryMode.REPAIR)) { return rfp.getRepairMaterials(); } else { return new ItemList<NamedItemStack>(); } }
@Override public double getProductionTime() { if (mode.equals(RepairFactoryMode.REPAIR)) { return rfp.getRepairTime(); } else { return rfp.getProductionTime(); } }
@Override public ItemList<NamedItemStack> getInputs() { if (mode.equals(RepairFactoryMode.RESET_ITEMS)) { return rfp.getRecipeMaterials(); } else { return new ItemList<NamedItemStack>(); } }
@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; } }