SweepGatesProc.php 33 KB

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