SweepGatesProc.php 42 KB

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