FightProc.php 18 KB

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