SweepGatesProc.php 43 KB

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