FightProc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. } else {
  217. $dic = GameConfig::evolve();
  218. foreach ($dic as $key => $value) {
  219. if ($value->specificEvolveId == $id) {
  220. $mo = $value;
  221. }
  222. }
  223. my_Assert($mo != null, ErrCode::err_const_no);
  224. if ($mo->specificEvolveCost != null) {
  225. $cost = explode(',', $mo->specificEvolveCost);
  226. $costId = $cost[0];
  227. $costNum = $cost[1];
  228. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $costId) && ctx()->store->items->$costId >= $costNum, ErrCode::notenough_item);
  229. }
  230. // my_Assert(ctx()->baseInfo->gold>=$mo->needGold_unlock, ErrCode::notenough_gold_msg);
  231. }
  232. ctx()->gates->evolveUnlockRecord[] = $id;
  233. UserProc::updateUserInfo();
  234. $ret = array(
  235. 'store' => ctx()->store,
  236. 'gates' => ctx()->gates,
  237. );
  238. return Resp::ok($ret);
  239. }
  240. /**
  241. * 6804 挑战奖励领取
  242. * @return type
  243. */
  244. public static function GateChallengePriceReviced() {
  245. list($zhangjieId, $gateId) = req()->paras;
  246. $gateMo = GameConfig::gate_getItem($gateId);
  247. my_Assert($gateMo != null, ErrCode::err_const_no);
  248. if (!StlUtil::dictHasProperty(ctx()->gates->GatesChallengeRecord, $zhangjieId)) {
  249. ctx()->gates->GatesChallengeRecord->$zhangjieId = array();
  250. }
  251. my_Assert(!in_array($gateId, ctx()->gates->GatesChallengeRecord->$zhangjieId), ErrCode::user_Gate_GatePriceHasReceive);
  252. my_Assert(in_array($gateMo->challengeUnlockId, ctx()->gates->GatesChallengeRecord->$zhangjieId), ErrCode::user_Gate_GateNoUnlock);
  253. ctx()->gates->GatesChallengeRecord->$zhangjieId[] = $gateId;
  254. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  255. ctx()->gates->CurrentGateId = $gateId;
  256. UserProc::updateUserInfo();
  257. $ret = array(
  258. 'store' => ctx()->store,
  259. 'gates' => ctx()->gates,
  260. );
  261. return Resp::ok($ret);
  262. }
  263. /**
  264. * 关卡选择
  265. * @return type
  266. */
  267. public static function SelectGate() {
  268. list($gateId) = req()->paras;
  269. ctx()->gates->CurrentGateId = $gateId;
  270. UserProc::updateUserInfo();
  271. $ret = array(
  272. 'gates' => ctx()->gates,
  273. );
  274. return Resp::ok($ret);
  275. }
  276. /**
  277. * 关卡战斗结算
  278. * @return type
  279. */
  280. public static function Settle() {
  281. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  282. $gateMo = GameConfig::gate_getItem($gateId);
  283. my_Assert($gateMo != null, ErrCode::err_const_no);
  284. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  285. $gateInfo = ctx()->gates->GateList->$gateId;
  286. $ts = $gateInfo->MaxSeconds;
  287. if ($curTs >= $ts) {
  288. $gateInfo->MaxSeconds = $curTs;
  289. }
  290. if ($resultType) { # 胜利
  291. if (ctx()->gates->GateList->$gateId->pass == 0) {
  292. ctx()->gates->GateList->$gateId->pass = 1;
  293. }
  294. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  295. if (Ins_GateInfo::GateTypeFromId($gateId) == 1) { # 是主线据情关卡
  296. ctx()->gates->UnlockNextPlotGate(); # 解锁下一剧情关卡
  297. } else { # 其他类型, 比如挑战关卡
  298. // 刷新挑战关卡记录
  299. }
  300. } else { # 失败
  301. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  302. }
  303. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  304. ctx()->baseInfo->Add_Gold($gold);
  305. //ctx()->baseInfo->Add_Exp($exp);
  306. UserProc::updateUserInfo();
  307. $ret = array(
  308. 'gates' => ctx()->gates,
  309. 'store' => ctx()->store,
  310. );
  311. return Resp::ok($ret);
  312. }
  313. /**
  314. * 章节宝箱的领取
  315. * @return type
  316. */
  317. public static function PassGateTsPrizeReceive() {
  318. list($gateId, $index) = req()->paras;
  319. $gateMo = GameConfig::gate_getItem($gateId);
  320. my_Assert($gateMo != null, ErrCode::err_const_no);
  321. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  322. $gateInfo = ctx()->gates->GateList->$gateId;
  323. $tag = false;
  324. $prize = "";
  325. $mask = 0;
  326. switch ($index) {
  327. case 1:
  328. $ts = $gateMo->first_ts1 * 60;
  329. if ($gateInfo->MaxSeconds >= $ts) {
  330. $tag = true;
  331. }
  332. $mask = 1;
  333. $prize = $gateMo->first_reward1;
  334. break;
  335. case 2:
  336. $ts = $gateMo->first_ts2 * 60;
  337. if ($gateInfo->MaxSeconds >= $ts) {
  338. $tag = true;
  339. }
  340. $mask = 2;
  341. $prize = $gateMo->first_reward2;
  342. break;
  343. case 3:
  344. if ($gateInfo->pass > 0) {
  345. $tag = true;
  346. }
  347. $mask = 3;
  348. $prize = $gateMo->first_reward3;
  349. break;
  350. default:
  351. break;
  352. }
  353. if ($tag) {
  354. StoreProc::AddMultiItemInStore($prize);
  355. $gateInfo->FirstReward = $mask;
  356. }
  357. ctx()->gates->GateList->$gateId = $gateInfo;
  358. UserProc::updateUserInfo();
  359. $ret = array(
  360. 'gates' => ctx()->gates,
  361. 'store' => ctx()->store,
  362. );
  363. return Resp::ok($ret);
  364. }
  365. }