FightProc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. } else {//快速巡逻
  175. my_Assert(ctx()->gates->xunluo_quick_buyRecord < $gateMo->xueluo_quick_num, ErrCode::err_const_no);
  176. ctx()->gates->xunluo_quick_buyRecord += 1;
  177. ctx()->baseInfo->Consume_tili(15);
  178. StoreProc::AddMultiItemInStore($gateMo->xueluo_quick_reward);
  179. }
  180. UserProc::updateUserInfo();
  181. $ret = array(
  182. 'gates' => ctx()->gates,
  183. );
  184. return Resp::ok($ret);
  185. }
  186. public static function FightDailyClear() {
  187. ctx()->gates->xunluo_quick_buyRecord = 0;
  188. }
  189. /**
  190. * 剧情回存
  191. * @return type
  192. */
  193. public static function PlotSav() {
  194. list($gateId) = req()->paras;
  195. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  196. ctx()->gates->GateList->$gateId->plotStart = 1;
  197. UserProc::updateUserInfo();
  198. $ret = array(
  199. 'ok' => 1,
  200. );
  201. return Resp::ok($ret);
  202. }
  203. /**
  204. * 6805 进化解锁
  205. * @return type
  206. */
  207. public static function EvolveUnlock() {
  208. list($type, $id) = req()->paras;
  209. if ($type == 1) {
  210. $mo = GameConfig::evolve_getItem($id);
  211. my_Assert($mo != null, ErrCode::err_const_no);
  212. my_Assert(ctx()->baseInfo->gold >= $mo->needGold_unlock, ErrCode::notenough_gold_msg);
  213. ctx()->baseInfo->Consume_Gold($mo->needGold_unlock);
  214. } else {
  215. $mo = GameConfig::evolveSpecific_getItem($id);
  216. my_Assert($mo != null, ErrCode::err_const_no);
  217. if ($mo->specificEvolveCost != null) {
  218. $cost = explode(',', $mo->specificEvolveCost);
  219. $costId = $cost[0];
  220. $costNum = $cost[1];
  221. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $costId) && ctx()->store->items->$costId >= $costNum, ErrCode::notenough_item);
  222. }
  223. // my_Assert(ctx()->baseInfo->gold>=$mo->needGold_unlock, ErrCode::notenough_gold_msg);
  224. }
  225. ctx()->gates->evolveUnlockRecord[] = $id;
  226. UserProc::updateUserInfo();
  227. $ret = array(
  228. 'store' => ctx()->store,
  229. 'gates' => ctx()->gates,
  230. );
  231. return Resp::ok($ret);
  232. }
  233. /**
  234. * 6804 挑战奖励领取
  235. * @return type
  236. */
  237. public static function GateChallengePriceReviced() {
  238. list($zhangjieId, $gateId) = req()->paras;
  239. $mo = GameConfig::gate_challenge_getItem($zhangjieId);
  240. my_Assert($mo != null, ErrCode::err_const_no);
  241. // $list = explode(',', $mo->gates);
  242. // my_Assert(in_array($gateId,$list), ErrCode::err_const_no);
  243. $gateMo = GameConfig::gate_getItem($gateId);
  244. my_Assert($gateMo != null, ErrCode::err_const_no);
  245. if (!StlUtil::dictHasProperty(ctx()->gates->GatesChallengeRecord, $zhangjieId)) {
  246. ctx()->gates->GatesChallengeRecord->$zhangjieId = array();
  247. }
  248. my_Assert(!in_array($gateId, ctx()->gates->GatesChallengeRecord->$zhangjieId), ErrCode::user_Gate_GatePriceHasReceive);
  249. ctx()->gates->GatesChallengeRecord->$zhangjieId[] = $gateId;
  250. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  251. ctx()->gates->CurrentGateId = $gateId;
  252. UserProc::updateUserInfo();
  253. $ret = array(
  254. 'store' => ctx()->store,
  255. 'gates' => ctx()->gates,
  256. );
  257. return Resp::ok($ret);
  258. }
  259. /**
  260. * 关卡选择
  261. * @return type
  262. */
  263. public static function SelectGate() {
  264. list($gateId) = req()->paras;
  265. ctx()->gates->CurrentGateId = $gateId;
  266. UserProc::updateUserInfo();
  267. $ret = array(
  268. 'gates' => ctx()->gates,
  269. );
  270. return Resp::ok($ret);
  271. }
  272. /**
  273. * 关卡战斗结算
  274. * @return type
  275. */
  276. public static function Settle() {
  277. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  278. $gateMo = GameConfig::gate_getItem($gateId);
  279. my_Assert($gateMo != null, ErrCode::err_const_no);
  280. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  281. $gateInfo = ctx()->gates->GateList->$gateId;
  282. $ts = $gateInfo->MaxSeconds;
  283. if ($curTs >= $ts) {
  284. $gateInfo->MaxSeconds = $curTs;
  285. }
  286. if ($resultType) { # 胜利
  287. if (ctx()->gates->GateList->$gateId->pass == 0) {
  288. ctx()->gates->GateList->$gateId->pass = 1;
  289. }
  290. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  291. $newGateId = $gateId + 1;
  292. if (!StlUtil::dictHasProperty(ctx()->gates->GateList, $newGateId)) {
  293. ctx()->gates->CurrentGateId = $newGateId;
  294. ctx()->gates->UnlockedGatesMaxId = $newGateId;
  295. $gate = new Ins_GateInfo();
  296. $gate->GateId = $newGateId;
  297. ctx()->gates->GateList->$newGateId = $gate;
  298. }
  299. } else { # 失败
  300. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  301. }
  302. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  303. ctx()->baseInfo->Add_Gold($gold);
  304. //ctx()->baseInfo->Add_Exp($exp);
  305. UserProc::updateUserInfo();
  306. $ret = array(
  307. 'gates' => ctx()->gates,
  308. 'store' => ctx()->store,
  309. );
  310. return Resp::ok($ret);
  311. }
  312. /**
  313. * 章节宝箱的领取
  314. * @return type
  315. */
  316. public static function PassGateTsPrizeReceive() {
  317. list($gateId, $index) = req()->paras;
  318. $gateMo = GameConfig::gate_getItem($gateId);
  319. my_Assert($gateMo != null, ErrCode::err_const_no);
  320. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  321. $gateInfo = ctx()->gates->GateList->$gateId;
  322. $tag = false;
  323. $prize = "";
  324. $mask = 0;
  325. switch ($index) {
  326. case 1:
  327. $ts = $gateMo->first_ts1 * 60;
  328. if ($ts >= $gateInfo->MaxSeconds) {
  329. $tag = true;
  330. }
  331. $mask = 1;
  332. $prize = $gateMo->first_reward1;
  333. break;
  334. case 2:
  335. $ts = $gateMo->first_ts2 * 60;
  336. if ($ts >= $gateInfo->MaxSeconds) {
  337. $tag = true;
  338. }
  339. $mask = 2;
  340. $prize = $gateMo->first_reward2;
  341. break;
  342. case 3:
  343. if ($gateInfo->pass > 0) {
  344. $tag = true;
  345. }
  346. $mask = 3;
  347. $prize = $gateMo->first_reward3;
  348. break;
  349. default:
  350. break;
  351. }
  352. if ($tag) {
  353. StoreProc::AddMultiItemInStore($prize);
  354. $gateInfo->FirstReward = $mask;
  355. }
  356. ctx()->gates->GateList->$gateId = $gateInfo;
  357. UserProc::updateUserInfo();
  358. $ret = array(
  359. 'gates' => ctx()->gates,
  360. 'store' => ctx()->store,
  361. );
  362. return Resp::ok($ret);
  363. }
  364. }