Ins_TaskStep.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 任务步骤, 用于任务卡功能(三组合一)
  5. * @author gwang(wanggangzero@qq.com)
  6. */
  7. class Ins_TaskStep extends Object_ext {
  8. /**
  9. * @var type 查询用的id
  10. */
  11. public $typeId = 0;
  12. /**
  13. * @var int 计数器
  14. */
  15. public $cur = 0;
  16. /**
  17. * @return \sm_task_step mo 获取对应的模板数据
  18. */
  19. public function mo() {
  20. $mo = GameConfig::task_step_getItem($this->typeId);
  21. my_Assert(null != $mo, ErrCode::err_const_no);
  22. return $mo;
  23. }
  24. /**
  25. * @return int 计数最大值
  26. */
  27. public function max() {
  28. return $this->mo()->num;
  29. }
  30. /**
  31. * @return string[] 参数数组
  32. */
  33. private function paras() {
  34. return explode(',', $this->mo()->paras);
  35. }
  36. /**
  37. * @return float 当前进度
  38. */
  39. public function progress() {
  40. return $this->cur / $this->max();
  41. }
  42. /**
  43. * 是否完成
  44. * @return bool
  45. */
  46. public function isFinish() {
  47. return $this->cur >= $this->max();
  48. }
  49. /**
  50. * 执行任务完成事件
  51. */
  52. public function doFinishAct() {
  53. if ($this->mo()->finishact > 0) {
  54. $act = GameConfig::eventAction_getItem($this->mo()->finishact);
  55. my_Assert($act, ErrCode::err_const_no);
  56. switch ($act->cmd) {
  57. case Enum_EventActionType::StartPlotScene: # 触发场景剧情,
  58. case Enum_EventActionType::StartPlotNPC: # 触发NPC剧情
  59. break;
  60. case Enum_EventActionType::UnlockBuild: # 解锁建筑
  61. req()->userInfo->game->privateState->unlockedBuild[] = $act->parameters;
  62. break;
  63. }
  64. }
  65. }
  66. /**
  67. * 执行任务开始事件
  68. */
  69. public function doStartAct() {
  70. var_dump("执行任务开始act");
  71. if ($this->mo()->startact > 0) {
  72. $act = GameConfig::eventAction_getItem($this->mo()->startact);
  73. my_Assert($act, ErrCode::err_const_no);
  74. switch ($act->cmd) {
  75. case Enum_EventActionType::StartPlotScene: # 触发场景剧情,
  76. case Enum_EventActionType::StartPlotNPC: # 触发NPC剧情
  77. break;
  78. case Enum_EventActionType::UnlockBuild: # 解锁建筑
  79. req()->userInfo->game->privateState->unlockedBuild[] = $act->parameters;
  80. NormalEventProc::OnUnlockBuild($act->parameters);
  81. break;
  82. }
  83. }
  84. }
  85. /**
  86. * 构造函数
  87. * @param type $args
  88. */
  89. public function __construct($args) {
  90. if (isInt($args)) {
  91. $this->typeId = $args;
  92. } else {
  93. parent::__construct($args);
  94. }
  95. }
  96. /**
  97. * 是否状态型任务
  98. * @param type $cmd
  99. */
  100. function isStatusType() {
  101. return $this->mo()->cmd == Enum_TaskCmdType::GainItem # 获取道具
  102. || $this->mo()->cmd == Enum_TaskCmdType::HeroLevelUpTo # 提升玩家等级到x
  103. || $this->mo()->cmd == Enum_TaskCmdType::CommanderLevelUpTo;
  104. }
  105. /**
  106. * 自动对齐可能出现统计失误的状态型任务计数
  107. * @return boolean 是否有修改
  108. */
  109. function autoCalcStatusCur() {
  110. if ($this->isStatusType()) {
  111. $mo = $this->mo();
  112. if ($mo != null) {
  113. $cur = $this->calcStatusCur();
  114. if ($cur > $this->max()) {
  115. $cur = $this->max();
  116. }
  117. if ($this->cur != $cur) {
  118. $this->cur = $cur;
  119. return true;
  120. }
  121. }
  122. }
  123. return false;
  124. }
  125. /**
  126. * @return int 计算状态类的进度
  127. */
  128. function calcStatusCur() {
  129. $mo = $this->mo();
  130. $paras = $this->paras();
  131. $para0 = "";
  132. $para1 = "";
  133. $para2 = "";
  134. if (count($paras) >= 1) {
  135. $para0 = $paras[0];
  136. }
  137. if (count($paras) >= 2) {
  138. $para1 = $paras[1];
  139. }
  140. if (count($paras) >= 3) {
  141. $para2 = $paras[2];
  142. }
  143. switch ($mo->cmd) {
  144. case Enum_TaskCmdType::GainItem: # 收集道具
  145. $store = new Info_Store(req()->userInfo->game->store);
  146. return $store->GetItemCount($para0);
  147. case Enum_TaskCmdType::CommanderLevelUpTo:
  148. $lvl = req()->userInfo->game->baseInfo->level;
  149. return $lvl;
  150. case Enum_TaskCmdType::HeroLevelUpTo:
  151. $hero = req()->userInfo->game->heros->GetHeroByMoID($para0);
  152. if (null != $hero) {
  153. return $hero->level;
  154. }
  155. break;
  156. }
  157. return 0;
  158. }
  159. /**
  160. * 检查任务条件(与petmini采用相同的参数和判定方法2020年12月12日11:38:02)
  161. * @param Ins_TaskEventArgs $taskCardEvent
  162. * @return bool
  163. */
  164. public function check_new($taskCardEvent) {
  165. // var_dump($taskCardEvent);
  166. if ($taskCardEvent->taskType != $this->mo()->cmd) { # 事件类型匹配
  167. return false;
  168. }
  169. if ($this->isStatusType()) { # 状态检查类任务
  170. return $this->autoCalcStatusCur();
  171. }
  172. if ($this->isFinish()) {
  173. return false;
  174. }
  175. if (strlen($this->mo()->paras) <= 0) { # 无参数
  176. return true;
  177. }
  178. $paras = $this->paras();
  179. $index = 0;
  180. foreach ($taskCardEvent->paras as $para) { # 其他任务, 执行参数判定
  181. if ($index < count($paras)) {
  182. if (strpos($para, "|") !== false) { # 某个条件是"或"的关系, 即有多重可能值, 满足其一即可
  183. $paraList = explode("|", $para);
  184. foreach ($paraList as $paraItem) {
  185. if ($paraItem == $paras[$index]) {
  186. continue; # 满足某一个即可, 继续判断下一个条件.
  187. }
  188. }
  189. } else { # only one, 不存在"或"的判定
  190. if ($paras[$index] != 0 && $para != $paras[$index]) { # 直接匹配
  191. return false; # 一但没匹配上, 直接返回false就好了.
  192. }
  193. }
  194. } # 参数中多余的数据就直接跳过,不比较了(因为自己不需要判断那么多参数)
  195. $index++;
  196. }
  197. return true; # 走到最后则判定满足条件.
  198. }
  199. /**
  200. * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22)
  201. * @param Ins_TaskEventArgs $taskParam
  202. */
  203. public function propel($taskParam) {
  204. // var_dump($taskParam);
  205. switch ($taskParam->ope) {
  206. case Enum_PropelType::set:
  207. $this->cur = $taskParam->val;
  208. break;
  209. case Enum_PropelType::add:
  210. $this->cur += $taskParam->val;
  211. break;
  212. case Enum_PropelType::inc:
  213. $this->cur += 1;
  214. break;
  215. case Enum_PropelType::max:
  216. if ($taskParam->val > $this->cur) {
  217. $this->cur = $taskParam->val;
  218. }
  219. break;
  220. case Enum_PropelType::stat:
  221. break;
  222. }
  223. }
  224. }