FightProc.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 战斗模块
  5. * @author c'y'zhao
  6. */
  7. class FightProc {
  8. public const TowerGateId = 940011999;
  9. /**
  10. * 逻辑分发
  11. * 所有的Proc中必须有这样一个方法
  12. * @param Req $req
  13. */
  14. public static function procMain($req) {
  15. switch ($req->cmd) {
  16. case CmdCode::fight_settle: # 6801 主线战斗结算
  17. return FightProc::Settle();
  18. case CmdCode::fight_PassGateTsPrizeReceive: # 6802 章节宝箱的领取
  19. return FightProc::PassGateTsPrizeReceive();
  20. case CmdCode::fight_selectGate: # 6803 主线剧情关卡选择
  21. return FightProc::SelectGate();
  22. case CmdCode::fight_gateChallengeRewards: # 6804 挑战关卡: 领取奖励
  23. return FightProc::GateChallengeRewards();
  24. case CmdCode::fihgt_towerStart: # 6805 挑战关卡: 开始挑战
  25. return FightProc::ChallengeGateStartFight();
  26. case CmdCode::fight_plotSav: # 6806 主线剧情(已播放)回存
  27. return FightProc::PlotSav();
  28. case CmdCode::fight_sweep: # 6807 主线扫荡
  29. return FightProc::FightSweep();
  30. case CmdCode::fight_startFight: # 6808 主线剧情关卡开始挑战
  31. return self::StartFight();
  32. case CmdCode::fight_tower_RefreshSkills: # 6809 挑战关卡: 刷新初始技能
  33. return self::TowerRefreshSkills();
  34. case CmdCode::fight_tower_updatelocklist: # 6810 挑战关卡: 更新技能锁定列表
  35. return self::TowerUpdateLockskillList();
  36. case CmdCode::fight_rankInfo: # 6811 获取主线关卡排行榜信息
  37. return self::GetRankInfo();
  38. case CmdCode::fight_rank_uidEquipInfo: # 6812 获取主线关卡榜内玩家的装备信息
  39. return self::GetUidEquipInfo_Rank();
  40. case CmdCode::fight_rank_GetMainGateRankRewardInfo: # 6813 荣誉榜信息
  41. return self::GetmainGate_RankRewardInfo();
  42. case CmdCode::fight_rank_GetFightPowerRankRewardInfo: # 6814 荣誉榜信息
  43. return self::GetFightPower_RankRewardInfo();
  44. case CmdCode::fight_rank_ReceiveRankReward: # 6815 领取荣誉榜奖励
  45. return self::ReceiveRankReward();
  46. default:
  47. Err(ErrCode::cmd_err);
  48. }
  49. }
  50. /**
  51. * 6807 扫荡
  52. * @return type
  53. */
  54. public static function FightSweep() {
  55. //list($gateId) = req()->paras;
  56. my_Assert(ctx()->gates->UnlockedGatesMaxId != 0, ErrCode::gate_NoSweep);
  57. $mo = GameConfig::gate_getItem(ctx()->gates->UnlockedGatesMaxId);
  58. $costTili = glc()->sweep_cost_tili;
  59. my_Assert(ctx()->baseInfo->tili >= $costTili, ErrCode::notenough_tili);
  60. $max = glc()->sweepMaxNum;
  61. my_Assert(ctx()->gates->fightSweepNum < $max, ErrCode::gate_SweepMaxNum_limit);
  62. ctx()->gates->fightSweepNum += 1;
  63. ctx()->baseInfo->Consume_tili($costTili);
  64. $prizeArr = array();
  65. $prizeArr[] = $mo->reward_win;
  66. if ($mo->sweep_gold != null) {
  67. $goodsStr = self::sweepRandReward($mo->sweep_gold);
  68. $prizeArr[] = $goodsStr;
  69. StoreProc::AddMultiItemInStore($goodsStr);
  70. }
  71. if ($mo->sweep_tuzhi != null) {
  72. $goodsStr = self::sweepRandReward($mo->sweep_tuzhi);
  73. $prizeArr[] = $goodsStr;
  74. StoreProc::AddMultiItemInStore($goodsStr);
  75. }
  76. if ($mo->sweep_gem != null) {
  77. $goodsStr = self::sweepRandReward($mo->sweep_gem);
  78. $list = explode(',', $goodsStr);
  79. $posId = rand(1, 6);
  80. $qual = $list[0];
  81. $dic = GameConfig::gem();
  82. foreach ($dic as $key => $gemMo) {
  83. if ($gemMo->qual == $qual && $gemMo->position == $posId) {
  84. $prizeArr[] = $gemMo->typeId . ',' . $list[1];
  85. StoreProc::PutGemInStore($gemMo->typeId, $list[1]);
  86. break;
  87. }
  88. }
  89. }
  90. if ($mo->sweep_qiling != null) {
  91. $goodsStr = self::sweepRandReward($mo->sweep_qiling);
  92. $prizeArr[] = $goodsStr;
  93. StoreProc::AddMultiItemInStore($goodsStr);
  94. }
  95. UserProc::updateUserInfo();
  96. $ret = array(
  97. 'tili' => ctx()->baseInfo->tili,
  98. 'fightSweepNum' => ctx()->gates->fightSweepNum,
  99. 'prizeArr' => $prizeArr,
  100. 'store' => ctx()->store,
  101. 'task' => ctx()->task,
  102. );
  103. return Resp::ok($ret);
  104. }
  105. static function sweepRandReward($rewardStr) {
  106. $ctxArr = explode(';', $rewardStr);
  107. $numArr = explode('-', $ctxArr[0]);
  108. $num = rand($numArr[0], $numArr[1]);
  109. $randNum = rand(1, 100);
  110. $start = 0;
  111. $end = 0;
  112. $res = "";
  113. $itemArr = explode(',', $ctxArr[1]);
  114. foreach ($itemArr as $str) {
  115. $arr = explode(':', $str);
  116. $itemId = $arr[0];
  117. $per = $arr[1];
  118. $end += $per;
  119. if ($randNum >= $start && $randNum < $end) {
  120. $res = $itemId;
  121. break;
  122. }
  123. $start = $end;
  124. }
  125. return $res . ',' . $num;
  126. }
  127. /**
  128. * 6808 开始挑战 (主线关卡:扣除体力, 挑战关卡: 增加次数)
  129. */
  130. private static function StartFight() {
  131. list($gateId, $layerNum) = req()->paras;
  132. my_Assert($gateId > 0, ErrCode::paras_err);
  133. $mo = GameConfig::gate_getItem($gateId);
  134. my_Assert(null != $mo, ErrCode::err_const_no);
  135. if (Ints::Slice($gateId, 0, 1) == 9) { # 爬塔模式
  136. // list($layerNum) = req()->paras;
  137. if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # 起始层数校验
  138. Err(ErrCode::tower_layerNum);
  139. }
  140. if (ctx()->gates()->TowerGateInfo()->TodayChanNum < 1) { # 剩余次数校验
  141. Err(ErrCode::tower_timeNo);
  142. }
  143. ctx()->gates()->TowerGateInfo()->TodayChanNum--; # 增加次数
  144. } else { # 主线剧情
  145. my_Assert(ctx()->base()->Consume_tili($mo->cost_tili), ErrCode::notenough_tili);
  146. }
  147. UserProc::updateUserInfo();
  148. return Resp::ok(array("tili" => ctx()->baseInfo->tili, "tili_ts" => ctx()->baseInfo->tili_ts));
  149. }
  150. /**
  151. * [废弃] 6807 巡逻奖励领取
  152. * @return type
  153. */
  154. public static function XunluoPrizeReceived() {
  155. list($type) = req()->paras;
  156. $gateId = ctx()->gates->UnlockedGatesMaxId;
  157. $gateMo = GameConfig::gate_getItem($gateId);
  158. my_Assert($gateMo != null, ErrCode::err_const_no);
  159. if ($type == 1) {//巡逻
  160. $curTs = now();
  161. $startTs = ctx()->gates->xunluo_StartTs;
  162. $ts = $curTs - $startTs;
  163. $ts2 = intval($ts / 60); //总的分钟数
  164. $fenzhong = intval($ts2 / 10); //有几个10分钟
  165. $gold = 0;
  166. $exp = 0;
  167. $price = "";
  168. if ($fenzhong > 0) {
  169. $gold = intval($gateMo->gold_xunluo / 6 * $fenzhong);
  170. $exp = intval($gateMo->exp_xunluo / 6 * $fenzhong);
  171. $price = "1," . $gold . ';' . "4," . $exp;
  172. }
  173. $itemStr = explode(';', $gateMo->xunluo_item_ts);
  174. $itemId = 0;
  175. $itemNum = 0;
  176. $tempTs = 0;
  177. foreach ($itemStr as $s) {
  178. $arr = explode('-', $s);
  179. $tsItemArr = explode(',', $arr[0]);
  180. $sTs = $tsItemArr[0]; //开始时间
  181. $eTs = $tsItemArr[1]; //终止时间
  182. $produceTs = $tsItemArr[2]; //间隔
  183. while (true) {
  184. $tempTs += $produceTs;
  185. if ($tempTs <= $eTs && $tempTs <= $ts2) {
  186. $sList = explode(',', $arr[1]);
  187. $itemId = $sList[0];
  188. $itemNum += $sList[1];
  189. }
  190. if ($tempTs >= $ts2) {
  191. break;
  192. }
  193. if ($tempTs >= $eTs) {
  194. $tempTs = $eTs;
  195. break;
  196. }
  197. }
  198. if ($tempTs >= $ts2) {
  199. break;
  200. }
  201. }
  202. if ($itemNum > 0) {
  203. $price = $price . ";" . $itemId . ',' . $itemNum;
  204. }
  205. //---------------------------
  206. $tuzhiStr = explode(';', $gateMo->xunluo_tuzhi_ts);
  207. $tuzhiId = 0;
  208. $tuzhiNum = 0;
  209. $tempTs2 = 0;
  210. foreach ($tuzhiStr as $s) {
  211. $arr = explode('-', $s);
  212. $tsItemArr = explode(',', $arr[0]);
  213. $sTs = $tsItemArr[0]; //开始时间
  214. $eTs = $tsItemArr[1]; //终止时间
  215. $produceTs = $tsItemArr[2]; //间隔
  216. while (true) {
  217. $tempTs2 += $produceTs;
  218. if ($tempTs2 <= $eTs && $tempTs2 <= $ts2) {
  219. $sList = explode(',', $arr[1]);
  220. $tuzhiId = $sList[0];
  221. $tuzhiNum += $sList[1];
  222. }
  223. if ($tempTs2 >= $ts2) {
  224. break;
  225. }
  226. if ($tempTs2 >= $eTs) {
  227. $tempTs2 = $eTs;
  228. break;
  229. }
  230. }
  231. if ($tempTs2 >= $ts2) {
  232. break;
  233. }
  234. }
  235. if ($tuzhiNum > 0) {
  236. $price = $price . ";" . $tuzhiId . ',' . $tuzhiNum;
  237. }
  238. //---------------------
  239. $equipStr = explode(';', $gateMo->xunluo_equip_ts);
  240. $equipId = 0;
  241. $equipNum = 0;
  242. $tempTs3 = 0;
  243. foreach ($equipStr as $s) {
  244. $arr = explode('-', $s);
  245. $tsItemArr = explode(',', $arr[0]);
  246. $sTs = $tsItemArr[0]; //开始时间
  247. $eTs = $tsItemArr[1]; //终止时间
  248. $produceTs = $tsItemArr[2]; //间隔
  249. while (true) {
  250. $tempTs3 += $produceTs;
  251. if ($tempTs3 <= $eTs && $tempTs3 <= $ts2) {
  252. $sList = explode(',', $arr[1]);
  253. $equipId = $sList[0];
  254. $equipNum += $sList[1];
  255. }
  256. if ($tempTs3 >= $ts2) {
  257. break;
  258. }
  259. if ($tempTs3 >= $eTs) {
  260. $tempTs3 = $eTs;
  261. break;
  262. }
  263. }
  264. if ($tempTs3 >= $ts2) {
  265. break;
  266. }
  267. }
  268. if ($equipNum > 0) {
  269. $price = $price . ";" . $equipId . ',' . $equipNum;
  270. }
  271. StoreProc::AddMultiItemInStore($price);
  272. ctx()->gates->xunluo_StartTs = now();
  273. } else {//快速巡逻
  274. my_Assert(ctx()->gates->xunluo_quick_buyRecord < $gateMo->xueluo_quick_num, ErrCode::err_const_no);
  275. ctx()->gates->xunluo_quick_buyRecord += 1;
  276. ctx()->baseInfo->Consume_tili(15);
  277. StoreProc::AddMultiItemInStore($gateMo->xueluo_quick_reward);
  278. }
  279. UserProc::updateUserInfo();
  280. $ret = array(
  281. 'tili' => ctx()->baseInfo->tili,
  282. 'gates' => ctx()->gates,
  283. );
  284. return Resp::ok($ret);
  285. }
  286. public static function FightDailyClear() {
  287. //ctx()->gates->xunluo_quick_buyRecord = 0;
  288. ctx()->gates->fightSweepNum = 0;
  289. ctx()->gates()->TowerGateInfo()->RefreshSkillTimes = 0;
  290. ctx()->gates()->TowerGateInfo()->TodayChanNum = glc()->tower_daily_chanceNum;
  291. }
  292. /**
  293. * 6806 剧情回存
  294. * @return type
  295. */
  296. public static function PlotSav() {
  297. list($gateId) = req()->paras;
  298. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  299. ctx()->gates->GateList->$gateId->plotStart = 1;
  300. UserProc::updateUserInfo();
  301. $ret = array(
  302. 'ok' => 1,
  303. );
  304. return Resp::ok($ret);
  305. }
  306. // <editor-fold defaultstate="collapsed" desc="挑战模块">
  307. /**
  308. * 6810 挑战关卡: 更新锁定技能列表
  309. */
  310. public static function TowerUpdateLockskillList() {
  311. list($li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  312. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  313. $t->skill_zhudong = $li_zd;
  314. $t->skill_beidong = $li_bd;
  315. $t->skill_zhudong_lockState = $li_zds;
  316. $t->skill_beidong_lockState = $li_bds;
  317. UserProc::updateUserInfo();
  318. return Resp::ok();
  319. }
  320. /**
  321. * 6809 挑战关卡: 刷新初始技能(扣除免费次数/cost)
  322. */
  323. public static function TowerRefreshSkills() {
  324. list($isFree, $li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  325. if ($isFree) {
  326. if (ctx()->gates()->TowerGateInfo()->RefreshSkillTimes >= glc()->tower_daily_refreshChanceNum) {
  327. Err(ErrCode::tower_refreshNo); # 免费次数不足
  328. }
  329. } else {
  330. list($type, $num) = explode(':', glc()->tower_refreshCost); # 二级货币类型(1:金币,2:元宝):数量
  331. if ($type == 1) { # 金币
  332. my_Assert(ctx()->base()->Consume_Gold($num), ErrCode::notenough_gold_msg);
  333. } else if ($type == 2) { # 元宝
  334. my_Assert(ctx()->base()->Consume_Cash($num), ErrCode::notenough_cash_msg);
  335. } else {
  336. Err(ErrCode::err_const_no, "检查刷新扣费配置信息!");
  337. }
  338. }
  339. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  340. $t->RefreshSkillTimes++;
  341. $t->skill_zhudong = $li_zd;
  342. $t->skill_beidong = $li_bd;
  343. $t->skill_zhudong_lockState = $li_zds;
  344. $t->skill_beidong_lockState = $li_bds;
  345. UserProc::updateUserInfo();
  346. $ret = array(
  347. 'task' => ctx()->task,
  348. );
  349. return Resp::ok($ret);
  350. }
  351. /**
  352. * 6805
  353. * @return type
  354. * @deprecated since version 2024年5月17日 已合并到6801
  355. */
  356. public static function ChallengeGateStartFight() {
  357. // list($layerNum) = req()->paras;
  358. // if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # 起始层数校验
  359. // return Resp::err(ErrCode::tower_layerNum);
  360. // }
  361. // if (ctx()->gates()->TowerGateInfo()->TodayChanNum < 1) { # 剩余次数校验
  362. // return Resp::err(ErrCode::tower_timeNo);
  363. // }
  364. // ctx()->gates()->TowerGateInfo()->TodayChanNum--; # 增加次数
  365. // UserProc::updateUserInfo();
  366. // return Resp::ok();
  367. }
  368. /**
  369. * 6804 挑战关卡: 奖励领取
  370. * @return type
  371. */
  372. public static function GateChallengeRewards() {
  373. list($finalLayer) = req()->paras; # 战斗结束时的层数
  374. $lastLayer = ctx()->gates()->TowerGateInfo()->CurLayer;
  375. $arr = GameConfig::waves_getItemArray(self::TowerGateId);
  376. if ($finalLayer > $lastLayer) {
  377. foreach ($arr as $layerId => $layerMo) {
  378. if ($layerId >= $lastLayer && $layerId < $finalLayer) {
  379. my_Assert($layerMo != null, ErrCode::err_const_no);
  380. StoreProc::AddMultiItemInStore($layerMo->rewards); # 发放奖励
  381. }
  382. }
  383. ctx()->gates()->TowerGateInfo()->CurLayer = $finalLayer;
  384. UserProc::updateUserInfo();
  385. $ret = array(
  386. 'store' => ctx()->store,
  387. 'gold' => ctx()->base()->gold,
  388. 'cash' => ctx()->base()->cash,
  389. 'task' => ctx()->task,
  390. );
  391. return Resp::ok($ret);
  392. }
  393. return Resp::err(ErrCode::tower_rewardNo); # 没有奖励
  394. }
  395. // </editor-fold>
  396. /**
  397. * 6803 关卡选择
  398. * @return type
  399. */
  400. public static function SelectGate() {
  401. list($gateId) = req()->paras;
  402. ctx()->gates->CurrentGateId = $gateId;
  403. UserProc::updateUserInfo();
  404. $ret = array(
  405. 'gates' => ctx()->gates,
  406. );
  407. return Resp::ok($ret);
  408. }
  409. /**
  410. * 6802 章节宝箱的领取
  411. * @return type
  412. */
  413. public static function PassGateTsPrizeReceive() {
  414. list($gateId, $index) = req()->paras;
  415. $gateMo = GameConfig::gate_getItem($gateId);
  416. my_Assert($gateMo != null, ErrCode::err_const_no);
  417. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  418. $gateInfo = ctx()->gates->GateList->$gateId;
  419. $tag = false;
  420. $prize = "";
  421. $mask = 0;
  422. switch ($index) {
  423. case 1:
  424. $ts = $gateMo->first_ts1 * 60;
  425. if ($gateInfo->MaxSeconds >= $ts) {
  426. $tag = true;
  427. }
  428. $mask = 1;
  429. $prize = $gateMo->first_reward1;
  430. break;
  431. case 2:
  432. $ts = $gateMo->first_ts2 * 60;
  433. if ($gateInfo->MaxSeconds >= $ts) {
  434. $tag = true;
  435. }
  436. $mask = 2;
  437. $prize = $gateMo->first_reward2;
  438. break;
  439. case 3:
  440. if ($gateInfo->pass > 0) {
  441. $tag = true;
  442. }
  443. $mask = 3;
  444. $prize = $gateMo->first_reward3;
  445. break;
  446. default:
  447. break;
  448. }
  449. if ($tag) {
  450. my_Assert($mask > $gateInfo->FirstReward, ErrCode::gate_GatePriceHasReceive);
  451. $gateInfo->FirstReward = $mask;
  452. StoreProc::AddMultiItemInStore($prize);
  453. }
  454. ctx()->gates->GateList->$gateId = $gateInfo;
  455. UserProc::updateUserInfo();
  456. $ret = array(
  457. 'gates' => ctx()->gates,
  458. 'store' => ctx()->store,
  459. 'task' => ctx()->task,
  460. 'gold' => ctx()->baseInfo->gold,
  461. );
  462. return Resp::ok($ret);
  463. }
  464. /**
  465. * [6801]关卡战斗结算
  466. * @return type
  467. */
  468. public static function Settle() {
  469. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  470. # 客户端需要增加参数: killmonserNum,killBosssNum, finalHpPercent(最终血量百分比)
  471. $gateMo = GameConfig::gate_getItem($gateId);
  472. my_Assert($gateMo != null, ErrCode::err_const_no);
  473. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  474. $gateInfo = ctx()->gates->GateList->$gateId;
  475. $ts = $gateInfo->MaxSeconds;
  476. if ($curTs >= $ts) {
  477. $gateInfo->MaxSeconds = $curTs;
  478. }
  479. if ($resultType) { # 胜利
  480. if (ctx()->gates->GateList->$gateId->pass == 0) {
  481. ctx()->gates->GateList->$gateId->pass = 1;
  482. TaskProc::Day7TaskReset($gateId);
  483. }
  484. TaskProc::OnPassGate_X($gateId);
  485. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  486. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  487. ctx()->gates->UnlockNextPlotGate();
  488. $dic = GameConfig::gate();
  489. $index = 0; # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  490. foreach ($dic as $id => $item) {
  491. if (Ins_GateInfo::GateTypeFromId($id) == Enum_GateType::MainChallengeGate && $item->challengeGateId == $gateId) {
  492. $index += 1;
  493. $gate = new Ins_GateInfo();
  494. $gate->GateId = $id;
  495. ctx()->gates->GateList->$id = $gate;
  496. }
  497. if ($index >= 3) {
  498. break;
  499. }
  500. }
  501. } else {
  502. }
  503. } else { # 失败
  504. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  505. }
  506. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  507. ctx()->baseInfo->Add_Gold($gold);
  508. //ctx()->baseInfo->Add_Exp($exp);
  509. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  510. TaskProc::OnFightNumMainGate();
  511. } else if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainChallengeGate) {
  512. TaskProc::OnFightNumChallengeGate();
  513. }
  514. TaskProc::OnKillCommonNumMonster(1000);
  515. TaskProc::OnKillleaderNumMonster(500);
  516. UserProc::updateUserInfo();
  517. $ret = array(
  518. 'gates' => ctx()->gates,
  519. 'store' => ctx()->store,
  520. 'task' => ctx()->task,
  521. );
  522. return Resp::ok($ret);
  523. }
  524. /**
  525. * [6801]关卡战斗结算
  526. * @return type
  527. */
  528. public static function Settle_bak() {
  529. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  530. # 客户端需要增加参数: killmonserNum,killBosssNum, finalHpPercent(最终血量百分比)
  531. $gateMo = GameConfig::gate_getItem($gateId);
  532. my_Assert($gateMo != null, ErrCode::err_const_no);
  533. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  534. $gateInfo = ctx()->gates->GateList->$gateId;
  535. $ts = $gateInfo->MaxSeconds;
  536. if ($curTs >= $ts) {
  537. $gateInfo->MaxSeconds = $curTs;
  538. }
  539. if ($resultType) { # 胜利
  540. if (ctx()->gates->GateList->$gateId->pass == 0) {
  541. ctx()->gates->GateList->$gateId->pass = 1;
  542. TaskProc::Day7TaskReset($gateId);
  543. }
  544. TaskProc::OnPassGate_X($gateId);
  545. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  546. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  547. ctx()->gates->UnlockNextPlotGate();
  548. $dic = GameConfig::gate();
  549. $index = 0; # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  550. foreach ($dic as $id => $item) {
  551. if (Ins_GateInfo::GateTypeFromId($id) == Enum_GateType::MainChallengeGate && $item->challengeGateId == $gateId) {
  552. $index += 1;
  553. $gate = new Ins_GateInfo();
  554. $gate->GateId = $id;
  555. ctx()->gates->GateList->$id = $gate;
  556. }
  557. if ($index >= 3) {
  558. break;
  559. }
  560. }
  561. } else {
  562. }
  563. } else { # 失败
  564. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  565. }
  566. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  567. ctx()->baseInfo->Add_Gold($gold);
  568. //ctx()->baseInfo->Add_Exp($exp);
  569. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  570. TaskProc::OnFightNumMainGate();
  571. } else if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainChallengeGate) {
  572. TaskProc::OnFightNumChallengeGate();
  573. }
  574. TaskProc::OnKillCommonNumMonster(1000);
  575. TaskProc::OnKillleaderNumMonster(500);
  576. UserProc::updateUserInfo();
  577. $ret = array(
  578. 'gates' => ctx()->gates,
  579. 'store' => ctx()->store,
  580. 'task' => ctx()->task,
  581. );
  582. return Resp::ok($ret);
  583. }
  584. /**
  585. * 参与主线关卡排行榜
  586. * @param type $gateIndex
  587. */
  588. public static function Ranking_MainGateIndex($maxGateIndex) {
  589. $memKey = MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid);
  590. $mem = gMem();
  591. $arr = array();
  592. $uid = req()->uid;
  593. $arr["$uid"] = $maxGateIndex;
  594. $mem->zadd($memKey, $arr);
  595. $length = $mem->zlen($memKey);
  596. if ($length > glc()->Rank_MainGateIndex_OnListRank) {
  597. $num = $length - glc()->Rank_MainGateIndex_OnListRank;
  598. $mem->zremrangebyrank($memKey, 0, $num - 1);
  599. }
  600. }
  601. /**
  602. * 战力榜
  603. * @param type $gateIndex
  604. */
  605. public static function Ranking_FightPower() {
  606. $memKey = MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid);
  607. $mem = gMem();
  608. $arr = array();
  609. $uid = req()->uid;
  610. $power = 10;
  611. $arr["$uid"] = $power;
  612. $mem->zadd($memKey, $arr);
  613. $length = $mem->zlen($memKey);
  614. if ($length > glc()->Rank_FightPower_OnListRank) {
  615. $num = $length - glc()->Rank_FightPower_OnListRank;
  616. $mem->zremrangebyrank($memKey, 0, $num - 1);
  617. }
  618. }
  619. /**
  620. * 6811 获取主线关卡排行榜信息
  621. * @return type
  622. */
  623. public static function GetRankInfo() {
  624. list($type) = req()->paras;
  625. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  626. $selfExtraInfo = 0;
  627. if ($type == 1) {
  628. $list = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  629. $selfExtraInfo = ctx()->gates->UnlockedGatesMaxId;
  630. } else {
  631. $list = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  632. $selfExtraInfo = 0; //战力还没有
  633. }
  634. $selfRank = self::initOtherUidRankInfo(req()->uid, $selfExtraInfo);
  635. $retArr = array();
  636. if (count($list) > 0) {
  637. foreach ($list as $uid => $score) {
  638. $rankInfo = self::initOtherUidRankInfo($uid, $score);
  639. if ($rankInfo->uid == req()->uid) {
  640. $selfIsHasRank = 1;
  641. $selfRank = $rankInfo;
  642. }
  643. $retArr[] = $rankInfo;
  644. }
  645. }
  646. UserProc::updateUserInfo();
  647. $ret = array(
  648. 'rankInfo' => $retArr,
  649. 'selfRank' => $selfRank,
  650. 'selfIsHasRank' => $selfIsHasRank,
  651. );
  652. return Resp::ok($ret);
  653. }
  654. /**
  655. * 初始化玩家rank
  656. * @param type $uid
  657. * @param type $score
  658. * @return \loyalsoft\Ins_rank
  659. */
  660. static function initOtherUidRankInfo($uid, $score) {
  661. $ins_rank = new Ins_rank();
  662. $lv = gMem()->zrank(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  663. if ($lv == null) {
  664. $lv = 0;
  665. }
  666. $ins_rank->rank = $lv + 1;
  667. $ins_rank->uid = $uid;
  668. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  669. $ins_rank->name = $userInfo->baseInfo->name;
  670. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  671. $ins_rank->score = $score;
  672. return $ins_rank;
  673. }
  674. /**
  675. * 6812 获取排行榜内玩家的装备信息
  676. * @return type
  677. */
  678. public static function GetUidEquipInfo_Rank() {
  679. list($uid) = req()->paras;
  680. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  681. $store = $userInfo->store;
  682. $heros = $userInfo->heros;
  683. UserProc::updateUserInfo();
  684. $ret = array(
  685. 'store' => $store,
  686. 'heros' => $heros,
  687. );
  688. return Resp::ok($ret);
  689. }
  690. /**
  691. * 通关奖励是否达成
  692. * @param type $maxGateIndex
  693. */
  694. public static function IsAchievedMainGate_PassReward($maxGateIndex) {
  695. $rewards = GameConfig::rank_passgatereward();
  696. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  697. foreach ($rewards as $passGateId => $mo) {
  698. if ($passGateId == $maxGateIndex && !gMem()->hexists($memKey, $maxGateIndex)) {
  699. gMem()->hset($memKey, $maxGateIndex, req()->uid);
  700. break;
  701. }
  702. }
  703. }
  704. /*
  705. * 战力奖励是否达成
  706. */
  707. public static function IsAchievedFightPower_PassReward() {
  708. $power = 0; //临时
  709. $rewards = GameConfig::rank_fightpowerreward();
  710. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  711. foreach ($rewards as $fightPower => $mo) {
  712. if ($power >= $fightPower && !gMem()->hexists($memKey, $fightPower)) {
  713. gMem()->hset($memKey, $fightPower, req()->uid);
  714. }
  715. }
  716. }
  717. /**
  718. * 6813
  719. * @return type
  720. */
  721. public static function GetmainGate_RankRewardInfo() {
  722. //list($type) = req()->paras;
  723. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  724. $dic = gMem()->hgetall($memKey);
  725. UserProc::updateUserInfo();
  726. $ret = array(
  727. 'rankReward' => $dic,
  728. );
  729. return Resp::ok($ret);
  730. }
  731. /**
  732. * 6814
  733. * @return type
  734. */
  735. public static function GetFightPower_RankRewardInfo() {
  736. //list($type) = req()->paras;
  737. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  738. $dic = gMem()->hgetall($memKey);
  739. UserProc::updateUserInfo();
  740. $ret = array(
  741. 'rankReward' => $dic,
  742. );
  743. return Resp::ok($ret);
  744. }
  745. /**
  746. * 6815
  747. * @return type
  748. */
  749. public static function ReceiveRankReward() {
  750. list($type, $id) = req()->paras;
  751. my_Assert($gateMo != null, ErrCode::err_const_no);
  752. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  753. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  754. $dic = gMem()->hgetall($memKey);
  755. UserProc::updateUserInfo();
  756. $ret = array(
  757. 'rankReward' => $dic,
  758. );
  759. return Resp::ok($ret);
  760. }
  761. }