TaskProc.php 56 KB

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