FightProc.php 15 KB

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