FightProc.php 18 KB

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