864 lines
36 KiB
PHP
864 lines
36 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/RankReward.php');
|
|
require_once('mt/KillReward.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Hero.php');
|
|
require_once('mt/HeroQuality.php');
|
|
require_once('mt/AttrHelper.php');
|
|
require_once('mt/PveGemini.php');
|
|
require_once('mt/PveGeminiMode.php');
|
|
require_once('mt/RankSeason.php');
|
|
require_once('mt/LevelUp.php');
|
|
|
|
require_once('models/Season.php');
|
|
require_once('models/Battle.php');
|
|
require_once('models/Bag.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/Chip.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/FragmentPool.php');
|
|
require_once('models/RealtimeData.php');
|
|
require_once('models/BattleHistory.php');
|
|
require_once('models/NftActive.php');
|
|
require_once('models/FragmentRecord.php');
|
|
require_once('models/BattleSettlement.php');
|
|
|
|
require_once('services/RankActivityService.php');
|
|
require_once('services/FormulaService.php');
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/LogService.php');
|
|
|
|
|
|
use models\BattleSettlement;
|
|
use models\Chip;
|
|
use models\FragmentRecord;
|
|
use models\Nft;
|
|
use models\NftActive;
|
|
use models\User;
|
|
use mt;
|
|
use services;
|
|
use phpcommon;
|
|
use phpcommon\SqlHelper;
|
|
use models\Season;
|
|
use models\Battle;
|
|
use models\Bag;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use models\RealtimeData;
|
|
use models\FragmentPool;
|
|
use models\BattleHistory;
|
|
use services\FormulaService;
|
|
use services\LogService;
|
|
|
|
class TameBattleDataService extends BaseService {
|
|
const ROOM_MODE_PVP = 0;
|
|
// const MATCH_MODE_MATCH = 1;
|
|
const ROOM_MODE_PVE = 1;
|
|
|
|
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 $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;
|
|
}
|
|
|
|
//录入战斗记录
|
|
// $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->updateRankData();
|
|
$this->updateScore();
|
|
$this->settlementReward();
|
|
myself()->_incDailyV(TN_DAILY_RANK_BATTLE_TIMES, 0, 1);
|
|
}
|
|
break;
|
|
default:{}
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
//PVE模式
|
|
case self::ROOM_MODE_PVE:
|
|
{
|
|
return;
|
|
//pve
|
|
$this->updatePveData();
|
|
if ($this->pveGeminiMeta &&
|
|
$this->pveGeminiModeMeta) {
|
|
$this->rewardFragmentPve();
|
|
}
|
|
myself()->_incDailyV(TN_DAILY_PVE_BATTLE_TIMES, 0, 1);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
}
|
|
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()
|
|
);
|
|
}
|
|
|
|
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['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){
|
|
$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,'ranked', 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){
|
|
$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 奖励碎片
|
|
}
|
|
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,
|
|
));
|
|
}
|
|
}
|
|
|
|
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']){
|
|
myself()->_addItems($member['reward']['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);
|
|
//组队模式前30名次数
|
|
if (getXVal($this->battleInfo,'ranked', 0) <= 30){
|
|
$this->incValue($battleData, 'total_team_top_X_battle_times', 1);
|
|
}
|
|
}
|
|
//排名
|
|
$ranked = getXVal($this->battleInfo,'ranked', 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,'ranked', 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);
|
|
}
|
|
|
|
} |