SweepGatesProc.php 43 KB

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