Thread: [PI] Bank Search Method

Results 1 to 2 of 2
  1. #1 [PI] Bank Search Method 
    Exiles Developer


    Join Date
    May 2009
    Age
    28
    Posts
    316
    Thanks given
    55
    Thanks received
    25
    Rep Power
    86
    Hello, so basically I found an old source that did not have bank tabs, but had a bank search method, I did not create it. I am using this method in order to search your inventory + bank for a clue scroll id. If you have the id, you cannot get another one. I had applied this process to a pet handler on the old source that I got this method from.

    Spoiler for CheckBank Method:
    Code:
        public boolean checkBank(int item) {
    		int found = 0;
    		int item2 = item + 1;
    		for (int i = 0; i < player.bankItems.length;i++) {
    			if (player.bankItems[i] == item2) {
    			    	found++;
    			}
    		}
    		if(found >= 1) {
    			return true;
    		}
        	return false;
    	}

    I am trying to find a way to do the same exact search but with my new source with bank tabs..

    Problem is I have absolutely NO experience with Iterators. I have not learned about them (if they are even in C++).

    Not sure if it can be included inside of a loop like the method above. If so, I would not know how to go about doing that with an Iterator...
    Here is my addItemToBank() (Could help you reverse engineer to create this method.):

    Spoiler for addItemToBank Method:
    Code:
    	public void addItemToBank(int itemId, int amount) {
    		if (player.inWild() || player.inClanWars()) {
    			player.sendGameMessage("You can't do that in the wilderness.");
    			return;
    		}
    		BankTab tab = player.getBank().getCurrentBankTab();
    		BankItem item = new BankItem(itemId + 1, amount);
    		Iterator<BankTab> iterator = Arrays.asList(player.getBank().getBankTab()).iterator();
    		while (iterator.hasNext()) {
    			BankTab t = iterator.next();
    			if (t != null && t.size() > 0) {
    				Iterator<BankItem> iterator2 = t.getItems().iterator();
    				while (iterator2.hasNext()) {
    					BankItem i = iterator2.next();
    					if (i.getId() == item.getId() && !isNotable(itemId)) {
    						if (t.getTabId() != tab.getTabId()) {
    							tab = t;
    							player.getBank().setCurrentBankTab(tab);
    							resetBank();
    						}
    					} else {
    						if (isNotable(itemId) && i.getId() == item.getId() - 1) {
    							item = new BankItem(itemId, amount);
    							if (t.getTabId() != tab.getTabId()) {
    								tab = t;
    								player.getBank().setCurrentBankTab(tab);
    								resetBank();
    							}
    						}
    					}
    				}
    			}
    		}
    		if (isNotable(itemId))
    			item = new BankItem(itemId, amount);
    		if (tab.freeSlots() == 0) {
    			player.sendGameMessage("Bank tab is full! The item has been dropped on the floor.");
    			GroundItemHandler.createGroundItem(
    					new GroundItem(new Item(itemId, amount), player.getX(), player.getY(), player.getHeight(), player));
    			return;
    		}
    		long totalAmount = ((long) tab.getItemAmount(item) + (long) item.getAmount());
    		if (totalAmount >= Integer.MAX_VALUE) {
    			player.sendGameMessage("Bank is full of this item! The item has been dropped on the floor.");
    			GroundItemHandler.createGroundItem(
    					new GroundItem(new Item(itemId, amount), player.getX(), player.getY(), player.getHeight(), player));
    			// ItemHandler.createGroundItem(c, itemId, c.absX, c.absY,
    			// c.heightLevel, amount);
    			return;
    		}
    		tab.add(item);
    		resetTempItems();
    		if (player.isBanking)
    			resetBank();
    		// c.sendMessage(getItemName(itemId) + " x" + item.getAmount() + " has
    		// been added to your bank.");
    	}


    I made an instance of it in my clue scroll class using:
    Code:
    BankTab tab = new BankTab();
    After that, I then used the contains method in the BankTab class as below:
    Code:
    if ((tab.contains(new BankItem(dropId + 1, 1))) || (c.getItems().playerHasItem(dropId, 1))) {
    Probably did something wrong.. but it does not work correctly..

    Edit: Just found this in the BankTab.java - contains method - I made it red so you can see it- seems like the same kind of thing.

    Spoiler for BankTab.java:
    Code:
    package server.game.items.bank;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    import server.Constants;
    
    public class BankTab {
    
    	final List<BankItem> bankItems = new ArrayList<>();
    	private int tabId;
    
    	public BankTab() {
    
    	}
    
    	/**
    	 * 
    	 * @param tabId
    	 *            The bank tab id
    	 */
    	public BankTab(int tabId) {
    		this.setTabId(tabId);
    	}
    
    	/**
    	 *
    	 * @param bankItem
    	 *            The object that contains the item id and amount
    	 */
    	public void add(BankItem bankItem) {
    		if (bankItem.getAmount() <= 0)
    			return;
    		for (BankItem item : bankItems) {
    			if (item.getId() == bankItem.getId()) {
    				item.setAmount(bankItem.getAmount() + item.getAmount());
    				if (item.getAmount() > Integer.MAX_VALUE)
    					item.setAmount(Integer.MAX_VALUE);
    				return;
    			}
    		}
    		bankItems.add(bankItem);
    	}
    
    	/**
    	 * 
    	 * @param bankItem
    	 *            Removes the BankItem object from the ArrayList
    	 */
    	public void remove(BankItem bankItem) {
    
    		Iterator<BankItem> $it = bankItems.iterator();
    		while ($it.hasNext()) {
    			BankItem item = $it.next();
    			if (item != null && item.getId() == bankItem.getId()) {
    				if (item.getAmount() - bankItem.getAmount() <= 0)
    					$it.remove();
    				else
    					item.setAmount(item.getAmount() - bankItem.getAmount());
    				break;
    			}
    		}
    	}
    
    	/**
    	 * 
    	 * @return The current amount of items in the bank tab
    	 */
    	public int size() {
    		return bankItems.size();
    	}
    
    	/**
    	 * 
    	 * @return The amount of free slots remaining in this tab
    	 */
    	public int freeSlots() {
    		return Constants.BANK_SIZE - bankItems.size();
    	}
    	
        public boolean checkBank(int item) {
    		int found = 0;
    		int item2 = item + 1;
    		for (int i = 0; i < bankItems.size(); i++) {
    			if (bankItems.get(i) != null)
    				if (bankItems.get(i).getId() == item2) {
    			    	found++;
    				}
    		}
    		if(found >= 1) {
    			return true;
    		}
        	return false;
    	}
        
    	public boolean contains(BankItem bankItem) {
    		for (int i = 0; i < bankItems.size(); i++)
    			if (bankItems.get(i) != null)
    				if (bankItems.get(i).getId() == bankItem.getId())
    					return true;
    		return false;
    	}
    
    	public boolean containsAmount(BankItem bankItem) {
    		for (int i = 0; i < bankItems.size(); i++)
    			if (bankItems.get(i) != null)
    				if (bankItems.get(i).getId() == bankItem.getId())
    					return bankItems.get(i).getAmount() >= bankItem.getAmount();
    		return false;
    	}
    
    	public boolean spaceAvailable(BankItem bankItem, int offset) {
    		for (int i = 0; i < bankItems.size(); i++)
    			if (bankItems.get(i) != null)
    				if (bankItems.get(i).getId() == bankItem.getId())
    					return bankItems.get(i).getAmount() + offset < Integer.MAX_VALUE;
    		return false;
    	}
    
    	public boolean spaceAvailable(BankItem bankItem) {
    		for (int i = 0; i < bankItems.size(); i++)
    			if (bankItems.get(i) != null)
    				if (bankItems.get(i).getId() == bankItem.getId())
    					return bankItems.get(i).getAmount() + bankItem.getAmount() < Integer.MAX_VALUE ? true : false;
    		return true;
    	}
    
    	public int getItemAmount(BankItem bankItem) {
    		for (BankItem item : bankItems)
    			if (item.getId() == bankItem.getId())
    				return item.getAmount();
    		return 0;
    	}
    
    	public BankItem getItem(int slot) {
    		if (slot < 0 || slot > bankItems.size()) {
    			return null;
    		}
    		return bankItems.get(slot);
    	}
    
    	public BankItem getItem(BankItem item) {
    		for (BankItem items : bankItems)
    			if (items.getId() == item.getId())
    				return items;
    		return null;
    	}
    
    	public void setItem(int slot, BankItem item) {
    		bankItems.set(slot, item);
    	}
    
    	public List<BankItem> getItems() {
    		return bankItems;
    	}
    
    	public int getTabId() {
    		return tabId;
    	}
    
    	public void setTabId(int tabId) {
    		this.tabId = tabId;
    	}
    
    }


    The following method has an example of the usage of the contains method in BankTab.java. The method is used to remove items from the bank.
    Spoiler for removeItem Method:
    Code:
    public void removeItem(int itemId, int amount) {
    		if (!tab.contains(new BankItem(itemId + 1, amount))) {
    			return;
    		}
    		for(BankTab tab : player.getBank().getBankTab()) {
    			for(BankItem bankItem : tab.getItems()) {
    				if(itemId == bankItem.getId() - 1) {
    					player.getBank().setCurrentBankTab(tab);
    					player.getItems().removeFromBank(itemId, amount, false);
    					break;
    				}
    			}
    		}
    		player.getBank().setCurrentBankTab(tab);
    		updateItems();
    		player.getItems().resetBank();
    	}

    I would appreciate any help, but I would like to understand the process if you have the time to explain it.

    Thank you for your time,
    Tyler
    Quote Originally Posted by Eazy View Post
    Quote Originally Posted by lostlegend View Post
    its not os-legacy its switched to Project-Insanity.
    And Very Much i ReCoded MEself. Check it out and u wil see ur self.
    People allways bothering with saying OS-LEGACY.. U NEVER CHECKED SERVERDONT COMPLAIN CHECK IT OUT B4 COMPLAINING
    So you switched Project-Insanity to Project-Insanity? gj
    Reply With Quote  
     

  2. #2  
    Exiles Developer


    Join Date
    May 2009
    Age
    28
    Posts
    316
    Thanks given
    55
    Thanks received
    25
    Rep Power
    86
    Last bump before I give up on this and just use player saved variables.
    Quote Originally Posted by Eazy View Post
    Quote Originally Posted by lostlegend View Post
    its not os-legacy its switched to Project-Insanity.
    And Very Much i ReCoded MEself. Check it out and u wil see ur self.
    People allways bothering with saying OS-LEGACY.. U NEVER CHECKED SERVERDONT COMPLAIN CHECK IT OUT B4 COMPLAINING
    So you switched Project-Insanity to Project-Insanity? gj
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Bank Searching
    By Gershon in forum Snippets
    Replies: 10
    Last Post: 05-23-2013, 05:20 PM
  2. [PI] Bank Searching
    By Women in forum Selling
    Replies: 7
    Last Post: 02-08-2012, 11:09 PM
  3. [PI] Bank Inventory Method-Reduce Lag
    By Hoodlum in forum Help
    Replies: 7
    Last Post: 08-26-2011, 10:29 AM
  4. [PI] Bank Inventory Method
    By Hoodlum in forum Requests
    Replies: 3
    Last Post: 05-21-2011, 09:41 AM
  5. Replies: 4
    Last Post: 07-25-2010, 08:52 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •