예제 #1
0
  /* handle compost bin filling */
  @SuppressWarnings("unused")
  public void fillCompostBin(final Position binPosition, final int organicItemUsed) {
    final CompostBinLocations compostBinLocations = CompostBinLocations.forPosition(binPosition);
    final int index = compostBinLocations.getCompostIndex();
    if (compostBinLocations == null) {
      return;
    }
    int incrementFactor = 0;
    // setting up the different increments.
    for (int normalCompost : COMPOST_ORGANIC) {
      if (organicItemUsed == normalCompost) {
        incrementFactor = 2;
      }
    }

    for (int superCompost : SUPER_COMPOST_ORGANIC) {
      if (organicItemUsed == superCompost) {
        incrementFactor = 17;
      }
    }

    if (organicItemUsed == TOMATO) {
      if (compostBins[index] % 77 == 0) {
        incrementFactor = 77;
      } else {
        incrementFactor = 2;
      }
    }

    // checking if the item used was an organic item.
    if (incrementFactor == 0) {
      player.sendMessage(
          "You need to put organic items into the compost bin in order to make compost.");
      return;
    }
    final int factor = incrementFactor;
    // launching the main event for filling the compost bin.
    World.getWorld()
        .schedule(
            new ScheduledTask(2, false) {

              @Override
              public void execute() {
                if (!player.getInventory().contains(organicItemUsed)
                    || organicItemAdded[index] == 15) {
                  stop();
                  return;
                }
                organicItemAdded[index]++;
                player.playAnimation(new Animation(832, 0));
                player.getInventory().remove(new Item(organicItemUsed));
                compostBins[index] += factor;
                updateCompostBin(index);
              }

              @Override
              public void stop() {
                player.stopAnimation();
                super.stop();
              }
            });
  }