SweepGatesProc.php 43 KB

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