/**
   * Handles npc attack option.
   *
   * @param player The player.
   * @param packet The packet.
   */
  private void handleOptionAttack(final Player player, Packet packet) {
    final int id = packet.getLEShort() & 0xFFFF;
    if (id < 0 || id >= Constants.MAX_NPCS) {
      return;
    }
    if (player.getCombatState().isDead()) {
      return;
    }
    player.getActionQueue().clearRemovableActions();

    final NPC npc = (NPC) World.getWorld().getNPCs().get(id);

    for (int[] element : SlayerTasks.SLAYER_LEVELS_TO_ATTACK_NPCS) {
      if (element[0] == npc.getDefinition().getId()) {
        if (player.getSkills().getLevel(18) < element[1]) {
          player
              .getActionSender()
              .sendMessage("You need a Slayer level of " + element[1] + " to attack this npc.");
          return;
        }
      }
    }

    player
        .getActionSender()
        .sendDebugPacket(
            packet.getOpcode(),
            "NpcAttack",
            new Object[] {"ID: " + npc.getDefinition().getId(), "Index: " + id});

    if (npc != null) {
      player.getCombatState().setQueuedSpell(null);
      player.getCombatState().startAttacking(npc, false);
    }
  }
 public void begin() {
   player.getActionSender().removeChatboxInterface();
   String message = "";
   if (bar.getPrimaryOre() != null && !player.getInventory().contains(bar.getPrimaryOre()))
     message =
         "You do not have enough "
             + bar.getPrimaryOre().getDefinition().getName().toLowerCase()
             + " to smelt this bar.";
   else if (bar.getSecondaryOre() != null
       && !player.getInventory().contains(bar.getSecondaryOre()))
     message =
         "You do not have enough "
             + bar.getSecondaryOre().getDefinition().getName().toLowerCase()
             + " to smelt this bar.";
   if (message != "") {
     player.getActionSender().sendMessage(message);
     return;
   }
   if (player.getSkills().getLevel(Skills.SMITHING) < bar.getRequiredLevel()) {
     player.getActionSender().sendMessage("Your smithing level is too low to make this bar.");
     return;
   }
   player.playAnimation(ANIMATION);
   player.getActionQueue().addAction(this);
 }
コード例 #3
0
  @Override
  public void handle(Player player, Packet packet) {
    if (player.getSkills().getLevel(Skills.HITPOINTS) < 1) {
      return;
    }
    int size = packet.getLength();
    if (packet.getOpcode() == 11) {
      size -= 14;
    }
    if (player.getInterfaceAttribute("fightPitOrbs") != null) {
      return;
    }
    if (packet.getOpcode() != 59) { // force walking
      player.getCombatState().setQueuedSpell(null);
      player.resetInteractingEntity();
      player.getActionQueue().clearAllActions();
      player.getActionSender().removeAllInterfaces();
    }

    player.getWalkingQueue().reset();

    if (!player.getCombatState().canMove()) {
      if (packet.getOpcode() != 59) { // force walking
        player.getActionSender().sendMessage("A magical force stops you from moving.");
      }
      return;
    }
    if (!player.canEmote()) {
      return; // stops walking during skillcape animations.
    }

    final int steps = (size - 5) / 2;
    final int[][] path = new int[steps][2];

    for (int i = 0; i < steps; i++) {
      final int byte1 = packet.getByte();
      final int byteS = packet.getByteS();
      path[i][0] = byte1;
      path[i][1] = byteS;
    }
    final int firstX = packet.getShortA();
    final int firstY = packet.getLEShort();
    final boolean runSteps = packet.get() == 1;

    player.getWalkingQueue().setRunningQueue(runSteps);
    player.getWalkingQueue().addStep(firstX, firstY);
    for (int i = 0; i < steps; i++) {
      path[i][0] += firstX;
      path[i][1] += firstY;
      player.getWalkingQueue().addStep(path[i][0], path[i][1]);
    }
    player.getWalkingQueue().finish();
    // Boothes.outBooth(player);
  }
  public static void openInterface(final Player player) {
    for (int i = 0; i < 9; i++) {
      int itemId = i == 1 ? 9467 : 2349 + (i * 2);
      String color =
          player.getSkills().getLevel(Skills.SMITHING) < REQUIRED_LEVELS[i] ? "<col=#FF0000>" : "";
      String move = "<br><br><br><br>";
      player
          .getActionSender()
          .sendString(INTERFACE, 16 + (i * 4), move + color + ITEM_NAMES[i])
          .sendInterfaceModel(INTERFACE, i + 4, 150, itemId);
    }
    World.getWorld()
        .submit(
            new Event(600) {

              @Override
              public void execute() {
                player.getActionSender().sendChatboxInterface(INTERFACE);
                this.stop();
              }
            });
  }
  @Override
  public void execute() {
    if (!player.getInventory().contains(bar.getPrimaryOre())
        || (bar.getSecondaryOre() != null && !player.getInventory().contains(bar.getSecondaryOre()))
        || productionAmount < 1) {
      this.stop();
      Animation.create(-1);
      return;
    }
    fourTickDelay++;
    animationTick++;
    if (animationTick % 5 == 0) {
      player.playAnimation(ANIMATION);
      fourTickDelay = 1;
      if (bar == Bar.GOLD)
        player.getActionSender().sendMessage("You place a lump of gold in the furnace.");
    }
    if (fourTickDelay % 5 != 0) {
      return;
    }
    if (bar == Bar.IRON && random.nextBoolean() && !player.getEquipment().contains(2568)) {
      player.getInventory().remove(bar.primary);
      player.getActionSender().sendMessage("The ore is too impure and you fail to refine it.");
    } else {
      player.getInventory().remove(bar.getPrimaryOre());
      player.getInventory().remove(bar.getSecondaryOre());
      String message = bar.toString().toLowerCase();
      message =
          bar == Bar.GOLD
              ? "You retrieve a lump of gold from the furnace"
              : "You smelt the " + message + " in the furnace.";
      player.getInventory().add(bar.getProduct());
      player.getActionSender().sendMessage(message);
      player.getSkills().addExperience(Skills.SMITHING, bar.getExperience());
    }

    productionAmount--;
  }