This commit is contained in:
aozhiwei 2021-12-17 14:59:12 +08:00
parent ebdbd71f6c
commit 4757cbf4a3
3 changed files with 46 additions and 2 deletions

View File

@ -40,8 +40,8 @@ class Battle(object):
['weapons_slot', '', '武器信息 weapon_id:use_times|'],
['heros', '', '武器信息 hero_id:skill_lv:weapon_lv|'],
#['rank_score', 0, '排位积分'],
['pass_score', 0, '通行证积分'],
['rank_score', 0, '排位积分'],
#['pass_score', 0, '通行证积分'],
['items', 0, '道具|分割'],
],
'response': [

View File

@ -16,6 +16,26 @@ class Rank {
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) {

View File

@ -5,6 +5,7 @@ namespace services;
require_once('mt/Item.php');
require_once('mt/Equip.php');
require_once('mt/Season.php');
require_once('mt/Rank.php');
require_once('models/Season.php');
require_once('models/Battle.php');
@ -32,6 +33,7 @@ class BattleDataService extends BaseService {
if (!$this->seasonDb) {
return;
}
$this->updateScore();
$hisBattleData = Battle::getMyBattleData();
if (!isset($hisBattleData)) {
$hisBattleData = array(
@ -241,4 +243,26 @@ class BattleDataService extends BaseService {
$battleData[$key] = max(getXVal($battleData, $key, 0), $val);
}
private function updateScore()
{
$userInfo = myself()->_getOrmUserInfo();
$rankScore = getReqVal('rank_score', 0);
if ($rankScore > 0) {
$newRank = $userInfo['rank'];
$newScore = $userInfo['score'];
mt\Rank::calcNewRankAndScore($userInfo['rank'], $userInfo['score'], $newRank, $newScore, $rankScore);
if ($newRank >= $userInfo['rank'] && $newScore != $userInfo['score']) {
myself()->_updateUserInfo(array(
'rank' => $newRank,
'score' => $newScore,
'history_best_rank' => max($userInfo['rank'], $newRank)
));
Season::update($this->currSeasonMeta['id'], array(
'rank' => $newRank,
'score' => $newScore
));
}
}
}
}