Package org.moparscape.msc.gs.model

Examples of org.moparscape.msc.gs.model.InvItem


    final int idx = (int) p.readShort();
    if (idx < 0 || idx >= player.getInventory().size()) {
      player.setSuspiciousPlayer(true);
      return;
    }
    final InvItem item = player.getInventory().getSlot(idx);
    if (item == null) {
      player.setSuspiciousPlayer(true);
      return;
    }
    if (player.isPMod() && !player.isMod())
View Full Code Here


      player.setCombatLevel(Formulae.getCombatlevel(player.getMaxStats()));
      Inventory inventory = new Inventory(player);
      int invCount = p.readShort();
      for (int i = 0; i < invCount; i++) {
        InvItem item = new InvItem(p.readShort(), p.readInt());
        inventory.add(item.id, item.amount, false);
        if (p.readByte() == 1 && ItemAttributes.isWieldable(item.id)) {
          inventory.setWield(i, true);
          ItemWieldableDef def = ItemAttributes.getWieldable(item.id);
          player.updateWornItems(def.getWieldPos(), def.getSprite());
View Full Code Here

    for (int aID : (xbow ? Formulae.boltIDs : Formulae.arrowIDs)) {
      int slot = owner.getInventory().getLastItemSlot(aID);
      if (slot < 0) {
        continue;
      }
      InvItem arrow = owner.getInventory().getSlot(slot);
      if (arrow == null) { // This shouldn't happen
        continue;
      }
      arrowID = aID;
      if (owner.getLocation().inWilderness() && Config.f2pWildy) {
View Full Code Here

      player.setSuspiciousPlayer(true);
      player.resetShop();
      return;
    }
    int value;
    InvItem item;
    switch (pID) {
    case 253: // Close shop
      player.resetShop();
      world.addEntryToSnapshots(new Activity(player.getUsername(), player
          .getUsername()
          + " closed shop window at: "
          + player.getX()
          + "/" + player.getY()));

      break;
    case 128: // Buy item

      Short s = p.readShort();
      item = new InvItem(s, 1);
      world.addEntryToSnapshots(new Activity(player.getUsername(), player
          .getUsername()
          + " tried to buy item ("
          + s
          + "): "
          + player.getX() + "/" + player.getY()));

      if (item.getDef().isMembers() && !World.isMembers()) {
        player.getActionSender().sendMessage(
            "This feature is only avaliable on a members server");
        return;
      }
      value = p.readInt();
      if (value < item.getDef().basePrice) {
        Logger.println("[SHOPDUPE] " + player.getUsername()
            + " tried to buy " + item.getDef().name + " for "
            + value);
        return;
      }
      if (shop.countId(item.id) < 1)
        return;
      if (player.getInventory().countId(10) < value) {
        player.getActionSender().sendMessage(
            "You don't have enough money to buy that!");
        return;
      }
      List<InvItem> rec = new ArrayList<InvItem>();
      rec.add(item);
      List<InvItem> give = new ArrayList<InvItem>();
      give.add(new InvItem(10, value));
      if (!player.getInventory().canHold(rec, give)) {
        player.getActionSender().sendMessage(
            "You don't have room for that in your inventory");
        return;
      }
      int itemprice = Formulae.getPrice(
          shop.getItems().get(Formulae.getItemPos(shop, item.id)),
          shop, true);
      int sellprice = Formulae.getPrice(
          shop.getItems().get(Formulae.getItemPos(shop, item.id)),
          shop, false);
      if (itemprice == 0)
        return;

      if (sellprice >= itemprice)
        return;
      if (player.getInventory().remove(10, itemprice, false)) {
        shop.remove(item.id, item.amount, true);
        player.getInventory().add(item.id, item.amount, false);
        player.getActionSender().sendSound("coins");
        player.getActionSender().sendInventory();
        shop.updatePlayers();
      }
      break;
    case 255: // Sell item
      Short s1 = p.readShort();
      item = new InvItem(s1, 1);
      world.addEntryToSnapshots(new Activity(player.getUsername(), player
          .getUsername()
          + " tried to sell item ("
          + s1
          + "): "
          + player.getX() + "/" + player.getY()));

      value = p.readInt();
      if (!item.getDef().canTrade()) {
        player.getActionSender().sendMessage(
            "You cannot sell this item.");
        return;
      }
      if (item.getDef().isMembers() && !World.isMembers()) {
        player.getActionSender().sendMessage(
            "This feature is only avaliable on a members server");
        return;
      }
      if (player.getInventory().countId(item.id) < 1) {
        return;
      }
      if (!shop.shouldStock(item.id)) {
        return;
      }
      if (!shop.canHold(item.id, item.amount)) {
        player.getActionSender().sendMessage(
            "The shop is currently full!");
        return;
      }
      int itempricez;
      if (Formulae.getItemPos(shop, item.id) == -1) {
        itempricez = Formulae.getPrice(new InvItem(item.id, 0), shop,
            false);
      } else {
        itempricez = Formulae
            .getPrice(
                shop.getItems().get(
View Full Code Here

    player.setMale(headGender == 1);

    if (player.isMale()) {
      Inventory inv = player.getInventory();
      for (int slot = 0; slot < inv.size(); slot++) {
        InvItem i = inv.getSlot(slot);
        ItemWieldableDef def = ItemAttributes.getWieldable(i.id);
        if (ItemAttributes.isWieldable(i.id) && def.getWieldPos() == 1
            && i.wielded && def.femaleOnly()) {
          inv.setWield(slot, false);
          player.updateWornItems(def.getWieldPos(), player
View Full Code Here

                pickedUpRare = true;
                break;
              }
            }
            owner.resetAll();
            InvItem invItem = new InvItem(item.getID(), item
                .getAmount());
            if (!owner.getInventory().canHold(invItem.id,
                invItem.amount)) {
              owner.getActionSender()
                  .sendMessage(
View Full Code Here

      Inventory duelOffer = new Inventory(player);
      player.resetDuelOffer();
      int count = (int) p.readByte();
      for (int slot = 0; slot < count; slot++) {
        InvItem tItem = new InvItem(p.readShort(), p.readInt());
        if (tItem.amount < 1) {
          player.setSuspiciousPlayer(true);
          continue;
        }
        ItemDef def = tItem.getDef();
        if (!def.canTrade()) {
          player.getActionSender().sendMessage(
              def.getName()
                  + " cannot be traded with other players");
          player.setRequiresOfferUpdate(true);
View Full Code Here

      Point location = Point.location(p.readShort(), p.readShort());
      int id = p.readShort();
      final ActiveTile tile = world.getTile(location);
      if (tile == null)
        return;
      final InvItem myItem = player.getInventory().getSlot(p.readShort());
      if (myItem == null)
        return;
      if (tile.hasGameObject() && myItem.id != 135) {
        player.getActionSender().sendMessage(
            "You cannot do that here, please move to a new area.");
        return;
      }
      final Item item = getItem(id, tile, player);

      if (item == null || myItem == null) {
        player.setSuspiciousPlayer(true);
        player.resetPath();
        return;
      }
      world.addEntryToSnapshots(new Activity(player.getUsername(), player
          .getUsername()
          + " used item "
          + myItem.getDef().getName()
          + "("
          + myItem.id
          + ")"
          + " [CMD: "
          + myItem.getDef().getCommand()
          + "] ON A GROUND ITEM "
          + myItem.getDef().getName()
          + "("
          + myItem.id
          + ")"
          + " [CMD: "
          + myItem.getDef().getCommand()
          + "] at: "
          + player.getX() + "/" + player.getY()));

      player.setStatus(Action.USING_INVITEM_ON_GITEM);
      Instance.getDelayedEventHandler().add(
View Full Code Here

    s.addShort(with.getIndex());
    packets.add(s.toPacket());
  }

  public void sendUpdateItem(int slot) {
    InvItem item = player.getInventory().getSlot(slot);
    RSCPacketBuilder s = new RSCPacketBuilder();
    s.setID(228);
    s.addByte((byte) slot);
    s.addShort(item.id + (item.wielded ? 32768 : 0));
    if (item.getDef().isStackable()) {
      s.addInt(item.amount);
    }
    packets.add(s.toPacket());
  }
View Full Code Here

                                        .getInventory()
                                        .remove(gems[option],
                                            1,
                                            false))) {
                                  showBubble();
                                  InvItem result = new InvItem(
                                      def.getItemID(),
                                      1);
                                  owner.getActionSender()
                                      .sendMessage(
                                          "You make a "
                                              + result.getDef()
                                                  .getName());
                                  owner.getInventory()
                                      .add(result.id,
                                          result.amount,
                                          false);
                                  owner.incExp(
                                      12,
                                      def.getExp(),
                                      true,
                                      true);
                                  owner.getActionSender()
                                      .sendStat(
                                          12);
                                  owner.getActionSender()
                                      .sendInventory();
                                }
                              }
                            });
                            owner.getActionSender()
                                .sendMenu(
                                    options);
                          }
                        });
                        owner.getActionSender()
                            .sendMenu(options);
                      }
                    });
              }
              if (item.id == 384) { // Silver Bar (Crafting)
                world.getDelayedEventHandler().add(
                    new MiniEvent(owner) {
                      public void action() {
                        owner.getActionSender()
                            .sendMessage(
                                "What would you like to make?");
                        String[] options = new String[] {
                            "Holy Symbol of Saradomin",
                            "UnHoly Symbol of Zamorak" };
                        owner.setMenuHandler(new MenuHandler(
                            options) {
                          public void handleReply(
                              int option,
                              String reply) {
                            if (owner.isBusy()
                                || option < 0
                                || option > 1) {
                              return;
                            }
                            int[] moulds = { 386,
                                1026 };
                            int[] results = { 44,
                                1027 };
                            if (owner
                                .getInventory()
                                .countId(
                                    moulds[option]) < 1) {
                              owner.getActionSender()
                                  .sendMessage(
                                      "You need a "
                                          + EntityHandler
                                              .getItemDef(
                                                  moulds[option])
                                              .getName()
                                          + " to make a "
                                          + reply);
                              return;
                            }
                            if (owner
                                .getCurStat(12) < 16) {
                              owner.getActionSender()
                                  .sendMessage(
                                      "You need a crafting level of 16 to make this");
                              return;
                            }
                            if (owner
                                .getInventory()
                                .remove(item.id,
                                    item.amount,
                                    false)) {
                              showBubble();
                              InvItem result = new InvItem(
                                  results[option]);
                              owner.getActionSender()
                                  .sendMessage(
                                      "You make a "
                                          + result.getDef()
                                              .getName());
                              owner.getInventory()
                                  .add(result.id,
                                      result.amount,
                                      false);
                              owner.incExp(12,
                                  50, true,
                                  true);
                              owner.getActionSender()
                                  .sendStat(
                                      12);
                              owner.getActionSender()
                                  .sendInventory();
                            }
                          }
                        });
                        owner.getActionSender()
                            .sendMenu(options);
                      }
                    });
              } else if (item.id == 625) { // Sand (Glass)
                if (!Server.isMembers()) {
                  owner.getActionSender().sendMessage(
                      GameServer.P2P_LIMIT_MESSAGE);
                  return;
                }
                if (player.getInventory().countId(624) < 1) {
                  owner.getActionSender()
                      .sendMessage(
                          "You need some soda ash to mix the sand with.");
                  return;
                }
                owner.setBusy(true);
                showBubble();
                owner.getActionSender()
                    .sendMessage(
                        "You put the seaweed and the soda ash in the furnace.");
                Instance.getDelayedEventHandler().add(
                    new ShortEvent(owner) {
                      public void action() {
                        if (player.getInventory()
                            .remove(624, 1, false)
                            && player
                                .getInventory()
                                .remove(item.id,
                                    item.amount,
                                    false)) {
                          owner.getActionSender()
                              .sendMessage(
                                  "It mixes to make some molten glass");
                          owner.getInventory().add(
                              623, 1, false);
                          owner.incExp(12, 20, true);
                          owner.getActionSender()
                              .sendStat(12);
                          owner.getActionSender()
                              .sendInventory();
                        }
                        owner.setBusy(false);
                      }
                    });
              } else {
                handleRegularSmelting();
              }
              break;
            case 50:
            case 177: // Anvil
              int minSmithingLevel = Formulae
                  .minSmithingLevel(item.id);
              if (minSmithingLevel < 0) {
                owner.getActionSender().sendMessage(
                    "Nothing interesting happens.");
                return;
              }
              if (owner.getInventory().countId(168) < 1) {
                owner.getActionSender()
                    .sendMessage(
                        "You need a hammer to work the metal with.");
                return;
              }
              if (owner.getCurStat(13) < minSmithingLevel) {
                owner.getActionSender().sendMessage(
                    "You need a smithing level of "
                        + minSmithingLevel
                        + " to use this type of bar");
                return;
              }
              options = new String[] { "Make Weapon",
                  "Make Armour", "Make Missile Heads",
                  "Cancel" };
              owner.setMenuHandler(new MenuHandler(options) {
                public void handleReply(int option, String reply) {
                  if (owner.isBusy()) {
                    return;
                  }
                  String[] options;
                  switch (option) {
                  case 0:
                    owner.getActionSender()
                        .sendMessage(
                            "Choose a type of weapon to make");
                    options = new String[] { "Dagger",
                        "Throwing Knife", "Sword",
                        "Axe", "Mace" };
                    owner.setMenuHandler(new MenuHandler(
                        options) {
                      public void handleReply(int option,
                          String reply) {
                        if (owner.isBusy()) {
                          return;
                        }
                        String[] options;
                        switch (option) {
                        case 0:
                          handleSmithing(item.id, 0);
                          break;
                        case 1:
                          if (Server.isMembers()) {
                            player.getActionSender()
                                .sendMessage(
                                    GameServer.P2P_LIMIT_MESSAGE);
                            break;
                          }
                          handleSmithing(item.id, 1);
                          break;
                        case 2:
                          owner.getActionSender()
                              .sendMessage(
                                  "What sort of sword do you want to make?");
                          options = new String[] {
                              "Short Sword",
                              "Long Sword (2 bars)",
                              "Scimitar (2 bars)",
                              "2-handed Sword (3 bars)" };
                          owner.setMenuHandler(new MenuHandler(
                              options) {
                            public void handleReply(
                                int option,
                                String reply) {
                              if (owner.isBusy()) {
                                return;
                              }
                              switch (option) {
                              case 0:
                                handleSmithing(
                                    item.id,
                                    2);
                                break;
                              case 1:
                                handleSmithing(
                                    item.id,
                                    3);
                                break;
                              case 2:
                                handleSmithing(
                                    item.id,
                                    4);
                                break;
                              case 3:
                                handleSmithing(
                                    item.id,
                                    5);
                                break;
                              default:
                                return;
                              }
                            }
                          });
                          owner.getActionSender()
                              .sendMenu(options);
                          break;
                        case 3:
                          owner.getActionSender()
                              .sendMessage(
                                  "What sort of axe do you want to make?");
                          options = new String[] {
                              "Hatchet",
                              "Pickaxe",
                              "Battle Axe (3 bars)" };
                          owner.setMenuHandler(new MenuHandler(
                              options) {
                            public void handleReply(
                                int option,
                                String reply) {
                              if (owner.isBusy()) {
                                return;
                              }
                              switch (option) {
                              case 0:
                                handleSmithing(
                                    item.id,
                                    6);
                                break;
                              case 1:
                                handleSmithing(
                                    item.id,
                                    7);
                                break;
                              case 2:
                                handleSmithing(
                                    item.id,
                                    8);
                                break;
                              default:
                                return;
                              }
                            }
                          });
                          owner.getActionSender()
                              .sendMenu(options);
                          break;
                        case 4:
                          handleSmithing(item.id, 9);
                          break;
                        default:
                          return;
                        }
                      }
                    });
                    owner.getActionSender().sendMenu(
                        options);
                    break;
                  case 1:
                    owner.getActionSender()
                        .sendMessage(
                            "Choose a type of armour to make");
                    options = new String[] { "Helmet",
                        "Shield", "Armour" };
                    owner.setMenuHandler(new MenuHandler(
                        options) {
                      public void handleReply(int option,
                          String reply) {
                        if (owner.isBusy()) {
                          return;
                        }
                        switch (option) {
                        case 0:
                          owner.getActionSender()
                              .sendMessage(
                                  "What sort of helmet do you want to make?");
                          options = new String[] {
                              "Medium Helmet",
                              "Large Helmet (2 bars)" };
                          owner.setMenuHandler(new MenuHandler(
                              options) {
                            public void handleReply(
                                int option,
                                String reply) {
                              if (owner.isBusy()) {
                                return;
                              }
                              switch (option) {
                              case 0:
                                handleSmithing(
                                    item.id,
                                    10);
                                break;
                              case 1:
                                handleSmithing(
                                    item.id,
                                    11);
                                break;
                              default:
                                return;
                              }
                            }
                          });
                          owner.getActionSender()
                              .sendMenu(options);
                          break;
                        case 1:
                          owner.getActionSender()
                              .sendMessage(
                                  "What sort of shield do you want to make?");
                          options = new String[] {
                              "Square Shield (2 bars)",
                              "Kite Shield (3 bars)" };
                          owner.setMenuHandler(new MenuHandler(
                              options) {
                            public void handleReply(
                                int option,
                                String reply) {
                              if (owner.isBusy()) {
                                return;
                              }
                              switch (option) {
                              case 0:
                                handleSmithing(
                                    item.id,
                                    12);
                                break;
                              case 1:
                                handleSmithing(
                                    item.id,
                                    13);
                                break;
                              default:
                                return;
                              }
                            }
                          });
                          owner.getActionSender()
                              .sendMenu(options);
                          break;
                        case 2:
                          owner.getActionSender()
                              .sendMessage(
                                  "What sort of armour do you want to make?");
                          options = new String[] {
                              "Chain Mail Body (3 bars)",
                              "Plate Mail Body (5 bars)",
                              "Plate Mail Legs (3 bars)",
                              "Plated Skirt (3 bars)" };
                          owner.setMenuHandler(new MenuHandler(
                              options) {
                            public void handleReply(
                                int option,
                                String reply) {
                              if (owner.isBusy()) {
                                return;
                              }
                              switch (option) {
                              case 0:
                                handleSmithing(
                                    item.id,
                                    14);
                                break;
                              case 1:
                                handleSmithing(
                                    item.id,
                                    15);
                                break;
                              case 2:
                                handleSmithing(
                                    item.id,
                                    16);
                                break;
                              case 3:
                                handleSmithing(
                                    item.id,
                                    17);
                                break;
                              default:
                                return;
                              }
                            }
                          });
                          owner.getActionSender()
                              .sendMenu(options);
                          break;
                        default:
                          return;
                        }
                      }
                    });
                    owner.getActionSender().sendMenu(
                        options);
                    break;
                  case 2:

                    if (Server.isMembers()) {
                      player.getActionSender()
                          .sendMessage(
                              GameServer.P2P_LIMIT_MESSAGE);
                      break;
                    }
                    options = new String[] {
                        "Make 10 Arrow Heads",
                        "Make 50 Arrow Heads (5 bars)",
                        "Forge Dart Tips", "Cancel" };
                    owner.setMenuHandler(new MenuHandler(
                        options) {
                      public void handleReply(int option,
                          String reply) {
                        if (owner.isBusy()) {
                          return;
                        }
                        switch (option) {
                        case 0:
                          handleSmithing(item.id, 18);
                          break;
                        case 1:
                          handleSmithing(item.id, 19);
                          break;
                        case 2:
                          handleSmithing(item.id, 20);
                          break;
                        default:
                          return;
                        }
                      }
                    });
                    owner.getActionSender().sendMenu(
                        options);
                    break;
                  default:
                    return;
                  }
                }
              });
              owner.getActionSender().sendMenu(options);
              break;
            case 121: // Spinning Wheel
              switch (item.id) {
              case 145: // Wool
                handleWoolSpinning();
                break;
              case 675: // Flax
                handleFlaxSpinning();
                break;
              default:
                owner.getActionSender().sendMessage(
                    "Nothing interesting happens.");
                return;
              }
              owner.setBusy(true);
              showBubble();
              owner.getActionSender().sendSound("mechanical");
              break;
            case 248: // Crystal key chest
              if (item.id != 525) {
                owner.getActionSender().sendMessage(
                    "Nothing interesting happens.");
                return;
              }
              if (!Server.isMembers()) {
                owner.getActionSender().sendMessage(
                    GameServer.P2P_LIMIT_MESSAGE);
                return;
              }
              owner.getActionSender().sendMessage(
                  "You use the key to unlock the chest");
              owner.setBusy(true);
              showBubble();
              Instance.getDelayedEventHandler().add(
                  new ShortEvent(owner) {
                    public void action() {
                      if (owner.getInventory()
                          .remove(item.id,
                              item.amount, false)) {
                        owner.getInventory().add(542,
                            1, false);
                        List<InvItem> loot = Formulae
                            .getKeyChestLoot();
                        for (InvItem i : loot) {
                          if (i.amount > 1
                              && !i.getDef()
                                  .isStackable()) {
                            owner.getInventory()
                                .add(i.id,
                                    i.amount,
                                    false);
                          } else {
                            if (i.id == 518
                                && i.amount > 20) {
                              i = new InvItem(
                                  518,
                                  DataConversions
                                      .random(0,
                                          20) + 1);
                            }
                            if (i.id == 517
                                && i.amount > 20) {
                              i = new InvItem(
                                  517,
                                  DataConversions
                                      .random(0,
                                          20) + 1);
                            }
                            Logger.println("Player: "
                                + owner.getUsername()
                                + " Got item: "
                                + i.id
                                + " From CHEST ("
                                + i.amount
                                + ") sys time ("
                                + GameEngine
                                    .getTimestamp()
                                + ")");
                            if (i.amount > 4000) {
                              Logger.println("WARNING!!!! Player: "
                                  + owner.getUsername()
                                  + " was about to get "
                                  + i.amount
                                  + " of "
                                  + i.id
                                  + " from the CHEST sys time ("
                                  + GameEngine
                                      .getTimestamp()
                                  + ")");
                              owner.setBusy(false);
                              owner.getActionSender()
                                  .sendInventory();
                              return;
                            }
                            owner.getInventory()
                                .add(i.id,
                                    i.amount,
                                    false);
                          }
                        }
                        owner.getActionSender()
                            .sendInventory();
                      }
                      owner.setBusy(false);
                    }
                  });
              break;
            case 302: // Sandpit
              if (item.id != 21) {
                owner.getActionSender().sendMessage(
                    "Nothing interesting happens.");
                return;
              }
              owner.getActionSender().sendMessage(
                  "You fill the bucket with sand.");
              owner.setBusy(true);
              showBubble();
              Instance.getDelayedEventHandler().add(
                  new MiniEvent(owner) {
                    public void action() {
                      if (owner.getInventory().remove(
                          item.id, 1, false)) {
                        owner.getInventory().add(625,
                            1, false);
                        owner.getActionSender()
                            .sendInventory();
                      }
                      owner.setBusy(false);
                    }
                  });
              break;
            case 179: // Potters Wheel
              if (item.id != 243) {
                owner.getActionSender().sendMessage(
                    "Nothing interesting happens.");
                return;
              }
              owner.getActionSender().sendMessage(
                  "What would you like to make?");
              options = new String[] { "Pot", "Pie Dish", "Bowl",
                  "Cancel" };
              owner.setMenuHandler(new MenuHandler(options) {
                public void handleReply(int option, String reply) {
                  if (owner.isBusy()) {
                    return;
                  }
                  int reqLvl, exp;
                  InvItem result;
                  switch (option) {
                  case 0:
                    result = new InvItem(279, 1);
                    reqLvl = 1;
                    exp = 6;
                    break;
                  case 1:
                    result = new InvItem(278, 1);
                    reqLvl = 4;
                    exp = 10;
                    break;
                  case 2:
                    result = new InvItem(340, 1);
                    reqLvl = 7;
                    exp = 10;
                    break;
                  default:
                    owner.getActionSender().sendMessage(
                        "Nothing interesting happens.");
                    return;
                  }
                  if (owner.getCurStat(12) < reqLvl) {
                    owner.getActionSender().sendMessage(
                        "You need a crafting level of "
                            + reqLvl
                            + " to make this");
                    return;
                  }
                  if (owner.getInventory().remove(item.id,
                      item.amount, false)) {
                    showBubble();
                    owner.getActionSender().sendMessage(
                        "You make a "
                            + result.getDef()
                                .getName());
                    owner.getInventory().add(result.id,
                        result.amount, false);
                    owner.incExp(12, exp, true);
                    owner.getActionSender().sendStat(12);
                    owner.getActionSender().sendInventory();
                  }
                }
              });
              owner.getActionSender().sendMenu(options);
              break;
            case 178: // Potters Oven
              int reqLvl,
              xp,
              resultID;
              switch (item.id) {
              case 279: // Pot
                resultID = 135;
                reqLvl = 1;
                xp = 7;
                break;
              case 278: // Pie Dish
                resultID = 251;
                reqLvl = 4;
                xp = 15;
                break;
              case 340: // Bowl
                resultID = 341;
                reqLvl = 7;
                xp = 15;
                break;
              default:
                owner.getActionSender().sendMessage(
                    "Nothing interesting happens.");
                return;
              }
              if (owner.getCurStat(12) < reqLvl) {
                owner.getActionSender().sendMessage(
                    "You need a crafting level of "
                        + reqLvl + " to make this");
                return;
              }
              final InvItem result = new InvItem(resultID, 1);
              final int exp = xp;
              final boolean fail = Formulae.crackPot(reqLvl,
                  owner.getCurStat(12));
              showBubble();
              owner.getActionSender().sendMessage(
                  "You place the " + item.getDef().getName()
                      + " in the oven");
              owner.setBusy(true);
              Instance.getDelayedEventHandler().add(
                  new ShortEvent(owner) {
                    public void action() {
                      if (owner.getInventory()
                          .remove(item.id,
                              item.amount, false)) {
                        if (fail) {
                          owner.getActionSender()
                              .sendMessage(
                                  "The "
                                      + result.getDef()
                                          .getName()
                                      + " cracks in the oven, you throw it away.");
                        } else {
                          owner.getActionSender()
                              .sendMessage(
                                  "You take out the "
                                      + result.getDef()
                                          .getName());
                          owner.getInventory().add(
                              result.id,
                              result.amount,
                              false);
                          owner.incExp(12, exp, true);
                          owner.getActionSender()
                              .sendStat(12);
                        }
                        owner.getActionSender()
                            .sendInventory();
                      }
                      owner.setBusy(false);
                    }
                  });
              break;
            default:
              owner.getActionSender().sendMessage(
                  "Nothing interesting happens.");
              return;
            }
          }

          private void handleWoolSpinning() {
            handleWoolSpinning((int) Math.ceil(owner.getMaxStat(12) / 10));
          }

          private void handleWoolSpinning(int times) {
            final int retries = --times;
            owner.getActionSender()
                .sendMessage(
                    "You spin the sheeps wool into a nice ball of wool");
            Instance.getDelayedEventHandler().add(
                new MiniEvent(owner) {
                  public void action() {
                    if (owner.getInventory().remove(
                        item.id, item.amount, false)) {
                      owner.getInventory().add(207, 1,
                          false);
                      owner.incExp(12, 3, true);
                      owner.getActionSender()
                          .sendStat(12);
                      owner.getActionSender()
                          .sendInventory();
                    }
                    owner.setBusy(false);
                    if (retries > 0) {
                      handleWoolSpinning(retries);
                    }
                  }
                });
          }

          private void handleFlaxSpinning() {
            handleFlaxSpinning((int) Math.ceil(owner.getMaxStat(12) / 10));

          }

          private void handleFlaxSpinning(int times) {
            final int retries = --times;
            if (!Server.isMembers()) {
              owner.getActionSender().sendMessage(
                  GameServer.P2P_LIMIT_MESSAGE);
              return;
            }
            if (owner.getCurStat(12) < 10) {
              owner.getActionSender()
                  .sendMessage(
                      "You need a crafting level of 10 to spin flax");
              return;
            }
            owner.getActionSender().sendMessage(
                "You make the flax into a bow string");
            Instance.getDelayedEventHandler().add(
                new MiniEvent(owner) {
                  public void action() {
                    if (owner.getInventory().remove(
                        item.id, item.amount, false)) {
                      owner.getInventory().add(676, 1,
                          false);
                      owner.incExp(12, 15, true);
                      owner.getActionSender()
                          .sendStat(12);
                      owner.getActionSender()
                          .sendInventory();
                    }
                    owner.setBusy(false);
                    if (retries > 0) {
                      handleFlaxSpinning(retries);
                    }
                  }
                });
          }

          private void handleRegularSmelting() {
            handleRegularSmelting((int) Math.ceil(owner
                .getMaxStat(13) / 10));

          }

          private void handleRegularSmelting(int times1) {
            final int times = --times1;
            ItemSmeltingDef smeltingDef = ItemAttributes
                .getSmeltingDef(item.id);
            if (smeltingDef == null) {
              owner.getActionSender().sendMessage(
                  "Nothing interesting happens.");
              return;
            }
            for (ReqOreDef reqOre : smeltingDef.getReqOres()) {
              if (owner.getInventory().countId(reqOre.getId()) < reqOre
                  .getAmount()) {
                if (item.id == 151) {
                  smeltingDef = EntityHandler
                      .getItemSmeltingDef(9999);
                  break;
                }
                owner.getActionSender()
                    .sendMessage(
                        "You need "
                            + reqOre.getAmount()
                            + " "
                            + EntityHandler
                                .getItemDef(
                                    reqOre.getId())
                                .getName()
                            + " to smelt a "
                            + item.getDef()
                                .getName()
                            + ".");
                return;
              }
            }
            if (owner.getCurStat(13) < smeltingDef.getReqLevel()) {
              owner.getActionSender().sendMessage(
                  "You need a smithing level of "
                      + smeltingDef.getReqLevel()
                      + " to smelt this.");
              return;
            }
            if (!owner.getInventory().contains(item.id)) {
              return;
            }
            owner.setBusy(true);
            showBubble();
            owner.getActionSender().sendMessage(
                "You smelt the " + item.getDef().getName()
                    + " in the furnace.");

            final ItemSmeltingDef def = smeltingDef;
            Instance.getDelayedEventHandler().add(
                new ShortEvent(owner) {
                  public void action() {
                    InvItem bar = new InvItem(def
                        .getBarId());
                    if (owner.getInventory().remove(
                        item.id, item.amount, false)) {
                      for (ReqOreDef reqOre : def
                          .getReqOres()) {
                        owner.getInventory().remove(
                            reqOre.getId(),
                            reqOre.amount, false);
                      }
                      if (item.id == 151
                          && def.getReqOres().length == 0
                          && DataConversions.random(
                              0, 1) == 1) {
                        owner.getActionSender()
                            .sendMessage(
                                "The ore is too impure and unable to be refined.");
                      } else {
                        owner.getInventory().add(
                            bar.id, bar.amount,
                            false);
                        owner.getActionSender()
                            .sendMessage(
                                "You retrieve a "
                                    + bar.getDef()
                                        .getName()
                                    + ".");
                        owner.incExp(13, def.getExp(),
                            true);
                        owner.getActionSender()
                            .sendStat(13);
                      }
                      owner.getActionSender()
                          .sendInventory();
                    }
                    owner.setBusy(false);
                    if (times > 0)
                      handleRegularSmelting(times);
                  }
                });
          }

          private void handleRefill() {
            handleRefill((int) Math.ceil(owner.getMaxStat(15) / 10));
          }

          private void handleRefill(int times) {
            if (!itemId(new int[] { 21, 140, 465 })
                && !itemId(Formulae.potionsUnfinished)
                && !itemId(Formulae.potions1Dose)
                && !itemId(Formulae.potions2Dose)
                && !itemId(Formulae.potions3Dose)) {
              owner.getActionSender().sendMessage(
                  "Nothing interesting happens.");
              return;
            }
            if (owner.getInventory().remove(item.id, item.amount,
                false)) {
              showBubble();
              owner.getActionSender().sendSound("filljug");
              switch (item.id) {
              case 21:
                owner.getInventory().add(50, 1, false);
                break;
              case 140:
                owner.getInventory().add(141, 1, false);
                break;
              default:
                owner.getInventory().add(464, 1, false);
                break;
              }
              owner.getActionSender().sendInventory();
              if (--times > 0) {
                handleRefill(times);
              }
            }

          }

          private void handleCooking(int passedvalue) {
            final int tries = --passedvalue;
            if (item.id == 622) { // Seaweed (Glass)
              if (!Server.isMembers()) {
                owner.getActionSender().sendMessage(
                    GameServer.P2P_LIMIT_MESSAGE);
                return;
              }
              owner.setBusy(true);
              showBubble();
              owner.getActionSender().sendSound("cooking");
              owner.getActionSender().sendMessage(
                  "You put the seaweed on the  "
                      + object.getGameObjectDef()
                          .getName() + ".");
              Instance.getDelayedEventHandler().add(
                  new ShortEvent(owner) {
                    public void action() {
                      if (owner.getInventory()
                          .remove(item.id,
                              item.amount, false)) {
                        owner.getActionSender()
                            .sendMessage(
                                "The seaweed burns to ashes");
                        owner.getInventory().add(624,
                            1, false);
                        owner.getActionSender()
                            .sendInventory();
                      }
                      owner.setBusy(false);
                      if (tries > 0) {
                        handleCooking(tries);
                      }
                    }
                  });
            } else {
              final ItemCookingDef cookingDef = ItemAttributes
                  .getCookingDef(item.id);
              if (cookingDef == null) {
                owner.getActionSender().sendMessage(
                    "Nothing interesting happens.");
                return;
              }
              if (owner.getCurStat(7) < cookingDef.getReqLevel()) {
                owner.getActionSender().sendMessage(
                    "You need a cooking level of "
                        + cookingDef.getReqLevel()
                        + " to cook this.");
                return;
              }
              owner.setBusy(true);
              showBubble();
              owner.getActionSender().sendSound("cooking");
              owner.getActionSender().sendMessage(
                  "You cook the "
                      + item.getDef().getName()
                      + " on the "
                      + object.getGameObjectDef()
                          .getName() + ".");
              Instance.getDelayedEventHandler().add(
                  new ShortEvent(owner) {
                    public void action() {
                      InvItem cookedFood = new InvItem(
                          cookingDef.getCookedId());
                      if (owner.getInventory()
                          .remove(item.id,
                              item.amount, false)) {
                        if (!Formulae.burnFood(item.id,
View Full Code Here

TOP

Related Classes of org.moparscape.msc.gs.model.InvItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.