/**
   * 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);
    }
  }
Esempio n. 2
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);
  }
  /**
   * Handles npc option 2.
   *
   * @param player The player.
   * @param packet The packet.
   */
  private void handleOption2(final Player player, Packet packet) {
    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);
    player
        .getActionSender()
        .sendDebugPacket(
            packet.getOpcode(),
            "NpcOpt2",
            new Object[] {"ID: " + npc.getDefinition().getId(), "Index: " + id});

    if (npc != null) {
      player.setInteractingEntity(InteractionMode.TALK, npc);
      Action action =
          new Action(player, 0) {
            @Override
            public void execute() {
              if (player.getCombatState().isDead()) {
                stop();
                return;
              }
              if (npc.getDefinition().getInteractionMenu()[2].startsWith("Bank")) {
                Bank.open(player);
              } else {
                String scriptName = "tradeWith" + npc.getDefinition().getId();
                if (!ScriptManager.getScriptManager().invokeWithFailTest(scriptName, player, npc)) {
                  // player.getActionSender().sendMessage(npc.getDefinedName() + " does not want to
                  // trade.");
                } else {
                  npc.setInteractingEntity(InteractionMode.TALK, player);
                }
              }
              stop();
            }

            @Override
            public AnimationPolicy getAnimationPolicy() {
              return AnimationPolicy.RESET_ALL;
            }

            @Override
            public CancelPolicy getCancelPolicy() {
              return CancelPolicy.ALWAYS;
            }

            @Override
            public StackPolicy getStackPolicy() {
              return StackPolicy.NEVER;
            }
          };
      int distance = 1;
      if (npc.getDefinition().getName().toLowerCase().contains("banker")
          || npc.getDefinition().getName().toLowerCase().contains("emily")
          || npc.getDefinition().getName().toLowerCase().contains("zambo")) {
        distance = 2;
      }
      player.addCoordinateAction(
          player.getWidth(),
          player.getHeight(),
          npc.getLocation(),
          npc.getWidth(),
          npc.getHeight(),
          distance,
          action);
    }
  }