446 lines
17 KiB
PHP
446 lines
17 KiB
PHP
<?php
|
||
|
||
require_once('mt/Parameter.php');
|
||
require_once('mt/Drop.php');
|
||
require_once('mt/Task.php');
|
||
require_once('mt/Season.php');
|
||
require_once('mt/RankSeason.php');
|
||
require_once('models/DynData.php');
|
||
require_once('models/Mission.php');
|
||
require_once('models/Hero.php');
|
||
require_once('models/Gun.php');
|
||
|
||
require_once('services/AwardService.php');
|
||
require_once('services/PropertyChgService.php');
|
||
require_once('services/SeasonService.php');
|
||
require_once('services/MissionService.php');
|
||
require_once('services/FormulaService.php');
|
||
require_once('services/LogService.php');
|
||
|
||
use phpcommon\SqlHelper;
|
||
use models\DynData;
|
||
use models\Mission;
|
||
use models\Hero;
|
||
use models\Gun;
|
||
use services\LogService;
|
||
|
||
class MissionController extends BaseAuthedController {
|
||
|
||
private $missionService = null;
|
||
private $awardService = null;
|
||
private $propertyChgService = null;
|
||
private $userInfo = null;
|
||
private $seasonService = null;
|
||
private $currRankSeasonMeta = null;
|
||
private $seasonDb = null;
|
||
|
||
public function _handlePre()
|
||
{
|
||
parent::_handlePre();
|
||
|
||
DynData::preload();
|
||
// $this->currRankSeasonMeta = mt\RankSeason::getCurrentSeason();
|
||
// if (!$this->currRankSeasonMeta) {
|
||
// $this->_rspErr(10, 'server internal error');
|
||
// die();
|
||
// }
|
||
$this->propertyChgService = new services\PropertyChgService();
|
||
$this->userInfo = $this->_safeGetOrmUserInfo();
|
||
// $this->seasonDb = Season::find($this->currRankSeasonMeta['id']);
|
||
// if (!$this->seasonDb) {
|
||
// Season::add($this->currRankSeasonMeta['id']);
|
||
// $this->seasonDb = Season::find($this->currRankSeasonMeta['id']);
|
||
// }
|
||
// if (!$this->seasonDb) {
|
||
// $this->_rspErr(10, 'server internal error');
|
||
// die();
|
||
// }
|
||
$this->awardService = new services\AwardService();
|
||
$this->missionService = new services\MissionService();
|
||
$this->missionService->init($this->userInfo, $this->seasonDb);
|
||
}
|
||
|
||
|
||
public function missionList()
|
||
{
|
||
$type = getReqVal('type', 0);
|
||
$missionMetaList = mt\Task::getCustomTypeMetaList($type, $this->missionService);
|
||
$missionHash = Mission::allToHash();
|
||
$missionDtoList1 = array();
|
||
$missionDtoList2 = array();
|
||
$specMissionDto = null;
|
||
$notFinishedCount = 0;
|
||
foreach ($missionMetaList as $missionMeta) {
|
||
$missionDb = getXVal($missionHash, $missionMeta['id'], null);
|
||
$missionDto = $this->missionService->getMissionDto(
|
||
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
||
if ($missionMeta['type'] == mt\Task::DAILY_MISSON_TYPE) {
|
||
if (in_array($missionMeta['subtype'],
|
||
array(
|
||
mt\Task::DAILY_ACTIVE_VALUE_MISSON_SUBTYPE,
|
||
mt\Task::WEAKLY_ACTIVE_VALUE_MISSON_SUBTYPE
|
||
))) {
|
||
array_push($missionDtoList1, $missionDto);
|
||
} else {
|
||
array_push($missionDtoList2, $missionDto);
|
||
// if ($missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
||
// $notFinishedCount++;
|
||
// }
|
||
// if ($missionMeta['condition'] == mt\Task::FINISHED_ALL_DAILY_MISSION_COND) {
|
||
// $specMissionDto &= $missionDto;
|
||
// }
|
||
}
|
||
} else {
|
||
array_push($missionDtoList1, $missionDto);
|
||
}
|
||
}
|
||
// if ($specMissionDto &&
|
||
// $specMissionDto['state'] == Mission::NOT_FINISHED_STATE &&
|
||
// $notFinishedCount <= 1) {
|
||
//// $specMissionDto['state'] = Mission::RECEIVEABLE_STATE;
|
||
// $specMissionDto['state'] = 9636;
|
||
// }
|
||
|
||
//刷新任务所需
|
||
{
|
||
$refreshTimes = $this->_getDailyV(TN_DAILY_REFRESH_MISSION_TIMES, 0);
|
||
$maxRefreshTimes = mt\Parameter::getVal('task_refresh_max', 0);
|
||
$taskCostParam = explode("|",mt\Parameter::getVal('task_refresh_cost', 10));
|
||
|
||
$key = min($refreshTimes,count($taskCostParam)-1);
|
||
|
||
$refreshInfo = array(
|
||
"refreshTimes" =>$refreshTimes,
|
||
"maxRefreshTimes" =>$maxRefreshTimes,
|
||
"item_id" =>V_ITEM_GOLD,
|
||
"item_num" =>$taskCostParam[$key],
|
||
);
|
||
}
|
||
$this->_rspData(array(
|
||
'current_day_active_value' => min($this->_getDailyV(TN_DAILY_ACTIVE, 0), mt\Parameter::getVal('activeness_limit', 0)),
|
||
'current_week_active_value' => min($this->_getWeeklyV(TN_WEEKLY_ACTIVE, 0), mt\Parameter::getVal('max_weekly', 0)),
|
||
'day_active_limit' => mt\Parameter::getVal('activeness_limit', 0),
|
||
'week_active_limit' => mt\Parameter::getVal('max_weekly', 0),
|
||
'day_time_end' => $this->_getDaySeconds(time())+3600*24,
|
||
'week_time_end' => $this->_getMondaySeconds() + 7*24*3600,
|
||
'mission_list1' => $missionDtoList1,
|
||
'mission_list2' => $missionDtoList2,
|
||
'refreshInfo' => $refreshInfo
|
||
));
|
||
}
|
||
|
||
public function commitMission()
|
||
{
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$missionMeta = mt\Task::get($missionId);
|
||
if (!$missionMeta) {
|
||
$this->_rspErr(1, 'mission_id parameter error');
|
||
return;
|
||
}
|
||
//
|
||
// if ($missionMeta['type'] == mt\Task::DAILY_MISSON_TYPE &&
|
||
// $missionMeta['subtype'] == mt\Task::WEAKLY_ACTIVE_VALUE_MISSON_SUBTYPE) {
|
||
// error_log(2);
|
||
// return;
|
||
// }
|
||
//
|
||
$missionDb = Mission::find($missionId);
|
||
$missionDto = $this->missionService->getMissionDto(
|
||
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
||
if (!$missionDto) {
|
||
$this->_rspErr(10, 'server internal error');
|
||
return;
|
||
}
|
||
if ($missionDto['state'] == Mission::RECEIVED_STATE) {
|
||
$this->_rspErr(2, "Can't get it again");
|
||
return;
|
||
}
|
||
if ($missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
||
$this->_rspErr(3, 'Mission objectives not achieved');
|
||
return;
|
||
}
|
||
// if ($missionMeta['condition'] == mt\Task::FINISHED_ALL_DAILY_MISSION_COND) {
|
||
// if (!$this->specMissionIsFinished($missionDto, $missionMeta)) {
|
||
// $this->_rspErr(3, 'Mission objectives not achieved');
|
||
// return;
|
||
// }
|
||
// }print_r($missionMeta);die;
|
||
if ($missionDto['state'] != Mission::RECEIVEABLE_STATE) {
|
||
$this->_rspErr(3, 'Unknown mission status');
|
||
return;
|
||
}
|
||
$dropMeta = mt\Drop::get($missionMeta['reward']);
|
||
if (!$dropMeta) {
|
||
$this->_rspErr(10, 'server internal error:' . $missionMeta['reward']);
|
||
return;
|
||
}
|
||
$this->_scatterDrop('mission:' . $missionId, $dropMeta, $this->awardService, $this->propertyChgService);
|
||
// $this->procSpecMissionCommit($missionDto, $missionMeta);
|
||
Mission::add($missionId);
|
||
$missionDb = Mission::find($missionId);
|
||
$missionDto = $this->missionService->getMissionDto(
|
||
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
||
if ( $missionMeta['type'] == \mt\Task::DAILY_MISSON_TYPE &&
|
||
! $missionMeta['subtype'] ){
|
||
$this->_incDailyV(TN_DAILY_COMPLETE_TASK_NUM, 0, 1);
|
||
}
|
||
|
||
$this->propertyChgService->addHeroChg();
|
||
$this->propertyChgService->addGunChg();
|
||
$this->_rspData(array(
|
||
'award' => $this->awardService->toDto(),
|
||
'property_chg' => $this->propertyChgService->toDto(),
|
||
'mission_chg' => $missionDto
|
||
));
|
||
}
|
||
|
||
public function commitAll()
|
||
{
|
||
$type = getReqVal('type', 0);
|
||
$missionMetaList = mt\Task::getCustomTypeMetaList(0, $this->missionService);
|
||
$missionHash = Mission::allToHash();
|
||
$missionDtoList = array();
|
||
$specMissionDto = null;
|
||
$notFinishedCount = 0;
|
||
foreach ($missionMetaList as $missionMeta) {
|
||
$missionDb = getXVal($missionHash, $missionMeta['id'], null);
|
||
$missionDto = $this->missionService->getMissionDto(
|
||
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
||
if ($missionDto['state'] == Mission::RECEIVEABLE_STATE) {
|
||
array_push($missionDtoList, $missionDto);
|
||
}
|
||
// if ($missionMeta['type'] == mt\Task::DAILY_MISSON_TYPE) {
|
||
// if ($missionMeta['subtype'] == mt\Task::DAILY_ACTIVE_VALUE_MISSON_SUBTYPE) {
|
||
// } else {
|
||
// if ($missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
||
// $notFinishedCount++;
|
||
// }
|
||
// if ($missionMeta['condition'] == mt\Task::FINISHED_ALL_DAILY_MISSION_COND &&
|
||
// $missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
||
// $specMissionDto = &$missionDto;
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
// if ($specMissionDto &&
|
||
// $specMissionDto['state'] == Mission::NOT_FINISHED_STATE &&
|
||
// $notFinishedCount <= 1) {
|
||
// $specMissionDto['state'] = Mission::RECEIVEABLE_STATE;
|
||
// array_push($missionDtoList, $missionDto);
|
||
// }
|
||
|
||
if (count($missionDtoList) < 1){
|
||
$this->_rspErr(1, "There are not rewards");
|
||
return;
|
||
}
|
||
foreach ($missionDtoList as $missionDto) {
|
||
$missionMeta = mt\Task::get($missionDto['mission_id']);
|
||
$dropMeta = mt\Drop::get($missionMeta['reward']);
|
||
if ($dropMeta) {
|
||
$dropSource = 'mission:' . $missionDto['mission_id'];
|
||
$this->_scatterDrop($dropSource, $dropMeta, $this->awardService, $this->propertyChgService);
|
||
Mission::add($missionDto['mission_id']);
|
||
if ( $missionMeta['type'] == \mt\Task::DAILY_MISSON_TYPE &&
|
||
! $missionMeta['subtype'] ){
|
||
$this->_incDailyV(TN_DAILY_COMPLETE_TASK_NUM, 0, 1);
|
||
}
|
||
}
|
||
// $this->procSpecMissionCommit($missionDto, $missionMeta);
|
||
}
|
||
$this->_rspData(array(
|
||
'award' => $this->awardService->toDto(),
|
||
'property_chg' => $this->propertyChgService->toDto(),
|
||
));
|
||
}
|
||
|
||
private function specMissionIsFinished($missionDto, $missionMeta)
|
||
{
|
||
$type = mt\Task::DAILY_MISSION_CUSTOM_TYPE;
|
||
$missionMetaList = mt\Task::getCustomTypeMetaList($type);
|
||
$missionHash = Mission::allToHash();
|
||
$notFinishedCount = 0;
|
||
foreach ($missionMetaList as $missionMeta) {
|
||
$missionDb = getXVal($missionHash, $missionMeta['id'], null);
|
||
$missionDto = $this->missionService->getMissionDto(
|
||
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
||
if ($missionMeta['type'] == mt\Task::DAILY_MISSON_TYPE) {
|
||
if ($missionMeta['subtype'] == mt\Task::DAILY_ACTIVE_VALUE_MISSON_SUBTYPE) {
|
||
} else {
|
||
if ($missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
||
$notFinishedCount++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $notFinishedCount == 1;
|
||
}
|
||
|
||
public function sendOfferRewardMission()
|
||
{
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$this->missionService->sendOfferRewardMission(
|
||
$missionId,
|
||
$this->propertyChgService);
|
||
}
|
||
|
||
public function offerRewardMissionPreview()
|
||
{
|
||
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$this->missionService->offerRewardMissionPreview(
|
||
$missionId
|
||
);
|
||
}
|
||
|
||
public function cancelOfferRewardMission()
|
||
{
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$this->missionService->cancelOfferRewardMission(
|
||
$missionId,
|
||
$this->propertyChgService);
|
||
}
|
||
|
||
public function boostOfferRewardMissionPreview(){
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$missionMeta = mt\Task::get($missionId);
|
||
if (!$missionMeta) {
|
||
$this->_rspErr(1, 'mission_id parameter error');
|
||
return;
|
||
}
|
||
//
|
||
if ($missionMeta['type'] == mt\Task::DAILY_MISSON_TYPE &&
|
||
$missionMeta['subtype'] == mt\Task::WEAKLY_ACTIVE_VALUE_MISSON_SUBTYPE) {
|
||
error_log(2);
|
||
return;
|
||
}
|
||
//
|
||
$missionDb = Mission::find($missionId);
|
||
$missionDto = $this->missionService->getMissionDto(
|
||
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
||
if (!$missionDto) {
|
||
$this->_rspErr(10, 'server internal error');
|
||
return;
|
||
}
|
||
if ($missionDto['lefttime']<=0){
|
||
$this->_rspErr(1, "Don't need to accelerate");
|
||
return;
|
||
}
|
||
$boost_ceg = \services\FormulaService::calcBoostMissionCeg($missionDto['ceg_num'],$missionDto['lefttime'],$missionMeta['time']);
|
||
$this->_rspData(array(
|
||
'boost_chg' => $boost_ceg
|
||
));
|
||
}
|
||
|
||
public function boostOfferRewardMission()
|
||
{
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$this->missionService->boostOfferRewardMission(
|
||
$missionId,
|
||
$this->awardService,
|
||
$this->propertyChgService);
|
||
}
|
||
|
||
|
||
private function procSpecMissionCommit($missionDto, $missionMeta)
|
||
{
|
||
switch ($missionMeta['type']) {
|
||
case mt\Task::DAILY_MISSON_TYPE:
|
||
{
|
||
//(账号内所有PVE角色NFT每日获得极限总和(CEG)+账号内所有PVE武器NFT每日获得极限总和(CEG))*10%/每日任务数量
|
||
$this->propertyChgService->addUserChg();
|
||
$cegUpLimit = Hero::getRawPveCegUpLimit() + Gun::getRawPveCegUpLimit();
|
||
$count = mt\Task::getDaildyMissionCount();
|
||
if (!$count || !$cegUpLimit) {
|
||
$this->_rspErr(10, 'server internal error:');
|
||
return;
|
||
}
|
||
$gold = ($cegUpLimit * 0.1) / $count;
|
||
error_log(json_encode(array(
|
||
'cegUpLimit' => $cegUpLimit,
|
||
'count' => $count,
|
||
'ceg' => $gold
|
||
)));
|
||
myself()->_addVirtualItem(V_ITEM_GOLD, round($gold,2));
|
||
$this->awardService->addItem(V_ITEM_GOLD, round($gold,2));
|
||
}
|
||
break;
|
||
case mt\Task::OFFER_REWARD_MISSON_TYPE:
|
||
{
|
||
$this->missionService->receiveOfferRewardMission
|
||
($missionDto['mission_id'],
|
||
$this->awardService,
|
||
$this->propertyChgService);
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
public function refreshMissionList()
|
||
{
|
||
|
||
$missionMetaList = mt\Task::getCustomTypeMetaList(0, $this->missionService);
|
||
$missionHash = Mission::allToHash();
|
||
$missionDtoList = array();
|
||
$refreshList = array();
|
||
$specMissionDto = null;
|
||
$num =1;
|
||
foreach ($missionMetaList as $missionMeta) {
|
||
$num ++;
|
||
$missionDb = getXVal($missionHash, $missionMeta['id'], null);
|
||
$missionDto = $this->missionService->getMissionDto(
|
||
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
||
array_push($missionDtoList, $num);
|
||
if ($missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
||
array_push($refreshList, $missionDto['mission_id']);
|
||
}
|
||
}
|
||
// //任务全完成不刷新
|
||
|
||
//刷新次数上限不刷新
|
||
$refreshTimes = $this->_getDailyV(TN_DAILY_REFRESH_MISSION_TIMES, 0);
|
||
$maxRefreshTimes = mt\Parameter::getVal('task_refresh_max', 0);
|
||
if ($refreshTimes >= $maxRefreshTimes || count($refreshList) < 1){
|
||
$this->_rspErr(1, 'Unable to refresh');
|
||
return;
|
||
}
|
||
//消耗不足不刷新
|
||
$taskCostParam = explode("|",mt\Parameter::getVal('task_refresh_cost', 10));
|
||
$key = min($refreshTimes,count($taskCostParam)-1);
|
||
$costNum = $taskCostParam[$key];
|
||
$costItems = array(
|
||
array(
|
||
'item_id' => V_ITEM_GOLD,
|
||
'item_num' => $costNum
|
||
),
|
||
);
|
||
$lackItem = null;
|
||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||
return;
|
||
}
|
||
foreach ($refreshList as $value){
|
||
$this->missionService->updateDailyRewardMission($value);
|
||
}
|
||
|
||
$this->_incDailyV(TN_DAILY_REFRESH_MISSION_TIMES, 0,1);
|
||
$this->_decItems($costItems);
|
||
{
|
||
//埋点
|
||
$event = [
|
||
'name' => LogService::REFRESH_MISSION,
|
||
'val' => $costNum
|
||
];
|
||
LogService::consumeGold($event);
|
||
}
|
||
$this->propertyChgService->addUserChg();
|
||
$this->_rspData(array(
|
||
'property_chg' => $this->propertyChgService->toDto(),
|
||
));
|
||
}
|
||
|
||
}
|