SweepGatesProc.php 41 KB

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