FightProc.php 8.9 KB

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