private void initBrokerService() { int loadedBrokerItemsCount = 0; int loadedSettledItemsCount = 0; List<BrokerItem> brokerItems = DAOManager.getDAO(BrokerDAO.class).loadBroker(); for (BrokerItem item : brokerItems) { if (item.getItemBrokerRace() == BrokerRace.ASMODIAN) { if (item.isSettled()) { asmodianSettledItems.put(item.getItemUniqueId(), item); loadedSettledItemsCount++; } else { asmodianBrokerItems.put(item.getItemUniqueId(), item); loadedBrokerItemsCount++; } } else if (item.getItemBrokerRace() == BrokerRace.ELYOS) { if (item.isSettled()) { elyosSettledItems.put(item.getItemUniqueId(), item); loadedSettledItemsCount++; } else { elyosBrokerItems.put(item.getItemUniqueId(), item); loadedBrokerItemsCount++; } } } log.info("Loaded " + loadedBrokerItemsCount + " Broker Items"); log.info("Loaded " + loadedSettledItemsCount + " Settled Items"); log.info("Broker loaded successfully"); }
private BrokerPlayerCache getPlayerCache(Player player) { BrokerPlayerCache cacheEntry = playerBrokerCache.get(player.getObjectId()); if (cacheEntry == null) { cacheEntry = new BrokerPlayerCache(); playerBrokerCache.put(player.getObjectId(), cacheEntry); } return cacheEntry; }
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)); } }
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)); }