Esempio n. 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);
    }
  }
Esempio n. 2
0
 /**
  * Get the date of delivery of one contract.
  *
  * @return the integer of date of delivery
  * @param contract: the contract that need to get delivery date.
  */
 public int getDeliveryDate(Contract contract) {
   World world = WorldManager.getInstance().getWorld();
   int currentDay = world.getTimeManager().getDays();
   int startDay = currentContracts.get(contract);
   int interval = contract.getInterval();
   return (startDay + interval) - currentDay;
 }