Exemplo n.º 1
0
 @Override
 public int countItems(Context context, Community community) throws SQLException {
   int total = 0;
   // add collection counts
   List<Collection> cols = community.getCollections();
   for (Collection col : cols) {
     total += itemService.countItems(context, col);
   }
   // add sub-community counts
   List<Community> comms = community.getSubcommunities();
   for (int j = 0; j < comms.size(); j++) {
     total += countItems(context, comms.get(j));
   }
   return total;
 }
Exemplo n.º 2
0
  public void registerItem(Player player, int itemUniqueId, long price, int itemCount) {
    Map<Integer, BrokerItem> brokerItems = getRaceBrokerItems(player.getCommonData().getRace());

    List<BrokerItem> registeredItems = new ArrayList<BrokerItem>();
    int playerId = player.getObjectId();

    for (BrokerItem item : brokerItems.values()) {
      if (item != null
          && item.getItem() != null
          && !item.isSold()
          && !item.isSettled()
          && playerId == item.getSellerId()) registeredItems.add(item);
    }

    if (registeredItems.size() >= 15) {
      PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300653));
      return;
    }

    Item itemToRegister = player.getInventory().getItemByObjId(itemUniqueId);
    Race playerRace = player.getCommonData().getRace();

    if (itemToRegister == null) return;

    if (!itemToRegister.getItemTemplate().isTradeable()) {
      PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300652));
      return;
    }

    if (itemToRegister.isSoulBound()) return;

    BrokerRace brRace;

    if (playerRace == Race.ASMODIANS) brRace = BrokerRace.ASMODIAN;
    else if (playerRace == Race.ELYOS) brRace = BrokerRace.ELYOS;
    else return;

    double priceRate = player.getPrices().getGlobalPrices(player.getCommonData().getRace()) * .01;
    double taxRate = player.getPrices().getTaxes(player.getCommonData().getRace()) * .01;
    double priceMod = player.getPrices().getGlobalPricesModifier() * .01;
    double priceFactor = 0.02 * priceRate * taxRate * priceMod;
    long registrationCommition =
        (long) (price * priceFactor * (registeredItems.size() >= 10 ? 2 : 1));

    if (registrationCommition < 10) registrationCommition = 10;

    if (player.getInventory().getKinahItem().getItemCount() < registrationCommition) {
      PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300647));
      return;
    }

    if (itemCount < itemToRegister.getItemCount() && itemCount > 0) {
      Item newItem =
          ItemService.newItem(
              itemToRegister.getItemTemplate().getTemplateId(),
              itemCount,
              itemToRegister.getCrafterName(),
              playerId,
              itemToRegister.getTempItemTimeLeft(),
              itemToRegister.getTempTradeTimeLeft());
      player.getInventory().decreaseItemCount(itemToRegister, itemCount);
      PacketSendUtility.sendPacket(player, new SM_UPDATE_ITEM(itemToRegister));
      itemToRegister = newItem;
    } else {
      boolean removeResult = player.getInventory().removeFromBag(itemToRegister, false);
      if (!removeResult) return;
      PacketSendUtility.sendPacket(player, new SM_DELETE_ITEM(itemToRegister.getObjectId()));
    }

    boolean decreaseResult = player.getInventory().decreaseKinah(registrationCommition);
    if (!decreaseResult) return;

    itemToRegister.setItemLocation(126);

    BrokerItem newBrokerItem =
        new BrokerItem(
            player, itemToRegister, price, player.getName(), player.getObjectId(), brRace);

    switch (brRace) {
      case ASMODIAN:
        asmodianBrokerItems.put(newBrokerItem.getItemUniqueId(), newBrokerItem);
        break;

      case ELYOS:
        elyosBrokerItems.put(newBrokerItem.getItemUniqueId(), newBrokerItem);
        break;
    }

    BrokerOpSaveTask bost =
        new BrokerOpSaveTask(
            newBrokerItem,
            itemToRegister,
            player.getInventory().getKinahItem(),
            player.getObjectId());
    saveManager.add(bost);

    BrokerItem[] brokerItem = new BrokerItem[1];
    brokerItem[0] = newBrokerItem;
    PacketSendUtility.sendPacket(
        player, new SM_BROKER_ITEMS(brokerItem, registeredItems.size() + 1, 3));
  }