TaskProc.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 任务类型枚举 用于任务进度对比,参数传递.
  5. */
  6. class EnumTaskType extends Enum {
  7. const CommanderLevelUpTo = 11;
  8. const HeroLevelUpTo = 12;
  9. const HeroGradeUpTo = 13;
  10. const HeroSegmentNumberTo = 14;
  11. const HeroSkillUnlock = 15;
  12. const PassGateN = 21;
  13. const passCarbonN = 22;
  14. const PvPWinNumberTo = 31;
  15. const PvPScoreTo = 32;
  16. const UserPowerTo = 33;
  17. const UserCollectScoreTo = 34;
  18. }
  19. /**
  20. * 任务参数,用于任务进度判定逻辑
  21. */
  22. class TaskParams {
  23. public function __construct($_taskType, $_canshu1 = null, $_canshu2 = null) {
  24. $this->taskType = $_taskType;
  25. $this->canshu1 = $_canshu1;
  26. $this->canshu2 = $_canshu2;
  27. }
  28. /**
  29. * @var int 任务类型
  30. */
  31. public $taskType;
  32. /**
  33. * @var number 参数1
  34. */
  35. public $canshu1;
  36. /**
  37. * @var number 参数2
  38. */
  39. public $canshu2;
  40. }
  41. /**
  42. * 任务模块
  43. * @version
  44. * 1.0.0 Created at 2017-11-3. by --gwang
  45. * @author gwang (mail@wanggangzero.cn)
  46. * @copyright ? 2017-11-3, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  47. */
  48. class TaskProc {
  49. function procMain($req) {
  50. switch ($req->cmd) {
  51. case CmdCode::cmd_task_getInfo: # 6201 刷新任务状态
  52. return TaskProc::GetTaskInfo($req);
  53. case CmdCode::cmd_task_getReward: # 6202 领取任务奖励
  54. return TaskProc::GetTaskReward($req);
  55. case CmdCode::cmd_Task_setAttentionTask: # 6203 设置关注任务
  56. return TaskProc::GetTaskInfo($req);
  57. default:
  58. return Err(ErrCode::cmd_err);
  59. }
  60. }
  61. /**
  62. * [6203] 设置关注任务
  63. * @param req $req
  64. */
  65. static function setAttentionTask($req) {
  66. list($taskId) = $req->paras;
  67. $userTask = $req->userInfo->game->task;
  68. my_Assert(StlUtil::dictHasProperty($userTask->taskListPlot, $taskId), ErrCode::task_no); # 任务存在
  69. isEditor() and $taskItem = new TaskInfo();
  70. $taskItem = $userTask->taskListPlot->$taskId;
  71. my_Assert($taskItem->rewardGeted < 1, ErrCode::task_reward_geted); # 任务奖励尚未领取
  72. $userTask->curTaskId = $taskId;
  73. return Resp::ok();
  74. }
  75. /**
  76. * [6201]更新任务状态
  77. * @param req $req
  78. */
  79. static function GetTaskInfo($req) {
  80. // 刷新
  81. // 返回
  82. return Resp::ok($req->userInfo->game->task);
  83. }
  84. /**
  85. * [6202]领取任务奖励 问:每日任务奖励和剧情任务奖励领取接口是否为一个?
  86. * @param req $req
  87. */
  88. static function GetTaskReward($req) {
  89. list($taskId) = $req->paras; # 提取参数: 任务id
  90. $userTask = $req->userInfo->game->task;
  91. # 根据任务类型分支不同任务容器 暂时未添加每日任务分支
  92. my_Assert(StlUtil::dictHasProperty($userTask->taskListPlot, $taskId), ErrCode::task_no); #判断是否存在指定任务
  93. isEditor() and $task = new TaskInfo();
  94. $task = $userTask->taskListPlot->$taskId;
  95. my_Assert($task->progress >= 1, ErrCode::task_progress_not_complete); # 判断任务进度是否已完成>=1f
  96. my_Assert($task->rewardGeted < 1, ErrCode::task_reward_geted); # 奖励不可重复领取
  97. $taskCfg = GameConfig::task_getItem($taskId); # 任务配置数据
  98. my_Assert($taskCfg != null, ErrCode::err_const_no);
  99. $ok = StoreProc::AddMultiItemInStore($req, $taskCfg->reward); # 发放任务奖励
  100. my_Assert($ok == ErrCode::ok, $ok);
  101. $task->rewardGeted = 1;
  102. $req->userInfo->game->task = $userTask; # 回存,理论上不用
  103. return Resp::ok(array(// # 返回
  104. "gold" => $req->userInfo->game->gold,
  105. "cash" => $req->userInfo->game->cash,
  106. "tili" => $req->userInfo->game->tili,
  107. "store" => $req->userInfo->game->store,
  108. "task" => $req->userInfo->game->task
  109. ));
  110. }
  111. // 每日任务, 自动刷新
  112. //
  113. //
  114. // <editor-fold defaultstate="collapsed" desc="辅助方法-比对判断">
  115. /**
  116. * 检查任务条件是否达成
  117. * @param TaskParams $taskParam Description
  118. */
  119. static function CheckTaskConditions($taskParam) {
  120. $bUpdate = false;
  121. foreach (req()->userInfo->game->task->taskListPlot as $tid => $task) {
  122. $taskCfg = GameConfig::task_getItem($tid);
  123. my_Assert($taskCfg != null, ErrCode::err_const_no); # 获取任务配置数据
  124. if ($taskCfg->tasktype != $taskParam->taskType) { # 任务类型必须匹配
  125. continue;
  126. }
  127. isEditor() and $task = new TaskInfo();
  128. if (is_null($taskCfg->canshu1)) {
  129. $task->progress = 1;
  130. $bUpdate = true;
  131. continue;
  132. }
  133. $task->tag1 = max($task->tag1, $taskParam->canshu1);
  134. if ($taskCfg->canshu1 <= $taskParam->canshu1) {
  135. if (null == $taskCfg->canshu2 || 0 == $taskCfg->canshu2) {
  136. $bUpdate = true;
  137. $task->progress = 1;
  138. } else {
  139. if (is_numeric($taskCfg->canshu2)) {
  140. $task->tag2 = max($task->tag2, $taskParam->canshu2);
  141. if ($taskCfg->canshu2 <= $taskParam->canshu2) {
  142. $bUpdate = true;
  143. $task->progress = 1;
  144. }
  145. } else {
  146. $task->tag2 = $taskParam->canshu2;
  147. if ($taskCfg->canshu2 == $taskParam->canshu2) {
  148. $bUpdate = true;
  149. $task->progress = 1;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. // meiri
  156. if ($bUpdate) {
  157. Resp::addTag("isTaskUpdated", true); # 附加tag信息, 任务有更新
  158. }
  159. }
  160. // </editor-fold>
  161. //
  162. // <editor-fold defaultstate="collapsed" desc="处理各种任务检测事务">
  163. //
  164. /**
  165. * 例如当指挥官等级提升的时候需要检查是否有任务达成
  166. */
  167. static function OnUserLevelUp($newLvl) {
  168. $taskParam = new TaskParams(EnumTaskType::CommanderLevelUpTo, $newLvl);
  169. self::CheckTaskConditions($taskParam);
  170. }
  171. static function OnHeroLevelUp($heroMoId, $newLvl) {
  172. $taskParam = new TaskParams(EnumTaskType::HeroLevelUpTo, $heroMoId, $newLvl);
  173. self::CheckTaskConditions($taskParam);
  174. }
  175. static function OnHeroGradeUp($heroMoId, $newGrade) {
  176. $taskParam = new TaskParams(EnumTaskType::HeroGradeUpTo, $heroMoId, $newGrade);
  177. self::CheckTaskConditions($taskParam);
  178. }
  179. static function OnHeroSegmengNum($heroMoId, $num) {
  180. $taskParam = new TaskParams(EnumTaskType::HeroSegmentNumberTo, $heroMoId, $num);
  181. self::CheckTaskConditions($taskParam);
  182. }
  183. static function OnHeroUnlocSkill($heroMoId, $skillId) {
  184. $taskParam = new TaskParams(EnumTaskType::HeroSkillUnlock, $heroMoId, $skillId);
  185. self::CheckTaskConditions($taskParam);
  186. }
  187. static function OnPassGateN($gateId, $difficulty) {
  188. $taskParam = new TaskParams(EnumTaskType::PassGateN, $gateId, $difficulty);
  189. self::CheckTaskConditions($taskParam);
  190. }
  191. static function OnPassCarboN($gateId, $difficulty) {
  192. $taskParam = new TaskParams(EnumTaskType::passCarbonN, $gateId, $difficulty);
  193. self::CheckTaskConditions($taskParam);
  194. }
  195. static function OnPvPWinN($num) {
  196. $taskParam = new TaskParams(EnumTaskType::PvPWinNumberTo, $num);
  197. self::CheckTaskConditions($taskParam);
  198. }
  199. /**
  200. *
  201. * @param type $score
  202. */
  203. static function OnPvPScoreN($score) {
  204. $taskParam = new TaskParams(EnumTaskType::PvPScoreTo, $score);
  205. self::CheckTaskConditions($taskParam);
  206. }
  207. /**
  208. * 玩家总战力值
  209. * @param type $num
  210. */
  211. static function OnUserFightPowerN($num) {
  212. $taskParam = new TaskParams(EnumTaskType::UserPowerTo, $num);
  213. self::CheckTaskConditions($taskParam);
  214. }
  215. /**
  216. * 玩家收集积分
  217. * @param type $num
  218. */
  219. static function OnUserCollectScoreN($num) {
  220. $taskParam = new TaskParams(EnumTaskType::UserCollectScoreTo, $num);
  221. self::CheckTaskConditions($taskParam);
  222. }
  223. //
  224. // </editor-fold>
  225. //
  226. }