本文整理匯總了PHP中pocketmine\math\Math::solveQuadratic方法的典型用法代碼示例。如果您正苦於以下問題:PHP Math::solveQuadratic方法的具體用法?PHP Math::solveQuadratic怎麽用?PHP Math::solveQuadratic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\math\Math
的用法示例。
在下文中一共展示了Math::solveQuadratic方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getLevelFromXp
/**
* 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];
}