예제 #1
0
  /**
   * Attempts to fulfill Contract by removing Crop Resources. Fails if not e
   *
   * @param contract
   */
  private void fulfilContract(Contract contract) {
    World world = WorldManager.getInstance().getWorld();
    contract.decrementRepeatCount();
    if (contract.getRepeatCount() > 0) {
      // attempt to remove inventory
      if (world.getStorageManager().getCrops().getQuantity(contract.getResourceType())
          < contract.getAmount()) {
        // failed to supply crops - penalize and break contract.
        LOGGER.info("Contract Failed");
        notifyUser("Contract Failed");
        world.getMoneyHandler().subtractAmount(contract.getPenalty());
        removeContract(contract);
      } else {
        // maybe give small payment?
        LOGGER.info("contract delivered");
        notifyUser("Contract Delivered");
        world.getMoneyHandler().addAmount(150);
        world
            .getStorageManager()
            .getCrops()
            .takeItem(contract.getResourceType(), contract.getAmount());
      }

    } else {
      // the contract has been completed

      // add the reward to bank and remove contract.
      LOGGER.info("contract completed");
      notifyUser("Contract Completed");
      world.getMoneyHandler().addAmount(contract.getReward());
      currentContracts.remove(contract);
    }
  }