TaskProc.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 任务模块
  5. * @version
  6. * 1.0.0 Created at 2017-11-3. by --gwang
  7. * @author gwang (mail@wanggangzero.cn)
  8. * @copyright ? 2017-11-3, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  9. */
  10. class TaskProc {
  11. /**
  12. * 任务卡-同时激活数量上限
  13. */
  14. const TaskCard_ActiveMax = 9;
  15. /**
  16. * 任务卡商店-刷新数量
  17. */
  18. const TaskCardShop_Refresh_ItemNum = 5;
  19. static function procMain() {
  20. switch (req()->cmd) {
  21. case CmdCode::cmd_task_getInfo: # 6201 刷新任务状态
  22. return TaskProc::GetTaskInfo();
  23. // case CmdCode::cmd_task_getReward: # 6202 领取任务奖励
  24. // return TaskProc::GetTaskReward();
  25. // case CmdCode::cmd_Task_setAttentionTask: # 6203 设置关注任务
  26. // return TaskProc::setAttentionTask();
  27. case CmdCode::cmd_Task_getActiveReward: # 6204 领取日常任务活跃度阶段奖励
  28. return TaskProc::getActiveReward();
  29. //---------------- 任务卡相关通讯 -----------------------------------------------
  30. case CmdCode::cmd_taskCard_PlotFinish: # 6210 任务卡剧情对话
  31. return self::PlotFinish();
  32. // case CmdCode::cmd_taskCard_PlotExchangeTaskCard: # 6211 任务卡兑换奖励
  33. // Err(ErrCode::err_method_obsoleted);
  34. // return self::PlotExchangeTaskCard($req);
  35. // case CmdCode::cmd_taskCard_PlotPresentTaskCard: # 6212 剧情赠送任务卡
  36. // Err(ErrCode::err_method_obsoleted);
  37. // return self::PlotPresetTaskCard($req);
  38. // case CmdCode::cmd_taskCard_FinishAndReward: # 6213 任务卡完成,并即时结算
  39. // Err(ErrCode::err_method_obsoleted);
  40. // return self::ImmetRewardTaskCard($req);
  41. case CmdCode::cmd_taskCard_onKillMonster: # 6214 杀死怪物事件
  42. return self::OnKillMonsterEvent();
  43. case CmdCode::cmd_taskCard_active: # 6215 激活任务卡
  44. return self::OnTaskCard_active();
  45. case CmdCode::cmd_taskCard_reward: # 6216 领取任务卡奖励
  46. return self::OnTaskCard_reward();
  47. case CmdCode::cmd_taskCard_info: # 6217 任务卡 - 更新信息
  48. return self::OnTaskCard_GetInfo();
  49. case CmdCode::cmd_taskCard_StepActionDone: # 6218 任务步骤 - start/finish action done
  50. return self::OnTaskCard_StepActionDone();
  51. case CmdCode::cmd_Task_setTracingCard: # 6219 设置当前追踪的任务卡
  52. return TaskProc::SetTracingCard();
  53. case CmdCode::cmd_task_StepFallBack: # 6220 任务步骤回撤重置
  54. return TaskProc::OnTaskStep_FallBack();
  55. // -------------- 任务卡商城 -----------------------------
  56. case CmdCode::cmd_taskcard_shop_open: # 6231 任务卡商店 - 开启
  57. return self::OnTaskCardShopOpen();
  58. case CmdCode::cmd_taskcard_shop_buy: # 6232 任务卡商店 - 购买
  59. return self::OnTaskCardShopBuy();
  60. case CmdCode::cmd_taskcard_shop_refresh: # 6233 任务卡商店 - 手动刷新
  61. return self::OnTaskCardShopRefresh();
  62. default:
  63. return Err(ErrCode::cmd_err);
  64. }
  65. }
  66. // <editor-fold defaultstate="collapsed" desc=" 任务卡商店">
  67. /**
  68. * [6231] 任务卡商店 - 开启
  69. */
  70. static function OnTaskCardShopOpen() {
  71. $userInfo = ctx();
  72. if (null == $userInfo->taskCardShop) { # 防御
  73. $userInfo->taskCardShop = new Info_TaskCard_Shop();
  74. }
  75. if (null == $userInfo->taskCardShop->curCards || count($userInfo->taskCardShop->curCards) < 1) {
  76. $arr = (array) GameConfig::taskcard_shop(); # 奖池配置
  77. $arr = self::FilterPrizepool($arr); # 利用玩家等级进行过滤
  78. $reward = ArrayInit();
  79. $err = self::Dice($arr, self::TaskCardShop_Refresh_ItemNum, $reward); # 获得随机结果
  80. my_Assert(ErrCode::ok == $err, $err);
  81. $userInfo->taskCardShop->curCards = $reward; # 更新任务卡列表
  82. $userInfo->taskCardShop->selled = array();
  83. ctx($userInfo);
  84. UserProc::updateUserInfo(); # 回写玩家数据
  85. }
  86. return Resp::ok(array('taskCardShop' => $userInfo->taskCardShop)); # 返回最新任务卡列表
  87. }
  88. /**
  89. * [6232] 任务卡商店 - 购买
  90. */
  91. static function OnTaskCardShopBuy() {
  92. list($typeId, $num) = req()->paras; # 提取参数: 任务卡类型ID,数量(暂时默认为1)
  93. $shopItemMo = GameConfig::taskcard_shop_getItem($typeId);
  94. my_Assert(null != $shopItemMo, ErrCode::err_const_no); # 常量异常
  95. my_Assert($num == 1, ErrCode::paras_err); # 数量异常
  96. $userInfo = ctx();
  97. $userInfo->taskCardShop = new Info_TaskCard_Shop($userInfo->taskCardShop);
  98. my_Assert(!in_array($typeId, $userInfo->taskCardShop->selled), ErrCode::taskCard_selled);
  99. switch ($shopItemMo->pricetype) {
  100. case 0: # 人民币
  101. Err(ErrCode::err_method_notimplement);
  102. // my_Assert(Data_UserGame::Consume_Cash($userInfo->baseInfo, $shopItemMo->price), ErrCode::notenough_cash_msg); # 扣除费用
  103. break;
  104. case 1: # 钻石
  105. my_Assert($userInfo->base()->Consume_Cash($shopItemMo->price), ErrCode::notenough_cash_msg); # 扣除费用
  106. break;
  107. case 2: # 金币
  108. my_Assert($userInfo->base()->Consume_Gold($shopItemMo->price), ErrCode::notenough_gold_msg); # 扣除费用
  109. break;
  110. default: # 其它
  111. Err(ErrCode::pay_m_type_err); # 定价类型异常
  112. break;
  113. }
  114. // $cid = StoreProc::PutTaskCardInStore($typeId); # 添加任务卡到背包
  115. StoreProc::PutOverlyingItemInStore($typeId, $num); # 直接进包裹items
  116. StatisticsProc::TargetStatistics(Enum_TargetStatistics::shopTaskId_BuyUserNum, $typeId);
  117. $userInfo->taskCardShop->selled[] = $typeId; # 添加售罄记录
  118. UserProc::updateUserInfo();
  119. self::OnBuyTaskCard($num); # 监控购买任务卡的任务卡[・_・?]
  120. return Resp::ok(array(
  121. 'gold' => ctx()->baseInfo->gold,
  122. 'cash' => ctx()->baseInfo->cash,
  123. 'store' => ctx()->store)); # 返回成功
  124. }
  125. /**
  126. * [6233] 任务卡商店 - 手动刷新
  127. */
  128. public static function OnTaskCardShopRefresh() {
  129. $cost = GameConfig::globalsettings()->TaskCardShop_Refresh_Cash; # 消耗
  130. $userInfo = ctx();
  131. // var_dump(Data_UserGame::Consume_Cash($userInfo->baseInfo, $cost));
  132. my_Assert($userInfo->base()->Consume_Cash($cost), ErrCode::notenough_cash_msg); # 扣除费用
  133. // 刷新任务卡
  134. $arr = (array) GameConfig::taskcard_shop(); # 奖池配置
  135. $arr = self::FilterPrizepool($arr); # 利用玩家等级进行过滤
  136. $reward = ArrayInit();
  137. $err = self::Dice($arr, self::TaskCardShop_Refresh_ItemNum, $reward); # 获得随机结果
  138. my_Assert(ErrCode::ok == $err, $err);
  139. // if (null == $userInfo->taskCardShop) { # 防御
  140. $userInfo->taskCardShop = new Info_TaskCard_Shop($userInfo->taskCardShop);
  141. // }
  142. $userInfo->taskCardShop->curCards = $reward; # 更新任务卡列表
  143. $userInfo->taskCardShop->selled = array();
  144. ctx($userInfo);
  145. UserProc::updateUserInfo(); # 回写玩家数据
  146. return Resp::ok(array(
  147. 'gold' => ctx()->baseInfo->gold,
  148. 'cash' => ctx()->baseInfo->cash,
  149. 'taskCardShop' => $userInfo->taskCardShop)); # 返回最新任务卡列表
  150. }
  151. /**
  152. * 过滤奖池
  153. * @param array $arr 奖池
  154. */
  155. static function FilterPrizepool($arr) {
  156. $ret = array_filter($arr, function ($value) {
  157. return(ctx()->baseInfo->level >= $value->unlock_level); # 等级限制
  158. });
  159. return $ret;
  160. }
  161. /**
  162. * 投骰子
  163. * @param assoc_array $arr 抽奖物品概率
  164. * @param int $number 连抽次数
  165. * @return array[] itemids
  166. */
  167. static function Dice($arr, $number, &$reward) {
  168. $max = 0; # 计算物品权重总和
  169. array_walk($arr, function ($value) use (&$max) {
  170. $max += $value->probability;
  171. });
  172. my_Assert($max > 0, ErrCode::err_const_no); # 配置数据有问题
  173. $reward = ArrayInit();
  174. for ($i = 0; $i < $number;) {
  175. $rnd = CommUtil::random(1, $max); # 投骰子
  176. $start = 0;
  177. $rew = null;
  178. foreach ($arr as $item) { # 循环判断落入那个物品上
  179. if ($start < $rnd && $rnd <= $start + $item->probability) { # 落入区间
  180. $rew = $item; # 记录物品
  181. break;
  182. }
  183. $start += $item->probability; # 继续判断是否落入下一物品的区间
  184. } # foreach end
  185. if (!$rew) {
  186. return ErrCode::lottery_noselecteditem;
  187. }
  188. if (!in_array($rew->typeId, $reward)) { # 去除重复卡
  189. $reward[] = $rew->typeId;
  190. $i++;
  191. }
  192. } # for end
  193. return ErrCode::ok;
  194. }
  195. //
  196. // </editor-fold>
  197. //
  198. // <editor-fold defaultstate="collapsed" desc=" 任务卡接口">
  199. //
  200. /**
  201. * [6210]剧情对话-触发任务卡结束条件检测(中间某个step结束,进入下一个step)
  202. */
  203. static function PlotFinish() {
  204. list($gate_or_npc_id, $stage) = req()->paras;
  205. $bUpdate = self::OnPlotOver($gate_or_npc_id, $stage); # 触发一下任务检查,更新任务状态
  206. $arr = GameConfig::plot_getItem($gate_or_npc_id, $stage); # 查找对应的剧情
  207. my_Assert(isset($arr), ErrCode::err_const_no); # 常量存在
  208. foreach ($arr as $plot) {
  209. isEditor() and $plot = new \sm_plot();
  210. if (!empty($plot->presentItem)) {
  211. if (strtolower($plot->presentItem) == strtolower("unlockBuild")) { # 特殊处理, 剧情中解锁建筑
  212. ctx()->privateState->unlockedBuild[] = $plot->presentEffect; # 添加解锁记录
  213. if ($plot->presentEffect == 1000) {
  214. $college = new Info_College();
  215. $college->setFunUnluckTs();
  216. }
  217. StatisticsProc::TargetStatistics(Enum_TargetStatistics::unlockbuidId, $plot->presentEffect);
  218. NormalEventProc::OnUnlockBuild($plot->presentEffect); # 插入解锁事件
  219. } else if (strtolower($plot->presentItem) == strtolower("rename")) {# 改名
  220. // 跳过特殊字符串
  221. } else if (strtolower($plot->presentItem) == strtolower("zhaohuanyanling")) {
  222. // 跳过特殊指令
  223. } else { # 普通奖励
  224. StoreProc::AddMultiItemInStore($plot->presentItem);
  225. }
  226. }
  227. if (!empty($plot->recycleItem)) {
  228. $val = explode(",", $plot->recycleItem);
  229. my_Assert(count($val) > 1, "解析回收道具字符串出错");
  230. StoreProc::removeItemFromStore(ctx()->store, $val[0], $val[1]);
  231. }
  232. }
  233. UserProc::updateUserInfo();
  234. return Resp::ok(array('store' => ctx()->store,
  235. 'taskCardUpdate' => $bUpdate));
  236. }
  237. // <editor-fold defaultstate="collapsed" desc="废弃">
  238. // /**
  239. // * [6211] 任务卡-剧情结束兑换奖励(销毁当前卡,换取新的任务卡)
  240. // * @deprecated since version 2020.12.12
  241. // * @param type $req
  242. // */
  243. // static function PlotExchangeTaskCard($req) {
  244. // Err(ErrCode::err_method_notimplement);
  245. // }
  246. //
  247. //
  248. // /**
  249. // * [6212] 任务卡- 剧情对话奖励任务卡
  250. // * @deprecated since version 2020.12.12
  251. // * @param req $req
  252. // */
  253. // static function PlotPresetTaskCard($req) {
  254. // // 发放任务卡
  255. // list($rwdStr) = $req->paras;
  256. // $err = StoreProc::AddMultiItemInStore($req, $rwdStr);
  257. // my_Assert(ErrCode::ok == $err, $err);
  258. // UserProc::updateUserInfo();
  259. // return Resp::ok(array('store' => $req->userInfo->game->store));
  260. // }
  261. //
  262. // /**
  263. // * [6213]任务卡 - 即时奖励型任务卡
  264. // * @deprecated since version 2020.12.12
  265. // * @param req $req
  266. // */
  267. // static function ImmetRewardTaskCard($req) {
  268. // // 销毁任务卡, 发放奖励
  269. // list($taskCardUID) = $req->paras;
  270. // my_Assert(StlUtil::dictHasProperty($req->userInfo->game->store->taskcards, $taskCardUID), ErrCode::taskCard_no); # 防御
  271. // $taskCard = new Ins_TaskCard($req->userInfo->game->store->taskcards->$taskCardUID); # 任务卡对象
  272. // if (strlen($taskCard->mo()->reward) > 0) { # 防御奖励串为空
  273. // StoreProc::AddMultiItemInStore($req, $taskCard->mo()->reward); # 发放奖励
  274. // }
  275. // if (strlen($taskCard->mo()->newTaskCard) > 0) { # 防御新卡串为空
  276. // StoreProc::AddMultiItemInStore($req, $taskCard->mo()->newTaskCard); # 发放新任务卡
  277. // }
  278. // StlUtil::dictRemove($req->userInfo->game->store->taskcards, $taskCardUID); # 移除任务卡
  279. // UserProc::updateUserInfo(); # 回存玩家数据
  280. // return Resp::ok(array('store' => $req->userInfo->game->store, 'taskCardUpdate' => true)); # 返回值更新背包
  281. // }
  282. // </editor-fold>
  283. /**
  284. * [6214] 任务卡 - 杀死怪物事件
  285. */
  286. static function OnKillMonsterEvent() {
  287. // 触发一下任务检查
  288. list($monsterID, $num) = req()->paras;
  289. $bUpdate = self::OnKillMonster($monsterID, $num);
  290. return Resp::ok(array('store' => ctx()->store,
  291. 'taskCardUpdate' => $bUpdate));
  292. }
  293. /**
  294. * [6215] 任务卡 - 激活任务卡
  295. */
  296. static function OnTaskCard_active() {
  297. list($taskCardUID) = req()->paras; # 提取参数: 任务卡实例id
  298. $store = ctx()->store; # 快速访问store
  299. my_Assert(StlUtil::dictHasProperty($store->taskcards, $taskCardUID), ErrCode::taskCard_no); # 防御找不到实例
  300. $taskCard = new Ins_TaskCard($store->taskcards->$taskCardUID); # 任务卡对象
  301. my_Assert($taskCard->state <= Enum_TaskCardStateType::notopen, ErrCode::taskCard_state); # 任务卡状态异常
  302. my_Assert(true != self::FindSameIngCard($taskCard->typeId), ErrCode::taskCard_active_multi); # 不可激活多张任务卡
  303. my_Assert(self::FindIngCardCount() <= self::TaskCard_ActiveMax, ErrCode::taskCard_active_max); # 激活数量上限
  304. $taskCard->state = Enum_TaskCardStateType::ing;
  305. NormalEventProc::OnTaskCard_Actived($taskCardUID, null); # 带入事件
  306. foreach ($taskCard->curSteps as &$tsp) { # 初期里面只有一个任务
  307. $tsp = new Ins_TaskStep($tsp);
  308. if ($tsp->isStatusType()) { # 如果是道具收集类的, 扣除所收集道具
  309. $tsp->autoCalcStatusCur();
  310. }
  311. // $tsp->doStartAct();
  312. }
  313. if ($taskCard->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
  314. $taskCard->state = Enum_TaskCardStateType::finish;
  315. NormalEventProc::OnTaskCard_Finish($taskCard->uid, null); # 广播卡完成事件
  316. }
  317. $store->taskcards->$taskCardUID = $taskCard;
  318. self::autoRecoverTaskTracingState(); # 更新任务追踪.
  319. UserProc::updateUserInfo(); # 回存玩家数据
  320. return Resp::ok(array(
  321. 'priv' => ctx()->privateState,
  322. 'store' => ctx()->store
  323. )); # 返回值更新背包
  324. }
  325. static function FindSameIngCard($typeId) {
  326. $cardDic = ctx()->store->taskcards;
  327. $find = false;
  328. array_walk($cardDic, function ($inst) use ($typeId, &$find) {
  329. // $inst = new Ins_TaskCard($inst);
  330. if ($inst->state == Enum_TaskCardStateType::ing && $inst->typeId == $typeId) {
  331. $find = true;
  332. }
  333. });
  334. return $find;
  335. }
  336. static function FindIngCardCount() {
  337. $cardDic = ctx()->store->taskcards;
  338. $num = 0;
  339. array_walk($cardDic, function ($inst) use (&$num) {
  340. // $inst = new Ins_TaskCard($inst);
  341. if ($inst->state == Enum_TaskCardStateType::ing #
  342. && GameConfig::item_taskcard_getItem($inst->typeId)->type != 3) {
  343. $num++;
  344. }
  345. });
  346. return $num;
  347. }
  348. /**
  349. * [6216] 任务卡 - 领取任务卡奖励
  350. */
  351. static function OnTaskCard_reward() {
  352. // 销毁任务卡, 发放奖励
  353. list($taskCardUID) = req()->paras;
  354. $store = ctx()->store(); # 快速访问store
  355. my_Assert(StlUtil::dictHasProperty($store->taskcards, $taskCardUID), ErrCode::taskCard_no); # 防御找不到实例
  356. $taskCard = new Ins_TaskCard($store->taskcards->$taskCardUID); # 任务卡对象
  357. my_Assert($taskCard->IsFinish(), ErrCode::task_progress_not_complete); # 任务卡尚未完成
  358. my_Assert($taskCard->state < 4, ErrCode::task_reward_geted); # 奖励已经领取过了
  359. foreach ($taskCard->curSteps as &$tsp) { # 初期里面只有一个任务
  360. $tsp = new Ins_TaskStep($tsp);
  361. if ($tsp->mo()->cmd == Enum_TaskCmdType::GainItem) { # 如果是道具收集类的, 扣除所收集道具
  362. $ok = StoreProc::removeItemFromStore($store, $tsp->mo()->paras, $tsp->mo()->num);
  363. my_Assert(ErrCode::ok == $ok, ErrCode::taskCard_gainItem_no);
  364. }
  365. }
  366. if (strlen($taskCard->mo()->reward) > 0) { # 防御奖励串为空
  367. StoreProc::AddMultiItemInStore($taskCard->mo()->reward); # 发放奖励
  368. }
  369. if ($taskCard->mo()->exp > 0) { # 任务卡增加了指挥官经验
  370. ctx()->base()->Add_Exp($taskCard->mo()->exp); # 加指挥官经验
  371. }
  372. $taskCard->state = Enum_TaskCardStateType::drawed;
  373. //2021-3-4
  374. $college = ctx()->college();
  375. $college->modifyTaskCardState($taskCard->typeId, Enum_TaskCardStateType::drawed);
  376. ctx()->college = $college;
  377. $store->taskcards->$taskCardUID = $taskCard; # 回写任务数据
  378. self::checkHandOverDailyTask(); #检测每次任务中的交付任务是否需要挂载了
  379. NormalEventProc::OnTaskCard_Reward($taskCard->mo()->reward, null); # 带入事件
  380. self::OnFinishTaskCard($taskCard); # 触发检查任务卡的任务卡[・_・?]
  381. if (!empty($taskCard->mo()->newTaskCard)) { # 下一个任务卡存在
  382. StoreProc::PutTaskCardInStore($taskCard->mo()->newTaskCard); # 放卡入背包
  383. }
  384. if ($taskCard->mo()->type == 2) {
  385. // 日常任务卡,不移除
  386. } else {
  387. StlUtil::dictRemove($store->taskcards, $taskCardUID); # 移除任务卡
  388. }
  389. self::autoRecoverStateMissions(); # 重新更新其它状态类的任务卡
  390. self::autoRecoverTaskTracingState(); # 更新任务追踪.
  391. StatisticsProc::SelfTaskDataCollect($taskCard->typeId); #统计自己的任务完成情况
  392. StatisticsProc::TaskDataCollect($taskCard->typeId); #统计最新任务
  393. if ($taskCard->mo()->type == 1) {//主线
  394. StatisticsProc::TargetStatistics(Enum_TargetStatistics::mainTaskId_ComUserNum, $taskCard->typeId);
  395. }
  396. if ($taskCard->mo()->type == 4) {//悬赏
  397. StatisticsProc::TargetStatistics(Enum_TargetStatistics::shopTaskId_ComUserNum, $taskCard->typeId);
  398. }
  399. if ($taskCard->mo()->type == 2) {//日常
  400. StatisticsProc::TargetStatistics(Enum_TargetStatistics::dailyTaskId_ComUserNum, $taskCard->typeId);
  401. }
  402. if ($taskCard->mo()->type == 3) {//圣哲
  403. StatisticsProc::TargetStatistics(Enum_TargetStatistics::collegeTaskId_ComUserNum, $taskCard->typeId);
  404. }
  405. ctx()->college->addScore($taskCard->mo()->score); #圣哲学院的任务是有积分累计的
  406. UserProc::updateUserInfo(); # 回存玩家数据
  407. return Resp::ok(array(
  408. 'gold' => ctx()->baseInfo->gold,
  409. 'cash' => ctx()->baseInfo->cash,
  410. 'lvl' => ctx()->baseInfo->level,
  411. 'store' => ctx()->store,
  412. 'priv' => ctx()->privateState,
  413. 'college' => ctx()->college,)); # 返回值更新背包
  414. }
  415. static function checkHandOverDailyTask() {
  416. if (ctx()->store->dailyTask_HandOver > 0) {
  417. return;
  418. }
  419. $taskcards = ctx()->store->taskcards;
  420. $list = explode(',', glc()->dailyTask_HandOver);
  421. // if(in_array($taskcards->$taskCardUID->typeId, $list)){
  422. // ctx()->store->dailyTask_HandOver = 1;
  423. // return;
  424. // }
  425. $num = 0;
  426. $handOverTask = 0;
  427. foreach ($taskcards as $uid => $task) {
  428. $mo = GameConfig::item_taskcard_getItem($task->typeId);
  429. if ($mo->type == 2) {
  430. if (in_array($task->typeId, $list)) {
  431. $handOverTask = 1;
  432. }
  433. if ($task->state == 4) {
  434. $num += 1;
  435. }
  436. }
  437. }
  438. if ($num >= 4 && $handOverTask == 0) {//每日任务全部完成,挂载每日任务--交付任务
  439. $count = count($list);
  440. $rand = rand(0, $count - 1);
  441. StoreProc::PutTaskCardInStore($list[$rand]);
  442. }
  443. }
  444. /**
  445. * [6217] 任务卡 - 更新信息
  446. */
  447. static function OnTaskCard_GetInfo() {
  448. return Resp::ok(array('store' => ctx()->store)); # 返回值更新背包
  449. }
  450. /**
  451. * [6218] 任务步骤 - start/finish Action done
  452. */
  453. static function OnTaskCard_StepActionDone() {
  454. list($taskCardUID, $stepTypeId, $actType) = req()->paras; # 参数提取,卡uid,步骤类型id,actType: 1:start,2:finish.
  455. $store = ctx()->store; # 快速访问store
  456. my_Assert(StlUtil::dictHasProperty($store->taskcards, $taskCardUID), ErrCode::taskCard_no); # 防御找不到实例
  457. $taskCard = new Ins_TaskCard($store->taskcards->$taskCardUID); # 任务卡对象
  458. foreach ($taskCard->curSteps as &$tsp) { # 初期里面只有一个任务
  459. $tsp = new Ins_TaskStep($tsp);
  460. if ($tsp->typeId == $stepTypeId) { # 找到指定步骤
  461. if ($actType == 1) {
  462. $tsp->doStartAct();
  463. } else if ($actType == 2) {
  464. $tsp->doFinishAct();
  465. }
  466. }
  467. }
  468. $store->taskcards->$taskCardUID = $taskCard;
  469. UserProc::updateUserInfo();
  470. return Resp::ok(array('store' => ctx()->store)); # 返回值更新背包
  471. }
  472. /**
  473. * [6219] 设置当前追踪的任务卡
  474. */
  475. static function SetTracingCard() {
  476. // (探索任务暂不开发)
  477. $pri = ctx()->privateData(); # 私有数据
  478. // 设置追踪
  479. list($cardType, $cardUID) = req()->paras; # 参数: 任务标签类型(1:主线;2:日程;3:圣哲;4:商店), 任务卡id.
  480. my_default_Obj($pri->taskCardTracing); # 确保 tracing数据结构是否完整.
  481. $pri->taskCardTracing->$cardType = $cardUID; # 更新tracing数据.
  482. UserProc::updateUserInfo(); # 回存
  483. return Resp::ok($pri->taskCardTracing); # 返回成功
  484. }
  485. /**
  486. * [6220] 任务步骤 - 回撤
  487. */
  488. static function OnTaskStep_FallBack() {
  489. // 遍历检查是否有任务步骤需要回撤
  490. $taskCards = ctx()->store->taskcards; # 快速访问store
  491. foreach ($taskCards as $uid => &$card) { # 加了&符号,理论上就能直接修改原始元素
  492. $card = new Ins_TaskCard($card); # 任务卡对象
  493. $fallbackID = 0;
  494. $stepArr = array();
  495. foreach ($card->curSteps as &$tsp) { # 初期里面只有一个任务
  496. $tsp = new Ins_TaskStep($tsp);
  497. if (!$tsp->isFinish() && $tsp->mo()->fallback > 0) { # 找到需要回撤的步骤,删除此步骤
  498. $fallbackID = $tsp->mo()->fallback;
  499. } else {
  500. $stepArr[] = $tsp;
  501. }
  502. }
  503. foreach ($stepArr as &$tsp) { # 回撤上一步的进度
  504. if ($tsp->typeId == $fallbackID) {
  505. $tsp->cur = 0;
  506. NormalEventProc::OnTaskCardStep_Process($card->uid, $tsp->typeId); # 任务进度更新
  507. }
  508. }
  509. $card->curSteps = $stepArr; # 更新任务步骤集合
  510. }
  511. ctx()->store->taskcards = $taskCards; # 更新任务卡
  512. UserProc::updateUserInfo();
  513. return Resp::ok();
  514. }
  515. //
  516. // </editor-fold>
  517. // <editor-fold defaultstate="collapsed" desc=" 任务接口 ">
  518. /**
  519. * [6204] 领取日常任务活跃度阶段奖励
  520. */
  521. static function getActiveReward() {
  522. list($num) = req()->paras; # 提取参数: 领奖的阶段
  523. $userTask = ctx()->task;
  524. $rewardCfg = GameConfig::task_active_reward_getItem($num); # 查找奖励配置
  525. my_Assert(null != $rewardCfg, ErrCode::err_const_no); # 防御: 常量丢失
  526. my_Assert(!in_array($num, $userTask->dailyActiveGetedRewardArr), ErrCode::task_reward_geted); # 判断尚未领取
  527. my_Assert($userTask->dailyActivePoint >= $num, ErrCode::task_activePoint_notenough); # 判断活跃点数足够
  528. $ok = StoreProc::AddMultiItemInStore($rewardCfg->reward); # 按照配置发放奖励
  529. my_Assert($ok == ErrCode::ok, $ok); # 发放成功
  530. $userTask->dailyActiveGetedRewardArr[] = $num; # 添加领取记录
  531. UserProc::updateUserInfo(); # 回存数据
  532. return Resp::ok(array(// # 返回
  533. "gold" => ctx()->baseInfo->gold,
  534. "cash" => ctx()->baseInfo->cash,
  535. "tili" => ctx()->baseInfo->tili,
  536. "store" => ctx()->store,
  537. "task" => ctx()->task
  538. ));
  539. }
  540. /**
  541. * [6203] 设置关注任务
  542. * @deprecated since version 0 废弃,替换为6219.(2021.9.26)
  543. */
  544. static function setAttentionTask() {
  545. // list($taskId) = req()->paras;
  546. // $userTask = ctx()->task;
  547. //
  548. // my_Assert(StlUtil::dictHasProperty($userTask->taskListPlot, $taskId), ErrCode::task_no); # 任务存在
  549. // $taskItem = new Ins_TaskInfo($userTask->taskListPlot->$taskId);
  550. // my_Assert($taskItem->rewardGeted < 1, ErrCode::task_reward_geted); # 任务奖励尚未领取
  551. // $userTask->curTaskId = $taskId;
  552. //// var_dump($userTask);
  553. // UserProc::updateUserInfo();
  554. // return Resp::ok(array("task" => ctx()->task));
  555. }
  556. /**
  557. * [6202]领取任务奖励 问:每日任务奖励和剧情任务奖励领取接口是否为一个?
  558. * @deprecated since version 0 已经更换为领取任务卡奖励.
  559. */
  560. static function GetTaskReward() {
  561. // list($taskId) = req()->paras; # 提取参数: 任务id
  562. // $userTask = new Info_UserTask(ctx()->task);
  563. // $mask = 100000; # 根据id段来区分任务和每日任务.
  564. // $type = intval($taskId / $mask); # 取出taskId第一位判断任务类型
  565. // switch ($type) { #
  566. // case 4: # 剧情任务
  567. // my_Assert(StlUtil::dictHasProperty($userTask->taskListPlot, $taskId), ErrCode::task_no); #判断是否存在指定任务
  568. // $task = new Ins_TaskInfo($userTask->taskListPlot->$taskId);
  569. // my_Assert($task->progress >= 1, ErrCode::task_progress_not_complete); # 判断任务进度是否已完成>=1f
  570. // my_Assert($task->rewardGeted < 1, ErrCode::task_reward_geted); # 奖励不可重复领取
  571. // $taskCfg = GameConfig::task_getItem($taskId); # 任务配置数据
  572. // my_Assert($taskCfg != null, ErrCode::err_const_no);
  573. // $ok = StoreProc::AddMultiItemInStore($taskCfg->reward); # 发放任务奖励
  574. // my_Assert($ok == ErrCode::ok, $ok);
  575. // $task->rewardGeted = 1;
  576. // $userTask->taskListPlot->$taskId = $task;
  577. // if ($userTask->IsAllPlotTaskOver()) { # 检查当前节点任务是否已经全部清空
  578. // $userTask->curTaskNode += 1;
  579. // $userTask->taskListPlot = ObjectInit();
  580. // $userTask->initialize();
  581. // }
  582. // break;
  583. // case 5: # 每日任务
  584. // my_Assert(StlUtil::dictHasProperty($userTask->taskListDaily, $taskId), ErrCode::task_no);
  585. // $task = new Ins_TaskInfo($userTask->taskListDaily->$taskId);
  586. // my_Assert($task->progress >= 1, ErrCode::task_progress_not_complete); # 判断任务进度是否已完成>=1f
  587. // my_Assert($task->rewardGeted < 1, ErrCode::task_reward_geted); # 奖励不可重复领取
  588. // $taskCfg = GameConfig::task_daily_getItem($taskId); # 任务配置数据
  589. // my_Assert($taskCfg != null, ErrCode::err_const_no);
  590. //// Data_UserGame::Add_Exp(ctx()->baseInfo, $taskCfg->exp); # 发放任务奖励
  591. // ctx()->base()->Add_Exp($taskCfg->exp); # 发放指挥官经验
  592. // $userTask->dailyActivePoint += $taskCfg->activePoint;
  593. // $task->rewardGeted = 1;
  594. // $userTask->taskListDaily->$taskId = $task; # 回存下
  595. // break;
  596. // default:
  597. // break;
  598. // }
  599. //
  600. // ctx()->task = $userTask; # 回存
  601. // UserProc::updateUserInfo();
  602. // return Resp::ok(array(// # 返回
  603. // "gold" => ctx()->baseInfo->gold,
  604. // "cash" => ctx()->baseInfo->cash,
  605. // "tili" => ctx()->baseInfo->tili,
  606. // "store" => ctx()->store,
  607. // "task" => ctx()->task
  608. // ));
  609. }
  610. /**
  611. * [6201]更新任务状态
  612. */
  613. static function GetTaskInfo() {
  614. self::autoRecoverStateMissions(); # 重新更新其它状态类的任务卡
  615. return Resp::ok(array("task" => ctx()->task));
  616. }
  617. // </editor-fold>
  618. /**
  619. * 每天重置日常任务.
  620. */
  621. static function ResetDailyTaskCards() {
  622. // var_dump("重置日常任务卡");
  623. $store = ctx()->store(true);
  624. my_default_Obj($store->taskcards);
  625. $store->dailyTask_HandOver = 0;
  626. $dailyCards = new \stdClass();
  627. foreach (GameConfig::item_taskcard() as $id => $cardMo) {
  628. isEditor() and $cardMo = new \sm_item_taskcard();
  629. if ($cardMo->type == 2) { # 1:主线;2:日程;3:圣哲;4:商店
  630. $dailyCards->$id = $cardMo;
  631. }
  632. }
  633. $dailyCards = (array) $dailyCards;
  634. ksort($dailyCards);
  635. foreach ($dailyCards as $id => $cardMo) {
  636. foreach ($store->taskcards as $uid => $card) {
  637. $cardVo = new Ins_TaskCard($card);
  638. if ($cardVo->typeId == $id) { # 找到对应的实例.
  639. unset($store->taskcards->$uid); # 删除昨日未完成日常
  640. }
  641. }
  642. }
  643. ctx()->store = $store;
  644. $pri = ctx()->privateData(); # 私有数据
  645. $cardType = 2; # 日常任务,设置追踪
  646. my_default_Obj($pri->taskCardTracing); # 确保 tracing数据结构是否完整.
  647. $commonTaskList = explode(',', glc()->dailyTask_Common);
  648. if (count($commonTaskList) < 4) {
  649. // 再遍历一遍, 添加今日日常任务.
  650. rsort($commonTaskList);
  651. $cid = 0;
  652. foreach ($commonTaskList as $id) {
  653. $cid = StoreProc::PutTaskCardInStore($id); # 添加任务卡到背包
  654. }
  655. $pri->taskCardTracing->$cardType = $cid; # 更新tracing数据
  656. } else {
  657. $tempCid = 0;
  658. $count = count($commonTaskList);
  659. $temp = array();
  660. while (true) {
  661. $num = rand(0, $count - 1);
  662. if (in_array($num, $temp)) {
  663. continue;
  664. }
  665. $index = 0;
  666. foreach ($commonTaskList as $id) {
  667. if ($index >= $num) {
  668. $cid = StoreProc::PutTaskCardInStore($id); # 添加任务卡到背包
  669. if ($tempCid == 0) {
  670. $tempCid = $cid;
  671. }
  672. break;
  673. }
  674. $index += 1;
  675. }
  676. $temp[] = $num;
  677. if (count($temp) >= 4) {
  678. break;
  679. }
  680. }
  681. $pri->taskCardTracing->$cardType = $tempCid; # 更新tracing数据
  682. }
  683. UserProc::updateUserInfo(); # 回存数据.(不管从哪里调用的, 更新肯定没错.)
  684. }
  685. /**
  686. * 重置每日任务
  687. * @deprecated since version 0 已废弃,换用任务卡接口. (2021.9.26)
  688. */
  689. static function ResetDailyTask() {
  690. return;
  691. // $userTask = new Info_UserTask(ctx()->task);
  692. // $userTask->resetDailyTask();
  693. // ctx()->task = $userTask;
  694. }
  695. //
  696. // <editor-fold defaultstate="collapsed" desc="辅助方法-比对判断">
  697. /**
  698. * 检查任务条件是否达成
  699. * @param Ins_TaskParams $taskParam Description
  700. * @deprecated since version 0 已废弃,换用taskcard.
  701. */
  702. static function CheckTaskConditions($taskParam) {
  703. return;
  704. //// var_dump($taskParam);
  705. // $bUpdate = false;
  706. // foreach (ctx()->task->taskListPlot as $tid => $task) {
  707. // $taskCfg = GameConfig::task_getItem($tid);
  708. // my_Assert($taskCfg != null, ErrCode::err_const_no); # 获取任务配置数据
  709. // if ($taskCfg->tasktype != $taskParam->taskType) { # 任务类型必须匹配
  710. // continue;
  711. // }
  712. // isEditor() and $task = new Ins_TaskInfo(-1);
  713. // if ($task->progress == 1) { # 已完成的不再更新处理
  714. // continue;
  715. // }
  716. // if (is_null($taskCfg->canshu1)) {
  717. // $task->progress = 1;
  718. // $bUpdate = true;
  719. // continue;
  720. // }
  721. //
  722. // if ($taskCfg->canshu1 == $taskParam->canshu1) {
  723. // $task->tag1 = $taskParam->canshu1;
  724. // if (null == $taskCfg->canshu2 || 0 == $taskCfg->canshu2) {
  725. // $task->progress = 1;
  726. // $task->tag2 = $taskParam->canshu2;
  727. // $bUpdate = true;
  728. // } else {
  729. // if (is_numeric($taskCfg->canshu2)) {
  730. // $task->tag2 = max($task->tag2, $taskParam->canshu2);
  731. // if ($taskCfg->canshu2 <= $taskParam->canshu2) {
  732. // $bUpdate = true;
  733. // $task->progress = 1;
  734. // }
  735. // } else {
  736. // $task->tag2 = $taskParam->canshu2;
  737. // if ($taskCfg->canshu2 == $taskParam->canshu2) {
  738. // $bUpdate = true;
  739. // $task->progress = 1;
  740. // }
  741. // }
  742. // }
  743. // }
  744. // }
  745. // if ($bUpdate) {
  746. // CornerSignEventProc::OnTask_Plot_new();
  747. // }
  748. }
  749. /**
  750. * 检查任务条件是否达成
  751. * @param Ins_TaskParams $taskParam Description
  752. * @deprecated since version 0 已废弃,换用taskcard
  753. */
  754. static function CheckDailyTaskConditions($taskParam) {
  755. return;
  756. // $bUpdate = false;
  757. // $daily = ctx()->task->taskListDaily;
  758. // foreach ($daily as $tid => &$task) {
  759. // $taskCfg = GameConfig::task_daily_getItem($tid);
  760. // my_Assert($taskCfg != null, ErrCode::err_const_no); # 获取任务配置数据
  761. // if ($taskCfg->tasktype != $taskParam->taskType) { # 任务类型必须匹配
  762. // continue;
  763. // }
  764. // $task = new Ins_TaskInfo($task);
  765. // if ($task->progress >= 1) { # 已完成的不再更新处理
  766. // continue;
  767. // }
  768. // $task->counter++; # 计数器
  769. // if (is_null($taskCfg->canshu1) || $taskCfg->canshu1 == 0) {
  770. // $task->progress = 1;
  771. // $bUpdate = true;
  772. // continue;
  773. // }
  774. // if ($taskCfg->canshu1 == $task->counter) {
  775. // $task->progress = 1;
  776. // $bUpdate = true;
  777. // continue;
  778. // }
  779. // }
  780. //
  781. // if ($bUpdate) {
  782. // CornerSignEventProc::OnTask_Daily_new();
  783. // }
  784. }
  785. // </editor-fold>
  786. //
  787. // <editor-fold defaultstate="collapsed" desc="处理各种任务检测事务">
  788. //
  789. /**
  790. * 神庙抽奖
  791. */
  792. static function OnTempleLottery() {
  793. // $taskParam = new Ins_TaskParams(Enum_TaskCmdType::TempleLottery);
  794. // self::CheckTaskConditions($taskParam);
  795. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::TempleLottery, Enum_PropelType::set, 1, array());
  796. self::CheckTaskCardConditions($taskEventArg);
  797. }
  798. /**
  799. * 例如当指挥官等级提升的时候需要检查是否有任务达成
  800. */
  801. static function OnUserLevelUp($newLvl) {
  802. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::CommanderLevelUpTo, $newLvl);
  803. self::CheckTaskConditions($taskParam);
  804. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::CommanderLevelUpTo, Enum_PropelType::set, $newLvl, array($newLvl));
  805. self::CheckTaskCardConditions($taskEventArg);
  806. }
  807. /**
  808. * 英雄升级
  809. * @param type $heroMoId
  810. * @param type $newLvl
  811. */
  812. static function OnHeroLevelUp($heroMoId, $newLvl) {
  813. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroLevelUpTo, $heroMoId, $newLvl);
  814. self::CheckTaskConditions($taskParam);
  815. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroLevelUpTo, Enum_PropelType::set, $newLvl, array($heroMoId));
  816. self::CheckTaskCardConditions($taskEventArg);
  817. }
  818. /**
  819. * 英雄升阶
  820. * @param type $heroMoId
  821. * @param type $newGrade
  822. */
  823. static function OnHeroGradeUp($heroMoId, $newGrade) {
  824. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroGradeUpTo, $heroMoId, $newGrade);
  825. self::CheckTaskConditions($taskParam);
  826. self::OnHeroImprove();
  827. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroGradeUpTo, Enum_PropelType::set, 1, array());
  828. self::CheckTaskCardConditions($taskEventArg);
  829. }
  830. /**
  831. * 英雄碎片数量达到指定值
  832. * @param type $heroMoId
  833. * @param type $num
  834. */
  835. static function OnHeroSegmengNum($heroMoId, $num) {
  836. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroSegmentNumberTo, $heroMoId, $num);
  837. self::CheckTaskConditions($taskParam);
  838. }
  839. /**
  840. * 英雄解锁技能
  841. * @param type $heroMoId
  842. * @param type $skillId
  843. */
  844. static function OnHeroUnlocSkill($heroMoId, $skillId) {
  845. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroSkillUnlock, $heroMoId, $skillId);
  846. self::CheckTaskConditions($taskParam);
  847. }
  848. /**
  849. * 英雄穿上武器
  850. * @param type $heroMoid
  851. * @param type $weaponMoId
  852. */
  853. static function OnHeroWearWeapon($heroMoid, $weaponMoId) {
  854. $weapMO = GameConfig::item_base_getItem($weaponMoId);
  855. my_Assert($weapMO, ErrCode::err_const_no);
  856. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroWearupWeapon_quality, Enum_PropelType::set, 1, array($heroMoid, $weapMO->quality));
  857. self::CheckTaskCardConditions($taskEventArg);
  858. }
  859. /**
  860. * 英雄装备言灵
  861. * @param type $heroMoid
  862. * @param type $weaponMoId
  863. */
  864. static function OnHeroWearYanling($heroMoid, $yanlingMoId) {
  865. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroWearupYanling, Enum_PropelType::set, 1, array($heroMoid, $yanlingMoId));
  866. self::CheckTaskCardConditions($taskEventArg); # 检查装备言灵任务
  867. $ylmo = GameConfig::item_base_getItem($yanlingMoId);
  868. my_Assert(null != $ylmo, ErrCode::err_const_no);
  869. $taskEventArg2 = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroWearUpXYanlingWithQualityN, Enum_PropelType::add, 1, array($ylmo->quality));
  870. self::CheckTaskCardConditions($taskEventArg2); # 检查装备x个n品质言灵任务
  871. }
  872. /**
  873. * 通关剧情关卡
  874. * @param type $gateId
  875. * @param type $difficulty
  876. */
  877. static function OnPassGateN($gateId, $difficulty) {
  878. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PassGateN, $gateId, $difficulty);
  879. self::CheckTaskConditions($taskParam);
  880. self::OnPassGate();
  881. // var_dump("通关剧情检测 $gateId $difficulty");
  882. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::PassGateN, Enum_PropelType::set, 1, array($gateId, $difficulty));
  883. self::CheckTaskCardConditions($taskEventArg);
  884. }
  885. /**
  886. * 通关材料副本第n层
  887. * @param type $gateId
  888. * @param type $level
  889. */
  890. static function OnPassMaterialCarbonN($gateId, $level) {
  891. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::PassMaterialCarbonN, Enum_PropelType::set, 1, array($gateId, $level));
  892. self::CheckTaskCardConditions($taskEventArg);
  893. }
  894. /**
  895. * 通关无尽塔副本关卡
  896. * @param type $gateId
  897. * @param type $difficulty 层数
  898. */
  899. static function OnPassEndlessCarboN($gateId, $difficulty) {
  900. // $taskParam = new Ins_TaskParams(Enum_TaskCmdType::passEndlessCarbonN, $gateId, $difficulty);
  901. // self::CheckTaskConditions($taskParam);
  902. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::passEndlessCarbonN, Enum_PropelType::set, 1, array($gateId, $difficulty));
  903. // var_dump($taskEventArg);
  904. self::CheckTaskCardConditions($taskEventArg);
  905. }
  906. /**
  907. * 完成一次boss战胜利
  908. * @param type $gateId
  909. */
  910. static function OnPassWorldBoss($gateId) {
  911. // $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PassWorldBoss, $gateId);
  912. // self::CheckTaskConditions($taskParam);
  913. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::PassWorldBoss, Enum_PropelType::set, 1, array($gateId));
  914. // var_dump($taskEventArg);
  915. self::CheckTaskCardConditions($taskEventArg);
  916. //
  917. $taskEventArgDaily = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyBossChallenge, Enum_PropelType::add, 1, array($gateId));
  918. // var_dump($taskEventArgDaily);
  919. self::CheckTaskCardConditions($taskEventArgDaily);
  920. }
  921. /**
  922. * 竞技场胜利场次
  923. * @param type $num
  924. */
  925. static function OnPvPWinN($num) {
  926. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PvPWinNumberTo, $num);
  927. self::CheckTaskConditions($taskParam);
  928. }
  929. /**
  930. * 竞技场积分
  931. * @param type $score
  932. */
  933. static function OnPvPScoreN($score) {
  934. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PvPScoreTo, $score);
  935. self::CheckTaskConditions($taskParam);
  936. }
  937. /**
  938. * 玩家总战力值
  939. * @param type $num
  940. */
  941. static function OnUserFightPowerN($num) {
  942. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::UserPowerTo, $num);
  943. self::CheckTaskConditions($taskParam);
  944. }
  945. /**
  946. * 玩家收集积分
  947. * @param type $num
  948. */
  949. static function OnUserCollectScoreN($num) {
  950. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::UserCollectScoreTo, $num);
  951. self::CheckTaskConditions($taskParam);
  952. }
  953. //
  954. // </editor-fold>
  955. //
  956. // <editor-fold defaultstate="collapsed" desc="每日任务条件检查">
  957. //
  958. // static function Upate
  959. /**
  960. * 每日登陆
  961. */
  962. static function OnUserLogin() {
  963. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyLogin);
  964. self::CheckDailyTaskConditions($taskParam);
  965. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyLogin, Enum_PropelType::set, 1, array());
  966. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  967. }
  968. /**
  969. * 每日:英雄强化(升级或升阶)n次
  970. */
  971. static function OnHeroImprove() {
  972. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyHeroImprove);
  973. self::CheckDailyTaskConditions($taskParam);
  974. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyHeroImprove, Enum_PropelType::inc, 1, array());
  975. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  976. }
  977. /**
  978. * 每日:剧情关卡,胜利n次
  979. */
  980. static function OnPassGate() {
  981. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyGatesWin);
  982. self::CheckDailyTaskConditions($taskParam);
  983. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyGatesWin, Enum_PropelType::inc, 1, array());
  984. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  985. }
  986. /**
  987. * 竞技场每日挑战,胜负均可
  988. */
  989. static function OnPvp() {
  990. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyPVP);
  991. self::CheckDailyTaskConditions($taskParam);
  992. self::CheckTaskCardConditions($taskParam);
  993. }
  994. /**
  995. * 每日挑战,胜负均可
  996. */
  997. static function OnRankChalenge() {
  998. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyRankChalenge);
  999. self::CheckDailyTaskConditions($taskParam);
  1000. self::CheckTaskCardConditions($taskParam);
  1001. }
  1002. /**
  1003. * 每日购买商品
  1004. */
  1005. static function OnShopping() {
  1006. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyShopping);
  1007. self::CheckDailyTaskConditions($taskParam);
  1008. self::CheckTaskCardConditions($taskParam);
  1009. }
  1010. //
  1011. // </editor-fold>
  1012. //
  1013. // <editor-fold defaultstate="collapsed" desc="处理任务卡条件检查">
  1014. //
  1015. /**
  1016. * 自动修正任务追踪信息
  1017. */
  1018. static function autoRecoverTaskTracingState() {
  1019. $tasks = ctx()->store->taskcards;
  1020. $pri = ctx()->privateData();
  1021. for ($tp = 1; $tp < 5; $tp++) {
  1022. if (StlUtil::dictHasProperty($pri->taskCardTracing, $tp)) {
  1023. $curId = $pri->taskCardTracing->$tp;
  1024. } else {
  1025. $curId = 0;
  1026. }
  1027. //$curId = my_null_default($pri->taskCardTracing->$tp, 0); # 当前追踪中的任务卡id
  1028. $needRefresh = false;
  1029. if ($curId > 0) { # 存在任务卡
  1030. if (CommUtil::isPropertyExists($tasks, $curId)) {
  1031. $curTask = new Ins_TaskCard($tasks->$curId);
  1032. if ($curTask->state >= 4) { # 任务卡已经被领取奖励, 尝试刷新
  1033. $needRefresh = true;
  1034. }
  1035. } else { # 任务卡已经被删除, 尝试刷新
  1036. $needRefresh = true;
  1037. }
  1038. } else { # 没有追踪目标, 尝试刷新
  1039. $needRefresh = true;
  1040. }
  1041. if ($needRefresh) {
  1042. $ok = false;
  1043. foreach ($tasks as $tid => &$task) {
  1044. $task = new Ins_TaskCard($task);
  1045. if ($task->mo()->type == $tp) {
  1046. if ($task->state >= 4) {
  1047. continue;
  1048. }
  1049. $pri->taskCardTracing->$tp = $tid;
  1050. $ok = true;
  1051. break;
  1052. }
  1053. }
  1054. if (!$ok) { # 没有找到合适的追踪对象
  1055. $pri->taskCardTracing->$tp = 0; # 删除所有追踪(剩余任务已经全部完成了)
  1056. }
  1057. ctx()->store->taskcards = $tasks;
  1058. ctx()->privateState = $pri;
  1059. }
  1060. }
  1061. }
  1062. /**
  1063. * 自动修复状态型任务
  1064. */
  1065. static function autoRecoverStateMissions() {
  1066. $tasks = ctx()->store->taskcards;
  1067. foreach ($tasks as $tid => &$task) {
  1068. $task = new Ins_TaskCard($task);
  1069. if ($task->state == Enum_TaskCardStateType::ing // # 进行中的或者已完成的
  1070. || $task->state == Enum_TaskCardStateType::finish) {
  1071. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  1072. $tsp = new Ins_TaskStep($tsp);
  1073. $tsp->autoCalcStatusCur();
  1074. }
  1075. if ($task->state == Enum_TaskCardStateType::finish) { # 检查是否任务卡的所有步骤都已完成
  1076. if (!$task->IsFinish()) {
  1077. $task->state = Enum_TaskCardStateType::ing; # 状态回退
  1078. }
  1079. }
  1080. }
  1081. }
  1082. Clog::info("更新状态统计类的任务卡!");
  1083. ctx()->store->taskcards = $tasks;
  1084. }
  1085. /**
  1086. * 检查任务卡条件是否达成
  1087. * @param Ins_TaskEventArgs $taskParam Description
  1088. */
  1089. static function CheckTaskCardConditions($taskParam) {
  1090. $bUpdate = false;
  1091. $tasks = ctx()->store->taskcards;
  1092. foreach ($tasks as $tid => &$task) {
  1093. $task = new Ins_TaskCard($task);
  1094. if ($task->state != Enum_TaskCardStateType::ing) {
  1095. continue;
  1096. }
  1097. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  1098. $tsp = new Ins_TaskStep($tsp);
  1099. if ($tsp->check_new($taskParam)) {
  1100. $bUpdate = true;
  1101. $tsp->propel($taskParam);
  1102. NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
  1103. if ($tsp->isFinish()) {
  1104. NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
  1105. // $tsp->doFinishAct();
  1106. }
  1107. }
  1108. }
  1109. if ($task->IsFinish()) { # 检查后添加后续任务
  1110. $arr = array();
  1111. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  1112. $tsp = new Ins_TaskStep($tsp);
  1113. if (strlen($tsp->mo()->next) > 0) { # 有后续任务
  1114. $arr = array_merge($arr, explode(',', $tsp->mo()->next)); # 累加下一个任务步骤
  1115. }
  1116. }
  1117. foreach ($arr as $stpid) { # 轮询添加后续任务
  1118. if ($stpid > 0) {
  1119. $task->AddStep($stpid); # 将后续任务追加到任务列表中
  1120. }
  1121. }
  1122. }
  1123. if ($task->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
  1124. $task->state = Enum_TaskCardStateType::finish;
  1125. NormalEventProc::OnTaskCard_Finish($task->uid, null); # 广播卡完成事件
  1126. }
  1127. }
  1128. if ($bUpdate) { # 带回数据到客户端
  1129. ctx()->store->taskcards = $tasks;
  1130. UserProc::updateUserInfo(); # 更新玩家数据
  1131. }
  1132. return $bUpdate;
  1133. }
  1134. static function OnKillMonster($monsterID, $num) {
  1135. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::KillMonster, Enum_PropelType::add, $num, array($monsterID));
  1136. return self::CheckTaskCardConditions($taskParam);
  1137. }
  1138. /**
  1139. * 获得道具
  1140. */
  1141. static function OnGainItem($itemId, $num) {
  1142. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::GainItem, Enum_PropelType::stat, $num, array($itemId));
  1143. self::CheckTaskCardConditions($taskParam);
  1144. }
  1145. /**
  1146. * 对话完成
  1147. * @param type $gate_or_npc_id
  1148. * @param type $stage
  1149. * @return type
  1150. */
  1151. static function OnPlotOver($gate_or_npc_id, $stage) {
  1152. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::PlotOver, Enum_PropelType::set, 1, array($gate_or_npc_id, "$stage"));
  1153. self::CheckTaskCardConditions($taskParam);
  1154. }
  1155. /**
  1156. * 购买n张任务卡(非特定)
  1157. * @param type $_num
  1158. * @return type
  1159. */
  1160. static function OnBuyTaskCard($_num = 1) {
  1161. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::BuyTaskCard_Num, Enum_PropelType::add, $_num, array());
  1162. self::CheckTaskCardConditions($taskParam);
  1163. }
  1164. /**
  1165. * 完成任务卡(不指定) 这是要造检查任务卡的任务卡[・_・?]
  1166. * @param Ins_TaskCard $taskCard
  1167. */
  1168. static function OnFinishTaskCard($taskCard) {
  1169. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishTaskCard_noID, Enum_PropelType::set, 1, array());
  1170. self::CheckTaskCardConditions($taskParam);
  1171. $cardBase = GameConfig::item_base_getItem($taskCard->mo()->typeId);
  1172. $taskParam2 = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishXCardWithQualityN, Enum_PropelType::add, 1, array($cardBase->quality));
  1173. self::CheckTaskCardConditions($taskParam2);
  1174. if ($taskCard->mo()->cardType == "言灵") {
  1175. $taskParam3 = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishXYanlingCardAboutQualityN, Enum_PropelType::add, 1, array($cardBase->quality));
  1176. self::CheckTaskCardConditions($taskParam3);
  1177. }
  1178. }
  1179. /**
  1180. * 领取系统邮件奖励
  1181. * @param type $mailId 指定邮件id
  1182. * @return type
  1183. */
  1184. static function OnDrawSysMail($mailId) {
  1185. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::DrawSysMail_ID, Enum_PropelType::set, 1, array($mailId));
  1186. self::CheckTaskCardConditions($taskParam);
  1187. }
  1188. /**
  1189. * 言灵升级
  1190. * @param type $yanlingType
  1191. * @param type $level
  1192. * @return type
  1193. */
  1194. static function OnYanlingLevelUp($yanlingType, $level) {
  1195. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::AnyYanlingLevelUp, Enum_PropelType::set, 1, array($yanlingType, $level));
  1196. self::CheckTaskCardConditions($taskParam);
  1197. }
  1198. /**
  1199. * 言灵升星(突破)
  1200. * @param type $newStar
  1201. */
  1202. static function OnYanlingStarUp($newStar) {
  1203. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::UpgradeXYanlingToNStar, Enum_PropelType::add, 1, array($newStar));
  1204. self::CheckTaskCardConditions($taskParam);
  1205. }
  1206. static function OnWeaponUpgrade() {
  1207. }
  1208. /**
  1209. * 武器突破
  1210. * @param type $newStar
  1211. */
  1212. static function OnWeaponStarUp($newStar) {
  1213. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::UpgradeXWeaponToNStar, Enum_PropelType::add, 1, array($newStar));
  1214. self::CheckTaskCardConditions($taskParam);
  1215. }
  1216. /**
  1217. * 领取任意一个学院课程下的任意一个任务(num:1,paras[])(学院界面)
  1218. */
  1219. static function OnGetSchoolTask() {
  1220. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::GetSchoolTask, Enum_PropelType::set, 1, array());
  1221. self::CheckTaskCardConditions($taskParam);
  1222. }
  1223. /**
  1224. * 完成任意一个学院课程下的任意一张任务卡(num:1,paras:[])(学院界面)
  1225. */
  1226. static function OnFinishSchoolTask() {
  1227. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishSchoolTask, Enum_PropelType::set, 1, array());
  1228. self::CheckTaskCardConditions($taskParam);
  1229. }
  1230. /**
  1231. * 完成指课程的全部任务(num:1,paras:[courseId])(学院界面)
  1232. * @param int $courseId 课程id
  1233. */
  1234. static function OnFinishAllSchoolTaskOfGrade($courseId) {
  1235. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishAllSchoolTaskOfGrade, Enum_PropelType::set, 1, array($courseId));
  1236. self::CheckTaskCardConditions($taskParam);
  1237. }
  1238. //
  1239. // </editor-fold>
  1240. //
  1241. }