SweepGatesProc.php 41 KB

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