Ins_TaskStep.php 10 KB

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