コード例 #1
0
ファイル: Compost.java プロジェクト: root-voicenet/Konklex
  public boolean handleObjectClick(int objectId, int objectX, int objectY) {

    switch (objectId) {
      case 7810:
      case 7812:
      case 7820:
      case 7822:
      case 7829:
      case 7833:
        closeCompostBin(
            CompostBinLocations.forPosition(new Position(objectX, objectY)).getCompostIndex());
        return true;

      case 7813:
      case 7823:
        openCompostBin(
            CompostBinLocations.forPosition(new Position(objectX, objectY)).getCompostIndex());
        return true;

      case 7830:
      case 7831:
      case 7834:
      case 7835:
        retrieveCompost(
            CompostBinLocations.forPosition(new Position(objectX, objectY)).getCompostIndex());
        return true;
    }
    return false;
  }
コード例 #2
0
ファイル: Compost.java プロジェクト: root-voicenet/Konklex
  public boolean handleItemOnObject(int itemUsed, int objectId, int objectX, int objectY) {
    switch (objectId) {
      case 7814:
      case 7815:
      case 7816:
      case 7817:
      case 7824:
      case 7825:
      case 7826:
      case 7827:
        if (itemUsed == 1925) {
          retrieveCompost(
              CompostBinLocations.forPosition(new Position(objectX, objectY)).getCompostIndex());
        } else {
          player.sendMessage("You might need some buckets to gather the compost.");
        }
        return true;

      case 7839:
      case 7838:
      case 7837:
      case 7836:
      case 7808:
      case 7809:
      case 7811:
      case 7819:
      case 7821:
      case 7828:
      case 7832:
        fillCompostBin(new Position(objectX, objectY), itemUsed);
        return true;
    }
    return false;
  }
コード例 #3
0
ファイル: Compost.java プロジェクト: root-voicenet/Konklex
 public static CompostBinLocations forPosition(Position position) {
   for (CompostBinLocations compostBinLocations : CompostBinLocations.values()) {
     if (compostBinLocations.binPosition.equals(position)) {
       return compostBinLocations;
     }
   }
   return null;
 }
コード例 #4
0
ファイル: Compost.java プロジェクト: root-voicenet/Konklex
 static {
   for (CompostBinLocations data : CompostBinLocations.values()) {
     bins.put(data.compostIndex, data);
   }
 }
コード例 #5
0
ファイル: Compost.java プロジェクト: root-voicenet/Konklex
  /* 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();
              }
            });
  }
コード例 #6
0
ファイル: Compost.java プロジェクト: root-voicenet/Konklex
  /* handle compost bin updating */
  private void updateCompostBin(int index) {
    CompostBinStages compostBinStages =
        CompostBinStages.forId(CompostBinLocations.forId(index).getBinObjectId());

    if (compostBinStages == null) {
      return;
    }
    int x = CompostBinLocations.forId(index).getBinPosition().getX();
    int y = CompostBinLocations.forId(index).getBinPosition().getY();
    int z = CompostBinLocations.forId(index).getBinPosition().getHeight();
    int finalObject;

    // handling the different ways to fill a compost bin
    if (compostBins[index] > 0) {
      if (compostBins[index] % 17 == 0) {
        finalObject = compostBinStages.getBinWithSuperCompostable();
      } else if (compostBins[index] % 77 == 0) {
        finalObject = compostBinStages.getBinWithTomatoes();
      } else {
        finalObject = compostBinStages.getBinWithCompostable();
      }
    } else {
      finalObject = compostBinStages.getBinEmpty();
    }

    // handling the different ways to complete a compost bin
    if (compostBins[index] == 255) {
      finalObject = compostBinStages.getBinFullOFSuperCompostable();
      tempCompostState = 2;
    } else if (compostBins[index] == 1155) {
      finalObject = compostBinStages.getBinFullOfTomatoes();
      tempCompostState = 3;
    } else if (organicItemAdded[index] == 15) {
      finalObject = compostBinStages.getBinFullOfCompostable();
      tempCompostState = 1;
    }
    // handling the closed state of the compost bin
    switch (compostBins[index]) {
      case 100:
      case 200:
      case 300:
        finalObject = compostBinStages.getClosedBin();
        break;

        // handling the rotted state of the compost in the bin
      case 150:
        finalObject = compostBinStages.getBinFullOfCompost();
        break;
      case 250:
        finalObject = compostBinStages.getBinFullOfSuperCompost();
        break;
      case 350:
        finalObject = compostBinStages.getBinFullOfRottenTomatoes();
        break;
    }

    // handle the compost bin state when the player retrieve the compost
    if (compostBins[index] == 150 && organicItemAdded[index] < 15) {
      finalObject = compostBinStages.getBinWithCompost();
    } else if (compostBins[index] == 250 && organicItemAdded[index] < 15) {
      finalObject = compostBinStages.getBinWithSuperCompost();
    }
    if (compostBins[index] == 350 && organicItemAdded[index] < 15) {
      finalObject = compostBinStages.getBinWithRottenTomatoes();
    }

    final Position pos = new Position(x, y, z);
    GameObject object =
        new GameObject(
            ObjectDefinition.forId(finalObject),
            pos,
            10,
            CompostBinLocations.forId(index).getObjectFace());
    player.send(new PositionEvent(player.getLastKnownRegion(), pos));
    player.send(new CreateObjectEvent(object));
  }