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