FightProc.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 战斗模块
  5. * @author c'y'zhao
  6. */
  7. class FightProc {
  8. /**
  9. * 逻辑分发
  10. * 所有的Proc中必须有这样一个方法
  11. * @param Req $req
  12. */
  13. public static function procMain($req) {
  14. switch ($req->cmd) {
  15. case CmdCode::fight_settle: # 6801 主线战斗结算
  16. return FightProc::Settle();
  17. case CmdCode::fight_PassGateTsPrizeReceive: # 6802 章节宝箱的领取
  18. return FightProc::PassGateTsPrizeReceive();
  19. case CmdCode::fight_selectGate: # 6803 主线剧情关卡选择
  20. return FightProc::SelectGate();
  21. case CmdCode::fight_gateChallengeRewards: # 6804 挑战关卡: 领取奖励
  22. return FightProc::GateChallengeRewards();
  23. case CmdCode::fihgt_towerStart: # 6805 挑战关卡: 开始挑战
  24. return FightProc::ChallengeGateStartFight();
  25. case CmdCode::fight_plotSav: # 6806 主线剧情(已播放)回存
  26. return FightProc::PlotSav();
  27. case CmdCode::fight_sweep: # 6807 主线扫荡
  28. return FightProc::FightSweep();
  29. case CmdCode::fight_startFight: # 6808 主线剧情关卡开始挑战
  30. return self::StartFight();
  31. case CmdCode::fight_tower_RefreshSkills: # 6809 挑战关卡: 刷新初始技能
  32. return self::TowerRefreshSkills();
  33. case CmdCode::fight_tower_updatelocklist: # 6810 挑战关卡: 更新技能锁定列表
  34. return self::TowerUpdateLockskillList();
  35. default:
  36. Err(ErrCode::cmd_err);
  37. }
  38. }
  39. /**
  40. * 6807 扫荡
  41. * @return type
  42. */
  43. public static function FightSweep() {
  44. //list($gateId) = req()->paras;
  45. my_Assert(ctx()->gates->UnlockedGatesMaxId != 0, ErrCode::gate_NoSweep);
  46. $mo = GameConfig::gate_getItem(ctx()->gates->UnlockedGatesMaxId);
  47. $costTili = glc()->sweep_cost_tili;
  48. my_Assert(ctx()->baseInfo->tili >= $costTili, ErrCode::notenough_tili);
  49. $max = glc()->sweepMaxNum;
  50. my_Assert(ctx()->gates->fightSweepNum < $max, ErrCode::gate_SweepMaxNum_limit);
  51. ctx()->gates->fightSweepNum += 1;
  52. ctx()->baseInfo->Consume_tili($costTili);
  53. $prizeArr = array();
  54. $prizeArr[] = $mo->reward_win;
  55. if ($mo->sweep_gold != null) {
  56. $goodsStr = self::sweepRandReward($mo->sweep_gold);
  57. $prizeArr[] = $goodsStr;
  58. StoreProc::AddMultiItemInStore($goodsStr);
  59. }
  60. if ($mo->sweep_tuzhi != null) {
  61. $goodsStr = self::sweepRandReward($mo->sweep_tuzhi);
  62. $prizeArr[] = $goodsStr;
  63. StoreProc::AddMultiItemInStore($goodsStr);
  64. }
  65. if ($mo->sweep_gem != null) {
  66. $goodsStr = self::sweepRandReward($mo->sweep_gem);
  67. $list = explode(',', $goodsStr);
  68. $posId = rand(1, 6);
  69. $qual = $list[0];
  70. $dic = GameConfig::gem();
  71. foreach ($dic as $key => $gemMo) {
  72. if ($gemMo->qual == $qual && $gemMo->position == $posId) {
  73. $prizeArr[] = $gemMo->typeId . ',' . $list[1];
  74. StoreProc::PutGemInStore($gemMo->typeId, $list[1]);
  75. break;
  76. }
  77. }
  78. }
  79. if ($mo->sweep_qiling != null) {
  80. $goodsStr = self::sweepRandReward($mo->sweep_qiling);
  81. $prizeArr[] = $goodsStr;
  82. StoreProc::AddMultiItemInStore($goodsStr);
  83. }
  84. UserProc::updateUserInfo();
  85. $ret = array(
  86. 'tili' => ctx()->baseInfo->tili,
  87. 'fightSweepNum' => ctx()->gates->fightSweepNum,
  88. 'prizeArr' => $prizeArr,
  89. 'store' => ctx()->store,
  90. );
  91. return Resp::ok($ret);
  92. }
  93. static function sweepRandReward($rewardStr) {
  94. $ctxArr = explode(';', $rewardStr);
  95. $numArr = explode('-', $ctxArr[0]);
  96. $num = rand($numArr[0], $numArr[1]);
  97. $randNum = rand(1, 100);
  98. $start = 0;
  99. $end = 0;
  100. $res = "";
  101. $itemArr = explode(',', $ctxArr[1]);
  102. foreach ($itemArr as $str) {
  103. $arr = explode(':', $str);
  104. $itemId = $arr[0];
  105. $per = $arr[1];
  106. $end += $per;
  107. if ($randNum >= $start && $randNum < $end) {
  108. $res = $itemId;
  109. break;
  110. }
  111. $start = $end;
  112. }
  113. return $res . ',' . $num;
  114. }
  115. /**
  116. * 6808 开始挑战 (主线关卡:扣除体力, 挑战关卡: 增加次数)
  117. */
  118. private static function StartFight() {
  119. list($gateId) = req()->paras;
  120. my_Assert($gateId > 0, ErrCode::paras_err);
  121. $mo = GameConfig::gate_getItem($gateId);
  122. my_Assert(null != $mo, ErrCode::err_const_no);
  123. if (Ints::Slice($gateId, 0, 1) == 9) { # 爬塔模式
  124. list($layerNum) = req()->paras;
  125. if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # 起始层数校验
  126. Err(ErrCode::tower_layerNum);
  127. }
  128. if (ctx()->gates()->TowerGateInfo()->TodayChanNum > glc()->tower_daily_chanceNum) { # 剩余次数校验
  129. Err(ErrCode::tower_timeNo);
  130. }
  131. ctx()->gates()->TowerGateInfo()->TodayChanNum++; # 增加次数
  132. } else { # 主线剧情
  133. my_Assert(ctx()->base()->Consume_tili($mo->cost_tili), ErrCode::notenough_tili);
  134. }
  135. UserProc::updateUserInfo();
  136. return Resp::ok(array("tili" => ctx()->baseInfo->tili, "tili_ts" => ctx()->baseInfo->tili_ts));
  137. }
  138. /**
  139. * [废弃] 6807 巡逻奖励领取
  140. * @return type
  141. */
  142. public static function XunluoPrizeReceived() {
  143. list($type) = req()->paras;
  144. $gateId = ctx()->gates->UnlockedGatesMaxId;
  145. $gateMo = GameConfig::gate_getItem($gateId);
  146. my_Assert($gateMo != null, ErrCode::err_const_no);
  147. if ($type == 1) {//巡逻
  148. $curTs = now();
  149. $startTs = ctx()->gates->xunluo_StartTs;
  150. $ts = $curTs - $startTs;
  151. $ts2 = intval($ts / 60); //总的分钟数
  152. $fenzhong = intval($ts2 / 10); //有几个10分钟
  153. $gold = 0;
  154. $exp = 0;
  155. $price = "";
  156. if ($fenzhong > 0) {
  157. $gold = intval($gateMo->gold_xunluo / 6 * $fenzhong);
  158. $exp = intval($gateMo->exp_xunluo / 6 * $fenzhong);
  159. $price = "1," . $gold . ';' . "4," . $exp;
  160. }
  161. $itemStr = explode(';', $gateMo->xunluo_item_ts);
  162. $itemId = 0;
  163. $itemNum = 0;
  164. $tempTs = 0;
  165. foreach ($itemStr as $s) {
  166. $arr = explode('-', $s);
  167. $tsItemArr = explode(',', $arr[0]);
  168. $sTs = $tsItemArr[0]; //开始时间
  169. $eTs = $tsItemArr[1]; //终止时间
  170. $produceTs = $tsItemArr[2]; //间隔
  171. while (true) {
  172. $tempTs += $produceTs;
  173. if ($tempTs <= $eTs && $tempTs <= $ts2) {
  174. $sList = explode(',', $arr[1]);
  175. $itemId = $sList[0];
  176. $itemNum += $sList[1];
  177. }
  178. if ($tempTs >= $ts2) {
  179. break;
  180. }
  181. if ($tempTs >= $eTs) {
  182. $tempTs = $eTs;
  183. break;
  184. }
  185. }
  186. if ($tempTs >= $ts2) {
  187. break;
  188. }
  189. }
  190. if ($itemNum > 0) {
  191. $price = $price . ";" . $itemId . ',' . $itemNum;
  192. }
  193. //---------------------------
  194. $tuzhiStr = explode(';', $gateMo->xunluo_tuzhi_ts);
  195. $tuzhiId = 0;
  196. $tuzhiNum = 0;
  197. $tempTs2 = 0;
  198. foreach ($tuzhiStr as $s) {
  199. $arr = explode('-', $s);
  200. $tsItemArr = explode(',', $arr[0]);
  201. $sTs = $tsItemArr[0]; //开始时间
  202. $eTs = $tsItemArr[1]; //终止时间
  203. $produceTs = $tsItemArr[2]; //间隔
  204. while (true) {
  205. $tempTs2 += $produceTs;
  206. if ($tempTs2 <= $eTs && $tempTs2 <= $ts2) {
  207. $sList = explode(',', $arr[1]);
  208. $tuzhiId = $sList[0];
  209. $tuzhiNum += $sList[1];
  210. }
  211. if ($tempTs2 >= $ts2) {
  212. break;
  213. }
  214. if ($tempTs2 >= $eTs) {
  215. $tempTs2 = $eTs;
  216. break;
  217. }
  218. }
  219. if ($tempTs2 >= $ts2) {
  220. break;
  221. }
  222. }
  223. if ($tuzhiNum > 0) {
  224. $price = $price . ";" . $tuzhiId . ',' . $tuzhiNum;
  225. }
  226. //---------------------
  227. $equipStr = explode(';', $gateMo->xunluo_equip_ts);
  228. $equipId = 0;
  229. $equipNum = 0;
  230. $tempTs3 = 0;
  231. foreach ($equipStr as $s) {
  232. $arr = explode('-', $s);
  233. $tsItemArr = explode(',', $arr[0]);
  234. $sTs = $tsItemArr[0]; //开始时间
  235. $eTs = $tsItemArr[1]; //终止时间
  236. $produceTs = $tsItemArr[2]; //间隔
  237. while (true) {
  238. $tempTs3 += $produceTs;
  239. if ($tempTs3 <= $eTs && $tempTs3 <= $ts2) {
  240. $sList = explode(',', $arr[1]);
  241. $equipId = $sList[0];
  242. $equipNum += $sList[1];
  243. }
  244. if ($tempTs3 >= $ts2) {
  245. break;
  246. }
  247. if ($tempTs3 >= $eTs) {
  248. $tempTs3 = $eTs;
  249. break;
  250. }
  251. }
  252. if ($tempTs3 >= $ts2) {
  253. break;
  254. }
  255. }
  256. if ($equipNum > 0) {
  257. $price = $price . ";" . $equipId . ',' . $equipNum;
  258. }
  259. StoreProc::AddMultiItemInStore($price);
  260. ctx()->gates->xunluo_StartTs = now();
  261. } else {//快速巡逻
  262. my_Assert(ctx()->gates->xunluo_quick_buyRecord < $gateMo->xueluo_quick_num, ErrCode::err_const_no);
  263. ctx()->gates->xunluo_quick_buyRecord += 1;
  264. ctx()->baseInfo->Consume_tili(15);
  265. StoreProc::AddMultiItemInStore($gateMo->xueluo_quick_reward);
  266. }
  267. UserProc::updateUserInfo();
  268. $ret = array(
  269. 'tili' => ctx()->baseInfo->tili,
  270. 'gates' => ctx()->gates,
  271. );
  272. return Resp::ok($ret);
  273. }
  274. public static function FightDailyClear() {
  275. //ctx()->gates->xunluo_quick_buyRecord = 0;
  276. ctx()->gates->fightSweepNum = 0;
  277. ctx()->gates()->TowerGateInfo()->RefreshSkillTimes = 0;
  278. ctx()->gates()->TowerGateInfo()->TodayChanNum = 0;
  279. }
  280. /**
  281. * 6806 剧情回存
  282. * @return type
  283. */
  284. public static function PlotSav() {
  285. list($gateId) = req()->paras;
  286. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  287. ctx()->gates->GateList->$gateId->plotStart = 1;
  288. UserProc::updateUserInfo();
  289. $ret = array(
  290. 'ok' => 1,
  291. );
  292. return Resp::ok($ret);
  293. }
  294. // <editor-fold defaultstate="collapsed" desc="挑战模块">
  295. /**
  296. * 6810 挑战关卡: 更新锁定技能列表
  297. */
  298. public static function TowerUpdateLockskillList() {
  299. list($li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  300. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  301. $t->skill_zhudong = $li_zd;
  302. $t->skill_beidong = $li_bd;
  303. $t->skill_zhudong_lockState = $li_zds;
  304. $t->skill_beidong_lockState = $li_bds;
  305. UserProc::updateUserInfo();
  306. return Resp::ok();
  307. }
  308. /**
  309. * 6809 挑战关卡: 刷新初始技能(扣除免费次数/cost)
  310. */
  311. public static function TowerRefreshSkills() {
  312. list($isFree, $li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  313. if ($isFree) {
  314. if (ctx()->gates()->TowerGateInfo()->RefreshSkillTimes >= glc()->tower_daily_refreshChanceNum) {
  315. Err(ErrCode::tower_refreshNo); # 免费次数不足
  316. }
  317. } else {
  318. list($type, $num) = explode(':', glc()->tower_refreshCost); # 二级货币类型(1:金币,2:元宝):数量
  319. if ($type == 1) { # 金币
  320. my_Assert(ctx()->base()->Consume_Gold($num), ErrCode::notenough_gold_msg);
  321. } else if ($type == 2) { # 元宝
  322. my_Assert(ctx()->base()->Consume_Cash($num), ErrCode::notenough_cash_msg);
  323. } else {
  324. Err(ErrCode::err_const_no, "检查刷新扣费配置信息!");
  325. }
  326. }
  327. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  328. $t->RefreshSkillTimes++;
  329. $t->skill_zhudong = $li_zd;
  330. $t->skill_beidong = $li_bd;
  331. $t->skill_zhudong_lockState = $li_zds;
  332. $t->skill_beidong_lockState = $li_bds;
  333. UserProc::updateUserInfo();
  334. return Resp::ok();
  335. }
  336. /**
  337. * 6805
  338. * @return type
  339. * @deprecated since version 2024年5月17日
  340. */
  341. public static function ChallengeGateStartFight() {
  342. list($layerNum) = req()->paras;
  343. if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # 起始层数校验
  344. return Resp::err(ErrCode::tower_layerNum);
  345. }
  346. if (ctx()->gates()->TowerGateInfo()->TodayChanNum > glc()->tower_daily_chanceNum) { # 剩余次数校验
  347. return Resp::err(ErrCode::tower_timeNo);
  348. }
  349. ctx()->gates()->TowerGateInfo()->TodayChanNum++; # 增加次数
  350. UserProc::updateUserInfo();
  351. return Resp::ok();
  352. }
  353. /**
  354. * 6804 挑战关卡: 奖励领取
  355. * @return type
  356. */
  357. public static function GateChallengeRewards() {
  358. list($finalLayer) = req()->paras; # 战斗结束时的层数
  359. $lastLayer = ctx()->gates()->TowerGateInfo()->CurLayer;
  360. if ($finalLayer > $lastLayer) {
  361. for ($layerId = $lastLayer; $layerId++; $layerId < $finalLayer) {
  362. $layerMo = GameConfig::tower_gate_getItem($layerId);
  363. my_Assert($layerMo != null, ErrCode::err_const_no);
  364. StoreProc::AddMultiItemInStore($layerMo->rewards); # 发放奖励
  365. }
  366. ctx()->gates()->TowerGateInfo()->CurLayer = $finalLayer;
  367. UserProc::updateUserInfo();
  368. $ret = array(
  369. 'store' => ctx()->store,
  370. 'gold' => ctx()->base()->gold,
  371. 'cash' => ctx()->base()->cash
  372. );
  373. return Resp::ok($ret);
  374. }
  375. return Resp::err(ErrCode::tower_rewardNo); # 没有奖励
  376. }
  377. // </editor-fold>
  378. /**
  379. * 6803 关卡选择
  380. * @return type
  381. */
  382. public static function SelectGate() {
  383. list($gateId) = req()->paras;
  384. ctx()->gates->CurrentGateId = $gateId;
  385. UserProc::updateUserInfo();
  386. $ret = array(
  387. 'gates' => ctx()->gates,
  388. );
  389. return Resp::ok($ret);
  390. }
  391. /**
  392. * 6802 章节宝箱的领取
  393. * @return type
  394. */
  395. public static function PassGateTsPrizeReceive() {
  396. list($gateId, $index) = req()->paras;
  397. $gateMo = GameConfig::gate_getItem($gateId);
  398. my_Assert($gateMo != null, ErrCode::err_const_no);
  399. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  400. $gateInfo = ctx()->gates->GateList->$gateId;
  401. $tag = false;
  402. $prize = "";
  403. $mask = 0;
  404. switch ($index) {
  405. case 1:
  406. $ts = $gateMo->first_ts1 * 60;
  407. if ($gateInfo->MaxSeconds >= $ts) {
  408. $tag = true;
  409. }
  410. $mask = 1;
  411. $prize = $gateMo->first_reward1;
  412. break;
  413. case 2:
  414. $ts = $gateMo->first_ts2 * 60;
  415. if ($gateInfo->MaxSeconds >= $ts) {
  416. $tag = true;
  417. }
  418. $mask = 2;
  419. $prize = $gateMo->first_reward2;
  420. break;
  421. case 3:
  422. if ($gateInfo->pass > 0) {
  423. $tag = true;
  424. }
  425. $mask = 3;
  426. $prize = $gateMo->first_reward3;
  427. break;
  428. default:
  429. break;
  430. }
  431. if ($tag) {
  432. my_Assert($mask > $gateInfo->FirstReward, ErrCode::gate_GatePriceHasReceive);
  433. $gateInfo->FirstReward = $mask;
  434. StoreProc::AddMultiItemInStore($prize);
  435. }
  436. ctx()->gates->GateList->$gateId = $gateInfo;
  437. UserProc::updateUserInfo();
  438. $ret = array(
  439. 'gates' => ctx()->gates,
  440. 'store' => ctx()->store,
  441. );
  442. return Resp::ok($ret);
  443. }
  444. /**
  445. * [6801]关卡战斗结算
  446. * @return type
  447. */
  448. public static function Settle() {
  449. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  450. $gateMo = GameConfig::gate_getItem($gateId);
  451. my_Assert($gateMo != null, ErrCode::err_const_no);
  452. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  453. $gateInfo = ctx()->gates->GateList->$gateId;
  454. $ts = $gateInfo->MaxSeconds;
  455. if ($curTs >= $ts) {
  456. $gateInfo->MaxSeconds = $curTs;
  457. }
  458. if ($resultType) { # 胜利
  459. if (ctx()->gates->GateList->$gateId->pass == 0) {
  460. ctx()->gates->GateList->$gateId->pass = 1;
  461. }
  462. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  463. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  464. ctx()->gates->UnlockNextPlotGate();
  465. $dic = GameConfig::gate();
  466. $index = 0; # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  467. foreach ($dic as $id => $item) {
  468. if (Ins_GateInfo::GateTypeFromId($id) == Enum_GateType::MainChallengeGate && $item->challengeGateId == $gateId) {
  469. $index += 1;
  470. $gate = new Ins_GateInfo();
  471. $gate->GateId = $id;
  472. ctx()->gates->GateList->$id = $gate;
  473. }
  474. if ($index >= 3) {
  475. break;
  476. }
  477. }
  478. } else {
  479. }
  480. } else { # 失败
  481. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  482. }
  483. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  484. ctx()->baseInfo->Add_Gold($gold);
  485. //ctx()->baseInfo->Add_Exp($exp);
  486. UserProc::updateUserInfo();
  487. $ret = array(
  488. 'gates' => ctx()->gates,
  489. 'store' => ctx()->store,
  490. );
  491. return Resp::ok($ret);
  492. }
  493. }