solveQuadratic() public static method

public static solveQuadratic ( $a, $b, $c ) : array
return array
Esempio n. 1
0
 /**
  * Converts a quantity of exp into a level and a progress percentage
  *
  * @param int $xp
  *
  * @return int[]
  */
 public static function getLevelFromXp(int $xp) : array
 {
     $xp &= 0x7fffffff;
     /** These values are correct up to and including level 16 */
     $a = 1;
     $b = 6;
     $c = -$xp;
     if ($xp > self::getTotalXpRequirement(16)) {
         /** Modify the coefficients to fit the relevant equation */
         if ($xp <= self::getTotalXpRequirement(31)) {
             /** Levels 16-31 */
             $a = 2.5;
             $b = -40.5;
             $c += 360;
         } else {
             /** Level 32+ */
             $a = 4.5;
             $b = -162.5;
             $c += 2220;
         }
     }
     $answer = max(Math::solveQuadratic($a, $b, $c));
     //Use largest result value
     $level = floor($answer);
     $progress = $answer - $level;
     return [$level, $progress];
 }