SweepGatesProc.php 40 KB

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