SweepGatesProc.php 40 KB

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