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