FightProc.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. ctx()->gates->xunluo_StartTs = now();
  63. } else {//快速巡逻
  64. ctx()->gates->xunluo_quick_buyRecord += 1;
  65. ctx()->baseInfo->Consume_tili(15);
  66. }
  67. UserProc::updateUserInfo();
  68. $ret = array(
  69. 'ok' => 1,
  70. );
  71. return Resp::ok($ret);
  72. }
  73. /**
  74. * 剧情回存
  75. * @return type
  76. */
  77. public static function PlotSav() {
  78. list($gateId) = req()->paras;
  79. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  80. ctx()->gates->GateList->$gateId->plotStart = 1;
  81. UserProc::updateUserInfo();
  82. $ret = array(
  83. 'ok' => 1,
  84. );
  85. return Resp::ok($ret);
  86. }
  87. /**
  88. * 6805 进化解锁
  89. * @return type
  90. */
  91. public static function EvolveUnlock() {
  92. list($type, $id) = req()->paras;
  93. if ($type == 1) {
  94. $mo = GameConfig::evolve_getItem($id);
  95. my_Assert($mo != null, ErrCode::err_const_no);
  96. my_Assert(ctx()->baseInfo->gold >= $mo->needGold_unlock, ErrCode::notenough_gold_msg);
  97. ctx()->baseInfo->Consume_Gold($mo->needGold_unlock);
  98. } else {
  99. $mo = GameConfig::evolveSpecific_getItem($id);
  100. my_Assert($mo != null, ErrCode::err_const_no);
  101. if ($mo->specificEvolveCost != null) {
  102. $cost = explode(',', $mo->specificEvolveCost);
  103. $costId = $cost[0];
  104. $costNum = $cost[1];
  105. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $costId) && ctx()->store->items->$costId >= $costNum, ErrCode::notenough_item);
  106. }
  107. // my_Assert(ctx()->baseInfo->gold>=$mo->needGold_unlock, ErrCode::notenough_gold_msg);
  108. }
  109. ctx()->gates->evolveUnlockRecord[] = $id;
  110. UserProc::updateUserInfo();
  111. $ret = array(
  112. 'store' => ctx()->store,
  113. 'gates' => ctx()->gates,
  114. );
  115. return Resp::ok($ret);
  116. }
  117. /**
  118. * 6804 挑战奖励领取
  119. * @return type
  120. */
  121. public static function GateChallengePriceReviced() {
  122. list($zhangjieId, $gateId) = req()->paras;
  123. $mo = GameConfig::gate_challenge_getItem($zhangjieId);
  124. my_Assert($mo != null, ErrCode::err_const_no);
  125. // $list = explode(',', $mo->gates);
  126. // my_Assert(in_array($gateId,$list), ErrCode::err_const_no);
  127. $gateMo = GameConfig::gate_getItem($gateId);
  128. my_Assert($gateMo != null, ErrCode::err_const_no);
  129. if (!StlUtil::dictHasProperty(ctx()->gates->GatesChallengeRecord, $zhangjieId)) {
  130. ctx()->gates->GatesChallengeRecord->$zhangjieId = array();
  131. }
  132. my_Assert(!in_array($gateId, ctx()->gates->GatesChallengeRecord->$zhangjieId), ErrCode::user_Gate_GatePriceHasReceive);
  133. ctx()->gates->GatesChallengeRecord->$zhangjieId[] = $gateId;
  134. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  135. ctx()->gates->CurrentGateId = $gateId;
  136. UserProc::updateUserInfo();
  137. $ret = array(
  138. 'store' => ctx()->store,
  139. 'gates' => ctx()->gates,
  140. );
  141. return Resp::ok($ret);
  142. }
  143. /**
  144. * 关卡选择
  145. * @return type
  146. */
  147. public static function SelectGate() {
  148. list($gateId) = req()->paras;
  149. ctx()->gates->CurrentGateId = $gateId;
  150. UserProc::updateUserInfo();
  151. $ret = array(
  152. 'gates' => ctx()->gates,
  153. );
  154. return Resp::ok($ret);
  155. }
  156. /**
  157. * 关卡战斗结算
  158. * @return type
  159. */
  160. public static function Settle() {
  161. list($resultType, $gateId, $gold, $curTs, $pickups) = req()->paras;
  162. $gateMo = GameConfig::gate_getItem($gateId);
  163. my_Assert($gateMo != null, ErrCode::err_const_no);
  164. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  165. $gateInfo = ctx()->gates->GateList->$gateId;
  166. $ts = $gateInfo->MaxSeconds;
  167. if ($curTs >= $ts) {
  168. $gateInfo->MaxSeconds = $curTs;
  169. }
  170. if ($resultType) { # 胜利
  171. if (ctx()->gates->GateList->$gateId->pass == 0) {
  172. ctx()->gates->GateList->$gateId->pass = 1;
  173. }
  174. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  175. $newGateId = $gateId + 1;
  176. if (!StlUtil::dictHasProperty(ctx()->gates->GateList, $newGateId)) {
  177. ctx()->gates->CurrentGateId = $newGateId;
  178. ctx()->gates->UnlockedGatesMaxId = $newGateId;
  179. $gate = new Ins_GateInfo();
  180. $gate->GateId = $newGateId;
  181. ctx()->gates->GateList->$newGateId = $gate;
  182. }
  183. } else { # 失败
  184. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  185. }
  186. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具
  187. ctx()->baseInfo->Add_Gold($gold);
  188. //ctx()->baseInfo->Add_Exp($exp);
  189. UserProc::updateUserInfo();
  190. $ret = array(
  191. 'gates' => ctx()->gates,
  192. 'store' => ctx()->store,
  193. );
  194. return Resp::ok($ret);
  195. }
  196. /**
  197. * 章节宝箱的领取
  198. * @return type
  199. */
  200. public static function PassGateTsPrizeReceive() {
  201. list($gateId, $index) = req()->paras;
  202. $gateMo = GameConfig::gate_getItem($gateId);
  203. my_Assert($gateMo != null, ErrCode::err_const_no);
  204. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  205. $gateInfo = ctx()->gates->GateList->$gateId;
  206. $tag = false;
  207. $prize = "";
  208. $mask = 0;
  209. switch ($index) {
  210. case 1:
  211. $ts = $gateMo->first_ts1 * 60;
  212. if ($ts >= $gateInfo->MaxSeconds) {
  213. $tag = true;
  214. }
  215. $mask = 1;
  216. $prize = $gateMo->first_reward1;
  217. break;
  218. case 2:
  219. $ts = $gateMo->first_ts2 * 60;
  220. if ($ts >= $gateInfo->MaxSeconds) {
  221. $tag = true;
  222. }
  223. $mask = 2;
  224. $prize = $gateMo->first_reward2;
  225. break;
  226. case 3:
  227. if ($gateInfo->pass > 0) {
  228. $tag = true;
  229. }
  230. $mask = 3;
  231. $prize = $gateMo->first_reward3;
  232. break;
  233. default:
  234. break;
  235. }
  236. if ($tag) {
  237. StoreProc::AddMultiItemInStore($prize);
  238. $gateInfo->FirstReward = $mask;
  239. }
  240. ctx()->gates->GateList->$gateId = $gateInfo;
  241. UserProc::updateUserInfo();
  242. $ret = array(
  243. 'gates' => ctx()->gates,
  244. 'store' => ctx()->store,
  245. );
  246. return Resp::ok($ret);
  247. }
  248. }