FightProc.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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. }
  487. TaskProc::OnPassGate_X($gateId); # 刷新任务进度: 通关第X关
  488. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  489. ctx()->gates()->UnlockNextPlotGate(); # 解锁下一主线关卡
  490. // ctx()->gates()->UnlockMainChallengeGate($gateId); # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  491. } else { # 不是主线关卡, 暂时没有其他逻辑
  492. }
  493. // StoreProc::AddMultiItemInStore($gateMo->reward_win); # 发放胜利奖励(2024.5.30 过期)
  494. }
  495. // else { # 失败
  496. //// StoreProc::AddMultiItemInStore($gateMo->reward_fail); # 发放失败奖励(2024.5.30 过期)
  497. // }
  498. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具直接入背包
  499. ctx()->base()->Add_Gold($gold); # 战场拾取的金币直接入背包
  500. //ctx()->base()->Add_Exp($exp);
  501. $waveMo = GameConfig::waveItem_getItem($gateId, $finalLayer);
  502. my_Assert(null != $waveMo, ErrCode::err_const_no);
  503. ctx()->base()->Add_Exp($waveMo->rewardExp); # 指挥官经验
  504. ctx()->base()->Add_Gold($waveMo->rewardGold); # 金币奖励
  505. # 图纸奖励: 数量min-max, 部位随机
  506. if (strlen($waveMo->rewardTuZhi) > 0 && str_contains($waveMo->rewardTuZhi, '-')) {
  507. list($tz_min, $tz_max) = str_split($waveMo->rewardTuZhi); # 图纸数量
  508. $tz_n = rand($tz_min, $tz_max);
  509. # 图纸部位数据源 1001, 1002, 1003, 1004, 1005, 1006
  510. for ($i = 0; $i < $tz_n; $i++) {
  511. $id = 1000 + rand(1, 6);
  512. StoreProc::AddMultiItemInStore("$id,1"); # 获得图纸
  513. $pickups .= ";$id,1";
  514. }
  515. }
  516. # 宝石奖励: 数量min-max;品质:权重,品质:权重...
  517. if (strlen($waveMo->rewardGem) > 0) {
  518. list($gs_num, $gs_props) = str_split($waveMo->rewardGem, ';');
  519. list($gem_min, $gem_max) = str_split($gs_num); # 宝石数量
  520. $gem_n = rand($gem_min, $gem_max);
  521. $arr = str_split($gs_props, ",");
  522. $pool = array();
  523. $n = 0;
  524. foreach ($arr as $str) {
  525. list($qual, $props) = str_split($str, ':');
  526. $pool[] = array('q' => $qual, 'p' => $props);
  527. $n += $props;
  528. }
  529. for ($i = 0; $i < $gem_n; $i++) { # 随机n块宝石
  530. $r = rand($n); # 投色子
  531. $l = 0;
  532. foreach ($pool as $item) {
  533. if ($r < ($l + $item->p)) {
  534. $gemId = $item->q * 10000 + rand(6) * 1000;
  535. StoreProc::PutGemInStore($gemId); # 发放宝石并退出本次投色子
  536. $pickups .= ";$gemId,1";
  537. break;
  538. }
  539. $l += $item->p; # 累计到下一段
  540. }
  541. }
  542. }
  543. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) { # 主线剧情,
  544. TaskProc::OnFightNumMainGate();
  545. } else if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainChallengeGate) { # 主线剧情对应的难度挑战
  546. TaskProc::OnFightNumChallengeGate();
  547. }
  548. TaskProc::OnKillCommonNumMonster($killMonsterNum);
  549. TaskProc::OnKillleaderNumMonster($killBossNum);
  550. UserProc::updateUserInfo();
  551. $ret = array(
  552. 'gates' => ctx()->gates,
  553. 'store' => ctx()->store,
  554. 'task' => ctx()->task,
  555. 'baseInfo' => ctx()->base(),
  556. 'gold' => $gold + $waveMo->rewardGold,
  557. 'exp' => $waveMo->rewardExp,
  558. 'rewardStr' => $pickups
  559. );
  560. return Resp::ok($ret);
  561. }
  562. /**
  563. * [6801]关卡战斗结算
  564. * @return type
  565. */
  566. public static function Settle_bak() {
  567. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  568. # 客户端需要增加参数: killmonserNum,killBosssNum, finalHpPercent(最终血量百分比)
  569. $gateMo = GameConfig::gate_getItem($gateId);
  570. my_Assert($gateMo != null, ErrCode::err_const_no);
  571. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  572. $gateInfo = ctx()->gates->GateList->$gateId;
  573. $ts = $gateInfo->MaxSeconds;
  574. if ($curTs >= $ts) {
  575. $gateInfo->MaxSeconds = $curTs;
  576. }
  577. if ($resultType) { # 胜利
  578. if (ctx()->gates->GateList->$gateId->pass == 0) {
  579. ctx()->gates->GateList->$gateId->pass = 1;
  580. TaskProc::Day7TaskReset($gateId);
  581. }
  582. TaskProc::OnPassGate_X($gateId);
  583. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  584. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  585. ctx()->gates->UnlockNextPlotGate();
  586. $dic = GameConfig::gate();
  587. $index = 0; # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  588. foreach ($dic as $id => $item) {
  589. if (Ins_GateInfo::GateTypeFromId($id) == Enum_GateType::MainChallengeGate && $item->challengeGateId == $gateId) {
  590. $index += 1;
  591. $gate = new Ins_GateInfo();
  592. $gate->GateId = $id;
  593. ctx()->gates->GateList->$id = $gate;
  594. }
  595. if ($index >= 3) {
  596. break;
  597. }
  598. }
  599. } else {
  600. }
  601. } else { # 失败
  602. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  603. }
  604. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  605. ctx()->baseInfo->Add_Gold($gold);
  606. //ctx()->baseInfo->Add_Exp($exp);
  607. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  608. TaskProc::OnFightNumMainGate();
  609. } else if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainChallengeGate) {
  610. TaskProc::OnFightNumChallengeGate();
  611. }
  612. TaskProc::OnKillCommonNumMonster(1000);
  613. TaskProc::OnKillleaderNumMonster(500);
  614. UserProc::updateUserInfo();
  615. $ret = array(
  616. 'gates' => ctx()->gates,
  617. 'store' => ctx()->store,
  618. 'task' => ctx()->task,
  619. );
  620. return Resp::ok($ret);
  621. }
  622. // <editor-fold defaultstate="collapsed" desc="排行榜">
  623. /**
  624. * 参与主线关卡排行榜
  625. * @param type $gateIndex
  626. */
  627. public static function Ranking_MainGateIndex($maxGateIndex) {
  628. $memKey = MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid);
  629. $mem = gMem();
  630. $arr = array();
  631. $uid = req()->uid;
  632. $arr["$uid"] = $maxGateIndex;
  633. $mem->zadd($memKey, $arr);
  634. $length = $mem->zlen($memKey);
  635. if ($length > glc()->Rank_MainGateIndex_OnListRank) {
  636. $num = $length - glc()->Rank_MainGateIndex_OnListRank;
  637. $mem->zremrangebyrank($memKey, 0, $num - 1);
  638. }
  639. }
  640. /**
  641. * 战力榜
  642. * @param type $gateIndex
  643. */
  644. public static function Ranking_FightPower() {
  645. $memKey = MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid);
  646. $mem = gMem();
  647. $arr = array();
  648. $uid = req()->uid;
  649. $power = 10;
  650. $arr["$uid"] = $power;
  651. $mem->zadd($memKey, $arr);
  652. $length = $mem->zlen($memKey);
  653. if ($length > glc()->Rank_FightPower_OnListRank) {
  654. $num = $length - glc()->Rank_FightPower_OnListRank;
  655. $mem->zremrangebyrank($memKey, 0, $num - 1);
  656. }
  657. }
  658. /**
  659. * 6811 获取主线关卡排行榜信息
  660. * @return type
  661. */
  662. public static function GetRankInfo() {
  663. list($type) = req()->paras;
  664. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  665. $selfExtraInfo = 0;
  666. if ($type == 1) {
  667. $list = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  668. $selfExtraInfo = ctx()->gates->UnlockedGatesMaxId;
  669. } else {
  670. $list = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  671. $selfExtraInfo = 0; //战力还没有
  672. }
  673. $selfRank = self::initOtherUidRankInfo(req()->uid, $selfExtraInfo);
  674. $retArr = array();
  675. if (count($list) > 0) {
  676. foreach ($list as $uid => $score) {
  677. $rankInfo = self::initOtherUidRankInfo($uid, $score);
  678. if ($rankInfo->uid == req()->uid) {
  679. $selfIsHasRank = 1;
  680. $selfRank = $rankInfo;
  681. }
  682. $retArr[] = $rankInfo;
  683. }
  684. }
  685. UserProc::updateUserInfo();
  686. $ret = array(
  687. 'rankInfo' => $retArr,
  688. 'selfRank' => $selfRank,
  689. 'selfIsHasRank' => $selfIsHasRank,
  690. );
  691. return Resp::ok($ret);
  692. }
  693. /**
  694. * 初始化玩家rank
  695. * @param type $uid
  696. * @param type $score
  697. * @return \loyalsoft\Ins_rank
  698. */
  699. static function initOtherUidRankInfo($uid, $score) {
  700. $ins_rank = new Ins_rank();
  701. $lv = gMem()->zrank(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  702. if ($lv == null) {
  703. $lv = 0;
  704. }
  705. $ins_rank->rank = $lv + 1;
  706. $ins_rank->uid = $uid;
  707. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  708. $ins_rank->name = $userInfo->baseInfo->name;
  709. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  710. $ins_rank->score = $score;
  711. return $ins_rank;
  712. }
  713. /**
  714. * 6812 获取排行榜内玩家的装备信息
  715. * @return type
  716. */
  717. public static function GetUidEquipInfo_Rank() {
  718. list($uid) = req()->paras;
  719. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  720. $store = $userInfo->store;
  721. $heros = $userInfo->heros;
  722. UserProc::updateUserInfo();
  723. $ret = array(
  724. 'store' => $store,
  725. 'heros' => $heros,
  726. );
  727. return Resp::ok($ret);
  728. }
  729. /**
  730. * 通关奖励是否达成
  731. * @param type $maxGateIndex
  732. */
  733. public static function IsAchievedMainGate_PassReward($maxGateIndex) {
  734. $rewards = GameConfig::rank_passgatereward();
  735. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  736. foreach ($rewards as $passGateId => $mo) {
  737. if ($passGateId == $maxGateIndex && !gMem()->hexists($memKey, $maxGateIndex)) {
  738. gMem()->hset($memKey, $maxGateIndex, req()->uid);
  739. break;
  740. }
  741. }
  742. }
  743. /*
  744. * 战力奖励是否达成
  745. */
  746. public static function IsAchievedFightPower_PassReward() {
  747. $power = 0; //临时
  748. $rewards = GameConfig::rank_fightpowerreward();
  749. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  750. foreach ($rewards as $fightPower => $mo) {
  751. if ($power >= $fightPower && !gMem()->hexists($memKey, $fightPower)) {
  752. gMem()->hset($memKey, $fightPower, req()->uid);
  753. }
  754. }
  755. }
  756. /**
  757. * 6813
  758. * @return type
  759. */
  760. public static function GetmainGate_RankRewardInfo() {
  761. //list($type) = req()->paras;
  762. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  763. $dic = gMem()->hgetall($memKey);
  764. $retArr = new \stdClass();
  765. foreach ($dic as $gateId => $uid) {
  766. $ins_rank = new Ins_rank();
  767. $ins_rank->uid = $uid;
  768. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  769. $ins_rank->name = $userInfo->baseInfo->name;
  770. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  771. $ins_rank->score = $gateId;
  772. $retArr->$gateId = $ins_rank;
  773. }
  774. UserProc::updateUserInfo();
  775. $ret = array(
  776. 'rankReward' => $retArr,
  777. );
  778. return Resp::ok($ret);
  779. }
  780. /**
  781. * 6814
  782. * @return type
  783. */
  784. public static function GetFightPower_RankRewardInfo() {
  785. //list($type) = req()->paras;
  786. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  787. $dic = gMem()->hgetall($memKey);
  788. $retArr = new \stdClass();
  789. foreach ($dic as $fightPower => $uid) {
  790. $ins_rank = new Ins_rank();
  791. $ins_rank->uid = $uid;
  792. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  793. $ins_rank->name = $userInfo->baseInfo->name;
  794. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  795. $ins_rank->score = $fightPower;
  796. $retArr->$fightPower = $ins_rank;
  797. }
  798. UserProc::updateUserInfo();
  799. $ret = array(
  800. 'rankReward' => $retArr,
  801. );
  802. return Resp::ok($ret);
  803. }
  804. /**
  805. * 6815 领取通关荣誉榜奖励
  806. * @return type
  807. */
  808. public static function ReceiveRankReward_MainGate() {
  809. list($gateId) = req()->paras;
  810. my_Assert(!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate), ErrCode::rankReward_HasReceive);
  811. $mo = GameConfig::rank_passgatereward_getItem($gateId);
  812. my_Assert($mo != null, ErrCode::err_const_no);
  813. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  814. if (gMem()->hexists($memKey, $gateId)) {
  815. StoreProc::AddMultiItemInStore($mo->reward);
  816. ctx()->privateState->rankReward_drawed_MainGate[] = $gateId;
  817. }
  818. UserProc::updateUserInfo();
  819. $ret = array();
  820. return Resp::ok($ret);
  821. }
  822. /**
  823. * 6816 领取战力荣誉榜奖励
  824. * @return type
  825. */
  826. public static function ReceiveRankReward_FightPower() {
  827. list($fightPower) = req()->paras;
  828. my_Assert(!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower), ErrCode::rankReward_HasReceive);
  829. $mo = GameConfig::rank_passgatereward_getItem($fightPower);
  830. my_Assert($mo != null, ErrCode::err_const_no);
  831. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  832. if (gMem()->hexists($memKey, $fightPower)) {
  833. StoreProc::AddMultiItemInStore($mo->reward);
  834. ctx()->privateState->rankReward_drawed_fightPower[] = $fightPower;
  835. }
  836. UserProc::updateUserInfo();
  837. $ret = array();
  838. return Resp::ok($ret);
  839. }
  840. // </editor-fold>
  841. }