SweepGatesProc.php 38 KB

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