FightProc.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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_gateChallengePriceReviced: # 6804 挑战关卡: 领取奖励
  22. return FightProc::GateChallengePriceReviced();
  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. default:
  32. Err(ErrCode::cmd_err);
  33. }
  34. }
  35. /**
  36. * 6807 扫荡
  37. * @return type
  38. */
  39. public static function FightSweep() {
  40. //list($gateId) = req()->paras;
  41. my_Assert(ctx()->gates->UnlockedGatesMaxId != 0, ErrCode::user_Gate_NoSweep);
  42. $mo = GameConfig::gate_getItem(ctx()->gates->UnlockedGatesMaxId);
  43. $costTili = glc()->sweep_cost_tili;
  44. my_Assert(ctx()->baseInfo->tili >= $costTili, ErrCode::notenough_tili);
  45. $max = glc()->sweepMaxNum;
  46. my_Assert(ctx()->gates->fightSweepNum < $max, ErrCode::user_Gate_SweepMaxNum_limit);
  47. ctx()->gates->fightSweepNum += 1;
  48. ctx()->baseInfo->Consume_tili($costTili);
  49. $prizeArr = array();
  50. $prizeArr[] = $mo->reward_win;
  51. if ($mo->sweep_gold != null) {
  52. $goodsStr = self::sweepRandReward($mo->sweep_gold);
  53. $prizeArr[] = $goodsStr;
  54. StoreProc::AddMultiItemInStore($goodsStr);
  55. }
  56. if ($mo->sweep_tuzhi != null) {
  57. $goodsStr = self::sweepRandReward($mo->sweep_tuzhi);
  58. $prizeArr[] = $goodsStr;
  59. StoreProc::AddMultiItemInStore($goodsStr);
  60. }
  61. if ($mo->sweep_gem != null) {
  62. $goodsStr = self::sweepRandReward($mo->sweep_gem);
  63. $list = explode(',', $goodsStr);
  64. $posId = rand(1, 6);
  65. $qual = $list[0];
  66. $dic = GameConfig::gem();
  67. foreach ($dic as $key => $gemMo) {
  68. if ($gemMo->qual == $qual && $gemMo->position == $posId) {
  69. $prizeArr[] = $gemMo->typeId . ',' . $list[1];
  70. StoreProc::PutGemInStore($gemMo->typeId, $list[1]);
  71. break;
  72. }
  73. }
  74. }
  75. if ($mo->sweep_qiling != null) {
  76. $goodsStr = self::sweepRandReward($mo->sweep_qiling);
  77. $prizeArr[] = $goodsStr;
  78. StoreProc::AddMultiItemInStore($goodsStr);
  79. }
  80. UserProc::updateUserInfo();
  81. $ret = array(
  82. 'tili' => ctx()->baseInfo->tili,
  83. 'fightSweepNum' => ctx()->gates->fightSweepNum,
  84. 'prizeArr' => $prizeArr,
  85. 'store' => ctx()->store,
  86. );
  87. return Resp::ok($ret);
  88. }
  89. static function sweepRandReward($rewardStr) {
  90. $ctxArr = explode(';', $rewardStr);
  91. $numArr = explode('-', $ctxArr[0]);
  92. $num = rand($numArr[0], $numArr[1]);
  93. $randNum = rand(1, 100);
  94. $start = 0;
  95. $end = 0;
  96. $res = "";
  97. $itemArr = explode(',', $ctxArr[1]);
  98. foreach ($itemArr as $str) {
  99. $arr = explode(':', $str);
  100. $itemId = $arr[1];
  101. $per = $arr[2];
  102. $end += $per;
  103. if ($randNum >= $start && $randNum < $end) {
  104. $res = $itemId;
  105. break;
  106. }
  107. $start = $end;
  108. }
  109. return $res . ',' . $num;
  110. }
  111. /**
  112. * 6808 主线关卡: 开始挑战 (扣除体力)
  113. */
  114. private static function StartFight() {
  115. list($gateId) = req()->paras;
  116. my_Assert($gateId > 0, ErrCode::paras_err);
  117. $mo = GameConfig::gate_getItem($gateId);
  118. my_Assert(null != $mo, ErrCode::err_const_no);
  119. my_Assert(ctx()->base()->Consume_tili($mo->cost_tili), ErrCode::notenough_tili);
  120. return Resp::ok(array("tili" => ctx()->baseInfo->tili, "tili_ts" => ctx()->baseInfo->tili_ts));
  121. }
  122. /**
  123. * [废弃] 6807 巡逻奖励领取
  124. * @return type
  125. */
  126. public static function XunluoPrizeReceived() {
  127. list($type) = req()->paras;
  128. $gateId = ctx()->gates->UnlockedGatesMaxId;
  129. $gateMo = GameConfig::gate_getItem($gateId);
  130. my_Assert($gateMo != null, ErrCode::err_const_no);
  131. if ($type == 1) {//巡逻
  132. $curTs = now();
  133. $startTs = ctx()->gates->xunluo_StartTs;
  134. $ts = $curTs - $startTs;
  135. $ts2 = intval($ts / 60); //总的分钟数
  136. $fenzhong = intval($ts2 / 10); //有几个10分钟
  137. $gold = 0;
  138. $exp = 0;
  139. $price = "";
  140. if ($fenzhong > 0) {
  141. $gold = intval($gateMo->gold_xunluo / 6 * $fenzhong);
  142. $exp = intval($gateMo->exp_xunluo / 6 * $fenzhong);
  143. $price = "1," . $gold . ';' . "4," . $exp;
  144. }
  145. $itemStr = explode(';', $gateMo->xunluo_item_ts);
  146. $itemId = 0;
  147. $itemNum = 0;
  148. $tempTs = 0;
  149. foreach ($itemStr as $s) {
  150. $arr = explode('-', $s);
  151. $tsItemArr = explode(',', $arr[0]);
  152. $sTs = $tsItemArr[0]; //开始时间
  153. $eTs = $tsItemArr[1]; //终止时间
  154. $produceTs = $tsItemArr[2]; //间隔
  155. while (true) {
  156. $tempTs += $produceTs;
  157. if ($tempTs <= $eTs && $tempTs <= $ts2) {
  158. $sList = explode(',', $arr[1]);
  159. $itemId = $sList[0];
  160. $itemNum += $sList[1];
  161. }
  162. if ($tempTs >= $ts2) {
  163. break;
  164. }
  165. if ($tempTs >= $eTs) {
  166. $tempTs = $eTs;
  167. break;
  168. }
  169. }
  170. if ($tempTs >= $ts2) {
  171. break;
  172. }
  173. }
  174. if ($itemNum > 0) {
  175. $price = $price . ";" . $itemId . ',' . $itemNum;
  176. }
  177. //---------------------------
  178. $tuzhiStr = explode(';', $gateMo->xunluo_tuzhi_ts);
  179. $tuzhiId = 0;
  180. $tuzhiNum = 0;
  181. $tempTs2 = 0;
  182. foreach ($tuzhiStr as $s) {
  183. $arr = explode('-', $s);
  184. $tsItemArr = explode(',', $arr[0]);
  185. $sTs = $tsItemArr[0]; //开始时间
  186. $eTs = $tsItemArr[1]; //终止时间
  187. $produceTs = $tsItemArr[2]; //间隔
  188. while (true) {
  189. $tempTs2 += $produceTs;
  190. if ($tempTs2 <= $eTs && $tempTs2 <= $ts2) {
  191. $sList = explode(',', $arr[1]);
  192. $tuzhiId = $sList[0];
  193. $tuzhiNum += $sList[1];
  194. }
  195. if ($tempTs2 >= $ts2) {
  196. break;
  197. }
  198. if ($tempTs2 >= $eTs) {
  199. $tempTs2 = $eTs;
  200. break;
  201. }
  202. }
  203. if ($tempTs2 >= $ts2) {
  204. break;
  205. }
  206. }
  207. if ($tuzhiNum > 0) {
  208. $price = $price . ";" . $tuzhiId . ',' . $tuzhiNum;
  209. }
  210. //---------------------
  211. $equipStr = explode(';', $gateMo->xunluo_equip_ts);
  212. $equipId = 0;
  213. $equipNum = 0;
  214. $tempTs3 = 0;
  215. foreach ($equipStr as $s) {
  216. $arr = explode('-', $s);
  217. $tsItemArr = explode(',', $arr[0]);
  218. $sTs = $tsItemArr[0]; //开始时间
  219. $eTs = $tsItemArr[1]; //终止时间
  220. $produceTs = $tsItemArr[2]; //间隔
  221. while (true) {
  222. $tempTs3 += $produceTs;
  223. if ($tempTs3 <= $eTs && $tempTs3 <= $ts2) {
  224. $sList = explode(',', $arr[1]);
  225. $equipId = $sList[0];
  226. $equipNum += $sList[1];
  227. }
  228. if ($tempTs3 >= $ts2) {
  229. break;
  230. }
  231. if ($tempTs3 >= $eTs) {
  232. $tempTs3 = $eTs;
  233. break;
  234. }
  235. }
  236. if ($tempTs3 >= $ts2) {
  237. break;
  238. }
  239. }
  240. if ($equipNum > 0) {
  241. $price = $price . ";" . $equipId . ',' . $equipNum;
  242. }
  243. StoreProc::AddMultiItemInStore($price);
  244. ctx()->gates->xunluo_StartTs = now();
  245. } else {//快速巡逻
  246. my_Assert(ctx()->gates->xunluo_quick_buyRecord < $gateMo->xueluo_quick_num, ErrCode::err_const_no);
  247. ctx()->gates->xunluo_quick_buyRecord += 1;
  248. ctx()->baseInfo->Consume_tili(15);
  249. StoreProc::AddMultiItemInStore($gateMo->xueluo_quick_reward);
  250. }
  251. UserProc::updateUserInfo();
  252. $ret = array(
  253. 'tili' => ctx()->baseInfo->tili,
  254. 'gates' => ctx()->gates,
  255. );
  256. return Resp::ok($ret);
  257. }
  258. public static function FightDailyClear() {
  259. //ctx()->gates->xunluo_quick_buyRecord = 0;
  260. ctx()->gates->fightSweepNum = 0;
  261. }
  262. /**
  263. * 6806 剧情回存
  264. * @return type
  265. */
  266. public static function PlotSav() {
  267. list($gateId) = req()->paras;
  268. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  269. ctx()->gates->GateList->$gateId->plotStart = 1;
  270. UserProc::updateUserInfo();
  271. $ret = array(
  272. 'ok' => 1,
  273. );
  274. return Resp::ok($ret);
  275. }
  276. /**
  277. * 6805 挑战关卡: 开始挑战(扣除次数)
  278. * @return type
  279. */
  280. public static function ChallengeGateStartFight() {
  281. list($type, $id) = req()->paras;
  282. UserProc::updateUserInfo();
  283. $ret = array(
  284. 'store' => ctx()->store,
  285. 'gates' => ctx()->gates,
  286. );
  287. return Resp::ok($ret);
  288. }
  289. /**
  290. * 6804 挑战关卡: 奖励领取
  291. * @return type
  292. */
  293. public static function GateChallengePriceReviced() {
  294. list($zhangjieId, $gateId) = req()->paras;
  295. $gateMo = GameConfig::gate_getItem($gateId);
  296. my_Assert($gateMo != null, ErrCode::err_const_no);
  297. if (!StlUtil::dictHasProperty(ctx()->gates->GatesChallengeRecord, $zhangjieId)) {
  298. ctx()->gates->GatesChallengeRecord->$zhangjieId = array();
  299. }
  300. my_Assert(!in_array($gateId, ctx()->gates->GatesChallengeRecord->$zhangjieId), ErrCode::user_Gate_GatePriceHasReceive);
  301. my_Assert(in_array($gateMo->challengeUnlockId, ctx()->gates->GatesChallengeRecord->$zhangjieId), ErrCode::user_Gate_GateNoUnlock);
  302. ctx()->gates->GatesChallengeRecord->$zhangjieId[] = $gateId;
  303. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  304. ctx()->gates->CurrentGateId = $gateId;
  305. UserProc::updateUserInfo();
  306. $ret = array(
  307. 'store' => ctx()->store,
  308. 'gates' => ctx()->gates,
  309. );
  310. return Resp::ok($ret);
  311. }
  312. /**
  313. * 6803 关卡选择
  314. * @return type
  315. */
  316. public static function SelectGate() {
  317. list($gateId) = req()->paras;
  318. ctx()->gates->CurrentGateId = $gateId;
  319. UserProc::updateUserInfo();
  320. $ret = array(
  321. 'gates' => ctx()->gates,
  322. );
  323. return Resp::ok($ret);
  324. }
  325. /**
  326. * 6802 章节宝箱的领取
  327. * @return type
  328. */
  329. public static function PassGateTsPrizeReceive() {
  330. list($gateId, $index) = req()->paras;
  331. $gateMo = GameConfig::gate_getItem($gateId);
  332. my_Assert($gateMo != null, ErrCode::err_const_no);
  333. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  334. $gateInfo = ctx()->gates->GateList->$gateId;
  335. $tag = false;
  336. $prize = "";
  337. $mask = 0;
  338. switch ($index) {
  339. case 1:
  340. $ts = $gateMo->first_ts1 * 60;
  341. if ($gateInfo->MaxSeconds >= $ts) {
  342. $tag = true;
  343. }
  344. $mask = 1;
  345. $prize = $gateMo->first_reward1;
  346. break;
  347. case 2:
  348. $ts = $gateMo->first_ts2 * 60;
  349. if ($gateInfo->MaxSeconds >= $ts) {
  350. $tag = true;
  351. }
  352. $mask = 2;
  353. $prize = $gateMo->first_reward2;
  354. break;
  355. case 3:
  356. if ($gateInfo->pass > 0) {
  357. $tag = true;
  358. }
  359. $mask = 3;
  360. $prize = $gateMo->first_reward3;
  361. break;
  362. default:
  363. break;
  364. }
  365. if ($tag) {
  366. my_Assert($mask > $gateInfo->FirstReward, ErrCode::user_Gate_GatePriceHasReceive);
  367. $gateInfo->FirstReward = $mask;
  368. StoreProc::AddMultiItemInStore($prize);
  369. }
  370. ctx()->gates->GateList->$gateId = $gateInfo;
  371. UserProc::updateUserInfo();
  372. $ret = array(
  373. 'gates' => ctx()->gates,
  374. 'store' => ctx()->store,
  375. );
  376. return Resp::ok($ret);
  377. }
  378. /**
  379. * [6801]关卡战斗结算
  380. * @return type
  381. */
  382. public static function Settle() {
  383. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  384. $gateMo = GameConfig::gate_getItem($gateId);
  385. my_Assert($gateMo != null, ErrCode::err_const_no);
  386. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  387. $gateInfo = ctx()->gates->GateList->$gateId;
  388. $ts = $gateInfo->MaxSeconds;
  389. if ($curTs >= $ts) {
  390. $gateInfo->MaxSeconds = $curTs;
  391. }
  392. if ($resultType) { # 胜利
  393. if (ctx()->gates->GateList->$gateId->pass == 0) {
  394. ctx()->gates->GateList->$gateId->pass = 1;
  395. }
  396. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  397. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  398. ctx()->gates->UnlockNextPlotGate();
  399. $dic = GameConfig::gate();
  400. $index = 0; # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  401. foreach ($dic as $id => $item) {
  402. if (Ins_GateInfo::GateTypeFromId($id) == Enum_GateType::MainChallengeGate && $item->challengeGateId == $gateId) {
  403. $index += 1;
  404. $gate = new Ins_GateInfo();
  405. $gate->GateId = $id;
  406. ctx()->gates->GateList->$id = $gate;
  407. }
  408. if ($index >= 3) {
  409. break;
  410. }
  411. }
  412. } else {
  413. }
  414. } else { # 失败
  415. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  416. }
  417. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  418. ctx()->baseInfo->Add_Gold($gold);
  419. //ctx()->baseInfo->Add_Exp($exp);
  420. UserProc::updateUserInfo();
  421. $ret = array(
  422. 'gates' => ctx()->gates,
  423. 'store' => ctx()->store,
  424. );
  425. return Resp::ok($ret);
  426. }
  427. }