TaskProc.php 8.7 KB

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