SweepGatesProc.php 40 KB

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