kd8lvt

[JS][VERY BASIC]Pokemon Gen V+ Exp Gain Formula

Feb 28th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Used in my Discord bot. Free to be adapted to anyone's use. See https://bulbapedia.bulbagarden.net/wiki/Experience#Gain_formula for more info.
  2. function calculateXpGain(user,msg) {
  3.     msg = msg.replace(/ /g,"");
  4.    
  5.     var charCount = msg.length;
  6.     var xpBonus = Math.floor(Math.pow(charCount,1/3)); //Cube root of the message length (excluding spaces) Was giving thousands of XP for "test", hence the cube root :P
  7.    
  8.     if (xpBonus != 0) {
  9.         var plrLevel = getLevel(user); //Returns an integer
  10.  
  11.         console.log("[DEBUG]: Base XP for this message: "+xpBonus)
  12.  
  13.         var gain = Math.floor(((((1*xpBonus*2)/(5*1))*(Math.pow((2*2+10),2.5)/(Math.pow((2+plrLevel+10),2.5)))+1)*1*1*1) //Actual formula. Feel free to remove the "*1"s, they are there for consistency to the actual formula.
  14.        
  15.         if (charCount < config.minMsgLen) {
  16.             gain = Math.floor(gain/2); //If the message is less than the desired length, halve XP gain. (Default 10)
  17.         }
  18.         console.log("[DEBUG]: Total XP Gain for this message: "+gain+"XP");
  19.         return gain;
  20.     } else {
  21.         return 0; //No reason to use extra CPU time calculating 0 lol
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment