Ins_TaskStep.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. * @return \sm_task_step mo 获取对应的模板数据
  18. */
  19. public function mo() {
  20. $mo = GameConfig::task_step_getItem($this->typeId);
  21. my_Assert(null != $mo, ErrCode::err_const_no);
  22. return $mo;
  23. }
  24. /**
  25. * @return int 计数最大值
  26. */
  27. public function max() {
  28. return $this->mo()->num;
  29. }
  30. /**
  31. * @return string[] 参数数组
  32. */
  33. private function paras() {
  34. return explode(',', $this->mo()->paras);
  35. }
  36. /**
  37. * @return float 当前进度
  38. */
  39. public function progress() {
  40. return $this->cur / $this->max();
  41. }
  42. /**
  43. * 是否完成
  44. * @return bool
  45. */
  46. public function isFinish() {
  47. return $this->cur >= $this->max();
  48. }
  49. /**
  50. * 构造函数
  51. * @param type $args
  52. */
  53. public function __construct($args) {
  54. if (isInt($args)) {
  55. $this->typeId = $args;
  56. } else {
  57. parent::__construct($args);
  58. }
  59. }
  60. /**
  61. * 是否状态型任务
  62. * @param type $cmd
  63. */
  64. function isStatusType() {
  65. return $this->mo()->cmd == Enum_TaskCmdType::GainItem;
  66. }
  67. /**
  68. * 自动对齐可能出现统计失误的状态型任务计数
  69. * @return boolean 是否有修改
  70. */
  71. function autoCalcStatusCur() {
  72. if ($this->isStatusType()) {
  73. $mo = $this->mo();
  74. if ($mo != null) {
  75. $cur = $this->calcStatusCur();
  76. if ($cur > $this->max()) {
  77. $cur = $this->max();
  78. }
  79. if ($this->cur != $cur) {
  80. $this->cur = $cur;
  81. return true;
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87. /**
  88. * @return int 计算状态类的进度
  89. */
  90. function calcStatusCur() {
  91. $mo = $this->mo();
  92. $paras = $this->paras();
  93. $para0 = "";
  94. $para1 = "";
  95. $para2 = "";
  96. if (count($paras) >= 1) {
  97. $para0 = $paras[0];
  98. }
  99. if (count($paras) >= 2) {
  100. $para1 = $paras[1];
  101. }
  102. if (count($paras) >= 3) {
  103. $para2 = $paras[2];
  104. }
  105. switch ($mo->cmd) {
  106. case Enum_TaskCmdType::GainItem: # 收集道具
  107. $store = new Info_Store(req()->userInfo->game->store);
  108. return $store->GetItemCount($para0);
  109. }
  110. return 0;
  111. }
  112. /**
  113. * 检查任务条件(与petmini采用相同的参数和判定方法2020年12月12日11:38:02)
  114. * @param Ins_TaskEventArgs $taskCardEvent
  115. * @return bool
  116. */
  117. public function check_new($taskCardEvent) {
  118. // var_dump($taskCardEvent);
  119. if ($this->isStatusType()) { # 状态检查类任务
  120. return $this->autoCalcStatusCur();
  121. }
  122. if ($this->isFinish()) {
  123. return true;
  124. }
  125. if ($taskCardEvent->taskType != $this->mo()->cmd) { # 事件类型匹配
  126. return false;
  127. }
  128. if (strlen($this->mo()->paras) <= 0) { # 无参数
  129. return true;
  130. }
  131. $paras = $this->paras();
  132. $index = 0;
  133. foreach ($taskCardEvent->paras as $para) { # 其他任务, 执行参数判定
  134. if ($index < count($paras)) {
  135. if (strpos($para, "|") !== false) { # 某个条件是"或"的关系, 即有多重可能值, 满足其一即可
  136. $paraList = explode("|", $para);
  137. foreach ($paraList as $paraItem) {
  138. if ($paraItem == $paras[$index]) {
  139. continue; # 满足某一个即可, 继续判断下一个条件.
  140. }
  141. }
  142. } else { # only one, 不存在"或"的判定
  143. if ($paras[$index] != 0 && $para != $paras[$index]) { # 直接匹配
  144. return false; # 一但没匹配上, 直接返回false就好了.
  145. }
  146. }
  147. } # 参数中多余的数据就直接跳过,不比较了(因为自己不需要判断那么多参数)
  148. $index++;
  149. }
  150. return true; # 走到最后则判定满足条件.
  151. }
  152. /**
  153. * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22)
  154. * @param Ins_TaskEventArgs $taskParam
  155. */
  156. public function propel($taskParam) {
  157. // var_dump($taskParam);
  158. switch ($taskParam->ope) {
  159. case Enum_PropelType::set:
  160. $this->cur = $taskParam->val;
  161. break;
  162. case Enum_PropelType::add:
  163. $this->cur += $taskParam->val;
  164. break;
  165. case Enum_PropelType::inc:
  166. $this->cur += 1;
  167. break;
  168. case Enum_PropelType::max:
  169. if ($taskParam->val > $this->cur) {
  170. $this->cur = $taskParam->val;
  171. }
  172. break;
  173. }
  174. }
  175. }