TaskProc.php 56 KB

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