/**
  * Retrieves an open height level by sifting through the mapping and attempting to retrieve the
  * lowest height level.
  *
  * @return the next lowest, open height level will be returned otherwise -1 will be returned. When
  *     -1 is returned it signifies that there are no heights open from 0 to {@link
  *     MAXIMUM_HEIGHT}.
  */
 public int getNextOpenHeight(Boundary boundary) {
   for (int height = 0; height < MAXIMUM_HEIGHT; height += 4) {
     if (active.containsKey(height)) {
       continue;
     }
     final int heightLevel = height;
     if (PlayerHandler.getPlayers()
         .stream()
         .anyMatch(p -> Boundary.isIn(p, boundary) && p.heightLevel == heightLevel)) {
       continue;
     }
     return height;
   }
   return -1;
 }
Exemplo n.º 2
0
  public static void activatePrayer(Player c, int i) {
    if (Server.getMultiplayerSessionListener().inSession(c, MultiplayerSessionType.TRADE)) {
      c.sendMessage("You cannot activate prayers whilst trading!");
      return;
    }
    if (Boundary.isIn(c, Boundary.DUEL_ARENAS)) {
      DuelSession session =
          (DuelSession)
              Server.getMultiplayerSessionListener()
                  .getMultiplayerSession(c, MultiplayerSessionType.DUEL);
      if (Objects.nonNull(session)) {
        if (session.getRules().contains(Rule.NO_PRAYER)) {
          c.sendMessage("Prayer has been disabled for this duel.");
          resetPrayers(c);
          return;
        }
      }
    }
    DuelSession duelSession =
        (DuelSession)
            Server.getMultiplayerSessionListener()
                .getMultiplayerSession(c, MultiplayerSessionType.DUEL);
    if (Objects.nonNull(duelSession)
        && duelSession.getStage().getStage() > MultiplayerSessionStage.REQUEST
        && duelSession.getStage().getStage() < MultiplayerSessionStage.FURTHER_INTERACTION) {
      c.sendMessage("You have declined the duel.");
      duelSession.getOther(c).sendMessage("The challenger has declined the duel.");
      duelSession.finish(MultiplayerSessionFinalizeType.WITHDRAW_ITEMS);
      return;
    }
    if (c.isDead || c.playerLevel[3] <= 0) {
      return;
    }
    if (c.clanWarRule[3]) {
      c.sendMessage("You are not allowed to use prayer during this war!");
      resetPrayers(c);
      return;
    }
    int[] defPray = {0, 5, 13, 24, 25};
    int[] strPray = {1, 6, 14, 24, 25};
    int[] atkPray = {2, 7, 15, 24, 25};
    int[] rangePray = {3, 11, 19};
    int[] magePray = {4, 12, 20};

    if (c.playerLevel[5] > 0 || !Config.PRAYER_POINTS_REQUIRED) {
      if (c.getPA().getLevelForXP(c.playerXP[5]) >= c.PRAYER_LEVEL_REQUIRED[i]
          || !Config.PRAYER_LEVEL_REQUIRED) {
        boolean headIcon = false;
        switch (i) {
          case 0:
          case 5:
          case 13:
            if (c.prayerActive[i] == false) {
              for (int j = 0; j < defPray.length; j++) {
                if (defPray[j] != i) {
                  c.prayerActive[defPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[defPray[j]], 0);
                }
              }
            }
            break;
          case 1:
          case 6:
          case 14:
            if (c.prayerActive[i] == false) {
              for (int j = 0; j < strPray.length; j++) {
                if (strPray[j] != i) {
                  c.prayerActive[strPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[strPray[j]], 0);
                }
              }
              for (int j = 0; j < rangePray.length; j++) {
                if (rangePray[j] != i) {
                  c.prayerActive[rangePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[rangePray[j]], 0);
                }
              }
              for (int j = 0; j < magePray.length; j++) {
                if (magePray[j] != i) {
                  c.prayerActive[magePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[magePray[j]], 0);
                }
              }
            }
            break;

          case 2:
          case 7:
          case 15:
            if (c.prayerActive[i] == false) {
              for (int j = 0; j < atkPray.length; j++) {
                if (atkPray[j] != i) {
                  c.prayerActive[atkPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[atkPray[j]], 0);
                }
              }
              for (int j = 0; j < rangePray.length; j++) {
                if (rangePray[j] != i) {
                  c.prayerActive[rangePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[rangePray[j]], 0);
                }
              }
              for (int j = 0; j < magePray.length; j++) {
                if (magePray[j] != i) {
                  c.prayerActive[magePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[magePray[j]], 0);
                }
              }
            }
            break;

          case 3: // range prays
          case 11:
          case 19:
            if (c.prayerActive[i] == false) {
              for (int j = 0; j < atkPray.length; j++) {
                if (atkPray[j] != i) {
                  c.prayerActive[atkPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[atkPray[j]], 0);
                }
              }
              for (int j = 0; j < strPray.length; j++) {
                if (strPray[j] != i) {
                  c.prayerActive[strPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[strPray[j]], 0);
                }
              }
              for (int j = 0; j < rangePray.length; j++) {
                if (rangePray[j] != i) {
                  c.prayerActive[rangePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[rangePray[j]], 0);
                }
              }
              for (int j = 0; j < magePray.length; j++) {
                if (magePray[j] != i) {
                  c.prayerActive[magePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[magePray[j]], 0);
                }
              }
            }
            break;
          case 4:
          case 12:
          case 20:
            if (c.prayerActive[i] == false) {
              for (int j = 0; j < atkPray.length; j++) {
                if (atkPray[j] != i) {
                  c.prayerActive[atkPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[atkPray[j]], 0);
                }
              }
              for (int j = 0; j < strPray.length; j++) {
                if (strPray[j] != i) {
                  c.prayerActive[strPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[strPray[j]], 0);
                }
              }
              for (int j = 0; j < rangePray.length; j++) {
                if (rangePray[j] != i) {
                  c.prayerActive[rangePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[rangePray[j]], 0);
                }
              }
              for (int j = 0; j < magePray.length; j++) {
                if (magePray[j] != i) {
                  c.prayerActive[magePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[magePray[j]], 0);
                }
              }
            }
            break;
          case 10:
            c.lastProtItem.reset();
            c.protectItem = !c.protectItem;
            break;

          case 16:
          case 17:
          case 18:
            if (System.currentTimeMillis() - c.stopPrayerDelay < 5000) {
              c.sendMessage("You have been injured and can't use this prayer!");
              c.getPA().sendFrame36(c.PRAYER_GLOW[16], 0);
              c.getPA().sendFrame36(c.PRAYER_GLOW[17], 0);
              c.getPA().sendFrame36(c.PRAYER_GLOW[18], 0);
              return;
            }
            if (i == 16) c.protMageDelay = System.currentTimeMillis();
            else if (i == 17) c.protRangeDelay = System.currentTimeMillis();
            else if (i == 18) c.protMeleeDelay = System.currentTimeMillis();
          case 21:
          case 22:
          case 23:
            headIcon = true;
            for (int p = 16; p < 24; p++) {
              if (i != p && p != 19 && p != 20) {
                c.prayerActive[p] = false;
                c.getPA().sendFrame36(c.PRAYER_GLOW[p], 0);
              }
            }
            break;
          case 24:
          case 25:
            if (c.prayerActive[i] == false) {
              for (int j = 0; j < atkPray.length; j++) {
                if (atkPray[j] != i) {
                  c.prayerActive[atkPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[atkPray[j]], 0);
                }
              }
              for (int j = 0; j < strPray.length; j++) {
                if (strPray[j] != i) {
                  c.prayerActive[strPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[strPray[j]], 0);
                }
              }
              for (int j = 0; j < rangePray.length; j++) {
                if (rangePray[j] != i) {
                  c.prayerActive[rangePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[rangePray[j]], 0);
                }
              }
              for (int j = 0; j < magePray.length; j++) {
                if (magePray[j] != i) {
                  c.prayerActive[magePray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[magePray[j]], 0);
                }
              }
              for (int j = 0; j < defPray.length; j++) {
                if (defPray[j] != i) {
                  c.prayerActive[defPray[j]] = false;
                  c.getPA().sendFrame36(c.PRAYER_GLOW[defPray[j]], 0);
                }
              }
            }
            break;
        }

        if (!headIcon) {
          if (c.prayerActive[i] == false) {
            c.prayerActive[i] = true;
            c.getPA().sendFrame36(c.PRAYER_GLOW[i], 1);
          } else {
            c.prayerActive[i] = false;
            c.getPA().sendFrame36(c.PRAYER_GLOW[i], 0);
          }
        } else {
          if (c.prayerActive[i] == false) {
            c.prayerActive[i] = true;
            c.getPA().sendFrame36(c.PRAYER_GLOW[i], 1);
            c.headIcon = c.PRAYER_HEAD_ICONS[i];
            c.getPA().requestUpdates();
          } else {
            c.prayerActive[i] = false;
            c.getPA().sendFrame36(c.PRAYER_GLOW[i], 0);
            c.headIcon = -1;
            c.getPA().requestUpdates();
          }
        }
      } else {
        c.getPA().sendFrame36(c.PRAYER_GLOW[i], 0);
        c.getPA()
            .sendFrame126(
                "You need a @blu@Prayer level of "
                    + c.PRAYER_LEVEL_REQUIRED[i]
                    + " to use "
                    + c.PRAYER_NAME[i]
                    + ".",
                357);
        c.getPA().sendFrame126("Click here to continue", 358);
        c.getPA().sendFrame164(356);
      }
    } else {
      c.getPA().sendFrame36(c.PRAYER_GLOW[i], 0);
      c.sendMessage("You have run out of prayer points!");
    }
  }