コード例 #1
0
  public void cancelRegisteredItem(Player player, int brokerItemId) {
    if (player.getInventory().isFull()) {
      PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(901298));
      return;
    }
    int playerId = player.getObjectId();
    Map<Integer, BrokerItem> brokerItems = getRaceBrokerItems(player.getCommonData().getRace());
    BrokerItem brokerItem = brokerItems.get(brokerItemId);

    if (brokerItem == null) return;
    if (playerId != brokerItem.getSellerId()) {
      Logger.getLogger(this.getClass())
          .info(
              "[AUDIT]Player: "
                  + player.getName()
                  + " is trying to steal: "
                  + brokerItem.getItemId()
                  + " => Hacking!");
      return;
    }
    synchronized (brokerItem) {
      if (brokerItem != null) {
        Item item = player.getInventory().putToBag(brokerItem.getItem());
        PacketSendUtility.sendPacket(player, new SM_INVENTORY_UPDATE(item, true));
        PacketSendUtility.sendPacket(player, new SM_BROKER_ITEMS(brokerItemId, 4));
        brokerItem.setPersistentState(PersistentState.DELETED);
        saveManager.add(new BrokerOpSaveTask(brokerItem));
        brokerItems.remove(brokerItemId);
      }
      showRegisteredItems(player);
    }
  }
コード例 #2
0
 private void expireItem(Race race, BrokerItem item) {
   if (MailService.getInstance()
       .sendSystemMail("VENDOR_RETURN_MAIL", "", "", item.getSellerId(), item.getItem(), 0)) {
     item.setPersistentState(PersistentState.DELETED);
     saveManager.add(new BrokerOpSaveTask(item));
   } else {
     putToSettled(race, item, false);
   }
 }
コード例 #3
0
  private void putToSettled(Race race, BrokerItem brokerItem, boolean isSold) {
    if (isSold) brokerItem.removeItem();
    else brokerItem.setSettled();

    brokerItem.setPersistentState(PersistentState.UPDATE_REQUIRED);

    switch (race) {
      case ASMODIANS:
        asmodianSettledItems.put(brokerItem.getItemUniqueId(), brokerItem);
        break;

      case ELYOS:
        elyosSettledItems.put(brokerItem.getItemUniqueId(), brokerItem);
        break;
    }

    Player seller = World.getInstance().findPlayer(brokerItem.getSellerId());

    saveManager.add(new BrokerOpSaveTask(brokerItem));

    if (seller != null) {
      Map<Integer, BrokerItem> brokerSettledItems =
          getRaceBrokerSettledItems(seller.getCommonData().getRace());

      int playerId = seller.getObjectId();

      List<BrokerItem> settledItems = new ArrayList<BrokerItem>();

      long totalKinah = 0;

      for (BrokerItem item : brokerSettledItems.values()) {
        if (item != null && playerId == item.getSellerId()) {
          settledItems.add(item);

          if (item.isSold()) totalKinah += item.getPrice();
        }
      }

      DescriptionId desId = new DescriptionId(brokerItem.getItem().getNameID());
      PacketSendUtility.sendPacket(seller, new SM_SYSTEM_MESSAGE(1301047, desId));
      showRegisteredItems(seller);
      PacketSendUtility.sendPacket(seller, new SM_BROKER_ITEMS(null, totalKinah, 2, 5));
    }
  }
コード例 #4
0
  public void settleAccount(Player player) {
    Race playerRace = player.getCommonData().getRace();
    Map<Integer, BrokerItem> brokerSettledItems = getRaceBrokerSettledItems(playerRace);
    List<BrokerItem> collectedItems = new ArrayList<BrokerItem>();
    int playerId = player.getObjectId();
    long kinahCollect = 0;
    boolean itemsLeft = false;

    for (BrokerItem item : brokerSettledItems.values()) {
      if (item.getSellerId() == playerId) collectedItems.add(item);
    }

    for (BrokerItem item : collectedItems) {
      if (item.isSold()) {
        boolean result = false;
        switch (playerRace) {
          case ASMODIANS:
            result = asmodianSettledItems.remove(item.getItemUniqueId()) != null;
            break;
          case ELYOS:
            result = elyosSettledItems.remove(item.getItemUniqueId()) != null;
            break;
        }

        if (result) {
          item.setPersistentState(PersistentState.DELETED);
          saveManager.add(new BrokerOpSaveTask(item));
          kinahCollect += item.getPrice();
        }
      } else {
        if (item.getItem() != null) {
          Item resultItem = player.getInventory().putToBag(item.getItem());
          if (resultItem != null) {
            boolean result = false;
            switch (playerRace) {
              case ASMODIANS:
                result = asmodianSettledItems.remove(item.getItemUniqueId()) != null;
                break;
              case ELYOS:
                result = elyosSettledItems.remove(item.getItemUniqueId()) != null;
                break;
            }

            if (result) {
              item.setPersistentState(PersistentState.DELETED);
              saveManager.add(new BrokerOpSaveTask(item));
              PacketSendUtility.sendPacket(
                  player, new SM_INVENTORY_UPDATE(Collections.singletonList(resultItem)));
            }
          } else itemsLeft = true;

        } else log.warn("Broker settled item missed. ObjID: " + item.getItemUniqueId());
      }
    }

    player.getInventory().increaseKinah(kinahCollect);

    showSettledItems(player);

    if (!itemsLeft) PacketSendUtility.sendPacket(player, new SM_BROKER_ITEMS(6));
  }
コード例 #5
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));
  }
コード例 #6
0
  public void buyBrokerItem(Player player, int itemUniqueId) {
    boolean isEmptyCache = getFilteredItems(player).length == 0;
    Race playerRace = player.getCommonData().getRace();

    BrokerItem buyingItem = getRaceBrokerItems(playerRace).get(itemUniqueId);

    if (buyingItem == null) return;

    synchronized (buyingItem) {
      if (buyingItem == null || buyingItem.isSold() || buyingItem.isSettled()) {
        if (buyingItem != null && buyingItem.getItem() != null)
          PacketSendUtility.sendPacket(
              player,
              new SM_SYSTEM_MESSAGE(1300647, new DescriptionId(buyingItem.getItem().getNameID())));
        return;
      }

      if (player.getObjectId() == buyingItem.getSellerId()) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400750));
        return;
      }

      if (player.getInventory().isFull()) {
        PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1300654));
        return;
      }

      long price = buyingItem.getPrice();

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

      getRaceBrokerItems(playerRace).remove(itemUniqueId);
      putToSettled(playerRace, buyingItem, true);

      if (!isEmptyCache) {
        BrokerItem[] newCache =
            (BrokerItem[]) ArrayUtils.removeElement(getFilteredItems(player), buyingItem);
        getPlayerCache(player).setBrokerListCache(newCache);
      }

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

      Item boughtItem = player.getInventory().putToBag(buyingItem.getItem());

      BrokerOpSaveTask bost =
          new BrokerOpSaveTask(
              buyingItem, boughtItem, player.getInventory().getKinahItem(), player.getObjectId());
      saveManager.add(bost);

      PacketSendUtility.sendPacket(player, new SM_INVENTORY_UPDATE(boughtItem, true));
      PacketSendUtility.sendPacket(player, new SM_BROKER_ITEMS(boughtItem, 2));

      showRequestedItems(
          player,
          getPlayerCache(player).getBrokerMaskCache(),
          getPlayerCache(player).getBrokerSortTypeCache(),
          getPlayerCache(player).getBrokerStartPageCache());
    }
  }