TaskProc.php 10 KB

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