SweepGatesProc.php 41 KB

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