FightProc.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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_MainGate: # 6815 领取通关荣誉榜奖励
  45. return self::ReceiveRankReward_MainGate();
  46. case CmdCode::fight_rank_ReceiveRankReward_FightPower: # 6816 领取战力荣誉榜奖励
  47. return self::ReceiveRankReward_FightPower();
  48. default:
  49. Err(ErrCode::cmd_err);
  50. }
  51. }
  52. /**
  53. * 6807 扫荡
  54. * @return type
  55. */
  56. public static function FightSweep() {
  57. //list($gateId) = req()->paras;
  58. my_Assert(ctx()->gates->UnlockedGatesMaxId != 0, ErrCode::gate_NoSweep);
  59. $mo = GameConfig::gate_getItem(ctx()->gates->UnlockedGatesMaxId);
  60. $costTili = glc()->sweep_cost_tili;
  61. my_Assert(ctx()->baseInfo->tili >= $costTili, ErrCode::notenough_tili);
  62. $max = glc()->sweepMaxNum;
  63. my_Assert(ctx()->gates->fightSweepNum < $max, ErrCode::gate_SweepMaxNum_limit);
  64. ctx()->gates->fightSweepNum += 1;
  65. ctx()->baseInfo->Consume_tili($costTili);
  66. $prizeArr = array();
  67. $prizeArr[] = $mo->reward_win;
  68. if ($mo->sweep_gold != null) {
  69. $goodsStr = self::sweepRandReward($mo->sweep_gold);
  70. $prizeArr[] = $goodsStr;
  71. StoreProc::AddMultiItemInStore($goodsStr);
  72. }
  73. if ($mo->sweep_tuzhi != null) {
  74. $goodsStr = self::sweepRandReward($mo->sweep_tuzhi);
  75. $prizeArr[] = $goodsStr;
  76. StoreProc::AddMultiItemInStore($goodsStr);
  77. }
  78. if ($mo->sweep_gem != null) {
  79. $goodsStr = self::sweepRandReward($mo->sweep_gem);
  80. $list = explode(',', $goodsStr);
  81. $posId = rand(1, 6);
  82. $qual = $list[0];
  83. $dic = GameConfig::gem();
  84. foreach ($dic as $key => $gemMo) {
  85. if ($gemMo->qual == $qual && $gemMo->position == $posId) {
  86. $prizeArr[] = $gemMo->typeId . ',' . $list[1];
  87. StoreProc::PutGemInStore($gemMo->typeId, $list[1]);
  88. break;
  89. }
  90. }
  91. }
  92. if ($mo->sweep_qiling != null) {
  93. $goodsStr = self::sweepRandReward($mo->sweep_qiling);
  94. $prizeArr[] = $goodsStr;
  95. StoreProc::AddMultiItemInStore($goodsStr);
  96. }
  97. UserProc::updateUserInfo();
  98. $ret = array(
  99. 'tili' => ctx()->baseInfo->tili,
  100. 'fightSweepNum' => ctx()->gates->fightSweepNum,
  101. 'prizeArr' => $prizeArr,
  102. 'store' => ctx()->store,
  103. 'task' => ctx()->task,
  104. );
  105. return Resp::ok($ret);
  106. }
  107. static function sweepRandReward($rewardStr) {
  108. $ctxArr = explode(';', $rewardStr);
  109. $numArr = explode('-', $ctxArr[0]);
  110. $num = rand($numArr[0], $numArr[1]);
  111. $randNum = rand(1, 100);
  112. $start = 0;
  113. $end = 0;
  114. $res = "";
  115. $itemArr = explode(',', $ctxArr[1]);
  116. foreach ($itemArr as $str) {
  117. $arr = explode(':', $str);
  118. $itemId = $arr[0];
  119. $per = $arr[1];
  120. $end += $per;
  121. if ($randNum >= $start && $randNum < $end) {
  122. $res = $itemId;
  123. break;
  124. }
  125. $start = $end;
  126. }
  127. return $res . ',' . $num;
  128. }
  129. /**
  130. * 6808 开始挑战 (主线关卡:扣除体力, 挑战关卡: 增加次数)
  131. */
  132. private static function StartFight() {
  133. list($gateId, $layerNum) = req()->paras;
  134. my_Assert($gateId > 0, ErrCode::paras_err);
  135. $mo = GameConfig::gate_getItem($gateId);
  136. my_Assert(null != $mo, ErrCode::err_const_no);
  137. if (Ints::Slice($gateId, 0, 1) == 9) { # 爬塔模式
  138. // list($layerNum) = req()->paras;
  139. if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # 起始层数校验
  140. Err(ErrCode::tower_layerNum);
  141. }
  142. if (ctx()->gates()->TowerGateInfo()->TodayChanNum < 1) { # 剩余次数校验
  143. Err(ErrCode::tower_timeNo);
  144. }
  145. ctx()->gates()->TowerGateInfo()->TodayChanNum--; # 增加次数
  146. } else { # 主线剧情
  147. my_Assert(ctx()->base()->Consume_tili($mo->cost_tili), ErrCode::notenough_tili);
  148. }
  149. UserProc::updateUserInfo();
  150. return Resp::ok(array("tili" => ctx()->baseInfo->tili, "tili_ts" => ctx()->baseInfo->tili_ts));
  151. }
  152. /**
  153. * [废弃] 6807 巡逻奖励领取
  154. * @return type
  155. */
  156. public static function XunluoPrizeReceived() {
  157. list($type) = req()->paras;
  158. $gateId = ctx()->gates->UnlockedGatesMaxId;
  159. $gateMo = GameConfig::gate_getItem($gateId);
  160. my_Assert($gateMo != null, ErrCode::err_const_no);
  161. if ($type == 1) {//巡逻
  162. $curTs = now();
  163. $startTs = ctx()->gates->xunluo_StartTs;
  164. $ts = $curTs - $startTs;
  165. $ts2 = intval($ts / 60); //总的分钟数
  166. $fenzhong = intval($ts2 / 10); //有几个10分钟
  167. $gold = 0;
  168. $exp = 0;
  169. $price = "";
  170. if ($fenzhong > 0) {
  171. $gold = intval($gateMo->gold_xunluo / 6 * $fenzhong);
  172. $exp = intval($gateMo->exp_xunluo / 6 * $fenzhong);
  173. $price = "1," . $gold . ';' . "4," . $exp;
  174. }
  175. $itemStr = explode(';', $gateMo->xunluo_item_ts);
  176. $itemId = 0;
  177. $itemNum = 0;
  178. $tempTs = 0;
  179. foreach ($itemStr as $s) {
  180. $arr = explode('-', $s);
  181. $tsItemArr = explode(',', $arr[0]);
  182. $sTs = $tsItemArr[0]; //开始时间
  183. $eTs = $tsItemArr[1]; //终止时间
  184. $produceTs = $tsItemArr[2]; //间隔
  185. while (true) {
  186. $tempTs += $produceTs;
  187. if ($tempTs <= $eTs && $tempTs <= $ts2) {
  188. $sList = explode(',', $arr[1]);
  189. $itemId = $sList[0];
  190. $itemNum += $sList[1];
  191. }
  192. if ($tempTs >= $ts2) {
  193. break;
  194. }
  195. if ($tempTs >= $eTs) {
  196. $tempTs = $eTs;
  197. break;
  198. }
  199. }
  200. if ($tempTs >= $ts2) {
  201. break;
  202. }
  203. }
  204. if ($itemNum > 0) {
  205. $price = $price . ";" . $itemId . ',' . $itemNum;
  206. }
  207. //---------------------------
  208. $tuzhiStr = explode(';', $gateMo->xunluo_tuzhi_ts);
  209. $tuzhiId = 0;
  210. $tuzhiNum = 0;
  211. $tempTs2 = 0;
  212. foreach ($tuzhiStr as $s) {
  213. $arr = explode('-', $s);
  214. $tsItemArr = explode(',', $arr[0]);
  215. $sTs = $tsItemArr[0]; //开始时间
  216. $eTs = $tsItemArr[1]; //终止时间
  217. $produceTs = $tsItemArr[2]; //间隔
  218. while (true) {
  219. $tempTs2 += $produceTs;
  220. if ($tempTs2 <= $eTs && $tempTs2 <= $ts2) {
  221. $sList = explode(',', $arr[1]);
  222. $tuzhiId = $sList[0];
  223. $tuzhiNum += $sList[1];
  224. }
  225. if ($tempTs2 >= $ts2) {
  226. break;
  227. }
  228. if ($tempTs2 >= $eTs) {
  229. $tempTs2 = $eTs;
  230. break;
  231. }
  232. }
  233. if ($tempTs2 >= $ts2) {
  234. break;
  235. }
  236. }
  237. if ($tuzhiNum > 0) {
  238. $price = $price . ";" . $tuzhiId . ',' . $tuzhiNum;
  239. }
  240. //---------------------
  241. $equipStr = explode(';', $gateMo->xunluo_equip_ts);
  242. $equipId = 0;
  243. $equipNum = 0;
  244. $tempTs3 = 0;
  245. foreach ($equipStr as $s) {
  246. $arr = explode('-', $s);
  247. $tsItemArr = explode(',', $arr[0]);
  248. $sTs = $tsItemArr[0]; //开始时间
  249. $eTs = $tsItemArr[1]; //终止时间
  250. $produceTs = $tsItemArr[2]; //间隔
  251. while (true) {
  252. $tempTs3 += $produceTs;
  253. if ($tempTs3 <= $eTs && $tempTs3 <= $ts2) {
  254. $sList = explode(',', $arr[1]);
  255. $equipId = $sList[0];
  256. $equipNum += $sList[1];
  257. }
  258. if ($tempTs3 >= $ts2) {
  259. break;
  260. }
  261. if ($tempTs3 >= $eTs) {
  262. $tempTs3 = $eTs;
  263. break;
  264. }
  265. }
  266. if ($tempTs3 >= $ts2) {
  267. break;
  268. }
  269. }
  270. if ($equipNum > 0) {
  271. $price = $price . ";" . $equipId . ',' . $equipNum;
  272. }
  273. StoreProc::AddMultiItemInStore($price);
  274. ctx()->gates->xunluo_StartTs = now();
  275. } else {//快速巡逻
  276. my_Assert(ctx()->gates->xunluo_quick_buyRecord < $gateMo->xueluo_quick_num, ErrCode::err_const_no);
  277. ctx()->gates->xunluo_quick_buyRecord += 1;
  278. ctx()->baseInfo->Consume_tili(15);
  279. StoreProc::AddMultiItemInStore($gateMo->xueluo_quick_reward);
  280. }
  281. UserProc::updateUserInfo();
  282. $ret = array(
  283. 'tili' => ctx()->baseInfo->tili,
  284. 'gates' => ctx()->gates,
  285. );
  286. return Resp::ok($ret);
  287. }
  288. public static function FightDailyClear() {
  289. //ctx()->gates->xunluo_quick_buyRecord = 0;
  290. ctx()->gates->fightSweepNum = 0;
  291. ctx()->gates()->TowerGateInfo()->RefreshSkillTimes = 0;
  292. ctx()->gates()->TowerGateInfo()->TodayChanNum = glc()->tower_daily_chanceNum;
  293. }
  294. /**
  295. * 6806 剧情回存
  296. * @return type
  297. */
  298. public static function PlotSav() {
  299. list($gateId) = req()->paras;
  300. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  301. ctx()->gates->GateList->$gateId->plotStart = 1;
  302. UserProc::updateUserInfo();
  303. $ret = array(
  304. 'ok' => 1,
  305. );
  306. return Resp::ok($ret);
  307. }
  308. // <editor-fold defaultstate="collapsed" desc="挑战模块">
  309. /**
  310. * 6810 挑战关卡: 更新锁定技能列表
  311. */
  312. public static function TowerUpdateLockskillList() {
  313. list($li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  314. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  315. $t->skill_zhudong = $li_zd;
  316. $t->skill_beidong = $li_bd;
  317. $t->skill_zhudong_lockState = $li_zds;
  318. $t->skill_beidong_lockState = $li_bds;
  319. UserProc::updateUserInfo();
  320. return Resp::ok();
  321. }
  322. /**
  323. * 6809 挑战关卡: 刷新初始技能(扣除免费次数/cost)
  324. */
  325. public static function TowerRefreshSkills() {
  326. list($isFree, $li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  327. if ($isFree) {
  328. if (ctx()->gates()->TowerGateInfo()->RefreshSkillTimes >= glc()->tower_daily_refreshChanceNum) {
  329. Err(ErrCode::tower_refreshNo); # 免费次数不足
  330. }
  331. } else {
  332. list($type, $num) = explode(':', glc()->tower_refreshCost); # 二级货币类型(1:金币,2:元宝):数量
  333. if ($type == 1) { # 金币
  334. my_Assert(ctx()->base()->Consume_Gold($num), ErrCode::notenough_gold_msg);
  335. } else if ($type == 2) { # 元宝
  336. my_Assert(ctx()->base()->Consume_Cash($num), ErrCode::notenough_cash_msg);
  337. } else {
  338. Err(ErrCode::err_const_no, "检查刷新扣费配置信息!");
  339. }
  340. }
  341. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  342. $t->RefreshSkillTimes++;
  343. $t->skill_zhudong = $li_zd;
  344. $t->skill_beidong = $li_bd;
  345. $t->skill_zhudong_lockState = $li_zds;
  346. $t->skill_beidong_lockState = $li_bds;
  347. UserProc::updateUserInfo();
  348. $ret = array(
  349. 'task' => ctx()->task,
  350. );
  351. return Resp::ok($ret);
  352. }
  353. /**
  354. * 6805
  355. * @return type
  356. * @deprecated since version 2024年5月17日 已合并到6801
  357. */
  358. public static function ChallengeGateStartFight() {
  359. // list($layerNum) = req()->paras;
  360. // if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # 起始层数校验
  361. // return Resp::err(ErrCode::tower_layerNum);
  362. // }
  363. // if (ctx()->gates()->TowerGateInfo()->TodayChanNum < 1) { # 剩余次数校验
  364. // return Resp::err(ErrCode::tower_timeNo);
  365. // }
  366. // ctx()->gates()->TowerGateInfo()->TodayChanNum--; # 增加次数
  367. // UserProc::updateUserInfo();
  368. // return Resp::ok();
  369. }
  370. /**
  371. * 6804 挑战关卡: 奖励领取
  372. * @return type
  373. */
  374. public static function GateChallengeRewards() {
  375. list($finalLayer) = req()->paras; # 战斗结束时的层数
  376. $lastLayer = ctx()->gates()->TowerGateInfo()->CurLayer;
  377. $arr = GameConfig::waves_getItemArray(self::TowerGateId);
  378. if ($finalLayer > $lastLayer) {
  379. foreach ($arr as $layerId => $layerMo) {
  380. if ($layerId >= $lastLayer && $layerId < $finalLayer) {
  381. my_Assert($layerMo != null, ErrCode::err_const_no);
  382. StoreProc::AddMultiItemInStore($layerMo->rewards); # 发放奖励
  383. }
  384. }
  385. ctx()->gates()->TowerGateInfo()->CurLayer = $finalLayer;
  386. UserProc::updateUserInfo();
  387. $ret = array(
  388. 'store' => ctx()->store,
  389. 'gold' => ctx()->base()->gold,
  390. 'cash' => ctx()->base()->cash,
  391. 'task' => ctx()->task,
  392. );
  393. return Resp::ok($ret);
  394. }
  395. return Resp::err(ErrCode::tower_rewardNo); # 没有奖励
  396. }
  397. // </editor-fold>
  398. /**
  399. * 6803 关卡选择
  400. * @return type
  401. */
  402. public static function SelectGate() {
  403. list($gateId) = req()->paras;
  404. ctx()->gates->CurrentGateId = $gateId;
  405. UserProc::updateUserInfo();
  406. $ret = array(
  407. 'gates' => ctx()->gates,
  408. );
  409. return Resp::ok($ret);
  410. }
  411. /**
  412. * 6802 章节宝箱的领取
  413. * @return type
  414. */
  415. public static function PassGateTsPrizeReceive() {
  416. list($gateId, $index) = req()->paras;
  417. $gateMo = GameConfig::gate_getItem($gateId);
  418. my_Assert($gateMo != null, ErrCode::err_const_no);
  419. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  420. $gateInfo = ctx()->gates->GateList->$gateId;
  421. $tag = false;
  422. $prize = "";
  423. $mask = 0;
  424. switch ($index) {
  425. case 1:
  426. $ts = $gateMo->first_ts1 * 60;
  427. if ($gateInfo->MaxSeconds >= $ts) {
  428. $tag = true;
  429. }
  430. $mask = 1;
  431. $prize = $gateMo->first_reward1;
  432. break;
  433. case 2:
  434. $ts = $gateMo->first_ts2 * 60;
  435. if ($gateInfo->MaxSeconds >= $ts) {
  436. $tag = true;
  437. }
  438. $mask = 2;
  439. $prize = $gateMo->first_reward2;
  440. break;
  441. case 3:
  442. if ($gateInfo->pass > 0) {
  443. $tag = true;
  444. }
  445. $mask = 3;
  446. $prize = $gateMo->first_reward3;
  447. break;
  448. default:
  449. break;
  450. }
  451. if ($tag) {
  452. my_Assert($mask > $gateInfo->FirstReward, ErrCode::gate_GatePriceHasReceive);
  453. $gateInfo->FirstReward = $mask;
  454. StoreProc::AddMultiItemInStore($prize);
  455. }
  456. ctx()->gates->GateList->$gateId = $gateInfo;
  457. UserProc::updateUserInfo();
  458. $ret = array(
  459. 'gates' => ctx()->gates,
  460. 'store' => ctx()->store,
  461. 'task' => ctx()->task,
  462. 'gold' => ctx()->baseInfo->gold,
  463. );
  464. return Resp::ok($ret);
  465. }
  466. /**
  467. * [6801]关卡战斗结算
  468. * @return type
  469. */
  470. public static function Settle() {
  471. list($resultType, $gateId, $gold, $curTs, $pickups,
  472. $finalLayer, $finalHpPercent, $killMonsterNum, $killBossNum) = req()->paras;
  473. # 客户端需要增加参数: killmonserNum,killBosssNum, finalHpPercent(最终血量百分比)
  474. $gateMo = GameConfig::gate_getItem($gateId);
  475. my_Assert($gateMo != null, ErrCode::err_const_no);
  476. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  477. $gateInfo = ctx()->gates->GateList->$gateId;
  478. $ts = $gateInfo->MaxSeconds;
  479. if ($curTs >= $ts) {
  480. $gateInfo->MaxSeconds = $curTs;
  481. }
  482. if ($resultType) { # 胜利
  483. if (ctx()->gates->GateList->$gateId->pass == 0) {
  484. ctx()->gates->GateList->$gateId->pass = 1;
  485. TaskProc::Day7TaskReset($gateId); # 刷新七日任务
  486. $maxGateId = ctx()->gates->maxPassGateId();
  487. if ($maxGateId > 0) {
  488. self::Ranking_MainGateIndex($maxGateId);
  489. }
  490. }
  491. TaskProc::OnPassGate_X($gateId); # 刷新任务进度: 通关第X关
  492. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  493. ctx()->gates()->UnlockNextPlotGate(); # 解锁下一主线关卡
  494. // ctx()->gates()->UnlockMainChallengeGate($gateId); # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  495. } else { # 不是主线关卡, 暂时没有其他逻辑
  496. }
  497. // StoreProc::AddMultiItemInStore($gateMo->reward_win); # 发放胜利奖励(2024.5.30 过期)
  498. }
  499. // else { # 失败
  500. //// StoreProc::AddMultiItemInStore($gateMo->reward_fail); # 发放失败奖励(2024.5.30 过期)
  501. // }
  502. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具直接入背包
  503. ctx()->base()->Add_Gold($gold); # 战场拾取的金币直接入背包
  504. //ctx()->base()->Add_Exp($exp);
  505. $waveMo = GameConfig::waveItem_getItem($gateId, $finalLayer);
  506. my_Assert(null != $waveMo, ErrCode::err_const_no);
  507. ctx()->base()->Add_Exp($waveMo->rewardExp); # 指挥官经验
  508. ctx()->base()->Add_Gold($waveMo->rewardGold); # 金币奖励
  509. $pickups .= ";1," . $gold + $waveMo->rewardGold;
  510. # 图纸奖励: 数量min-max, 部位随机
  511. if (strlen($waveMo->rewardTuZhi) > 0 && str_contains($waveMo->rewardTuZhi, '-')) {
  512. list($tz_min, $tz_max) = explode('-', $waveMo->rewardTuZhi); # 图纸数量
  513. $tz_n = rand($tz_min, $tz_max);
  514. # 图纸部位数据源 1001, 1002, 1003, 1004, 1005, 1006
  515. for ($i = 0; $i < $tz_n; $i++) {
  516. $id = 1000 + rand(1, 6);
  517. StoreProc::AddMultiItemInStore("$id,1"); # 获得图纸
  518. $pickups .= ";$id,1";
  519. }
  520. }
  521. # 宝石奖励: 数量min-max;品质:权重,品质:权重...
  522. if (strlen($waveMo->rewardGem) > 0) {
  523. list($gs_num, $gs_props) = explode(';', $waveMo->rewardGem);
  524. list($gem_min, $gem_max) = explode('-', $gs_num); # 宝石数量
  525. $gem_n = rand($gem_min, $gem_max);
  526. $arr = explode(",", $gs_props);
  527. $pool = array();
  528. $n = 0;
  529. foreach ($arr as $str) {
  530. list($qual, $props) = explode(':', $str);
  531. $pool[] = array('q' => $qual, 'p' => $props);
  532. $n += $props;
  533. }
  534. for ($i = 0; $i < $gem_n; $i++) { # 随机n块宝石
  535. $r = rand(0, $n); # 投色子
  536. $l = 0;
  537. foreach ($pool as $item) {
  538. if ($r < ($l + $item->p)) {
  539. $gemId = $item->q * 10000 + rand(1, 6) * 1000;
  540. StoreProc::PutGemInStore($gemId); # 发放宝石并退出本次投色子
  541. $pickups .= ";$gemId,1";
  542. break;
  543. }
  544. $l += $item->p; # 累计到下一段
  545. }
  546. }
  547. }
  548. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) { # 主线剧情,
  549. TaskProc::OnFightNumMainGate();
  550. } else if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainChallengeGate) { # 主线剧情对应的难度挑战
  551. TaskProc::OnFightNumChallengeGate();
  552. }
  553. TaskProc::OnKillCommonNumMonster($killMonsterNum);
  554. TaskProc::OnKillleaderNumMonster($killBossNum);
  555. UserProc::updateUserInfo();
  556. $ret = array(
  557. 'gates' => ctx()->gates,
  558. 'store' => ctx()->store,
  559. 'task' => ctx()->task,
  560. 'baseInfo' => ctx()->base(),
  561. 'gold' => $gold + $waveMo->rewardGold,
  562. 'exp' => $waveMo->rewardExp,
  563. 'rewardStr' => $pickups
  564. );
  565. return Resp::ok($ret);
  566. }
  567. /**
  568. * [6801]关卡战斗结算
  569. * @return type
  570. */
  571. public static function Settle_bak() {
  572. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  573. # 客户端需要增加参数: killmonserNum,killBosssNum, finalHpPercent(最终血量百分比)
  574. $gateMo = GameConfig::gate_getItem($gateId);
  575. my_Assert($gateMo != null, ErrCode::err_const_no);
  576. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  577. $gateInfo = ctx()->gates->GateList->$gateId;
  578. $ts = $gateInfo->MaxSeconds;
  579. if ($curTs >= $ts) {
  580. $gateInfo->MaxSeconds = $curTs;
  581. }
  582. if ($resultType) { # 胜利
  583. if (ctx()->gates->GateList->$gateId->pass == 0) {
  584. ctx()->gates->GateList->$gateId->pass = 1;
  585. TaskProc::Day7TaskReset($gateId);
  586. }
  587. TaskProc::OnPassGate_X($gateId);
  588. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  589. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  590. ctx()->gates->UnlockNextPlotGate();
  591. $dic = GameConfig::gate();
  592. $index = 0; # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  593. foreach ($dic as $id => $item) {
  594. if (Ins_GateInfo::GateTypeFromId($id) == Enum_GateType::MainChallengeGate && $item->challengeGateId == $gateId) {
  595. $index += 1;
  596. $gate = new Ins_GateInfo();
  597. $gate->GateId = $id;
  598. ctx()->gates->GateList->$id = $gate;
  599. }
  600. if ($index >= 3) {
  601. break;
  602. }
  603. }
  604. } else {
  605. }
  606. } else { # 失败
  607. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  608. }
  609. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  610. ctx()->baseInfo->Add_Gold($gold);
  611. //ctx()->baseInfo->Add_Exp($exp);
  612. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  613. TaskProc::OnFightNumMainGate();
  614. } else if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainChallengeGate) {
  615. TaskProc::OnFightNumChallengeGate();
  616. }
  617. TaskProc::OnKillCommonNumMonster(1000);
  618. TaskProc::OnKillleaderNumMonster(500);
  619. UserProc::updateUserInfo();
  620. $ret = array(
  621. 'gates' => ctx()->gates,
  622. 'store' => ctx()->store,
  623. 'task' => ctx()->task,
  624. );
  625. return Resp::ok($ret);
  626. }
  627. // <editor-fold defaultstate="collapsed" desc="排行榜">
  628. /**
  629. * 参与主线关卡排行榜
  630. * @param type $gateIndex
  631. */
  632. public static function Ranking_MainGateIndex($maxGateIndex) {
  633. $memKey = MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid);
  634. $mem = gMem();
  635. $uid = req()->uid;
  636. $arr = array();
  637. $arr["$uid"] = $maxGateIndex;
  638. $mem->zadd($memKey, $arr);
  639. $length = $mem->zlen($memKey);
  640. if ($length > glc()->Rank_MainGateIndex_OnListRank) {
  641. $num = $length - glc()->Rank_MainGateIndex_OnListRank;
  642. $mem->zremrangebyrank($memKey, 0, $num - 1);
  643. }
  644. }
  645. /**
  646. * 战力榜
  647. * @param type $gateIndex
  648. */
  649. public static function Ranking_FightPower() {
  650. $memKey = MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid);
  651. $mem = gMem();
  652. $arr = array();
  653. $uid = req()->uid;
  654. $power = 10;
  655. $arr["$uid"] = $power;
  656. $mem->zadd($memKey, $arr);
  657. $length = $mem->zlen($memKey);
  658. if ($length > glc()->Rank_FightPower_OnListRank) {
  659. $num = $length - glc()->Rank_FightPower_OnListRank;
  660. $mem->zremrangebyrank($memKey, 0, $num - 1);
  661. }
  662. }
  663. /**
  664. * 6811 获取主线关卡排行榜信息
  665. * @return type
  666. */
  667. public static function GetRankInfo() {
  668. list($type) = req()->paras;
  669. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  670. $selfExtraInfo = 0;
  671. $isExistFinishReward = false;
  672. if ($type == 1) {
  673. $list = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  674. $selfExtraInfo = ctx()->gates->UnlockedGatesMaxId;
  675. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  676. $dic = gMem()->hgetall($memKey);
  677. foreach ($dic as $gateId => $ins_rank) {
  678. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  679. $isExistFinishReward = true;
  680. break;
  681. }
  682. }
  683. } else {
  684. $list = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  685. $selfExtraInfo = 0; //战力还没有
  686. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  687. $dic = gMem()->hgetall($memKey);
  688. foreach ($dic as $fightPower => $ins_rank) {
  689. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  690. $isExistFinishReward = true;
  691. break;
  692. }
  693. }
  694. }
  695. $selfRank = self::initOtherUidRankInfo(req()->uid, $selfExtraInfo);
  696. $retArr = array();
  697. if (count($list) > 0) {
  698. foreach ($list as $uid => $score) {
  699. $rankInfo = self::initOtherUidRankInfo($uid, $score);
  700. if ($rankInfo->uid == req()->uid) {
  701. $selfIsHasRank = 1;
  702. $selfRank = $rankInfo;
  703. }
  704. $retArr[] = $rankInfo;
  705. }
  706. }
  707. UserProc::updateUserInfo();
  708. $ret = array(
  709. 'rankInfo' => $retArr,
  710. 'selfRank' => $selfRank,
  711. 'selfIsHasRank' => $selfIsHasRank,
  712. 'isExistFinishReward' => $isExistFinishReward,
  713. );
  714. return Resp::ok($ret);
  715. }
  716. /**
  717. * 初始化玩家rank
  718. * @param type $uid
  719. * @param type $score
  720. * @return \loyalsoft\Ins_rank
  721. */
  722. static function initOtherUidRankInfo($uid, $score) {
  723. $ins_rank = new Ins_rank();
  724. $lv = gMem()->zrank(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  725. if ($lv == null) {
  726. $lv = 0;
  727. }
  728. $ins_rank->rank = $lv + 1;
  729. $ins_rank->uid = $uid;
  730. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  731. $ins_rank->name = $userInfo->baseInfo->name;
  732. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  733. $ins_rank->score = $score;
  734. return $ins_rank;
  735. }
  736. /**
  737. * 6812 获取排行榜内玩家的装备信息
  738. * @return type
  739. */
  740. public static function GetUidEquipInfo_Rank() {
  741. list($uid) = req()->paras;
  742. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  743. $store = $userInfo->store;
  744. $heros = $userInfo->heros;
  745. UserProc::updateUserInfo();
  746. $ret = array(
  747. 'store' => $store,
  748. 'heros' => $heros,
  749. );
  750. return Resp::ok($ret);
  751. }
  752. /**
  753. * 通关奖励是否达成
  754. * @param type $maxGateIndex
  755. */
  756. public static function IsAchievedMainGate_PassReward($maxGateIndex) {
  757. $rewards = GameConfig::rank_passgatereward();
  758. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  759. foreach ($rewards as $passGateId => $mo) {
  760. if ($passGateId == $maxGateIndex && !gMem()->hexists($memKey, $maxGateIndex)) {
  761. $ins_rank = new Ins_rank();
  762. $ins_rank->uid = req()->uid;
  763. $ins_rank->name = ctx()->baseInfo->name;
  764. $ins_rank->headImg = ctx()->baseInfo->headImg;
  765. $ins_rank->score = $passGateId;
  766. gMem()->hset($memKey, $maxGateIndex, $ins_rank);
  767. break;
  768. }
  769. }
  770. }
  771. /*
  772. * 战力奖励是否达成
  773. */
  774. public static function IsAchievedFightPower_PassReward() {
  775. $power = 0; //临时
  776. $rewards = GameConfig::rank_fightpowerreward();
  777. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  778. foreach ($rewards as $fightPower => $mo) {
  779. if ($power >= $fightPower && !gMem()->hexists($memKey, $fightPower)) {
  780. $ins_rank = new Ins_rank();
  781. $ins_rank->uid = req()->uid;
  782. $ins_rank->name = ctx()->baseInfo->name;
  783. $ins_rank->headImg = ctx()->baseInfo->headImg;
  784. $ins_rank->score = $fightPower;
  785. gMem()->hset($memKey, $fightPower, $ins_rank);
  786. }
  787. }
  788. }
  789. /**
  790. * 6813
  791. * @return type
  792. */
  793. public static function GetmainGate_RankRewardInfo() {
  794. //list($type) = req()->paras;
  795. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  796. $dic = gMem()->hgetall($memKey);
  797. // $retArr = new \stdClass();
  798. // foreach ($dic as $gateId => $uid) {
  799. // $ins_rank = new Ins_rank();
  800. // $ins_rank->uid = $uid;
  801. // $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  802. // $ins_rank->name = $userInfo->baseInfo->name;
  803. // $ins_rank->headImg = $userInfo->baseInfo->headImg;
  804. // $ins_rank->score = $gateId;
  805. // $retArr->$gateId = $ins_rank;
  806. // }
  807. UserProc::updateUserInfo();
  808. $ret = array(
  809. 'rankReward' => $dic,
  810. );
  811. return Resp::ok($ret);
  812. }
  813. /**
  814. * 6814
  815. * @return type
  816. */
  817. public static function GetFightPower_RankRewardInfo() {
  818. //list($type) = req()->paras;
  819. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  820. $dic = gMem()->hgetall($memKey);
  821. // $retArr = new \stdClass();
  822. // foreach ($dic as $fightPower => $uid) {
  823. // $ins_rank = new Ins_rank();
  824. // $ins_rank->uid = $uid;
  825. // $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  826. // $ins_rank->name = $userInfo->baseInfo->name;
  827. // $ins_rank->headImg = $userInfo->baseInfo->headImg;
  828. // $ins_rank->score = $fightPower;
  829. // $retArr->$fightPower = $ins_rank;
  830. // }
  831. UserProc::updateUserInfo();
  832. $ret = array(
  833. 'rankReward' => $dic,
  834. );
  835. return Resp::ok($ret);
  836. }
  837. /**
  838. * 6815 领取通关荣誉榜奖励
  839. * @return type
  840. */
  841. public static function ReceiveRankReward_MainGate() {
  842. list($gateId) = req()->paras;
  843. my_Assert(!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate), ErrCode::rankReward_HasReceive);
  844. $mo = GameConfig::rank_passgatereward_getItem($gateId);
  845. my_Assert($mo != null, ErrCode::err_const_no);
  846. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  847. if (gMem()->hexists($memKey, $gateId)) {
  848. StoreProc::AddMultiItemInStore($mo->reward);
  849. ctx()->privateState->rankReward_drawed_MainGate[] = $gateId;
  850. }
  851. UserProc::updateUserInfo();
  852. $ret = array();
  853. return Resp::ok($ret);
  854. }
  855. /**
  856. * 6816 领取战力荣誉榜奖励
  857. * @return type
  858. */
  859. public static function ReceiveRankReward_FightPower() {
  860. list($fightPower) = req()->paras;
  861. my_Assert(!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower), ErrCode::rankReward_HasReceive);
  862. $mo = GameConfig::rank_passgatereward_getItem($fightPower);
  863. my_Assert($mo != null, ErrCode::err_const_no);
  864. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  865. if (gMem()->hexists($memKey, $fightPower)) {
  866. StoreProc::AddMultiItemInStore($mo->reward);
  867. ctx()->privateState->rankReward_drawed_fightPower[] = $fightPower;
  868. }
  869. UserProc::updateUserInfo();
  870. $ret = array();
  871. return Resp::ok($ret);
  872. }
  873. /*
  874. * 删除排行榜内注销账号的玩家
  875. */
  876. public static function DeleteRankInvalidUser($uid) {
  877. gMem()->zrem(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  878. gMem()->zrem(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
  879. }
  880. /*
  881. * 排行玩家头像变动
  882. */
  883. public static function UpdateRankUserHeadImg($uid,$headImg) {
  884. $memKey1 = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  885. $dic = gMem()->hgetall($memKey1);
  886. foreach ($dic as $gateId => $ins_rank) {
  887. if($ins_rank->uid == $uid){
  888. $ins_rank->headImg = $headImg;
  889. gMem()->hset($memKey1, $gateId, $ins_rank);
  890. }
  891. }
  892. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  893. $dic2 = gMem()->hgetall($memKey2);
  894. foreach ($dic2 as $fightPower => $ins_rank) {
  895. if($ins_rank->uid == $uid){
  896. $ins_rank->headImg = $headImg;
  897. gMem()->hset($memKey2, $fightPower, $ins_rank);
  898. }
  899. }
  900. }
  901. // </editor-fold>
  902. }