/** * @param p - The player buying an item. * @param item - The item the player wants to buy. */ public static void buyItem(Player p, Item item) { String key = item.getItemId() + ":" + item.getDamage(); int amount = ITEMS.getInt(key, 0); if (amount == -1) { p.sendMessage(WShop.PRE + "The server does not sell that item at this time."); return; } if (amount < item.getAmount()) { p.sendMessage(WShop.PRE + "The server does not have that much of " + key); return; } // end if double price = PRICES.getDouble(key + "_buy", -1); if (price == -1) { p.sendMessage(WShop.PRE + "The server does not sell that item at this time." + key); return; } if (canPay(p, price)) { payPlayer(p, -price); // Make sure we charge them here, not pay them. Negate the price. p.giveItem(item); ITEMS.setInt(key, amount - item.getAmount()); p.sendMessage( WShop.PRE + "Bought an item. ID:" + item.getItemId() + ", Damage:" + item.getDamage() + ", Amount:" + item.getAmount() + ", Cost:" + price); } else { p.sendMessage(WShop.PRE + "You do not have enough money to buy " + key); return; } } // end buyItem
/* * assumes item1 and item2 id types have already been compared */ private static boolean isSameColor(Item item1, Item item2) { if (item1.getItemId() != BlockType.CLOTH && item1.getItemId() != BlockType.LOG && item1.getItemId() != 351 // dye ) { return true; } return item1.getDamage() == item2.getDamage(); }
public void addItem(Item item, boolean isInStock) { CartItem cartItem = (CartItem) itemMap.get(item.getItemId()); if (cartItem == null) { cartItem = new CartItem(); cartItem.setItem(item); cartItem.setQuantity(0); cartItem.setInStock(isInStock); itemMap.put(item.getItemId(), cartItem); itemList.add(cartItem); } }
private void init() { for (Item each : getItems()) { _totalChance += each.getChance(); if (ItemTable.getInstance().getTemplate(each.getItemId()) == null) { getItems().remove(each); _log.warning("item ID " + each.getItemId() + " is not found。"); } } if ((getTotalChance() != 0) && (getTotalChance() != 1000000)) { _log.warning("ID " + getBoxId() + " 的總機率不等於100%。"); } }
private void init() { for (Item each : getItems()) { _totalChance += each.getChance(); if (ItemTable.getInstance().getTemplate(each.getItemId()) == null) { getItems().remove(each); _log.warning("アイテムID " + each.getItemId() + " のテンプレートが見つかりません。"); } } if (getTotalChance() != 0 && getTotalChance() != 1000000) { _log.warning("ID " + getBoxId() + " の確率の合計が100%になりません。"); } }
/** * TreasureBoxを開けるPCにアイテムを入手させる。PCがアイテムを持ちきれなかった場合は アイテムは地面に落ちる。 * * @param pc - TreasureBoxを開けるPC * @return 開封した結果何らかのアイテムが出てきた場合はtrueを返す。 持ちきれず地面に落ちた場合もtrueになる。 */ public boolean open(L1PcInstance pc) { L1ItemInstance item = null; if (getType().equals(TYPE.SPECIFIC)) { // 出るアイテムが決まっているもの for (Item each : getItems()) { item = ItemTable.getInstance().createItem(each.getItemId()); if (item != null) { item.setCount(each.getCount()); storeItem(pc, item); } } } else if (getType().equals(TYPE.RANDOM)) { // 出るアイテムがランダムに決まるもの RandomGenerator random = RandomGeneratorFactory.getSharedRandom(); int chance = 0; int r = random.nextInt(getTotalChance()); for (Item each : getItems()) { chance += each.getChance(); if (r < chance) { item = ItemTable.getInstance().createItem(each.getItemId()); if (item != null) { item.setCount(each.getCount()); storeItem(pc, item); } break; } } } if (item == null) { return false; } else { int itemId = getBoxId(); // 魂の結晶の破片、魔族のスクロール、ブラックエントの実 if (itemId == 40576 || itemId == 40577 || itemId == 40578 || itemId == 40411 || itemId == 49013) { pc.death(null); // キャラクターを死亡させる } return true; } }
public static void sendInfo(Player p, Item item) { String key = item.getItemId() + ":" + item.getDamage(); p.sendMessage(WShop.PRE + key); p.sendMessage(WShop.PRE + "Price (sell): " + PRICES.getDouble(key + "_sell", -1)); p.sendMessage(WShop.PRE + "Price (buy): " + PRICES.getDouble(key + "_buy", -1)); p.sendMessage(WShop.PRE + "Amount: " + ITEMS.getInt(key, 0)); }
@Override public String toString() { if (method == PaymentMethod.iConomy) { return String.valueOf(money); } else if (method == PaymentMethod.Blocks) { StringBuilder builder = new StringBuilder(); for (Item item : items) { if (builder.length() > 0) { builder.append(", "); } if (item.getAmount() > 1) { builder.append(item.getAmount()); builder.append("* "); } builder.append(etc.getDataSource().getItem(item.getItemId())); } return builder.toString(); } else { return "None"; } }
@Test public void testItemLookupExists() throws Exception { final String ITEM_ID = "BUTTER"; Item item = lookupItem.sendInOut(ITEM_ID).getContent(Item.class); Assert.assertNotNull(item); Assert.assertEquals(ITEM_ID, item.getItemId()); }
public boolean isEmpty() { return (amount == null || amount == 0.0) && (discount == null || discount == 0.0) && invoiceItemId == null && Utils.isBlank(description) && (item == null || item.getItemId() == null) && // (quantity == null || quantity == 0) && (unitPrice == null || unitPrice == 0.0); }
/** * Checks to see if this getArray() has one slot that has the item id and equal or more to the * amount. * * @param itemId item to look for * @param minimum amount of items that must be in the stack * @return */ public boolean hasItem(int itemId, int minimum) { Item[] items = getContents(); for (Item item : items) { if ((item != null) && (item.getItemId() == itemId) && (item.getAmount() >= minimum)) { return true; } } return false; }
/** * Retrieves from the slot * * @param id * @return item */ public Item getItemFromId(int id) { Item[] items = getContents(); for (Item item : items) { if ((item != null) && (item.getItemId() == id)) { return item; } } return null; }
/** * Adds the specified item. If the item doesn't have a slot, it will get the nearest available * slot. If amount is equal to 0, it will delete the item if a slot is specified. * * @param item item to add */ public void addItem(Item item) { if (item == null) { return; } int slot = item.getSlot(); if (slot < _getArray().length && slot >= 0) { if (item.getAmount() <= 0) { _getArray()[slot] = null; } else if (Item.isValidItem(item.getItemId())) { _getArray()[slot] = new hn(item.getItemId(), item.getAmount()); } } else if (slot == -1) { int newSlot = getEmptySlot(); if (newSlot != -1) { _getArray()[newSlot] = new hn(item.getItemId(), item.getAmount()); item.setSlot(newSlot); } } }
private boolean deductBlocks(Player player) { Inventory inventory = player.getInventory(); for (Item item : items) { if (inventory.hasItem(item.getItemId(), item.getAmount(), 65)) { inventory.removeItem(item); inventory.update(); return true; } } return false; }
/** * @param p - The player trying to sell. * @param item - The item to sell, commonly the players help item. */ public static void sellItem(Player p, Item item) { String key = item.getItemId() + ":" + item.getDamage(); double price = PRICES.getDouble(key + "_sell", -1); if (price == -1) { p.sendMessage(WShop.PRE + "The server does not buy that item at this time."); return; } int amount = ITEMS.getInt(key, 0); p.getInventory().removeItem(item); ITEMS.setInt(key, amount + item.getAmount()); payPlayer(p, price); return; } // end sellItem
private static JSONObject generateMoveJson( String characterId, Item item, boolean transferToVault, int stackSize) { JSONObject json = new JSONObject(); try { json.put("characterId", characterId); json.put("itemId", item.getItemId()); json.put("itemReferenceHash", item.getItemHash()); json.put("membershipType", Data.getInstance().getMembership().getType()); json.put("stackSize", stackSize); json.put("transferToVault", transferToVault); } catch (JSONException e) { Log.e(LOG_TAG, "exception", e); e.printStackTrace(); } return json; }
/** * Removes the item. No slot needed, it will go through the inventory until the amount specified * is removed. * * @param id item to remove * @param amount amount to remove */ public void removeItem(int id, int amount) { Item[] items = getContents(); for (Item item : items) { if ((item != null) && (item.getItemId() == id)) { if (item.getAmount() == amount) { removeItem(item.getSlot()); return; } else if (item.getAmount() > amount) { setSlot(id, item.getAmount() - amount, item.getSlot()); amount -= item.getAmount(); } else { removeItem(item.getSlot()); amount -= item.getAmount(); } } } }
public static Promise equip( final ClientWebView webView, final String owner, final Item item, final Promise p) { final Promise p_inner = new Promise(); JSONObject obj = new JSONObject(); try { obj.put("characterId", owner); obj.put("itemId", item.getItemId()); obj.put("membershipType", Data.getInstance().getMembership().getType()); } catch (JSONException e) { Log.e(LOG_TAG, "exception", e); e.printStackTrace(); } webView .call("destinyService.EquipItem", obj) .then( new ClientWebView.Callback() { @Override public void onAccept(String result) { for (Item tested_item : Items.getInstance().all()) { if (tested_item.getBucketTypeHash() == item.getBucketTypeHash() && item.getItemHash() != tested_item.getItemHash() && Items.getInstance().getItemOwner(tested_item).equals(owner) && tested_item.getCanEquip()) { tested_item.setIsEquipped(false); item.setIsEquipped(true); break; } } p_inner.onSuccess(); } @Override public void onError(String result) { p_inner.onError(result); } }); return p_inner; }
public void addItem(Item item) { items.put(item.getItemId(), item); }
/* * assumes item is valid */ protected static int getStackMax(Item item) { return OItem.e[item.getItemId()].k(); }
public static void moveItemArrayToChestBag( ItemArray<?> from, NearbyChestBlockBag bag, int itemType, int itemColor, int itemAmount) { Item[] fromItems = from.getContents(); Inventory[] inventories = bag.getInventories(); int invenIndex = 0; boolean changed = false; int currentAmount = 0; try { for (int cartSlot = 0; cartSlot < fromItems.length; cartSlot++) { Item cartItem = fromItems[cartSlot]; if (cartItem == null || cartItem.getAmount() == 0 || (itemType > 0 && (itemType != cartItem.getItemId() || (itemColor != -1 && itemColor != cartItem.getDamage())))) { continue; } currentAmount += cartItem.getAmount(); Item itemCopy = null; if (itemAmount > 0 && currentAmount > itemAmount) { itemCopy = new Item( cartItem.getItemId(), currentAmount - itemAmount, cartItem.getSlot(), cartItem.getDamage()); cartItem.setAmount(cartItem.getAmount() - itemCopy.getAmount()); } try { for (; invenIndex < inventories.length; invenIndex++) { Item[] chestItems = inventories[invenIndex].getContents(); for (int chestSlot = 0; chestSlot < chestItems.length; chestSlot++) { Item chestItem = chestItems[chestSlot]; if (chestItem == null) { chestItems[chestSlot] = cartItem; fromItems[cartSlot] = null; setContents(inventories[invenIndex], chestItems); changed = true; throw new TransferredItemException(); } else { int maxStack = getStackMax(chestItem); if (chestItem.getItemId() == cartItem.getItemId() && isSameColor(chestItem, cartItem) && chestItem.getAmount() < maxStack && chestItem.getAmount() >= 0) { int spaceAvailable = maxStack - chestItem.getAmount(); if (spaceAvailable >= cartItem.getAmount()) { chestItem.setAmount(chestItem.getAmount() + cartItem.getAmount()); fromItems[cartSlot] = null; setContents(inventories[invenIndex], chestItems); changed = true; throw new TransferredItemException(); } else { cartItem.setAmount(cartItem.getAmount() - spaceAvailable); chestItem.setAmount(maxStack); changed = true; } } } } if (changed) { setContents(inventories[invenIndex], chestItems); } } throw new TargetFullException(); } catch (TransferredItemException e) { } if (itemAmount > 0 && currentAmount >= itemAmount) { if (itemCopy != null) { if (fromItems[cartSlot] != null) { itemCopy.setAmount(itemCopy.getAmount() + fromItems[cartSlot].getAmount()); } fromItems[cartSlot] = itemCopy; } break; } } } catch (TargetFullException e) { } if (changed) { setContents(from, fromItems); } }
public static boolean onCommand(Player player, String[] split) { String ItemID; String ItemsFilep1 = "plugins/config/iExchange/GroupPrices/"; String ItemsFilep2 = "sell.txt"; if (split.length == 2) { player.sendMessage("§e[iExchange] §bUsage is /iex sell [Item] [Amount]"); return true; } else { String Numberof = null; Inventory inventory = player.getInventory(); if (split.length > 3) { Numberof = split[3]; } int amount = 0; if (Numberof != null) { try { amount = Integer.parseInt(Numberof); } catch (NumberFormatException localNumberFormatException) { player.sendMessage("§e[iExchage] §cERROR 409: CONFLICT"); player.sendMessage("§c(You didn't enter a proper number)"); return true; } } else { amount = 1; } if (amount <= 0) { player.sendMessage("§e[iExchage] §cERROR 409: CONFLICT"); player.sendMessage("§c(You entered a number less than 1)"); return true; } ItemID = split[2].toUpperCase(); ArrayList<String> ITEMPRICES = new ArrayList<String>(); String[] group = player.getGroups(); try { BufferedReader in = new BufferedReader(new FileReader(ItemsFilep1 + group[0] + ItemsFilep2)); String str; while ((str = in.readLine()) != null) { String Upped = str.toUpperCase(); String[] CheckName = Upped.split(":"); if (CheckName[0].equals(ItemID)) { ITEMPRICES.add(str.toString()); } } in.close(); } catch (IOException e) { player.sendMessage("§e[iExchange] §cERROR 404: SellPriceList Not Found "); player.sendMessage("§c(the SellPriceList for your group does not exist)"); player.sendMessage("§c(ask a ADMIN or the SERVER OWNER to correct the issue)"); return true; } if (!(ITEMPRICES.isEmpty())) { String ItemIDS = ITEMPRICES.toString(); String[] Item = ItemIDS.split(":"); String PricePrice = Item[2].replace("]", ""); int ID = 0; int price = 0; int damage = 0; try { ID = Integer.parseInt(Item[1]); } catch (NumberFormatException localNumberFormatException) { player.sendMessage("§e[iExchange] §cERROR 404: ITEM NOT FOUND!"); player.sendMessage("§c(Props file error! Yell at your ADMIN or SERVER OWNER)"); ITEMPRICES.clear(); return true; } Item itemd = new Item(); if ((ID == 6) || (ID == 17) || (ID == 18) || (ID == 35) || (ID == 44) || (ID == 98) || (ID == 263) || (ID == 351) || (ID == 358)) { damage = Integer.parseInt(Item[2]); if (Item[3].contains(",")) { String[] unfuck = Item[3].split(","); PricePrice = unfuck[0]; itemd = new Item(ID, amount, -1, damage); } else { PricePrice = Item[3].replace("]", ""); itemd = new Item(ID, amount, -1, damage); } } else { if (Item[2].contains(",")) { String[] unfuck = Item[2].split(","); PricePrice = unfuck[0]; } else { PricePrice = Item[2].replace("]", ""); } itemd = new Item(ID, amount); } try { price = Integer.parseInt(PricePrice); } catch (NumberFormatException localNumberFormatException) { player.sendMessage("§e[iExchange] §cERROR 404: PRICE NOT FOUND!"); player.sendMessage("§c(Props file error! Yell at your ADMIN or SERVER OWNER)"); ITEMPRICES.clear(); return true; } String ItemItem = Item[0].replace("[", ""); String ItemGave = ItemItem.toUpperCase(); if (inventory.hasItem(itemd.getItemId())) { if ((ID == 6) || (ID == 17) || (ID == 18) || (ID == 35) || (ID == 44) || (ID == 98) || (ID == 263) || (ID == 351) || (ID == 358)) { int i = -1; int scan = -1; int invamount = 0; while (scan < 37) { scan++; if (inventory.getItemFromSlot(scan) != null) { Item itemcheck = inventory.getItemFromSlot(scan); int id1 = itemd.getItemId(); int id2 = itemcheck.getItemId(); int d1 = itemd.getDamage(); int d2 = itemcheck.getDamage(); int icA = itemcheck.getAmount(); if ((id1 == id2) && (d1 == d2)) { invamount += icA; } } } if (invamount < amount) { player.sendMessage("§e[iExchange] §cERROR 404: AMOUNT NOT FOUND!"); player.sendMessage("§cYou don't have that much!"); ITEMPRICES.clear(); return true; } while (i <= 40) { i++; if (inventory.getItemFromSlot(i) != null) { Item item2 = inventory.getItemFromSlot(i); int id1 = itemd.getItemId(); int id2 = item2.getItemId(); int d1 = itemd.getDamage(); int d2 = item2.getDamage(); if ((id1 == id2) && (d1 == d2)) { if (amount > 0) { int oldamount = item2.getAmount(); int newamount = (oldamount - amount); if (newamount <= 0) { inventory.removeItem(i); inventory.update(); amount -= oldamount; } else { inventory.removeItem(i); inventory.setSlot(itemd.getItemId(), newamount, d1, i); inventory.update(); amount -= oldamount; } } else { break; } } } } if (Numberof != null) { amount = Integer.parseInt(Numberof); } else { amount = 1; } etc.getLoader() .callCustomHook( "iBalance", new Object[] {"deposit", player.getName(), (price * amount)}); player.sendMessage( "§e[iExchange] §2" + amount + " " + ItemGave + " §bsold for §2$" + price * amount); ITEMPRICES.clear(); return true; } else if (ID != 0) { int scan = -1; int invamount = 0; while (scan < 37) { scan++; if (inventory.getItemFromSlot(scan) != null) { Item itemcheck = inventory.getItemFromSlot(scan); int id1 = itemd.getItemId(); int id2 = itemcheck.getItemId(); int icA = itemcheck.getAmount(); if (id1 == id2) { invamount += icA; } } } if (invamount < amount) { player.sendMessage("§e[iExchange] §cERROR 404: AMOUNT NOT FOUND!"); player.sendMessage("§cYou don't have that much!"); ITEMPRICES.clear(); return true; } int i = -1; while (i <= 40) { i++; if (inventory.getItemFromSlot(i) != null) { Item item2 = inventory.getItemFromSlot(i); int id1 = itemd.getItemId(); int id2 = item2.getItemId(); if ((id1 == id2)) { if (amount > 0) { int oldamount = item2.getAmount(); int newamount = (oldamount - amount); if (newamount <= 0) { inventory.removeItem(i); inventory.update(); amount -= oldamount; } else { inventory.removeItem(i); inventory.setSlot(itemd.getItemId(), newamount, i); inventory.update(); amount -= oldamount; } } else { break; } } } } if (Numberof != null) { amount = Integer.parseInt(Numberof); } else { amount = 1; } etc.getLoader() .callCustomHook( "iBalance", new Object[] {"deposit", player.getName(), (price * amount)}); player.sendMessage( "§e[iExchange] §2" + amount + " " + ItemGave + " §bsold for §2$" + price * amount); ITEMPRICES.clear(); return true; } } else { player.sendMessage("§e[iExchange] §cERROR 404: ITEM NOT FOUND!"); player.sendMessage("§cYou don't have that item!"); ITEMPRICES.clear(); return true; } } else { player.sendMessage("§e[iExchange] §cError 400: ITEM NOT ON LIST!"); player.sendMessage("§c(check your spelling or ask an ADMIN if item is on the list)"); ITEMPRICES.clear(); return true; } } return false; }
/** * TreasureBoxを開けるPCにアイテムを入手させる。PCがアイテムを持ちきれなかった場合は アイテムは地面に落ちる。 * * @param pc - TreasureBoxを開けるPC * @return 開封した結果何らかのアイテムが出てきた場合はtrueを返す。 持ちきれず地面に落ちた場合もtrueになる。 */ public boolean open(PcInstance pc) { ItemInstance item = null; if (getType().equals(TYPE.SPECIFIC)) { // 出るアイテムが決まっているもの for (Item each : getItems()) { item = ItemTable.getInstance().createItem(each.getItemId()); item.setEnchantLevel(each.getEnchant()); // Enchant Feature for treasure_box if (item != null) { item.setCount(each.getCount()); storeItem(pc, item); } } } else if (getType().equals(TYPE.RANDOM)) { // 出るアイテムがランダムに決まるもの int chance = 0; int r = Random.nextInt(getTotalChance()); for (Item each : getItems()) { chance += each.getChance(); if (r < chance) { item = ItemTable.getInstance().createItem(each.getItemId()); item.setEnchantLevel(each.getEnchant()); // Enchant Feature for treasure_box if (item != null) { item.setCount(each.getCount()); storeItem(pc, item); } break; } } } if (item == null) { return false; } else { int itemId = getBoxId(); // 魂の結晶の破片、魔族のスクロール、ブラックエントの実 if ((itemId == 40576) || (itemId == 40577) || (itemId == 40578) || (itemId == 40411) || (itemId == 49013)) { pc.death(null); // キャラクターを死亡させる } // 多魯嘉之袋 if ((itemId == 46000)) { ItemInstance box = pc.getInventory().findItemId(itemId); box.setChargeCount(box.getChargeCount() - 1); pc.getInventory().updateItem(box, LsimulatorPcInventory.COL_CHARGE_COUNT); if (box.getChargeCount() < 1) { pc.getInventory().removeItem(box, 1); } } return true; } }
/** * Sets the specified slot with item * * @param item item to set * @param slot slot to use */ public void setSlot(Item item, int slot) { setSlot(item.getItemId(), item.getAmount(), slot); }
/** * Removes the item. No slot needed, it will go through the inventory until the amount specified * is removed. * * @param item item id and amount to remove */ public void removeItem(Item item) { removeItem(item.getItemId(), item.getAmount()); }
/* * M4411K4: redoing code here because the last code from * I guess sk89q, didn't work properly and used more resources * than should have (using exceptions to break? o_O) */ public static void moveChestBagToItemArray( ItemArray<?> to, NearbyChestBlockBag bag, int itemType, int itemColor, int itemAmount) { Item[] toItems = to.getContents(); Inventory[] bags = bag.getInventories(); boolean changed = false; int currentAmount = 0; for (int toSlot = 0; toSlot < toItems.length; toSlot++) { Item toItem = toItems[toSlot]; int maxStack = 0; if (toItem != null) { maxStack = getStackMax(toItem); if (toItem.getAmount() >= maxStack || (itemType > 0 && (itemType != toItem.getItemId() || (itemColor != -1 && itemColor != toItem.getDamage())))) { continue; } } boolean moved = false; for (Inventory inventory : bags) { Item[] chestItems = inventory.getContents(); for (int chestSlot = 0; chestSlot < chestItems.length; chestSlot++) { Item chestItem = chestItems[chestSlot]; if (chestItem == null || chestItem.getAmount() == 0 || (toItem != null && (chestItem.getItemId() != toItem.getItemId() || chestItem.getDamage() != toItem.getDamage())) || (itemType > 0 && (itemType != chestItem.getItemId() || (itemColor != -1 && itemColor != chestItem.getDamage())))) { // empty or not the same item so move on to next slot continue; } currentAmount += chestItem.getAmount(); Item itemCopy = null; if (itemAmount > 0 && currentAmount > itemAmount) { itemCopy = new Item( chestItem.getItemId(), currentAmount - itemAmount, chestItem.getSlot(), chestItem.getDamage()); chestItem.setAmount(chestItem.getAmount() - itemCopy.getAmount()); } // can move to slot if (toItem == null) { toItems[toSlot] = chestItem; chestItems[chestSlot] = null; } else { // maxStack should have correct value since toItem is not null int spaceAvailable = maxStack - toItem.getAmount(); if (spaceAvailable >= chestItem.getAmount()) { // everything fits toItem.setAmount(toItem.getAmount() + chestItem.getAmount()); chestItems[chestSlot] = null; } else { // doesn't fit into slot toItem.setAmount(maxStack); chestItem.setAmount(chestItem.getAmount() - spaceAvailable); } } // if not max, re-check slot maxStack = getStackMax(toItems[toSlot]); if (toItems[toSlot].getAmount() < maxStack) { toSlot--; } if (itemCopy != null) { if (chestItems[chestSlot] != null) { itemCopy.setAmount(itemCopy.getAmount() + chestItems[chestSlot].getAmount()); } chestItems[chestSlot] = itemCopy; } moved = true; changed = true; break; } if (moved || (itemAmount > 0 && currentAmount >= itemAmount)) { // set chest items with new values setContents(inventory, chestItems); // go to next item slot break; } } if (itemAmount > 0 && currentAmount >= itemAmount) { break; } } if (changed) { setContents(to, toItems); } }