FightProc.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 战斗模块
  5. * @author c'y'zhao
  6. */
  7. class FightProc {
  8. public const TowerGateId = 940011999;
  9. /**
  10. * 逻辑分发
  11. * 所有的Proc中必须有这样一个方法
  12. * @param Req $req
  13. */
  14. public static function procMain($req) {
  15. switch ($req->cmd) {
  16. case CmdCode::fight_settle: # 6801 主线战斗结算
  17. return FightProc::Settle();
  18. case CmdCode::fight_PassGateTsPrizeReceive: # 6802 章节宝箱的领取
  19. return FightProc::PassGateTsPrizeReceive();
  20. case CmdCode::fight_selectGate: # 6803 主线剧情关卡选择
  21. return FightProc::SelectGate();
  22. case CmdCode::fight_gateChallengeRewards: # 6804 挑战关卡: 领取奖励
  23. return FightProc::GateChallengeRewards();
  24. case CmdCode::fihgt_reliveCost: # 6805 战斗: 复活花费
  25. return FightProc::ReliveCost();
  26. case CmdCode::fight_plotSav: # 6806 主线剧情(已播放)回存
  27. return FightProc::PlotSav();
  28. case CmdCode::fight_sweep: # 6807 主线扫荡
  29. return FightProc::FightSweep();
  30. case CmdCode::fight_startFight: # 6808 主线剧情关卡开始挑战
  31. return self::StartFight();
  32. case CmdCode::fight_tower_RefreshSkills: # 6809 挑战关卡: 刷新初始技能
  33. return self::TowerRefreshSkills();
  34. case CmdCode::fight_tower_updatelocklist: # 6810 挑战关卡: 更新技能锁定列表
  35. return self::TowerUpdateLockskillList();
  36. case CmdCode::fight_rankInfo: # 6811 获取主线关卡排行榜信息
  37. return self::GetRankInfo();
  38. case CmdCode::fight_rank_uidEquipInfo: # 6812 获取主线关卡榜内玩家的装备信息
  39. return self::GetUidEquipInfo_Rank();
  40. case CmdCode::fight_rank_GetMainGateRankRewardInfo: # 6813 获取通关荣誉榜信息
  41. return self::GetmainGate_RankRewardInfo();
  42. case CmdCode::fight_rank_GetFightPowerRankRewardInfo: # 6814 获取战力荣誉榜信息
  43. return self::GetFightPower_RankRewardInfo();
  44. case CmdCode::fight_rank_ReceiveRankReward_MainGate: # 6815 领取通关荣誉榜奖励
  45. return self::ReceiveRankReward_MainGate();
  46. case CmdCode::fight_rank_ReceiveRankReward_FightPower: # 6816 领取战力荣誉榜奖励
  47. return self::ReceiveRankReward_FightPower();
  48. case CmdCode::fight_rank_IsExistRankReward: # 6817 是否存在未领取的荣誉榜奖励
  49. return self::IsExistRankReward();
  50. case CmdCode::fight_evolveUnlock: # 6818 启灵解锁
  51. return self::EvolveUnlock();
  52. case CmdCode::fight_MainTZPass: # 6819 主线挑战--通关
  53. return self::MainTZPass();
  54. case CmdCode::fight_MainTZGetReward: # 6820 主线挑战--领取奖励
  55. return self::MainTZGetReward();
  56. case CmdCode::fight_ResetChallange_RedMask: # 6821 每天重置挑战红点
  57. return self::ResetChallange_RedMask();
  58. case CmdCode::fight_lockSkill: # 6822 封印/解封技能
  59. return self::LockSkill();
  60. case CmdCode::fight_buyLockSkillCount: # 6823 购买更多封印数量
  61. return self::BuySkillLockCount();
  62. default:
  63. Err(ErrCode::cmd_err);
  64. }
  65. }
  66. /**
  67. * 6823 购买更多技能封印数量
  68. */
  69. static function BuySkillLockCount() {
  70. list($n) = req()->paras; # 解锁数量
  71. my_Assert($n > ctx()->privateData()->skillLockerNumber, ErrCode::paras_err); # 参数异常
  72. $amt = 0;
  73. foreach (explode(",", glc()->Skill_LockBtn_BuyCount_Cost) as $str) {
  74. list($cnt, $cost) = explode(':', $str);
  75. if ($cnt == $n) {
  76. $amt = $cost;
  77. break;
  78. }
  79. }
  80. my_Assert($amt > 0, "消耗元宝数量配置出错!");
  81. my_Assert(ctx()->base()->Consume_Cash($amt), ErrCode::notenough_cash_msg);
  82. ctx()->privateData()->skillLockerNumber = $cnt;
  83. UserProc::updateUserInfo();
  84. return Resp::ok();
  85. }
  86. /**
  87. * 6822 封印/解封技能
  88. */
  89. static function LockSkill() {
  90. list($skillTypeId) = req()->paras; # 技能类型ID
  91. $pri = ctx()->privateData();
  92. // my_Assert(in_array($skillTypeId, $pri->skillUnlockRecord), "技能尚未解锁!");
  93. if (in_array($skillTypeId, $pri->skillReLocked)) { # 解封
  94. StlUtil::arrayRemove($pri->skillReLocked, $skillTypeId);
  95. } else { # 封印
  96. my_Assert(count($pri->skillReLocked) < $pri->skillLockerNumber, "超出封印上限!");
  97. $pri->skillReLocked[] = $skillTypeId;
  98. }
  99. return Resp::ok();
  100. }
  101. /**
  102. * 6821 每天重置挑战红点
  103. */
  104. static function ResetChallange_RedMask() {
  105. ctx()->privateState->challange_RedMask = 1;
  106. UserProc::updateUserInfo();
  107. return Resp::ok();
  108. }
  109. /**
  110. * 6819 主线挑战 -- 通关
  111. */
  112. static function MainTZPass() {
  113. list($gateId, $index, $killMonsterNum, $killBossNum) = req()->paras; # 关卡id, 通关难度索引(1/2/3)
  114. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  115. // isEditor() && $gateInfo = new Ins_GateInfo();
  116. $gateInfo = ctx()->gates->GateList->$gateId;
  117. my_Assert($gateInfo->pass, ErrCode::gate_GateNoUnlock); # 通关后解锁难度1
  118. my_Assert($gateInfo->tz_state + 1 >= $index, ErrCode::gate_GateNoUnlock); # 通关上一难度解锁当前难度
  119. $gateInfo->tz_state = $index;
  120. TaskProc::OnPassMainChallengeGate_X_Num($gateId, $index);
  121. TaskProc::OnKillCommonNumMonster($killMonsterNum);
  122. TaskProc::OnKillleaderNumMonster($killBossNum);
  123. UserProc::updateUserInfo();
  124. return Resp::ok(array("task" => ctx()->task,));
  125. }
  126. /**
  127. * 6820 主线挑战 -- 领取奖励
  128. */
  129. static function MainTZGetReward() {
  130. list($gateId, $index) = req()->paras; # 关卡id, 通关难度索引(1/2/3)
  131. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  132. // isEditor() && $gateInfo = new Ins_GateInfo();
  133. $gateInfo = ctx()->gates->GateList->$gateId;
  134. my_Assert($gateInfo->pass, ErrCode::gate_GateNoUnlock); # 通关后解锁难度1
  135. my_Assert($gateInfo->tz_state >= $index, ErrCode::gate_GateNoUnlock); # 已解锁当前难度
  136. my_Assert(Bits::GetBitValue($gateInfo->tz_rewards, $index - 1) == false, ErrCode::gate_GatePriceHasReceive);
  137. $gateInfo->tz_rewards = Bits::SetBitValue($gateInfo->tz_rewards, $index - 1, true); # 更新领取记录
  138. $prize = "tz_reward" . $index;
  139. $mo = GameConfig::gate_getItem($gateId);
  140. StoreProc::AddMultiItemInStore($mo->$prize);
  141. UserProc::updateUserInfo();
  142. return Resp::ok();
  143. }
  144. /**
  145. * 6818 启灵解锁
  146. * @return type
  147. */
  148. public static function EvolveUnlock() {
  149. list($type, $id) = req()->paras; //$id废弃 因为玩家可能不安顺序点
  150. if ($type == 1) {
  151. $nextId = ctx()->gates->evolveMaxId_left + 1;
  152. my_Assert($id == $nextId, ErrCode::err_const_no);
  153. $mo = GameConfig::evolve_getItem($nextId);
  154. my_Assert($mo != null, ErrCode::err_const_no);
  155. my_Assert(ctx()->baseInfo->level >= $mo->level, ErrCode::evolve_canotUnlock_levelLimit);
  156. my_Assert(ctx()->baseInfo->gold >= $mo->needGold_unlock, ErrCode::notenough_gold_msg);
  157. ctx()->baseInfo->Consume_Gold($mo->needGold_unlock);
  158. ctx()->gates->evolveMaxId_left = $nextId;
  159. TaskProc::OnCompleteNumQiLing();
  160. } else {
  161. $nextId = ctx()->gates->evolveMaxId_right + 1;
  162. my_Assert($id == $nextId, ErrCode::err_const_no);
  163. $dic = GameConfig::evolve();
  164. foreach ($dic as $key => $value) {
  165. if ($value->specificEvolveId == $nextId) {
  166. $mo = $value;
  167. }
  168. }
  169. my_Assert(ctx()->baseInfo->level >= $mo->level, ErrCode::evolve_canotUnlock_levelLimit);
  170. my_Assert($mo != null, ErrCode::err_const_no);
  171. if ($mo->specificEvolveCost != null) {
  172. $cost = explode(',', $mo->specificEvolveCost);
  173. $costId = $cost[0];
  174. $costNum = $cost[1];
  175. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $costId) && ctx()->store->items->$costId >= $costNum, ErrCode::notenough_item);
  176. ctx()->store->removeItem($costId, $costNum);
  177. }
  178. ctx()->gates->evolveMaxId_right = $id;
  179. TaskProc::OnCompleteNumSpecialQiLing();
  180. }
  181. UserProc::updateUserInfo();
  182. $ret = array(
  183. 'task' => ctx()->task,
  184. 'gold' => ctx()->baseInfo->gold,
  185. 'items' => ctx()->store->items,
  186. 'evolveMaxId_right' => ctx()->gates->evolveMaxId_right,
  187. 'evolveMaxId_left' => ctx()->gates->evolveMaxId_left,
  188. );
  189. return Resp::ok($ret);
  190. }
  191. /**
  192. * 6807 扫荡
  193. * @return type
  194. */
  195. public static function FightSweep() {
  196. //list($gateId) = req()->paras;
  197. $passGateId = ctx()->gates->maxPassGateId();
  198. my_Assert($passGateId != 0, ErrCode::gate_NoSweep);
  199. $mo = GameConfig::gate_getItem($passGateId);
  200. $gateName = $mo->gateName;
  201. $costTili = glc()->sweep_cost_tili;
  202. $curTili = ctx()->baseInfo->CurTili();
  203. my_Assert($curTili >= $costTili, ErrCode::notenough_tili);
  204. if (ctx()->privateState->honourCardShop_ts == 0) {
  205. $max = glc()->sweepMaxNum;
  206. my_Assert(ctx()->gates->fightSweepNum < $max, ErrCode::gate_SweepMaxNum_limit);
  207. }
  208. ctx()->gates->fightSweepNum += 1;
  209. ctx()->baseInfo->Consume_tili($costTili);
  210. $wavesArr = GameConfig::waves_getItemArray($passGateId);
  211. $count = count($wavesArr);
  212. $wavesMo = $wavesArr[$count - 1];
  213. $gold = $wavesMo->rewardGold;
  214. StoreProc::AddMultiItemInStore("1," . $gold);
  215. $oldLevel = ctx()->baseInfo->level;
  216. $exp = $wavesMo->rewardExp;
  217. StoreProc::AddMultiItemInStore("4," . $exp);
  218. $newLevel = ctx()->baseInfo->level;
  219. if ($wavesMo->rewardTuZhi != null) {
  220. $tuzhi = explode('-', $wavesMo->rewardTuZhi);
  221. $n = rand($tuzhi[0], $tuzhi[1]);
  222. $tuzhiArr = array();
  223. $item = GameConfig::item();
  224. foreach ($item as $id => $mo) {
  225. if ($mo->itemType == 100) {
  226. $tuzhiArr[] = $id;
  227. }
  228. }
  229. for ($i = 0; $i < $n; $i++) {
  230. $index = rand(0, count($tuzhiArr) - 1);
  231. $goodsStr = $tuzhiArr[$index] . ',' . 1;
  232. $prizeArr[] = $goodsStr;
  233. StoreProc::AddMultiItemInStore($goodsStr);
  234. }
  235. }
  236. if ($wavesMo->rewardGem != null) {
  237. $goodsStr = self::sweepRandReward($wavesMo->rewardGem);
  238. $str = explode(';', $goodsStr);
  239. $dic = GameConfig::gem();
  240. foreach ($str as $value) {
  241. $list = explode(',', $value);
  242. $posId = rand(1, 6);
  243. $qual = $list[0];
  244. foreach ($dic as $key => $gemMo) {
  245. if ($gemMo->qual == $qual && $gemMo->position == $posId && $gemMo->isfixed_predicateId == 0) {
  246. $gemStr = $gemMo->typeId . ',' . $list[1];
  247. SystemProc::GetGem_GreaterOrangeQual_SweepMainGateIndex(req()->zoneid, ctx()->baseInfo->name, Ins_GateInfo::gateNum($passGateId), $gateName, $gemMo->typeId);
  248. //StoreProc::PutGemInStore($gemMo->typeId, $list[1]);
  249. StoreProc::AddMultiItemInStore($gemStr);
  250. break;
  251. }
  252. }
  253. }
  254. }
  255. UserProc::updateUserInfo();
  256. $ret = array(
  257. 'gold' => ctx()->baseInfo->gold,
  258. 'cash' => ctx()->baseInfo->cash,
  259. 'tili' => ctx()->baseInfo->tili,
  260. 'tili_ts' => ctx()->baseInfo->tili_ts,
  261. 'xp' => ctx()->baseInfo->xp,
  262. 'maxXp' => ctx()->baseInfo->maxXp,
  263. 'level' => ctx()->baseInfo->level,
  264. 'fightSweepNum' => ctx()->gates->fightSweepNum,
  265. //'prizeArr' => $prizeArr,
  266. 'store' => ctx()->store,
  267. 'task' => ctx()->task,
  268. 'reward' => StoreProc::$reward,
  269. 'reward_Gem' => StoreProc::$reward_Gem,
  270. 'oldLevel' => $oldLevel,
  271. 'newLevel' => $newLevel,
  272. );
  273. return Resp::ok($ret);
  274. }
  275. static function sweepRandReward($rewardStr) {
  276. $ctxArr = explode(';', $rewardStr);
  277. $numArr = explode('-', $ctxArr[0]);
  278. $num = rand($numArr[0], $numArr[1]);
  279. $rand = 0;
  280. $itemArr = explode(',', $ctxArr[1]);
  281. foreach ($itemArr as $value) {
  282. $arr = explode(':', $value);
  283. $itemId = $arr[0];
  284. $per = $arr[1];
  285. $rand += $per;
  286. }
  287. $res = "";
  288. for ($i = 0; $i < $num; $i++) {
  289. $start = 0;
  290. $end = 0;
  291. $randNum = rand(1, $rand);
  292. $id = 0;
  293. foreach ($itemArr as $str) {
  294. $arr = explode(':', $str);
  295. $itemId = $arr[0];
  296. $per = $arr[1];
  297. $end += $per;
  298. if ($randNum > $start && $randNum <= $end) {
  299. $id = $itemId;
  300. break;
  301. }
  302. $start = $end;
  303. }
  304. if ($id != 0) {
  305. $str = $id . ',1';
  306. if ($res == "") {
  307. $res = $str;
  308. } else {
  309. $res = $res . ';' . $str;
  310. }
  311. }
  312. }
  313. return $res;
  314. }
  315. /**
  316. * 6808 开始挑战 (主线关卡:扣除体力, 挑战关卡: 增加次数)
  317. */
  318. private static function StartFight() {
  319. list($gateId, $layerNum) = req()->paras;
  320. my_Assert($gateId > 0, ErrCode::paras_err);
  321. $mo = GameConfig::gate_getItem($gateId);
  322. my_Assert(null != $mo, ErrCode::err_const_no);
  323. if (Ints::Slice($gateId, 0, 1) == 9) { # 爬塔模式
  324. // list($layerNum) = req()->paras;
  325. if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # 起始层数校验
  326. Err(ErrCode::tower_layerNum);
  327. }
  328. if (ctx()->gates()->TowerGateInfo()->TodayChanNum < 1) { # 剩余次数校验
  329. Err(ErrCode::tower_timeNo);
  330. }
  331. ctx()->gates()->TowerGateInfo()->TodayChanNum--; # 增加次数
  332. } else { # 主线剧情
  333. my_Assert(ctx()->base()->Consume_tili($mo->cost_tili), ErrCode::notenough_tili);
  334. }
  335. UserProc::updateUserInfo();
  336. return Resp::ok(array("tili" => ctx()->baseInfo->tili, "tili_ts" => ctx()->baseInfo->tili_ts));
  337. }
  338. public static function FightDailyClear() {
  339. //ctx()->gates->xunluo_quick_buyRecord = 0;
  340. ctx()->gates->fightSweepNum = 0;
  341. ctx()->gates()->TowerGateInfo()->RefreshSkillTimes = 0;
  342. ctx()->gates()->TowerGateInfo()->TodayChanNum = glc()->tower_daily_chanceNum;
  343. ctx()->privateState->challange_RedMask = 0;
  344. }
  345. /**
  346. * 6806 剧情回存
  347. * @return type
  348. */
  349. public static function PlotSav() {
  350. list($gateId) = req()->paras;
  351. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  352. ctx()->gates->GateList->$gateId->plotStart = 1;
  353. UserProc::updateUserInfo();
  354. $ret = array(
  355. 'ok' => 1,
  356. );
  357. return Resp::ok($ret);
  358. }
  359. // <editor-fold defaultstate="collapsed" desc="挑战模块">
  360. /**
  361. * 6810 挑战关卡: 更新锁定技能列表
  362. */
  363. public static function TowerUpdateLockskillList() {
  364. list($li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  365. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  366. $t->skill_zhudong = $li_zd;
  367. $t->skill_beidong = $li_bd;
  368. $t->skill_zhudong_lockState = $li_zds;
  369. $t->skill_beidong_lockState = $li_bds;
  370. UserProc::updateUserInfo();
  371. return Resp::ok();
  372. }
  373. /**
  374. * 6809 挑战关卡: 刷新初始技能(扣除免费次数/cost)
  375. */
  376. public static function TowerRefreshSkills() {
  377. list($isFree, $li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  378. if ($isFree) {
  379. if (ctx()->gates()->TowerGateInfo()->RefreshSkillTimes > glc()->tower_daily_refreshChanceNum) {
  380. Err(ErrCode::tower_refreshNo); # 免费次数不足
  381. }
  382. } else {
  383. list($type, $num) = explode(':', glc()->tower_refreshCost); # 二级货币类型(1:金币,2:元宝):数量
  384. if ($type == 1) { # 金币
  385. my_Assert(ctx()->base()->Consume_Gold($num), ErrCode::notenough_gold_msg);
  386. } else if ($type == 2) { # 元宝
  387. my_Assert(ctx()->base()->Consume_Cash($num), ErrCode::notenough_cash_msg);
  388. } else {
  389. Err(ErrCode::err_const_no, "检查刷新扣费配置信息!");
  390. }
  391. }
  392. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  393. $t->RefreshSkillTimes++;
  394. $t->skill_zhudong = $li_zd;
  395. $t->skill_beidong = $li_bd;
  396. $t->skill_zhudong_lockState = $li_zds;
  397. $t->skill_beidong_lockState = $li_bds;
  398. UserProc::updateUserInfo();
  399. $ret = array(
  400. 'task' => ctx()->task,
  401. );
  402. return Resp::ok($ret);
  403. }
  404. /**
  405. * 6805 战斗: 复活花费
  406. * @return type
  407. * @version 2024年5月17日 重整利用为复活扣除消耗功能
  408. */
  409. public static function ReliveCost() {
  410. // 复活可以扣除复活币(暂无)或者元宝,(客户端看广告复活不需要跟服务器通讯)
  411. list($reliveNum) = req()->paras;
  412. $arr = explode(',', glc()->Relive_cost);
  413. my_Assert($reliveNum >= 0 && $reliveNum <= Count($arr), ErrCode::paras_err); # 参数范围>0
  414. $amt = $arr[$reliveNum];
  415. my_Assert(ctx()->base()->Consume_Cash($amt), ErrCode::notenought_yuanbao);
  416. UserProc::updateUserInfo();
  417. return Resp::ok();
  418. }
  419. /**
  420. * 6804 挑战关卡: 奖励领取
  421. * @return type
  422. */
  423. public static function GateChallengeRewards() {
  424. list($finalLayer, $killedMonster, $killedBoss) = req()->paras; # 战斗结束时的层数
  425. $lastLayer = ctx()->gates()->TowerGateInfo()->CurLayer;
  426. $arr = GameConfig::waves_getItemArray(self::TowerGateId);
  427. TaskProc::OnFightNumChallengeGate();
  428. TaskProc::OnKillCommonNumMonster($killedMonster);
  429. TaskProc::OnKillleaderNumMonster($killedBoss);
  430. if ($finalLayer > $lastLayer) {
  431. foreach ($arr as $layerId => $layerMo) {
  432. if ($layerMo->waveId >= $lastLayer && $layerMo->waveId < $finalLayer) {
  433. my_Assert($layerMo != null, ErrCode::err_const_no);
  434. StoreProc::AddMultiItemInStore($layerMo->rewards); # 发放奖励
  435. }
  436. }
  437. ctx()->gates()->TowerGateInfo()->CurLayer = $finalLayer;
  438. TaskProc::OnPassLayer_ChallengeGate($finalLayer - 1);
  439. UserProc::updateUserInfo();
  440. $ret = array(
  441. 'store' => ctx()->store,
  442. 'gold' => ctx()->base()->gold,
  443. 'cash' => ctx()->base()->cash,
  444. 'task' => ctx()->task,
  445. );
  446. return Resp::ok($ret);
  447. } else if ($finalLayer == $lastLayer) {
  448. $ret = array(
  449. 'store' => ctx()->store,
  450. 'gold' => ctx()->base()->gold,
  451. 'cash' => ctx()->base()->cash,
  452. 'task' => ctx()->task,
  453. );
  454. return Resp::ok($ret);
  455. }
  456. return Resp::err(ErrCode::tower_rewardNo); # 没有奖励
  457. }
  458. // </editor-fold>
  459. /**
  460. * 6803 关卡选择
  461. * @return type
  462. */
  463. public static function SelectGate() {
  464. list($gateId) = req()->paras;
  465. ctx()->gates->CurrentGateId = $gateId;
  466. UserProc::updateUserInfo();
  467. $ret = array(
  468. 'gates' => ctx()->gates,
  469. );
  470. return Resp::ok($ret);
  471. }
  472. /**
  473. * 6802 章节宝箱的领取
  474. * @return type
  475. */
  476. public static function PassGateTsPrizeReceive() {
  477. list($gateId, $index) = req()->paras;
  478. $gateMo = GameConfig::gate_getItem($gateId);
  479. my_Assert($gateMo != null, ErrCode::err_const_no);
  480. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  481. $gateInfo = ctx()->gates->GateList->$gateId;
  482. $tag = false;
  483. $prize = "";
  484. $mask = 0;
  485. switch ($index) {
  486. case 1:
  487. $ts = $gateMo->first_ts1 * 60;
  488. if ($gateInfo->MaxSeconds >= $ts) {
  489. $tag = true;
  490. }
  491. $mask = 1;
  492. $prize = $gateMo->first_reward1;
  493. break;
  494. case 2:
  495. $ts = $gateMo->first_ts2 * 60;
  496. if ($gateInfo->MaxSeconds >= $ts) {
  497. $tag = true;
  498. }
  499. $mask = 2;
  500. $prize = $gateMo->first_reward2;
  501. break;
  502. case 3:
  503. if ($gateInfo->pass > 0) {
  504. $tag = true;
  505. }
  506. $mask = 3;
  507. $prize = $gateMo->first_reward3;
  508. break;
  509. default:
  510. break;
  511. }
  512. if ($tag) {
  513. my_Assert(!in_array($mask, $gateInfo->FirstReward), ErrCode::gate_GatePriceHasReceive);
  514. $gateInfo->FirstReward[] = $mask;
  515. StoreProc::AddMultiItemInStore($prize);
  516. }
  517. ctx()->gates->GateList->$gateId = $gateInfo;
  518. UserProc::updateUserInfo();
  519. $ret = array(
  520. 'gates' => ctx()->gates,
  521. 'store' => ctx()->store,
  522. 'task' => ctx()->task,
  523. 'gold' => ctx()->baseInfo->gold,
  524. 'cash' => ctx()->baseInfo->cash,
  525. 'reward' => StoreProc::$reward,
  526. 'reward_Gem' => StoreProc::$reward_Gem,
  527. );
  528. return Resp::ok($ret);
  529. }
  530. /**
  531. * [6801]关卡战斗结算
  532. * @return type
  533. */
  534. public static function Settle() {
  535. list($resultType, $gateId, $gold, $curTs, $pickups,
  536. $finalLayer, $finalHpPercent, $killMonsterNum, $killBossNum,
  537. $finalLevel, $reliveNum) = req()->paras;
  538. # 客户端需要增加参数: killmonserNum,killBosssNum, finalHpPercent(最终血量百分比)
  539. $gateMo = GameConfig::gate_getItem($gateId);
  540. my_Assert($gateMo != null, ErrCode::err_const_no);
  541. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  542. $gateInfo = ctx()->gates->GateList->$gateId;
  543. $ts = $gateInfo->MaxSeconds;
  544. if ($curTs >= $ts) {
  545. $gateInfo->MaxSeconds = $curTs;
  546. }
  547. self::funUnlock($resultType, $gateId); //备注:这个接口的位置不能动 里面有关卡第一次胜利解锁的功能提示校验
  548. if ($resultType) { # 胜利
  549. self::skillUnlock_gate($resultType, $gateId); //备注 这个接口位置不能动
  550. if (ctx()->gates->GateList->$gateId->pass == 0) {
  551. ctx()->gates->GateList->$gateId->pass = 1;
  552. TaskProc::Day7TaskReset($gateId); # 刷新七日任务
  553. $maxGateId = ctx()->gates->maxPassGateNumId();
  554. if ($maxGateId > 0) {
  555. self::Ranking_MainGateIndex($maxGateId);
  556. self::IsAchievedMainGate_PassReward($maxGateId);
  557. }
  558. }
  559. TaskProc::OnPassGate_X($gateId); # 刷新任务进度: 通关第X关
  560. TaskProc::OnPassGate_X_state($gateId);
  561. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  562. ctx()->gates()->UnlockNextPlotGate($gateId); # 解锁下一主线关卡
  563. // ctx()->gates()->UnlockMainChallengeGate($gateId); # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  564. } else { # 不是主线关卡, 暂时没有其他逻辑
  565. }
  566. // StoreProc::AddMultiItemInStore($gateMo->reward_win); # 发放胜利奖励(2024.5.30 过期)
  567. } else {
  568. ctx()->gates->GateList->$gateId->fightNum_fail += 1;
  569. self::skillUnlock_fightNum($resultType); //这个接口位置不能动
  570. }
  571. // else { # 失败
  572. //// StoreProc::AddMultiItemInStore($gateMo->reward_fail); # 发放失败奖励(2024.5.30 过期)
  573. // }
  574. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具直接入背包
  575. //ctx()->base()->Add_Gold($gold); # 战场拾取的金币直接入背包
  576. //ctx()->base()->Add_Exp($exp);
  577. $waveMo = GameConfig::waveItem_getItem($gateId, $finalLayer);
  578. my_Assert(null != $waveMo, ErrCode::err_const_no);
  579. $oldLevel = ctx()->baseInfo->level;
  580. StoreProc::AddMultiItemInStore('4,' . $waveMo->rewardExp);
  581. //ctx()->base()->Add_Exp($waveMo->rewardExp); # 指挥官经验
  582. $newLevel = ctx()->baseInfo->level;
  583. if ($oldLevel != $newLevel) {
  584. ctx()->privateState->oldLevel = $oldLevel;
  585. ctx()->privateState->upLevel = $newLevel;
  586. }
  587. //ctx()->base()->Add_Gold($waveMo->rewardGold); # 金币奖励
  588. //$pickups .= ";1," . $gold + $waveMo->rewardGold;
  589. $str = "1," . $gold + $waveMo->rewardGold;
  590. StoreProc::AddMultiItemInStore($str);
  591. # 图纸奖励: 数量min-max, 部位随机
  592. if (strlen($waveMo->rewardTuZhi) > 0 && str_contains($waveMo->rewardTuZhi, '-')) {
  593. list($tz_min, $tz_max) = explode('-', $waveMo->rewardTuZhi); # 图纸数量
  594. $tz_n = rand($tz_min, $tz_max);
  595. # 图纸部位数据源 1001, 1002, 1003, 1004, 1005, 1006
  596. for ($i = 0; $i < $tz_n; $i++) {
  597. $id = 1000 + rand(1, 6);
  598. StoreProc::AddMultiItemInStore("$id,1"); # 获得图纸
  599. //$pickups .= ";$id,1";
  600. }
  601. }
  602. # 宝石奖励: 数量min-max;品质:权重,品质:权重...
  603. if (strlen($waveMo->rewardGem) > 0) {
  604. list($gs_num, $gs_props) = explode(';', $waveMo->rewardGem);
  605. list($gem_min, $gem_max) = explode('-', $gs_num); # 宝石数量
  606. $gem_n = rand($gem_min, $gem_max);
  607. $arr = explode(",", $gs_props);
  608. $pool = array();
  609. $n = 0;
  610. foreach ($arr as $str) {
  611. list($qual, $props) = explode(':', $str);
  612. $pool[] = array('q' => $qual, 'p' => $props);
  613. $n += $props;
  614. }
  615. for ($i = 0; $i < $gem_n; $i++) { # 随机n块宝石
  616. $r = rand(1, $n); # 投色子
  617. $l = 0;
  618. foreach ($pool as $item) {
  619. if ($r <= ($l + $item['p'])) {
  620. $gemId = $item['q'] * 100000 + rand(1, 6) * 1000;
  621. SystemProc::GetGem_GreaterOrangeQual_MainGate(req()->zoneid, ctx()->baseInfo->name, Ins_GateInfo::gateNum($gateId), $gateMo->gateName, $gemId); //广播
  622. //StoreProc::PutGemInStore($gemId); # 发放宝石并退出本次投色子
  623. //$pickups .= ";$gemId,1";
  624. StoreProc::AddMultiItemInStore("$gemId,1");
  625. break;
  626. }
  627. $l += $item['p']; # 累计到下一段
  628. }
  629. }
  630. }
  631. ctx()->gates->GateList->$gateId->fightNum += 1;
  632. TaskProc::OnFightNumMainGate();
  633. TaskProc::OnKillCommonNumMonster($killMonsterNum);
  634. TaskProc::OnKillleaderNumMonster($killBossNum);
  635. TaskProc::OnFightGate_X($gateId);
  636. UserProc::updateUserInfo();
  637. $ret = array(
  638. 'gates' => ctx()->gates,
  639. 'store' => ctx()->store,
  640. 'task' => ctx()->task,
  641. 'baseInfo' => ctx()->base(),
  642. 'gold' => $gold + $waveMo->rewardGold,
  643. 'exp' => $waveMo->rewardExp,
  644. //'rewardStr' => $pickups
  645. 'reward' => StoreProc::$reward,
  646. 'reward_Gem' => StoreProc::$reward_Gem,
  647. 'oldLevel' => $oldLevel,
  648. 'newLevel' => $newLevel,
  649. 'funUnlockRecord' => ctx()->privateState->funUnlockRecord,
  650. 'skillUnlockRecord' => ctx()->privateState->skillUnlockRecord,
  651. 'heros' => ctx()->heros,
  652. );
  653. return Resp::ok($ret);
  654. }
  655. /**
  656. * 检测功能解锁的
  657. * @param type $resultType
  658. * @param type $gateId
  659. * @return type
  660. */
  661. static function funUnlock($resultType, $gateId) {
  662. $dic = GameConfig::fun_unlock();
  663. foreach ($dic as $id => $mo) {
  664. if ($mo->unlockTip == 1 && $mo->unlockGateId == $gateId) {
  665. $tag = false;
  666. //1:参与战斗结束即可 2战斗胜利 3某场战斗参加N次数才行
  667. switch ($mo->unlockType) {
  668. case 1:
  669. if (ctx()->gates->GateList->$gateId->fightNum == 0) {
  670. $tag = true;
  671. }
  672. break;
  673. case 2:
  674. if ($resultType == true && ctx()->gates->GateList->$gateId->pass == 0) {
  675. $tag = true;
  676. }
  677. break;
  678. default:
  679. break;
  680. }
  681. if ($tag) {
  682. ctx()->privateState->funUnlockRecord[] = $id;
  683. }
  684. }
  685. }
  686. }
  687. // <editor-fold defaultstate="collapsed" desc="技能解锁">
  688. /**
  689. * 检测技能解锁的 1 关卡解锁,游玩到一定关卡解锁技能
  690. * @param type $resultType
  691. * @param type $gateId
  692. * @return type
  693. */
  694. static function skillUnlock_gate($resultType, $gateId) {
  695. $dic = GameConfig::skills();
  696. $gateIndex = Ins_GateInfo::gateNum($gateId);
  697. foreach ($dic as $id => $mo) {
  698. if ($mo->unlock_acc_id_new == null) {
  699. continue;
  700. }
  701. $strList = explode(':', $mo->unlock_acc_id_new);
  702. $unlockType = $strList[0];
  703. $unlockId = $strList[1];
  704. if ($unlockType == 1 && $unlockId == $gateIndex && $resultType == true && ctx()->gates->GateList->$gateId->pass == 0 && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  705. ctx()->privateState->skillUnlockRecord[] = $mo->typeId;
  706. }
  707. }
  708. }
  709. /**
  710. * 检测技能解锁的 2://皮肤解锁,获取到人物解锁后对应皮肤技能
  711. * @param type $resultType
  712. * @param type $gateId
  713. * @return type
  714. */
  715. static function skillUnlock_heroUnlock($heroId) {
  716. $dic = GameConfig::skills();
  717. foreach ($dic as $id => $mo) {
  718. if ($mo->unlock_acc_id_new == null) {
  719. continue;
  720. }
  721. $strList = explode(':', $mo->unlock_acc_id_new);
  722. $unlockType = $strList[0];
  723. $unlockId = $strList[1];
  724. if ($unlockType != 2) {
  725. continue;
  726. }
  727. $heroMo = GameConfig::hero_getItem($heroId);
  728. $heroTypeId = $heroMo->typeID;
  729. $isUnlock = ctx()->heros->Dic->$heroId->isUnlock;
  730. if ($unlockId == $heroTypeId && $isUnlock == 0 && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  731. ctx()->privateState->skillUnlockRecord[] = $mo->typeId;
  732. }
  733. }
  734. }
  735. /**
  736. * 检测技能解锁的 3://玩家失败X次后解锁
  737. * @param type $resultType
  738. * @param type $gateId
  739. * @return type
  740. */
  741. static function skillUnlock_fightNum($resultType) {
  742. if ($resultType) {
  743. return;
  744. }
  745. $GateList = ctx()->gates->GateList;
  746. $num = 0;
  747. foreach ($GateList as $gateId => $Ins_GateInfo) {
  748. $num += $Ins_GateInfo->fightNum_fail;
  749. }
  750. $dic = GameConfig::skills();
  751. foreach ($dic as $id => $mo) {
  752. if ($mo->unlock_acc_id_new == null) {
  753. continue;
  754. }
  755. $strList = explode(':', $mo->unlock_acc_id_new);
  756. $unlockType = $strList[0];
  757. $unlockId = $strList[1];
  758. if ($unlockType != 3) {
  759. continue;
  760. }
  761. if ($num == $unlockId && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  762. ctx()->privateState->skillUnlockRecord[] = $mo->typeId;
  763. }
  764. }
  765. }
  766. /**
  767. * 玩家等级解锁技能
  768. * @param type $curLevel
  769. */
  770. static function skillUnlock_userLevel($curLevel) {
  771. $dic = GameConfig::skills();
  772. foreach ($dic as $id => $mo) {
  773. if ($mo->unlock_acc_id_new == null) {
  774. continue;
  775. }
  776. $strList = explode(':', $mo->unlock_acc_id_new);
  777. $unlockType = $strList[0];
  778. $unlockId = $strList[1];
  779. if ($unlockType != 5) { // 玩家等级
  780. continue;
  781. }
  782. if ($unlockId <= $curLevel && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  783. ctx()->privateState->skillUnlockRecord[] = $mo->typeId;
  784. }
  785. }
  786. }
  787. // </editor-fold>
  788. // <editor-fold defaultstate="collapsed" desc="排行榜">
  789. /**
  790. * 参与主线关卡排行榜
  791. * @param type $gateIndex
  792. */
  793. public static function Ranking_MainGateIndex($maxGateIndex) {
  794. $memKey = MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid);
  795. $mem = gMem();
  796. $uid = req()->uid;
  797. $score = self::GetRankScoreUid($uid, 1);
  798. if ($maxGateIndex > $score) {
  799. $arr = array();
  800. $arr["$uid"] = self::createScore($maxGateIndex);
  801. $mem->zadd($memKey, $arr);
  802. }
  803. $length = $mem->zlen($memKey);
  804. if ($length > glc()->Rank_MainGateIndex_OnListRank) {
  805. $num = $length - glc()->Rank_MainGateIndex_OnListRank;
  806. $mem->zremrangebyrank($memKey, 0, $num - 1);
  807. }
  808. }
  809. public static function createScore($score) {
  810. if ($score > 0) {
  811. $newScore = $score . '.' . (9999999999 - now());
  812. return $newScore;
  813. }
  814. return 0;
  815. }
  816. /**
  817. * 战力榜
  818. * @param type $gateIndex
  819. */
  820. public static function Ranking_FightPower() {
  821. $memKey = MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid);
  822. $mem = gMem();
  823. $uid = req()->uid;
  824. $score = self::GetRankScoreUid($uid, 2);
  825. $power = self::countUserFightPower();
  826. if ($power > $score) {
  827. $arr = array();
  828. $arr["$uid"] = self::createScore($power);
  829. $mem->zadd($memKey, $arr);
  830. self::IsAchievedFightPower_PassReward($power);
  831. }
  832. $length = $mem->zlen($memKey);
  833. if ($length > glc()->Rank_FightPower_OnListRank) {
  834. $num = $length - glc()->Rank_FightPower_OnListRank;
  835. $mem->zremrangebyrank($memKey, 0, $num - 1);
  836. }
  837. }
  838. public static function GetRankScoreUid($uid_rank, $type) {
  839. if ($type == 1) {
  840. $score = gMem()->zscore(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid_rank);
  841. } else {
  842. $score = gMem()->zscore(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid_rank);
  843. }
  844. if ($score == null) {
  845. $score = 0;
  846. }
  847. return intval($score);
  848. }
  849. /**
  850. * 6811 获取主线关卡排行榜信息
  851. * @return type
  852. */
  853. public static function GetRankInfo() {
  854. list($type) = req()->paras;
  855. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  856. $selfExtraInfo = 0;
  857. $isExistFinishReward = 0;
  858. $isExistFinishReward_other = 0;
  859. if ($type == 1) {
  860. $list = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  861. $selfExtraInfo = ctx()->gates->maxPassGateNumId();
  862. $isExistFinishReward = self::isExistNoDrawed_MainGate();
  863. $isExistFinishReward_other = self::isExistNoDrawed_FightPower();
  864. } else {
  865. $list = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  866. $selfExtraInfo = self::countUserFightPower();
  867. $isExistFinishReward = self::isExistNoDrawed_FightPower();
  868. $isExistFinishReward_other = self::isExistNoDrawed_MainGate();
  869. }
  870. if ($isExistFinishReward == 1) {
  871. $isExistFinishReward = true;
  872. } else {
  873. $isExistFinishReward = false;
  874. }
  875. if ($isExistFinishReward_other == 1) {
  876. $isExistFinishReward_other = true;
  877. } else {
  878. $isExistFinishReward_other = false;
  879. }
  880. $selfRank = null;
  881. $retArr = array();
  882. if (count($list) > 0) {
  883. foreach ($list as $uid => $score) {
  884. $rankInfo = self::initOtherUidRankInfo($uid, $score, $type);
  885. if ($rankInfo->uid == req()->uid) {
  886. $selfIsHasRank = 1;
  887. $selfRank = $rankInfo;
  888. }
  889. $retArr[] = $rankInfo;
  890. }
  891. }
  892. if ($selfRank == null) {
  893. $selfRank = self::initOtherUidRankInfo(req()->uid, $selfExtraInfo, $type);
  894. }
  895. UserProc::updateUserInfo();
  896. $ret = array(
  897. 'rankInfo' => $retArr,
  898. 'selfRank' => $selfRank,
  899. 'selfIsHasRank' => $selfIsHasRank,
  900. 'isExistFinishReward' => $isExistFinishReward,
  901. 'isExistFinishReward_other' => $isExistFinishReward_other,
  902. );
  903. return Resp::ok($ret);
  904. }
  905. /**
  906. * 初始化玩家rank
  907. * @param type $uid
  908. * @param type $score
  909. * @return \loyalsoft\Ins_rank
  910. */
  911. static function initOtherUidRankInfo($uid, $score, $type = null) {
  912. $ins_rank = new Ins_rank();
  913. if ($type == 1) {
  914. $lv = gMem()->zrevrank(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  915. } else {
  916. $lv = gMem()->zrevrank(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
  917. }
  918. if ($lv == null) {
  919. $lv = 0;
  920. }
  921. $ins_rank->rank = $lv + 1;
  922. $ins_rank->uid = $uid;
  923. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  924. $ins_rank->name = $userInfo->baseInfo->name;
  925. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  926. //$ret = intval($score);
  927. // if(!$isToRank){
  928. // $ret = $score;
  929. // }
  930. $ins_rank->score = intval($score);
  931. return $ins_rank;
  932. }
  933. /**
  934. * 6812 获取排行榜内玩家的装备信息
  935. * @return type
  936. */
  937. public static function GetUidEquipInfo_Rank() {
  938. list($uid) = req()->paras;
  939. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  940. $store = $userInfo->store;
  941. $heros = $userInfo->heros;
  942. $gates = $userInfo->gates;
  943. UserProc::updateUserInfo();
  944. $ret = array(
  945. 'store' => $store,
  946. 'heros' => $heros,
  947. 'gates' => $gates,
  948. );
  949. return Resp::ok($ret);
  950. }
  951. /**
  952. * 通关奖励是否达成
  953. * @param type $maxGateIndex
  954. */
  955. public static function IsAchievedMainGate_PassReward($maxGateIndex) {
  956. $rewards = GameConfig::rank_passgatereward();
  957. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  958. foreach ($rewards as $passGateId => $mo) {
  959. if ($passGateId == $maxGateIndex && !gMem()->hexists($memKey, $maxGateIndex)) {
  960. $ins_rank = new Ins_rank();
  961. $ins_rank->uid = req()->uid;
  962. $ins_rank->name = ctx()->baseInfo->name;
  963. $ins_rank->headImg = ctx()->baseInfo->headImg;
  964. $ins_rank->score = $passGateId;
  965. gMem()->hset($memKey, $maxGateIndex, $ins_rank);
  966. break;
  967. }
  968. }
  969. }
  970. /*
  971. * 战力奖励是否达成
  972. */
  973. public static function IsAchievedFightPower_PassReward($power) {
  974. $rewards = GameConfig::rank_fightpowerreward();
  975. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  976. foreach ($rewards as $fightPower => $mo) {
  977. if ($power >= $fightPower && !gMem()->hexists($memKey, $fightPower)) {
  978. $ins_rank = new Ins_rank();
  979. $ins_rank->uid = req()->uid;
  980. $ins_rank->name = ctx()->baseInfo->name;
  981. $ins_rank->headImg = ctx()->baseInfo->headImg;
  982. $ins_rank->score = $fightPower;
  983. gMem()->hset($memKey, $fightPower, $ins_rank);
  984. }
  985. }
  986. }
  987. public static function isExistNoDrawed_MainGate() {
  988. $isExistFinishReward = 0;
  989. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  990. $dic = gMem()->hgetall($memKey);
  991. foreach ($dic as $gateId => $ins_rank) {
  992. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  993. $isExistFinishReward = 1;
  994. break;
  995. }
  996. }
  997. ctx()->privateState->redTip_RewardMainGateRank = $isExistFinishReward;
  998. return $isExistFinishReward;
  999. }
  1000. public static function isExistNoDrawed_FightPower() {
  1001. $isExistFinishReward = 0;
  1002. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1003. $dic = gMem()->hgetall($memKey);
  1004. foreach ($dic as $fightPower => $ins_rank) {
  1005. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1006. $isExistFinishReward = 1;
  1007. break;
  1008. }
  1009. }
  1010. ctx()->privateState->redTip_RewardFightPowerRank = $isExistFinishReward;
  1011. return $isExistFinishReward;
  1012. }
  1013. /**
  1014. * 6813
  1015. * @return type
  1016. */
  1017. public static function GetmainGate_RankRewardInfo() {
  1018. //list($type) = req()->paras;
  1019. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1020. $dic = gMem()->hgetall($memKey);
  1021. if ($dic == null) {
  1022. $dic = new \stdClass();
  1023. }
  1024. UserProc::updateUserInfo();
  1025. $ret = array(
  1026. 'rankReward' => $dic,
  1027. );
  1028. return Resp::ok($ret);
  1029. }
  1030. /**
  1031. * 6814
  1032. * @return type
  1033. */
  1034. public static function GetFightPower_RankRewardInfo() {
  1035. //list($type) = req()->paras;
  1036. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1037. $dic = gMem()->hgetall($memKey);
  1038. if ($dic == null) {
  1039. $dic = new \stdClass();
  1040. }
  1041. UserProc::updateUserInfo();
  1042. $ret = array(
  1043. 'rankReward' => $dic,
  1044. );
  1045. return Resp::ok($ret);
  1046. }
  1047. /**
  1048. * 6815 领取通关荣誉榜奖励
  1049. * @return type
  1050. */
  1051. public static function ReceiveRankReward_MainGate() {
  1052. list($gateId) = req()->paras;
  1053. my_Assert(!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate), ErrCode::rankReward_HasReceive);
  1054. $mo = GameConfig::rank_passgatereward_getItem($gateId);
  1055. my_Assert($mo != null, ErrCode::err_const_no);
  1056. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1057. if (gMem()->hexists($memKey, $gateId)) {
  1058. StoreProc::AddMultiItemInStore($mo->reward);
  1059. ctx()->privateState->rankReward_drawed_MainGate[] = $gateId;
  1060. TaskProc::OnRankPrize_Num();
  1061. }
  1062. $tag = self::isExistNoDrawed_MainGate();
  1063. UserProc::updateUserInfo();
  1064. $ret = array('redTip' => $tag, 'task' => ctx()->task,);
  1065. return Resp::ok($ret);
  1066. }
  1067. /**
  1068. * 6816 领取战力荣誉榜奖励
  1069. * @return type
  1070. */
  1071. public static function ReceiveRankReward_FightPower() {
  1072. list($fightPower) = req()->paras;
  1073. my_Assert(!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower), ErrCode::rankReward_HasReceive);
  1074. $mo = GameConfig::rank_fightpowerreward_getItem($fightPower);
  1075. my_Assert($mo != null, ErrCode::err_const_no);
  1076. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1077. if (gMem()->hexists($memKey, $fightPower)) {
  1078. StoreProc::AddMultiItemInStore($mo->reward);
  1079. ctx()->privateState->rankReward_drawed_fightPower[] = $fightPower;
  1080. TaskProc::OnRankPrize_Num();
  1081. }
  1082. $tag = self::isExistNoDrawed_FightPower();
  1083. UserProc::updateUserInfo();
  1084. $ret = array('redTip' => $tag, 'task' => ctx()->task,);
  1085. return Resp::ok($ret);
  1086. }
  1087. /**
  1088. * 6817
  1089. */
  1090. public static function IsExistRankReward() {
  1091. //list($type) = req()->paras;
  1092. $type = 0;
  1093. $isExistFinishReward = false;
  1094. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1095. $dic = gMem()->hgetall($memKey);
  1096. foreach ($dic as $gateId => $ins_rank) {
  1097. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  1098. $isExistFinishReward = true;
  1099. $type = 1;
  1100. break;
  1101. }
  1102. }
  1103. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1104. $dic2 = gMem()->hgetall($memKey2);
  1105. foreach ($dic2 as $fightPower => $ins_rank) {
  1106. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1107. $isExistFinishReward = true;
  1108. $type = 2;
  1109. break;
  1110. }
  1111. }
  1112. UserProc::updateUserInfo();
  1113. $ret = array(
  1114. 'isExistFinishReward' => $isExistFinishReward,
  1115. 'type' => $type,
  1116. );
  1117. return Resp::ok($ret);
  1118. }
  1119. /*
  1120. * 删除排行榜内注销账号的玩家
  1121. */
  1122. public static function DeleteRankInvalidUser($uid2) {
  1123. $dic1 = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  1124. foreach ($dic1 as $uid => $score) {
  1125. if ($uid == $uid2) {
  1126. gMem()->zrem(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  1127. break;
  1128. }
  1129. }
  1130. $dic2 = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  1131. foreach ($dic2 as $uid => $score) {
  1132. if ($uid == $uid2) {
  1133. gMem()->zrem(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
  1134. break;
  1135. }
  1136. }
  1137. }
  1138. /*
  1139. * 排行玩家头像变动
  1140. */
  1141. public static function UpdateRankUserHeadImg($uid, $headImg) {
  1142. $memKey1 = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1143. $dic = gMem()->hgetall($memKey1);
  1144. foreach ($dic as $gateId => $ins_rank) {
  1145. if ($ins_rank->uid == $uid) {
  1146. $ins_rank->headImg = $headImg;
  1147. gMem()->hset($memKey1, $gateId, $ins_rank);
  1148. }
  1149. }
  1150. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1151. $dic2 = gMem()->hgetall($memKey2);
  1152. foreach ($dic2 as $fightPower => $ins_rank) {
  1153. if ($ins_rank->uid == $uid) {
  1154. $ins_rank->headImg = $headImg;
  1155. gMem()->hset($memKey2, $fightPower, $ins_rank);
  1156. }
  1157. }
  1158. }
  1159. /*
  1160. * 统计战力 战斗力=攻击x(生命-伤害减免值)x(1+暴击率/100x(暴击伤害倍率-1))
  1161. */
  1162. public static function countUserFightPower() {
  1163. $CurrentHeroId = ctx()->heros->CurrentHeroId;
  1164. //$hero = ctx()->heros->Dic->$CurrentHeroId;
  1165. list($addHp, $addAtk, $addDecDamage, $addEatFood) = ctx()->gates()->GetEnvovleBuffs(); // 启灵加成
  1166. $mo = GameConfig::hero_getItem($CurrentHeroId);
  1167. my_Assert($mo != null, ErrCode::err_const_no);
  1168. $heroBashAttack = $mo->attack;
  1169. $heroBashHp = $mo->hp;
  1170. $equipDic = ctx()->store->equip;
  1171. $attck = 0;
  1172. $hp = 0;
  1173. foreach ($equipDic as $index => $ins_equip) {
  1174. $Ins_Equip = new Ins_Equip($ins_equip);
  1175. if ($Ins_Equip->mo()->upgradeType == 1) {//攻击力
  1176. $attck += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->attckNum;
  1177. } elseif ($Ins_Equip->mo()->upgradeType == 2) {
  1178. $hp += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->hpNum;
  1179. } else {
  1180. $attck += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->attckNum;
  1181. $hp += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->hpNum;
  1182. }
  1183. }
  1184. $heroAttck = $heroBashAttack + $attck + $addAtk; # 英雄基础攻击力+装备宝石词条攻击力+启灵攻击力
  1185. $heroHp = $heroBashHp + $hp + $addHp; # 英雄基础hp + 装备宝石词条hp + 启灵hp
  1186. $pag = ctx()->store->equipPag;
  1187. $gemDic = ctx()->store->gemEquip->$pag; //Dictionary<E_EquipPosition, Dictionary<int, Ins_Gem>>
  1188. $per = 0;
  1189. $parasVal = 0;
  1190. $per_hp = 0;
  1191. $parasVal_hp = 0;
  1192. foreach ($equipDic as $index => $ins_equip) {
  1193. if (StlUtil::dictHasProperty($gemDic, $index)) {
  1194. $dic = $gemDic->$index;
  1195. foreach ($dic as $k => $gem) {
  1196. $ins_Gem = new Ins_Gem($gem);
  1197. if ($ins_Gem->predicateMo()->actionType == "mulDamage") {
  1198. $per += $ins_Gem->predicateMo()->actionParam1;
  1199. } elseif ($ins_Gem->predicateMo()->actionType == "addDamage") {
  1200. $parasVal += $ins_Gem->predicateMo()->actionParam1;
  1201. } elseif ($ins_Gem->predicateMo()->actionType == "mulHp") {
  1202. $per_hp += $ins_Gem->predicateMo()->actionParam1;
  1203. } elseif ($ins_Gem->predicateMo()->actionType == "addHp") {
  1204. $parasVal_hp += $ins_Gem->predicateMo()->actionParam1;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. if ($per != 0) {
  1210. $heroAttck = round($heroAttck + $heroAttck * $per);
  1211. }
  1212. if ($parasVal != 0) {
  1213. $heroAttck += $parasVal;
  1214. }
  1215. if ($per_hp != 0) {
  1216. $heroHp = round($heroHp + $heroHp * $per_hp);
  1217. }
  1218. if ($parasVal_hp != 0) {
  1219. $heroHp += $parasVal_hp;
  1220. }
  1221. $dec_demage = $mo->dec_demage + $addDecDamage; # 英雄基础减伤 + 启灵减伤
  1222. $bigHit_Val = $mo->bigHit_Val / 100;
  1223. $bigHit_rate = $mo->bigHit_rate / 100;
  1224. $val = $heroAttck * ($heroHp - $dec_demage) * (1 + $bigHit_rate * ($bigHit_Val - 1));
  1225. return intval($val);
  1226. }
  1227. // </editor-fold>
  1228. }