TaskProc.php 8.2 KB

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