TaskProc.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. ksort($retDic);
  61. $index = ctx()->task->taskIndex;
  62. foreach ($retDic as $id => $mo) {
  63. $index += 1;
  64. $task = new Ins_TaskCard($id);
  65. $taskcards->$index = $task;
  66. }
  67. ctx()->task->taskIndex = $index;
  68. ctx()->task->taskcards = $taskcards;
  69. UserProc::updateUserInfo();
  70. }
  71. /**
  72. * 每周任务重置
  73. */
  74. static function ResetTask_Week() {
  75. $dic = GameConfig::taskcard();
  76. $retDic = new \stdClass();
  77. $taskcards = ctx()->task->taskcards;
  78. $dailyCards = array();
  79. foreach ($dic as $id => $mo) {
  80. if($mo->type == 2){
  81. foreach ($taskcards as $uid => $card) {
  82. if($card->typeId == $mo->id){
  83. $dailyCards[] = $uid;
  84. }
  85. }
  86. $retDic->$id = $mo;
  87. }
  88. }
  89. foreach ($dailyCards as $uid) {
  90. unset($taskcards->$uid);
  91. }
  92. $retDic = (array) $retDic;
  93. ksort($retDic);
  94. $index = ctx()->task->taskIndex;
  95. foreach ($retDic as $id => $mo) {
  96. $index += 1;
  97. $task = new Ins_TaskCard($id);
  98. $taskcards->$index = $task;
  99. }
  100. ctx()->task->taskIndex = $index;
  101. ctx()->task->taskcards = $taskcards;
  102. UserProc::updateUserInfo();
  103. }
  104. //---------------------
  105. /**
  106. * 每日登陆
  107. */
  108. static function OnUserLogin() {
  109. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyLogin, Enum_PropelType::set, 1, array());
  110. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  111. }
  112. /**
  113. * 参与主线关卡X次
  114. */
  115. static function OnChallengeZhuXianGate() {
  116. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::ChallengeZhuXianGate, Enum_PropelType::add, 1, array());
  117. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  118. }
  119. /**
  120. * 参与日常关卡1次
  121. */
  122. static function OnChallengeDailyGate() {
  123. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::ChallengeDailyGate, Enum_PropelType::add, 1, array());
  124. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  125. }
  126. /**
  127. * 每日商店购买物品1次
  128. */
  129. static function OnDailyShopBuyNum() {
  130. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyShopBuyNum, Enum_PropelType::add, 1, array());
  131. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  132. }
  133. static function CheckTaskCardConditions($taskParam) {
  134. $bUpdate = false;
  135. $tasks = ctx()->task->taskcards;
  136. foreach ($tasks as $tid => &$task) {
  137. $task = new Ins_TaskCard($task);
  138. if ($task->state != Enum_TaskCardStateType::ing) {
  139. continue;
  140. }
  141. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  142. $tsp = new Ins_TaskStep($tsp);
  143. if ($tsp->check_new($taskParam)) {
  144. $bUpdate = true;
  145. $tsp->propel($taskParam);
  146. NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
  147. if ($tsp->isFinish()) {
  148. NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
  149. // $tsp->doFinishAct();
  150. }
  151. }
  152. }
  153. if ($task->IsFinish()) { # 检查后添加后续任务
  154. $arr = array();
  155. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  156. $tsp = new Ins_TaskStep($tsp);
  157. if (strlen($tsp->mo()->next) > 0) { # 有后续任务
  158. $arr = array_merge($arr, explode(',', $tsp->mo()->next)); # 累加下一个任务步骤
  159. }
  160. }
  161. foreach ($arr as $stpid) { # 轮询添加后续任务
  162. if ($stpid > 0) {
  163. $task->AddStep($stpid); # 将后续任务追加到任务列表中
  164. }
  165. }
  166. if (count($arr) != 0) {
  167. self::autoRecoverStateMissions($taskParam);
  168. }
  169. }
  170. if ($task->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
  171. $task->state = Enum_TaskCardStateType::finish;
  172. NormalEventProc::OnTaskCard_Finish($task->uid, null); # 广播卡完成事件
  173. }
  174. }
  175. if ($bUpdate) { # 带回数据到客户端
  176. ctx()->task->taskcards = $tasks;
  177. UserProc::updateUserInfo(); # 更新玩家数据
  178. }
  179. return $bUpdate;
  180. }
  181. /**
  182. * 自动修复状态型任务
  183. */
  184. static function autoRecoverStateMissions() {
  185. $tasks = ctx()->task->taskcards;
  186. foreach ($tasks as $tid => &$task) {
  187. $task = new Ins_TaskCard($task);
  188. if ($task->state == Enum_TaskCardStateType::ing // # 进行中的或者已完成的
  189. || $task->state == Enum_TaskCardStateType::finish) {
  190. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  191. $tsp = new Ins_TaskStep($tsp);
  192. $tsp->autoCalcStatusCur();
  193. }
  194. if ($task->state == Enum_TaskCardStateType::finish) { # 检查是否任务卡的所有步骤都已完成
  195. if (!$task->IsFinish()) {
  196. $task->state = Enum_TaskCardStateType::ing; # 状态回退
  197. }
  198. }
  199. }
  200. }
  201. // Clog::info("更新状态统计类的任务卡!");
  202. ctx()->task->taskcards = $tasks;
  203. }
  204. }