TaskProc.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace loyalsoft;
  8. /**
  9. * Description of TaskProc
  10. *
  11. * @author c'y'zhao
  12. */
  13. class TaskProc {
  14. /**
  15. * 逻辑分发
  16. * 所有的Proc中必须有这样一个方法
  17. * @param Req $req
  18. */
  19. public static function procMain($req) {
  20. switch ($req->cmd) {
  21. case CmdCode::cmd_task_getInfo: # 6201
  22. return TaskProc::getTaskInfo();
  23. case CmdCode::cmd_task_getReward: # 6202
  24. return TaskProc::getReward();
  25. default:
  26. Err(ErrCode::cmd_err);
  27. }
  28. }
  29. public static function getTaskInfo() {
  30. list() = req()->paras;//武器uid
  31. self::ResetTask_Daily();
  32. return Resp::ok(array());
  33. }
  34. static function ResetTask() {
  35. self::ResetTask_Daily();
  36. //self::ResetTask_Week();
  37. }
  38. /**
  39. * 每日任务重置
  40. */
  41. static function ResetTask_Daily() {
  42. $dic = GameConfig::taskcard();
  43. $retDic = new \stdClass();
  44. $taskcards = ctx()->task->taskcards;
  45. $dailyCards = array();
  46. foreach ($dic as $id => $mo) {
  47. if($mo->type == 1){
  48. foreach ($taskcards as $uid => $card) {
  49. if($card->typeId == $mo->typeId){
  50. $dailyCards[] = $uid;
  51. }
  52. }
  53. $retDic->$id = $mo;
  54. }
  55. }
  56. foreach ($dailyCards as $uid) {
  57. unset($taskcards->$uid);
  58. }
  59. $retDic = (array) $retDic;
  60. if(count($retDic) <= 0){
  61. return;
  62. }
  63. ksort($retDic);
  64. $index = ctx()->task->taskIndex;
  65. foreach ($retDic as $id => $mo) {
  66. $index += 1;
  67. $task = new Ins_TaskCard($id);
  68. $taskcards->$index = $task;
  69. }
  70. ctx()->task->taskIndex = $index;
  71. ctx()->task->taskcards = $taskcards;
  72. UserProc::updateUserInfo();
  73. }
  74. /**
  75. * 每周任务重置
  76. */
  77. static function ResetTask_Week() {
  78. $dic = GameConfig::taskcard();
  79. $retDic = new \stdClass();
  80. $taskcards = ctx()->task->taskcards;
  81. $dailyCards = array();
  82. foreach ($dic as $id => $mo) {
  83. if($mo->type == 2){
  84. foreach ($taskcards as $uid => $card) {
  85. if($card->typeId == $mo->typeId){
  86. $dailyCards[] = $uid;
  87. }
  88. }
  89. $retDic->$id = $mo;
  90. }
  91. }
  92. foreach ($dailyCards as $uid) {
  93. unset($taskcards->$uid);
  94. }
  95. $retDic = (array) $retDic;
  96. if(count($retDic) <= 0){
  97. return;
  98. }
  99. ksort($retDic);
  100. $index = ctx()->task->taskIndex;
  101. foreach ($retDic as $id => $mo) {
  102. $index += 1;
  103. $task = new Ins_TaskCard($id);
  104. $taskcards->$index = $task;
  105. }
  106. ctx()->task->taskIndex = $index;
  107. ctx()->task->taskcards = $taskcards;
  108. UserProc::updateUserInfo();
  109. }
  110. //---------------------
  111. /**
  112. * 每日登陆
  113. */
  114. static function OnUserLogin() {
  115. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyLogin, Enum_PropelType::set, 1, array());
  116. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  117. }
  118. /**
  119. * 参与主线关卡X次
  120. */
  121. static function OnChallengeZhuXianGate() {
  122. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::ChallengeZhuXianGate, Enum_PropelType::add, 1, array());
  123. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  124. }
  125. /**
  126. * 参与日常关卡1次
  127. */
  128. static function OnChallengeDailyGate() {
  129. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::ChallengeDailyGate, Enum_PropelType::add, 1, array());
  130. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  131. }
  132. /**
  133. * 每日商店购买物品1次
  134. */
  135. static function OnDailyShopBuyNum() {
  136. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyShopBuyNum, Enum_PropelType::add, 1, array());
  137. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  138. }
  139. static function CheckTaskCardConditions($taskParam) {
  140. $bUpdate = false;
  141. $tasks = ctx()->task->taskcards;
  142. foreach ($tasks as $tid => &$task) {
  143. $task = new Ins_TaskCard($task);
  144. if ($task->state != Enum_TaskCardStateType::ing) {
  145. continue;
  146. }
  147. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  148. $tsp = new Ins_TaskStep($tsp);
  149. if ($tsp->check_new($taskParam)) {
  150. $bUpdate = true;
  151. $tsp->propel($taskParam);
  152. NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
  153. if ($tsp->isFinish()) {
  154. NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
  155. // $tsp->doFinishAct();
  156. }
  157. }
  158. }
  159. if ($task->IsFinish()) { # 检查后添加后续任务
  160. $arr = array();
  161. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  162. $tsp = new Ins_TaskStep($tsp);
  163. if (strlen($tsp->mo()->next) > 0) { # 有后续任务
  164. $arr = array_merge($arr, explode(',', $tsp->mo()->next)); # 累加下一个任务步骤
  165. }
  166. }
  167. foreach ($arr as $stpid) { # 轮询添加后续任务
  168. if ($stpid > 0) {
  169. $task->AddStep($stpid); # 将后续任务追加到任务列表中
  170. }
  171. }
  172. if (count($arr) != 0) {
  173. self::autoRecoverStateMissions($taskParam);
  174. }
  175. }
  176. if ($task->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
  177. $task->state = Enum_TaskCardStateType::finish;
  178. NormalEventProc::OnTaskCard_Finish($task->uid, null); # 广播卡完成事件
  179. }
  180. }
  181. if ($bUpdate) { # 带回数据到客户端
  182. ctx()->task->taskcards = $tasks;
  183. UserProc::updateUserInfo(); # 更新玩家数据
  184. }
  185. return $bUpdate;
  186. }
  187. /**
  188. * 自动修复状态型任务
  189. */
  190. static function autoRecoverStateMissions() {
  191. $tasks = ctx()->task->taskcards;
  192. foreach ($tasks as $tid => &$task) {
  193. $task = new Ins_TaskCard($task);
  194. if ($task->state == Enum_TaskCardStateType::ing // # 进行中的或者已完成的
  195. || $task->state == Enum_TaskCardStateType::finish) {
  196. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  197. $tsp = new Ins_TaskStep($tsp);
  198. $tsp->autoCalcStatusCur();
  199. }
  200. if ($task->state == Enum_TaskCardStateType::finish) { # 检查是否任务卡的所有步骤都已完成
  201. if (!$task->IsFinish()) {
  202. $task->state = Enum_TaskCardStateType::ing; # 状态回退
  203. }
  204. }
  205. }
  206. }
  207. // Clog::info("更新状态统计类的任务卡!");
  208. ctx()->task->taskcards = $tasks;
  209. }
  210. }