TaskProc.php 60 KB

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