164 lines
6.0 KiB
PHP
164 lines
6.0 KiB
PHP
<?php
|
|
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/Task.php');
|
|
require_once('mt/Season.php');
|
|
|
|
require_once('models/User.php');
|
|
require_once('models/DynData.php');
|
|
require_once('models/Mission.php');
|
|
require_once('models/Season.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/SeasonService.php');
|
|
require_once('services/MissionService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\User;
|
|
use models\DynData;
|
|
use models\Mission;
|
|
use models\Season;
|
|
|
|
class MissionController extends BaseAuthedController {
|
|
|
|
private $missionService = null;
|
|
private $awardService = null;
|
|
private $propertyChgService = null;
|
|
private $userInfo = null;
|
|
private $seasonService = null;
|
|
private $currSeasonMeta = null;
|
|
private $seasonDb = null;
|
|
|
|
public function _handlePre()
|
|
{
|
|
parent::_handlePre();
|
|
DynData::preload();
|
|
$this->currSeasonMeta = mt\Season::getCurrentSeason();
|
|
if (!$this->currSeasonMeta) {
|
|
$this->_rspErr(10, '服务器内部错误');
|
|
die();
|
|
}
|
|
$this->propertyChgService = new services\PropertyChgService();
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
$this->seasonService = new services\SeasonService();
|
|
if (!$this->seasonService->checkSeason($this->userInfo)) {
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
$this->propertyChgService->addUserChg();
|
|
}
|
|
$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) {
|
|
$this->_rspErr(10, '服务器内部错误');
|
|
die();
|
|
}
|
|
$this->awardService = new services\AwardService();
|
|
$this->missionService = new services\MissionService();
|
|
}
|
|
|
|
public function missionList()
|
|
{
|
|
$type = getReqVal('type', 0);
|
|
$missionMetaList = mt\Task::getCustomTypeMetaList($type);
|
|
$missionHash = Mission::allToHash();
|
|
$missionDtoList1 = array();
|
|
$missionDtoList2 = array();
|
|
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) {
|
|
array_push($missionDtoList1, $missionDto);
|
|
} else {
|
|
array_push($missionDtoList2, $missionDto);
|
|
}
|
|
} else {
|
|
array_push($missionDtoList1, $missionDto);
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'current_active_value' => 0,
|
|
'max_active_value' => 0,
|
|
'mission_list1' => $missionDtoList1,
|
|
'mission_list2' => $missionDtoList2
|
|
));
|
|
}
|
|
|
|
public function commitMission()
|
|
{
|
|
$missionId = getReqVal('mission_id', 0);
|
|
$missionMeta = mt\Task::get($missionId);
|
|
if (!$missionMeta) {
|
|
$this->_rspErr(1, 'mission_id参数错误');
|
|
return;
|
|
}
|
|
$missionDb = Mission::find($missionId);
|
|
$missionDto = $this->missionService->getMissionDto(
|
|
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
|
if (!$missionDto) {
|
|
$this->_rspErr(10, '服务器内部错误');
|
|
return;
|
|
}
|
|
if ($missionDto['state'] == Mission::RECEIVED_STATE) {
|
|
$this->_rspErr(2, '不能重复领取');
|
|
return;
|
|
}
|
|
if ($missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
|
$this->_rspErr(3, '任务目标未达成');
|
|
return;
|
|
}
|
|
if ($missionDto['state'] != Mission::RECEIVEABLE_STATE) {
|
|
$this->_rspErr(3, '未知任务状态');
|
|
return;
|
|
}
|
|
$dropMeta = mt\Drop::get($missionMeta['reward']);
|
|
if (!$dropMeta) {
|
|
$this->_rspErr(10, '服务器内部错误drop错误:' . $missionMeta['reward']);
|
|
return;
|
|
}
|
|
$this->_scatterDrop('mission:' . $missionId, $dropMeta, $this->awardService, $this->propertyChgService);
|
|
Mission::add($missionId);
|
|
$missionDb = Mission::find($missionId);
|
|
$missionDto = $this->missionService->getMissionDto(
|
|
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
|
$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($type);
|
|
$missionHash = Mission::allToHash();
|
|
$missionDtoList = array();
|
|
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);
|
|
}
|
|
}
|
|
foreach ($missionDtoList as $missionDto) {
|
|
$missionMeta = mt\Mission::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);
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'award' => $this->awardService->toDto(),
|
|
'property_chg' => $this->propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
}
|