273 lines
11 KiB
PHP
273 lines
11 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('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, 'server internal error');
|
||
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, '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;
|
||
}
|
||
$this->_rspData(array(
|
||
'current_active_value' => $this->_getV(TN_DAILY_ACTIVE, 0),
|
||
'max_active_value' => mt\Parameter::getVal('max_activity', 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 parameter error');
|
||
return;
|
||
}
|
||
if (mt\Task::isOfferRewardMission($missionMeta)) {
|
||
$this->commitOfferRewardMission($missionMeta);
|
||
return;
|
||
}
|
||
//
|
||
if ($missionMeta['type'] == mt\Task::DAILY_MISSON_TYPE &&
|
||
$missionMeta['subtype'] == mt\Task::WEAKLY_ACTIVE_VALUE_MISSON_SUBTYPE) {
|
||
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;
|
||
}
|
||
}
|
||
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);
|
||
if ($missionMeta['type'] == 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;
|
||
myself()->_addVirtualItem(V_ITEM_GOLD, round($gold));
|
||
}
|
||
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, $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);
|
||
}
|
||
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(),
|
||
));
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
private function commitOfferRewardMission($missionMeta)
|
||
{
|
||
$this->missionService->commitOfferRewardMission($missionMeta);
|
||
}
|
||
|
||
public function sendOfferRewardMission()
|
||
{
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$this->missionService->sendOfferRewardMission($missionId, $this->propertyChgService);
|
||
}
|
||
|
||
public function boostOfferRewardMission()
|
||
{
|
||
$missionId = getReqVal('mission_id', 0);
|
||
$this->missionService->boostOfferRewardMission(
|
||
$missionId,
|
||
$this->awardService,
|
||
$this->propertyChgService);
|
||
}
|
||
|
||
}
|