123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- namespace loyalsoft;
- /**
- * Description of TaskProc
- *
- * @author c'y'zhao
- */
- class TaskProc {
- /**
- * 逻辑分发
- * 所有的Proc中必须有这样一个方法
- * @param Req $req
- */
- public static function procMain($req) {
- switch ($req->cmd) {
- case CmdCode::cmd_task_getInfo: # 6201
- return TaskProc::getTsskInfo();
- case CmdCode::cmd_task_getReward: # 6202
- return TaskProc::getReward();
- default:
- Err(ErrCode::cmd_err);
- }
- }
-
- static function ResetTask() {
- self::ResetTask_Daily();
- self::ResetTask_Week();
- }
-
- /**
- * 每日任务重置
- */
- static function ResetTask_Daily() {
- $dic = GameConfig::task_step();
-
- $retDic = new \stdClass();
- $taskcards = ctx()->task->taskcards;
-
- $dailyCards = array();
- foreach ($dic as $id => $mo) {
- if($mo->type == 1){
- foreach ($taskcards as $uid => $card) {
- if($card->typeId == $mo->id){
- $dailyCards[] = $uid;
- }
- }
-
- $retDic->$id = $mo;
- }
- }
-
- foreach ($dailyCards as $uid) {
- unset($taskcards->$uid);
- }
-
- $retDic = (array) $retDic;
- ksort($retDic);
- $index = ctx()->task->taskIndex;
- foreach ($retDic as $id => $mo) {
- $index += 1;
- $task = new Ins_TaskStep($id);
- $taskcards->$index = $task;
- }
- ctx()->task->taskIndex = $index;
- ctx()->task->taskcards = $taskcards;
-
- UserProc::updateUserInfo();
- }
-
- /**
- * 每周任务重置
- */
- static function ResetTask_Week() {
- $dic = GameConfig::task_step();
-
- $retDic = new \stdClass();
- $taskcards = ctx()->task->taskcards;
-
- $dailyCards = array();
- foreach ($dic as $id => $mo) {
- if($mo->type == 2){
- foreach ($taskcards as $uid => $card) {
- if($card->typeId == $mo->id){
- $dailyCards[] = $uid;
- }
- }
-
- $retDic->$id = $mo;
- }
- }
-
- foreach ($dailyCards as $uid) {
- unset($taskcards->$uid);
- }
-
- $retDic = (array) $retDic;
- ksort($retDic);
- $index = ctx()->task->taskIndex;
- foreach ($retDic as $id => $mo) {
- $index += 1;
- $task = new Ins_TaskStep($id);
- $taskcards->$index = $task;
- }
- ctx()->task->taskIndex = $index;
- ctx()->task->taskcards = $taskcards;
-
- UserProc::updateUserInfo();
- }
- //---------------------
- /**
- * 每日登陆
- */
- static function OnUserLogin() {
- $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyLogin, Enum_PropelType::set, 1, array());
- self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
- }
-
- /**
- * 参与主线关卡X次
- */
- static function OnChallengeZhuXianGate() {
- $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::ChallengeZhuXianGate, Enum_PropelType::add, 1, array());
- self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
- }
-
- /**
- * 参与日常关卡1次
- */
- static function OnChallengeDailyGate() {
- $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::ChallengeDailyGate, Enum_PropelType::add, 1, array());
- self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
- }
-
- /**
- * 每日商店购买物品1次
- */
- static function OnDailyShopBuyNum() {
- $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyShopBuyNum, Enum_PropelType::add, 1, array());
- self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
- }
-
-
-
- static function CheckTaskCardConditions($taskParam) {
- $bUpdate = false;
- $tasks = ctx()->task->taskcards;
- foreach ($tasks as $tid => &$task) {
- $tsp = new Ins_TaskStep($task);
- if ($tsp->state != Enum_TaskCardStateType::ing) {
- continue;
- }
-
- if ($tsp->check_new($taskParam)) {
- $bUpdate = true;
- $tsp->propel($taskParam);
- NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
- if ($tsp->isFinish()) {
- NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
- // $tsp->doFinishAct();
- }
- }
-
- if ($tsp->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
- $tsp->state = Enum_TaskCardStateType::finish;
- NormalEventProc::OnTaskCard_Finish($tsp->uid, null); # 广播卡完成事件
- }
-
-
- }
-
- if ($bUpdate) { # 带回数据到客户端
- ctx()->task->taskcards = $tasks;
- UserProc::updateUserInfo(); # 更新玩家数据
- }
-
- }
- /**
- * 检查任务卡条件是否达成
- * @param Ins_TaskEventArgs $taskParam Description
- */
- static function CheckTaskCardConditions_old($taskParam) {
- $bUpdate = false;
- $tasks = ctx()->task->taskcards;
- foreach ($tasks as $tid => &$task) {
- $task = new Ins_TaskCard($task);
- if ($task->state != Enum_TaskCardStateType::ing) {
- continue;
- }
- foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
- $tsp = new Ins_TaskStep($tsp);
- if ($tsp->check_new($taskParam)) {
- $bUpdate = true;
- $tsp->propel($taskParam);
- NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
- if ($tsp->isFinish()) {
- NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
- // $tsp->doFinishAct();
- }
- }
- }
- if ($task->IsFinish()) { # 检查后添加后续任务
- $arr = array();
- foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
- $tsp = new Ins_TaskStep($tsp);
- if (strlen($tsp->mo()->next) > 0) { # 有后续任务
- $arr = array_merge($arr, explode(',', $tsp->mo()->next)); # 累加下一个任务步骤
- }
- }
- foreach ($arr as $stpid) { # 轮询添加后续任务
- if ($stpid > 0) {
- $task->AddStep($stpid); # 将后续任务追加到任务列表中
- }
- }
- if (count($arr) != 0) {
- self::autoRecoverStateMissions();
- }
- }
- if ($task->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
- $task->state = Enum_TaskCardStateType::finish;
- NormalEventProc::OnTaskCard_Finish($task->uid, null); # 广播卡完成事件
- }
- }
- if ($bUpdate) { # 带回数据到客户端
- ctx()->store->taskcards = $tasks;
- UserProc::updateUserInfo(); # 更新玩家数据
- }
- return $bUpdate;
- }
- }
|