TaskProc.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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::task_step();
  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_TaskStep($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::task_step();
  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_TaskStep($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. $tsp = new Ins_TaskStep($task);
  133. if ($tsp->state != Enum_TaskCardStateType::ing) {
  134. continue;
  135. }
  136. if ($tsp->check_new($taskParam)) {
  137. $bUpdate = true;
  138. $tsp->propel($taskParam);
  139. NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
  140. if ($tsp->isFinish()) {
  141. NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
  142. // $tsp->doFinishAct();
  143. }
  144. }
  145. if ($tsp->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
  146. $tsp->state = Enum_TaskCardStateType::finish;
  147. NormalEventProc::OnTaskCard_Finish($tsp->uid, null); # 广播卡完成事件
  148. }
  149. }
  150. if ($bUpdate) { # 带回数据到客户端
  151. ctx()->task->taskcards = $tasks;
  152. UserProc::updateUserInfo(); # 更新玩家数据
  153. }
  154. }
  155. /**
  156. * 检查任务卡条件是否达成
  157. * @param Ins_TaskEventArgs $taskParam Description
  158. */
  159. static function CheckTaskCardConditions_old($taskParam) {
  160. $bUpdate = false;
  161. $tasks = ctx()->task->taskcards;
  162. foreach ($tasks as $tid => &$task) {
  163. $task = new Ins_TaskCard($task);
  164. if ($task->state != Enum_TaskCardStateType::ing) {
  165. continue;
  166. }
  167. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  168. $tsp = new Ins_TaskStep($tsp);
  169. if ($tsp->check_new($taskParam)) {
  170. $bUpdate = true;
  171. $tsp->propel($taskParam);
  172. NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
  173. if ($tsp->isFinish()) {
  174. NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
  175. // $tsp->doFinishAct();
  176. }
  177. }
  178. }
  179. if ($task->IsFinish()) { # 检查后添加后续任务
  180. $arr = array();
  181. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  182. $tsp = new Ins_TaskStep($tsp);
  183. if (strlen($tsp->mo()->next) > 0) { # 有后续任务
  184. $arr = array_merge($arr, explode(',', $tsp->mo()->next)); # 累加下一个任务步骤
  185. }
  186. }
  187. foreach ($arr as $stpid) { # 轮询添加后续任务
  188. if ($stpid > 0) {
  189. $task->AddStep($stpid); # 将后续任务追加到任务列表中
  190. }
  191. }
  192. if (count($arr) != 0) {
  193. self::autoRecoverStateMissions();
  194. }
  195. }
  196. if ($task->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
  197. $task->state = Enum_TaskCardStateType::finish;
  198. NormalEventProc::OnTaskCard_Finish($task->uid, null); # 广播卡完成事件
  199. }
  200. }
  201. if ($bUpdate) { # 带回数据到客户端
  202. ctx()->store->taskcards = $tasks;
  203. UserProc::updateUserInfo(); # 更新玩家数据
  204. }
  205. return $bUpdate;
  206. }
  207. }