Ins_TaskStep.php 4.0 KB

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