Ins_TaskStep.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 任务步骤, 用于任务卡功能(三组合一)
  5. * @author gwang(wanggangzero@qq.com)
  6. */
  7. class Ins_TaskStep extends Object_ext {
  8. public $uid = 0;
  9. /**
  10. * @var type 查询用的id
  11. */
  12. public $typeId = 0;
  13. /**
  14. * @var int 计数器
  15. */
  16. public $cur = 0;
  17. /**
  18. * @var int start/finish act已执行(0:startAct未执行,1:StartAct已执行且finishAct未执行,2:finishAct已执行)
  19. */
  20. public $actState = 0;
  21. /**
  22. * 进行中 完成未领奖 已经领取奖励
  23. * @var type
  24. */
  25. public $state = 0;
  26. /**
  27. * @return \sm_task_step mo 获取对应的模板数据
  28. */
  29. public function mo() {
  30. $mo = GameConfig::task_step_getItem($this->typeId);
  31. my_Assert(null != $mo, ErrCode::err_const_no);
  32. return $mo;
  33. }
  34. /**
  35. * @return int 计数最大值
  36. */
  37. public function max() {
  38. return $this->mo()->num;
  39. }
  40. /**
  41. * @return string[] 参数数组
  42. */
  43. private function paras() {
  44. return explode(',', $this->mo()->paras);
  45. }
  46. /**
  47. * @return float 当前进度
  48. */
  49. public function progress() {
  50. return $this->cur / $this->max();
  51. }
  52. /**
  53. * 是否完成
  54. * @return bool
  55. */
  56. public function isFinish() {
  57. return $this->cur >= $this->max();
  58. }
  59. /**
  60. * 构造函数
  61. * @param type $args
  62. */
  63. public function __construct($args) {
  64. if (isInt($args)) {
  65. $this->typeId = $args;
  66. } else {
  67. parent::__construct($args);
  68. }
  69. }
  70. /**
  71. * 是否状态型任务---2022-7-29最新备注:add类型的只能动作触发-不能在这里添加类型 ;set类型只动作触发不添加在这,要是满足条件就完成任务就添加在这
  72. * @param type $cmd
  73. */
  74. function isStatusType() {
  75. return false;
  76. // return $this->mo()->cmd == Enum_TaskCmdType::GainItem # 获取道具
  77. // || $this->mo()->cmd == Enum_TaskCmdType::HeroLevelUpTo; # 唤灵师等级达到x级
  78. //|| $this->mo()->cmd == Enum_TaskCmdType::UpgradeXYanlingToNStar;#言灵突破升星
  79. }
  80. /**
  81. * 自动对齐可能出现统计失误的状态型任务计数
  82. * @return boolean 是否有修改
  83. */
  84. function autoCalcStatusCur() {
  85. if ($this->isStatusType()) {
  86. $mo = $this->mo();
  87. if ($mo != null) {
  88. $cur = $this->calcStatusCur();
  89. if ($cur > $this->max()) {
  90. $cur = $this->max();
  91. }
  92. if ($this->cur != $cur) {
  93. $this->cur = $cur;
  94. return true;
  95. }
  96. }
  97. }
  98. return false;
  99. }
  100. /**
  101. * @return int 计算状态类的进度
  102. */
  103. function calcStatusCur() {
  104. $mo = $this->mo();
  105. $paras = $this->paras();
  106. $para0 = "";
  107. $para1 = "";
  108. $para2 = "";
  109. if (count($paras) >= 1) {
  110. $para0 = $paras[0];
  111. }
  112. if (count($paras) >= 2) {
  113. $para1 = $paras[1];
  114. }
  115. if (count($paras) >= 3) {
  116. $para2 = $paras[2];
  117. }
  118. // switch ($mo->cmd) {
  119. // case Enum_TaskCmdType::passEndlessCarbonN: # 通关无尽塔X层
  120. //// isEditor() and $hero = new Ins_UserHero();
  121. // $num = ctx()->privateState->endlessTower - 1;
  122. // return $num;
  123. // default:
  124. // break;
  125. // }
  126. return 0;
  127. }
  128. /**
  129. * 检查任务条件(与petmini采用相同的参数和判定方法2020年12月12日11:38:02)
  130. * @param Ins_TaskEventArgs $taskCardEvent
  131. * @return bool
  132. */
  133. public function check_new($taskCardEvent) {
  134. if ($taskCardEvent->taskType != $this->mo()->cmd) { # 事件类型匹配
  135. return false;
  136. }
  137. if ($this->isStatusType()) { # 状态检查类任务
  138. return $this->autoCalcStatusCur();
  139. }
  140. if ($this->isFinish()) {
  141. return false;
  142. }
  143. if (strlen($this->mo()->paras) <= 0) { # 无参数
  144. return true;
  145. }
  146. $paras = $this->paras();
  147. $index = 0;
  148. foreach ($taskCardEvent->paras as $para) { # 其他任务, 执行参数判定
  149. if ($index < count($paras)) {
  150. if (strpos($para, "|") !== false) { # 某个条件是"或"的关系, 即有多重可能值, 满足其一即可
  151. $paraList = explode("|", $para);
  152. foreach ($paraList as $paraItem) {
  153. if ($paraItem == $paras[$index]) {
  154. continue; # 满足某一个即可, 继续判断下一个条件.
  155. }
  156. }
  157. } else { # only one, 不存在"或"的判定
  158. if ($para != $paras[$index]) { # 直接匹配
  159. return false; # 一但没匹配上, 直接返回false就好了.
  160. }
  161. }
  162. } # 参数中多余的数据就直接跳过,不比较了(因为自己不需要判断那么多参数)
  163. $index++;
  164. }
  165. return true; # 走到最后则判定满足条件.
  166. }
  167. /**
  168. * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22)
  169. * @param Ins_TaskEventArgs $taskParam
  170. */
  171. public function propel($taskParam) {
  172. // var_dump($taskParam);
  173. switch ($taskParam->ope) {
  174. case Enum_PropelType::set:
  175. $this->cur = $taskParam->val;
  176. break;
  177. case Enum_PropelType::add:
  178. $this->cur += $taskParam->val;
  179. break;
  180. case Enum_PropelType::inc:
  181. $this->cur += 1;
  182. break;
  183. case Enum_PropelType::max:
  184. if ($taskParam->val > $this->cur) {
  185. $this->cur = $taskParam->val;
  186. }
  187. break;
  188. case Enum_PropelType::stat:
  189. break;
  190. }
  191. }
  192. }