740 lines
28 KiB
PHP
740 lines
28 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('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/FragmentPool.php');
|
|
require_once('models/RealtimeData.php');
|
|
|
|
require_once('services/RankActivityService.php');
|
|
require_once('services/FormulaService.php');
|
|
|
|
use mt;
|
|
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 services\FormulaService;
|
|
|
|
class BattleDataService extends BaseService {
|
|
|
|
const MAX_DROP_NUM = 2;
|
|
|
|
const MATCH_MODE_PVP = 0;
|
|
const MATCH_MODE_MATCH = 1;
|
|
const MATCH_MODE_PVE = 2;
|
|
|
|
private $seasonDb = array();
|
|
private $heroDto = null;
|
|
private $heroMeta = null;
|
|
private $weapon1Dto = null;
|
|
private $weapon2Dto = null;
|
|
|
|
private $reward = array(
|
|
'hero' => array(),
|
|
'weapon1' => array(),
|
|
'weapon2' => array(),
|
|
'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');
|
|
{
|
|
$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'] = $matchMode == self::MATCH_MODE_PVE ?
|
|
$this->heroDto['pve_ceg_uplimit'] : $this->heroDto['pvp_ceg_uplimit'];
|
|
}
|
|
{
|
|
$weaponUuid1 = getReqVal('weapon_uuid1', '');
|
|
if ($weaponUuid1) {
|
|
$weaponDb = Gun::find($weaponUuid1);
|
|
if (!$weaponDb) {
|
|
return false;
|
|
}
|
|
$this->weapon1Dto = Gun::toDto($weaponDb);
|
|
$this->reward['weapon1']['gun_uniid'] = $this->weapon1Dto['gun_uniid'];
|
|
$this->reward['weapon1']['ceg_uplimit'] = $matchMode == self::MATCH_MODE_PVE ?
|
|
$this->weapon1Dto['pve_ceg_uplimit'] : $this->weapon1Dto['pvp_ceg_uplimit'];
|
|
}
|
|
}
|
|
{
|
|
$weaponUuid2 = getReqVal('weapon_uuid2', '');
|
|
if ($weaponUuid2) {
|
|
$weaponDb = Gun::find($weaponUuid2);
|
|
if (!$weaponDb) {
|
|
return false;
|
|
}
|
|
$this->weapon2Dto = Gun::toDto($weaponDb);
|
|
$this->reward['weapon2']['gun_uniid'] = $this->weapon2Dto['gun_uniid'];
|
|
$this->reward['weapon2']['ceg_uplimit'] = $matchMode == self::MATCH_MODE_PVE ?
|
|
$this->weapon2Dto['pve_ceg_uplimit'] : $this->weapon2Dto['pvp_ceg_uplimit'];
|
|
}
|
|
}
|
|
switch ($matchMode) {
|
|
case self::MATCH_MODE_PVP:
|
|
{
|
|
//匹配赛模式
|
|
$this->updatePvpData();
|
|
$this->rewardCegPvp();
|
|
$this->rewardFragmentPvp();
|
|
$this->_incDailyV(TN_DAILY_PVP_BATTLE_TIMES, 1);
|
|
}
|
|
break;
|
|
case self::MATCH_MODE_MATCH:
|
|
{
|
|
//排位赛
|
|
}
|
|
break;
|
|
case self::MATCH_MODE_PVE:
|
|
{
|
|
//pve
|
|
$this>updatePveData();
|
|
if ($this->pveGeminiMeta &&
|
|
$this->pveGeminiMetaMode) {
|
|
$this->rewardCegPve();
|
|
$this->rewardFragmentPve();
|
|
}
|
|
$this->_incDailyV(TN_DAILY_PVE_BATTLE_TIMES, 1);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
if (getReqVal('ranked', 0) == 1) {
|
|
$this->incValue($battleData, 'total_win_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', $damage_out);
|
|
$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', $kills);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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()
|
|
{
|
|
if (getReqVal('room_mode', 0) == 0) {
|
|
$userInfo = myself()->_getOrmUserInfo();
|
|
$rankScore = getReqVal('rank_score', 0);
|
|
if ($rankScore > 0) {
|
|
$newRank = $userInfo['rank'];
|
|
$newScore = $userInfo['score'];
|
|
mt\Rank::calcNewRankAndScore($userInfo['rank'], $userInfo['score'], $newRank, $newScore, $rankScore);
|
|
if ($newRank >= $userInfo['rank'] && $newScore != $userInfo['score']) {
|
|
myself()->_updateUserInfo(array(
|
|
'rank' => $newRank,
|
|
'score' => $newScore,
|
|
'history_best_rank' => max($userInfo['rank'], $newRank),
|
|
'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,
|
|
'history_best_rank' => max($userInfo['rank'], $newRank),
|
|
'score_modifytime' => myself()->_getNowTime(),
|
|
'score_modifytime' => myself()->_getNowTime(),
|
|
'best_rank_modifytime' => $newRank > $userInfo['rank'] ?
|
|
myself()->_getNowTime() : $userInfo['best_rank_modifytime'],
|
|
));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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');
|
|
$this->currSeasonMeta = mt\Season::getCurrentSeason();
|
|
if (!$this->currSeasonMeta) {
|
|
return;
|
|
}
|
|
error_log('updateBattleData3');
|
|
$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();
|
|
$hisBattleData = Battle::getMyBattleData();
|
|
if (!isset($hisBattleData)) {
|
|
$hisBattleData = array(
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
);
|
|
}
|
|
$this->apply($hisBattleData);
|
|
Battle::add(json_encode($hisBattleData));
|
|
$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 (!($userInfo['pve_instance_id'] == $instanceId ||
|
|
$userInfo['pve_instance_id'] == $instanceId + 1)) {
|
|
$this->pveGeminiMeta = null;
|
|
}
|
|
}
|
|
$this->pveGeminiMetaMode = 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()
|
|
{
|
|
$todayPveGetFragmentNum = $this->_getDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 0);
|
|
$todayPvpGetFragmentNum = $this->_getDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 0);
|
|
|
|
if ($todayPveGetFragmentNum + $todayPvpGetFragmentNum < self::MAX_DROP_NUM) {
|
|
$todayPvpBattleTimes = $this->_getDailyV(TN_DAILY_PVP_BATTLE_TIMES, 0);
|
|
|
|
$onlineNum = RealtimeData::getOnline();
|
|
$heroFragmentNum = FragmentPool::getHeroNum();
|
|
$gunFragmentNum = FragmentPool::getGunNum();
|
|
|
|
$heroProbability = FormulaService::calcHeroFragmentProbabilityPvp
|
|
($_REQUEST,
|
|
$onlineNum,
|
|
$heroFragmentNum,
|
|
$todayPvpBattleTimes);
|
|
$gunProbability = FormulaService::calcGunFragmentProbabilityPvp
|
|
($_REQUEST,
|
|
$onlineNum,
|
|
$gunFragmentNum,
|
|
$todayPvpBattleTimes);
|
|
|
|
$heroProbability = max($heroProbability, 0);
|
|
$gunProbability = max($gunProbability, 0);
|
|
$emptyProbability = max(1 - $heroProbability - $gunProbability, 0);
|
|
|
|
$dropIdx = $this->randWeight(array($heroProbability, $gunProbability, $emptyProbability));
|
|
$this->procDrop($dropIdx);
|
|
}
|
|
}
|
|
|
|
private function rewardFragmentPve()
|
|
{
|
|
$todayPveBattleTimes = $this->_getDailyV(TN_DAILY_PVE_BATTLE_TIMES, 0);
|
|
$todayPveGetFragmentNum = $this->_getDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 0);
|
|
$todayPvpGetFragmentNum = $this->_getDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 0);
|
|
|
|
if ($todayPveGetFragmentNum + $todayPvpGetFragmentNum < self::MAX_DROP_NUM) {
|
|
$onlineNum = RealtimeData::getOnline();
|
|
$heroFragmentNum = FragmentPool::getHeroNum();
|
|
$gunFragmentNum = FragmentPool::getGunNum();
|
|
|
|
$instanceLevel = $this->pveGeminiMeta['gemini_lv'];
|
|
$instanceRank = $this->instanceRank;
|
|
$instanceRankRate = $this->getInstanceRankRate();
|
|
$bossReward = getReqVal('pve_kill_boss', 0) ? 1 : 0;
|
|
$heroQuality = $this->heroDto['quality'];
|
|
|
|
$dropRate = max(1.15 - ($heroQuality - $instanceLevel) * 0.25, 0);
|
|
$dropMul = 0.8 - ($instanceRank - 1) * 0.25 + $bossReward * 0.2;
|
|
|
|
$heroProbability = min($heroFragmentNum / $onlineNum *
|
|
$dropRate * ($instanceRankRate + $bossReward*0.2) *
|
|
pow(2, $todayPveBattleTimes - $todayPveGetFragmentNum -1), 1);
|
|
$gunProbability = min($gunFragmentNum / $onlineNum *
|
|
$dropRate * ($instanceRankRate + $bossReward*0.2) *
|
|
pow(2, $todayPveBattleTimes - $todayPveGetFragmentNum -1), 1);
|
|
|
|
$heroProbability = max($heroProbability, 0);
|
|
$gunProbability = max($gunProbability, 0);
|
|
$emptyProbability = max(1 - $heroProbability - $gunProbability, 0);
|
|
|
|
$dropIdx = $this->randWeight(array($heroProbability, $gunProbability, $emptyProbability));
|
|
$this->procDrop($dropIdx);
|
|
}
|
|
}
|
|
|
|
private function rewardCegPvp()
|
|
{
|
|
{
|
|
$ranked = getReqVal('ranked', 0);
|
|
$kills = getReqVal('kills', 0);
|
|
$aliveTime = getReqVal('alive_time', 0);
|
|
$cond = (1 - ($ranked > 30 ? 1 : 0)) *
|
|
($kills > 1 ? 1 : 0) *
|
|
($aliveTime > 30 ? 1 : 0);
|
|
if ($cond) {
|
|
return;
|
|
}
|
|
}
|
|
$heroPvpCeg = FormulaService::calcHeroPvpCeg($this->heroDto, $_REQUEST);
|
|
$weaponPvpCeg1 = 0;
|
|
$weaponPvpCeg2 = 0;
|
|
if ($this->weapon1Dto) {
|
|
$weaponPvpCeg1 = FormulaService::calcWeaponPvpCeg($this->weapon1Dto, $_REQUEST);
|
|
}
|
|
if ($this->weapon2Dto) {
|
|
$weaponPvpCeg2 = FormulaService::calcWeaponPvpCeg($this->weapon2Dto, $_REQUEST);
|
|
}
|
|
error_log(json_encode(array(
|
|
'heroPvpCeg' => $heroPvpCeg,
|
|
'weaponPvpCeg1' => $weaponPvpCeg1,
|
|
'weaponPvpCeg2' => $weaponPvpCeg2,
|
|
)));
|
|
if ($heroPvpCeg > 0) {
|
|
$heroPvpCeg = Hero::gainGoldPvp($this->heroDto, $heroPvpCeg);
|
|
$this->reward['hero']['obtain_ceg'] = $this->heroDto['current_pvp_get_ceg'] + $heroPvpCeg;
|
|
}
|
|
if ($weaponPvpCeg1 > 0) {
|
|
$weaponPvpCeg1 = Gun::gainGoldPvp($this->weapon1Dto, $weaponPvpCeg1);
|
|
$this->reward['weapon1']['obtain_ceg'] = $this->weapon1Dto['current_pvp_get_ceg'] + $weaponPvpCeg1;
|
|
}
|
|
if ($weaponPvpCeg2 > 0) {
|
|
$weaponPvpCeg2 = Gun::gainGoldPvp($this->weapon1Dto, $weaponPvpCeg2);
|
|
$this->reward['weapon2']['obtain_ceg'] = $this->weapon2Dto['current_pvp_get_ceg'] + $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 rewardCegPve()
|
|
{
|
|
$instanceLevel = $this->pveGeminiMeta['gemini_lv'];
|
|
$bossReward = getReqVal(pve_kill_boss) ? 1 : 0;
|
|
|
|
$heroPveCeg = FormulaService::calcHeroPveCeg($this->heroDto, $instanceLevel, $instanceRank, $bossReward);
|
|
$weaponPveCeg1 = 0;
|
|
$weaponPveCeg2 = 0;
|
|
if ($this->weapon1Dto) {
|
|
$weaponPveCeg1 = FormulaService::calcWeaponPveCeg($this->weapon1Dto, $instanceLevel, $instanceRank, $bossReward);
|
|
}
|
|
if ($this->weapon2Dto) {
|
|
$weaponPveCeg2 = FormulaService::calcWeaponPveCeg($this->weapon2Dto, $instanceLevel, $instanceRank, $bossReward);
|
|
}
|
|
error_log(json_encode(array(
|
|
'heroPveCeg' => $heroPveCeg,
|
|
'weaponPveCeg1' => $weaponPveCeg1,
|
|
'weaponPveCeg2' => $weaponPveCeg2,
|
|
)));
|
|
if ($heroPveCeg > 0) {
|
|
$heroPveCeg = Hero::gainGoldPve($this->heroDto, $heroPveCeg);
|
|
$this->reward['hero']['obtain_ceg'] = $this->heroDto['current_pve_get_ceg'] + $heroPveCeg;
|
|
}
|
|
if ($weaponPveCeg1 > 0) {
|
|
$weaponPveCeg1 = Gun::gainGoldPve($this->weapon1Dto, $weaponPveCeg1);
|
|
$this->reward['weapon1']['obtain_ceg'] = $this->weapon1Dto['current_pve_get_ceg'] + $weaponPveCeg1;
|
|
}
|
|
if ($weaponPveCeg2 > 0) {
|
|
$weaponPveCeg2 = Gun::gainGoldPve($this->weapon1Dto, $weaponPveCeg2);
|
|
$this->reward['weapon2']['obtain_ceg'] = $this->weapon2Dto['current_pve_get_ceg'] + $weaponPveCeg2;
|
|
}
|
|
error_log(json_encode(array(
|
|
'new_heroPveCeg' => $heroPveCeg,
|
|
'new_weaponPveCeg1' => $weaponPveCeg1,
|
|
'new_weaponPveCeg2' => $weaponPveCeg2,
|
|
)));
|
|
$gold = $heroPveCeg + $weaponPveCeg1 + $weaponPveCeg2;
|
|
if ($gold > 0) {
|
|
myself()->_addVirtualItem(V_ITEM_GOLD, $gold);
|
|
}
|
|
}
|
|
|
|
private function randWeight($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)
|
|
{
|
|
$matchMode = getReqVal('match_mode');
|
|
if ($dropIdx == 0) {
|
|
$itemId = FragmentPool::dropHero();
|
|
if ($itemId) {
|
|
array_push($this->reward['items'],
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => 1
|
|
));
|
|
if ($matchMode == self::MATCH_MODE_PVE) {
|
|
$this->_incDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 1);
|
|
} else {
|
|
$this->_incDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 1);
|
|
}
|
|
}
|
|
} else if ($dropIdx == 1) {
|
|
$itemId = FragmentPool::dropGun();
|
|
if ($itemId) {
|
|
array_push($this->reward['items'],
|
|
array(
|
|
'item_id' => $itemId,
|
|
'item_num' => 1
|
|
));
|
|
if ($matchMode == self::MATCH_MODE_PVE) {
|
|
$this->_incDailyV(TN_DAILY_PVE_GET_FRAGMENT_NUM, 1);
|
|
} else {
|
|
$this->_incDailyV(TN_DAILY_PVP_GET_FRAGMENT_NUM, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|