SweepGatesProc.php 40 KB

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