50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace mt;
|
|
|
|
use phpcommon;
|
|
|
|
class Rank {
|
|
|
|
public static function get($id)
|
|
{
|
|
return getXVal(self::getMetaList(), $id);
|
|
}
|
|
|
|
public static function getInitRank()
|
|
{
|
|
return self::get(1);
|
|
}
|
|
|
|
public static function calcNewRankAndScore($oldRank, $oldScore, &$newRank, &$newScore, $addScore)
|
|
{
|
|
$currRankMeta = self::get($oldRank);
|
|
if ($currRankMeta && $currRankMeta['max_score'] > 0) {
|
|
$newScore = min($oldScore, $currRankMeta['max_score']) + $addScore;
|
|
do {
|
|
if ($newScore > $currRankMeta['max_score']) {
|
|
++$newRank;
|
|
$currRankMeta = self::get($newRank);
|
|
if ($currRankMeta['max_score'] < 0) {
|
|
$newScore = $currRankMeta['min_score'];
|
|
break;
|
|
}
|
|
} else {
|
|
break;
|
|
}
|
|
} while ($currRankMeta);
|
|
}
|
|
}
|
|
|
|
protected static function getMetaList()
|
|
{
|
|
if (!self::$metaList) {
|
|
self::$metaList = getMetaTable('rank@rank.php');
|
|
}
|
|
return self::$metaList;
|
|
}
|
|
|
|
protected static $metaList;
|
|
|
|
}
|