/**
   * Handles npc spell option.
   *
   * @param player The player.
   * @param packet The packet.
   */
  private void handleOptionSpell(final Player player, Packet packet) {
    packet.getShort();
    int interfaceValue = packet.getLEInt();
    //		int interfaceId = interfaceValue >> 16;
    final int childButton = interfaceValue & 0xFFFF;
    int id = packet.getLEShortA();
    if (id < 0 || id >= Constants.MAX_NPCS) {
      return;
    }
    if (player.getCombatState().isDead()) {
      return;
    }
    player.getActionQueue().clearRemovableActions();

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

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

    Spell spell = Spell.forId(childButton, SpellBook.forId(player.getCombatState().getSpellBook()));
    if (npc != null && spell != null) {
      if (spell.getSpellType() == SpellType.NON_COMBAT) {
        return;
      }
      MagicCombatAction.setAutocast(player, null, -1, false);
      player.getCombatState().setQueuedSpell(spell);
      player.getCombatState().startAttacking(npc, false);
    }
  }
  /**
   * 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);
    }
  }
 @Override
 public void handle(Player player, Packet packet) {
   int privateBefore = player.getInterfaceState().getPrivateChat();
   player.getInterfaceState().setPublicChat(packet.get());
   player.getInterfaceState().setPrivateChat(packet.get());
   player.getInterfaceState().setTrade(packet.get());
   if (privateBefore
       != player.getInterfaceState().getPrivateChat()) { // private chat has been toggled
     player.getPrivateChat().updateFriendList(true);
   }
 }
Esempio n. 4
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);
  }
 @Override
 public void handle(Player player, Packet packet) {
   if (player.getAttribute("cutScene") != null) {
     return;
   }
   if (player.getInterfaceAttribute("fightPitOrbs") != null) {
     return;
   }
   switch (packet.getOpcode()) {
     case OPTION_1:
       handleOption1(player, packet);
       break;
     case OPTION_2:
       handleOption2(player, packet);
       break;
     case OPTION_3:
       handleOption3(player, packet);
       break;
     case OPTION_ATTACK:
       handleOptionAttack(player, packet);
       break;
     case OPTION_SPELL:
       handleOptionSpell(player, packet);
       break;
     case OPTION_EXAMINE:
       handleOptionExamine(player, packet);
       break;
   }
 }
  /**
   * Handles npc option examine.
   *
   * @param player The player.
   * @param packet The packet.
   */
  private void handleOptionExamine(Player player, Packet packet) {
    int id = packet.getShortA() & 0xFFFF;
    if (id < 0 || id >= Constants.MAX_NPCS) {
      return;
    }
    if (player.getCombatState().isDead()) {
      return;
    }

    player
        .getActionSender()
        .sendDebugPacket(packet.getOpcode(), "NpcExamine", new Object[] {"ID: " + id});

    NPCDefinition npcDef = NPCDefinition.forId(id);
    if (npcDef != null) {
      player.getActionSender().sendMessage(npcDef.getDescription());
    }
  }
  /**
   * Handles npc option 1.
   *
   * @param player The player.
   * @param packet The packet.
   */
  private void handleOption1(final Player player, Packet packet) {
    final int id = packet.getShort() & 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(),
            "NpcOpt1",
            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()[0].startsWith("Talk")) {
                if (npc.getDefinition().getId() == 905) {
                  DialogueManager.openDialogue(player, 222);
                } else if (npc.getDefinition().getId() == 198) {
                  DialogueManager.openDialogue(player, 258);
                } else if (npc.getDefinition().getId() == 1597) {
                  DialogueManager.openDialogue(player, 241);
                } else {
                }
                if (npc.getDefinition().getName().toLowerCase().contains("banker")) {
                  DialogueManager.openDialogue(player, 0);
                } else {
                  String scriptName = "talkTo" + npc.getDefinition().getId();
                  if (!ScriptManager.getScriptManager()
                      .invokeWithFailTest(scriptName, player, npc)) {
                    //		player.getActionSender().sendMessage(npc.getDefinedName() + " does not want
                    // to talk.");
                  }
                }
                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);
    }
  }