Ins_TaskStep.php 9.8 KB

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