array( 'hero_uniid' => '', 'gold_uplimit' => 0, 'obtain_gold' => 0, 'curr_gold' => 0, ), 'total_ceg' => 0, 'items' => array(), ); private $teamReward = array(); private $seasonDb = array(); private $currSeasonMeta = null; public function updateBattleData() { error_log('updateBattleData'); $matchMode = getXVal($this->allInfo,'room_mode', 0); $userInfo = myself()->_getOrmUserInfo(); if (!$userInfo){ return false; } $this->userInfo = $userInfo; $heroDb = Hero::find(getXVal($this->battleInfo,'hero_uniid', 0)); if (!$heroDb) { return false; } $this->heroDto = Hero::toDto($heroDb); $heroMeta = mt\Hero::get($this->heroDto['hero_id']); if (!$heroMeta) { return false; } //录入战斗记录 // $this->saveBattleHistory(); switch ($matchMode) { //PVP模式 case self::ROOM_MODE_PVP: { $pvpMode = getXVal($this->allInfo,'pvp_match_mode', 0); switch ($pvpMode){ case self::MATCH_MODE_PVP: { //匹配赛模式 $this->updatePvpData(); $this->settlementReward(); myself()->_incDailyV(TN_DAILY_PVP_BATTLE_TIMES, 0, 1); } break; case self::MATCH_MODE_RANK: { //排位赛 $this->updatePvpData(); $this->updateRankData(); $this->updateScore(); $this->settlementReward(); myself()->_incDailyV(TN_DAILY_RANK_BATTLE_TIMES, 0, 1); } break; default:{} break; } //记录战斗数据的排行榜 $this->recordBattleRanking(); // //结算用户star数量 // $this->rewardStarNum(); } break; //PVE模式 case self::ROOM_MODE_PVE: { //pve $this->updatePveData(); if ($this->pveGeminiMeta ) { $this->rewardFragmentPve(); } myself()->_incDailyV(TN_DAILY_PVE_BATTLE_TIMES, 0, 1); } break; default: { } break; } } // //每局战斗结算star数量 // private function rewardStarNum(){ // $paramMeta = mt\Parameter::getByName('star_get_num'); // if ($paramMeta){ // $star_get_num = getXVal($paramMeta,'param_value', 0); // $num_arr = explode('|',$star_get_num); // $rank = getXVal($this->battleInfo,'pvp_personal_rank', 0); // if ($rank>count($num_arr) || $rank<1){ // $finalNum = 0; // }else{ // $finalNum = $this->calFinalStarNum($num_arr[$rank-1]); // } // $items = array( // array( // 'item_id'=>V_ITEM_STAR, // 'item_num'=>$finalNum // ) // );print_r($items); // $propertyChgService = new services\PropertyChgService(); // $awardService = new services\AwardService(); //// myself()->_addItems($items, $awardService,$propertyChgService); // myself()->_incDailyV(TN_DAILY_GET_STAR_NUM, 0,$finalNum); // } // } //记录战斗数据的排行榜 private function recordBattleRanking(){ $account = getXVal($this->battleInfo,'account_id', 0); //游戏场次 (存活30S算有效场次) if (getXVal($this->battleInfo,'pvp_survia_time', 0)/1000 > 30 && getXVal($this->battleInfo,'abandon_battle', 0) == 0){ RankBattle::upsert($account,RankBattle::GAME_TIMES,1); } //吃鸡数 //pvp_team_rank if (getXVal($this->allInfo,'pvp_team_rank', 0) == 1){ RankBattle::upsert($account,RankBattle::WIN_TIMES,1); } //mvp if (getXVal($this->battleInfo,'is_mvp', 0) == 1){ RankBattle::upsert($account,RankBattle::MVP_TIMES,1); } //前三 if (getXVal($this->allInfo,'pvp_team_rank', 0) <= 3){ RankBattle::upsert($account,RankBattle::TOP_THREE_TIMES,1); } //击杀 if (getXVal($this->battleInfo,'pvp_kill', 0) > 0){ RankBattle::upsert($account,RankBattle::KILL_TIMES,getXVal($this->battleInfo,'pvp_kill', 0)); } } private function updatePveData() { error_log('updatePveData'); $instanceId = getXVal($this->allInfo,'pve_instance_id', 0); $pveRankScore = getXVal($this->battleInfo,'pve_score', 0); $pveBossKilled = getXVal($this->battleInfo,'pve_boss_killed', 0); $userInfo = myself()->_getOrmUserInfo(); $this->pveGeminiMeta = mt\PveGemini::get($instanceId); if ($this->pveGeminiMeta) { if (!( ($instanceId == mt\PveGemini::FIRST_INSTANCE_ID && $userInfo['pve_instance_id'] == 0 ) || $userInfo['pve_instance_id'] == $instanceId || $userInfo['pve_instance_id'] + 1 == $instanceId) ) { $this->pveGeminiMeta = null; } } // $this->pveGeminiModeMeta = mt\PveGeminiMode::get($instanceMode); // if ($this->pveGeminiModeMeta) { // $this->instanceRank = mt\PveGeminiMode::calcStar($this->pveGeminiModeMeta, $pveRankScore); // } if ($pveBossKilled == 1) { if ($this->pveGeminiMeta) { myself()->_updateUserInfo(array( 'pve_instance_id' => $instanceId )); } } } private function rewardFragmentPve() { error_log('rewardFragmentPve'); $bossReward = getXVal($this->battleInfo,'pve_boss_killed', 0) ? 1 : 0; if ( !$bossReward) { return; } $dropRate = $this->pveGeminiMeta['drop_rate']; $todayPveGetHeroFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_HERO_FRAGMENT_NUM, 0); $todayPveGetGunFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_GUN_FRAGMENT_NUM, 0); $reward = array(); if ($todayPveGetHeroFragmentNum < self::MAX_DROP_NUM) { $gamesNum = FragmentRecord::getGamesNum(FragmentRecord::HERO_FRAGMENT); $rate = $dropRate*($gamesNum+1); if (rand(1,100) < $rate*100){ $dropHeroFragmentId = $this->randWeight2(1); $this->drop($reward,$dropHeroFragmentId,1); FragmentRecord::upsertGamesNum(FragmentRecord::HERO_FRAGMENT,0); }else{ FragmentRecord::upsertGamesNum(FragmentRecord::HERO_FRAGMENT,$gamesNum+1); } } if ($todayPveGetGunFragmentNum < self::MAX_DROP_NUM) { $gamesNum = FragmentRecord::getGamesNum(FragmentRecord::GUN_FRAGMENT); $rate = $dropRate*($gamesNum+1); if (rand(1,100) < $rate*100){ $dropGunFragmentId = $this->randWeight2(2); $this->drop($reward,$dropGunFragmentId,2); FragmentRecord::upsertGamesNum(FragmentRecord::GUN_FRAGMENT,0); }else{ FragmentRecord::upsertGamesNum(FragmentRecord::GUN_FRAGMENT,$gamesNum+1); } } if ($reward){ //记录获得得碎片奖励 $battle_uuid = getXVal($this->allInfo,'battle_uuid', 0); $room_uuid = getXVal($this->allInfo,'room_uuid', 0); $db = BattleSettlement::findTeam($battle_uuid,$room_uuid); if ($db){ $data = emptyReplace(json_decode($db['data'], true), array()); if ($data){ foreach ($data['members'] as &$member){ if ($member['account_id'] == myself()->_getAccountId()){ $member['reward']['items'] = $reward; } } } BattleSettlement::addTeam($battle_uuid,$room_uuid,$data); } } } private function randWeight2($type){ $itemMeta = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE); $heroFragment = array(); $gunFragment = array(); foreach ($itemMeta as $meta){ if ($meta['sub_type'] == 3 || $meta['sub_type'] == 1){ array_push($heroFragment,$meta['id']); } if ($meta['sub_type'] == 4 || $meta['sub_type'] == 2){ array_push($gunFragment,$meta['id']); } } $weightRate = array( array(0,4), array(1,12), array(2,12), array(3,12), array(4,12), array(5,12), array(6,12), array(7,12), array(8,12), ); $weight = 0; $tempData = array (); foreach ($weightRate as $one) { $weight += $one[1]; for ($i = 0; $i < $one[1]; $i++) { $tempData[] = $one; } } $key = $tempData[rand(0, $weight -1)][0]; switch ($type){ case 1:return $heroFragment[$key]; case 2:return $gunFragment[$key]; default:return null; } } private function drop(&$reward,$itemId,$type){ $itemMeta = mt\Item::get($itemId); if ($itemMeta){ $propertyChgService = new services\PropertyChgService(); $awardService = new services\AwardService(); array_push($reward, array( 'item_id' => $itemId, 'item_num' => 1 )); myself()->_addItems( array( array( 'item_id' => $itemId, 'item_num' => 1 )), $awardService, $propertyChgService ); switch ($type){ case 1:myself()->_incDailyV(TN_DAILY_PVE_GET_HERO_FRAGMENT_NUM, 0, 1);break; case 2:myself()->_incDailyV(TN_DAILY_PVE_GET_GUN_FRAGMENT_NUM, 0, 1);break; } } } private function updatePvpData() { error_log('updatePvpData'); $hisBattleData = Battle::getMyBattleData(); if (!isset($hisBattleData['data'])) { $hisBattleData['data'] = array( 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); } if (!isset($hisBattleData['today_data'])) { $hisBattleData['today_data'] = array( 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); } if (!isset($hisBattleData['this_week_data'])) { $hisBattleData['this_week_data'] = array( 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); } //上局游戏数据 $hisBattleData['last_game_data'] = array( 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); if (myself()->_getDaySeconds($hisBattleData['today_data']['modifytime']) < myself()->_getNowDaySeconds()) { $hisBattleData['today_data'] = array( 'createtime' => $hisBattleData['today_data']['createtime'], 'modifytime' => myself()->_getNowTime() ); } if (myself()->_getDaySeconds($hisBattleData['this_week_data']['modifytime']) < myself()->_getMondaySeconds()) { $hisBattleData['this_week_data'] = array( 'createtime' => $hisBattleData['this_week_data']['createtime'], 'modifytime' => myself()->_getNowTime() ); } $this->apply($hisBattleData['last_game_data']); $this->apply($hisBattleData['today_data']); $this->apply($hisBattleData['this_week_data']); $oldDataKills = getXVal($hisBattleData['data'], 'total_kills_times', 0); $this->apply($hisBattleData['data']); $newDataKills = getXVal($hisBattleData['data'], 'total_kills_times', 0); if ($newDataKills > $oldDataKills) { Battle::update(array( 'kills_modifytime' => myself()->_getNowTime(), )); } Battle::add(json_encode($hisBattleData)); } public function addBattleSettlementSingle() { error_log('BattleSettlementSingle'); $pvp_mode = getXVal($this->allInfo,'pvp_match_mode', 0); $battleUuid = getXVal($this->allInfo,'battle_uuid', 0); $roomUuid = getXVal($this->allInfo,'room_uuid', 0); $newRank = $this->userInfo['rank']; $newScore = $this->userInfo['score']; if ($pvp_mode == self::MATCH_MODE_RANK){ myself()->_setV(TN_LAST_RANKING_TIME,0,getXVal($this->battleInfo,'game_time', 0)); $winningPro = $this->celWinningPro($this->userInfo); if ($winningPro){ $newScore = FormulaService::calcBattleAfterRankScore($this->userInfo,$this->battleInfo,$winningPro); //赛后排位积分 mt\Rank::calcNewRankAndScore( $newRank, $newScore); } } $data = array( "battle_uuid" => $battleUuid, "account_id" => getXVal($this->battleInfo,'account_id', 0), "room_mode" => getXVal($this->allInfo,'room_mode', 0), "pvp_mode" => $pvp_mode, "team_mode" => getXVal($this->allInfo,'team_mode', 0), "battle_rank" => getXVal($this->battleInfo,'pvp_personal_rank', 0), "team_rank" => getXVal($this->allInfo,'pvp_team_rank', 0), "team_kills" => getXVal($this->allInfo,'pvp_team_kills', 0), "is_win" => getXVal($this->battleInfo,'pve_boss_killed', 0), "kills" => getXVal($this->battleInfo,'kills', 0), "hero_id" => getXVal($this->battleInfo,'hero_uniid', 0), "weapon1" => getXVal($this->battleInfo,'weapon_uuid1', 0), "weapon2" => getXVal($this->battleInfo,'weapon_uuid2', 0), "battle_end_time" => getXVal($this->battleInfo,'game_time', 0), "current_level_class" => $newRank, "current_level_class_score" => $newScore, "level_class_score_chg" => $newScore - $this->userInfo['score'], // 排位分改变 "pve_rank_score" => getXVal($this->battleInfo,'pve_score', 0), "pve_kill_boss" => getXVal($this->battleInfo,'pve_boss_killed', 0), "pve_instance_id" => getXVal($this->allInfo,'pve_instance_id', 0), // "pve_instance_mode" => getXVal($this->allInfo,'pve_instance_mode', 0), ); BattleSettlement::addSingle($battleUuid,$roomUuid,$data); } public function addBattleSettlementTeam() { error_log('BattleSettlementTeam'); $room_mode = getXVal($this->allInfo,'room_mode', 0); switch ($room_mode){ case self::ROOM_MODE_PVP: { $team_mode = getXVal($this->allInfo,'pvp_settelement_type', 0); } break; case self::ROOM_MODE_PVE: { $team_mode = getXVal($this->allInfo,'pve_settelement_type', 0); } break; default: { $team_mode = null; } break; } $data = array( 'version'=> getXVal($this->allInfo,'version', 0), 'team_id'=> getXVal($this->allInfo,'team_id', 0), 'room_uuid'=> getXVal($this->allInfo,'room_uuid', 0), 'room_mode'=> getXVal($this->allInfo,'room_mode', 0), 'team_mode'=> $team_mode, 'game_over'=>1, 'victory'=> getXVal($this->allInfo,'victory', 0), 'watchable'=> 1, 'map_id'=> getXVal($this->allInfo,'map_id', 0), 'battle_uuid'=> getXVal($this->allInfo,'battle_uuid', 0), 'settlement_status'=>1, 'pvp_settlement_type'=> getXVal($this->allInfo,'pvp_settelement_type', 0), 'pvp_settlement_color'=> getXVal($this->allInfo,'pvp_settelement_color', 0), 'pvp_team_rank'=> getXVal($this->allInfo,'pvp_team_rank', 0), 'pvp_total_human_num'=> getXVal($this->allInfo,'pvp_total_human_num', 0), 'pvp_alive_human_num'=> getXVal($this->allInfo,'pvp_alive_human_num', 0), 'pvp_total_team_num'=> getXVal($this->allInfo,'pvp_total_team_num', 0), 'pvp_match_mode'=> getXVal($this->allInfo,'pvp_match_mode', 0), 'pve_settlement_color'=> getXVal($this->allInfo,'pve_settlement_color', 0), 'pve_wave'=> getXVal($this->allInfo,'pve_wave', 0), 'pve_max_wave'=> getXVal($this->allInfo,'pve_max_wave', 0), 'pve_instance_id'=> getXVal($this->allInfo,'pve_instance_id', 0), ); $data['members'] = array(); $pvp_mode = getXVal($this->allInfo,'pvp_match_mode', 0); foreach ($this->teamInfo as $info){ $info['team_rank'] = getXVal($this->allInfo,'pvp_team_rank', 0); $oldRank = 0; $newRank = 0; $oldScore = 0; $newScore = 0; $userDb = User::find(getXVal($info,'account_id', 0)); if ($userDb){ $oldRank = $userDb['rank']; $newRank = $userDb['rank']; $oldScore = $userDb['score']; $newScore = $userDb['score']; if ($pvp_mode == self::MATCH_MODE_RANK){ $heroDb = Hero::findByAccountId(getXVal($info,'account_id', 0),getXVal($info,'hero_uniid', 0)); if ($heroDb){ $winningPro = $this->celWinningPro($userDb); if ($winningPro){ $newScore = FormulaService::calcBattleAfterRankScore($userDb,$info,$winningPro); //赛后排位积分 mt\Rank::calcNewRankAndScore( $newRank, $newScore); } } } } $temp = array( 'account_id'=> getXVal($info,'account_id', 0), 'name'=> getXVal($info,'name', 0), 'head'=> getXVal($info,'head', 0), 'head_frame'=> getXVal($info,'head_frame', 0), 'sex'=> getXVal($info,'sex', 0), 'hero_uniid'=> getXVal($info,'hero_uniid', 0), 'hero_id'=> getXVal($info,'hero_id', 0), 'dead'=> getXVal($info,'dead', 0), 'is_mvp'=> getXVal($info,'is_mvp', 0), 'old_rank'=> $oldRank, 'new_rank'=> $newRank, 'old_score'=> $oldScore, 'new_score'=> $newScore, 'pvp_kill'=> getXVal($info,'pvp_kill', 0), 'pvp_damage'=> getXVal($info,'pvp_damage', 0), 'pvp_assist'=> getXVal($info,'pvp_assist', 0), 'pvp_survia_time'=> getXVal($info,'pvp_survia_time', 0), 'pvp_recover'=> getXVal($info,'pvp_recover', 0), 'pvp_rescue'=> getXVal($info,'pvp_rescue', 0), 'pvp_personal_rank'=> getXVal($info,'pvp_personal_rank', 0), 'pve_order'=> getXVal($info,'pve_order', 0), 'pve_score'=> getXVal($info,'pve_score', 0), 'pve_star'=> getXVal($info,'pve_star', 0), 'pve_damage'=> getXVal($info,'pve_damage', 0), 'pve_revive'=> getXVal($info,'pve_revive', 0), 'pve_survia_time'=> getXVal($info,'pve_survia_time', 0), 'pve_wave'=> getXVal($info,'pve_wave', 0), 'pve_max_wave'=> getXVal($info,'pve_max_wave', 0), 'pve_boss_killed'=> getXVal($info,'pve_boss_killed', 0), // 'pve_rank_score'=> getXVal($info,'pve_rank_score', 0), ); $temp['reward'] = array( 'hero' => array( 'hero_uniid' => '', 'id' => '', 'gold_uplimit' => 0, 'obtain_gold' => 0, 'curr_gold' => 0, ), 'items' => array(), ); switch ($room_mode){ case self::ROOM_MODE_PVP: { //pvp奖励 gold if ($userDb){ $this->calStarNum2($temp['reward'],getXVal($info,'pvp_personal_rank', 0)); $heroDb = Hero::findByAccountId(getXVal($info,'account_id', 0),getXVal($info,'hero_uniid', 0)); if (!$heroDb){ break; } $heroDto = Hero::toDto($heroDb); $temp['reward']['hero']['hero_uniid'] = $heroDto['hero_uniid']; $temp['reward']['hero']['id'] = $heroDto['hero_id']; $temp['reward']['hero']['gold_uplimit'] = $heroDto['gold_uplimit']; $this->rewardGoldPvp($temp['reward'],$heroDto,$userDb['rank']); } } break; case self::ROOM_MODE_PVE: { //pve 奖励碎片 // print_r($data);die; } break; default:{} } array_push($data['members'],$temp); } BattleSettlement::addTeam( getXVal($this->allInfo,'battle_uuid', 0), getXVal($this->allInfo,'room_uuid', 0), $data ); } private function rewardGoldPvp(&$reward,$heroDto,$userRank) { $heroPvpGold = FormulaService::calcHeroPvpGold($heroDto, $this->allInfo,$userRank); if ($heroPvpGold > 0) { $heroPvpGold = Hero::gainGoldPvp($heroDto, $heroPvpGold); $reward['hero']['curr_gold'] = '' . ($heroDto['current_get_gold'] + $heroPvpGold); $reward['hero']['obtain_gold'] = '' . ($heroDto['current_get_gold'] + $heroPvpGold); } if ($heroPvpGold > 0) { array_push($reward['items'],array( 'item_id'=> V_ITEM_GOLD, 'item_num'=>$heroPvpGold, )); } } public function calStarNum(){ $pvp_rank = getReqVal('pvp_personal_rank', 0); $paramMeta = mt\Parameter::getByName('star_get_num'); if ($paramMeta){ $star_get_num = getXVal($paramMeta,'param_value', 0); $num_arr = explode('|',$star_get_num); if ($pvp_rank>count($num_arr) || $pvp_rank<1){ $finalNum = 0; }else{ $finalNum = $this->calFinalStarNum($num_arr[$pvp_rank-1]); } if ($finalNum > 0){ $items = array( array( 'item_id' => V_ITEM_STAR, 'item_num' => $finalNum ), ); $propertyChgService = new services\PropertyChgService(); $awardService = new services\AwardService(); myself()->_addItems($items, $awardService,$propertyChgService); } } } public function calStarNum2(&$reward,$pvp_rank){ $paramMeta = mt\Parameter::getByName('star_get_num'); if ($paramMeta){ $star_get_num = getXVal($paramMeta,'param_value', 0); $num_arr = explode('|',$star_get_num); if ($pvp_rank>count($num_arr) || $pvp_rank<1){ $finalNum = 0; }else{ $finalNum = $this->calFinalStarNum($num_arr[$pvp_rank-1]); } if ($finalNum > 0){ array_push($reward['items'],array( 'item_id'=> V_ITEM_STAR, 'item_num'=>$finalNum, )); } } } private function calFinalStarNum($num){ $finalNum = 0; if ($num <= 0) { return $finalNum; } $paramMeta = mt\Parameter::getByName('starroad_max'); $starMax = getXVal($paramMeta,'param_value', 0); if ($starMax){ $starNum = myself()->_getDailyV(TN_DAILY_GET_STAR_NUM, 0); $newNum = min($starMax,$starNum + $num); $finalNum = max(0,$newNum-$starNum); } return $finalNum; } private function settlementReward(){ error_log('settlementReward'); $battle_uuid = getXVal($this->allInfo,'battle_uuid', 0); $room_uuid = getXVal($this->allInfo,'room_uuid', 0); $propertyChgService = new services\PropertyChgService(); $awardService = new services\AwardService(); $db = BattleSettlement::findTeam($battle_uuid,$room_uuid); if ($db){ $data = emptyReplace(json_decode($db['data'], true), array()); if ($data){ foreach ($data['members'] as $member){ if ($member['account_id'] == myself()->_getAccountId()){ if ($member['reward']['items']){ $items = array(); foreach ($member['reward']['items'] as $value){ if ($value['item_id'] != V_ITEM_STAR){ array_push($items,$value); } } myself()->_addItems($items, $awardService,$propertyChgService); } if ($member['reward']['hero']['hero_uniid']){ Hero::update($member['reward']['hero']['hero_uniid'], array( 'today_get_gold' => $member['reward']['hero']['curr_gold'] * 100, 'last_get_gold_time' => myself()->_getNowTime() )); } } } } } } private function updateRankData() { error_log('updateRankData'); $this->currSeasonMeta = mt\RankSeason::getCurrentSeason(); 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']); $this->seasonDb = Season::find($this->currSeasonMeta['id']); } if (!$this->seasonDb) { return; } // $this->updateScore(); $seasonBattleData = json_decode($this->seasonDb['battle_data'], true); if (!isset($seasonBattleData['today_data'])) { $seasonBattleData['today_data'] = array( 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); } if (!isset($seasonBattleData['season_data'])) { $seasonBattleData['season_data'] = array( 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); } if (!isset($seasonBattleData['this_week_data'])) { $seasonBattleData['this_week_data'] = array( 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); } if (myself()->_getDaySeconds($seasonBattleData['today_data']['modifytime']) < myself()->_getNowDaySeconds()) { $seasonBattleData['today_data'] = array( 'createtime' => $seasonBattleData['today_data']['createtime'], 'modifytime' => myself()->_getNowTime() ); } if (myself()->_getDaySeconds($seasonBattleData['this_week_data']['modifytime']) < myself()->_getMondaySeconds()) { $seasonBattleData['this_week_data'] = array( 'createtime' => $seasonBattleData['this_week_data']['createtime'], 'modifytime' => myself()->_getNowTime() ); } $oldSeasonDataKills = getXVal($seasonBattleData['season_data'], 'total_kills_times', 0); $this->apply($seasonBattleData['season_data']); $newSeasonDataKills = getXVal($seasonBattleData['season_data'], 'total_kills_times', 0); if ($newSeasonDataKills > $oldSeasonDataKills) { Season::update($this->currSeasonMeta['id'], array( 'kills_modifytime' => myself()->_getNowTime(), )); Battle::update(array( 'kills_modifytime' => myself()->_getNowTime(), )); } $this->apply($seasonBattleData['today_data']); $this->apply($seasonBattleData['this_week_data']); Season::update( $this->currSeasonMeta['id'], array( 'battle_data' => json_encode($seasonBattleData), ) ); } } private function updateScore() { error_log('updateScore'); $newRank = $this->userInfo['rank']; $winningPro = $this->celWinningPro($this->userInfo); if ($winningPro){ $newScore = FormulaService::calcBattleAfterRankScore($this->userInfo,$this->battleInfo,$winningPro); //赛后排位积分 $newElo = FormulaService::calcUserEloValue($this->userInfo,$this->battleInfo,$winningPro); //赛后elo积分 mt\Rank::calcNewRankAndScore( $newRank, $newScore); if ( $newScore != $this->userInfo['score'] ) { myself()->_updateUserInfo(array( 'rank' => $newRank, 'score' => $newScore, 'elo' => $newElo, 'history_best_rank' => max($this->userInfo['rank'], $newRank), 'history_best_score' => max($this->userInfo['score'], $newScore), 'score_modifytime' => myself()->_getNowTime(), 'best_rank_modifytime' => $newRank > $this->userInfo['rank'] ? myself()->_getNowTime() : $this->userInfo['best_rank_modifytime'], )); Season::update($this->currSeasonMeta['id'], array( 'rank' => $newRank, 'score' => $newScore, 'elo' => $newElo, 'history_best_rank' => max($this->userInfo['rank'], $newRank), 'score_modifytime' => myself()->_getNowTime(), 'best_rank_modifytime' => $newRank > $this->userInfo['rank'] ? myself()->_getNowTime() : $this->userInfo['best_rank_modifytime'], )); } } } public function celWinningPro($userInfo){ $team_id = getXVal($this->allInfo,'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; $winningPro = 1/(1+pow(10,(-(0.7*($userInfo['elo']-$myAvg)+0.3*(0))/400))); } error_log(json_encode( array( 'account_id' => $userInfo['account_id'], 'myElo' =>$userInfo['elo'], 'myAvg' => $myAvg, 'myTeam' =>$myTeam, 'opponentAvg'=>$tempSumList, 'winningPro' => $winningPro, ) )); return $winningPro; } private function apply(&$battleData) { //战斗次数 $this->incValue($battleData, 'total_battle_times', 1); if (getXVal($this->allInfo,'team_mode', 0) == 0) { //单人模式战斗次数 $this->incValue($battleData, 'total_single_battle_times', 1); //单人模式最高排名 $this->minValue($battleData, 'single_battle_rank', getXVal($this->battleInfo,'pvp_personal_rank', 0)); } else { //组队模式最高排名 $this->minValue($battleData, 'team_battle_rank', getXVal($this->allInfo,'pvp_team_rank', 0)); //组队模式战斗次数 $this->incValue($battleData, 'total_team_battle_times', 1); //组队模式前15名次数 if (getXVal($this->battleInfo,'pvp_personal_rank', 0) <= 15){ $this->incValue($battleData, 'total_team_top_X_battle_times', 1); } } //排名 $ranked = getXVal($this->battleInfo,'pvp_team_rank', 0); if ($ranked == 1) { //吃鸡次数 $this->incValue($battleData, 'total_win_times', 1); } if ($ranked <= 10 && $ranked>0){ //排名前十 总次数 $this->incValue($battleData, 'total_top_ten_times', 1); } //击杀 $kills = getXVal($this->battleInfo,'kills', 0); if ($kills > 0) { //击杀总次数 $this->incValue($battleData, 'total_kills_times', $kills); //单局最大击杀数 $this->maxValue($battleData, 'max_kills_times', $kills); } //输出 $damageOut = getXVal($this->battleInfo,'damage_out', 0); if ($damageOut > 0) { //伤害输出总量 $this->incValue($battleData, 'total_damage_out', $damageOut); //单局最大伤害输出 $this->maxValue($battleData, 'max_damage_out', $damageOut); } //承伤 $damageIn = getXVal($this->battleInfo,'damage_in', 0); if ($damageIn > 0) { //受到伤害总量 $this->incValue($battleData, 'total_damage_in', $damageIn); //单局最大受到伤害量 $this->maxValue($battleData, 'max_damage_in', $damageIn); } //回复 $recoverHp = getXVal($this->battleInfo,'recover_hp', 0); if ($recoverHp > 0) { //自疗总量 $this->incValue($battleData, 'total_recover_hp', $recoverHp); //单局最大自疗量 $this->maxValue($battleData, 'max_recover_hp', $recoverHp); } //存活时间 $aliveTime = getXVal($this->battleInfo,'alive_time', 0); if ($aliveTime > 0) { //总存活时间 $this->incValue($battleData, 'total_alive_time', $aliveTime); //单局最大存活时间 $this->maxValue($battleData, 'max_alive_time', $aliveTime); } //救援次数 $this->incValue($battleData, 'rescue_teammate_times', getXVal($this->battleInfo,'rescue_teammate_times', 0)); //潜水次数 $this->incValue($battleData, 'diving_times', getXVal($this->battleInfo,'diving_times', 0)); //开启空投次数 $this->incValue($battleData, 'open_airdrop_times', getXVal($this->battleInfo,'open_airdrop_times', 0)); //使用药品次数 $this->incValue($battleData, 'use_medicine_times', getXVal($this->battleInfo,'use_medicine_times', 0)); //击毁机甲次数 $this->incValue($battleData, 'destory_car_times', getXVal($this->battleInfo,'destory_car_times', 0)); //使用伪装次数 $this->incValue($battleData, 'use_camouflage_times', getXVal($this->battleInfo,'use_camouflage_times', 0)); //使用技能次数 $this->incValue($battleData, 'use_skill_times', getXVal($this->battleInfo,'use_skill_times', 0)); //驾驶机甲移动距离 $this->incValue($battleData, 'ride_car_move_distance', getXVal($this->battleInfo,'ride_car_move_distance', 0)); //驾驶机甲击杀数 $this->incValue($battleData, 'ride_car_kills', getXVal($this->battleInfo,'ride_car_kills', 0)); //使用的英雄最高等级 $this->maxValue($battleData, 'max_single_battle_hero_lv', getXVal($this->battleInfo,'max_single_battle_hero_lv', 0)); $this->procWeaponsEquip($battleData); $this->procWeaponsSlot($battleData); $this->procHeros($battleData); if (!isset($battleData['createtime'])) { $battleData['createtime'] = myself()->_getNowTime(); } $battleData['modifytime'] = myself()->_getNowTime(); } private function procWeaponsEquip(&$battleData) { if (!isset($battleData['weapons_type_data'])) { $battleData['weapons_type_data'] = array(); } //武器类型数据 $weaponsTypeDb = &$battleData['weapons_type_data']; { $tmpStrs1 = explode('|', getXVal($this->battleInfo,'weapons_type', '')); foreach ($tmpStrs1 as $str) { $tmpStrs2 = explode(':', $str); if (count($tmpStrs2) >= 4) { list($weaponId, $kills, $damageOut, $obtainCount) = $tmpStrs2; $weaponMeta = mt\Equip::get($weaponId); if ($weaponMeta) { $key = $weaponMeta['equip_type'] . '_' . $weaponMeta['equip_subtype']; if (!isset($weaponsTypeDb[$key])) { $weaponsTypeDb[$key] = array(); } //使用此种类型武器击杀数 $this->incValue($weaponsTypeDb, 'kills', $kills); //使用此种武器伤害输出 $this->incValue($weaponsTypeDb, 'damage_out', $damageOut); //战斗中获得此种武器数量 $this->incValue($weaponsTypeDb, 'obtain_count', $obtainCount); } } } } } private function procWeaponsSlot(&$battleData) { if (!isset($battleData['weapons_slot_data'])) { $battleData['weapons_slot_data'] = array(); } //武器槽位数据 $weaponsSlotDb = &$battleData['weapons_slot_data']; { $tmpStrs1 = explode('|', getXVal($this->battleInfo,'weapons_slot', '')); foreach ($tmpStrs1 as $str) { $tmpStrs2 = explode(':', $str); if (count($tmpStrs2) >= 4) { list($weaponId, $use_times) = $tmpStrs2; $weaponMeta = mt\Equip::get($weaponId); if ($weaponMeta && $weaponMeta['inventory_slot'] > 0) { $key = $weaponMeta['inventory_slot']; if (!isset($weaponsSlotDb[$key])) { $weaponsSlotDb[$key] = array(); } //使用次数 $this->incValue($weaponsSlotDb, 'use_times', $use_times); } } } } } private function procHeros(&$battleData) { if (!isset($battleData['hero_data'])) { $battleData['hero_data'] = array(); } //英雄数据 $heroDb = &$battleData['hero_data']; { $tmpStrs1 = explode('|', getXVal($this->battleInfo,'heros', '')); foreach ($tmpStrs1 as $str) { $tmpStrs2 = explode(':', $str); if (count($tmpStrs2) >= 4) { list($heroId, $skillLv, $weaponLv) = $tmpStrs2; $heroMeta = mt\Item::get($heroId); if ($heroMeta && $heroMeta['type'] == mt\Item::HERO_TYPE) { $key = $heroMeta['id']; if (!isset($heroDb[$key])) { $heroDb[$key] = array(); } //最大技能等级 $this->maxValue($heroDb, 'skill_lv', $skillLv); //最大武器等级 $this->maxValue($heroDb, 'weapon_lv', $weaponLv); } } } } //统计使用的英雄及枪械的信息 if (!isset($battleData['hero_info'])) { $battleData['hero_info'] = array(); } $heroInfo = &$battleData['hero_info']; { $hero_uniid = getXVal($this->battleInfo,'hero_uniid', ''); $hero = Hero::find($hero_uniid); if ($hero){ if (!isset($heroInfo[$hero['hero_id']])){ $heroInfo[$hero['hero_id']] = array(); } $this->incValue($heroInfo[$hero['hero_id']], "use_times", 1); //每个英雄使用次数 $ranked = getXVal($this->battleInfo,'pvp_team_rank', 0); if ($ranked == 1) { //吃鸡次数 $this->incValue($heroInfo[$hero['hero_id']], 'win_times', 1);//使用该英雄吃鸡获胜次数 } if ($ranked <= 10){ //排名前十 总次数 $this->incValue($heroInfo[$hero['hero_id']], 'top_ten_times', 1);//使用该英雄进前十次数 } if (!isset($heroInfo[$hero['hero_id']]['weapon'])){ $heroInfo[$hero['hero_id']]['weapon'] = array(); } $weapon_uuid1 = getXVal($this->battleInfo,'weapon_uuid1', 0); $weapon1 = Gun::find($weapon_uuid1); if ($weapon1){ $this->incValue($heroInfo[$hero['hero_id']]['weapon'], $weapon1['gun_id'], 1);//该英雄下选用每个武器的次数 } $weapon_uuid2 = getXVal($this->battleInfo,'weapon_uuid2', 0); $weapon2 = Gun::find($weapon_uuid2); if ($weapon2){ $this->incValue($heroInfo[$hero['hero_id']]['weapon'], $weapon2['gun_id'], 1);//该英雄下选用每个武器的次数 } } } } private function incValue(&$battleData, $key, $val) { if ($val > 0) { $battleData[$key] = getXVal($battleData, $key, 0) + $val; } } private function minValue(&$battleData, $key, $val) { $battleData[$key] = min(getXVal($battleData, $key, 0), $val); } private function maxValue(&$battleData, $key, $val) { $battleData[$key] = max(getXVal($battleData, $key, 0), $val); } }