FightProc.php 14 KB

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