コード例 #1
0
  // XXX Beliebige Projekte unterstützen
  public void startProject(/*String projectId*/ ) {
    Blueprint blueprint = new LagerProject();
    Project project = new Project();
    project.setBlueprint(blueprint.getId());
    project.setName(blueprint.getName());
    // XXX Woher kommt's Level?
    project.setResourcesToFinish(blueprint.getResourcesNeeded(1));

    projectRepository.save(project);
  }
コード例 #2
0
  /**
   * Let {@link Inhabitant} work on current Project.
   *
   * @return if inhabitant has actually worked
   */
  public boolean workOnCurrentProject(ResourcesManager resources, Inhabitant inhabitant) {
    Project currentProject = getCurrentProject();

    if (currentProject == null) {
      return false;
    }

    Collection<ResourceAmount> resourcesToFinish = currentProject.getResourcesToFinish();
    boolean projectFinished = true;
    boolean inhabitantWorked = false;

    for (ResourceAmount finishResourceAmount : resourcesToFinish) {
      final int finishAmount = finishResourceAmount.getAmount();

      if (finishAmount > 0) {
        int potentialBuildingProgress = inhabitant.getSkill(BUILDING);
        TYPE resourceType = finishResourceAmount.getType();

        // Calculate actualBuildingProgress
        int actualBuildingProgress =
            Math.min(
                potentialBuildingProgress,
                resources.getAmount(resourceType)); // memberBuildingProgress
        actualBuildingProgress = Math.min(actualBuildingProgress, finishAmount);

        // Adjust resources
        resources.reduce(TYPE.WOOD, actualBuildingProgress);
        finishResourceAmount.setAmount(finishAmount - actualBuildingProgress);

        // Adjust Project status
        projectFinished = finishAmount == actualBuildingProgress;
        inhabitantWorked = actualBuildingProgress > 0;
        break;
      }
    }

    if (projectFinished) {
      String blueprintId = currentProject.getBlueprint();
      getBlueprintById(blueprintId).executeResult(resourcesManager);

      projectRepository.delete(currentProject);
    } else {
      projectRepository.save(currentProject);
    }

    return inhabitantWorked;
  }