FightProc.php 54 KB

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