1307 lines
51 KiB
PHP
1307 lines
51 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/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('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\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 BattleDataService extends BaseService {
|
|
|
|
const MAX_DROP_NUM = 2;
|
|
|
|
const MATCH_MODE_PVP = 0;
|
|
const MATCH_MODE_MATCH = 1;
|
|
const MATCH_MODE_PVE = 2;
|
|
|
|
public $teamList = array();
|
|
|
|
private $seasonDb = array();
|
|
private $userinfo = array();
|
|
private $heroDto = null;
|
|
private $heroMeta = null;
|
|
private $weapon1Dto = null;
|
|
private $weapon2Dto = null;
|
|
private $currSeasonMeta = null;
|
|
|
|
private $reward = array(
|
|
'hero' => array(
|
|
'hero_uniid' => '',
|
|
'ceg_uplimit' => 0,
|
|
'obtain_ceg' => 0,
|
|
'curr_ceg' => 0,
|
|
),
|
|
'total_ceg' => 0,
|
|
'is_settlement' => 0,
|
|
'items' => array(),
|
|
);
|
|
private $rankActivityService = null;
|
|
private $pveGeminiMeta = null;
|
|
private $pveGeminiModeMeta = null;
|
|
private $instanceRank = 0;
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->rankActivityService = new RankActivityService();
|
|
}
|
|
|
|
public function updateBattleData()
|
|
{
|
|
// error_log(json_encode($_REQUEST));
|
|
$matchMode = getReqVal('match_mode', 0);
|
|
// {
|
|
// $heroDb = Hero::find(getReqVal('hero_uniid', 0));
|
|
// if (!$heroDb) {
|
|
// return false;
|
|
// }
|
|
// $this->heroDto = Hero::toDto($heroDb);
|
|
// if (Hero::heroIsLocking($heroDb)) {
|
|
// return false;
|
|
// }
|
|
// $this->heroMeta = mt\Hero::get($this->heroDto['hero_id']);
|
|
// if (!$this->heroMeta) {
|
|
// return false;
|
|
// }
|
|
// $this->reward['hero']['hero_uniid'] = $this->heroDto['hero_uniid'];
|
|
// $this->reward['hero']['ceg_uplimit'] = $this->heroDto['gold_uplimit'];
|
|
// }
|
|
|
|
|
|
//录入战斗记录
|
|
// $this->saveBattleHistory();
|
|
// error_log('updateBattleData0----------'.$matchMode);
|
|
switch ($matchMode) {
|
|
case self::MATCH_MODE_PVP:
|
|
{
|
|
error_log('updateBattleData1');
|
|
//匹配赛模式
|
|
$this->updatePvpData();
|
|
// $this->rewardCegPvp();
|
|
myself()->_incDailyV(TN_DAILY_PVP_BATTLE_TIMES, 0, 1);
|
|
}
|
|
break;
|
|
case self::MATCH_MODE_MATCH:
|
|
{
|
|
//排位赛(和匹配合二为一)
|
|
// $this->updateSeasonData();
|
|
// myself()->_incDailyV(TN_DAILY_RANK_BATTLE_TIMES, 0, 1);
|
|
}
|
|
break;
|
|
case self::MATCH_MODE_PVE:
|
|
{
|
|
//pve
|
|
$this->updatePveData();
|
|
if ($this->pveGeminiMeta &&
|
|
$this->pveGeminiModeMeta) {
|
|
$this->rewardFragmentPve();
|
|
}
|
|
myself()->_incDailyV(TN_DAILY_PVE_BATTLE_TIMES, 0, 1);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public function rewardExpPvp(){
|
|
$expNum = 222;
|
|
if ($expNum>0){
|
|
array_push($this->reward['items'],
|
|
array(
|
|
'item_id' => V_ITEM_EXP,
|
|
'item_num' => $expNum
|
|
));
|
|
$userInfo = myself()->_getOrmUserInfo();
|
|
$newExp = $userInfo['exp']+$expNum;
|
|
$newLv = $userInfo['level'];
|
|
mt\LevelUp::getExpByLv($newLv,$newExp);
|
|
$this->reward['lvInfo'] = array(
|
|
'oldLv' => $userInfo['level'],
|
|
'newLv' => $newLv
|
|
);
|
|
if ( $newExp != $userInfo['exp'] ) {
|
|
myself()->_updateUserInfo(array(
|
|
'level' => $newLv,
|
|
'exp' => $newExp,
|
|
));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private function saveBattleHistory(){
|
|
$user = myself()->_getOrmUserInfo();
|
|
$newRank = $user['rank'];
|
|
$newScore = $user['score'];
|
|
$match_mode = getReqVal('match_mode', 0);
|
|
if (mt\RankSeason::getCurrentSeason() && !$match_mode && myself()->_getV(TN_RANK_STATUS, 0 ) == 0 ){
|
|
$winningPro = $this->celWinningPro();
|
|
if ($winningPro){
|
|
$newScore = FormulaService::calcBattleAfterRankScore($user,$_REQUEST,$winningPro); //赛后排位积分
|
|
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
|
|
}
|
|
$match_mode = 1;
|
|
}
|
|
$gold = 0;
|
|
if (getReqVal('is_team_statemented', 0) == 1){
|
|
$gold = FormulaService::calcHeroPvpGold($this->heroDto, $_REQUEST,$user);
|
|
}
|
|
$data = array(
|
|
"battle_uniid" => getReqVal('battle_uuid', 0),
|
|
"account_id" => myself()->_getAccountId(),
|
|
"match_mode" => $match_mode,
|
|
"team_mode" => getReqVal('team_mode', 0),
|
|
"battle_rank" => getReqVal('ranked', 0),
|
|
"team_rank" => getReqVal('team_rank', 0), // 队伍排名
|
|
"team_kills" => getReqVal('team_kills', 0), // 队伍击杀数
|
|
"gold" => $gold, // 队伍击杀数
|
|
"is_win" => getReqVal('pve_kill_boss', 0),
|
|
"kills" => getReqVal('kills', 0),
|
|
"hero_id" => getReqVal('hero_uniid', 0),
|
|
"weapon1" => getReqVal('weapon_uuid1', 0),
|
|
"weapon2" => getReqVal('weapon_uuid2', 0),
|
|
"damage" => getReqVal('damage_out', 0),
|
|
"battle_end_time" => myself()->_getNowTime(),
|
|
"current_level_class" => $newRank,
|
|
"current_level_class_score" => $newScore,
|
|
"level_class_score_chg" => $newScore-$user['score'], // 排位分改变
|
|
"pve_rank_score" => getReqVal('pve_rank_score', 0),
|
|
"pve_kill_boss" => getReqVal('pve_kill_boss', 0),
|
|
"pve_instance_id" => getReqVal('pve_instance_id', 0),
|
|
"pve_instance_mode" => getReqVal('pve_instance_mode', 0),
|
|
);
|
|
BattleHistory::add($data);
|
|
}
|
|
|
|
public function getReward()
|
|
{
|
|
return $this->reward;
|
|
}
|
|
|
|
private function apply(&$battleData)
|
|
{
|
|
//战斗次数
|
|
$this->incValue($battleData, 'total_battle_times', 1);
|
|
if (getReqVal('team_mode', 0) == 0) {
|
|
//单人模式战斗次数
|
|
$this->incValue($battleData, 'total_single_battle_times', 1);
|
|
//单人模式最高排名
|
|
$this->minValue($battleData, 'single_battle_rank', getReqVal('ranked', 0));
|
|
} else {
|
|
//组队模式最高排名
|
|
$this->minValue($battleData, 'team_battle_rank', getReqVal('ranked', 0));
|
|
//组队模式战斗次数
|
|
$this->incValue($battleData, 'total_team_battle_times', 1);
|
|
//组队模式前30名次数
|
|
if (getReqVal('ranked', 0) <= 30){
|
|
$this->incValue($battleData, 'total_team_top_X_battle_times', 1);
|
|
}
|
|
}
|
|
$ranked = getReqVal('ranked', 0);
|
|
if ($ranked == 1) {
|
|
//吃鸡次数
|
|
$this->incValue($battleData, 'total_win_times', 1);
|
|
}
|
|
if ($ranked <= 10){
|
|
//排名前十 总次数
|
|
$this->incValue($battleData, 'total_top_ten_times', 1);
|
|
}
|
|
$kills = getReqVal('kills', 0);
|
|
if ($kills > 0) {
|
|
//击杀总次数
|
|
$this->incValue($battleData, 'total_kills_times', $kills);
|
|
//单局最大击杀数
|
|
$this->maxValue($battleData, 'max_kills_times', $kills);
|
|
}
|
|
$damageOut = getReqVal('damage_out', 0);
|
|
if ($damageOut > 0) {
|
|
//伤害输出总量
|
|
$this->incValue($battleData, 'total_damage_out', $damageOut);
|
|
//单局最大伤害输出
|
|
$this->maxValue($battleData, 'max_damage_out', $damageOut);
|
|
}
|
|
$damageIn = getReqVal('damage_in', 0);
|
|
if ($damageIn > 0) {
|
|
//受到伤害总量
|
|
$this->incValue($battleData, 'total_damage_in', $damageIn);
|
|
//单局最大受到伤害量
|
|
$this->maxValue($battleData, 'max_damage_in', $damageIn);
|
|
}
|
|
$recoverHp = getReqVal('recover_hp', 0);
|
|
if ($recoverHp > 0) {
|
|
//自疗总量
|
|
$this->incValue($battleData, 'total_recover_hp', $recoverHp);
|
|
//单局最大自疗量
|
|
$this->maxValue($battleData, 'max_recover_hp', $recoverHp);
|
|
}
|
|
$aliveTime = getReqVal('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', getReqVal('rescue_teammate_times', 0));
|
|
//潜水次数
|
|
$this->incValue($battleData, 'diving_times', getReqVal('diving_times', 0));
|
|
//开启空投次数
|
|
$this->incValue($battleData, 'open_airdrop_times', getReqVal('open_airdrop_times', 0));
|
|
//使用药品次数
|
|
$this->incValue($battleData, 'use_medicine_times', getReqVal('use_medicine_times', 0));
|
|
//击毁机甲次数
|
|
$this->incValue($battleData, 'destory_car_times', getReqVal('destory_car_times', 0));
|
|
//使用伪装次数
|
|
$this->incValue($battleData, 'use_camouflage_times', getReqVal('use_camouflage_times', 0));
|
|
//使用技能次数
|
|
$this->incValue($battleData, 'use_skill_times', getReqVal('use_skill_times', 0));
|
|
//驾驶机甲移动距离
|
|
$this->incValue($battleData, 'ride_car_move_distance', getReqVal('ride_car_move_distance', 0));
|
|
//驾驶机甲击杀数
|
|
$this->incValue($battleData, 'ride_car_kills', getReqVal('ride_car_kills', 0));
|
|
//使用的英雄最高等级
|
|
$this->maxValue($battleData, 'max_single_battle_hero_lv', getReqVal('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('|', getReqVal('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('|', getReqVal('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('|', getReqVal('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 = getReqVal('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 = getReqVal('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 = getReqVal('weapon_uuid1', '');
|
|
$weapon1 = Gun::find($weapon_uuid1);
|
|
if ($weapon1){
|
|
$this->incValue($heroInfo[$hero['hero_id']]['weapon'], $weapon1['gun_id'], 1);//该英雄下选用每个武器的次数
|
|
}
|
|
$weapon_uuid2 = getReqVal('weapon_uuid2', '');
|
|
$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);
|
|
}
|
|
|
|
private function updateScore()
|
|
{
|
|
$userInfo = myself()->_getOrmUserInfo();
|
|
$newRank = $userInfo['rank'];
|
|
$winningPro = $this->celWinningPro();
|
|
if ($winningPro){
|
|
$newScore = FormulaService::calcBattleAfterRankScore($userInfo,$_REQUEST,$winningPro); //赛后排位积分
|
|
$newElo = FormulaService::calcUserEloValue($userInfo,$_REQUEST,$winningPro); //赛后elo积分
|
|
mt\Rank::calcNewRankAndScore( $newRank, $newScore);
|
|
if ( $newScore != $userInfo['score'] ) {
|
|
myself()->_updateUserInfo(array(
|
|
'rank' => $newRank,
|
|
'score' => $newScore,
|
|
'elo' => $newElo,
|
|
'history_best_rank' => max($userInfo['rank'], $newRank),
|
|
'history_best_score' => max($userInfo['score'], $newScore),
|
|
'score_modifytime' => myself()->_getNowTime(),
|
|
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
|
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
|
));
|
|
Season::update($this->currSeasonMeta['id'], array(
|
|
'rank' => $newRank,
|
|
'score' => $newScore,
|
|
'elo' => $newElo,
|
|
'history_best_rank' => max($userInfo['rank'], $newRank),
|
|
'score_modifytime' => myself()->_getNowTime(),
|
|
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
|
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function celWinningPro(){
|
|
$team_id = getReqVal('team_id', 0);
|
|
if (empty($this->teamList) || ! count($this->teamList)){
|
|
error_log('ELO1-----没获取到所有队伍信息:AllTeamList');
|
|
return false;
|
|
}
|
|
$userInfo = myself()->_getOrmUserInfo();
|
|
$myAvg = 0;
|
|
$opponentAvg = 0;
|
|
$teamIdHash = array();
|
|
foreach ($this->teamList as &$team){
|
|
foreach ($team['members'] as $k=>$member){
|
|
if (!empty($member['account_id'])){
|
|
$channelId = phpcommon\extractChannel($member['account_id']);
|
|
if ($channelId == SELFSDK_CHANNEL) {
|
|
unset($team['members'][$k]);
|
|
}
|
|
}else{
|
|
unset($team['members'][$k]);
|
|
}
|
|
}
|
|
$teamIdHash[$team['team_id']] = $team;
|
|
}
|
|
$myTeam = array_key_exists($team_id,$teamIdHash)?$teamIdHash[$team_id]:null;
|
|
unset($teamIdHash[$team_id]);
|
|
if (!$myTeam){
|
|
error_log('ELO2-----没获取到我的队伍信息:MyTeamList');
|
|
return false;
|
|
}
|
|
$myTeamEloSum = 0;
|
|
foreach ($myTeam['members'] as $value){
|
|
$userDb = User::find($value['account_id']);
|
|
$myTeamEloSum+=$userDb['elo'];
|
|
}
|
|
$myAvg = $myTeamEloSum/count($myTeam['members']);
|
|
$tempSumList = array();
|
|
foreach ($teamIdHash as $k=>&$item){
|
|
if ($team_id != $item['team_id'] && count($item['members'])>0){
|
|
$tempSum = 0;
|
|
foreach ($item['members'] as $value){
|
|
$userDb = User::find($value['account_id']);
|
|
$tempSum += $userDb['elo'];
|
|
}
|
|
array_push($tempSumList,$tempSum/count($item['members']));
|
|
}
|
|
}
|
|
if (count($tempSumList) > 0){
|
|
$opponentAvg = array_sum($tempSumList)/count($tempSumList);
|
|
//总胜率=70%*P(个人ELO值-敌队平均ELO值)+30%*P(己队平均ELO值-敌队平均ELO值) --> P(D)=1/(1+10^(-D/400))
|
|
$winningPro = 1/(1+pow(10,(-(0.7*($userInfo['elo']-$opponentAvg)+0.3*($myAvg-$opponentAvg))/400)));
|
|
}else{
|
|
error_log('ELO3-----无真人敌对队伍');
|
|
$winningPro = 0.5;
|
|
}
|
|
error_log(json_encode(
|
|
array(
|
|
'myElo' =>$userInfo['elo'],
|
|
'myAvg' => $myAvg,
|
|
'myTeam' =>$myTeam,
|
|
'opponentAvg'=>$tempSumList,
|
|
'winningPro' => $winningPro,
|
|
)
|
|
));
|
|
return $winningPro;
|
|
}
|
|
|
|
private function _settlementMyTeamGold(){
|
|
$team_id = getReqVal('team_id', 0);
|
|
$battleUid = getReqVal('battle_uuid', 0);
|
|
$myTeam = array();
|
|
foreach ($this->teamList as $team){
|
|
if ($team['team_id'] == $team_id){
|
|
$myTeam = $team['members'];
|
|
}
|
|
}
|
|
foreach ($myTeam as $member){
|
|
if (!empty($member['account_id'])){
|
|
$user = User::find($member['account_id']);
|
|
if ($member['account_id'] != myself()->_getAccountId()){
|
|
$battleDb = BattleHistory::findByAccount($member['account_id'],$battleUid);
|
|
if ($battleDb){
|
|
$heroDto = Hero::toDto(Hero::find($battleDb['hero_id']));
|
|
$heroPvpGold = FormulaService::calcHeroPvpGold($heroDto, $_REQUEST,$user);
|
|
$heroPvpGold = Hero::gainGoldPvp($heroDto, $heroPvpGold);
|
|
BattleHistory::updateField($member['account_id'],$battleUid,
|
|
array(
|
|
'gold' => $heroPvpGold,
|
|
'team_rank' => getReqVal('team_rank', 0),
|
|
'team_kills' => getReqVal('team_kills', 0),
|
|
));
|
|
//给该用户 add gold
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private function rewardGold($heroDto)
|
|
{
|
|
$heroMeta = mt\Item::get($heroDto['hero_id']);
|
|
if (!$heroMeta) {
|
|
return;
|
|
}
|
|
$heroPvpCeg = FormulaService::calcHeroPvpCeg($heroDto, $_REQUEST);
|
|
$weaponPvpCeg1 = 0;
|
|
$weaponPvpCeg2 = 0;
|
|
$weaponDb1 = Gun::find(getReqVal('weapon_uuid1', 0));
|
|
if ($weaponDb1) {
|
|
$weaponDto1 = Gun::toDto($weaponDb1);
|
|
$weaponPvpCeg1 = FormulaService::calcWeaponPvpCeg($weaponDto1, $_REQUEST);
|
|
}
|
|
$weaponDb2 = Gun::find(getReqVal('weapon_uuid2', 0));
|
|
if ($weaponDb2) {
|
|
$weaponDto2 = Gun::toDto($weaponDb2);
|
|
$weaponPvpCeg2 = FormulaService::calcWeaponPvpCeg($weaponDto2, $_REQUEST);
|
|
}
|
|
error_log(json_encode(array(
|
|
'heroPvpCeg' => $heroPvpCeg,
|
|
'weaponPvpCeg1' => $weaponPvpCeg1,
|
|
'weaponPvpCeg2' => $weaponPvpCeg2,
|
|
)));
|
|
if ($heroPvpCeg > 0) {
|
|
$heroPvpCeg = Hero::gainGoldPvp($heroDto, $heroPvpCeg);
|
|
}
|
|
if ($weaponPvpCeg1 > 0) {
|
|
$weaponPvpCeg1 = Gun::gainGoldPvp($weaponDto1, $weaponPvpCeg1);
|
|
}
|
|
if ($weaponPvpCeg2 > 0) {
|
|
$weaponPvpCeg2 = Gun::gainGoldPvp($weaponDto2, $weaponPvpCeg2);
|
|
}
|
|
error_log(json_encode(array(
|
|
'new_heroPvpCeg' => $heroPvpCeg,
|
|
'new_weaponPvpCeg1' => $weaponPvpCeg1,
|
|
'new_weaponPvpCeg2' => $weaponPvpCeg2,
|
|
)));
|
|
$gold = $heroPvpCeg + $weaponPvpCeg1 + $weaponPvpCeg2;
|
|
if ($gold > 0) {
|
|
myself()->_addVirtualItem(V_ITEM_GOLD, $gold);
|
|
}
|
|
}
|
|
|
|
// private function updatePvpData()
|
|
// {
|
|
// error_log('updateBattleData1');
|
|
// $this->rankActivityService->updateBattleData();
|
|
// error_log('updateBattleData2');
|
|
// $hisBattleData = Battle::getMyBattleData();
|
|
// if (!isset($hisBattleData)) {
|
|
// $hisBattleData = array(
|
|
// 'createtime' => myself()->_getNowTime(),
|
|
// 'modifytime' => myself()->_getNowTime()
|
|
// );
|
|
// }
|
|
// $this->apply($hisBattleData);
|
|
// Battle::add(json_encode($hisBattleData));
|
|
// }
|
|
|
|
private function updatePvpData()
|
|
{
|
|
|
|
error_log('updateBattleData2');
|
|
$hisBattleData = Battle::getMyBattleData();
|
|
if (!isset($hisBattleData)) {
|
|
$hisBattleData = array(
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
);
|
|
}
|
|
$this->apply($hisBattleData);
|
|
Battle::add(json_encode($hisBattleData));
|
|
error_log('updateBattleData:'.json_encode($hisBattleData));
|
|
//
|
|
// error_log('updateBattleData3');
|
|
$this->currSeasonMeta = mt\RankSeason::getCurrentSeason();
|
|
error_log('currSeasonMeta:'.$this->currSeasonMeta['id']);
|
|
//// if ( $this->currSeasonMeta && myself()->_getV(TN_RANK_STATUS, 0 ) == 0) {
|
|
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;
|
|
}
|
|
error_log('updateBattleData4');
|
|
// $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['his_week_data'])) {
|
|
$seasonBattleData['his_week_data'] = array(
|
|
);
|
|
}
|
|
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 updatePveData()
|
|
{
|
|
$instanceId = getReqVal('pve_instance_id', 0);
|
|
$instanceMode = getReqVal('pve_instance_mode', 0);
|
|
$pveRankScore = getReqVal('pve_rank_score', 0);
|
|
$userInfo = myself()->_getOrmUserInfo();
|
|
$this->pveGeminiMeta = mt\PveGemini::get($instanceId);
|
|
if ($this->pveGeminiMeta) {
|
|
if (!(
|
|
$instanceId == mt\PveGemini::FIRST_INSTANCE_ID ||
|
|
$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 (getReqVal('pve_kill_boss', 0) == 1) {
|
|
if ($this->pveGeminiMeta) {
|
|
myself()->_updateUserInfo(array(
|
|
'pve_instance_id' => $instanceId
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
private function rewardFragmentPvp()
|
|
{
|
|
{
|
|
$ranked = getReqVal('ranked', 0);
|
|
$kills = getReqVal('kills', 0);
|
|
$aliveTime = getReqVal('alive_time', 0)/1000;
|
|
$cond = (1 - ($ranked > 30 ? 1 : 0) *
|
|
($kills < 1 ? 1 : 0) *
|
|
($aliveTime < 30 ? 1 : 0));
|
|
if (!$cond) {
|
|
return;
|
|
}
|
|
}
|
|
//print_r($this->reward);die;
|
|
$todayPveGetFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 0);
|
|
$todayPvpGetFragmentNum = myself()->_getDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 0);
|
|
|
|
if ($todayPveGetFragmentNum + $todayPvpGetFragmentNum < self::MAX_DROP_NUM) {
|
|
$todayPvpBattleTimes = myself()->_getDailyV(TN_DAILY_PVP_BATTLE_TIMES, 0);
|
|
|
|
$onlineNum = RealtimeData::getOnline();
|
|
$heroFragmentNum = FragmentPool::getHeroNum(0);
|
|
$gunFragmentNum = FragmentPool::getGunNum(0);
|
|
|
|
$heroProbability = FormulaService::calcHeroFragmentProbabilityPvp
|
|
($_REQUEST,
|
|
$onlineNum,
|
|
$heroFragmentNum,
|
|
$todayPvpBattleTimes);
|
|
$gunProbability = FormulaService::calcWeaponFragmentProbabilityPvp
|
|
($_REQUEST,
|
|
$onlineNum,
|
|
$gunFragmentNum,
|
|
$todayPvpBattleTimes);
|
|
$emptyProbability = max(1 - $heroProbability - $gunProbability, 0);
|
|
|
|
$dropIdx = $this->randWeight(array($heroProbability, $gunProbability, $emptyProbability));
|
|
$this->procDrop($dropIdx);
|
|
}
|
|
}
|
|
|
|
private function rewardFragmentPve()
|
|
{
|
|
$bossReward = getReqVal('pve_kill_boss', 0) ? 1 : 0;
|
|
if ($this->instanceRank < 1 || !$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);
|
|
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($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($dropGunFragmentId,2);
|
|
FragmentRecord::upsertGamesNum(FragmentRecord::GUN_FRAGMENT,0);
|
|
}else{
|
|
FragmentRecord::upsertGamesNum(FragmentRecord::GUN_FRAGMENT,$gamesNum+1);
|
|
}
|
|
|
|
}
|
|
|
|
// $todayPveBattleTimes = myself()->_getDailyV(TN_DAILY_PVE_BATTLE_TIMES, 0);
|
|
// $todayPveLastGetFragmentBattle = myself()->_getDailyV(TN_DAILY_PVE_LAST_GET_FRAGMENT_BATTLE, 0);
|
|
// $todayPveGetFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 0);
|
|
// $todayPvpGetFragmentNum = myself()->_getDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 0);
|
|
//
|
|
// if ($todayPveGetFragmentNum + $todayPvpGetFragmentNum < self::MAX_DROP_NUM) {
|
|
// $onlineNum = RealtimeData::getOnline();
|
|
// $heroFragmentNum = FragmentPool::getHeroNum(1);
|
|
// $gunFragmentNum = FragmentPool::getGunNum(1);
|
|
//
|
|
// $instanceLevel = $this->pveGeminiMeta['gemini_lv'];
|
|
// $instanceRank = $this->instanceRank;
|
|
// $instanceRankRate = $this->getInstanceRankRate();
|
|
// $bossReward = getReqVal('pve_kill_boss', 0) ? 1 : 0;
|
|
// $heroQuality = $this->heroDto['quality'];
|
|
//
|
|
// $heroProbability = FormulaService::calcHeroFragmentProbabilityPve
|
|
// (
|
|
// $heroQuality,
|
|
// $onlineNum,
|
|
// $heroFragmentNum,
|
|
// $todayPveBattleTimes,
|
|
// $instanceLevel,
|
|
// $instanceRank,
|
|
// $instanceRankRate,
|
|
// $bossReward,
|
|
// $todayPveLastGetFragmentBattle
|
|
// );
|
|
// $gunProbability = FormulaService::calcWeaponFragmentProbabilityPve
|
|
// (
|
|
// $heroQuality,
|
|
// $onlineNum,
|
|
// $gunFragmentNum,
|
|
// $todayPveBattleTimes,
|
|
// $instanceLevel,
|
|
// $instanceRank,
|
|
// $instanceRankRate,
|
|
// $bossReward,
|
|
// $todayPveLastGetFragmentBattle
|
|
// );
|
|
// $emptyProbability = max(1 - $heroProbability - $gunProbability, 0);
|
|
//
|
|
// $dropIdx = $this->randWeight(array($heroProbability, $gunProbability, $emptyProbability));
|
|
// $this->procDrop($dropIdx);
|
|
// }
|
|
}
|
|
|
|
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($itemId,$type){
|
|
$itemMeta = mt\Item::get($itemId);
|
|
if ($itemMeta){
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
array_push($this->reward['items'],
|
|
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 rewardGoldPvp()
|
|
{
|
|
$this->_settlementMyTeamGold();
|
|
$heroPvpGold = FormulaService::calcHeroPvpGold($this->heroDto, $_REQUEST,$this->userinfo);
|
|
error_log(json_encode(array(
|
|
'heroPvpGold' => $heroPvpGold,
|
|
)));
|
|
if ($heroPvpGold > 0) {
|
|
$heroPvpGold = Hero::gainGoldPvp($this->heroDto, $heroPvpGold);
|
|
{
|
|
//埋点
|
|
$log_param = [
|
|
'battle_uniid' => getReqVal('battle_uniid', 0),
|
|
'match_mode' => getReqVal('match_mode', 0),
|
|
'room_uuid' => getReqVal('room_uuid', 0),
|
|
];
|
|
$event = [
|
|
'name' => LogService::BATTLE_AWARD_PVP,
|
|
'val' => $heroPvpGold
|
|
];
|
|
LogService::productCEG($event,$this->heroDto,$log_param);
|
|
}
|
|
|
|
$this->reward['hero']['curr_gold'] = '' . ($this->heroDto['current_get_gold'] + $heroPvpGold);
|
|
$this->reward['hero']['obtain_gold'] = '' . ($this->heroDto['current_get_gold'] + $heroPvpGold);
|
|
$this->reward['total_gold'] += $heroPvpGold;
|
|
}
|
|
|
|
$this->reward['total_gold'] .= '';
|
|
error_log(json_encode(array(
|
|
'new_heroPvpGold' => $heroPvpGold,
|
|
)));
|
|
$gold = $heroPvpGold;
|
|
error_log('updateBattleData1');
|
|
$this->rankActivityService->updateBattleData($gold);
|
|
if ($gold > 0) {
|
|
myself()->_addVirtualItem(V_ITEM_GOLD, $gold);
|
|
}
|
|
}
|
|
|
|
private function rewardCegPvp()
|
|
{
|
|
{
|
|
$ranked = getReqVal('ranked', 0);
|
|
$kills = getReqVal('kills', 0);
|
|
$aliveTime = getReqVal('alive_time', 0)/1000;
|
|
$log_param = [
|
|
'battle_uniid' => getReqVal('battle_uniid', 0),
|
|
'match_mode' => getReqVal('match_mode', 0),
|
|
'room_uuid' => getReqVal('room_uuid', 0),
|
|
];
|
|
$cond = (1 - ($ranked > 30 ? 1 : 0) *
|
|
($kills < 1 ? 1 : 0) *
|
|
($aliveTime < 30 ? 1 : 0));
|
|
if (!$cond) {
|
|
return;
|
|
}
|
|
}
|
|
$heroPvpCeg = FormulaService::calcHeroPvpCeg($this->heroDto, $_REQUEST);
|
|
error_log(json_encode(array(
|
|
'heroPvpCeg' => $heroPvpCeg,
|
|
)));
|
|
if ($heroPvpCeg > 0) {
|
|
$heroPvpCeg = Hero::gainGoldPvp($this->heroDto, $heroPvpCeg);
|
|
{
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BATTLE_AWARD_PVP,
|
|
'val' => $heroPvpCeg
|
|
];
|
|
LogService::productCEG($event,$this->heroDto,$log_param);
|
|
}
|
|
|
|
$this->reward['hero']['curr_ceg'] = '' . ($this->heroDto['current_get_gold'] + $heroPvpCeg);
|
|
$this->reward['hero']['obtain_ceg'] = '' . ($this->heroDto['current_get_gold'] + $heroPvpCeg);
|
|
$this->reward['total_ceg'] += $heroPvpCeg;
|
|
}
|
|
|
|
$this->reward['total_ceg'] .= '';
|
|
error_log(json_encode(array(
|
|
'new_heroPvpCeg' => $heroPvpCeg,
|
|
)));
|
|
$gold = $heroPvpCeg;
|
|
error_log('updateBattleData1');
|
|
$this->rankActivityService->updateBattleData($gold);
|
|
if ($gold > 0) {
|
|
myself()->_addVirtualItem(V_ITEM_GOLD, $gold);
|
|
}
|
|
}
|
|
|
|
private function rewardCegPve()
|
|
{
|
|
$log_param = [
|
|
'battle_uniid' => getReqVal('battle_uniid', 0),
|
|
'match_mode' => getReqVal('match_mode', 0),
|
|
'room_uuid' => getReqVal('room_uuid', 0),
|
|
];
|
|
if ($this->instanceRank < 1) {
|
|
return;
|
|
}
|
|
$instanceLevel = $this->pveGeminiMeta['gemini_lv'];
|
|
$bossReward = getReqVal('pve_kill_boss', 0) ? 1 : 0;
|
|
|
|
$heroPveCeg = FormulaService::calcHeroPveCeg(
|
|
$this->heroDto,
|
|
$instanceLevel,
|
|
$this->instanceRank,
|
|
$bossReward);
|
|
$weaponPveCeg1 = 0;
|
|
$weaponPveCeg2 = 0;
|
|
if ($this->weapon1Dto) {
|
|
$weaponPveCeg1 = FormulaService::calcWeaponPveCeg(
|
|
$this->weapon1Dto,
|
|
$instanceLevel,
|
|
$this->instanceRank,
|
|
$bossReward);
|
|
}
|
|
if ($this->weapon2Dto) {
|
|
$weaponPveCeg2 = FormulaService::calcWeaponPveCeg(
|
|
$this->weapon2Dto,
|
|
$instanceLevel,
|
|
$this->instanceRank,
|
|
$bossReward);
|
|
}
|
|
error_log(json_encode(array(
|
|
'heroPveCeg' => $heroPveCeg,
|
|
'weaponPveCeg1' => $weaponPveCeg1,
|
|
'weaponPveCeg2' => $weaponPveCeg2,
|
|
)));
|
|
if ($heroPveCeg > 0) {
|
|
$heroPveCeg = Hero::gainGoldPve($this->heroDto, $heroPveCeg);
|
|
|
|
{
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BATTLE_AWARD_PVE,
|
|
'val' => $heroPveCeg
|
|
];
|
|
LogService::productCEG($event,$this->heroDto,$log_param);
|
|
}
|
|
|
|
$this->reward['hero']['obtain_ceg'] = '' . ($this->heroDto['current_pve_get_ceg'] + $heroPveCeg);
|
|
$this->reward['total_ceg'] += $heroPveCeg;
|
|
}
|
|
if ($weaponPveCeg1 > 0) {
|
|
$weaponPveCeg1 = Gun::gainGoldPve($this->weapon1Dto, $weaponPveCeg1);
|
|
|
|
{
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BATTLE_AWARD_PVE,
|
|
'val' => $weaponPveCeg1
|
|
];
|
|
LogService::productCEG($event,$this->weapon1Dto,$log_param);
|
|
}
|
|
|
|
$this->reward['weapon1']['obtain_ceg'] = '' . ($this->weapon1Dto['current_pve_get_ceg'] + $weaponPveCeg1);
|
|
$this->reward['total_ceg'] += $weaponPveCeg1;
|
|
}
|
|
if ($weaponPveCeg2 > 0) {
|
|
$weaponPveCeg2 = Gun::gainGoldPve($this->weapon1Dto, $weaponPveCeg2);
|
|
|
|
{
|
|
//埋点
|
|
$event = [
|
|
'name' => LogService::BATTLE_AWARD_PVE,
|
|
'val' => $weaponPveCeg2
|
|
];
|
|
LogService::productCEG($event,$this->weapon2Dto,$log_param);
|
|
}
|
|
|
|
$this->reward['weapon2']['obtain_ceg'] = '' . ($this->weapon2Dto['current_pve_get_ceg'] + $weaponPveCeg2);
|
|
$this->reward['total_ceg'] += $weaponPveCeg2;
|
|
}
|
|
$this->reward['total_ceg'] .= '';
|
|
error_log(json_encode(array(
|
|
'new_heroPveCeg' => $heroPveCeg,
|
|
'new_weaponPveCeg1' => $weaponPveCeg1,
|
|
'new_weaponPveCeg2' => $weaponPveCeg2,
|
|
)));
|
|
$gold = $heroPveCeg + $weaponPveCeg1 + $weaponPveCeg2;
|
|
error_log('updateBattleData1');
|
|
$this->rankActivityService->updateBattleData($gold);
|
|
if ($heroPveCeg>0){
|
|
NftService::addNftActive($this->heroDto,1);
|
|
}
|
|
if ($weaponPveCeg1>0){
|
|
NftService::addNftActive($this->weapon1Dto,2);
|
|
}
|
|
if ($weaponPveCeg2>0){
|
|
NftService::addNftActive($this->weapon2Dto,2);
|
|
}
|
|
if ($gold > 0) {
|
|
myself()->_addVirtualItem(V_ITEM_GOLD, $gold);
|
|
}
|
|
}
|
|
|
|
private function randWeight($items)
|
|
{
|
|
// error_log(json_encode($items));
|
|
$weights = array();
|
|
{
|
|
$weight = 0;
|
|
foreach ($items as $item) {
|
|
$weight += (int)($item * 10000);
|
|
array_push($weights, $weight);
|
|
}
|
|
}
|
|
if (count($weights) > 0) {
|
|
$rnd = rand(0, $weights[count($weights) - 1]);
|
|
for ($i = 0; $i < count($weights); ++$i) {
|
|
if ($rnd <= $weights[$i]) {
|
|
return $i;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private function getInstanceRankRate()
|
|
{
|
|
switch ($this->instanceRank) {
|
|
case 1:
|
|
{
|
|
return 0.8;
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
return 0.55;
|
|
}
|
|
break;
|
|
case 3:
|
|
{
|
|
return 0.3;
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
return 0;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private function procDrop($dropIdx)
|
|
{
|
|
$log_param = [
|
|
'battle_uniid' => getReqVal('battle_uniid', 0),
|
|
'match_mode' => getReqVal('match_mode', 0),
|
|
'room_uuid' => getReqVal('room_uuid', 0),
|
|
'fragment_type' => $dropIdx
|
|
];
|
|
$event = array();
|
|
|
|
$todayPveBattleTimes = myself()->_getDailyV(TN_DAILY_PVE_BATTLE_TIMES, 0);
|
|
$todayPveLastGetFragmentBattle = myself()->_getDailyV(TN_DAILY_PVE_LAST_GET_FRAGMENT_BATTLE, 0);
|
|
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
$matchMode = getReqVal('match_mode', 0);
|
|
$type = 0;
|
|
if ($matchMode == self::MATCH_MODE_PVE) {
|
|
$type = 1;
|
|
$event['name'] = LogService::BATTLE_AWARD_PVE;
|
|
}
|
|
if ($matchMode == self::MATCH_MODE_PVP) {
|
|
$event['name'] = LogService::BATTLE_AWARD_PVP;
|
|
}
|
|
if ($matchMode == self::MATCH_MODE_MATCH) {
|
|
$type = 1;
|
|
$event['name'] = LogService::BATTLE_AWARD_MATCH;
|
|
}
|
|
if ($dropIdx == 0) {
|
|
$itemId = FragmentPool::dropHero($type);
|
|
if ($itemId) {
|
|
array_push($this->reward['items'],
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => 1
|
|
));
|
|
myself()->_addItems(
|
|
array(
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => 1
|
|
)),
|
|
$awardService,
|
|
$propertyChgService
|
|
);
|
|
if ($matchMode == self::MATCH_MODE_PVE) {
|
|
myself()->_incDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 0, 1);
|
|
myself()->_setDailyV(TN_DAILY_PVE_LAST_GET_FRAGMENT_BATTLE, 0, $todayPveBattleTimes + 1);
|
|
} else {
|
|
myself()->_incDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 0, 1);
|
|
}
|
|
|
|
{
|
|
//埋点
|
|
$event['item_id'] = $itemId;
|
|
$event['number'] = 1;
|
|
LogService::productFragment($event,$log_param);
|
|
}
|
|
}
|
|
} else if ($dropIdx == 1) {
|
|
$itemId = FragmentPool::dropGun($type);
|
|
if ($itemId) {
|
|
array_push($this->reward['items'],
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => 1
|
|
));
|
|
myself()->_addItems(
|
|
array(
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => 1
|
|
)),
|
|
$awardService,
|
|
$propertyChgService
|
|
);
|
|
if ($matchMode == self::MATCH_MODE_PVE) {
|
|
myself()->_incDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 0, 1);
|
|
myself()->_setDailyV(TN_DAILY_PVE_LAST_GET_FRAGMENT_BATTLE, 0, $todayPveBattleTimes + 1);
|
|
} else {
|
|
myself()->_incDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 0, 1);
|
|
}
|
|
|
|
{
|
|
//埋点
|
|
$event['item_id'] = $itemId;
|
|
$event['number'] = 1;
|
|
LogService::productFragment($event,$log_param);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|