TaskProc.php 59 KB

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