SweepGatesProc.php 43 KB

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