typeId); my_Assert(null != $mo, ErrCode::err_const_no); return $mo; } /** * @return int 计数最大值 */ public function max() { return $this->mo()->num; } /** * @return string[] 参数数组 */ private function paras() { return explode(',', $this->mo()->paras); } /** * @return float 当前进度 */ public function progress() { return $this->cur / $this->max(); } /** * 是否完成 * @return bool */ public function isFinish() { return $this->cur >= $this->max(); } /** * 执行任务完成事件 */ public function doFinishAct() { // if ($this->mo()->finishact > 0) { // $act = GameConfig::eventAction_getItem($this->mo()->finishact); // $this->execAct($act); // } $this->actState = 2; } /** * * @param \sm_eventAction $act */ private function execAct($act) { my_Assert($act, ErrCode::err_const_no); switch ($act->cmd) { case Enum_EventActionType::StartPlotScene: # 触发场景剧情, case Enum_EventActionType::StartPlotNPC: # 触发NPC剧情 $paras = explode(',', $act->parameters); # 解析下参数 $arr = GameConfig::plot_getItem($paras[0], $paras[1]); # 查找对应的剧情 foreach ($arr as $plot) { isEditor() and $plot = new \sm_plot(); if (!empty($plot->presentItem)) { StoreProc::AddMultiItemInStore($plot->presentItem); } if (!empty($plot->recycleItem)) { $val = explode(",", $plot->recycleItem); my_Assert(count($val) > 1, "解析回收道具字符串出错"); StoreProc::removeItemFromStore(ctx()->store, $val[0], $val[1]); } } break; case Enum_EventActionType::UnlockBuild: # 解锁建筑 ctx()->privateState->unlockedBuild[] = $act->parameters; break; } } /** * 执行任务开始事件 */ public function doStartAct() { // if ($this->mo()->startact > 0) { // $act = GameConfig::eventAction_getItem($this->mo()->startact); // $this->execAct($act); // } $this->actState = 1; } /** * 构造函数 * @param type $args */ public function __construct($args) { if (isInt($args)) { $this->typeId = $args; } else { parent::__construct($args); } } /** * 是否状态型任务---2022-7-29最新备注:add类型的只能动作触发-不能在这里添加类型 ;set类型只动作触发不添加在这,要是满足条件就完成任务就添加在这 * @param type $cmd */ function isStatusType() { return $this->mo()->cmd == Enum_TaskCmdType::GainItem # 获取道具 || $this->mo()->cmd == Enum_TaskCmdType::HeroLevelUpTo # 唤灵师等级达到x级 || $this->mo()->cmd == Enum_TaskCmdType::WeaponLevelUp # 唤灵师突破升星 || $this->mo()->cmd == Enum_TaskCmdType::YanlingLevelUp # 将指定言灵升级到指定等级 || $this->mo()->cmd == Enum_TaskCmdType::CommanderLevelUpTo # 指挥官等级 || $this->mo()->cmd == Enum_TaskCmdType::HeroWearingYanling # 唤灵师装备了任意言灵 || $this->mo()->cmd == Enum_TaskCmdType::HeroWearingWeapon_Except#唤灵师装备了除(xx)外的武器 || $this->mo()->cmd == Enum_TaskCmdType::UserOwnXYanlingWithQualityN # 拥有言灵 || $this->mo()->cmd == Enum_TaskCmdType::HeroGradeUpTo_status #武器突破升星 | $this->mo()->cmd == Enum_TaskCmdType::passEndlessCarbonN; #武器突破升星 //|| $this->mo()->cmd == Enum_TaskCmdType::UpgradeXYanlingToNStar;#言灵突破升星 } /** * 自动对齐可能出现统计失误的状态型任务计数 * @return boolean 是否有修改 */ function autoCalcStatusCur() { if ($this->isStatusType()) { $mo = $this->mo(); if ($mo != null) { $cur = $this->calcStatusCur(); if ($cur > $this->max()) { $cur = $this->max(); } if ($this->cur != $cur) { $this->cur = $cur; return true; } } } return false; } /** * @return int 计算状态类的进度 */ function calcStatusCur() { $mo = $this->mo(); $paras = $this->paras(); $para0 = ""; $para1 = ""; $para2 = ""; if (count($paras) >= 1) { $para0 = $paras[0]; } if (count($paras) >= 2) { $para1 = $paras[1]; } if (count($paras) >= 3) { $para2 = $paras[2]; } switch ($mo->cmd) { case Enum_TaskCmdType::GainItem: # 收集道具 $store = new Info_Store(ctx()->store); return $store->GetItemCount($para0); case Enum_TaskCmdType::CommanderLevelUpTo: $lvl = ctx()->base()->level; return $lvl; case Enum_TaskCmdType::HeroLevelUpTo: $heros = new Info_UserGameHero(ctx()->heros); $hero = $heros->GetHeroByMoID($para0); if (null != $hero) { return $hero->level; } break; case Enum_TaskCmdType::HeroGradeUpTo_status: #唤灵师进行一个突破升星 $heros = new Info_UserGameHero(ctx()->heros); $hero = $heros->GetHeroByMoID(101005); if (null != $hero) { return $hero->curStar; } break; case Enum_TaskCmdType::UserOwnXYanlingWithQualityN: # 拥有x个n品质的言灵 $store = new Info_Store(ctx()->store); $num = 0; foreach ($store->yanling as $uid => $yanlingvo) { $yanlingvo = new Ins_YanLin($yanlingvo); // var_dump($yanlingvo); $itemMo = GameConfig::item_base_getItem($yanlingvo->typeId); my_Assert(null != $itemMo, ErrCode::err_const_no); if ($itemMo->quality >= $para0) { $num++; } } // CLog::info("当前拥有$num 个对应品质的言灵."); return $num; case Enum_TaskCmdType::WeaponLevelUp: # 将特定的武器升级到X级(num 等级数,paras:武器id) $equipment = ctx()->store->equipment; $n = 0; foreach ($equipment as $eUid => $equip) { if ($equip->typeId == $para0 && $n < $equip->level) { $n = $equip->level; } } return $n; case Enum_TaskCmdType::YanlingLevelUp: #将任意言灵突破到N星 $yanling = ctx()->store->yanling; $lv = 0; foreach ($yanling as $yUid => $yl) { // if ($yl->typeId == $para0 && $lv < $equip->level) { // $lv = $yl->level; // //break; // } if ($yl->level >= $lv) { $lv = $yl->level; } } return $lv; case Enum_TaskCmdType::HeroWearingYanling: # 检查唤灵师是否已经装备了言灵 // isEditor() and $hero = new Ins_UserHero(); $heros = new Info_UserGameHero(ctx()->heros); $hero = $heros->GetHeroByMoID($para0); if (null != $hero) { foreach ($hero->yanling as $pos => $item) { if (isset($item) && $item->itemuid > 0) { return 1; # 找到言灵 } } } return 0; case Enum_TaskCmdType::HeroWearingWeapon_Except: # 检查唤灵师是否已经装备了武器(xx)除外 // isEditor() and $hero = new Ins_UserHero(); $heros = new Info_UserGameHero(ctx()->heros); $hero = $heros->GetHeroByMoID($para0); if (null != $hero) { if (isset($hero->equip->weapon->itemuid) # && $hero->equip->weapon->itemuid > 0) {# $eqid = $hero->equip->weapon->itemuid; $store = new Info_Store(ctx()->store); if (property_exists($store->equipment, $eqid)) { $equip = $store->equipment->$eqid; if ($equip->typeId != $para1) { return 1; # 找到武器 } } } } return 0; case Enum_TaskCmdType::passEndlessCarbonN: # 通关无尽塔X层 // isEditor() and $hero = new Ins_UserHero(); $num = ctx()->privateState->endlessTower - 1; return $num; default: break; } return 0; } /** * 检查任务条件(与petmini采用相同的参数和判定方法2020年12月12日11:38:02) * @param Ins_TaskEventArgs $taskCardEvent * @return bool */ public function check_new($taskCardEvent) { // echoLine(" check: " . json_encode($taskCardEvent)); // CLog::info("{$this->typeId} checking: " . json_encode($taskCardEvent)); if ($taskCardEvent->taskType != $this->mo()->cmd) { # 事件类型匹配 return false; } if ($this->isStatusType()) { # 状态检查类任务 return $this->autoCalcStatusCur(); } if ($this->isFinish()) { return false; } if (strlen($this->mo()->paras) <= 0) { # 无参数 return true; } $paras = $this->paras(); $index = 0; foreach ($taskCardEvent->paras as $para) { # 其他任务, 执行参数判定 if ($index < count($paras)) { if (strpos($para, "|") !== false) { # 某个条件是"或"的关系, 即有多重可能值, 满足其一即可 $paraList = explode("|", $para); foreach ($paraList as $paraItem) { if ($paraItem == $paras[$index]) { continue; # 满足某一个即可, 继续判断下一个条件. } } } else { # only one, 不存在"或"的判定 if ($para != $paras[$index]) { # 直接匹配 return false; # 一但没匹配上, 直接返回false就好了. } } } # 参数中多余的数据就直接跳过,不比较了(因为自己不需要判断那么多参数) $index++; } return true; # 走到最后则判定满足条件. } /** * 推进任务进度(采用和petmini相同的推进算法,2020年12月12日11:38:22) * @param Ins_TaskEventArgs $taskParam */ public function propel($taskParam) { // var_dump($taskParam); switch ($taskParam->ope) { case Enum_PropelType::set: $this->cur = $taskParam->val; break; case Enum_PropelType::add: $this->cur += $taskParam->val; break; case Enum_PropelType::inc: $this->cur += 1; break; case Enum_PropelType::max: if ($taskParam->val > $this->cur) { $this->cur = $taskParam->val; } break; case Enum_PropelType::stat: break; } } }