Ins_TaskStep.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. * @var int start/finish act已执行(0:startAct未执行,1:StartAct已执行且finishAct未执行,2:finishAct已执行)
  18. */
  19. public $actState = 0;
  20. /**
  21. * @return \sm_task_step mo 获取对应的模板数据
  22. */
  23. public function mo() {
  24. $mo = GameConfig::task_step_getItem($this->typeId);
  25. my_Assert(null != $mo, ErrCode::err_const_no);
  26. return $mo;
  27. }
  28. /**
  29. * @return int 计数最大值
  30. */
  31. public function max() {
  32. return $this->mo()->num;
  33. }
  34. /**
  35. * @return string[] 参数数组
  36. */
  37. private function paras() {
  38. return explode(',', $this->mo()->paras);
  39. }
  40. /**
  41. * @return float 当前进度
  42. */
  43. public function progress() {
  44. return $this->cur / $this->max();
  45. }
  46. /**
  47. * 是否完成
  48. * @return bool
  49. */
  50. public function isFinish() {
  51. return $this->cur >= $this->max();
  52. }
  53. /**
  54. * 执行任务完成事件
  55. */
  56. public function doFinishAct() {
  57. if ($this->mo()->finishact > 0) {
  58. $act = GameConfig::eventAction_getItem($this->mo()->finishact);
  59. $this->execAct($act);
  60. // my_Assert($act, ErrCode::err_const_no);
  61. // switch ($act->cmd) {
  62. // case Enum_EventActionType::StartPlotScene: # 触发场景剧情,
  63. // case Enum_EventActionType::StartPlotNPC: # 触发NPC剧情
  64. // $arr = GameConfig::plot_getItem($act->parameters[0], $act->parameters[1]);
  65. // foreach ($arr as $plot) {
  66. // isEditor() and $plot = new \sm_plot();
  67. // if (!empty($plot->presentItem)) {
  68. // StoreProc::AddMultiItemInStore(req(), $plot->presentItem);
  69. // }
  70. // if (!empty($plot->recycleItem)) {
  71. // $val = explode(",", $plot->recycleItem);
  72. // my_Assert(count($val) > 1, "解析回收道具字符串出错");
  73. // StoreProc::removeItemFromStore($store, $val[0], $val[1]);
  74. // }
  75. // }
  76. // break;
  77. // case Enum_EventActionType::UnlockBuild: # 解锁建筑
  78. // req()->userInfo->game->privateState->unlockedBuild[] = $act->parameters;
  79. // $this->actState = 2;
  80. // break;
  81. // }
  82. }
  83. }
  84. /**
  85. *
  86. * @param \sm_eventAction $act
  87. */
  88. private function execAct($act) {
  89. my_Assert($act, ErrCode::err_const_no);
  90. switch ($act->cmd) {
  91. case Enum_EventActionType::StartPlotScene: # 触发场景剧情,
  92. case Enum_EventActionType::StartPlotNPC: # 触发NPC剧情
  93. $paras = explode(',', $act->parameters); # 解析下参数
  94. $arr = GameConfig::plot_getItem($paras[0], $paras[1]); # 查找对应的剧情
  95. foreach ($arr as $plot) {
  96. isEditor() and $plot = new \sm_plot();
  97. if (!empty($plot->presentItem)) {
  98. StoreProc::AddMultiItemInStore(req(), $plot->presentItem);
  99. }
  100. if (!empty($plot->recycleItem)) {
  101. $val = explode(",", $plot->recycleItem);
  102. my_Assert(count($val) > 1, "解析回收道具字符串出错");
  103. StoreProc::removeItemFromStore($store, $val[0], $val[1]);
  104. }
  105. }
  106. break;
  107. case Enum_EventActionType::UnlockBuild: # 解锁建筑
  108. req()->userInfo->game->privateState->unlockedBuild[] = $act->parameters;
  109. $this->actState = 2;
  110. break;
  111. }
  112. }
  113. /**
  114. * 执行任务开始事件
  115. */
  116. public function doStartAct() {
  117. if ($this->mo()->startact > 0) {
  118. $act = GameConfig::eventAction_getItem($this->mo()->startact);
  119. $this->execAct($act);
  120. // my_Assert($act, ErrCode::err_const_no);
  121. // switch ($act->cmd) {
  122. // case Enum_EventActionType::StartPlotScene: # 触发场景剧情,
  123. // case Enum_EventActionType::StartPlotNPC: # 触发NPC剧情
  124. // $arr = GameConfig::plot_getItem($act->parameters[0], $act->parameters[1]);
  125. // foreach ($arr as $plot) {
  126. // isEditor() and $plot = new \sm_plot();
  127. // if (!empty($plot->presentItem)) {
  128. // StoreProc::AddMultiItemInStore(req(), $plot->presentItem);
  129. // }
  130. // if (!empty($plot->recycleItem)) {
  131. // $val = explode(",", $plot->recycleItem);
  132. // my_Assert(count($val) > 1, "解析回收道具字符串出错");
  133. // StoreProc::removeItemFromStore($store, $val[0], $val[1]);
  134. // }
  135. // }
  136. // break;
  137. // case Enum_EventActionType::UnlockBuild: # 解锁建筑
  138. // req()->userInfo->game->privateState->unlockedBuild[] = $act->parameters;
  139. // NormalEventProc::OnUnlockBuild($act->parameters);
  140. // $this->actState = 1;
  141. // break;
  142. // }
  143. }
  144. }
  145. /**
  146. * 构造函数
  147. * @param type $args
  148. */
  149. public function __construct($args) {
  150. if (isInt($args)) {
  151. $this->typeId = $args;
  152. } else {
  153. parent::__construct($args);
  154. }
  155. }
  156. /**
  157. * 是否状态型任务
  158. * @param type $cmd
  159. */
  160. function isStatusType() {
  161. return $this->mo()->cmd == Enum_TaskCmdType::GainItem # 获取道具
  162. || $this->mo()->cmd == Enum_TaskCmdType::HeroLevelUpTo # 提升玩家等级到x
  163. || $this->mo()->cmd == Enum_TaskCmdType::CommanderLevelUpTo;
  164. }
  165. /**
  166. * 自动对齐可能出现统计失误的状态型任务计数
  167. * @return boolean 是否有修改
  168. */
  169. function autoCalcStatusCur() {
  170. if ($this->isStatusType()) {
  171. $mo = $this->mo();
  172. if ($mo != null) {
  173. $cur = $this->calcStatusCur();
  174. if ($cur > $this->max()) {
  175. $cur = $this->max();
  176. }
  177. if ($this->cur != $cur) {
  178. $this->cur = $cur;
  179. return true;
  180. }
  181. }
  182. }
  183. return false;
  184. }
  185. /**
  186. * @return int 计算状态类的进度
  187. */
  188. function calcStatusCur() {
  189. $mo = $this->mo();
  190. $paras = $this->paras();
  191. $para0 = "";
  192. $para1 = "";
  193. $para2 = "";
  194. if (count($paras) >= 1) {
  195. $para0 = $paras[0];
  196. }
  197. if (count($paras) >= 2) {
  198. $para1 = $paras[1];
  199. }
  200. if (count($paras) >= 3) {
  201. $para2 = $paras[2];
  202. }
  203. switch ($mo->cmd) {
  204. case Enum_TaskCmdType::GainItem: # 收集道具
  205. $store = new Info_Store(req()->userInfo->game->store);
  206. return $store->GetItemCount($para0);
  207. case Enum_TaskCmdType::CommanderLevelUpTo:
  208. $lvl = req()->userInfo->game->baseInfo->level;
  209. return $lvl;
  210. case Enum_TaskCmdType::HeroLevelUpTo:
  211. $heros = new Info_UserGameHero(req()->userInfo->game->heros);
  212. $hero = $heros->GetHeroByMoID($para0);
  213. if (null != $hero) {
  214. return $hero->level;
  215. }
  216. break;
  217. }
  218. return 0;
  219. }
  220. /**
  221. * 检查任务条件(与petmini采用相同的参数和判定方法2020年12月12日11:38:02)
  222. * @param Ins_TaskEventArgs $taskCardEvent
  223. * @return bool
  224. */
  225. public function check_new($taskCardEvent) {
  226. // var_dump($taskCardEvent);
  227. if ($taskCardEvent->taskType != $this->mo()->cmd) { # 事件类型匹配
  228. return false;
  229. }
  230. if ($this->isStatusType()) { # 状态检查类任务
  231. return $this->autoCalcStatusCur();
  232. }
  233. if ($this->isFinish()) {
  234. return false;
  235. }
  236. if (strlen($this->mo()->paras) <= 0) { # 无参数
  237. return true;
  238. }
  239. $paras = $this->paras();
  240. $index = 0;
  241. foreach ($taskCardEvent->paras as $para) { # 其他任务, 执行参数判定
  242. if ($index < count($paras)) {
  243. if (strpos($para, "|") !== false) { # 某个条件是"或"的关系, 即有多重可能值, 满足其一即可
  244. $paraList = explode("|", $para);
  245. foreach ($paraList as $paraItem) {
  246. if ($paraItem == $paras[$index]) {
  247. continue; # 满足某一个即可, 继续判断下一个条件.
  248. }
  249. }
  250. } else { # only one, 不存在"或"的判定
  251. if ($paras[$index] != 0 && $para != $paras[$index]) { # 直接匹配
  252. return false; # 一但没匹配上, 直接返回false就好了.
  253. }
  254. }
  255. } # 参数中多余的数据就直接跳过,不比较了(因为自己不需要判断那么多参数)
  256. $index++;
  257. }
  258. return true; # 走到最后则判定满足条件.
  259. }
  260. /**
  261. * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22)
  262. * @param Ins_TaskEventArgs $taskParam
  263. */
  264. public function propel($taskParam) {
  265. // var_dump($taskParam);
  266. switch ($taskParam->ope) {
  267. case Enum_PropelType::set:
  268. $this->cur = $taskParam->val;
  269. break;
  270. case Enum_PropelType::add:
  271. $this->cur += $taskParam->val;
  272. break;
  273. case Enum_PropelType::inc:
  274. $this->cur += 1;
  275. break;
  276. case Enum_PropelType::max:
  277. if ($taskParam->val > $this->cur) {
  278. $this->cur = $taskParam->val;
  279. }
  280. break;
  281. case Enum_PropelType::stat:
  282. break;
  283. }
  284. }
  285. }