SweepGatesProc.php 43 KB

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