FightProc.php 17 KB

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