SweepGatesProc.php 43 KB

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