FightProc.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. default:
  32. Err(ErrCode::cmd_err);
  33. }
  34. }
  35. /**
  36. * EvolveUnlock
  37. * @return type
  38. */
  39. public static function EvolveUnlock() {
  40. list($type,$id) = req()->paras;
  41. if($type == 1){
  42. $mo = GameConfig::evolve_getItem($id);
  43. my_Assert($mo!=null, ErrCode::err_const_no);
  44. my_Assert(ctx()->baseInfo->gold>=$mo->needGold_unlock, ErrCode::notenough_gold_msg);
  45. ctx()->baseInfo->Consume_Gold($mo->needGold_unlock);
  46. } else {
  47. $mo =GameConfig::evolveSpecific_getItem($id);
  48. my_Assert($mo!=null, ErrCode::err_const_no);
  49. if($mo->specificEvolveCost != null){
  50. $cost = explode(',', $mo->specificEvolveCost);
  51. $costId = $cost[0];
  52. $costNum = $cost[1];
  53. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $costId) && ctx()->store->items->$costId >= $costNum , ErrCode::notenough_item);
  54. }
  55. // my_Assert(ctx()->baseInfo->gold>=$mo->needGold_unlock, ErrCode::notenough_gold_msg);
  56. }
  57. ctx()->gates->evolveUnlockRecord[] = $id;
  58. UserProc::updateUserInfo();
  59. $ret = array(
  60. 'store' => ctx()->store,
  61. 'gates' => ctx()->gates,
  62. );
  63. return Resp::ok($ret);
  64. }
  65. /**
  66. * 挑战奖励领取
  67. * @return type
  68. */
  69. public static function GateChallengePriceReviced() {
  70. list($zhangjieId, $gateId) = req()->paras;
  71. $mo = GameConfig::gate_challenge_getItem($zhangjieId);
  72. my_Assert($mo!=null, ErrCode::err_const_no);
  73. // $list = explode(',', $mo->gates);
  74. // my_Assert(in_array($gateId,$list), ErrCode::err_const_no);
  75. $gateMo = GameConfig::gate_getItem($gateId);
  76. my_Assert($gateMo!=null, ErrCode::err_const_no);
  77. if(!StlUtil::dictHasProperty(ctx()->gates->GatesChallengeRecord, $zhangjieId)){
  78. ctx()->gates->GatesChallengeRecord->$zhangjieId = array();
  79. }
  80. my_Assert(!in_array($gateId,ctx()->gates->GatesChallengeRecord->$zhangjieId), ErrCode::user_Gate_GatePriceHasReceive);
  81. ctx()->gates->GatesChallengeRecord->$zhangjieId[] = $gateId;
  82. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  83. ctx()->gates->CurrentGateId = $gateId;
  84. UserProc::updateUserInfo();
  85. $ret = array(
  86. 'store' => ctx()->store,
  87. 'gates' => ctx()->gates,
  88. );
  89. return Resp::ok($ret);
  90. }
  91. /**
  92. * 关卡选择
  93. * @return type
  94. */
  95. public static function SelectGate() {
  96. list($gateId) = req()->paras;
  97. ctx()->gates->CurrentGateId = $gateId;
  98. UserProc::updateUserInfo();
  99. $ret = array(
  100. 'gates' => ctx()->gates,
  101. );
  102. return Resp::ok($ret);
  103. }
  104. /**
  105. * 关卡战斗结算
  106. * @return type
  107. */
  108. public static function Settle() {
  109. list($resultType, $gateId,$gold,$curTs) = req()->paras;
  110. $gateMo = GameConfig::gate_getItem($gateId);
  111. my_Assert($gateMo!=null, ErrCode::err_const_no);
  112. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::user_Gate_NoUserGateInfo);
  113. $gateInfo = ctx()->gates->GateList->$gateId;
  114. $ts = $gateInfo->MaxSeconds;
  115. if($curTs >= $ts){
  116. $gateInfo->MaxSeconds = $curTs;
  117. }
  118. if($resultType){
  119. if(ctx()->gates->GateList->$gateId->pass == 0){
  120. ctx()->gates->GateList->$gateId->pass = 1;
  121. }
  122. StoreProc::AddMultiItemInStore($gateMo->reward_win);
  123. $newGateId = $gateId+1;
  124. if(!StlUtil::dictHasProperty(ctx()->gates->GateList, $newGateId)){
  125. ctx()->gates->CurrentGateId = $newGateId;
  126. ctx()->gates->UnlockedGatesMaxId = $newGateId;
  127. $gate = new Ins_GateInfo();
  128. $gate->GateId = $newGateId;
  129. ctx()->gates->GateList->$newGateId = $gate;
  130. }
  131. } else {
  132. StoreProc::AddMultiItemInStore($gateMo->reward_fail);
  133. }
  134. ctx()->baseInfo->Add_Gold($gold);
  135. //ctx()->baseInfo->Add_Exp($exp);
  136. UserProc::updateUserInfo();
  137. $ret = array(
  138. 'gates' => ctx()->gates,
  139. 'store' => ctx()->store,
  140. );
  141. return Resp::ok($ret);
  142. }
  143. /**
  144. * 章节宝箱的领取
  145. * @return type
  146. */
  147. public static function PassGateTsPrizeReceive() {
  148. list($gateId,$index) = 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. $tag = false;
  154. $prize = "";
  155. $mask =0;
  156. switch ($index) {
  157. case 1:
  158. $ts = $gateMo->first_ts1 *60;
  159. if($ts >= $gateInfo->MaxSeconds){
  160. $tag = true;
  161. }
  162. $mask=1;
  163. $prize = $gateMo->first_reward1;
  164. break;
  165. case 2:
  166. $ts = $gateMo->first_ts2*60;
  167. if($ts >= $gateInfo->MaxSeconds){
  168. $tag = true;
  169. }
  170. $mask = 2;
  171. $prize = $gateMo->first_reward2;
  172. break;
  173. case 3:
  174. if($gateInfo->pass > 0){
  175. $tag = true;
  176. }
  177. $mask =3;
  178. $prize = $gateMo->first_reward3;
  179. break;
  180. default:
  181. break;
  182. }
  183. if($tag){
  184. StoreProc::AddMultiItemInStore($prize);
  185. $gateInfo->FirstReward = $mask;
  186. }
  187. ctx()->gates->GateList->$gateId=$gateInfo;
  188. UserProc::updateUserInfo();
  189. $ret = array(
  190. 'gates' => ctx()->gates,
  191. 'store' => ctx()->store,
  192. );
  193. return Resp::ok($ret);
  194. }
  195. }