SweepGatesProc.php 43 KB

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