FightProc.php 20 KB

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