This commit is contained in:
aozhiwei 2022-11-21 11:51:13 +08:00
commit 702b2ee4c3
6 changed files with 174 additions and 46 deletions

View File

@ -60,8 +60,56 @@ class BattleController extends BaseAuthedController {
if ($data) {
$teamList = $data['team_list'];
}
error_log(json_encode($teamList));
// $teamList = array(
// array(
// "team_id" => 10001,
// 'members' => array(
// array(
// 'account_id'=>'6000_2006_test1111',
// ),
// array(
// 'account_id'=>'6513_2006_dYayfOVObW0KpfXhNr1enZ92rkaxmu3c',
// ),
// array(
// 'account_id'=>'6513_2006_6000_2006_test1111',
// ),
// )
// ),
// array(
// "team_id" => 10002,
// 'members' => array(
// array(
// 'account_id'=>'6513_2006_oUnnMgxxU5apjZVF8tSOQnHhIXzLuAzT',
// ),
// array(
// 'account_id'=>'6513_2006_DmQHkZp0hoqvmSBwCvP6Z0Bru7WhU1fN',
// ),
// array(
// 'account_id'=>'6513_2006_1Ul37E5eNO905laoE1kA9lvC1ydplC0m',
// ),
// )
// ),
// array(
// "team_id" => 10003,
// 'members' => array(
// array(
// 'account_id'=>'6513_2006_6jJQLHhVbdyi83FJW1k4QiGPoXs12bBD',
// ),
// array(
// 'account_id'=>'6000_2006_DmQHkZp0hoqvmSBwCvP6Z0Bru7WhU1fN',
// ),
// array(
// 'account_id'=>'6000_2006_1Ul37E5eNO905laoE1kA9lvC1ydplC0m',
// ),
// array(
// 'account_id'=>'6000_2006_qqqqwwwwweeee',
// ),
// )
// ),
// );
$battleDataService = new services\BattleDataService();
$battleDataService->teamList = $teamList;
$battleDataService->updateBattleData();
SqlHelper::insert(
$this->_getSelfMysql(),
@ -77,10 +125,16 @@ class BattleController extends BaseAuthedController {
$data = array(
'reward' => $battleDataService->getReward()
);
if (getReqVal('match_mode', 0) == services\BattleDataService::MATCH_MODE_PVP && mt\RankSeason::getCurrentSeason()){
if ( getReqVal('match_mode', 0) == services\BattleDataService::MATCH_MODE_PVP
&& mt\RankSeason::getCurrentSeason()
&& myself()->_getV(TN_RANK_STATUS, 0 ) == 0 ){
$newRank = $userInfo['rank'];
$newScore = \services\FormulaService::calcBattleAfterRankScore($userInfo,$_REQUEST);
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
$newScore = $userInfo['score'];
$winningPro = $battleDataService->celWinningPro();
if ($winningPro){
$newScore = \services\FormulaService::calcBattleAfterRankScore($userInfo,$_REQUEST,$winningPro);
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
}
$scoreInfo = array(
'old_rank' => $userInfo['rank'],
'old_score' => $userInfo['score'],

View File

@ -359,9 +359,12 @@ class Chip extends BaseModel
$chipIdsArr = explode('|',$chip_ids);
foreach ($chipIdsArr as $val){
// $chip = self::toDto(self::getChipByIdx($val));
$chip = self::toDto(self::getChipByTokenId($val));
foreach ($chip['rand_attr'] as $v){
array_push($chipAttr,$v);
$row = self::getChipByTokenId($val);
if ($row){
$chip = self::toDto($row);
foreach ($chip['rand_attr'] as $v){
array_push($chipAttr,$v);
}
}
}
$item = [];

View File

@ -38,8 +38,10 @@ require_once('services/LogService.php');
use models\Chip;
use models\Nft;
use models\NftActive;
use models\User;
use mt;
use services;
use phpcommon;
use phpcommon\SqlHelper;
use models\Season;
use models\Battle;
@ -60,6 +62,8 @@ class BattleDataService extends BaseService {
const MATCH_MODE_MATCH = 1;
const MATCH_MODE_PVE = 2;
public $teamList = array();
private $seasonDb = array();
private $heroDto = null;
private $heroMeta = null;
@ -192,9 +196,12 @@ class BattleDataService extends BaseService {
$newRank = $user['rank'];
$newScore = $user['score'];
$match_mode = getReqVal('match_mode', 0);
if (mt\RankSeason::getCurrentSeason() && !$match_mode && myself()->_getV(TN_RANK_STATUS, 0 ) != 1){
$newScore = FormulaService::calcBattleAfterRankScore($user,$_REQUEST); //赛后排位积分
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
if (mt\RankSeason::getCurrentSeason() && !$match_mode && myself()->_getV(TN_RANK_STATUS, 0 ) == 0 ){
$winningPro = $this->celWinningPro();
if ($winningPro){
$newScore = FormulaService::calcBattleAfterRankScore($user,$_REQUEST,$winningPro); //赛后排位积分
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
}
$match_mode = 1;
}
$data = array(
@ -219,10 +226,7 @@ class BattleDataService extends BaseService {
"pve_instance_id" => getReqVal('pve_instance_id', 0),
"pve_instance_mode" => getReqVal('pve_instance_mode', 0),
);
$res = BattleHistory::add($data);
if (! $res){
error_log('############## insert Battle History failed #################');
}
BattleHistory::add($data);
}
public function getReward()
@ -464,32 +468,99 @@ class BattleDataService extends BaseService {
{
$userInfo = myself()->_getOrmUserInfo();
$newRank = $userInfo['rank'];
$newScore = FormulaService::calcBattleAfterRankScore($userInfo,$_REQUEST); //赛后排位积分
$newElo = FormulaService::calcUserEloValue($userInfo,$_REQUEST); //赛后elo积分
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
if ( $newScore != $userInfo['score'] ) {
myself()->_updateUserInfo(array(
'rank' => $newRank,
'score' => $newScore,
'elo' => $newElo,
'history_best_rank' => max($userInfo['rank'], $newRank),
'history_best_score' => max($userInfo['score'], $newScore),
'score_modifytime' => myself()->_getNowTime(),
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
));
Season::update($this->currSeasonMeta['id'], array(
'rank' => $newRank,
'score' => $newScore,
'elo' => $newElo,
'history_best_rank' => max($userInfo['rank'], $newRank),
'score_modifytime' => myself()->_getNowTime(),
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
));
$winningPro = $this->celWinningPro();
if ($winningPro){
$newScore = FormulaService::calcBattleAfterRankScore($userInfo,$_REQUEST,$winningPro); //赛后排位积分
$newElo = FormulaService::calcUserEloValue($userInfo,$_REQUEST,$winningPro); //赛后elo积分
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
if ( $newScore != $userInfo['score'] ) {
myself()->_updateUserInfo(array(
'rank' => $newRank,
'score' => $newScore,
'elo' => $newElo,
'history_best_rank' => max($userInfo['rank'], $newRank),
'history_best_score' => max($userInfo['score'], $newScore),
'score_modifytime' => myself()->_getNowTime(),
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
));
Season::update($this->currSeasonMeta['id'], array(
'rank' => $newRank,
'score' => $newScore,
'elo' => $newElo,
'history_best_rank' => max($userInfo['rank'], $newRank),
'score_modifytime' => myself()->_getNowTime(),
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
));
}
}
}
public function celWinningPro(){
$team_id = getReqVal('team_id', 0);
if (empty($this->teamList) || ! count($this->teamList)){
error_log('ELO1-----没获取到所有队伍信息:AllTeamList');
return false;
}
$userInfo = myself()->_getOrmUserInfo();
$myAvg = 0;
$opponentAvg = 0;
$teamIdHash = array();
foreach ($this->teamList as &$team){
foreach ($team['members'] as $k=>$member){
if (!empty($member['account_id'])){
$channelId = phpcommon\extractChannel($member['account_id']);
if ($channelId == SELFSDK_CHANNEL) {
unset($team['members'][$k]);
}
}else{
unset($team['members'][$k]);
}
}
$teamIdHash[$team['team_id']] = $team;
}
$myTeam = array_key_exists($team_id,$teamIdHash)?$teamIdHash[$team_id]:null;
unset($teamIdHash[$team_id]);
if (!$myTeam){
error_log('ELO2-----没获取到我的队伍信息:MyTeamList');
return false;
}
$myTeamEloSum = 0;
foreach ($myTeam['members'] as $value){
$userDb = User::find($value['account_id']);
$myTeamEloSum+=$userDb['elo'];
}
$myAvg = $myTeamEloSum/count($myTeam['members']);
$tempSumList = array();
foreach ($teamIdHash as $k=>&$item){
if ($team_id != $item['team_id'] && count($item['members'])>0){
$tempSum = 0;
foreach ($item['members'] as $value){
$userDb = User::find($value['account_id']);
$tempSum += $userDb['elo'];
}
array_push($tempSumList,$tempSum/count($item['members']));
}
}
if (count($tempSumList) > 0){
$opponentAvg = array_sum($tempSumList)/count($tempSumList);
//总胜率=70%*P(个人ELO值-敌队平均ELO值)+30%*P(己队平均ELO值-敌队平均ELO值) --> P(D)=1/(1+10^(-D/400))
$winningPro = 1/(1+pow(10,(-(0.7*($userInfo['elo']-$opponentAvg)+0.3*($myAvg-$opponentAvg))/400)));
}else{
error_log('ELO3-----无真人敌对队伍');
$winningPro = 0.5;
}
error_log(json_encode(
array(
'myElo' =>$userInfo['elo'],
'myAvg' => $myAvg,
'myTeam' =>$myTeam,
'opponentAvg'=>$tempSumList,
'winningPro' => $winningPro,
)
));
return $winningPro;
}
private function rewardGold($heroDto)
@ -555,7 +626,6 @@ class BattleDataService extends BaseService {
private function updatePvpData()
{
error_log('updateBattleData2');
$hisBattleData = Battle::getMyBattleData();
if (!isset($hisBattleData)) {
@ -569,7 +639,7 @@ class BattleDataService extends BaseService {
error_log('updateBattleData3');
$this->currSeasonMeta = mt\RankSeason::getCurrentSeason();
if ( $this->currSeasonMeta && myself()->_getV(TN_RANK_STATUS, 0 ) != 1) {
if ( $this->currSeasonMeta && myself()->_getV(TN_RANK_STATUS, 0 ) == 0) {
$this->seasonDb = Season::find($this->currSeasonMeta['id']);
if (!$this->seasonDb) {
Season::add($this->currSeasonMeta['id']);
@ -580,7 +650,6 @@ class BattleDataService extends BaseService {
}
error_log('updateBattleData4');
$this->updateScore();
$seasonBattleData = json_decode($this->seasonDb['battle_data'], true);
if (!isset($seasonBattleData['today_data'])) {
$seasonBattleData['today_data'] = array(

View File

@ -321,7 +321,7 @@ class FormulaService extends BaseService {
return 0;
}
public static function calcBattleAfterRankScore($userDb,$params){
public static function calcBattleAfterRankScore($userDb,$params,$winningPro){
/**一个玩家的赛后积分 = 赛前积分+K*(胜负率-总胜率)+2K*(表现分-段位要求的及格分)*/
//胜负率=1-(排名-1)/(最大排名-1)
$ranked = getXVal($params, 'ranked');
@ -329,7 +329,7 @@ class FormulaService extends BaseService {
$maxRanked = $meta1 ? $meta1['param_value'] : 40; //************** parameter 参数表获取 ************
$winRate = 1-($ranked-1)/($maxRanked-1);
//总胜率=70%*P(个人ELO值-敌队平均ELO值)+30%*P(己队平均ELO值-敌队平均ELO值) --> P(D)=1/(1+10^(-D/400))
$winRateSum = 1;
$winRateSum = $winningPro;
//表现分=f(全局排名Top X%)*50%+f(PK人数排名Top X%)*30%+f(存活时间排名Top X%)*15%+f(英雄阶数排名Top X%)*3%+f(枪械阶数排名Top X%)*2% --> f(Top X%) = ROUND(1-(X/10-1)/9,2)
$rankedTopX = getXVal($params, 'ranked_topx');
$killsTopX = getXVal($params, 'kills_topx');
@ -351,7 +351,7 @@ class FormulaService extends BaseService {
return round($battleAfterScore);
}
public static function calcUserEloValue($userDb,$params){
public static function calcUserEloValue($userDb,$params,$winningPro){
/**一个玩家的赛后ELO值 = MAX(赛前ELO值+K*(胜负率-总胜率),150)*/
//胜负率=1-(排名-1)/(最大排名-1)
$ranked = getXVal($params, 'ranked');
@ -359,7 +359,7 @@ class FormulaService extends BaseService {
$maxRanked = $meta1 ? $meta1['param_value'] : 40; //************** parameter 参数表获取 ************
$winRate = 1-($ranked-1)/($maxRanked-1);
//总胜率=70%*P(个人ELO值-敌队平均ELO值)+30%*P(己队平均ELO值-敌队平均ELO值) --> P(D)=1/(1+10^(-D/400))
$winRateSum = 1;
$winRateSum = $winningPro;
$meta2 = mt\Parameter::getByName('rank_k');
$K = $meta2 ? $meta2['param_value'] : 30; //************** parameter 参数表获取 ************
return round(max($userDb['elo']+$K*($winRate-$winRateSum),150));

View File

@ -593,9 +593,11 @@ class MissionService extends BaseService {
}
$metas = mt\Task::getOfferRewardMissions
($this->offerRewartdMission['missions']);
error_log(json_encode($metas));
if (count($metas)<1) {
return;
}
error_log(json_encode('Mission Number ___'.count($metas)));
$count = count($metas)>=5 ? 5 : count($metas);
foreach (array_rand($metas, $count) as $key) {
$meta = $metas[$key];

View File

@ -50,7 +50,7 @@ class RankActivityService extends BaseService {
error_log(
json_encode(array(
'account_id' => $userDb['account_id'],
'themeType' => $currentRankingMeta['themeType'],
'themeType' => $currentRankingMeta?$currentRankingMeta['themeType']:null,
'kill' => getReqVal('kills', 0),
'ranked' => getReqVal('ranked', 0),
'ceg'=>$gold