1277 lines
55 KiB
PHP
1277 lines
55 KiB
PHP
<?php
|
||
namespace services;
|
||
|
||
require_once('mt/Item.php');
|
||
require_once('mt/Equip.php');
|
||
require_once('mt/Season.php');
|
||
require_once('mt/Rank.php');
|
||
require_once('mt/Parameter.php');
|
||
require_once('mt/Hero.php');
|
||
require_once('mt/PveGemini.php');
|
||
require_once('mt/PveGeminiMode.php');
|
||
require_once('mt/RankSeason.php');
|
||
require_once('mt/StarLevel.php');
|
||
require_once('mt/AchievementsCycle.php');
|
||
require_once('mt/ServerTaskTime.php');
|
||
require_once('mt/MapMode.php');
|
||
require_once('mt/BattleReward.php');
|
||
require_once('mt/CircuitTime.php');
|
||
|
||
require_once('models/Season.php');
|
||
require_once('models/Battle.php');
|
||
require_once('models/Hero.php');
|
||
require_once('models/FragmentRecord.php');
|
||
require_once('models/BattleSettlement.php');
|
||
require_once('models/RankBattle.php');
|
||
require_once('models/HashRateBattleData.php');
|
||
require_once('models/GlobalData.php');
|
||
require_once('models/Circuit.php');
|
||
|
||
require_once('services/RankActivityService.php');
|
||
require_once('services/AwardService.php');
|
||
require_once('services/PropertyChgService.php');
|
||
require_once('services/LogService.php');
|
||
require_once('services/LootService.php');
|
||
|
||
|
||
use models\BattleSettlement;
|
||
|
||
use models\Circuit;
|
||
use models\FragmentRecord;
|
||
use models\GlobalData;
|
||
use models\HashRate;
|
||
use models\RankBattle;
|
||
use models\User;
|
||
use mt;
|
||
use services;
|
||
use phpcommon;
|
||
use phpcommon\SqlHelper;
|
||
use models\Season;
|
||
use models\Battle;
|
||
use models\HashRateBattleData;
|
||
use models\Hero;
|
||
use services\LogService;
|
||
|
||
class TameBattleDataService extends BaseService {
|
||
|
||
const MAX_DROP_NUM = 2;
|
||
|
||
const ROOM_MODE_PVP = 0;
|
||
const ROOM_MODE_PVE = 1;
|
||
const ROOM_MODE_MOBA = 2;
|
||
|
||
const MATCH_MODE_PVP = 0;
|
||
const MATCH_MODE_RANK = 1;
|
||
|
||
public $allInfo = array();
|
||
public $battleInfo = array();
|
||
public $teamInfo = array();
|
||
public $teamList = array();
|
||
private $userInfo = array();
|
||
private $heroDto = array();
|
||
private $pveGeminiMeta = null;
|
||
|
||
private $reward = array(
|
||
'hero' => 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;
|
||
}
|
||
myself()->_fireEvent('Battle','onSettlement',$this->battleInfo);
|
||
//记录战斗有效行为
|
||
// $this->_updateBattleData();
|
||
//记录战斗数据的排行榜
|
||
$this->recordBattleRanking();
|
||
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();
|
||
|
||
myself()->_incDailyV(TN_DAILY_PVP_BATTLE_TIMES, 0, 1);
|
||
}
|
||
break;
|
||
case self::MATCH_MODE_RANK:
|
||
{
|
||
//排位赛
|
||
$this->updatePvpData();
|
||
$this->updateRankData();
|
||
// $this->updateScore();
|
||
myself()->_incDailyV(TN_DAILY_RANK_BATTLE_TIMES, 0, 1);
|
||
}
|
||
break;
|
||
default:{}
|
||
break;
|
||
}
|
||
}
|
||
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;
|
||
case self::ROOM_MODE_MOBA :
|
||
{
|
||
$this->updateMobaData();
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
}
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
//记录战斗数据的排行榜
|
||
private function recordBattleRanking(){
|
||
$account = getXVal($this->battleInfo,'account_id', 0);
|
||
$room_mode = getXVal($this->allInfo,'room_mode', 0);
|
||
switch ($room_mode){
|
||
case self::ROOM_MODE_PVP : {
|
||
//游戏场次 (存活30S算有效场次)
|
||
if (getXVal($this->battleInfo,'pvp_survia_time', 0)/1000 > 30 &&
|
||
getXVal($this->battleInfo,'abandon_battle', 0) == 0){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::GAME_TIMES,1);
|
||
}
|
||
//吃鸡数 //pvp_team_rank
|
||
// print_r(getXVal($this->battleInfo,'pvp_kill', 0));die;
|
||
if (getXVal($this->allInfo,'pvp_team_rank', 0) == 1){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::WIN_TIMES,1);
|
||
}
|
||
|
||
//mvp
|
||
if (getXVal($this->battleInfo,'is_mvp', 0) == 1){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::MVP_TIMES,1);
|
||
}
|
||
|
||
//前三
|
||
if (getXVal($this->allInfo,'pvp_team_rank', 0) <= 3){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::TOP_THREE_TIMES,1);
|
||
}
|
||
|
||
//击杀
|
||
if (getXVal($this->battleInfo,'pvp_kill', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::KILL_TIMES,getXVal($this->battleInfo,'pvp_kill', 0));
|
||
}
|
||
|
||
//伤害
|
||
if (getXVal($this->battleInfo,'pvp_damage', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::DAMAGES_OUT,getXVal($this->battleInfo,'pvp_damage', 0));
|
||
}
|
||
|
||
//助攻
|
||
if (getXVal($this->battleInfo,'pvp_assist', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::ASSIST_TIMES,getXVal($this->battleInfo,'pvp_assist', 0));
|
||
}
|
||
|
||
//治疗
|
||
if (getXVal($this->battleInfo,'pvp_recover', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::RECOVER_HP,getXVal($this->battleInfo,'pvp_recover', 0));
|
||
}
|
||
|
||
//存活时间
|
||
if (getXVal($this->battleInfo,'pvp_survia_time', 0)/1000 >= 1 ){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::SURVIVAL_TIME,round(getXVal($this->battleInfo,'pvp_survia_time', 0)/1000));
|
||
}
|
||
|
||
//救援数
|
||
if (getXVal($this->battleInfo,'pvp_rescue', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::RESCUE_TIMES,getXVal($this->battleInfo,'pvp_rescue', 0));
|
||
}
|
||
}
|
||
break;
|
||
case self::ROOM_MODE_MOBA : {
|
||
//游戏场次 (存活30S算有效场次)
|
||
if (! getXVal($this->battleInfo,'is_run_away', 0)){
|
||
RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::GAME_TIMES,1);
|
||
}
|
||
//胜利数
|
||
if (getXVal($this->allInfo,'victory', 0)){
|
||
RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::WIN_TIMES,1);
|
||
}
|
||
//击杀
|
||
if (getXVal($this->battleInfo,'kills', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::KILL_TIMES,getXVal($this->battleInfo,'kills', 0));
|
||
}
|
||
//伤害
|
||
if (getXVal($this->battleInfo,'damage_out', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::DAMAGES_OUT,getXVal($this->battleInfo,'damage_out', 0));
|
||
}
|
||
//助攻
|
||
if (getXVal($this->battleInfo,'assist', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::ASSIST_TIMES,getXVal($this->battleInfo,'assist', 0));
|
||
}
|
||
//治疗
|
||
if (getXVal($this->battleInfo,'recover_hp', 0) > 0){
|
||
RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::RECOVER_HP,getXVal($this->battleInfo,'recover_hp', 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));
|
||
}
|
||
|
||
private function updateMobaData(){
|
||
error_log('updateMobaData');
|
||
$hisBattleData = Battle::getMyBattleData();
|
||
if (!isset($hisBattleData['moba_data'])) {
|
||
$hisBattleData['moba_data'] = array(
|
||
'createtime' => myself()->_getNowTime(),
|
||
'modifytime' => myself()->_getNowTime()
|
||
);
|
||
}
|
||
if (!isset($hisBattleData['today_data'])) {
|
||
$hisBattleData['today_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()
|
||
);
|
||
}
|
||
$this->apply($hisBattleData['moba_data']);
|
||
$this->apply($hisBattleData['today_data']);
|
||
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);
|
||
|
||
$oldRank = $this->userInfo['rank'];
|
||
$newRank = $this->userInfo['rank'];
|
||
$oldScore = $this->userInfo['score'];
|
||
$newScore = $this->userInfo['score'];
|
||
$oldElo = $this->userInfo['elo'];
|
||
$newElo = $this->userInfo['elo'];
|
||
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){
|
||
|
||
$newElo = FormulaService::calcUserEloValue($this->userInfo,$this->battleInfo,$winningPro); //赛后elo积分
|
||
$newScore = FormulaService::calcBattleAfterRankScore($this->userInfo,$this->battleInfo,$winningPro); //赛后排位积分
|
||
//黄金以下段位,失败时不扣积分
|
||
if ($newScore < $this->userInfo['score'] && $this->userInfo['score']< 1300){
|
||
$newScore = $this->userInfo['score'];
|
||
}
|
||
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
|
||
}
|
||
}
|
||
switch (getXVal($this->allInfo,'room_mode', 0)){
|
||
case self::ROOM_MODE_PVP:
|
||
{
|
||
if (getXVal($this->allInfo,'map_mode', 0) == mt\MapMode::CIRCUIT_MODE){
|
||
$battle_history_type = 3;
|
||
}else{
|
||
$battle_history_type = 1;
|
||
}
|
||
}
|
||
break;
|
||
case self::ROOM_MODE_MOBA:
|
||
{
|
||
$battle_history_type = 2;
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
$team_mode = null;
|
||
$battle_history_type = 0;
|
||
}
|
||
}
|
||
$circuitMeta = mt\CircuitTime::getCurrentCircuit();
|
||
$circuitScore = Circuit::getMyScore($circuitMeta['circuit_season']);
|
||
$data = array(
|
||
"battle_uuid" => $battleUuid,
|
||
"map_mode_id" => getXVal($this->allInfo,'map_mode_id', 0),
|
||
"map_id" => getXVal($this->allInfo,'map_id', 0),
|
||
"map_mode" => getXVal($this->allInfo,'map_mode', 0),
|
||
"room_mode" => getXVal($this->allInfo,'room_mode', 0),
|
||
"pvp_mode" => $pvp_mode,
|
||
"team_mode" => getXVal($this->allInfo,'team_mode', 0),
|
||
"pvp_team_kills" => getXVal($this->allInfo,'pvp_team_kills', 0),
|
||
"pvp_team_rank" => getXVal($this->allInfo,'pvp_team_rank', 0),
|
||
'account_id'=> getXVal($this->battleInfo,'account_id', 0),
|
||
'name'=> getXVal($this->battleInfo,'name', 0),
|
||
'head'=> getXVal($this->battleInfo,'head', 0),
|
||
'head_frame'=> getXVal($this->battleInfo,'head_frame', 0),
|
||
'sex'=> getXVal($this->battleInfo,'sex', 0),
|
||
'hero_uniid'=> getXVal($this->battleInfo,'hero_uniid', 0),
|
||
'hero_id'=> getXVal($this->battleInfo,'hero_id', 0),
|
||
'dead'=> getXVal($this->battleInfo,'dead', 0),
|
||
'skin_id'=> getXVal($this->battleInfo,'skin_id', 0),
|
||
'is_mvp'=> getXVal($this->battleInfo,'is_mvp', 0),
|
||
'damage_out'=> getXVal($this->battleInfo,'damage_out', 0),
|
||
'move_distance'=> getXVal($this->battleInfo,'move_distance', 0),
|
||
'old_rank'=> $oldRank,
|
||
'new_rank'=> $newRank,
|
||
'old_score'=> $oldScore,
|
||
'new_score'=> $newScore,
|
||
'old_elo'=> $oldElo,
|
||
'new_elo'=> $newElo,
|
||
'old_circuit_score'=> $circuitScore,
|
||
'new_circuit_score'=> $circuitScore,
|
||
'pvp_kill'=> getXVal($this->battleInfo,'pvp_kill', 0),
|
||
'pvp_damage'=> getXVal($this->battleInfo,'pvp_damage', 0),
|
||
'pvp_assist'=> getXVal($this->battleInfo,'pvp_assist', 0),
|
||
'pvp_survia_time'=> getXVal($this->battleInfo,'pvp_survia_time', 0),
|
||
'pvp_recover'=> getXVal($this->battleInfo,'pvp_recover', 0),
|
||
'pvp_rescue'=> getXVal($this->battleInfo,'pvp_rescue', 0),
|
||
'pvp_personal_rank'=> getXVal($this->battleInfo,'pvp_personal_rank', 0),
|
||
'pve_order'=> getXVal($this->battleInfo,'pve_order', 0),
|
||
'pve_score'=> getXVal($this->battleInfo,'pve_score', 0),
|
||
'pve_star'=> getXVal($this->battleInfo,'pve_star', 0),
|
||
'pve_damage'=> getXVal($this->battleInfo,'pve_damage', 0),
|
||
'pve_revive'=> getXVal($this->battleInfo,'pve_revive', 0),
|
||
'pve_survia_time'=> getXVal($this->battleInfo,'pve_survia_time', 0),
|
||
'pve_wave'=> getXVal($this->battleInfo,'pve_wave', 0),
|
||
'pve_max_wave'=> getXVal($this->battleInfo,'pve_max_wave', 0),
|
||
'pve_boss_killed'=> getXVal($this->battleInfo,'pve_boss_killed', 0),
|
||
'hero_lv'=> getXVal($this->battleInfo,'hero_level', 1),
|
||
'dead_times'=> getXVal($this->battleInfo,'dead_times', 0),
|
||
"game_time" => getXVal($this->battleInfo,'game_time', 0),
|
||
"battle_history_type" => $battle_history_type,
|
||
'reward' => array(),
|
||
);
|
||
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:
|
||
{
|
||
if (getXVal($this->allInfo,'map_mode', 0) == mt\MapMode::CIRCUIT_MODE){
|
||
$battle_history_type = 3;
|
||
}else{
|
||
$battle_history_type = 1;
|
||
}
|
||
}
|
||
break;
|
||
case self::ROOM_MODE_MOBA:
|
||
{
|
||
$battle_history_type = 2;
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
$team_mode = null;
|
||
$battle_history_type = 0;
|
||
}
|
||
}
|
||
$circuitMeta = mt\CircuitTime::getCurrentCircuit();
|
||
$circuitScore = Circuit::getMyScore($circuitMeta['circuit_season']);
|
||
$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),
|
||
'map_mode'=> getXVal($this->allInfo,'map_mode', 0),
|
||
'map_mode_id'=> getXVal($this->allInfo,'map_mode_id', 0),
|
||
'battle_history_type'=> $battle_history_type,
|
||
'team_mode'=> getXVal($this->allInfo,'pvp_settelement_type', 0),
|
||
'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'=>0,
|
||
'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),
|
||
'moba_my_team_kills'=> getXVal($this->allInfo,'moba_my_team_kills', 0),
|
||
'moba_enemy_team_kills'=> getXVal($this->allInfo,'moba_enemy_team_kills', 0),
|
||
);
|
||
|
||
$data['members'] = array();
|
||
$pvp_mode = getXVal($this->allInfo,'pvp_match_mode', 0);
|
||
foreach ($this->teamInfo as $info){
|
||
$info['pvp_team_rank'] = getXVal($this->allInfo,'pvp_team_rank', 0);
|
||
$oldRank = 0;
|
||
$newRank = 0;
|
||
$oldScore = 0;
|
||
$newScore = 0;
|
||
$oldElo = 0;
|
||
$newElo = 0;
|
||
$winningPro=0;
|
||
$userDb = User::find(getXVal($info,'account_id', 0));
|
||
$rewards = array();
|
||
if ($userDb){
|
||
$winningPro = $this->celWinningPro($userDb);
|
||
$oldRank = $userDb['rank'];
|
||
$newRank = $userDb['rank'];
|
||
$oldScore = $userDb['score'];
|
||
$newScore = $userDb['score'];
|
||
$oldElo = $userDb['elo'];
|
||
$newElo = $userDb['elo'];
|
||
// $heroDb = Hero::findByAccountId(getXVal($info,'account_id', 0),getXVal($info,'hero_uniid', 0));
|
||
// if ($heroDb){
|
||
//// self::calBattleReward($userDb,$heroDb,$rewards);
|
||
// if ($pvp_mode == self::MATCH_MODE_RANK){
|
||
// $winningPro = $this->celWinningPro($userDb);
|
||
// if ($winningPro){
|
||
// $newElo = FormulaService::calcUserEloValue($userDb,$info,$winningPro); //赛后elo积分
|
||
// $newScore = FormulaService::calcBattleAfterRankScore($userDb,$info,$winningPro); //赛后排位积分
|
||
// //黄金以下段位,失败时不扣积分
|
||
// if ($newScore < $userDb['score'] && $userDb['score']< 1300){
|
||
// $newScore = $userDb['score'];
|
||
// }
|
||
// 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),
|
||
'skin_id'=> getXVal($info,'skin_id', 0),
|
||
'is_mvp'=> getXVal($info,'is_mvp', 0),
|
||
'damage_out'=> getXVal($info,'damage_out', 0),
|
||
'move_distance'=> getXVal($info,'move_distance', 0),
|
||
'old_rank'=> $oldRank,
|
||
'new_rank'=> $newRank,
|
||
'old_score'=> $oldScore,
|
||
'new_score'=> $newScore,
|
||
'old_elo'=> $oldElo,
|
||
'new_elo'=> $newElo,
|
||
'old_circuit_score'=> $circuitScore,
|
||
'new_circuit_score'=> $circuitScore,
|
||
'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),
|
||
'pvp_team_rank'=> getXVal($info,'pvp_team_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),
|
||
'hero_lv'=> getXVal($info,'hero_lv', 1),
|
||
'dead_times'=> getXVal($info,'dead_times', 0),
|
||
'box_num'=> getXVal($info,'box_num', 0),
|
||
'battle_score'=> 0,
|
||
'reward' => $rewards,
|
||
'winningPro' => $winningPro,
|
||
'match_room_uuid' => getXVal($info,'match_room_uuid', 0),
|
||
);
|
||
array_push($data['members'],$temp);
|
||
}
|
||
BattleSettlement::addTeam(
|
||
getXVal($this->allInfo,'battle_uuid', 0),
|
||
getXVal($this->allInfo,'room_uuid', 0),
|
||
$data
|
||
);
|
||
}
|
||
|
||
private function updateRankData()
|
||
{
|
||
error_log('updateRankData');
|
||
$this->currSeasonMeta = mt\RankSeason::getCurrentSeason();
|
||
if ( $this->currSeasonMeta) {
|
||
$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::upsert($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::upsert(
|
||
$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); //赛后排位积分
|
||
//黄金以下段位,失败时不扣积分
|
||
if ($newScore < $this->userInfo['score'] && $this->userInfo['score']< 1300){
|
||
$newScore = $this->userInfo['score'];
|
||
}
|
||
$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['history_best_rank'], $newRank),
|
||
'history_best_score' => max($this->userInfo['history_best_score'], $newScore),
|
||
'score_modifytime' => myself()->_getNowTime(),
|
||
'best_rank_modifytime' => $newRank > $this->userInfo['rank'] ?
|
||
myself()->_getNowTime() : $this->userInfo['best_rank_modifytime'],
|
||
));
|
||
Season::upsert($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']) && !myself()->_isAndroidAccountId($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)));
|
||
}
|
||
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);
|
||
}
|
||
}
|
||
|
||
if (!isset($battleData['total_map_win_times'])) {
|
||
$battleData['total_map_win_times'] = array();
|
||
}
|
||
$mapId = getXVal($this->allInfo,'map_id', 0);
|
||
|
||
//排名
|
||
$ranked = getXVal($this->battleInfo,'pvp_team_rank', 0);
|
||
$mapMode = getXVal($this->allInfo,'map_mode', 0);
|
||
if ($ranked == 1) {
|
||
//吃鸡次数
|
||
$this->incValue($battleData, 'total_win_times', 1);
|
||
//地图吃鸡数
|
||
$this->incValue($battleData['total_map_win_times'], $mapId, 1);
|
||
if ($mapMode== mt\MapMode::RANKING_MODE || $mapMode == mt\MapMode::BET_MODE){
|
||
$this->incValue($battleData, "total_special_win_times", 1);
|
||
}
|
||
}
|
||
if ($ranked <= 3 && $ranked>0){
|
||
//排名前十 总次数
|
||
$this->incValue($battleData, 'total_top_three_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);
|
||
}
|
||
//助攻次数
|
||
$assistTime = getXVal($this->battleInfo,'pvp_assist', 0);
|
||
if ($assistTime > 0) {
|
||
//总助攻次数
|
||
$this->incValue($battleData, 'total_assist_time', $assistTime);
|
||
//单局最大助攻次数
|
||
$this->maxValue($battleData, 'max_assist_time', $assistTime);
|
||
}
|
||
//等级
|
||
$level = getXVal($this->battleInfo,'hero_lv', 1);
|
||
if ($level > 0) {
|
||
//总等级
|
||
$this->incValue($battleData, 'total_level', $level);
|
||
//单局最大等级
|
||
$this->maxValue($battleData, 'max_level', $level);
|
||
}
|
||
//救援次数
|
||
$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) >= 2) {
|
||
list($weaponId, $use_times) = $tmpStrs2;
|
||
$weaponMeta = mt\Equip::get($weaponId);
|
||
if ($weaponMeta && $weaponMeta['inventory_slot'] > 0) {
|
||
//使用次数
|
||
$this->incValue($weaponsSlotDb, $weaponId, $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'];
|
||
$heroId = $this->heroDto['hero_id'];
|
||
if (!isset($heroInfo[$heroId])){
|
||
$heroInfo[$heroId] = array();
|
||
}
|
||
$this->incValue($heroInfo[$heroId], "battle_times", 1); //英雄使用次数
|
||
$ranked = getXVal($this->battleInfo,'pvp_team_rank', 0);
|
||
if ($ranked == 1) {
|
||
//吃鸡次数
|
||
$this->incValue($heroInfo[$heroId], 'win_times', 1);//英雄吃鸡获胜次数
|
||
}
|
||
//英雄释放技能数
|
||
$this->incValue($heroInfo[$heroId], 'use_skill_times', getXVal($this->battleInfo,'use_skill_times', 0));
|
||
//英雄击杀次数
|
||
$kills = getXVal($this->battleInfo,'kills', 0);
|
||
if ($kills > 0) {
|
||
$this->incValue($heroInfo[$heroId], 'kills_times', $kills);
|
||
}
|
||
//英雄输出
|
||
$damageOut = getXVal($this->battleInfo,'damage_out', 0);
|
||
if ($damageOut > 0) {
|
||
$this->incValue($heroInfo[$heroId], 'damage_out', $damageOut);
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
private function _updateBattleData(){
|
||
error_log("_updateBattleData");
|
||
$hisBattleData = HashRateBattleData::getMyBattleData();
|
||
// $serverTaskData = GlobalData::getServerTaskData();
|
||
|
||
//算力系统任务统计
|
||
$currentHashRate= \mt\AchievementsCycle::getCurrentPeriod();
|
||
if (!isset($hisBattleData['hash_rate_data'])) {
|
||
$hisBattleData['hash_rate_data'] = array(
|
||
'pvpData' => array(),
|
||
'mobaData' => array(),
|
||
'createtime' => myself()->_getNowTime(),
|
||
'modifytime' => myself()->_getNowTime()
|
||
);
|
||
}
|
||
if ($currentHashRate && myself()->_getDaySeconds($hisBattleData['hash_rate_data']['modifytime']) <
|
||
myself()->_getDaySeconds(strtotime($currentHashRate['obtain_start_time']) )) {
|
||
$hisBattleData['hash_rate_data'] = array(
|
||
'pvpData' => array(),
|
||
'mobaData' => array(),
|
||
'createtime' => $hisBattleData['hash_rate_data']['createtime'],
|
||
'modifytime' => myself()->_getNowTime()
|
||
);
|
||
}
|
||
|
||
switch (getXVal($this->allInfo,'room_mode', 0)){
|
||
case self::MATCH_MODE_PVP :{
|
||
if ($currentHashRate &&
|
||
myself()->_getNowTime() > strtotime($currentHashRate['obtain_start_time']) &&
|
||
strtotime($currentHashRate['obtain_end_time']) > myself()->_getNowTime()){
|
||
$this->applyEx($hisBattleData['hash_rate_data']['pvpData']);
|
||
$hisBattleData['hash_rate_data']['modifytime'] = myself()->_getNowTime();
|
||
}
|
||
|
||
|
||
}
|
||
break;
|
||
case self::ROOM_MODE_MOBA :{
|
||
if ($currentHashRate &&
|
||
myself()->_getNowTime() > strtotime($currentHashRate['obtain_start_time']) &&
|
||
strtotime($currentHashRate['obtain_end_time']) > myself()->_getNowTime()){
|
||
$this->applyEx($hisBattleData['hash_rate_data']['mobaData']);
|
||
$hisBattleData['hash_rate_data']['modifytime'] = myself()->_getNowTime();
|
||
}
|
||
|
||
|
||
}
|
||
break;
|
||
default:{}
|
||
}
|
||
|
||
HashRateBattleData::add(json_encode($hisBattleData));
|
||
|
||
}
|
||
|
||
private function applyEx(&$battleData)
|
||
{
|
||
//战斗次数
|
||
if (! getXVal($this->battleInfo,'is_run_away', 0)){
|
||
$this->incValue($battleData, 'total_battle_times', 1);
|
||
}
|
||
|
||
switch (getXVal($this->allInfo,'room_mode', 0)){
|
||
case self::MATCH_MODE_PVP :{
|
||
//排名
|
||
$ranked = getXVal($this->battleInfo,'pvp_personal_rank', 0);
|
||
if ($ranked == 40){
|
||
$this->incValue($battleData, 'total_last_runner_times', 1);
|
||
}
|
||
//救援次数
|
||
$this->incValue($battleData, 'total_rescue_times', getXVal($this->battleInfo,'rescue_teammate_times', 0));
|
||
//行走距离
|
||
$distance = getXVal($this->battleInfo,'move_distance', 0);
|
||
$this->incValue($battleData, 'total_walking_distance', $distance);
|
||
}
|
||
break;
|
||
case self::ROOM_MODE_MOBA :{
|
||
//几分钟结束战斗
|
||
$duration = getXVal($this->battleInfo,'game_duration', 0);
|
||
if ($duration && floor($duration / 60) < 5){
|
||
$this->incValue($battleData, 'total_fiveMin_times', 1);
|
||
}
|
||
//第一个升满级
|
||
$fullLv = getXVal($this->battleInfo,'full_level_idx', 0);
|
||
if ($fullLv == 1){
|
||
$this->incValue($battleData, 'total_first_Lv_up', 1);
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
//是否胜利
|
||
if (getXVal($this->allInfo,'victory', 0)){
|
||
$this->incValue($battleData, 'total_win_times', 1);
|
||
}
|
||
//击杀
|
||
$this->incValue($battleData, 'total_kills_times', getXVal($this->battleInfo,'kills', 0));
|
||
//造成伤害
|
||
$this->incValue($battleData, 'total_damage_out', getXVal($this->battleInfo,'damage_out', 0));
|
||
//使用技能次数
|
||
$this->incValue($battleData, 'use_skill_times', getXVal($this->battleInfo,'use_skill_times', 0));
|
||
//道具使用
|
||
$this->procWeaponsSlot($battleData);
|
||
|
||
if (!isset($battleData['createtime'])) {
|
||
$battleData['createtime'] = myself()->_getNowTime();
|
||
}
|
||
$battleData['modifytime'] = myself()->_getNowTime();
|
||
}
|
||
|
||
}
|