341 lines
16 KiB
PHP
341 lines
16 KiB
PHP
<?php
|
|
namespace services;
|
|
|
|
require_once('models/BattleSettlement.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/HashRate.php');
|
|
|
|
require_once('mt/MapMode.php');
|
|
require_once('mt/Rank.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
use mt;
|
|
use services;
|
|
use phpcommon;
|
|
use phpcommon\SqlHelper;
|
|
use models\BattleSettlement;
|
|
use models\Hero;
|
|
use models\HashRate;
|
|
|
|
class RoomBattleDataService extends BaseService {
|
|
const ROOM_MODE_PVP = 0;
|
|
const ROOM_MODE_PVE = 1;
|
|
const ROOM_MODE_MOBA = 2;
|
|
|
|
|
|
public $teamExpScoreSort = array();
|
|
|
|
|
|
public $mapMode = 0;
|
|
public $inputData = array();
|
|
public $teamData = array();
|
|
public $battleSettlementDb = array();
|
|
public $maxKill = 0;
|
|
public $maxAssist = 0;
|
|
public $maxDamage = 0;
|
|
public $maxRecover= 0;
|
|
public $maxLevel= 0;
|
|
public $maxAlive= 0;
|
|
public $realUserCount= 0;
|
|
public $logData = array();
|
|
|
|
|
|
public function settlementReward(){
|
|
$realUserNum = 0;
|
|
$myTeamScore = 0;
|
|
foreach ($this->teamData['members'] as $member){
|
|
if(!myself()->_isAndroidAccountId(getXVal($member,'account_id', 0))){
|
|
$realUserNum += 1;
|
|
$myTeamScore += $this->_calBattleScore($member);
|
|
}
|
|
}
|
|
$myTeamScoreAvg = $myTeamScore / $realUserNum;
|
|
// $paramMeta = mt\Parameter::getVal('performance_score_range',0);
|
|
// $scoreParam = explode("|",$paramMeta);
|
|
// if (count($paramMeta) < 2){
|
|
// error_log('Parameter table error');
|
|
// return;
|
|
// }
|
|
// $room_mode = getXVal($this->inputData,'room_mode', 0);
|
|
$battleData = emptyReplace(json_decode($this->battleSettlementDb['data'], true), array());
|
|
if ($battleData['settlement_status'] == 1){
|
|
error_log('Cannot be resettled');
|
|
return;
|
|
}
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
foreach ($battleData['members'] as &$member){
|
|
$battleScore = $this->_calBattleScore($member);
|
|
$member['battle_score'] = $battleScore;
|
|
|
|
// //验证非机器人
|
|
$teamRanked = getXVal($member,'pvp_team_rank', 0);
|
|
$winningPro = getXVal($member,'winningPro', 0);
|
|
$account = getXVal($member,'account_id', 0);
|
|
if(!myself()->_isAndroidAccountId($account)){
|
|
error_log('Real Account:'.$account);
|
|
myself()->switchAccount($account);
|
|
$userDb = myself()->_getOrmUserInfo();
|
|
$heroDb = Hero::find(getXVal($member,'hero_uniid', 0));
|
|
if ($userDb && $heroDb){
|
|
//排位模式排位分计算
|
|
if ($this->mapMode == mt\MapMode::RANKING_MODE){
|
|
$newRank=$userDb['rank'];
|
|
$ranked = $this->getMyRanked($account);
|
|
$newScore = FormulaService::calcBattleAfterRankScoreNew($userDb,$ranked,$teamRanked,$winningPro);
|
|
if ($account == "6513_2006_VBpXS6ACSw6oqbEspB3N1ezsAty0IIvk"){
|
|
error_log("RankParam: ".json_encode(array(
|
|
'rank' => $ranked,
|
|
'teamRank' => $teamRanked,
|
|
'winningPro' => $winningPro,
|
|
"sortAccount" => $this->teamExpScoreSort
|
|
)));
|
|
}
|
|
$newElo = FormulaService::calcUserEloValueNew($userDb,$ranked,$winningPro);
|
|
if ($newScore < $userDb['score'] && $userDb['score']< 1300){
|
|
$newScore = $userDb['score'];
|
|
}
|
|
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
|
|
myself()->_updateUserInfo(array(
|
|
'rank' => $newRank,
|
|
'score' => $newScore,
|
|
'elo' => $newElo,
|
|
'history_best_rank' => max($userDb['history_best_rank'], $newRank),
|
|
'history_best_score' => max($userDb['history_best_score'], $newScore),
|
|
'score_modifytime' => myself()->_getNowTime(),
|
|
'best_rank_modifytime' => $newRank > $userDb['rank'] ?
|
|
myself()->_getNowTime() : $userDb['best_rank_modifytime'],
|
|
));
|
|
$member['new_rank'] = $newRank;
|
|
$member['new_score'] = $newScore;
|
|
$member['new_elo'] = $newElo;
|
|
}
|
|
|
|
if ($this->mapMode == mt\MapMode::GOLD_MODE && $member['move_distance'] <= 2000 ){
|
|
error_log("金币模式:消极战斗");
|
|
}else{
|
|
$this->_getBattleRewards($userDb,$heroDb,$battleScore,$myTeamScoreAvg,$myTeamScore,$member['reward']);
|
|
myself()->_addItems($member['reward'], $awardService,$propertyChgService);
|
|
}
|
|
|
|
$battleSingleDb = BattleSettlement::findSingle($this->battleSettlementDb['battle_uuid']);
|
|
if ($battleSingleDb){
|
|
$battleSingleData = emptyReplace(json_decode($battleSingleDb['data'], true), array());
|
|
$battleSingleData['reward'] = $member['reward'];
|
|
$battleSingleData['new_rank'] = $member['new_rank'];
|
|
$battleSingleData['new_score'] = $member['new_score'];
|
|
$battleSingleData['new_elo'] = $member['new_elo'];
|
|
BattleSettlement::addSingle($battleSingleDb['battle_uuid'],$battleSingleDb['room_uuid'],$battleSingleData);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
$battleData['settlement_status'] = 1;
|
|
BattleSettlement::addTeam(
|
|
$this->battleSettlementDb['battle_uuid'],
|
|
$this->battleSettlementDb['room_uuid'],
|
|
$battleData
|
|
);
|
|
|
|
}
|
|
|
|
public function _getBattleRewards($userDb,$heroDb,$battleScore,$teamScoreAvg,$teamScore,&$reward){
|
|
$mapModeMeta = mt\MapMode::findByMapMode($this->mapMode);
|
|
$teamRank = getXVal($this->teamData,'pvp_team_rank', 0);
|
|
if ($mapModeMeta){
|
|
$baseGold = 0;
|
|
$gold = 0;
|
|
// $accountLucky = Hero::getAccountLucky($userDb['address']);
|
|
$accountLucky = Hero::getAccountLuckyTemp();
|
|
$rewardMeta = mt\BattleReward::find($mapModeMeta['rewardMode'],$accountLucky);
|
|
if (!$rewardMeta){
|
|
return ;
|
|
}
|
|
$goldModeTimes = myself()->_getDailyV(TN_DAILY_GOLD_MODE_BATTLE_TIMES,0);
|
|
if ($this->mapMode == mt\MapMode::GOLD_MODE){
|
|
myself()->_incDailyV(TN_DAILY_GOLD_MODE_BATTLE_TIMES,0,1);
|
|
}
|
|
//金币模式检验
|
|
if ($this->mapMode == mt\MapMode::GOLD_MODE &&
|
|
// ($goldModeTimes >= $mapModeMeta['rewards_max_time'] )){
|
|
(!Hero::verifyValid($heroDb) || $goldModeTimes >= $mapModeMeta['rewards_max_time'] )){
|
|
error_log("金币模式:出战英雄没有打金时间或每日打金场次上限");
|
|
}else{
|
|
if (!empty($rewardMeta['goldLoot'])){
|
|
$items = LootService::dropOutItem($rewardMeta['goldLoot']);
|
|
foreach ($items as $item){
|
|
if ($item['item_id'] = V_ITEM_GOLD){
|
|
$gold = $item['item_num'];
|
|
$baseGold = $item['item_num'];
|
|
}else{
|
|
array_push($reward,$item);
|
|
}
|
|
}
|
|
}
|
|
if ($gold > 0){
|
|
// $strArr = explode("|",$rewardMeta['goldParam']);
|
|
$coefficientArr = explode(";",$rewardMeta['goldParam']);
|
|
$coefficient = isset($coefficientArr[$teamRank-1]) ? $coefficientArr[$teamRank-1] : 0;
|
|
if ($this->mapMode == mt\MapMode::GOLD_MODE){
|
|
$gold = $gold * $coefficient * ($battleScore / $teamScoreAvg);
|
|
}
|
|
if ($this->mapMode == mt\MapMode::BET_MODE){
|
|
$gold = $gold * $this->realUserCount * $coefficient * ($battleScore / $teamScore);
|
|
}
|
|
|
|
}
|
|
|
|
//财富值加成
|
|
$wealthK = mt\Parameter::getVal('economy_hero_wealth_K',0);
|
|
$wealthE = mt\Parameter::getVal('economy_hero_wealth_E',0);
|
|
$gold = $gold * (1 + $wealthE * (Hero::getHeroWealth($heroDb) / (Hero::getHeroWealth($heroDb) + $wealthK)));
|
|
|
|
//算力加成
|
|
$currentPeriod= \mt\AchievementsCycle::getCurrentPeriod();
|
|
if ($currentPeriod && myself()->_getNowTime() >= strtotime($currentPeriod['income_start_time'])){
|
|
$lastCompute = HashRate::getTotalByAccount($userDb['account_id'], $currentPeriod['id'] - 1);
|
|
$currentCompute = HashRate::getTotalByAccount($userDb['account_id'], $currentPeriod['id']);
|
|
$s = mt\Parameter::getVal('economy_account_compute_s',0);
|
|
$totalCompute = $currentCompute + $s * $lastCompute;
|
|
$computeParam = mt\Parameter::getVal('economy_account_compute_K',0);
|
|
$computeMaxEffect = mt\Parameter::getVal('economy_account_compute_E',0);
|
|
$gold = $gold * ($totalCompute / ($totalCompute + $computeParam) * $computeMaxEffect + 1);
|
|
$compute = ($totalCompute / ($totalCompute + $computeParam) * $computeMaxEffect + 1);
|
|
}
|
|
if ($userDb['account_id'] == "6513_2006_ZsmnBnmQYcJ4XElLOmqTDBRySOrE66Kj"){
|
|
error_log("BattleRewardsInfo:".json_encode(array(
|
|
'goldLootIndex' => $rewardMeta['goldLoot'],
|
|
'map_mode' => $this->mapMode,
|
|
'*baseGold*' => $baseGold,
|
|
'teamRank' => $teamRank,
|
|
'*ranking*' => isset($coefficient) ? $coefficient : '空',
|
|
'battleScore' => $battleScore,
|
|
'realUserCount' => $this->realUserCount,
|
|
'teamScoreTotal' => $teamScore,
|
|
'teamScoreAvg' => $teamScoreAvg,
|
|
'*score*' => '=========',
|
|
'wealthK' => $wealthK,
|
|
'wealthE' => $wealthE,
|
|
'wealthValue' => Hero::getHeroWealth($heroDb),
|
|
'*wealth*' => (1 + $wealthE * (Hero::getHeroWealth($heroDb) / (Hero::getHeroWealth($heroDb) + $wealthK))),
|
|
'lastCompute' => isset($lastCompute) ? $lastCompute : '空',
|
|
'currentCompute' => isset($currentCompute) ? $currentCompute : '空',
|
|
'*compute*' => isset($compute) ? $compute : '算力系统关闭',
|
|
'finalGold' => floor($gold)
|
|
)));
|
|
}
|
|
if ($gold > 0){
|
|
array_push($reward,array(
|
|
"item_id" => V_ITEM_GOLD,
|
|
"item_num" => floor($gold),
|
|
));
|
|
myself()->_incDailyV(TN_DAILY_GATHER_GOLD,0,floor($gold));
|
|
}
|
|
}
|
|
|
|
//宝箱掉落
|
|
if ($rewardMeta['chestLootProb'] > 0){
|
|
$rand = $rewardMeta['chestLootProb'] * 100;
|
|
$rnd = rand(1,100);
|
|
if ($rnd <= $rand){
|
|
$chestItems = LootService::dropOutItem($rewardMeta['chestLoot']);
|
|
foreach ($chestItems as $item){
|
|
array_push($reward,$item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function _calBattleScore($battleInfo){
|
|
$paramMeta = mt\Parameter::getVal('performance_score_range',0);
|
|
$paramMetaMoba = mt\Parameter::getVal('performance_score_weight_4V4',0);
|
|
$paramMetaPvp = mt\Parameter::getVal('performance_score_weight_BR',0);
|
|
$weightMoba = explode("|",$paramMetaMoba);
|
|
$weightPvp = explode("|",$paramMetaPvp);
|
|
$scoreParam = explode("|",$paramMeta);
|
|
if (count($scoreParam) < 2){
|
|
error_log('Parameter table error');
|
|
return 0;
|
|
}
|
|
$room_mode = getXVal($this->inputData,'room_mode', 0);
|
|
if ($this->maxKill == 0) {
|
|
$killSco = $scoreParam[0];
|
|
} else {
|
|
$kill = getXVal($battleInfo, 'pvp_kill', 0);
|
|
$killSco = ($scoreParam[1] - $scoreParam[0]) / ($this->maxKill - 0) * ($kill - 0) + $scoreParam[0];
|
|
}
|
|
if ($this->maxAssist == 0) {
|
|
$assistSco = $scoreParam[0];
|
|
} else {
|
|
$assist = getXVal($battleInfo, 'pvp_assist', 0);
|
|
$assistSco = ($scoreParam[1] - $scoreParam[0]) / ($this->maxAssist - 0) * ($assist - 0) + $scoreParam[0];
|
|
}
|
|
if ($this->maxDamage == 0) {
|
|
$damageSco = $scoreParam[0];
|
|
} else {
|
|
$damage = getXVal($battleInfo, 'pvp_damage', 0);
|
|
$damageSco = ($scoreParam[1] - $scoreParam[0]) / ($this->maxDamage - 0) * ($damage - 0) + $scoreParam[0];
|
|
}
|
|
if ($this->maxRecover == 0) {
|
|
$recoverSco = $scoreParam[0];
|
|
} else {
|
|
$recover = getXVal($battleInfo, 'pvp_recover', 0);
|
|
$recoverSco = ($scoreParam[1] - $scoreParam[0]) / ($this->maxRecover - 0) * ($recover - 0) + $scoreParam[0];
|
|
}
|
|
if ($this->maxLevel == 1) {
|
|
$levelSco = $scoreParam[0];
|
|
} else {
|
|
$level = getXVal($battleInfo, 'hero_lv', 0);
|
|
$levelSco = ($scoreParam[1] - $scoreParam[0]) / ($this->maxLevel - 0) * ($level - 0) + $scoreParam[0];
|
|
}
|
|
if ($this->maxAlive == 0) {
|
|
$aliveSco = $scoreParam[0];
|
|
} else {
|
|
$alive = getXVal($battleInfo, 'pvp_survia_time', 0) / 1000;
|
|
$aliveSco = ($scoreParam[1] - $scoreParam[0]) / ($this->maxAlive - 0) * ($alive - 0) + $scoreParam[0];
|
|
}
|
|
switch ($room_mode){
|
|
case self::ROOM_MODE_PVP: {
|
|
if (count($weightPvp) == 5){
|
|
$killSco *= $weightPvp[0];
|
|
$assistSco *= $weightPvp[1];
|
|
$damageSco *= $weightPvp[2];
|
|
$recoverSco *= $weightPvp[3];
|
|
$aliveSco *= $weightPvp[4];
|
|
}
|
|
$battleScore = round($killSco + $assistSco + $damageSco + $recoverSco + $aliveSco , 2);
|
|
}
|
|
break;
|
|
case self::ROOM_MODE_MOBA :{
|
|
if (count($weightMoba) == 5){
|
|
$killSco *= $weightMoba[0];
|
|
$assistSco *= $weightMoba[1];
|
|
$damageSco *= $weightMoba[2];
|
|
$recoverSco *= $weightMoba[3];
|
|
$levelSco *= $weightMoba[4];
|
|
}
|
|
$battleScore = round($killSco + $assistSco + $damageSco + $recoverSco + $levelSco , 2);
|
|
}
|
|
break;
|
|
default : {
|
|
$battleScore = 0;
|
|
}
|
|
}
|
|
return $battleScore;
|
|
}
|
|
|
|
private function getMyRanked($account){
|
|
foreach ($this->teamExpScoreSort as $k=>$value){
|
|
if ($value['account_id'] == $account){
|
|
return $k+1;
|
|
}
|
|
}
|
|
return 8;
|
|
}
|
|
|
|
}
|