SweepGatesProc.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 战斗 - 关卡
  5. * @author gwang
  6. */
  7. class SweepGatesProc {
  8. /**
  9. * [6817]新版本的挑战地图关卡
  10. * @param req $req
  11. */
  12. public static function NewArenas_Fight($req) {
  13. # 提取参数
  14. $gateId = $req->paras[0]; # 0. 挑战的关卡Id
  15. $difficulty = $req->paras[1]; # 1. 关卡难度 difficulty
  16. $star = $req->paras[2]; # 2. 几星
  17. $TeamObj = $req->paras[3]; # 3. 队伍信息
  18. $bossId = $req->paras[4]; # 4. 本关消灭的bossid (<=0代表本关卡未出现boss)
  19. $rewards = $req->paras[5]; # 5. 本关获得的宝箱列表,id:num,id:num,...
  20. $smGate = GameConfig::gate_getItem($gateId); # 关卡配置数据
  21. ///按 三个难度取不同的值.
  22. $i = $difficulty + 1;
  23. $tili = self::getProperty_n($smGate, "tili", $i);
  24. // $reward = self::getProperty_n($smGate, "reward", $i);
  25. $gold = self::getProperty_n($smGate, "gold", $i);
  26. $exp = self::getProperty_n($smGate, "exp", $i);
  27. self::recordFight($req, $gateId, $difficulty, $star); # 更新战斗记录
  28. $canfighterr = SweepGatesProc::CanFight($req, $gateId, $difficulty); # 是否可以挑战当前关卡计算
  29. if ($canfighterr) { # 不能符合战斗要求
  30. return $canfighterr;
  31. }
  32. //
  33. ActiveProc::ChangeTili(-$tili, $req); # 扣减体力
  34. $req->userInfo->game->gates->TotalNum++; # 更新战斗次数统计
  35. $req->userInfo->game->gates->Times++;
  36. ///增加英雄经验 组长去掉
  37. foreach ($TeamObj as $heroUID) {
  38. HeroProc::HeroAddEXP($heroUID, $tili, $req);
  39. }
  40. $rewardsArr = explode(",", $rewards); // 开箱子抽奖品
  41. $rewardArr = array();
  42. foreach ($rewardsArr as $r) {
  43. $arr = explode(':', $r);
  44. $boxID = intval($arr[0]);
  45. $num = intval($arr[1]);
  46. // $boxMo = GameConfig::item_box_getItem($boxID);
  47. $boxPool = GameConfig::boxpool_getItem($boxID); # 提取对应序列的奖池,
  48. $itemArr = array_filter($boxPool, function($item) use($dropindex) { # 这一步形同虚设了. 所有dropType都填的1
  49. return $item->dropType == 1;
  50. });
  51. $itemArr = Lotterys::FilterPrizepool($req, $itemArr); # 对奖池依解锁等级进行过滤
  52. foreach ($itemArr as $item) {
  53. $prop = $item->normal;
  54. if ($prop < 0) {
  55. $prop = 0;
  56. }
  57. $item->probability = $prop;
  58. }
  59. $err = Lotterys::Dice($itemArr, $num, $rewardstr); # 投骰子
  60. if ($err != ErrCode::ok) { # 出错了
  61. return Resp::err($err);
  62. }
  63. if (strlen($rewardstr) <= 0) { # 抽奖结果为空
  64. return Resp::err(ErrCode::err_innerfault);
  65. }
  66. $rewardArr[] = $rewardstr;
  67. }
  68. if ($bossId > 0) { # boss关处理
  69. $req->userInfo->game->gates->killedBoss[] = $bossId;
  70. }
  71. $err = UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $gold); # 发放金币奖励
  72. if ($err != ErrCode::ok) {
  73. return Resp::err($err);
  74. }
  75. UserGameModel::Add_Exp($req, $exp); # 发放经验奖励
  76. UserProc::updateUserInfo($req); # 在获取战利品哪里已经update了.
  77. $result = array(
  78. 'store' => $req->userInfo->game->store,
  79. 'heros' => $req->userInfo->game->heros,
  80. 'gates' => $req->userInfo->game->gates,
  81. 'tili' => $req->userInfo->game->tili,
  82. 'time' => $req->userInfo->game->privateState->TiliTime,
  83. 'gold' => $gold,
  84. 'exp' => $exp,
  85. 'rewardstr' => implode(';', $rewardArr)
  86. );
  87. return Resp::ok($result);
  88. }
  89. /**
  90. * 更新战斗记录
  91. * @param req $req
  92. * @param type $gateId
  93. * @param type $difficulty
  94. * @param type $star
  95. */
  96. private static function recordFight($req, $gateId, $difficulty, $star) {
  97. if (!CommUtil::isPropertyExists($req->userInfo->game->gates, "newGateRecord")) {
  98. $req->userInfo->game->gates->newGateRecord = ObjectInit(); # 防御未初始化的变量
  99. }
  100. $gatesRecord = $req->userInfo->game->gates->newGateRecord;
  101. if (!CommUtil::isPropertyExists($gatesRecord, "record")) { # 防御未初始化的变量
  102. $gatesRecord->record = ObjectInit();
  103. }
  104. if (!CommUtil::isPropertyExists($gatesRecord->record, $gateId)) { # 补充战斗记录
  105. $gatesRecord->record->$gateId = ObjectInit();
  106. }
  107. if ($difficulty <= 0) {
  108. $gatesRecord->record->$gateId->normal = $star;
  109. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "normalToday")) {
  110. $gatesRecord->record->$gateId->normalToday = 0;
  111. }
  112. } else if ($difficulty == 1) {
  113. $gatesRecord->record->$gateId->hard = $star;
  114. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "hardToday")) {
  115. $gatesRecord->record->$gateId->hardToday = 0;
  116. }
  117. } else if ($difficulty == 2) {
  118. $gatesRecord->record->$gateId->elite = $star;
  119. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "eliteToday")) {
  120. $gatesRecord->record->$gateId->eliteToday = 0;
  121. }
  122. }
  123. $req->userInfo->game->gates->newGateRecord = $gatesRecord; # 回写数据
  124. }
  125. /**
  126. * 提取某个对象的某个字段(利用后面2个参数组合为字段名)
  127. * @param type $obj
  128. * @param type $name
  129. * @param type $index
  130. * @return type
  131. */
  132. private static function getProperty_n($obj, $name, $index) {
  133. if (is_object($obj)) {
  134. $ke = "$name$index";
  135. if (property_exists($obj, $ke)) {
  136. return $obj->$ke;
  137. }
  138. }
  139. return null;
  140. }
  141. /**
  142. * [6818]更改地图所停留的城镇
  143. * //需要消耗体力
  144. * @param type $req
  145. */
  146. public static function ChangeArenas_StayCity($req) {
  147. # 提取参数
  148. # 0. 目标地址
  149. # 1. 消耗体力
  150. $cityId = $req->paras[0];
  151. $costTili = $req->paras[1];
  152. if (!CommUtil::isPropertyExists($req->userInfo->game->gates, "newGateRecord")) {
  153. $req->userInfo->game->gates->newGateRecord = ObjectInit();
  154. }
  155. $gatesRecord = $req->userInfo->game->gates->newGateRecord;
  156. #在此补充检查消耗体力的数值是否正确
  157. #
  158. $gatesRecord->lastStayCityId = $cityId;
  159. $req->userInfo->game->gates->newGateRecord = $gatesRecord;
  160. #体力变化
  161. ActiveProc::ChangeTili(-$costTili, $req);
  162. UserProc::updateUserInfo($req);
  163. $result = array(
  164. 'gates' => $req->userInfo->game->gates,
  165. 'tili' => $req->userInfo->game->tili,
  166. 'time' => $req->userInfo->game->privateState->TiliTime,
  167. );
  168. return Resp::ok($result);
  169. }
  170. /**
  171. * [6801] 关卡挑战1次
  172. * @param Req $req
  173. * @deprecated since version 0 用新版
  174. */
  175. public static function Arenas_Fight($req) {
  176. # 提取参数
  177. # 0. 挑战的关卡Id
  178. # 1. 挑战结果 和李宁商量了,挑战结果是没有用的,只有胜利以后才会发送服务器端.所以这里打算改为关卡难度(0,1,2)
  179. # 2. 挑战记录 // 验证之用.几星.
  180. #3.队伍信息
  181. $gateId = $req->paras[0];
  182. $difficulty = $req->paras[1]; ///这里将会改为关卡难度 difficulty
  183. $star = $req->paras[2];
  184. $TeamObj = $req->paras[3];
  185. $bossId = $req->paras[4]; // 本关消灭的bossid (<=0代表本关卡未出现boss)
  186. $isNewbieGuideGate = false;
  187. if ($gateId == 504001) {
  188. $isNewbieGuideGate = true;
  189. }
  190. $smGate = GameConfig::gate_getItem($gateId);
  191. ///按三个难度取不同的值.
  192. if ($difficulty == 0) {
  193. $gates = $req->userInfo->game->gates->normal;
  194. $tili = $smGate->tili1;
  195. $rwdstr = $smGate->reward1;
  196. $gold = $smGate->gold1;
  197. $exp = $smGate->exp1;
  198. } else if ($difficulty == 1) {
  199. $gates = $req->userInfo->game->gates->hard;
  200. $tili = $smGate->tili2;
  201. $rwdstr = $smGate->reward2;
  202. $gold = $smGate->gold2;
  203. $exp = $smGate->exp2;
  204. } else if ($difficulty == 2) {
  205. $gates = $req->userInfo->game->gates->elite;
  206. $tili = $smGate->tili3;
  207. $rwdstr = $smGate->reward3;
  208. $gold = $smGate->gold3;
  209. $exp = $smGate->exp3;
  210. }
  211. $typeId = substr($gates->highest, 0, 3); #分类
  212. if ($typeId != '503') {
  213. $gates->highest = 503000;
  214. }
  215. if (!$isNewbieGuideGate) {
  216. if ($gateId > $gates->highest + 1) { # 不能跳关
  217. return Resp::err(ErrCode::err_arenasgate_indexillegal);
  218. } else if ($gateId == $gates->highest + 1) {
  219. $gates->highest += 1; // 更新最高记录
  220. }
  221. $gates->latest = $gateId;
  222. #记录数据
  223. $uGate = new UGateModel();
  224. if (isset($gates->gates->$gateId)) {
  225. $uGate = $gates->gates->$gateId;
  226. }
  227. $uGate->challengeTimes++;
  228. if ($uGate->star < $star) {
  229. $uGate->star = $star;
  230. }
  231. $uGate->cleared = 1;
  232. $gates->gates->$gateId = $uGate;
  233. ////体力变化
  234. // UserGameModel::Add_Exp($req->mem, $req->userInfo->game, $tili);////老的增加玩家经验的去掉
  235. ActiveProc::ChangeTili(-$tili, $req);
  236. ///增加英雄经验 这个功能组长取消掉了
  237. // foreach ($TeamObj as $heroUID) {
  238. // HeroProc::HeroAddEXP($heroUID, $tili, $req);
  239. // }
  240. ////总战斗次数+1
  241. $req->userInfo->game->gates->TotalNum++;
  242. $req->userInfo->game->gates->Times++;
  243. }
  244. /////检测如果当前物品格子大于物品总数,则可以获取战利品,否则不可以
  245. ////战利品获取
  246. $err = StoreProc::AddMultiItemInStore($req, $rwdstr);
  247. if ($err) {
  248. return Resp::err($err);
  249. }
  250. if ($bossId > 0) {
  251. $req->userInfo->game->gates->killedBoss[] = $bossId;
  252. }
  253. // 增加发经验和发金币
  254. UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $gold);
  255. UserGameModel::Add_Exp($req, $exp);
  256. UserProc::updateUserInfo($req); //在获取战利品哪里已经update了.
  257. $result = array(
  258. 'store' => $req->userInfo->game->store,
  259. 'heros' => $req->userInfo->game->heros,
  260. 'gates' => $req->userInfo->game->gates,
  261. 'tili' => $req->userInfo->game->tili,
  262. 'time' => $req->userInfo->game->privateState->TiliTime,
  263. 'gold' => $gold,
  264. 'exp' => $exp
  265. );
  266. return Resp::ok($result);
  267. }
  268. //
  269. // <editor-fold defaultstate="collapsed" desc=" 扫荡 ">
  270. // /**
  271. // * 关卡-扫荡
  272. // * @param RequestVo $req
  273. // */
  274. // public static function Arenas_SweepFight($req)
  275. // {
  276. // $resp = ResponseVo::err($req, ErrCode::msg_methodnotimplement);
  277. // # 提取参数
  278. // # 0. 扫荡的关卡Id
  279. // # 1. 扫荡次数
  280. // # 2. 挑战记录 // 验证之用.
  281. // $gateId = $req->paras[0];
  282. // $iNum = $req->paras[1];
  283. // $fightLog = $req->paras[2];
  284. // $isNewbieGuideGate = false;
  285. // $gates = $req->userInfo->game->gates;
  286. // if ($gateId == 504001) {
  287. // $isNewbieGuideGate = true;
  288. // }
  289. // if ($iNum && !$fightLog) {# 检查挑战记录
  290. // return ResponseVo::err($req, ErrCode::err_arenas_logillegal);
  291. // }
  292. // if (!$isNewbieGuideGate) {
  293. // if ($gateId > $gates->highest + 1) { # 不能跳关
  294. // return ResponseVo::err($req, ErrCode::err_arenasgate_indexillegal);
  295. // }
  296. // }
  297. // #记录数据
  298. // $uGate = new UGateModel();
  299. // if (isset($gates->gates->$gateId)) {
  300. // $uGate = $gates->gates->$gateId;
  301. // }
  302. // $uGate->challengeTimes += $iNum;
  303. // $gates->gates->$gateId = $uGate;
  304. // UserProc::updateUserInfo($req);
  305. // $resp = ResponseVo::ok($req, array()); // 返回成功,以及奖励数据
  306. //
  307. // return $resp;
  308. // }
  309. /**
  310. * [6802]新扫荡
  311. * @param req $req
  312. */
  313. public static function Arenas_NewSweepFight($req) {
  314. $gateId = $req->paras[0];
  315. $difficulty = $req->paras[1]; # 关卡难度 difficulty
  316. $costItemId = $req->paras[2]; #扫荡券id
  317. $smGate = GameConfig::gate_getItem($gateId);
  318. if (!CommUtil::isPropertyExists($req->userInfo->game->gates, "newGateRecord")) {
  319. $req->userInfo->game->gates->newGateRecord = ObjectInit(); # 防御未初始化的变量
  320. }
  321. $gatesRecord = $req->userInfo->game->gates->newGateRecord;
  322. if (!CommUtil::isPropertyExists($gatesRecord, "record")) {
  323. $gatesRecord->record = ObjectInit(); # 防御未初始化的变量
  324. }
  325. ///按 三个难度取不同的值.
  326. $i = $difficulty + 1;
  327. $tili = self::getProperty_n($smGate, "tili", $i);
  328. $reward = self::getProperty_n($smGate, "reward", $i);
  329. $gold = self::getProperty_n($smGate, "gold", $i);
  330. $exp = self::getProperty_n($smGate, "exp", $i);
  331. $err = StoreProc::removeItemFromStore($req->userInfo->game->store, $costItemId, 1);
  332. if ($err) { # 扣除失败
  333. return Resp::err($err);
  334. }
  335. #补充战斗记录
  336. $canfighterr = SweepGatesProc::CanFight($req, $gateId, $difficulty);
  337. if ($canfighterr) {#不能符合战斗要求
  338. return $canfighterr;
  339. }
  340. //
  341. $req->userInfo->game->gates->newGateRecord = $gatesRecord; # 回写数据
  342. ActiveProc::ChangeTili(- $tili, $req); # 扣减体力
  343. $req->userInfo->game->gates->TotalNum++; # 更新战斗次数统计
  344. $req->userInfo->game->gates->Times++;
  345. // 按照概率规则发放奖品
  346. $rewardsArr = explode(";", $reward);
  347. $rwds = array();
  348. foreach ($rewardsArr as $r) {
  349. $arr = explode(',', $r);
  350. $itemid = intval($arr[0]);
  351. $num = intval($arr[1]);
  352. $probability = intval($arr[2]);
  353. if (CommUtil::randomPercent($probability)) { # 投色子
  354. $err = StoreProc::AddMultiItemInStore($req, "$itemid,$num");
  355. if ($err) {
  356. return Resp::err($err);
  357. }
  358. $rwds[] = "$itemid,$num";
  359. }
  360. }
  361. UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $gold); # 发放金币奖励
  362. if ($err) {
  363. return Resp::err($err);
  364. }
  365. UserGameModel::Add_Exp($req, $exp); # 发放经验奖励
  366. UserProc::updateUserInfo($req); # 在获取战利品哪里已经update了.
  367. $result = array(
  368. 'store' => $req->userInfo->game->store,
  369. 'heros' => $req->userInfo->game->heros,
  370. 'gates' => $req->userInfo->game->gates,
  371. 'tili' => $req->userInfo->game->tili,
  372. 'time' => $req->userInfo->game->privateState->TiliTime,
  373. 'gold' => $gold,
  374. 'exp' => $exp,
  375. 'rewardstr' => implode(';', $rwds)
  376. );
  377. return Resp::ok($result);
  378. }
  379. /**
  380. * 是否可以战斗
  381. * @param type $req
  382. * @param $gateId
  383. * @param $difficulty
  384. * @return type
  385. */
  386. static function CanFight($req, $gateId, $difficulty) {
  387. $gatesRecord = $req->userInfo->game->gates->newGateRecord;
  388. $smGate = GameConfig::gate_getItem($gateId);
  389. if (!CommUtil::isPropertyExists($gatesRecord->record, $gateId)) {
  390. $gatesRecord->record->$gateId = ObjectInit();
  391. }
  392. if ($difficulty > 2) {
  393. return Resp::err(ErrCode::err_arenasgate_indexillegal);
  394. }
  395. if ($difficulty == 0) {
  396. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "normal")) {
  397. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  398. }
  399. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "normalToday")) {
  400. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  401. }
  402. if ($smGate->cishu1 - $gatesRecord->record->$gateId->normalToday < 1) {
  403. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  404. }
  405. $gatesRecord->record->$gateId->normalToday += 1;
  406. } else if ($difficulty == 1) {
  407. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "hard")) {
  408. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  409. }
  410. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "hardToday")) {
  411. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  412. }
  413. if ($smGate->cishu2 - $gatesRecord->record->$gateId->hardToday < 1) {
  414. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  415. }
  416. $gatesRecord->record->$gateId->hardToday += 1;
  417. } else if ($difficulty == 2) {
  418. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "elite")) {
  419. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  420. }
  421. if (!CommUtil::isPropertyExists($gatesRecord->record->$gateId, "eliteToday")) {
  422. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  423. }
  424. if ($smGate->cishu3 - $gatesRecord->record->$gateId->eliteToday < 1) {
  425. return Resp::err(ErrCode::err_arenas_normalgate_numno);
  426. }
  427. $gatesRecord->record->$gateId->eliteToday += 1;
  428. }
  429. return null; // false
  430. }
  431. // </editor-fold>
  432. //
  433. /**
  434. * [6803] 关卡—————— 根据星星数量获得对应奖励
  435. * @param type $req
  436. * @deprecated since version 0 用新版
  437. */
  438. public static function GetArenasStarReward($req) {
  439. $resp = Resp::err(ErrCode::err_method_notimplement);
  440. $gamedata = $req->userInfo->game;
  441. $rewardID = $req->paras[0]; //奖励的数据ID
  442. //1.检查奖励数据是否存在
  443. $rewardCfg = GameConfig::gate_starreward_getItem($rewardID); // ConstProc::getArenasGate_StarReward($rewardID);
  444. if (!$rewardCfg) {
  445. return Resp::err(ErrCode::err_arenas_starreward_const_no);
  446. }
  447. //2.检查玩家是否已经领取了
  448. $gates = $req->userInfo->game->gates;
  449. $getStarRewardRecord = ArrayInit();
  450. if (CommUtil::isPropertyExists($gates, "starRewards")) {
  451. $getStarRewardRecord = $gates->starRewards;
  452. }
  453. if (CommUtil::isInArray($getStarRewardRecord, $rewardID)) {
  454. return Resp::err(ErrCode::err_arenas_hasgetstarreward);
  455. }
  456. //3.检查玩家的当前星星数是否满足数量要求
  457. //"normal": {
  458. // "latest": 502001,
  459. // "highest": 502001,
  460. // "gates": {
  461. // "502001": {
  462. // "star": 3,
  463. // "cleared": 1,
  464. // "challengeTimes": 1
  465. // }
  466. // }
  467. $totalStarNum = 0;
  468. $normalRecord = $gates->normal;
  469. foreach ($normalRecord->gates as $key => $gate) {
  470. $totalStarNum += $gate->star;
  471. }
  472. $hardRecord = $gates->hard;
  473. foreach ($hardRecord->gates as $key => $gate) {
  474. $totalStarNum += $gate->star;
  475. }
  476. $eliteRecord = $gates->elite;
  477. foreach ($eliteRecord->gates as $key => $gate) {
  478. $totalStarNum += $gate->star;
  479. }
  480. DebugHelper::var_dump($totalStarNum);
  481. if ($totalStarNum < $rewardCfg->star) {
  482. return Resp::err(ErrCode::err_arenas_starreward_starNotEnough);
  483. }
  484. $rewardStr = $rewardCfg->reward;
  485. $arr_reward = explode(",", $rewardStr);
  486. $itemId = $arr_reward[0];
  487. $itemNum = $arr_reward[1];
  488. $str1 = substr($itemId, 0, 3);
  489. switch ($str1) {
  490. ///怪物卡或者英雄卡牌获取
  491. case "101":
  492. case "201":
  493. // HeroProc::AddHeroTFromStore($req, $itemId);
  494. break;
  495. ///装备物品的获取.
  496. case "301":
  497. case "302":
  498. case "303":
  499. StoreProc::PutEquipInStore($itemId, $req);
  500. break;
  501. ///宝石的获取
  502. case "304":
  503. StoreProc:: PutOverlyingItemInStore($itemId, $itemNum, $req);
  504. break;
  505. //金币的获取
  506. case "399":
  507. if ($itemId == "399002") {
  508. UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $itemNum);
  509. }
  510. break;
  511. default:
  512. break;
  513. }
  514. //保存记录
  515. $getStarRewardRecord[] = $rewardID;
  516. $req->userInfo->game->gates->starRewards = $getStarRewardRecord;
  517. // 更新数据库数据
  518. UserProc::updateUserInfo($req);
  519. $result = ObjectInit();
  520. $result->getreward = true;
  521. $resp = Resp::ok($result);
  522. return $resp;
  523. }
  524. /**
  525. * [6804] 扣除买buffer的费用
  526. * @param type $req
  527. * @return type
  528. */
  529. public static function ConsumeBufferGold($req) {
  530. $user = $req->userInfo->game; # user引用
  531. $money = $req->paras[0]; //需要的手工费
  532. // echo var_dump($money);
  533. $bDeal = UserGameModel::Consume_Gold($user, $money);
  534. if ($bDeal) {
  535. $result = array(
  536. 'resp' => "succeed!"
  537. );
  538. // 更新数据库数据
  539. $resp = Resp::ok($result);
  540. } else {
  541. // $user->gold=0;
  542. $result = array(
  543. 'resp' => "succeed!"
  544. );
  545. // 更新数据库数据
  546. $resp = Resp::ok($result);
  547. }
  548. UserProc::updateUserInfo($req);
  549. return $resp;
  550. }
  551. //
  552. // <editor-fold defaultstate="collapsed" desc=" 好友租借 ">
  553. /**
  554. * [6805] 查询租借好友记录
  555. * @param Req $req
  556. */
  557. public static function GetBorrowedFriends($req) {
  558. // 查询好友借用记录中的数据
  559. $rentedfriends = $req->userInfo->game->privateState->rentedFriends;
  560. if (!$rentedfriends || !is_array($rentedfriends)) {
  561. $rentedfriends = ArrayInit();
  562. }
  563. return Resp::ok(array('ret' => $rentedfriends));
  564. }
  565. /**
  566. * 清理战斗租借好友记录
  567. *
  568. */
  569. public static function ClearFightRentRecord($req) {
  570. $req->userInfo->game->privateState->rentedFriends = ArrayInit();
  571. }
  572. /**
  573. * [6806] 扣除借用好友费用
  574. * @param Req $req
  575. */
  576. public static function ConsumeBorrowFriend($req) {
  577. // 提取参数:好友id
  578. $friend_uid = $req->paras[0];
  579. // 验证好友关系
  580. if (!FriendProc::isFriendship($req->zoneid, $req->uid, $friend_uid)) {
  581. return Resp::err(ErrCode::friend_no_err);
  582. }
  583. // 验证尚未租借过
  584. $rentedfriends = $req->userInfo->game->privateState->rentedFriends;
  585. if (!$rentedfriends || !is_array($rentedfriends)) {
  586. $rentedfriends = ArrayInit();
  587. }
  588. if (in_array($friend_uid, $rentedfriends)) {
  589. return Resp::err(array('err' => -1, 'msg' => 'has rented this player today!'));
  590. }
  591. // 验证好友出借英雄
  592. $friend_info = UserProc::getUserInfo(gMem(), $req->zoneid, $friend_uid);
  593. if (!$friend_info) {
  594. return Resp::err(ErrCode::user_no_err, '找不到好友的游戏数据!');
  595. }
  596. // todo:啦啦啦... 先不写了,管它用的是哪个英雄呢
  597. //
  598. // 扣除费用,失败->金币不足
  599. $arr = explode(',', glc()->User_Friends_HireFriendForBattle_Cost);
  600. if (count($arr) < 2) {
  601. return Resp::err(ErrCode::err_const_no);
  602. }
  603. $itemid = $arr[0]; # 道具id
  604. $amt = $arr[1]; # 数量
  605. if ($itemid == META_GOLD_ITEMID) {
  606. $user = $req->userInfo->game;
  607. if ($user->gold < $amt) {
  608. return Resp::err(array('err' => -2, 'msg' => 'gold not enough!'));
  609. }
  610. UserGameModel::Consume_Gold($user, $amt);
  611. // todo: 给好友发送金币 邮件
  612. EmailProc::SendHireCoinFromFight($req->zoneid, $friend_uid, #
  613. $req->userInfo->game->name, $req->uid, $amt); # 好友收益需要扣除系统税率.
  614. } else {
  615. return Resp::err(ErrCode::err_const_no);
  616. }
  617. // 添加借用记录
  618. $rentedfriends[] = $friend_uid;
  619. $req->userInfo->game->privateState->rentedFriends = $rentedfriends;
  620. // 回写数据
  621. UserProc::updateUserInfo($req); // 玩家数据
  622. // UserProc::setUserInfo(global_mem(), $friend_info); // 好友数据
  623. // 返回
  624. return Resp::ok(array('err' => 0, 'curgold' => $user->gold));
  625. }
  626. // </editor-fold>
  627. //
  628. /**
  629. * [6807] 挑战黄金 无穷无尽战斗模式
  630. * @param type $req
  631. */
  632. public static function ChallengeEndlessFightMode_Gold($req) {
  633. $gateForeverId = $req->paras[0];
  634. $difficuty = $req->paras[1];
  635. $bociCount = $req->paras[2];
  636. //判断是否已经达到挑战的次数上限
  637. $gates = $req->userInfo->game->gates;
  638. if (!CommUtil::isPropertyExists($gates, "forever_Gold_FightTimes")) {
  639. $gates->forever_Gold_FightTimes = 0;
  640. }
  641. if ($gates->forever_Gold_FightTimes >= glc()->Battle_Forever_MaxCountEveryDay) {
  642. return Resp::err(ErrCode::err_gateForever_countIsFull, '挑战次数已经用尽!');
  643. }
  644. //1.取出无尽模式的关卡常量数据
  645. $gateForeverConst = GameConfig::gateforever_getItem($gateForeverId); // ConstProc::getGold_GateForeverGoldConst($gateForeverId);
  646. $gateBattleBociConst = GameConfig::gatecombat_getItem($gateForeverId);
  647. if (!$gateForeverConst) {
  648. return Resp::err(ErrCode::err_gateForever_const_no);
  649. }
  650. //判断次数是否合法
  651. $bociArr = explode(",", $gateBattleBociConst->level);
  652. if ($bociCount > count($bociArr)) {
  653. return Resp::err(ErrCode::err_gateForever_countillegal);
  654. }
  655. //2.取出模式下的奖励数据
  656. $rewardStr = $gateForeverConst->reward1;
  657. $arr_reward = explode(";", $rewardStr);
  658. foreach ($arr_reward as $value) {
  659. if (strlen($value) > 0) {
  660. $arr_RealReward = explode(",", $value);
  661. $itemId = $arr_RealReward[0];
  662. $itemNum = $arr_RealReward[1];
  663. $str1 = substr($itemId, 0, 3);
  664. //3.根据挑战的波次数据,重复累计获得奖励
  665. for ($i = 0; $i < $bociCount; $i++) {
  666. switch ($str1) {
  667. ///怪物卡或者英雄卡牌获取
  668. case "101":
  669. case "201":
  670. // HeroProc::AddHeroTFromStore($req, $itemId);
  671. break;
  672. ///装备物品的获取.
  673. case "301":
  674. case "302":
  675. case "303":
  676. StoreProc::PutEquipInStore($itemId, $req);
  677. break;
  678. ///宝石的获取
  679. case "304":
  680. StoreProc:: PutOverlyingItemInStore($itemId, $itemNum, $req);
  681. break;
  682. //金币的获取
  683. case "399":
  684. if ($itemId == "399002") {
  685. UserGameModel::Add_Gold($req->mem, $req->userInfo->game, $itemNum);
  686. }
  687. break;
  688. default:
  689. break;
  690. }
  691. }
  692. }
  693. }
  694. //4、存储玩家的挑战次数
  695. $gates->forever_Gold_FightTimes = $gates->forever_Gold_FightTimes + 1;
  696. // 回写数据
  697. UserProc::updateUserInfo($req);
  698. $result = ObjectInit();
  699. $result->result = "succeed";
  700. $result->forever_Gold_FightTimes = $gates->forever_Gold_FightTimes;
  701. $resp = Resp::ok($result);
  702. return $resp;
  703. }
  704. /**
  705. * 清理挑战无尽模式的 次数记录
  706. *
  707. */
  708. public static function ClearGateForeverGold_FightCountEveryDay($req) {
  709. $req->userInfo->game->gates->forever_Gold_FightTimes = 0;
  710. }
  711. /**
  712. * 清理每个难度副本的每日战斗次数
  713. * @param type $req
  714. */
  715. public static function ClearGateTimes($req) {
  716. if (!CommUtil::isPropertyExists($req->userInfo->game->gates, 'newGateRecord')) {
  717. $req->userInfo->game->gates->newGateRecord = ObjectInit();
  718. }
  719. if (!CommUtil::isPropertyExists($req->userInfo->game->gates->newGateRecord, 'record')) {
  720. return;
  721. }
  722. $obj = $req->userInfo->game->gates->newGateRecord->record;
  723. //$result = empty($obj);
  724. // if ($result == true) {
  725. // return;
  726. //}
  727. foreach ($obj as $key => $value) {
  728. $value->normalToday = 0;
  729. $value->hardToday = 0;
  730. $value->eliteToday = 0;
  731. }
  732. UserProc::updateUserInfo($req);
  733. }
  734. //
  735. // <editor-fold defaultstate="collapsed" desc=" 副本 ">
  736. //
  737. /**
  738. * [6801] 开启副本
  739. * @param Req $req
  740. */
  741. public static function OpenTheCarbon($req) {
  742. $gates = $req->userInfo->game->gates;
  743. $openedcarbons = $gates->carbons->openedCarbons;
  744. # 提取参数
  745. $carbonId = $req->paras[0]; # 副本ID
  746. $difficulty = $req->paras[1]; # 难度等级 1,2,3
  747. $key = "$carbonId-$difficulty"; # 键值
  748. if (!($gates && $openedcarbons)) {
  749. return Resp::err(ErrCode::err_innerfault);
  750. }
  751. if ($difficulty > 3 || $difficulty < 1) {
  752. return Resp::err(ErrCode::carbon_wrongdifficult);
  753. }
  754. if (CommUtil::isPropertyExists($openedcarbons, $key)) {
  755. $carbon = $openedcarbons->$key;
  756. } else {
  757. $carbon = new CarbonModel();
  758. }
  759. if ($carbon->closeTs > now()) {
  760. return Resp::err(ErrCode::carbon_opened);
  761. }
  762. $carbonModel = GameConfig::gate_carbon_getItem($carbonId); # 常量
  763. # 扣除开启消耗的道具
  764. $keyid = "keyId$difficulty";
  765. $keynum = "keyNum$difficulty";
  766. $costItemId = $carbonModel->$keyid;
  767. $costItemNum = $carbonModel->$keynum;
  768. $err = StoreProc::removeItemFromStore($req->userInfo->game->store, $costItemId, $costItemNum);
  769. if ($err) { # 扣除失败
  770. return Resp::err($err);
  771. }
  772. $carbon->closeTs = now() + $carbonModel->duration; # 关闭倒计时
  773. $carbon->curIndex = 0; # 索引重置为0
  774. $openedcarbons->$key = $carbon;
  775. $req->userInfo->game->gates->carbons->openedCarbons = $openedcarbons;
  776. UserProc::updateUserInfo($req);
  777. return Resp::ok(array('err' => 0, 'carbons' => $openedcarbons));
  778. }
  779. /**
  780. * 挑战副本关卡
  781. * @param Req $req
  782. */
  783. public static function ChallengeCarbon($req) {
  784. $gates = $req->userInfo->game->gates;
  785. $carbons = $gates->carbons->openedCarbons;
  786. # 提取参数
  787. $carbonId = $req->paras[0]; # 副本ID
  788. $difficulty = $req->paras[1]; # 难度等级 1,2,3
  789. $gateindex = $req->paras[2]; # 关卡索引 0,1,2,...
  790. $star = $req->paras[3]; # 战斗评价(几星)
  791. $TeamObj = $req->paras[4]; # 队伍信息
  792. // $bossId = $req->paras[5]; # 本关消灭的bossid (<=0代表本关卡未出现boss)
  793. if ($difficulty > 3 || $difficulty < 1) {
  794. return Resp::err(ErrCode::carbon_wrongdifficult);
  795. }
  796. $key = "$carbonId-$difficulty"; # 键值
  797. # 0 当前副本处于开启状态
  798. # 1 当前关卡索引,不能跳着打,
  799. # 2 记录下战斗评价(几星), 也许以后用得着,比如最后通关后,给个啥奖励
  800. # 3 决定掉落物品, 发给客户端
  801. # 4 发放对应的经验之类的东西
  802. # 5 检查是否最后一个关卡, 是, 关闭副本
  803. # 6 回存数据,返回
  804. isEditor() && $carbon = new CarbonModel;
  805. if (CommUtil::isPropertyExists($carbons, $key)) {
  806. $carbon = $carbons->$key;
  807. } else {
  808. $carbon = null;
  809. }
  810. if (!$carbon || $carbon->closeTs < now()) {
  811. return Resp::err(ErrCode::carbon_closed);
  812. }
  813. $carbonModel = GameConfig::gate_carbon_getItem($carbonId); # 副本常量数据
  814. $gateIds = explode(',', $carbonModel->gateids);
  815. if ($gateindex < 0 || $gateindex >= count($gateIds)) {
  816. return Resp::err(ErrCode::carbon_gateIndex);
  817. }
  818. if ($carbon->curIndex == $gateindex || $gateindex == 0) {
  819. $carbon->curIndex += 1; # 更新进度
  820. } else { # 不能跳关
  821. return Resp::err(ErrCode::carbon_gateIndex);
  822. }
  823. $gateId = $gateIds[$gateindex]; # 通过索引获得关卡ID
  824. $tl = "tili$difficulty"; # 体力难度
  825. $rwd = "reward$difficulty"; # 奖励难度
  826. $arr = array("normal", 'hard', 'elite'); # 难度名称
  827. $gt = $arr[$difficulty - 1]; # 关卡分类
  828. $gateModel = GameConfig::gate_carbon_content_getItem($gateId); # 副本关卡常量数据
  829. $tili = $gateModel->$tl; # 扣除体力
  830. $reward = $gateModel->$rwd; # 获得奖励
  831. #
  832. # 打副本呢也要扣除体力
  833. ActiveProc::ChangeTili(-$tili, $req);
  834. # 扣除多少体力就给账号增加多少经验 -by 李宁, reconfirmed by wg 20170519144109
  835. UserGameModel::Add_Exp($req, $tili);
  836. # 增加英雄经验(也是依据扣除的体力数)
  837. foreach ($TeamObj as $heroUID) {
  838. HeroProc::HeroAddEXP($heroUID, $tili, $req);
  839. }
  840. // $carbon->stars; 暂不记录了
  841. # 掉落战利品->获取
  842. $err = StoreProc::AddMultiItemInStore($req, $reward);
  843. if ($err) {
  844. return Resp::err($err);
  845. }
  846. if (count($gateIds) == $gateindex + 1) { # 最后一个关卡
  847. unset($carbons->$key); # 关闭掉关卡,或者是直接删掉
  848. } else {
  849. $carbons->$key = $carbon; # 回存数据
  850. }
  851. $req->userInfo->game->gates->carbons->openedCarbons = $carbons;
  852. UserProc::updateUserInfo($req); //在获取战利品哪里已经update了.
  853. # Ps.备注,奖品是固定的,所以不必返回
  854. $result = array(
  855. 'store' => $req->userInfo->game->store,
  856. 'heros' => $req->userInfo->game->heros,
  857. 'gates' => $req->userInfo->game->gates,
  858. 'tili' => $req->userInfo->game->tili,
  859. 'time' => $req->userInfo->game->privateState->TiliTime
  860. );
  861. return Resp::ok($result);
  862. }
  863. /**
  864. * [6809]新版本的挑战 副本胜利
  865. * @param Req $req
  866. */
  867. public static function NewChallengeCarbon($req) {
  868. $gates = $req->userInfo->game->gates;
  869. $carbons = $gates->carbons->openedCarbons;
  870. # 提取参数
  871. $carbonId = $req->paras[0]; # 副本ID
  872. $gateId = $req->paras[1]; # 关卡ID
  873. $difficulty = $req->paras[2]; # 难度等级 1,2,3
  874. $star = $req->paras[3]; # 战斗评价(几星)
  875. $TeamObj = $req->paras[4]; # 队伍信息
  876. if ($difficulty > 3 || $difficulty < 1) {
  877. return Resp::err(ErrCode::carbon_wrongdifficult);
  878. }
  879. $key = "$carbonId-$difficulty"; # 键值
  880. # 0 当前副本处于开启状态
  881. # 1 战斗胜利之后,副本直接关闭
  882. # 2 记录下战斗评价(几星), 也许以后用得着,比如最后通关后,给个啥奖励
  883. # 3 决定掉落物品, 发给客户端
  884. # 4 发放对应的经验之类的东西
  885. # 5 检查是否最后一个关卡, 是, 关闭副本
  886. # 6 回存数据,返回
  887. isEditor() && $carbon = new CarbonModel;
  888. if (CommUtil::isPropertyExists($carbons, $key)) {
  889. $carbon = $carbons->$key;
  890. } else {
  891. $carbon = null;
  892. }
  893. if (!$carbon || $carbon->closeTs < now()) {
  894. return Resp::err(ErrCode::carbon_closed);
  895. }
  896. unset($carbons->$key);
  897. $tl = "tili$difficulty"; # 体力难度
  898. $rwd = "reward$difficulty"; # 奖励难度
  899. $gateModel = GameConfig::gate_carbon_content_getItem($gateId); # 副本关卡常量数据
  900. $tili = $gateModel->$tl; # 扣除体力
  901. $reward = $gateModel->$rwd; # 获得奖励
  902. #
  903. # 打副本呢也要扣除体力
  904. ActiveProc::ChangeTili(-$tili, $req);
  905. // 按照概率规则发放奖品
  906. $rewardsArr = explode(";", $reward);
  907. $rwds = array();
  908. foreach ($rewardsArr as $r) {
  909. $arr = explode(',', $r);
  910. $itemid = intval($arr[0]);
  911. $num = intval($arr[1]);
  912. $probability = floatval($arr[2]); # 掉落概率精度精确到±0.01%
  913. if (CommUtil::randomPercent($probability)) { # 投色子
  914. $err = StoreProc::AddMultiItemInStore($req, "$itemid,$num");
  915. if ($err) {
  916. return Resp::err($err);
  917. }
  918. $rwds[] = "$itemid,$num";
  919. }
  920. }
  921. if ($err) {
  922. return Resp::err($err);
  923. }
  924. $req->userInfo->game->gates->carbons->openedCarbons = $carbons;
  925. UserProc::updateUserInfo($req); //在获取战利品哪里已经update了.
  926. # Ps.备注,奖品是固定的,所以不必返回
  927. SystemProc::Carbon_Win($req->zoneid, $req->userInfo->game, $carbonId, $difficulty); # 插入通过副本消息
  928. $result = array(
  929. 'store' => $req->userInfo->game->store,
  930. 'heros' => $req->userInfo->game->heros,
  931. 'gates' => $req->userInfo->game->gates,
  932. 'tili' => $req->userInfo->game->tili,
  933. 'time' => $req->userInfo->game->privateState->TiliTime,
  934. 'gold' => 0,
  935. 'exp' => 0,
  936. 'rewardstr' => implode(';', $rwds)
  937. );
  938. return Resp::ok($result);
  939. }
  940. /**
  941. * [6816] 挑战剧情关卡
  942. * @param type $req
  943. */
  944. public static function ChallengeStoryGate($req) {
  945. $gates = $req->userInfo->game->gates;
  946. # 提取参数
  947. $storyId = $req->paras[0]; # 剧情ID
  948. $difficulty = $req->paras[1]; # 难度等级 1,2,3
  949. $star = $req->paras[2]; # 战斗评价(几星)
  950. $TeamObj = $req->paras[3]; # 队伍信息
  951. $bossId = $req->paras[4]; # 本关消灭的bossid (<=0代表本关卡未出现boss)
  952. //
  953. #1. 判断是否有记录过剧情的战斗信息
  954. if (!CommUtil::isPropertyExists($gates, "story")) {
  955. $gates->story = ObjectInit();
  956. $gates->story->lastFinishedStoryGateId = 0;
  957. $gates->story->allFinishedStoryGateIdList = ArrayInit();
  958. }
  959. $storrRecord = $gates->story;
  960. #2.取出模式下的奖励数据
  961. $memStoryModel = GameConfig::gatestory_getItem($storyId);
  962. $tili = 0;
  963. $rewardStr = $memStoryModel->storyGateReward;
  964. #3 同步下剧情的推进进度数据
  965. if ($storrRecord->lastFinishedStoryGateId == $storyId || in_array($storyId, $storrRecord->allFinishedStoryGateIdList)) {
  966. return Resp::err(ErrCode::story_repeatfight); #剧情关卡不能重复战斗 只能打一次
  967. } else {
  968. $storrRecord->lastFinishedStoryGateId = $storyId;
  969. $storrRecord->allFinishedStoryGateIdList[] = $storyId;
  970. }
  971. #
  972. # 4 万一打剧情也扣除体力呢
  973. if ($tili > 0) {
  974. ActiveProc::ChangeTili(-$tili, $req);
  975. # 扣除多少体力就给账号增加多少经验 -by 李宁, reconfirmed by wg 20170519144109
  976. UserGameModel::Add_Exp($req, $tili);
  977. # 增加英雄经验(也是依据扣除的体力数)
  978. foreach ($TeamObj as $heroUID) {
  979. HeroProc::HeroAddEXP($heroUID, $tili, $req);
  980. }
  981. }# 5 玩家获得 剧情的战斗奖励
  982. $err = StoreProc::AddMultiItemInStore($req, $rewardStr);
  983. if ($err) {
  984. return Resp::err($err);
  985. }# 6 回存玩家的战斗记录
  986. $req->userInfo->game->gates->story = $storrRecord;
  987. UserProc::updateUserInfo($req); //在获取战利品哪里已经update了.
  988. # Ps.备注,奖品是固定的,所以不必返回
  989. $result = array(
  990. 'store' => $req->userInfo->game->store,
  991. 'heros' => $req->userInfo->game->heros,
  992. 'gates' => $req->userInfo->game->gates,
  993. 'tili' => $req->userInfo->game->tili,
  994. 'time' => $req->userInfo->game->privateState->TiliTime
  995. );
  996. return Resp::ok($result);
  997. }
  998. //
  999. // </editor-fold>
  1000. //
  1001. }