SweepGatesProc.php 39 KB

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