Ins_TaskStep.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * 检查任务条件(与petmini采用相同的参数和判定方法2020年12月12日11:38:02)
  62. * @param Ins_TaskEventArgs $taskCardEvent
  63. * @return bool
  64. */
  65. public function check_new($taskCardEvent) {
  66. if ($this->isFinish()) {
  67. return true;
  68. }
  69. if ($taskCardEvent->taskType == $this->mo()->cmd) { # 事件类型匹配
  70. return false;
  71. }
  72. if (strlen($this->mo()->paras) <= 0) { # 无参数
  73. return true;
  74. }
  75. $paras = $this->paras();
  76. $index = 0;
  77. foreach ($taskCardEvent->paras as $para) {
  78. if ($index < count($paras)) {
  79. if (strpos($para, "|") !== false) { # 某个条件是"或"的关系, 即有多重可能值, 满足其一即可
  80. $paraList = explode("|", $para);
  81. foreach ($paraList as $paraItem) {
  82. if ($paraItem == $paras[$index]) {
  83. continue; # 满足某一个即可, 继续判断下一个条件.
  84. }
  85. }
  86. } else { # only one, 不存在"或"的判定
  87. if ($paras[$index] != 0 && $para != $paras[$index]) { # 直接匹配
  88. return false; # 一但没匹配上, 直接返回false就好了.
  89. }
  90. }
  91. } # 参数中多余的数据就直接跳过,不比较了(因为自己不需要判断那么多参数)
  92. $index++;
  93. }
  94. return true; # 走到最后则判定满足条件.
  95. }
  96. /**
  97. * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22)
  98. * @param Ins_TaskEventArgs $taskParam
  99. */
  100. public function propel($taskParam) {
  101. switch ($taskParam->ope) {
  102. case Enum_PropelType::set:
  103. $this->cur = $taskParam->val;
  104. break;
  105. case Enum_PropelType::add:
  106. $this->cur += $taskParam->val;
  107. break;
  108. case Enum_PropelType::inc:
  109. $this->cur += 1;
  110. break;
  111. case Enum_PropelType::max:
  112. if ($taskParam->val > $this->cur) {
  113. $this->cur = $taskParam->val;
  114. }
  115. break;
  116. }
  117. }
  118. }