Ins_TaskStep.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. StoreProc::AddMultiItemInStore($plot->presentItem);
  78. }
  79. if (!empty($plot->recycleItem)) {
  80. $val = explode(",", $plot->recycleItem);
  81. my_Assert(count($val) > 1, "解析回收道具字符串出错");
  82. StoreProc::removeItemFromStore(ctx()->store, $val[0], $val[1]);
  83. }
  84. }
  85. break;
  86. case Enum_EventActionType::UnlockBuild: # 解锁建筑
  87. ctx()->privateState->unlockedBuild[] = $act->parameters;
  88. StatisticsProc::TargetStatistics(Enum_TargetStatistics::unlockbuidId, $act->parameters);
  89. break;
  90. }
  91. }
  92. /**
  93. * 执行任务开始事件
  94. */
  95. public function doStartAct() {
  96. // if ($this->mo()->startact > 0) {
  97. // $act = GameConfig::eventAction_getItem($this->mo()->startact);
  98. // $this->execAct($act);
  99. // }
  100. $this->actState = 1;
  101. }
  102. /**
  103. * 构造函数
  104. * @param type $args
  105. */
  106. public function __construct($args) {
  107. if (isInt($args)) {
  108. $this->typeId = $args;
  109. } else {
  110. parent::__construct($args);
  111. }
  112. }
  113. /**
  114. * 是否状态型任务---2022-7-29最新备注:add类型的只能动作触发-不能在这里添加类型 ;set类型只动作触发不添加在这,要是满足条件就完成任务就添加在这
  115. * @param type $cmd
  116. */
  117. function isStatusType() {
  118. return $this->mo()->cmd == Enum_TaskCmdType::GainItem # 获取道具
  119. || $this->mo()->cmd == Enum_TaskCmdType::HeroLevelUpTo # 唤灵师等级达到x级
  120. || $this->mo()->cmd == Enum_TaskCmdType::WeaponLevelUp # 唤灵师突破升星
  121. || $this->mo()->cmd == Enum_TaskCmdType::YanlingLevelUp # 将指定言灵升级到指定等级
  122. || $this->mo()->cmd == Enum_TaskCmdType::CommanderLevelUpTo # 指挥官等级
  123. || $this->mo()->cmd == Enum_TaskCmdType::HeroWearingYanling # 唤灵师装备了任意言灵
  124. || $this->mo()->cmd == Enum_TaskCmdType::HeroWearingWeapon_Except#唤灵师装备了除(xx)外的武器
  125. || $this->mo()->cmd == Enum_TaskCmdType::UserOwnXYanlingWithQualityN # 拥有言灵
  126. || $this->mo()->cmd == Enum_TaskCmdType::HeroGradeUpTo_status #武器突破升星
  127. | $this->mo()->cmd == Enum_TaskCmdType::passEndlessCarbonN; #武器突破升星
  128. //|| $this->mo()->cmd == Enum_TaskCmdType::UpgradeXYanlingToNStar;#言灵突破升星
  129. }
  130. /**
  131. * 自动对齐可能出现统计失误的状态型任务计数
  132. * @return boolean 是否有修改
  133. */
  134. function autoCalcStatusCur() {
  135. if ($this->isStatusType()) {
  136. $mo = $this->mo();
  137. if ($mo != null) {
  138. $cur = $this->calcStatusCur();
  139. if ($cur > $this->max()) {
  140. $cur = $this->max();
  141. }
  142. if ($this->cur != $cur) {
  143. $this->cur = $cur;
  144. return true;
  145. }
  146. }
  147. }
  148. return false;
  149. }
  150. /**
  151. * @return int 计算状态类的进度
  152. */
  153. function calcStatusCur() {
  154. $mo = $this->mo();
  155. $paras = $this->paras();
  156. $para0 = "";
  157. $para1 = "";
  158. $para2 = "";
  159. if (count($paras) >= 1) {
  160. $para0 = $paras[0];
  161. }
  162. if (count($paras) >= 2) {
  163. $para1 = $paras[1];
  164. }
  165. if (count($paras) >= 3) {
  166. $para2 = $paras[2];
  167. }
  168. switch ($mo->cmd) {
  169. case Enum_TaskCmdType::GainItem: # 收集道具
  170. $store = new Info_Store(ctx()->store);
  171. return $store->GetItemCount($para0);
  172. case Enum_TaskCmdType::CommanderLevelUpTo:
  173. $lvl = ctx()->base()->level;
  174. return $lvl;
  175. case Enum_TaskCmdType::HeroLevelUpTo:
  176. $heros = new Info_UserGameHero(ctx()->heros);
  177. $hero = $heros->GetHeroByMoID($para0);
  178. if (null != $hero) {
  179. return $hero->level;
  180. }
  181. break;
  182. case Enum_TaskCmdType::HeroGradeUpTo_status: #唤灵师进行一个突破升星
  183. $heros = new Info_UserGameHero(ctx()->heros);
  184. $hero = $heros->GetHeroByMoID(101005);
  185. if (null != $hero) {
  186. return $hero->curStar;
  187. }
  188. break;
  189. case Enum_TaskCmdType::UserOwnXYanlingWithQualityN: # 拥有x个n品质的言灵
  190. $store = new Info_Store(ctx()->store);
  191. $num = 0;
  192. foreach ($store->yanling as $uid => $yanlingvo) {
  193. $yanlingvo = new Ins_YanLin($yanlingvo);
  194. // var_dump($yanlingvo);
  195. $itemMo = GameConfig::item_base_getItem($yanlingvo->typeId);
  196. my_Assert(null != $itemMo, ErrCode::err_const_no);
  197. if ($itemMo->quality >= $para0) {
  198. $num++;
  199. }
  200. }
  201. // CLog::info("当前拥有$num 个对应品质的言灵.");
  202. return $num;
  203. case Enum_TaskCmdType::WeaponLevelUp: # 将特定的武器升级到X级(num 等级数,paras:武器id)
  204. $equipment = ctx()->store->equipment;
  205. $n = 0;
  206. foreach ($equipment as $eUid => $equip) {
  207. if ($equip->typeId == $para0 && $n < $equip->level) {
  208. $n = $equip->level;
  209. }
  210. }
  211. return $n;
  212. case Enum_TaskCmdType::YanlingLevelUp: #将任意言灵突破到N星
  213. $yanling = ctx()->store->yanling;
  214. $lv = 0;
  215. foreach ($yanling as $yUid => $yl) {
  216. // if ($yl->typeId == $para0 && $lv < $equip->level) {
  217. // $lv = $yl->level;
  218. // //break;
  219. // }
  220. if ($yl->level >= $lv) {
  221. $lv = $yl->level;
  222. }
  223. }
  224. return $lv;
  225. case Enum_TaskCmdType::HeroWearingYanling: # 检查唤灵师是否已经装备了言灵
  226. // isEditor() and $hero = new Ins_UserHero();
  227. $heros = new Info_UserGameHero(ctx()->heros);
  228. $hero = $heros->GetHeroByMoID($para0);
  229. if (null != $hero) {
  230. foreach ($hero->yanling as $pos => $item) {
  231. if (isset($item) && $item->itemuid > 0) {
  232. return 1; # 找到言灵
  233. }
  234. }
  235. }
  236. return 0;
  237. case Enum_TaskCmdType::HeroWearingWeapon_Except: # 检查唤灵师是否已经装备了武器(xx)除外
  238. // isEditor() and $hero = new Ins_UserHero();
  239. $heros = new Info_UserGameHero(ctx()->heros);
  240. $hero = $heros->GetHeroByMoID($para0);
  241. if (null != $hero) {
  242. if (isset($hero->equip->weapon->itemuid) #
  243. && $hero->equip->weapon->itemuid > 0) {#
  244. $eqid = $hero->equip->weapon->itemuid;
  245. $store = new Info_Store(ctx()->store);
  246. if (property_exists($store->equipment, $eqid)) {
  247. $equip = $store->equipment->$eqid;
  248. if ($equip->typeId != $para1) {
  249. return 1; # 找到武器
  250. }
  251. }
  252. }
  253. }
  254. return 0;
  255. case Enum_TaskCmdType::passEndlessCarbonN: # 通关无尽塔X层
  256. // isEditor() and $hero = new Ins_UserHero();
  257. $num = ctx()->privateState->endlessTower - 1;
  258. return $num;
  259. default:
  260. break;
  261. }
  262. return 0;
  263. }
  264. /**
  265. * 检查任务条件(与petmini采用相同的参数和判定方法2020年12月12日11:38:02)
  266. * @param Ins_TaskEventArgs $taskCardEvent
  267. * @return bool
  268. */
  269. public function check_new($taskCardEvent) {
  270. // echoLine(" check: " . json_encode($taskCardEvent));
  271. // CLog::info("{$this->typeId} checking: " . json_encode($taskCardEvent));
  272. if ($taskCardEvent->taskType != $this->mo()->cmd) { # 事件类型匹配
  273. return false;
  274. }
  275. if ($this->isStatusType()) { # 状态检查类任务
  276. return $this->autoCalcStatusCur();
  277. }
  278. if ($this->isFinish()) {
  279. return false;
  280. }
  281. if (strlen($this->mo()->paras) <= 0) { # 无参数
  282. return true;
  283. }
  284. $paras = $this->paras();
  285. $index = 0;
  286. foreach ($taskCardEvent->paras as $para) { # 其他任务, 执行参数判定
  287. if ($index < count($paras)) {
  288. if (strpos($para, "|") !== false) { # 某个条件是"或"的关系, 即有多重可能值, 满足其一即可
  289. $paraList = explode("|", $para);
  290. foreach ($paraList as $paraItem) {
  291. if ($paraItem == $paras[$index]) {
  292. continue; # 满足某一个即可, 继续判断下一个条件.
  293. }
  294. }
  295. } else { # only one, 不存在"或"的判定
  296. if ($para != $paras[$index]) { # 直接匹配
  297. return false; # 一但没匹配上, 直接返回false就好了.
  298. }
  299. }
  300. } # 参数中多余的数据就直接跳过,不比较了(因为自己不需要判断那么多参数)
  301. $index++;
  302. }
  303. return true; # 走到最后则判定满足条件.
  304. }
  305. /**
  306. * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22)
  307. * @param Ins_TaskEventArgs $taskParam
  308. */
  309. public function propel($taskParam) {
  310. // var_dump($taskParam);
  311. switch ($taskParam->ope) {
  312. case Enum_PropelType::set:
  313. $this->cur = $taskParam->val;
  314. break;
  315. case Enum_PropelType::add:
  316. $this->cur += $taskParam->val;
  317. break;
  318. case Enum_PropelType::inc:
  319. $this->cur += 1;
  320. break;
  321. case Enum_PropelType::max:
  322. if ($taskParam->val > $this->cur) {
  323. $this->cur = $taskParam->val;
  324. }
  325. break;
  326. case Enum_PropelType::stat:
  327. break;
  328. }
  329. }
  330. }