Thread: Cant figure out this simple fix

Results 1 to 3 of 3
  1. #1 Cant figure out this simple fix 
    Donator


    Join Date
    Nov 2008
    Posts
    885
    Thanks given
    13
    Thanks received
    35
    Rep Power
    100
    Anyways i'm adding a polypore staff to a 317, the staff has a maximum 3000 charges and can be recharged with 5 fire runes per 1 charge, so 15000 fire runes to fully recharge, well my problem is like if you have 200 charges left on the staff and then you take like 15000 fire runes and use it on the staff itll add to 3200 instead of 3000, i for the life of me cannot figure this simple thing out and am getting frustrated, please do not flame me as i already understand that i have failed on this lol.

    Code:
    if(c.ppsLeft < 3000 && itemUsed == 554 && useWith == 12494 || c.ppsLeft < 3000 && itemUsed == 12494 && useWith == 554) {
    			int getFireRune = c.getItems().getItemSlot(554);
    			int getAmount =  c.getItems().getItemAmount(554) / 5 ;
    			int staffCharge = (3000 - c.ppsLeft) * 5; 
    			int staffRecharge = 3000 - (c.ppsLeft + getAmount); 
    			//int ppsRunes = (15000 - (3000 - c.ppsLeft) / 5;
    			c.getItems().deleteItem(554, c.getItems().getItemSlot(554), staffCharge);
    			c.ppsLeft += (3000 - staffRecharge);
    			c.sendMessage("You have recharged your Polypore Staff");
    			c.sendMessage("You have " + c.ppsLeft + " charges left!");
    		} else if (c.ppsLeft >= 3000 && itemUsed == 554 && useWith == 12494 || itemUsed == 12494 && useWith == 554) {
    			c.sendMessage("Your Polypore staff is already fully charged!");
    		}
    that is my itemonitem, i have tried multiple math sequences to get this correct so dont mind what it is now. i am not that good at math ><
    Reply With Quote  
     

  2. #2  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    Let's break this down:
    ----(A) newCharges = oldCharges + chargesToAdd
    ----(B) newCharges <= MAX_CHARGES
    Therefore (A) = (B):
    ----(C) oldCharges + chargesToAdd <= MAX_CHARGES
    Move oldCharges to the right:
    ----(D) chargesToAdd <= MAX_CHARGES - oldCharges
    to add 1 charge, you need 5 fire runes:
    ----(E) chargesToAdd * 5 = fireRunesToAdd
    ----(F) chargesToAdd = fireRunesToAdd / 5
    Insert (F) in (D):
    ----(G) fireRunesToAdd/5 <= (MAX_CHARGES - oldCharges)
    ----(H) fireRunesToAdd <= (MAX_CHARGES - oldCharges) * 5

    (G) or (H) is our formula to test:
    If you fill in the variables you know (fireRunesToAdd, MAX_CHARGES, oldCharges) you can test if the condition is true
    If so, then there will be no overflow and you can add:
    Math.floor(fireRunesToAdd / 5) charges
    while taking:
    fireRunesToAdd - fireRunesToAdd % 5

    The last one can also be written as chargesToAdd * 5, when chargesToAdd is the number calculated by the Math.Floor(int) code.
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Donator


    Join Date
    Nov 2008
    Posts
    885
    Thanks given
    13
    Thanks received
    35
    Rep Power
    100
    Ah thank you so much for the detailed response, and thanks for actually explaining it and not just giving me a fix.
    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. Replies: 2
    Last Post: 03-01-2010, 01:36 AM
  2. cant figure this out...
    By 0runu in forum Help
    Replies: 4
    Last Post: 11-04-2009, 05:20 AM
  3. Cant figure it out...
    By solcrystal in forum Help
    Replies: 1
    Last Post: 08-04-2009, 10:35 AM
  4. Simple Error I cant Figure out...
    By Senthery in forum Help
    Replies: 5
    Last Post: 04-11-2009, 09:22 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
  •