Beispiel #1
0
 @Override
 public void execute() {
   Iterator<Player> it = WarriorsGuild.IN_GAME.iterator();
   while (it.hasNext()) {
     Player p = it.next();
     p.getInventory().remove(REMOVE);
     p.getActionSender().sendMessage("Ten of your tokens crumble away.");
     Item item = p.getInventory().getById(WarriorsGuild.TOKENS);
     if (item == null || item.getCount() < 10) {
       p.getWarriorsGuild().outOfTokens(); // Registers a 25 seconds
       // event.. ;)
     }
   }
 }
  @Override
  public void handle(Player player, Packet packet) {
    int button = packet.getShort();
    int interfaceId = packet.getShort();
    packet.getLEShortA();
    if (interfaceId != player.getInterfaceState().getCurrentInterface()) {
      player.getActionSender().sendCloseInterface();
      System.out.println("AMFG HACKERS.");
      return;
    }
    DialogueLoader dl = player.getCurrentDialogueLoader();
    switch (interfaceId) {
        /** DialougeLoader. */
      case 64:
      case 65:
      case 66:
      case 67:
      case 241:
      case 242:
      case 243:
      case 244:
        if (dl == null || player.getNextDialogueIds() == null) {
          /*
           * If the next dialogue ID's are null, we've most likely set
           * them null.
           */
          /*
           * We close all interfaces.
           */
          player.getActionSender().sendCloseInterface();
          /*
           * Check if the Monk of Entrana just searched us.
           */
          Object entranaTraveling = player.getTemporaryAttribute("EntranaShipTraveling");
          if (entranaTraveling != null) {
            if ((Boolean) entranaTraveling) {
              ShipTraveling.travel(player, ShipLocation.PORT_SARIM, ShipLocation.ENTRANA);
            }
            player.removeTemporaryAttribute("EntranaShipTraveling");
          }
          break;
        }
        int nextDialogueId = player.getNextDialogueIds()[0];
        DialogueLoader.getNextDialogue(player, dl, nextDialogueId);
        break;
        /** Options. */
      case 228: // Two options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Yes.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // NO.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
        }
        break;
      case 230: // Three options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Option 1.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // Option 2.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
          case 3: // Option 3.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[2]);
            return;
        }
        break;
      case 232: // Four options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Option 1.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // Option 2.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
          case 3: // Option 3.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[2]);
            return;
          case 4: // Option 4.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[3]);
            return;
        }
        break;
      case 234: // Five options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Option 1.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // Option 2.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
          case 3: // Option 3.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[2]);
            return;
          case 4: // Option 4.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[3]);
            return;
          case 5: // Option 5.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[4]);
            return;
        }
        break;
        /*
         * Interface with one line of info.
         */
      case 101:
        Object entranaTraveling1 = player.getTemporaryAttribute("EntranaShipTraveling");
        if (entranaTraveling1 != null) {
          boolean canTravel = (Boolean) entranaTraveling1;
          if (canTravel) {
            String[] lines = {"All is satisfactory. You may board the boat now."};
            DialogueLoader.dialogue(
                player,
                player.getInteractingEntity() == null
                    ? new NPC(NPCDefinition.forId(657))
                    : player.getInteractingEntity(),
                Emotes.DEFAULT,
                lines);
            player.setNextDialogueIds(null);
          } else {
            String[] lines = {
              "Grr! I see you brought some illegal items! Get", "out of my sight immediately!"
            };
            DialogueLoader.dialogue(
                player,
                player.getInteractingEntity() == null
                    ? new NPC(NPCDefinition.forId(657))
                    : player.getInteractingEntity(),
                Emotes.ANGER2,
                lines);
            player.setNextDialogueIds(null);
          }
          return;
        }
        player.getActionSender().sendCloseInterface();
        break;
        /*
         * Only used for Construction at the moment..
         */
      case 233:
        if (player.getConstruction().getBuildingRoom() == null) {
          switch (button) {
              /*
               * Enter your house.
               */
            case 1:
              player.getConstruction().enterHouse(false);
              break;
              /*
               * Enter your house (building mode)
               */
            case 2:
              player.getConstruction().enterHouse(true);
              break;
              /*
               * Enter friends house.
               */
            case 3:
              player.getInterfaceState().openEnterNameInterface(interfaceId);
              break;
          }
        } else {
          switch (button) {
              /*
               * Rotate clockwise
               */
            case 1:
              player
                  .getActionSender()
                  .sendMessage(
                      "I almost had this, but spend 2 days fixing it. Its a delayed feature for now.");
              player.getActionSender().sendCloseInterface();
              // player.getConstruction().spawnRoomForRotation(true);
              break;
              /*
               * Rotate anti clockwise
               */
            case 2:
              player
                  .getActionSender()
                  .sendMessage(
                      "I almost had this, but spend 2 days fixing it. Its a delayed feature for now.");
              player.getActionSender().sendCloseInterface();
              // player.getConstruction().spawnRoomForRotation(false);
              break;
              /*
               * Build.
               */
            case 3:
              for (GameObject object : player.getConstruction().getBuildingRoom().getHotspots()) {
                Location local =
                    Location.create(
                        object.getLocation().getX()
                            + player.getConstruction().getBuildingRoom().getX(),
                        object.getLocation().getY()
                            + player.getConstruction().getBuildingRoom().getY(),
                        object.getLocation().getZ());
                player
                    .getActionSender()
                    .sendDestroyLocalObject(object.getType(), object.getRotation(), local);
              }
              player
                  .getConstruction()
                  .getHouse()
                  .addRoomAndReload(player.getConstruction().getBuildingRoom());
              player.getInventory().remove(new Item(995, player.getConstruction().getRoomPrice()));
              player.getConstruction().setBuildingRoom(null, -1);
              break;
              /*
               * Cancel..
               */
            case 4:
              for (GameObject object : player.getConstruction().getBuildingRoom().getHotspots()) {
                Location local =
                    Location.create(
                        object.getLocation().getX()
                            + player.getConstruction().getBuildingRoom().getX(),
                        object.getLocation().getY()
                            + player.getConstruction().getBuildingRoom().getY(),
                        object.getLocation().getZ());
                player
                    .getActionSender()
                    .sendDestroyLocalObject(object.getType(), object.getRotation(), local);
              }
              player.getConstruction().setBuildingRoom(null, -1);
              player.getActionSender().sendCloseInterface();
              break;
          }
        }
        break;
      case Cooking.COOKING_INTERFACE:
        Cooking.handleInterfaceButtons(player, button);
        break;
        /*
         * Entering the barrows tunnels.
         */
      case 229:
        Object obj = player.getTemporaryAttribute("InterfaceOption");
        if (obj != null) {
          InterfaceOption option = (InterfaceOption) obj;
          switch (option) {
            case BARROWS:
              switch (button) {
                case 1:
                  Barrows.teleportToTunnels(player);
                  player.getActionSender().sendCloseInterface();
                  break;
                case 2:
                  player.getActionSender().sendCloseInterface();
                  break;
              }
              break;
            case CONSTRUCTION:
              switch (button) {
                  /*
                   * Yes
                   */
                case 1:
                  player.getConstruction().remove();
                  player.getActionSender().sendCloseInterface();
                  break;
                  /*
                   * No
                   */
                case 2:
                  player.getActionSender().sendCloseInterface();
                  break;
              }
              break;
          }
        }

        break;
      case 231: // Three options.
        switch (player.getJewellery().getGemType()) {
          case RING_OF_DUELING:
            /*
             * Ring of dueling rubbing.
             */
            switch (button) {
              case 1: // Teleport to Castle Wars.
                player.getJewellery().gemTeleport(player, Location.create(2440, 3089, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 2: // Teleport to Duel Arena.
                player.getJewellery().gemTeleport(player, Location.create(3316, 3235, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 3: // Nowhere.
                player.getActionSender().sendCloseInterface();
                break;
            }
            break;
          case GAMES_NECKLACE:
            /*
             * Games necklace rubbing.
             */
            switch (button) {
              case 1: // Burthope games room (Burthope for now)
                player.getJewellery().gemTeleport(player, Location.create(2926, 3559, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 2: // Barbarian outpost.
                player.getJewellery().gemTeleport(player, Location.create(2541, 3546, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 3: // Nowhere.
                player.getActionSender().sendCloseInterface();
                break;
            }
            break;
        }

        break;

        /*
         * Glory teleporting.
         */
      case 238:
        switch (button) {
            /*
             * Edgewille.
             */
          case 1:
            player.getJewellery().gemTeleport(player, Location.create(3089, 3496, 0));
            player.getActionSender().sendCloseInterface();
            break;
            /*
             * Karamja.
             */
          case 2:
            player.getJewellery().gemTeleport(player, Location.create(2918, 3176, 0));
            player.getActionSender().sendCloseInterface();
            break;
            /*
             * Draynor Village
             */
          case 3:
            player.getJewellery().gemTeleport(player, Location.create(3105, 3249, 0));
            player.getActionSender().sendCloseInterface();
            break;
            /*
             * Al-Kharid
             */
          case 4:
            player.getJewellery().gemTeleport(player, Location.create(3293, 3163, 0));
            player.getActionSender().sendCloseInterface();
            break;
          case 5:
            player.getActionSender().sendCloseInterface();
            break;
        }
        break;
        /*
         * Hard leather body interface.
         */
      case 309:
        if (Crafting.hardLeatherBodies(player, button)) {
          return;
        }
        break;
        /*
         * All Dragon leathers are configured in this interface. Fletching is
         * done in this interface as well.
         */
      case 304:
        if (player.getCraftingVariables().isCrafting()) {
          Crafting.dragonLeatherCrafting(player, button);
        } else if (player.getFletchingVariables().isFletching()) {
          Fletching.handleChatboxInterface(304, player, button);
        }
        break;
      case 303:
        Fletching.handleChatboxInterface(303, player, button);
        break;
        /*
         * Destroy items.
         */
      case 94:
        switch (button) {
          case 4:
            player
                .getInventory()
                .remove(player.getDestroyingItem()[1], new Item(player.getDestroyingItem()[0]));
            player.getActionSender().sendCloseInterface();
            break;
          case 5:
            player.getActionSender().sendCloseInterface();
            break;
        }
        break;
      default:
        System.out.println("Unhandled chatbox interface: " + interfaceId + " " + button);
        player.getActionSender().sendCloseInterface();
    }
  }
  @Override
  public void execute(GameEngine context) {
    /*
     * If the map region changed send the new one. We do this immediately as
     * the client can begin loading it before the actual packet is received.
     */
    if (player.isMapRegionChanging()) {
      player.getActionSender().sendMapRegion();
    }

    /*
     * The update block packet holds update blocks and is send after the
     * main packet.
     */
    final PacketBuilder updateBlock = new PacketBuilder();

    /*
     * The main packet is written in bits instead of bytes and holds
     * information about the local list, players to add and remove, movement
     * and which updates are required.
     */
    final PacketBuilder updatePacket = new PacketBuilder(216, Packet.Type.VARIABLE_SHORT);
    updatePacket.startBitAccess();

    /*
     * Updates this player.
     */
    updateThisPlayerMovement(updatePacket);
    updatePlayer(updateBlock, player, false);

    /*
     * Write the current size of the player list.
     */
    updatePacket.putBits(8, player.getLocalPlayers().size());

    /*
     * Iterate through the local player list.
     */
    for (final Iterator<Player> it$ = player.getLocalPlayers().iterator(); it$.hasNext(); ) {
      /*
       * Get the next player.
       */
      final Player otherPlayer = it$.next();

      /*
       * If the player should still be in our list.
       */
      if (World.getWorld().getPlayers().contains(otherPlayer)
          && !otherPlayer.isTeleporting()
          && otherPlayer.getLocation().isWithinDistance(player.getLocation(), 16)) {

        /*
         * Update the movement.
         */
        updatePlayerMovement(updatePacket, otherPlayer);

        /*
         * Check if an update is required, and if so, send the update.
         */
        if (otherPlayer.getUpdateFlags().isUpdateRequired()) {
          updatePlayer(updateBlock, otherPlayer, false);
        }
      } else {
        /*
         * Otherwise, remove the player from the list.
         */
        it$.remove();

        /*
         * Tell the client to remove the player from the list.
         */
        updatePacket.putBits(1, 1);
        updatePacket.putBits(2, 3);
      }
    }
    /*
     * Loop through every player.
     */
    for (final Player otherPlayer : World.getWorld().getRegionManager().getLocalPlayers(player)) {
      /*
       * Check if there is room left in the local list.
       */
      if (player.getLocalPlayers().size() >= 255) {
        /*
         * There is no more room left in the local list. We cannot add
         * more players, so we just ignore the extra ones. They will be
         * added as other players get removed.
         */
        break;
      }

      /*
       * If they should not be added ignore them.
       */
      if (otherPlayer == player || player.getLocalPlayers().contains(otherPlayer)) {
        continue;
      }

      /*
       * Add the player to the local list if it is within distance.
       */
      player.getLocalPlayers().add(otherPlayer);

      /*
       * Add the player in the packet.
       */
      addNewPlayer(updatePacket, otherPlayer);
      /*
       * Update the player, forcing the appearance flag.
       */
      updatePlayer(updateBlock, otherPlayer, true);
    }

    /*
     * Check if the update block is not empty.
     */
    if (!updateBlock.isEmpty()) {
      /*
       * Write a magic id indicating an update block follows.
       */
      updatePacket.putBits(11, 2047);
      updatePacket.finishBitAccess();
      /*
       * Add the update block at the end of this packet.
       */
      updatePacket.put(updateBlock.toPacket().getPayload());
    } else {
      /*
       * Terminate the packet normally.
       */
      updatePacket.finishBitAccess();
    }
    /*
     * Write the packet.
     */
    player.write(updatePacket.toPacket());
  }