TaskProc.php 60 KB

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