Ins_TaskStep_Active.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 任务步骤, 用于任务卡功能(三组合一)
  5. * @author gwang(wanggangzero@qq.com)
  6. */
  7. class Ins_TaskStep_Active extends Object_ext {
  8. /**
  9. *
  10. * @var type
  11. */
  12. public $uid = 0;
  13. /**
  14. * @var type 查询用的id
  15. */
  16. public $typeId = 0;
  17. /**
  18. * @var int 计数器
  19. */
  20. public $cur = 0;
  21. /**
  22. * @var 2:进行中 3:完成未领取奖励 4 已经领取奖励
  23. */
  24. public $state = 0;
  25. /**
  26. * @return \sm_task_step mo 获取对应的模板数据
  27. */
  28. public function mo() {
  29. $mo = GameConfig::activeTask_getItem($this->typeId);
  30. my_Assert(null != $mo, ErrCode::err_const_no);
  31. return $mo;
  32. }
  33. /**
  34. * @return int 计数最大值
  35. */
  36. public function max() {
  37. return $this->mo()->num;
  38. }
  39. /**
  40. * @return string[] 参数数组
  41. */
  42. private function paras() {
  43. return explode(',', $this->mo()->paras);
  44. }
  45. /**
  46. * @return float 当前进度
  47. */
  48. public function progress() {
  49. return $this->cur / $this->max();
  50. }
  51. /**
  52. * 是否完成
  53. * @return bool
  54. */
  55. public function isFinish() {
  56. return $this->cur >= $this->max();
  57. }
  58. /**
  59. * 构造函数
  60. * @param type $args
  61. */
  62. public function __construct($args) {
  63. if (isInt($args)) {
  64. $this->typeId = $args;
  65. } else {
  66. parent::__construct($args);
  67. }
  68. }
  69. /**
  70. * 是否状态型任务
  71. * @param type $cmd
  72. */
  73. function isStatusType() {
  74. return $this->mo()->cmd == Enum_TaskCmdType::SetSpecialQualGem || $this->mo()->cmd == Enum_TaskCmdType::AnyEquipUpLevel_X || $this->mo()->cmd == Enum_TaskCmdType::AllEquipUpLevel_X;
  75. }
  76. function calcStatusCur() {
  77. $mo = $this->mo();
  78. $paras = $this->paras();
  79. $para0 = "";
  80. $para1 = "";
  81. $para2 = "";
  82. if (count($paras) >= 1) {
  83. $para0 = $paras[0];
  84. }
  85. if (count($paras) >= 2) {
  86. $para1 = $paras[1];
  87. }
  88. if (count($paras) >= 3) {
  89. $para2 = $paras[2];
  90. }
  91. switch ($mo->cmd) {
  92. case Enum_ActiveTaskCmdType::SetSpecialQualGem: # 镶嵌3个普通品质以上宝石
  93. $gemEquip = ctx()->store->gemEquip;
  94. $num = 0;
  95. foreach ($gemEquip as $pag => $dic) {
  96. foreach ($dic as $posId => $equip) {
  97. if($equip != null){
  98. foreach ($equip as $index => $gem) {
  99. $ins_gem = new Ins_Gem($gem);
  100. if($ins_gem->mo()->qual > $para0){
  101. $num += 1;
  102. }
  103. }
  104. }
  105. }
  106. }
  107. return $num;
  108. case Enum_ActiveTaskCmdType::AnyEquipUpLevel_X: # 任意1件装备等级达到2
  109. $num = 0;
  110. $equip = ctx()->store->equip;
  111. foreach ($equip as $index => $item) {
  112. $ins_equip = new Ins_Equip($item);
  113. if($ins_equip->level >= $para0){
  114. $num += 1;
  115. }
  116. }
  117. return $num;
  118. case Enum_ActiveTaskCmdType::AllEquipUpLevel_X: # 全身装备等级达到3级以上
  119. $num = 0;
  120. $equip = ctx()->store->equip;
  121. foreach ($equip as $index => $item) {
  122. $ins_equip = new Ins_Equip($item);
  123. if($ins_equip->level > $para0){
  124. $num += 1;
  125. }
  126. }
  127. return $num;
  128. default:
  129. break;
  130. }
  131. return 0;
  132. }
  133. /**
  134. * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22)
  135. * @param Ins_TaskEventArgs $taskParam
  136. */
  137. public function propel($taskParam) {
  138. // var_dump($taskParam);
  139. switch ($taskParam->ope) {
  140. case Enum_PropelType::set:
  141. $this->cur = $taskParam->val;
  142. break;
  143. case Enum_PropelType::add:
  144. $this->cur += $taskParam->val;
  145. break;
  146. case Enum_PropelType::inc:
  147. $this->cur += 1;
  148. break;
  149. case Enum_PropelType::max:
  150. if ($taskParam->val > $this->cur) {
  151. $this->cur = $taskParam->val;
  152. }
  153. break;
  154. case Enum_PropelType::stat:
  155. break;
  156. }
  157. }
  158. }