Thread: [OSRS Pk] Fixing the ItemContainer total wealth

Results 1 to 4 of 4
  1. #1 [OSRS Pk] Fixing the ItemContainer total wealth 
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    Cba to show pictures and stuff, just do a trade or open the price checker, and offer stuff over the integer max value..
    It overflows becoming negative, and so on, this fixes it pretty much completely.

    Still has a chance to overflow with a long, but common, 9 quintillion?



    In the ItemContainer class, replace your #getTotalValue method with this one;

    Code:
    	/**
    	 * Gets the total wealth of this container's items as a string.
    	 * @return
    	 */
    	public String getTotalValue() {
    		
    		int totalValue = 0;
    
    		for(Item item : getValidItems()) {
    			final long itemValues = item.getDefinition().getValue();
    			
    			if (itemValues + itemValues >= Integer.MAX_VALUE || itemValues + itemValues <= -1)
    				return "Too High!";
    			
    			if (totalValue + itemValues >= Integer.MAX_VALUE || totalValue + itemValues <= -1)
    				return "Too High!";
    			
    			if (itemValues * item.getAmount() >= Integer.MAX_VALUE || itemValues * item.getAmount() <= -1)
    				return "Too High!";
    			
    			else
    				totalValue += item.getDefinition().getValue() * item.getAmount();
    		}
    		return Misc.format(totalValue);
    	}

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  2. #2  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    Updated
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Thanks for the share.
    Reply With Quote  
     

  4. #4  
    Registered Member Hyped's Avatar
    Join Date
    Dec 2016
    Posts
    171
    Thanks given
    21
    Thanks received
    7
    Rep Power
    4
    Thanks for this
    learning, learning, learning, learning
    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. [Elvarg/OSRS PK]Fixing broken textures
    By Zion in forum Snippets
    Replies: 12
    Last Post: 08-11-2019, 11:55 AM
  2. Replies: 41
    Last Post: 08-08-2018, 01:31 PM
  3. Replies: 15
    Last Post: 07-21-2017, 03:06 PM
  4. How to fix the wierd object names in OSRS #108
    By 3pic f4il in forum Tutorials
    Replies: 10
    Last Post: 05-20-2016, 03:23 PM
  5. OSR PK - Run by the players
    By TheeRash in forum Projects
    Replies: 39
    Last Post: 01-16-2016, 04:40 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •