TaskProc.php 9.4 KB

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