TaskProc.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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($taskCardUID); #检测每次任务中的交付任务是否需要挂载了
  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($taskCardUID) {
  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. } else {
  433. $num += 1;
  434. }
  435. }
  436. }
  437. if($num==0 && $handOverTask == 0){//每日任务全部完成,挂载每日任务--交付任务
  438. $count = count($list);
  439. $rand = rand(0,$count-1);
  440. StoreProc::PutTaskCardInStore($list[$rand]);
  441. }
  442. }
  443. /**
  444. * [6217] 任务卡 - 更新信息
  445. */
  446. static function OnTaskCard_GetInfo() {
  447. return Resp::ok(array('store' => ctx()->store)); # 返回值更新背包
  448. }
  449. /**
  450. * [6218] 任务步骤 - start/finish Action done
  451. */
  452. static function OnTaskCard_StepActionDone() {
  453. list($taskCardUID, $stepTypeId, $actType) = req()->paras; # 参数提取,卡uid,步骤类型id,actType: 1:start,2:finish.
  454. $store = ctx()->store; # 快速访问store
  455. my_Assert(StlUtil::dictHasProperty($store->taskcards, $taskCardUID), ErrCode::taskCard_no); # 防御找不到实例
  456. $taskCard = new Ins_TaskCard($store->taskcards->$taskCardUID); # 任务卡对象
  457. foreach ($taskCard->curSteps as &$tsp) { # 初期里面只有一个任务
  458. $tsp = new Ins_TaskStep($tsp);
  459. if ($tsp->typeId == $stepTypeId) { # 找到指定步骤
  460. if ($actType == 1) {
  461. $tsp->doStartAct();
  462. } else if ($actType == 2) {
  463. $tsp->doFinishAct();
  464. }
  465. }
  466. }
  467. $store->taskcards->$taskCardUID = $taskCard;
  468. UserProc::updateUserInfo();
  469. return Resp::ok(array('store' => ctx()->store)); # 返回值更新背包
  470. }
  471. /**
  472. * [6219] 设置当前追踪的任务卡
  473. */
  474. static function SetTracingCard() {
  475. // (探索任务暂不开发)
  476. $pri = ctx()->privateData(); # 私有数据
  477. // 设置追踪
  478. list($cardType, $cardUID) = req()->paras; # 参数: 任务标签类型(1:主线;2:日程;3:圣哲;4:商店), 任务卡id.
  479. my_default_Obj($pri->taskCardTracing); # 确保 tracing数据结构是否完整.
  480. $pri->taskCardTracing->$cardType = $cardUID; # 更新tracing数据.
  481. UserProc::updateUserInfo(); # 回存
  482. return Resp::ok($pri->taskCardTracing); # 返回成功
  483. }
  484. /**
  485. * [6220] 任务步骤 - 回撤
  486. */
  487. static function OnTaskStep_FallBack() {
  488. // 遍历检查是否有任务步骤需要回撤
  489. $taskCards = ctx()->store->taskcards; # 快速访问store
  490. foreach ($taskCards as $uid => &$card) { # 加了&符号,理论上就能直接修改原始元素
  491. $card = new Ins_TaskCard($card); # 任务卡对象
  492. $fallbackID = 0;
  493. $stepArr = array();
  494. foreach ($card->curSteps as &$tsp) { # 初期里面只有一个任务
  495. $tsp = new Ins_TaskStep($tsp);
  496. if ($tsp->mo()->fallback > 0) { # 找到需要回撤的步骤,删除此步骤
  497. $fallbackID = $tsp->mo()->fallback;
  498. } else {
  499. $stepArr[] = $tsp;
  500. }
  501. }
  502. foreach ($stepArr as &$tsp) { # 回撤上一步的进度
  503. if ($tsp->typeId == $fallbackID) {
  504. $tsp->cur = 0;
  505. NormalEventProc::OnTaskCardStep_Process($card->uid, $tsp->typeId); # 任务进度更新
  506. }
  507. }
  508. $card->curSteps = $stepArr; # 更新任务步骤集合
  509. }
  510. ctx()->store->taskcards = $taskCards; # 更新任务卡
  511. UserProc::updateUserInfo();
  512. return Resp::ok();
  513. }
  514. //
  515. // </editor-fold>
  516. // <editor-fold defaultstate="collapsed" desc=" 任务接口 ">
  517. /**
  518. * [6204] 领取日常任务活跃度阶段奖励
  519. */
  520. static function getActiveReward() {
  521. list($num) = req()->paras; # 提取参数: 领奖的阶段
  522. $userTask = ctx()->task;
  523. $rewardCfg = GameConfig::task_active_reward_getItem($num); # 查找奖励配置
  524. my_Assert(null != $rewardCfg, ErrCode::err_const_no); # 防御: 常量丢失
  525. my_Assert(!in_array($num, $userTask->dailyActiveGetedRewardArr), ErrCode::task_reward_geted); # 判断尚未领取
  526. my_Assert($userTask->dailyActivePoint >= $num, ErrCode::task_activePoint_notenough); # 判断活跃点数足够
  527. $ok = StoreProc::AddMultiItemInStore($rewardCfg->reward); # 按照配置发放奖励
  528. my_Assert($ok == ErrCode::ok, $ok); # 发放成功
  529. $userTask->dailyActiveGetedRewardArr[] = $num; # 添加领取记录
  530. UserProc::updateUserInfo(); # 回存数据
  531. return Resp::ok(array(// # 返回
  532. "gold" => ctx()->baseInfo->gold,
  533. "cash" => ctx()->baseInfo->cash,
  534. "tili" => ctx()->baseInfo->tili,
  535. "store" => ctx()->store,
  536. "task" => ctx()->task
  537. ));
  538. }
  539. /**
  540. * [6203] 设置关注任务
  541. * @deprecated since version 0 废弃,替换为6219.(2021.9.26)
  542. */
  543. static function setAttentionTask() {
  544. // list($taskId) = req()->paras;
  545. // $userTask = ctx()->task;
  546. //
  547. // my_Assert(StlUtil::dictHasProperty($userTask->taskListPlot, $taskId), ErrCode::task_no); # 任务存在
  548. // $taskItem = new Ins_TaskInfo($userTask->taskListPlot->$taskId);
  549. // my_Assert($taskItem->rewardGeted < 1, ErrCode::task_reward_geted); # 任务奖励尚未领取
  550. // $userTask->curTaskId = $taskId;
  551. //// var_dump($userTask);
  552. // UserProc::updateUserInfo();
  553. // return Resp::ok(array("task" => ctx()->task));
  554. }
  555. /**
  556. * [6202]领取任务奖励 问:每日任务奖励和剧情任务奖励领取接口是否为一个?
  557. * @deprecated since version 0 已经更换为领取任务卡奖励.
  558. */
  559. static function GetTaskReward() {
  560. // list($taskId) = req()->paras; # 提取参数: 任务id
  561. // $userTask = new Info_UserTask(ctx()->task);
  562. // $mask = 100000; # 根据id段来区分任务和每日任务.
  563. // $type = intval($taskId / $mask); # 取出taskId第一位判断任务类型
  564. // switch ($type) { #
  565. // case 4: # 剧情任务
  566. // my_Assert(StlUtil::dictHasProperty($userTask->taskListPlot, $taskId), ErrCode::task_no); #判断是否存在指定任务
  567. // $task = new Ins_TaskInfo($userTask->taskListPlot->$taskId);
  568. // my_Assert($task->progress >= 1, ErrCode::task_progress_not_complete); # 判断任务进度是否已完成>=1f
  569. // my_Assert($task->rewardGeted < 1, ErrCode::task_reward_geted); # 奖励不可重复领取
  570. // $taskCfg = GameConfig::task_getItem($taskId); # 任务配置数据
  571. // my_Assert($taskCfg != null, ErrCode::err_const_no);
  572. // $ok = StoreProc::AddMultiItemInStore($taskCfg->reward); # 发放任务奖励
  573. // my_Assert($ok == ErrCode::ok, $ok);
  574. // $task->rewardGeted = 1;
  575. // $userTask->taskListPlot->$taskId = $task;
  576. // if ($userTask->IsAllPlotTaskOver()) { # 检查当前节点任务是否已经全部清空
  577. // $userTask->curTaskNode += 1;
  578. // $userTask->taskListPlot = ObjectInit();
  579. // $userTask->initialize();
  580. // }
  581. // break;
  582. // case 5: # 每日任务
  583. // my_Assert(StlUtil::dictHasProperty($userTask->taskListDaily, $taskId), ErrCode::task_no);
  584. // $task = new Ins_TaskInfo($userTask->taskListDaily->$taskId);
  585. // my_Assert($task->progress >= 1, ErrCode::task_progress_not_complete); # 判断任务进度是否已完成>=1f
  586. // my_Assert($task->rewardGeted < 1, ErrCode::task_reward_geted); # 奖励不可重复领取
  587. // $taskCfg = GameConfig::task_daily_getItem($taskId); # 任务配置数据
  588. // my_Assert($taskCfg != null, ErrCode::err_const_no);
  589. //// Data_UserGame::Add_Exp(ctx()->baseInfo, $taskCfg->exp); # 发放任务奖励
  590. // ctx()->base()->Add_Exp($taskCfg->exp); # 发放指挥官经验
  591. // $userTask->dailyActivePoint += $taskCfg->activePoint;
  592. // $task->rewardGeted = 1;
  593. // $userTask->taskListDaily->$taskId = $task; # 回存下
  594. // break;
  595. // default:
  596. // break;
  597. // }
  598. //
  599. // ctx()->task = $userTask; # 回存
  600. // UserProc::updateUserInfo();
  601. // return Resp::ok(array(// # 返回
  602. // "gold" => ctx()->baseInfo->gold,
  603. // "cash" => ctx()->baseInfo->cash,
  604. // "tili" => ctx()->baseInfo->tili,
  605. // "store" => ctx()->store,
  606. // "task" => ctx()->task
  607. // ));
  608. }
  609. /**
  610. * [6201]更新任务状态
  611. */
  612. static function GetTaskInfo() {
  613. self::autoRecoverStateMissions(); # 重新更新其它状态类的任务卡
  614. return Resp::ok(array("task" => ctx()->task));
  615. }
  616. // </editor-fold>
  617. /**
  618. * 每天重置日常任务.
  619. */
  620. static function ResetDailyTaskCards() {
  621. // var_dump("重置日常任务卡");
  622. $store = ctx()->store(true);
  623. my_default_Obj($store->taskcards);
  624. $store->dailyTask_HandOver = 0;
  625. $dailyCards = new \stdClass();
  626. foreach (GameConfig::item_taskcard() as $id => $cardMo) {
  627. isEditor() and $cardMo = new \sm_item_taskcard();
  628. if ($cardMo->type == 2) { # 1:主线;2:日程;3:圣哲;4:商店
  629. $dailyCards->$id = $cardMo;
  630. }
  631. }
  632. $dailyCards = (array) $dailyCards;
  633. ksort($dailyCards);
  634. foreach ($dailyCards as $id => $cardMo) {
  635. foreach ($store->taskcards as $uid => $card) {
  636. $cardVo = new Ins_TaskCard($card);
  637. if ($cardVo->typeId == $id) { # 找到对应的实例.
  638. unset($store->taskcards->$uid); # 删除昨日未完成日常
  639. }
  640. }
  641. }
  642. ctx()->store = $store;
  643. $pri = ctx()->privateData(); # 私有数据
  644. $cardType = 2; # 日常任务,设置追踪
  645. my_default_Obj($pri->taskCardTracing); # 确保 tracing数据结构是否完整.
  646. $commonTaskList = explode(',', glc()->dailyTask_Common);
  647. if (count($commonTaskList) < 4) {
  648. // 再遍历一遍, 添加今日日常任务.
  649. rsort($commonTaskList);
  650. $cid = 0;
  651. foreach ($commonTaskList as $id) {
  652. $cid = StoreProc::PutTaskCardInStore($id); # 添加任务卡到背包
  653. }
  654. $pri->taskCardTracing->$cardType = $cid; # 更新tracing数据
  655. } else {
  656. $tempCid = 0;
  657. $count = count($commonTaskList);
  658. $temp = array();
  659. while (true) {
  660. $num = rand(0,$count-1);
  661. if(in_array($num, $temp)){
  662. continue;
  663. }
  664. $index = 0;
  665. foreach ($commonTaskList as $id) {
  666. if($index >= $num){
  667. $cid = StoreProc::PutTaskCardInStore($id); # 添加任务卡到背包
  668. if($tempCid == 0){
  669. $tempCid = $cid;
  670. }
  671. break;
  672. }
  673. $index+=1;
  674. }
  675. $temp[] = $num;
  676. if(count($temp)>=4){
  677. break;
  678. }
  679. }
  680. $pri->taskCardTracing->$cardType = $tempCid; # 更新tracing数据
  681. }
  682. UserProc::updateUserInfo(); # 回存数据.(不管从哪里调用的, 更新肯定没错.)
  683. }
  684. /**
  685. * 重置每日任务
  686. * @deprecated since version 0 已废弃,换用任务卡接口. (2021.9.26)
  687. */
  688. static function ResetDailyTask() {
  689. return;
  690. // $userTask = new Info_UserTask(ctx()->task);
  691. // $userTask->resetDailyTask();
  692. // ctx()->task = $userTask;
  693. }
  694. //
  695. // <editor-fold defaultstate="collapsed" desc="辅助方法-比对判断">
  696. /**
  697. * 检查任务条件是否达成
  698. * @param Ins_TaskParams $taskParam Description
  699. * @deprecated since version 0 已废弃,换用taskcard.
  700. */
  701. static function CheckTaskConditions($taskParam) {
  702. return;
  703. //// var_dump($taskParam);
  704. // $bUpdate = false;
  705. // foreach (ctx()->task->taskListPlot as $tid => $task) {
  706. // $taskCfg = GameConfig::task_getItem($tid);
  707. // my_Assert($taskCfg != null, ErrCode::err_const_no); # 获取任务配置数据
  708. // if ($taskCfg->tasktype != $taskParam->taskType) { # 任务类型必须匹配
  709. // continue;
  710. // }
  711. // isEditor() and $task = new Ins_TaskInfo(-1);
  712. // if ($task->progress == 1) { # 已完成的不再更新处理
  713. // continue;
  714. // }
  715. // if (is_null($taskCfg->canshu1)) {
  716. // $task->progress = 1;
  717. // $bUpdate = true;
  718. // continue;
  719. // }
  720. //
  721. // if ($taskCfg->canshu1 == $taskParam->canshu1) {
  722. // $task->tag1 = $taskParam->canshu1;
  723. // if (null == $taskCfg->canshu2 || 0 == $taskCfg->canshu2) {
  724. // $task->progress = 1;
  725. // $task->tag2 = $taskParam->canshu2;
  726. // $bUpdate = true;
  727. // } else {
  728. // if (is_numeric($taskCfg->canshu2)) {
  729. // $task->tag2 = max($task->tag2, $taskParam->canshu2);
  730. // if ($taskCfg->canshu2 <= $taskParam->canshu2) {
  731. // $bUpdate = true;
  732. // $task->progress = 1;
  733. // }
  734. // } else {
  735. // $task->tag2 = $taskParam->canshu2;
  736. // if ($taskCfg->canshu2 == $taskParam->canshu2) {
  737. // $bUpdate = true;
  738. // $task->progress = 1;
  739. // }
  740. // }
  741. // }
  742. // }
  743. // }
  744. // if ($bUpdate) {
  745. // CornerSignEventProc::OnTask_Plot_new();
  746. // }
  747. }
  748. /**
  749. * 检查任务条件是否达成
  750. * @param Ins_TaskParams $taskParam Description
  751. * @deprecated since version 0 已废弃,换用taskcard
  752. */
  753. static function CheckDailyTaskConditions($taskParam) {
  754. return;
  755. // $bUpdate = false;
  756. // $daily = ctx()->task->taskListDaily;
  757. // foreach ($daily as $tid => &$task) {
  758. // $taskCfg = GameConfig::task_daily_getItem($tid);
  759. // my_Assert($taskCfg != null, ErrCode::err_const_no); # 获取任务配置数据
  760. // if ($taskCfg->tasktype != $taskParam->taskType) { # 任务类型必须匹配
  761. // continue;
  762. // }
  763. // $task = new Ins_TaskInfo($task);
  764. // if ($task->progress >= 1) { # 已完成的不再更新处理
  765. // continue;
  766. // }
  767. // $task->counter++; # 计数器
  768. // if (is_null($taskCfg->canshu1) || $taskCfg->canshu1 == 0) {
  769. // $task->progress = 1;
  770. // $bUpdate = true;
  771. // continue;
  772. // }
  773. // if ($taskCfg->canshu1 == $task->counter) {
  774. // $task->progress = 1;
  775. // $bUpdate = true;
  776. // continue;
  777. // }
  778. // }
  779. //
  780. // if ($bUpdate) {
  781. // CornerSignEventProc::OnTask_Daily_new();
  782. // }
  783. }
  784. // </editor-fold>
  785. //
  786. // <editor-fold defaultstate="collapsed" desc="处理各种任务检测事务">
  787. //
  788. /**
  789. * 神庙抽奖
  790. */
  791. static function OnTempleLottery() {
  792. // $taskParam = new Ins_TaskParams(Enum_TaskCmdType::TempleLottery);
  793. // self::CheckTaskConditions($taskParam);
  794. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::TempleLottery, Enum_PropelType::set, 1, array());
  795. self::CheckTaskCardConditions($taskEventArg);
  796. }
  797. /**
  798. * 例如当指挥官等级提升的时候需要检查是否有任务达成
  799. */
  800. static function OnUserLevelUp($newLvl) {
  801. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::CommanderLevelUpTo, $newLvl);
  802. self::CheckTaskConditions($taskParam);
  803. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::CommanderLevelUpTo, Enum_PropelType::set, $newLvl, array($newLvl));
  804. self::CheckTaskCardConditions($taskEventArg);
  805. }
  806. /**
  807. * 英雄升级
  808. * @param type $heroMoId
  809. * @param type $newLvl
  810. */
  811. static function OnHeroLevelUp($heroMoId, $newLvl) {
  812. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroLevelUpTo, $heroMoId, $newLvl);
  813. self::CheckTaskConditions($taskParam);
  814. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroLevelUpTo, Enum_PropelType::set, $newLvl, array($heroMoId));
  815. self::CheckTaskCardConditions($taskEventArg);
  816. }
  817. /**
  818. * 英雄升阶
  819. * @param type $heroMoId
  820. * @param type $newGrade
  821. */
  822. static function OnHeroGradeUp($heroMoId, $newGrade) {
  823. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroGradeUpTo, $heroMoId, $newGrade);
  824. self::CheckTaskConditions($taskParam);
  825. self::OnHeroImprove();
  826. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroGradeUpTo, Enum_PropelType::set, 1, array());
  827. self::CheckTaskCardConditions($taskEventArg);
  828. }
  829. /**
  830. * 英雄碎片数量达到指定值
  831. * @param type $heroMoId
  832. * @param type $num
  833. */
  834. static function OnHeroSegmengNum($heroMoId, $num) {
  835. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroSegmentNumberTo, $heroMoId, $num);
  836. self::CheckTaskConditions($taskParam);
  837. }
  838. /**
  839. * 英雄解锁技能
  840. * @param type $heroMoId
  841. * @param type $skillId
  842. */
  843. static function OnHeroUnlocSkill($heroMoId, $skillId) {
  844. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::HeroSkillUnlock, $heroMoId, $skillId);
  845. self::CheckTaskConditions($taskParam);
  846. }
  847. /**
  848. * 英雄穿上武器
  849. * @param type $heroMoid
  850. * @param type $weaponMoId
  851. */
  852. static function OnHeroWearWeapon($heroMoid, $weaponMoId) {
  853. $weapMO = GameConfig::item_base_getItem($weaponMoId);
  854. my_Assert($weapMO, ErrCode::err_const_no);
  855. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroWearupWeapon_quality, Enum_PropelType::set, 1, array($heroMoid, $weapMO->quality));
  856. self::CheckTaskCardConditions($taskEventArg);
  857. }
  858. /**
  859. * 英雄装备言灵
  860. * @param type $heroMoid
  861. * @param type $weaponMoId
  862. */
  863. static function OnHeroWearYanling($heroMoid, $yanlingMoId) {
  864. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroWearupYanling, Enum_PropelType::set, 1, array($heroMoid, $yanlingMoId));
  865. self::CheckTaskCardConditions($taskEventArg); # 检查装备言灵任务
  866. $ylmo = GameConfig::item_base_getItem($yanlingMoId);
  867. my_Assert(null != $ylmo, ErrCode::err_const_no);
  868. $taskEventArg2 = new Ins_TaskEventArgs(Enum_TaskCmdType::HeroWearUpXYanlingWithQualityN, Enum_PropelType::add, 1, array($ylmo->quality));
  869. self::CheckTaskCardConditions($taskEventArg2); # 检查装备x个n品质言灵任务
  870. }
  871. /**
  872. * 通关剧情关卡
  873. * @param type $gateId
  874. * @param type $difficulty
  875. */
  876. static function OnPassGateN($gateId, $difficulty) {
  877. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PassGateN, $gateId, $difficulty);
  878. self::CheckTaskConditions($taskParam);
  879. self::OnPassGate();
  880. // var_dump("通关剧情检测 $gateId $difficulty");
  881. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::PassGateN, Enum_PropelType::set, 1, array($gateId, $difficulty));
  882. self::CheckTaskCardConditions($taskEventArg);
  883. }
  884. /**
  885. * 通关材料副本第n层
  886. * @param type $gateId
  887. * @param type $level
  888. */
  889. static function OnPassMaterialCarbonN($gateId, $level) {
  890. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::PassMaterialCarbonN, Enum_PropelType::set, 1, array($gateId, $level));
  891. self::CheckTaskCardConditions($taskEventArg);
  892. }
  893. /**
  894. * 通关无尽塔副本关卡
  895. * @param type $gateId
  896. * @param type $difficulty 层数
  897. */
  898. static function OnPassEndlessCarboN($gateId, $difficulty) {
  899. // $taskParam = new Ins_TaskParams(Enum_TaskCmdType::passEndlessCarbonN, $gateId, $difficulty);
  900. // self::CheckTaskConditions($taskParam);
  901. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::passEndlessCarbonN, Enum_PropelType::set, 1, array($gateId, $difficulty));
  902. // var_dump($taskEventArg);
  903. self::CheckTaskCardConditions($taskEventArg);
  904. }
  905. /**
  906. * 完成一次boss战胜利
  907. * @param type $gateId
  908. */
  909. static function OnPassWorldBoss($gateId) {
  910. // $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PassWorldBoss, $gateId);
  911. // self::CheckTaskConditions($taskParam);
  912. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::PassWorldBoss, Enum_PropelType::set, 1, array($gateId));
  913. // var_dump($taskEventArg);
  914. self::CheckTaskCardConditions($taskEventArg);
  915. //
  916. $taskEventArgDaily = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyBossChallenge, Enum_PropelType::add, 1, array($gateId));
  917. // var_dump($taskEventArgDaily);
  918. self::CheckTaskCardConditions($taskEventArgDaily);
  919. }
  920. /**
  921. * 竞技场胜利场次
  922. * @param type $num
  923. */
  924. static function OnPvPWinN($num) {
  925. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PvPWinNumberTo, $num);
  926. self::CheckTaskConditions($taskParam);
  927. }
  928. /**
  929. * 竞技场积分
  930. * @param type $score
  931. */
  932. static function OnPvPScoreN($score) {
  933. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::PvPScoreTo, $score);
  934. self::CheckTaskConditions($taskParam);
  935. }
  936. /**
  937. * 玩家总战力值
  938. * @param type $num
  939. */
  940. static function OnUserFightPowerN($num) {
  941. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::UserPowerTo, $num);
  942. self::CheckTaskConditions($taskParam);
  943. }
  944. /**
  945. * 玩家收集积分
  946. * @param type $num
  947. */
  948. static function OnUserCollectScoreN($num) {
  949. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::UserCollectScoreTo, $num);
  950. self::CheckTaskConditions($taskParam);
  951. }
  952. //
  953. // </editor-fold>
  954. //
  955. // <editor-fold defaultstate="collapsed" desc="每日任务条件检查">
  956. //
  957. // static function Upate
  958. /**
  959. * 每日登陆
  960. */
  961. static function OnUserLogin() {
  962. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyLogin);
  963. self::CheckDailyTaskConditions($taskParam);
  964. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyLogin, Enum_PropelType::set, 1, array());
  965. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  966. }
  967. /**
  968. * 每日:英雄强化(升级或升阶)n次
  969. */
  970. static function OnHeroImprove() {
  971. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyHeroImprove);
  972. self::CheckDailyTaskConditions($taskParam);
  973. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyHeroImprove, Enum_PropelType::inc, 1, array());
  974. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  975. }
  976. /**
  977. * 每日:剧情关卡,胜利n次
  978. */
  979. static function OnPassGate() {
  980. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyGatesWin);
  981. self::CheckDailyTaskConditions($taskParam);
  982. $taskEventArg = new Ins_TaskEventArgs(Enum_TaskCmdType::DailyGatesWin, Enum_PropelType::inc, 1, array());
  983. self::CheckTaskCardConditions($taskEventArg); # 检查日常任务
  984. }
  985. /**
  986. * 竞技场每日挑战,胜负均可
  987. */
  988. static function OnPvp() {
  989. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyPVP);
  990. self::CheckDailyTaskConditions($taskParam);
  991. self::CheckTaskCardConditions($taskParam);
  992. }
  993. /**
  994. * 每日挑战,胜负均可
  995. */
  996. static function OnRankChalenge() {
  997. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyRankChalenge);
  998. self::CheckDailyTaskConditions($taskParam);
  999. self::CheckTaskCardConditions($taskParam);
  1000. }
  1001. /**
  1002. * 每日购买商品
  1003. */
  1004. static function OnShopping() {
  1005. $taskParam = new Ins_TaskParams(Enum_TaskCmdType::DailyShopping);
  1006. self::CheckDailyTaskConditions($taskParam);
  1007. self::CheckTaskCardConditions($taskParam);
  1008. }
  1009. //
  1010. // </editor-fold>
  1011. //
  1012. // <editor-fold defaultstate="collapsed" desc="处理任务卡条件检查">
  1013. //
  1014. /**
  1015. * 自动修正任务追踪信息
  1016. */
  1017. static function autoRecoverTaskTracingState() {
  1018. $tasks = ctx()->store->taskcards;
  1019. $pri = ctx()->privateData();
  1020. for ($tp = 1; $tp < 5; $tp++) {
  1021. if (StlUtil::dictHasProperty($pri->taskCardTracing, $tp)) {
  1022. $curId = $pri->taskCardTracing->$tp;
  1023. } else {
  1024. $curId = 0;
  1025. }
  1026. //$curId = my_null_default($pri->taskCardTracing->$tp, 0); # 当前追踪中的任务卡id
  1027. $needRefresh = false;
  1028. if ($curId > 0) { # 存在任务卡
  1029. if (CommUtil::isPropertyExists($tasks, $curId)) {
  1030. $curTask = new Ins_TaskCard($tasks->$curId);
  1031. if ($curTask->state >= 4) { # 任务卡已经被领取奖励, 尝试刷新
  1032. $needRefresh = true;
  1033. }
  1034. } else { # 任务卡已经被删除, 尝试刷新
  1035. $needRefresh = true;
  1036. }
  1037. } else { # 没有追踪目标, 尝试刷新
  1038. $needRefresh = true;
  1039. }
  1040. if ($needRefresh) {
  1041. $ok = false;
  1042. foreach ($tasks as $tid => &$task) {
  1043. $task = new Ins_TaskCard($task);
  1044. if ($task->mo()->type == $tp) {
  1045. if ($task->state >= 4) {
  1046. continue;
  1047. }
  1048. $pri->taskCardTracing->$tp = $tid;
  1049. $ok = true;
  1050. break;
  1051. }
  1052. }
  1053. if (!$ok) { # 没有找到合适的追踪对象
  1054. $pri->taskCardTracing->$tp = 0; # 删除所有追踪(剩余任务已经全部完成了)
  1055. }
  1056. ctx()->store->taskcards = $tasks;
  1057. ctx()->privateState = $pri;
  1058. }
  1059. }
  1060. }
  1061. /**
  1062. * 自动修复状态型任务
  1063. */
  1064. static function autoRecoverStateMissions() {
  1065. $tasks = ctx()->store->taskcards;
  1066. foreach ($tasks as $tid => &$task) {
  1067. $task = new Ins_TaskCard($task);
  1068. if ($task->state == Enum_TaskCardStateType::ing // # 进行中的或者已完成的
  1069. || $task->state == Enum_TaskCardStateType::finish) {
  1070. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  1071. $tsp = new Ins_TaskStep($tsp);
  1072. $tsp->autoCalcStatusCur();
  1073. }
  1074. if ($task->state == Enum_TaskCardStateType::finish) { # 检查是否任务卡的所有步骤都已完成
  1075. if (!$task->IsFinish()) {
  1076. $task->state = Enum_TaskCardStateType::ing; # 状态回退
  1077. }
  1078. }
  1079. }
  1080. }
  1081. Clog::info("更新状态统计类的任务卡!");
  1082. ctx()->store->taskcards = $tasks;
  1083. }
  1084. /**
  1085. * 检查任务卡条件是否达成
  1086. * @param Ins_TaskEventArgs $taskParam Description
  1087. */
  1088. static function CheckTaskCardConditions($taskParam) {
  1089. $bUpdate = false;
  1090. $tasks = ctx()->store->taskcards;
  1091. foreach ($tasks as $tid => &$task) {
  1092. $task = new Ins_TaskCard($task);
  1093. if ($task->state != Enum_TaskCardStateType::ing) {
  1094. continue;
  1095. }
  1096. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  1097. $tsp = new Ins_TaskStep($tsp);
  1098. if ($tsp->check_new($taskParam)) {
  1099. $bUpdate = true;
  1100. $tsp->propel($taskParam);
  1101. NormalEventProc::OnTaskCardStep_Process($task->uid, $tsp->typeId); # 任务进度更新
  1102. if ($tsp->isFinish()) {
  1103. NormalEventProc::OnTaskCardStep_Complete($task->uid, $tsp->typeId); # 广播任务步骤完成事件
  1104. // $tsp->doFinishAct();
  1105. }
  1106. }
  1107. }
  1108. if ($task->IsFinish()) { # 检查后添加后续任务
  1109. $arr = array();
  1110. foreach ($task->curSteps as &$tsp) { # 初期里面只有一个任务
  1111. $tsp = new Ins_TaskStep($tsp);
  1112. if (strlen($tsp->mo()->next) > 0) { # 有后续任务
  1113. $arr = array_merge($arr, explode(',', $tsp->mo()->next)); # 累加下一个任务步骤
  1114. }
  1115. }
  1116. foreach ($arr as $stpid) { # 轮询添加后续任务
  1117. if ($stpid > 0) {
  1118. $task->AddStep($stpid); # 将后续任务追加到任务列表中
  1119. }
  1120. }
  1121. }
  1122. if ($task->IsFinish()) { # 检查是否任务卡的所有步骤都已完成
  1123. $task->state = Enum_TaskCardStateType::finish;
  1124. NormalEventProc::OnTaskCard_Finish($task->uid, null); # 广播卡完成事件
  1125. }
  1126. }
  1127. if ($bUpdate) { # 带回数据到客户端
  1128. ctx()->store->taskcards = $tasks;
  1129. UserProc::updateUserInfo(); # 更新玩家数据
  1130. }
  1131. return $bUpdate;
  1132. }
  1133. static function OnKillMonster($monsterID, $num) {
  1134. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::KillMonster, Enum_PropelType::add, $num, array($monsterID));
  1135. return self::CheckTaskCardConditions($taskParam);
  1136. }
  1137. /**
  1138. * 获得道具
  1139. */
  1140. static function OnGainItem($itemId, $num) {
  1141. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::GainItem, Enum_PropelType::stat, $num, array($itemId));
  1142. self::CheckTaskCardConditions($taskParam);
  1143. }
  1144. /**
  1145. * 对话完成
  1146. * @param type $gate_or_npc_id
  1147. * @param type $stage
  1148. * @return type
  1149. */
  1150. static function OnPlotOver($gate_or_npc_id, $stage) {
  1151. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::PlotOver, Enum_PropelType::set, 1, array($gate_or_npc_id, "$stage"));
  1152. self::CheckTaskCardConditions($taskParam);
  1153. }
  1154. /**
  1155. * 购买n张任务卡(非特定)
  1156. * @param type $_num
  1157. * @return type
  1158. */
  1159. static function OnBuyTaskCard($_num = 1) {
  1160. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::BuyTaskCard_Num, Enum_PropelType::add, $_num, array());
  1161. self::CheckTaskCardConditions($taskParam);
  1162. }
  1163. /**
  1164. * 完成任务卡(不指定) 这是要造检查任务卡的任务卡[・_・?]
  1165. * @param Ins_TaskCard $taskCard
  1166. */
  1167. static function OnFinishTaskCard($taskCard) {
  1168. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishTaskCard_noID, Enum_PropelType::set, 1, array());
  1169. self::CheckTaskCardConditions($taskParam);
  1170. $cardBase = GameConfig::item_base_getItem($taskCard->mo()->typeId);
  1171. $taskParam2 = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishXCardWithQualityN, Enum_PropelType::add, 1, array($cardBase->quality));
  1172. self::CheckTaskCardConditions($taskParam2);
  1173. if ($taskCard->mo()->cardType == "言灵") {
  1174. $taskParam3 = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishXYanlingCardAboutQualityN, Enum_PropelType::add, 1, array($cardBase->quality));
  1175. self::CheckTaskCardConditions($taskParam3);
  1176. }
  1177. }
  1178. /**
  1179. * 领取系统邮件奖励
  1180. * @param type $mailId 指定邮件id
  1181. * @return type
  1182. */
  1183. static function OnDrawSysMail($mailId) {
  1184. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::DrawSysMail_ID, Enum_PropelType::set, 1, array($mailId));
  1185. self::CheckTaskCardConditions($taskParam);
  1186. }
  1187. /**
  1188. * 言灵升级
  1189. * @param type $yanlingType
  1190. * @param type $level
  1191. * @return type
  1192. */
  1193. static function OnYanlingLevelUp($yanlingType, $level) {
  1194. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::AnyYanlingLevelUp, Enum_PropelType::set, 1, array($yanlingType, $level));
  1195. self::CheckTaskCardConditions($taskParam);
  1196. }
  1197. /**
  1198. * 言灵升星(突破)
  1199. * @param type $newStar
  1200. */
  1201. static function OnYanlingStarUp($newStar) {
  1202. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::UpgradeXYanlingToNStar, Enum_PropelType::add, 1, array($newStar));
  1203. self::CheckTaskCardConditions($taskParam);
  1204. }
  1205. static function OnWeaponUpgrade() {
  1206. }
  1207. /**
  1208. * 武器突破
  1209. * @param type $newStar
  1210. */
  1211. static function OnWeaponStarUp($newStar) {
  1212. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::UpgradeXWeaponToNStar, Enum_PropelType::add, 1, array($newStar));
  1213. self::CheckTaskCardConditions($taskParam);
  1214. }
  1215. /**
  1216. * 领取任意一个学院课程下的任意一个任务(num:1,paras[])(学院界面)
  1217. */
  1218. static function OnGetSchoolTask() {
  1219. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::GetSchoolTask, Enum_PropelType::set, 1, array());
  1220. self::CheckTaskCardConditions($taskParam);
  1221. }
  1222. /**
  1223. * 完成任意一个学院课程下的任意一张任务卡(num:1,paras:[])(学院界面)
  1224. */
  1225. static function OnFinishSchoolTask() {
  1226. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishSchoolTask, Enum_PropelType::set, 1, array());
  1227. self::CheckTaskCardConditions($taskParam);
  1228. }
  1229. /**
  1230. * 完成指课程的全部任务(num:1,paras:[courseId])(学院界面)
  1231. * @param int $courseId 课程id
  1232. */
  1233. static function OnFinishAllSchoolTaskOfGrade($courseId) {
  1234. $taskParam = new Ins_TaskEventArgs(Enum_TaskCmdType::FinishAllSchoolTaskOfGrade, Enum_PropelType::set, 1, array($courseId));
  1235. self::CheckTaskCardConditions($taskParam);
  1236. }
  1237. //
  1238. // </editor-fold>
  1239. //
  1240. }