FightProc.php 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * 战斗模块
  5. * @author c'y'zhao
  6. */
  7. class FightProc {
  8. /**
  9. * 逻辑分发
  10. * 所有的Proc中必须有这样一个方法
  11. * @param Req $req
  12. */
  13. public static function procMain($req) {
  14. switch ($req->cmd) {
  15. case CmdCode::fight_settle: # 6801 主线战斗结算
  16. return FightProc::Settle();
  17. case CmdCode::fight_PassGateTsPrizeReceive: # 6802 章节宝箱的领取
  18. return FightProc::PassGateTsPrizeReceive();
  19. case CmdCode::fight_selectGate: # 6803 主线剧情关卡选择
  20. return FightProc::SelectGate();
  21. case CmdCode::fight_gateChallengeRewards: # 6804 挑战关卡: 领取奖励
  22. return FightProc::GateChallengeRewards();
  23. case CmdCode::fihgt_reliveCost: # 6805 战斗: 复活花费
  24. return FightProc::ReliveCost();
  25. case CmdCode::fight_plotSav: # 6806 主线剧情(已播放)回存
  26. return FightProc::PlotSav();
  27. case CmdCode::fight_sweep: # 6807 主线扫荡
  28. return FightProc::FightSweep();
  29. case CmdCode::fight_startFight: # 6808 主线剧情关卡开始挑战
  30. return self::StartFight();
  31. case CmdCode::fight_tower_RefreshSkills: # 6809 挑战关卡: 刷新初始技能
  32. return self::TowerRefreshSkills();
  33. case CmdCode::fight_tower_updatelocklist: # 6810 挑战关卡: 更新技能锁定列表
  34. return self::TowerUpdateLockskillList();
  35. case CmdCode::fight_rankInfo: # 6811 获取主线关卡排行榜信息
  36. return self::GetRankInfo();
  37. case CmdCode::fight_rank_uidEquipInfo: # 6812 获取主线关卡榜内玩家的装备信息
  38. return self::GetUidEquipInfo_Rank();
  39. case CmdCode::fight_rank_GetMainGateRankRewardInfo: # 6813 获取通关荣誉榜信息
  40. return self::GetmainGate_RankRewardInfo();
  41. case CmdCode::fight_rank_GetFightPowerRankRewardInfo: # 6814 获取战力荣誉榜信息
  42. return self::GetFightPower_RankRewardInfo();
  43. case CmdCode::fight_rank_ReceiveRankReward_MainGate: # 6815 领取通关荣誉榜奖励
  44. return self::ReceiveRankReward_MainGate();
  45. case CmdCode::fight_rank_ReceiveRankReward_FightPower: # 6816 领取战力荣誉榜奖励
  46. return self::ReceiveRankReward_FightPower();
  47. case CmdCode::fight_rank_IsExistRankReward: # 6817 是否存在未领取的荣誉榜奖励
  48. return self::IsExistRankReward();
  49. case CmdCode::fight_evolveUnlock: # 6818 启灵解锁
  50. return self::EvolveUnlock();
  51. case CmdCode::fight_MainTZPass: # 6819 主线挑战--通关
  52. return self::MainTZPass();
  53. case CmdCode::fight_MainTZGetReward: # 6820 主线挑战--领取奖励
  54. return self::MainTZGetReward();
  55. case CmdCode::fight_ResetChallange_RedMask: # 6821 每天重置挑战红点
  56. return self::ResetChallange_RedMask();
  57. case CmdCode::fight_lockSkill: # 6822 封印/解封技能
  58. return self::LockSkill();
  59. case CmdCode::fight_buyLockSkillCount: # 6823 购买更多封印数量
  60. return self::BuySkillLockCount();
  61. case CmdCode::fight_rank_ReceiveRankReward: # 6824 排行奖励一键领取
  62. return self::ReceiveRankReward();
  63. case CmdCode::fight_PVP_match: # 6825 PVP 匹配一个对手
  64. return self::PvpMatchPlayer();
  65. case CmdCode::fight_WorldBoss_rankInfo: # 6826 世界boss的排名信息
  66. return self::GetWorldBoss_RankInfo();
  67. case CmdCode::fight_WorldBoss_getRankDamageVal: # 6827 当前轮次下 自己的最高伤害值
  68. return self::GetWorldBoss_RankDamageVal();
  69. case CmdCode::fight_WorldBoss_getSelfRank: # 6828 获取自己的排名信息
  70. return self::GetWorldBoss_GetSelfRank();
  71. case CmdCode::fight_WorldBoss_claimRewards: # 6829 领取奖励
  72. return self::GetWorldBoss_ClaimRewards();
  73. case CmdCode::fight_WorldBoss_settle: # 6830 世界boss结算
  74. return self::WorldBoss_settle();
  75. default:
  76. Err(ErrCode::cmd_err);
  77. }
  78. }
  79. /**
  80. * 6825 pvp 匹配一个对手
  81. * @return Resp
  82. */
  83. static function PvpMatchPlayer() {
  84. // 先从排行榜上随机取一个玩家的数据返回 -gwang 2024.10.30
  85. // $uid = req()->uid;
  86. $memKey = MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid);
  87. $mem = gMem();
  88. $length = $mem->zlen($memKey);
  89. if ($length > glc()->Rank_FightPower_OnListRank) {
  90. $length = glc()->Rank_FightPower_OnListRank;
  91. }
  92. $arr = $mem->zrange($memKey, 0, $length - 1);
  93. $uid = $arr[array_rand($arr)]; # 这里是否应该去掉自己呢? 算了不用,自己打自己也是一种挑战
  94. $pvpPlayer = UserProc::getUserGame(req()->zoneid, $uid);
  95. return Resp::ok($pvpPlayer);
  96. }
  97. /**
  98. * 6823 购买更多技能封印数量
  99. */
  100. static function BuySkillLockCount() {
  101. list($n) = req()->paras; # 解锁数量
  102. my_Assert($n > ctx()->privateData()->skillLockerNumber, ErrCode::paras_err); # 参数异常
  103. $amt = 0;
  104. foreach (explode(",", glc()->Skill_LockBtn_BuyCount_Cost) as $str) {
  105. list($cnt, $cost) = explode(':', $str);
  106. if ($cnt == $n) {
  107. $amt = $cost;
  108. break;
  109. }
  110. }
  111. my_Assert($amt > 0, "消耗元宝数量配置出错!");
  112. my_Assert(ctx()->base(true)->Consume_Cash($amt), ErrCode::notenough_cash_msg);
  113. ctx()->privateData(true)->skillLockerNumber = $cnt;
  114. UserProc::updateUserInfo();
  115. return Resp::ok();
  116. }
  117. /**
  118. * 6822 封印/解封技能
  119. */
  120. static function LockSkill() {
  121. list($skillTypeId) = req()->paras; # 技能类型ID
  122. $pri = ctx()->privateData(true);
  123. // my_Assert(in_array($skillTypeId, $pri->skillUnlockRecord), "技能尚未解锁!");
  124. if (in_array($skillTypeId, $pri->skillReLocked)) { # 解封
  125. StlUtil::arrayRemove($pri->skillReLocked, $skillTypeId);
  126. } else { # 封印
  127. my_Assert(count($pri->skillReLocked) < $pri->skillLockerNumber, "超出封印上限!");
  128. $pri->skillReLocked[] = $skillTypeId;
  129. TaskProc::OnCloseSkill();
  130. }
  131. return Resp::ok(array("task" => ctx()->task,));
  132. }
  133. /**
  134. * 6821 每天重置挑战红点
  135. */
  136. static function ResetChallange_RedMask() {
  137. ctx()->privateData(true)->challange_RedMask = 1;
  138. UserProc::updateUserInfo();
  139. return Resp::ok();
  140. }
  141. /**
  142. * 6819 主线挑战 -- 通关
  143. */
  144. static function MainTZPass() {
  145. list($gateId, $index, $killMonsterNum, $killBossNum) = req()->paras; # 关卡id, 通关难度索引(1/2/3)
  146. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  147. // isEditor() && $gateInfo = new Ins_GateInfo();
  148. $gateInfo = ctx()->gates->GateList->$gateId;
  149. my_Assert($gateInfo->pass, ErrCode::gate_GateNoUnlock); # 通关后解锁难度1
  150. // my_Assert($gateInfo->tz_state + 1 >= $index, ErrCode::gate_GateNoUnlock); # 通关上一难度解锁当前难度
  151. FightProc::funUnlock_mainChallengeGate_State(true, $gateId, $index);
  152. $gateInfo->tz_state = $index;
  153. TaskProc::OnPassMainChallengeGate_X_Num($gateId, $index);
  154. TaskProc::OnKillCommonNumMonster($killMonsterNum);
  155. TaskProc::OnKillleaderNumMonster($killBossNum);
  156. //TaskProc::Day7TaskReset();
  157. UserProc::updateUserInfo();
  158. return Resp::ok(array("task" => ctx()->task,
  159. 'privateState' => ctx()->privateState,
  160. // 'funUnlockRecord' => ctx()->privateState->funUnlockRecord,
  161. // 'funUnlockRecord_2' => ctx()->privateState->funUnlockRecord_2,
  162. ));
  163. }
  164. /**
  165. * 6820 主线挑战 -- 领取奖励
  166. */
  167. static function MainTZGetReward() {
  168. list($gateId, $index) = req()->paras; # 关卡id, 通关难度索引(1/2/3)
  169. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  170. // isEditor() && $gateInfo = new Ins_GateInfo();
  171. $gateInfo = ctx()->gates->GateList->$gateId;
  172. my_Assert($gateInfo->pass, ErrCode::gate_GateNoUnlock); # 通关后解锁难度1
  173. my_Assert($gateInfo->tz_state >= $index, ErrCode::gate_GateNoUnlock); # 已解锁当前难度
  174. my_Assert(Bits::GetBitValue($gateInfo->tz_rewards, $index - 1) == false, ErrCode::gate_GatePriceHasReceive);
  175. $gateInfo->tz_rewards = Bits::SetBitValue($gateInfo->tz_rewards, $index - 1, true); # 更新领取记录
  176. $prize = "tz_reward" . $index;
  177. $mo = GameConfig::gate_getItem($gateId);
  178. StoreProc::AddMultiItemInStore($mo->$prize);
  179. UserProc::updateUserInfo();
  180. return Resp::ok(array(
  181. 'gold' => ctx()->baseInfo->gold,
  182. 'cash' => ctx()->baseInfo->cash,
  183. 'store' => ctx()->store,
  184. 'reward' => StoreProc::$reward,
  185. 'reward_Gem' => StoreProc::$reward_Gem,
  186. 'reward_equip' => StoreProc::$reward_equip,
  187. ));
  188. }
  189. /**
  190. * 6818 启灵解锁
  191. * @return type
  192. */
  193. public static function EvolveUnlock() {
  194. list($type, $id) = req()->paras; //$id废弃 因为玩家可能不安顺序点
  195. if ($type == 1) {
  196. $nextId = ctx()->gates->evolveMaxId_left + 1;
  197. my_Assert($id == $nextId, ErrCode::err_const_no);
  198. $mo = GameConfig::evolve_getItem($nextId);
  199. my_Assert($mo != null, ErrCode::err_const_no);
  200. my_Assert(ctx()->baseInfo->level >= $mo->level, ErrCode::evolve_canotUnlock_levelLimit);
  201. my_Assert(ctx()->baseInfo->gold >= $mo->needGold_unlock, ErrCode::notenough_gold_msg);
  202. ctx()->baseInfo->Consume_Gold($mo->needGold_unlock);
  203. ctx()->gates->evolveMaxId_left = $nextId;
  204. GuideProc::Shop_Guide_Trigger(ctx()->gates->evolveMaxId_left);
  205. TaskProc::OnCompleteNumQiLing();
  206. } else {
  207. $nextId = ctx()->gates->evolveMaxId_right + 1;
  208. my_Assert($id == $nextId, ErrCode::err_const_no);
  209. $dic = GameConfig::evolve();
  210. foreach ($dic as $key => $value) {
  211. if ($value->specificEvolveId == $nextId) {
  212. $mo = $value;
  213. }
  214. }
  215. my_Assert(ctx()->baseInfo->level >= $mo->level, ErrCode::evolve_canotUnlock_levelLimit);
  216. my_Assert($mo != null, ErrCode::err_const_no);
  217. if ($mo->specificEvolveCost != null) {
  218. $cost = explode(',', $mo->specificEvolveCost);
  219. $costId = $cost[0];
  220. $costNum = $cost[1];
  221. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $costId) && ctx()->store->items->$costId >= $costNum, ErrCode::notenough_item);
  222. ctx()->store->removeItem($costId, $costNum);
  223. }
  224. ctx()->gates->evolveMaxId_right = $id;
  225. TaskProc::OnCompleteNumSpecialQiLing();
  226. }
  227. FightProc::Ranking_FightPower();
  228. UserProc::updateUserInfo();
  229. $ret = array(
  230. 'task' => ctx()->task,
  231. 'gold' => ctx()->baseInfo->gold,
  232. 'items' => ctx()->store->items,
  233. 'evolveMaxId_right' => ctx()->gates->evolveMaxId_right,
  234. 'evolveMaxId_left' => ctx()->gates->evolveMaxId_left,
  235. );
  236. return Resp::ok($ret);
  237. }
  238. /**
  239. * 6807 扫荡
  240. * @return type
  241. */
  242. public static function FightSweep() {
  243. //list($gateId) = req()->paras;
  244. // 2024.12.17 扫荡修改: 前3次免费, 后面可以一直看广告免费.(特权月卡可以免广告, 结合到一起, 特权月卡就可以一直刷了.)
  245. $passGateId = ctx()->gates->maxPassGateId(); # 最高通关关卡id
  246. my_Assert($passGateId != 0, ErrCode::gate_NoSweep); # 还没有通关关卡
  247. $mo = GameConfig::gate_getItem($passGateId); # 关卡配置数据
  248. my_Assert(null != $mo, ErrCode::err_const_no); # 防御: 关卡配置找不到
  249. $gateName = $mo->gateName;
  250. $costTili = glc()->sweep_cost_tili;
  251. $curTili = ctx()->baseInfo->CurTili();
  252. my_Assert($curTili >= $costTili, ErrCode::notenough_tili); # 检查: 体力不足
  253. # 2024.12.17 去掉了次数限制, 故这段废弃
  254. // if (ctx()->privateState->honourCardShop_ts == 0) {
  255. // $max = glc()->sweepMaxNum;
  256. // my_Assert(ctx()->gates->fightSweepNum < $max, ErrCode::gate_SweepMaxNum_limit);
  257. // }
  258. if (ctx()->gates->fightSweepNum < glc()->sweepMaxNum) {
  259. ctx()->gates->fightSweepTs = now(); # 前三次无冷却
  260. } else {
  261. ctx()->gates->fightSweepTs = now(60); # 下次扫荡时间戳(广告时需要间隔)
  262. }
  263. ctx()->gates->fightSweepNum += 1; # 增加扫荡次数记录
  264. ctx()->baseInfo->Consume_tili($costTili); # 扣除体力
  265. ctx()->privateData(true)->battlePass_tili += $costTili; # 增加体力消耗记录
  266. # 发放扫荡奖励↓
  267. $wavesArr = GameConfig::waves_getItemArray($passGateId);
  268. $count = count($wavesArr);
  269. $wavesMo = $wavesArr[$count - 1];
  270. $gold = $wavesMo->rewardGold;
  271. StoreProc::AddMultiItemInStore("1," . $gold);
  272. $oldLevel = ctx()->baseInfo->level;
  273. $exp = $wavesMo->rewardExp;
  274. StoreProc::AddMultiItemInStore("4," . $exp);
  275. $newLevel = ctx()->baseInfo->level;
  276. if ($wavesMo->rewardTuZhi != null) {
  277. $tuzhi = explode('-', $wavesMo->rewardTuZhi);
  278. $n = rand($tuzhi[0], $tuzhi[1]);
  279. $tuzhiArr = array();
  280. $item = GameConfig::item();
  281. foreach ($item as $id => $mo) {
  282. if ($mo->itemType == 100) {
  283. $tuzhiArr[] = $id;
  284. }
  285. }
  286. for ($i = 0; $i < $n; $i++) {
  287. $index = rand(0, count($tuzhiArr) - 1);
  288. $goodsStr = $tuzhiArr[$index] . ',' . 1;
  289. $prizeArr[] = $goodsStr;
  290. StoreProc::AddMultiItemInStore($goodsStr);
  291. }
  292. }
  293. if ($wavesMo->rewardItem != null) {
  294. $reward = StoreProc::Distribute_Rewards($wavesMo->rewardItem);
  295. StoreProc::AddMultiItemInStore($reward);
  296. }
  297. if ($wavesMo->rewardGem != null) {
  298. $goodsStr = self::sweepRandReward($wavesMo->rewardGem);
  299. $str = explode(';', $goodsStr);
  300. $dic = GameConfig::gem();
  301. foreach ($str as $value) {
  302. $list = explode(',', $value);
  303. $posId = rand(1, 6);
  304. $qual = $list[0];
  305. foreach ($dic as $key => $gemMo) {
  306. if ($gemMo->qual == $qual && $gemMo->position == $posId && $gemMo->isfixed_predicateId == 0) {
  307. $gemStr = $gemMo->typeId . ',' . $list[1];
  308. SystemProc::GetGem_GreaterOrangeQual_SweepMainGateIndex(req()->zoneid, ctx()->baseInfo->name, Ins_GateInfo::gateNum($passGateId), $gateName, $gemMo->typeId);
  309. //StoreProc::PutGemInStore($gemMo->typeId, $list[1]);
  310. StoreProc::AddMultiItemInStore($gemStr);
  311. break;
  312. }
  313. }
  314. }
  315. }
  316. # 奖励逻辑结束.
  317. TaskProc::OnFightSweepGate();
  318. UserProc::updateUserInfo();
  319. $ret = array(
  320. 'gold' => ctx()->baseInfo->gold,
  321. 'cash' => ctx()->baseInfo->cash,
  322. 'tili' => ctx()->baseInfo->tili,
  323. 'tili_ts' => ctx()->baseInfo->tili_ts,
  324. 'xp' => ctx()->baseInfo->xp,
  325. 'maxXp' => ctx()->baseInfo->maxXp,
  326. 'level' => ctx()->baseInfo->level,
  327. 'fightSweepNum' => ctx()->gates->fightSweepNum,
  328. 'fightSweepTs' => ctx()->gates->fightSweepTs,
  329. //'prizeArr' => $prizeArr,
  330. 'store' => ctx()->store,
  331. 'task' => ctx()->task,
  332. 'reward' => StoreProc::$reward,
  333. 'reward_Gem' => StoreProc::$reward_Gem,
  334. 'reward_equip' => StoreProc::$reward_equip,
  335. 'oldLevel' => $oldLevel,
  336. 'newLevel' => $newLevel,
  337. );
  338. return Resp::ok($ret);
  339. }
  340. static function sweepRandReward($rewardStr) {
  341. $ctxArr = explode(';', $rewardStr);
  342. $numArr = explode('-', $ctxArr[0]);
  343. $num = rand($numArr[0], $numArr[1]);
  344. $rand = 0;
  345. $itemArr = explode(',', $ctxArr[1]);
  346. foreach ($itemArr as $value) {
  347. $arr = explode(':', $value);
  348. $itemId = $arr[0];
  349. $per = $arr[1];
  350. $rand += $per;
  351. }
  352. $res = "";
  353. for ($i = 0; $i < $num; $i++) {
  354. $start = 0;
  355. $end = 0;
  356. $randNum = rand(1, $rand);
  357. $id = 0;
  358. foreach ($itemArr as $str) {
  359. $arr = explode(':', $str);
  360. $itemId = $arr[0];
  361. $per = $arr[1];
  362. $end += $per;
  363. if ($randNum > $start && $randNum <= $end) {
  364. $id = $itemId;
  365. break;
  366. }
  367. $start = $end;
  368. }
  369. if ($id != 0) {
  370. $str = $id . ',1';
  371. if ($res == "") {
  372. $res = $str;
  373. } else {
  374. $res = $res . ';' . $str;
  375. }
  376. }
  377. }
  378. return $res;
  379. }
  380. /**
  381. * 6808 开始挑战 (主线关卡:扣除体力, 挑战关卡: 增加次数)
  382. */
  383. private static function StartFight() {
  384. list($gateId, $layerNum) = req()->paras;
  385. my_Assert($gateId > 0, ErrCode::paras_err);
  386. $mo = GameConfig::gate_getItem($gateId);
  387. my_Assert(null != $mo, ErrCode::err_const_no);
  388. if (Ints::Slice($gateId, 0, 1) == 9) { # 爬塔模式
  389. // list($layerNum) = req()->paras;
  390. if ($layerNum != ctx()->gates()->TowerGateInfo()->CurLayer) { # --起始层数校验
  391. Err(ErrCode::tower_layerNum);
  392. }
  393. if (ctx()->gates()->TowerGateInfo()->TodayChanNum < 1) { # --剩余次数校验
  394. Err(ErrCode::tower_timeNo);
  395. }
  396. ctx()->gates()->TowerGateInfo()->TodayChanNum--; # --增加次数
  397. } else if (Ints::Slice($gateId, 0, 1) == 8) { # 兔羊模式
  398. // nothing todo 临时
  399. } else { # 主线剧情
  400. my_Assert(ctx()->base(true)->Consume_tili($mo->cost_tili), ErrCode::notenough_tili);
  401. ctx()->privateData(true)->battlePass_tili += $mo->cost_tili;
  402. }
  403. ctx()->gates()->lastStartFightTs = now(); # 记录下开始战斗的时间戳(状态变量,用于校验战斗用时,排除作弊)
  404. UserProc::updateUserInfo();
  405. return Resp::ok(array("tili" => ctx()->baseInfo->tili, "tili_ts" => ctx()->baseInfo->tili_ts));
  406. }
  407. /**
  408. * 战斗模块 - 每日清理变量
  409. */
  410. public static function FightDailyClear() {
  411. //ctx()->gates->xunluo_quick_buyRecord = 0;
  412. ctx()->gates->fightSweepNum = 0;
  413. ctx()->gates->fightSweepTs = now();
  414. ctx()->gates()->TowerGateInfo()->RefreshSkillTimes = 0;
  415. ctx()->gates()->TowerGateInfo()->TodayChanNum = glc()->tower_daily_chanceNum;
  416. ctx()->privateState->challange_RedMask = 0;
  417. }
  418. /**
  419. * 6806 剧情回存
  420. * @return type
  421. */
  422. public static function PlotSav() {
  423. list($gateId) = req()->paras;
  424. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::err_const_no);
  425. ctx()->gates->GateList->$gateId->plotStart = 1;
  426. UserProc::updateUserInfo();
  427. $ret = array(
  428. 'ok' => 1,
  429. );
  430. return Resp::ok($ret);
  431. }
  432. // <editor-fold defaultstate="collapsed" desc="挑战模块">
  433. /**
  434. * 6810 挑战关卡: 更新锁定技能列表
  435. */
  436. public static function TowerUpdateLockskillList() {
  437. list($li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  438. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  439. $t->skill_zhudong = $li_zd;
  440. $t->skill_beidong = $li_bd;
  441. $t->skill_zhudong_lockState = $li_zds;
  442. $t->skill_beidong_lockState = $li_bds;
  443. UserProc::updateUserInfo();
  444. return Resp::ok();
  445. }
  446. /**
  447. * 6809 挑战关卡: 刷新初始技能(扣除免费次数/cost)
  448. */
  449. public static function TowerRefreshSkills() {
  450. list($isFree, $li_zd, $li_bd, $li_zds, $li_bds) = req()->paras; # 参数解析
  451. if ($isFree) {
  452. if (ctx()->gates()->TowerGateInfo()->RefreshSkillTimes > glc()->tower_daily_refreshChanceNum) {
  453. Err(ErrCode::tower_refreshNo); # 免费次数不足
  454. }
  455. } else {
  456. list($type, $num) = explode(':', glc()->tower_refreshCost); # 二级货币类型(1:金币,2:元宝):数量
  457. if ($type == 1) { # 金币
  458. my_Assert(ctx()->base(true)->Consume_Gold($num), ErrCode::notenough_gold_msg);
  459. } else if ($type == 2) { # 元宝
  460. my_Assert(ctx()->base(true)->Consume_Cash($num), ErrCode::notenough_cash_msg);
  461. } else {
  462. Err(ErrCode::err_const_no, "检查刷新扣费配置信息!");
  463. }
  464. }
  465. $t = ctx()->gates()->TowerGateInfo(); # 记忆技能刷新结果
  466. $t->RefreshSkillTimes++;
  467. $t->skill_zhudong = $li_zd;
  468. $t->skill_beidong = $li_bd;
  469. $t->skill_zhudong_lockState = $li_zds;
  470. $t->skill_beidong_lockState = $li_bds;
  471. UserProc::updateUserInfo();
  472. $ret = array(
  473. 'task' => ctx()->task,
  474. );
  475. return Resp::ok($ret);
  476. }
  477. /**
  478. * 6805 战斗: 复活花费
  479. * @return type
  480. * @version 2024年5月17日 重整利用为复活扣除消耗功能
  481. */
  482. public static function ReliveCost() {
  483. // 复活可以扣除复活币(暂无)或者元宝,(客户端看广告复活不需要跟服务器通讯)
  484. list($reliveNum) = req()->paras;
  485. $arr = explode(',', glc()->Relive_cost);
  486. my_Assert($reliveNum >= 0 && $reliveNum <= Count($arr), ErrCode::paras_err); # 参数范围>0
  487. $amt = $arr[$reliveNum];
  488. my_Assert(ctx()->base(true)->Consume_Cash($amt), ErrCode::notenought_yuanbao);
  489. UserProc::updateUserInfo();
  490. return Resp::ok();
  491. }
  492. /**
  493. * 6804 挑战关卡: 奖励领取
  494. * @return type
  495. */
  496. public static function GateChallengeRewards() {
  497. list($finalLayer, $killedMonster, $killedBoss) = req()->paras; # 战斗结束时的层数
  498. $lastLayer = ctx()->gates()->TowerGateInfo()->CurLayer;
  499. $arr = GameConfig::waves_getItemArray(glc()->TowerGateId);
  500. TaskProc::OnFightNumChallengeGate();
  501. TaskProc::OnKillCommonNumMonster($killedMonster);
  502. TaskProc::OnKillleaderNumMonster($killedBoss);
  503. if ($finalLayer > $lastLayer) {
  504. foreach ($arr as $layerId => $layerMo) {
  505. if ($layerMo->waveId >= $lastLayer && $layerMo->waveId < $finalLayer) {
  506. my_Assert($layerMo != null, ErrCode::err_const_no);
  507. StoreProc::AddMultiItemInStore($layerMo->rewards); # 发放奖励
  508. }
  509. }
  510. ctx()->gates()->TowerGateInfo()->CurLayer = $finalLayer;
  511. TaskProc::OnPassLayer_ChallengeGate($finalLayer - 1);
  512. UserProc::updateUserInfo();
  513. $ret = array(
  514. 'store' => ctx()->store,
  515. 'gold' => ctx()->base()->gold,
  516. 'cash' => ctx()->base()->cash,
  517. 'task' => ctx()->task,
  518. );
  519. return Resp::ok($ret);
  520. } else if ($finalLayer == $lastLayer) {
  521. $ret = array(
  522. 'store' => ctx()->store,
  523. 'gold' => ctx()->base()->gold,
  524. 'cash' => ctx()->base()->cash,
  525. 'task' => ctx()->task,
  526. );
  527. return Resp::ok($ret);
  528. }
  529. return Resp::err(ErrCode::tower_rewardNo); # 没有奖励
  530. }
  531. // </editor-fold>
  532. /**
  533. * 6803 关卡选择
  534. * @return type
  535. */
  536. public static function SelectGate() {
  537. list($gateId) = req()->paras;
  538. ctx()->gates->CurrentGateId = $gateId;
  539. UserProc::updateUserInfo();
  540. $ret = array(
  541. 'gates' => ctx()->gates,
  542. );
  543. return Resp::ok($ret);
  544. }
  545. /**
  546. * 6802 章节宝箱的领取
  547. * @return type
  548. */
  549. public static function PassGateTsPrizeReceive() {
  550. list($gateId, $index) = req()->paras;
  551. $gateMo = GameConfig::gate_getItem($gateId);
  552. my_Assert($gateMo != null, ErrCode::err_const_no);
  553. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  554. $gateInfo = ctx()->gates->GateList->$gateId;
  555. $tag = false;
  556. $prize = "";
  557. $mask = 0;
  558. switch ($index) {
  559. case 1:
  560. $ts = $gateMo->first_ts1 * 60;
  561. if ($gateInfo->MaxSeconds >= $ts || $gateInfo->pass > 0) {
  562. $tag = true;
  563. }
  564. $mask = 1;
  565. $prize = $gateMo->first_reward1;
  566. break;
  567. case 2:
  568. $ts = $gateMo->first_ts2 * 60;
  569. if ($gateInfo->MaxSeconds >= $ts || $gateInfo->pass > 0) {
  570. $tag = true;
  571. }
  572. $mask = 2;
  573. $prize = $gateMo->first_reward2;
  574. break;
  575. case 3:
  576. if ($gateInfo->pass > 0) {
  577. $tag = true;
  578. }
  579. $mask = 3;
  580. $prize = $gateMo->first_reward3;
  581. break;
  582. default:
  583. break;
  584. }
  585. if ($tag) {
  586. my_Assert(!in_array($mask, $gateInfo->FirstReward), ErrCode::gate_GatePriceHasReceive);
  587. $gateInfo->FirstReward[] = $mask;
  588. GuideProc::HeroChange_Guide_Trigger($gateId, $index);
  589. StoreProc::AddMultiItemInStore($prize);
  590. }
  591. ctx()->gates->GateList->$gateId = $gateInfo;
  592. TaskProc::OnReceiveGateBoxReward();
  593. UserProc::updateUserInfo();
  594. $ret = array(
  595. 'gates' => ctx()->gates,
  596. 'store' => ctx()->store,
  597. 'task' => ctx()->task,
  598. 'gold' => ctx()->baseInfo->gold,
  599. 'cash' => ctx()->baseInfo->cash,
  600. 'reward' => StoreProc::$reward,
  601. 'reward_Gem' => StoreProc::$reward_Gem,
  602. 'reward_equip' => StoreProc::$reward_equip,
  603. 'heros' => ctx()->heros,
  604. 'funUnlockRecord' => ctx()->privateState->funUnlockRecord,
  605. 'funUnlockRecord_2' => ctx()->privateState->funUnlockRecord_2,
  606. 'funUnlockRecord_3' => ctx()->privateState->funUnlockRecord_3,
  607. );
  608. return Resp::ok($ret);
  609. }
  610. /**
  611. * [6801]关卡战斗结算
  612. * @return type
  613. */
  614. public static function Settle() {
  615. list($resultType, $gateId, $gold, $curTs, $pickups,
  616. $finalLayer, $finalHpPercent, $killMonsterNum, $killBossNum,
  617. $finalLevel, $reliveNum) = req()->paras;
  618. # 客户端需要增加参数: killmonserNum,killBosssNum, finalHpPercent(最终血量百分比)
  619. $gateMo = GameConfig::gate_getItem($gateId);
  620. my_Assert($gateMo != null, ErrCode::err_const_no);
  621. my_Assert(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId), ErrCode::gate_NoUserGateInfo);
  622. $gateInfo = ctx()->gates->GateList->$gateId;
  623. $ts = $gateInfo->MaxSeconds;
  624. if ($curTs >= $ts) {
  625. $gateInfo->MaxSeconds = $curTs;
  626. }
  627. self::funUnlock_Gate($resultType, $gateId); //备注:这个接口的位置不能动 里面有关卡第一次胜利解锁的功能提示校验
  628. //self::subFunUnlock($resultType, $gateId);
  629. if ($resultType) { # 胜利
  630. self::skillUnlock_gate($resultType, $gateId); //备注 这个接口位置不能动
  631. GuideProc::GateBoxReceived_Guide_Trigger($gateId, 1);
  632. if (ctx()->gates->GateList->$gateId->pass == 0) {
  633. ctx()->gates->GateList->$gateId->pass = 1;
  634. $maxGateId = ctx()->gates->maxPassGateNumId();
  635. if ($maxGateId > 0) {
  636. self::Ranking_MainGateIndex($maxGateId);
  637. self::IsAchievedMainGate_PassReward($maxGateId);
  638. }
  639. }
  640. TaskProc::OnPassGate_X($gateId); # 刷新任务进度: 通关第X关
  641. TaskProc::OnPassGate_X_state($gateId);
  642. if (Ins_GateInfo::GateTypeFromId($gateId) == Enum_GateType::MainStoryGate) {
  643. ctx()->gates()->UnlockNextPlotGate($gateId); # 解锁下一主线关卡
  644. // ctx()->gates()->UnlockMainChallengeGate($gateId); # 挑战关卡解锁逻辑. -gwang 2024年4月15日
  645. } else { # 不是主线关卡, 暂时没有其他逻辑
  646. }
  647. // StoreProc::AddMultiItemInStore($gateMo->reward_win); # 发放胜利奖励(2024.5.30 过期)
  648. } else {
  649. ctx()->gates->GateList->$gateId->fightNum_fail += 1;
  650. self::skillUnlock_fightNum($resultType); //这个接口位置不能动
  651. }
  652. // else { # 失败
  653. //// StoreProc::AddMultiItemInStore($gateMo->reward_fail); # 发放失败奖励(2024.5.30 过期)
  654. // }
  655. StoreProc::AddMultiItemInStore($pickups); # 战场拾取道具直接入背包
  656. //ctx()->base()->Add_Gold($gold); # 战场拾取的金币直接入背包
  657. //ctx()->base()->Add_Exp($exp);
  658. $waveMo = GameConfig::waveItem_getItem($gateId, $finalLayer);
  659. my_Assert(null != $waveMo, ErrCode::err_const_no);
  660. my_Assert(now() - ctx()->gates->lastStartFightTs > $waveMo->minTs, ErrCode::err_opTimeTooShort); # todo:校验战斗耗时 2025年4月10日16:29:46
  661. $oldLevel = ctx()->baseInfo->level;
  662. StoreProc::AddMultiItemInStore('4,' . $waveMo->rewardExp);
  663. //ctx()->base()->Add_Exp($waveMo->rewardExp); # 指挥官经验
  664. $newLevel = ctx()->baseInfo->level;
  665. if ($oldLevel != $newLevel) {
  666. ctx()->privateData(true)->oldLevel = $oldLevel;
  667. ctx()->privateData(true)->upLevel = $newLevel;
  668. }
  669. //ctx()->base()->Add_Gold($waveMo->rewardGold); # 金币奖励
  670. //$pickups .= ";1," . $gold + $waveMo->rewardGold;
  671. $str = "1," . $gold + $waveMo->rewardGold;
  672. StoreProc::AddMultiItemInStore($str);
  673. if ($waveMo->rewardItem != null) {
  674. $reward = StoreProc::Distribute_Rewards($waveMo->rewardItem);
  675. StoreProc::AddMultiItemInStore($reward);
  676. // if(count(StoreProc::$reward_equip) > 0){
  677. // self::funUnlock_equip_firstTime();
  678. // }
  679. }
  680. # 图纸奖励: 数量min-max, 部位随机
  681. if (strlen($waveMo->rewardTuZhi) > 0 && str_contains($waveMo->rewardTuZhi, '-')) {
  682. list($tz_min, $tz_max) = explode('-', $waveMo->rewardTuZhi); # 图纸数量
  683. $tz_n = rand($tz_min, $tz_max);
  684. # 图纸部位数据源 1001, 1002, 1003, 1004, 1005, 1006
  685. for ($i = 0; $i < $tz_n; $i++) {
  686. $id = 1000 + rand(1, 6);
  687. StoreProc::AddMultiItemInStore("$id,1"); # 获得图纸
  688. //$pickups .= ";$id,1";
  689. }
  690. }
  691. # 宝石奖励: 数量min-max;品质:权重,品质:权重...
  692. if (strlen($waveMo->rewardGem) > 0) {
  693. //self::funUnlock_Gem();
  694. list($gs_num, $gs_props) = explode(';', $waveMo->rewardGem);
  695. list($gem_min, $gem_max) = explode('-', $gs_num); # 宝石数量
  696. $gem_n = rand($gem_min, $gem_max);
  697. $arr = explode(",", $gs_props);
  698. $pool = array();
  699. $n = 0;
  700. foreach ($arr as $str) {
  701. list($qual, $props) = explode(':', $str);
  702. $pool[] = array('q' => $qual, 'p' => $props);
  703. $n += $props;
  704. }
  705. for ($i = 0; $i < $gem_n; $i++) { # 随机n块宝石
  706. $r = rand(1, $n); # 投色子
  707. $l = 0;
  708. foreach ($pool as $item) {
  709. if ($r <= ($l + $item['p'])) {
  710. $gemId = $item['q'] * 100000 + rand(1, 6) * 1000;
  711. SystemProc::GetGem_GreaterOrangeQual_MainGate(req()->zoneid, ctx()->baseInfo->name, Ins_GateInfo::gateNum($gateId), $gateMo->gateName, $gemId); //广播
  712. //StoreProc::PutGemInStore($gemId); # 发放宝石并退出本次投色子
  713. //$pickups .= ";$gemId,1";
  714. StoreProc::AddMultiItemInStore("$gemId,1");
  715. break;
  716. }
  717. $l += $item['p']; # 累计到下一段
  718. }
  719. }
  720. }
  721. ctx()->gates->GateList->$gateId->fightNum += 1;
  722. GuideProc::MainTaskRewardReceived_Guide_Trigger($gateId, ctx()->gates->GateList->$gateId->fightNum);
  723. //TaskProc::Day7TaskReset();
  724. TaskProc::OnFightNumMainGate();
  725. TaskProc::OnKillCommonNumMonster($killMonsterNum);
  726. TaskProc::OnKillleaderNumMonster($killBossNum);
  727. TaskProc::OnFightGate_X($gateId);
  728. if ($gateId == 11000) {
  729. ctx()->gates()->UnlockNextPlotGate(11000);
  730. ctx()->gates(true)->CurrentGateId = 11001;
  731. StlUtil::dictRemove(ctx()->gates->GateList, 11000);
  732. ctx()->baseInfo->animation = 1;
  733. }
  734. UserProc::updateUserInfo();
  735. $ret = array(
  736. 'gates' => ctx()->gates,
  737. 'store' => ctx()->store,
  738. 'task' => ctx()->task,
  739. 'baseInfo' => ctx()->base(),
  740. 'gold' => $gold + $waveMo->rewardGold,
  741. 'exp' => $waveMo->rewardExp,
  742. //'rewardStr' => $pickups
  743. 'reward' => StoreProc::$reward,
  744. 'reward_Gem' => StoreProc::$reward_Gem,
  745. 'reward_equip' => StoreProc::$reward_equip,
  746. 'oldLevel' => $oldLevel,
  747. 'newLevel' => $newLevel,
  748. //'funUnlockRecord' => ctx()->privateState->funUnlockRecord,
  749. //'funUnlockRecord_2' => ctx()->privateState->funUnlockRecord_2,
  750. //'LoginDays'=> ctx()->privateState->LoginDays,
  751. //'skillUnlockRecord' => ctx()->privateState->skillUnlockRecord,
  752. 'heros' => ctx()->heros,
  753. 'privateState' => ctx()->privateState,
  754. );
  755. return Resp::ok($ret);
  756. }
  757. /**
  758. * 装备概率结算
  759. * @param type $equipStr
  760. */
  761. private static function EquipSettle($equipStr) {
  762. StoreProc::DistributeItemsBox($itemId);
  763. }
  764. // <editor-fold defaultstate="collapsed" desc="功能解锁">
  765. /**
  766. * 检测功能解锁的 关卡
  767. * @param type $resultType
  768. * @param type $gateId
  769. * @return type
  770. */
  771. static function funUnlock_Gate($resultType, $gateId) {
  772. $dic = GameConfig::fun_unlock();
  773. foreach ($dic as $id => $mo) {
  774. if ($mo->unlockTip == 1) {//$mo->unlockGateId == $gateId
  775. $tag = false;
  776. if ($mo->unlockType1 != null) {
  777. //1:参与战斗结束即可 2战斗胜利 3某场战斗参加N次数才行
  778. switch ($mo->unlockType1) {
  779. case Enum_FunUnlockType::battle_Gate:
  780. if ($mo->unlockParas1 == $gateId && ctx()->gates->GateList->$gateId->fightNum == 0) {
  781. $tag = true;
  782. }
  783. break;
  784. case Enum_FunUnlockType::passBattle_Gate:
  785. if ($resultType == true && $mo->unlockParas1 == $gateId && ctx()->gates->GateList->$gateId->pass == 0) {
  786. $tag = true;
  787. }
  788. break;
  789. default:
  790. break;
  791. }
  792. }
  793. if ($mo->unlockType2 != null) {
  794. //1:参与战斗结束即可 2战斗胜利 3某场战斗参加N次数才行
  795. switch ($mo->unlockType2) {
  796. case Enum_FunUnlockType::battle_Gate:
  797. if ($mo->unlockParas2 == $gateId && ctx()->gates->GateList->$gateId->fightNum == 0) {
  798. $tag = true;
  799. }
  800. break;
  801. case Enum_FunUnlockType::passBattle_Gate:
  802. if ($resultType == true && $mo->unlockParas2 == $gateId && ctx()->gates->GateList->$gateId->pass == 0) {
  803. $tag = true;
  804. }
  805. break;
  806. default:
  807. break;
  808. }
  809. }
  810. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  811. ctx()->privateData(true)->funUnlockRecord[] = $id;
  812. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  813. if ($id == 13 || $id == 16 || $id == 14) {
  814. self::unlockGuideType($id);
  815. //ctx()->privateData(true)->funUnlockRecord_3[] =
  816. }
  817. self::SubFunDateInit_FunUnlock($id);
  818. }
  819. }
  820. }
  821. }
  822. public static function unlockGuideType($id) {
  823. GuideProc::Qingling_EquipWear_Guide_Trigger($id);
  824. // $type = 0;
  825. // switch ($id) {
  826. // case 16://启灵
  827. // $type = E_GuideTypeState::Qingling_Guide;
  828. // break;
  829. // case 14://装备 首次获得装备 装备功能解锁 同时开启装备穿戴引导
  830. // $type = E_GuideTypeState::EquipWear_Guide;
  831. // break;
  832. // default:
  833. // break;
  834. // }
  835. //
  836. // if($type >0 && !in_array($type,ctx()->privateData(true)->funUnlockRecord_3)){
  837. // ctx()->privateData(true)->funUnlockRecord_3[] = $type;
  838. // }
  839. //return $type;
  840. }
  841. /**
  842. * 初次得到装备 功能解锁
  843. */
  844. static function funUnlock_equip_firstTime() {
  845. $dic = GameConfig::fun_unlock();
  846. foreach ($dic as $id => $mo) {
  847. $tag = false;
  848. if ($mo->unlockTip == 1) {//$mo->unlockGateId == $gateId
  849. if ($mo->unlockType1 != null && $mo->unlockType1 == Enum_FunUnlockType::equip_firstTime && count(StlUtil::dictToArray(ctx()->store->equip)) == 0) {
  850. $tag = true;
  851. }
  852. if ($mo->unlockType2 != null && $mo->unlockType2 == Enum_FunUnlockType::equip_firstTime && count(StlUtil::dictToArray(ctx()->store->equip)) == 0) {
  853. $tag = true;
  854. }
  855. }
  856. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  857. ctx()->privateData(true)->funUnlockRecord[] = $id;
  858. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  859. if ($id == 13 || $id == 16 || $id == 14) {
  860. self::unlockGuideType($id);
  861. //ctx()->privateData(true)->funUnlockRecord_3[] =
  862. }
  863. self::SubFunDateInit_FunUnlock($id);
  864. }
  865. }
  866. }
  867. /**
  868. * 玩家等级要求 功能解锁
  869. */
  870. static function funUnlock_userLv($level) {
  871. $dic = GameConfig::fun_unlock();
  872. foreach ($dic as $id => $mo) {
  873. $tag = false;
  874. if ($mo->unlockTip == 1) {//$mo->unlockGateId == $gateId
  875. if ($mo->unlockType1 != null && $mo->unlockType1 == Enum_FunUnlockType::userLv && $mo->unlockParas1 == $level) {
  876. $tag = true;
  877. }
  878. if ($mo->unlockType2 != null && $mo->unlockType2 == Enum_FunUnlockType::userLv && $mo->unlockParas2 == $level) {
  879. $tag = true;
  880. }
  881. }
  882. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  883. ctx()->privateData(true)->funUnlockRecord[] = $id;
  884. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  885. if ($id == 13 || $id == 16 || $id == 14) {
  886. self::unlockGuideType($id);
  887. //ctx()->privateData(true)->funUnlockRecord_3[] = self::unlockGuideType($id);
  888. }
  889. self::SubFunDateInit_FunUnlock($id);
  890. }
  891. }
  892. }
  893. /**
  894. * 主线挑战 功能解锁
  895. */
  896. static function funUnlock_mainChallengeGate_State($result, $gateId, $state) {
  897. $dic = GameConfig::fun_unlock();
  898. foreach ($dic as $id => $mo) {
  899. $tag = false;
  900. if ($mo->unlockTip == 1) {//$mo->unlockGateId == $gateId
  901. if ($mo->unlockType1 != null && $result = true && $mo->unlockType1 == Enum_FunUnlockType::mainChallengeGate_State) {
  902. $str = explode(',', $mo->unlockParas1);
  903. $uGateId = $str[0];
  904. $gateState = $str[1];
  905. if ($uGateId == $gateId && StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId) && ctx()->gates->GateList->$gateId->tz_state == $gateState - 1) {
  906. $tag = true;
  907. }
  908. }
  909. if ($mo->unlockType2 != null && $result = true && $mo->unlockType2 == Enum_FunUnlockType::mainChallengeGate_State) {
  910. $str = explode(',', $mo->unlockParas2);
  911. $uGateId = $str[0];
  912. $gateState = $str[1];
  913. if ($uGateId == $gateId && StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId) && ctx()->gates->GateList->$gateId->tz_state == $gateState - 1) {
  914. $tag = true;
  915. }
  916. }
  917. }
  918. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  919. ctx()->privateData(true)->funUnlockRecord[] = $id;
  920. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  921. if ($id == 13 || $id == 16 || $id == 14) {
  922. self::unlockGuideType($id);
  923. //ctx()->privateData(true)->funUnlockRecord_3[] = self::unlockGuideType($id);
  924. }
  925. self::SubFunDateInit_FunUnlock($id);
  926. }
  927. }
  928. }
  929. /**
  930. * 查看某功能是否解锁
  931. * @param type $id
  932. */
  933. static function isFunUnlock($id) {
  934. $funMo = GameConfig::fun_unlock_getItem($id);
  935. if ($funMo->unlockType1 != null && self::unlockCondition($funMo->unlockType1, $funMo->unlockParas1)) {
  936. return true;
  937. }
  938. if ($funMo->unlockType2 != null && self::unlockCondition($funMo->unlockType2, $funMo->unlockParas2)) {
  939. return true;
  940. }
  941. return false;
  942. }
  943. /**
  944. * 解锁条件id
  945. * @param type $conditionId
  946. */
  947. static function unlockCondition($conditionId, $paras) {
  948. $funUnlock = false;
  949. switch ($conditionId) {
  950. case Enum_FunUnlockType::battle_Gate:
  951. $gateId = $paras;
  952. if (ctx()->gates->GateList->$gateId->fightNum > 0) {
  953. $funUnlock = true;
  954. }
  955. break;
  956. case Enum_FunUnlockType::passBattle_Gate:
  957. $gateId = $paras;
  958. if (ctx()->gates->GateList->$gateId->pass >= 1) {
  959. $funUnlock = true;
  960. }
  961. break;
  962. case Enum_FunUnlockType::equip_firstTime:
  963. if (ctx()->store->equip != null) {
  964. $funUnlock = true;
  965. }
  966. break;
  967. case Enum_FunUnlockType::userLv:
  968. if (ctx()->baseInfo->level >= $paras) {
  969. $funUnlock = true;
  970. }
  971. break;
  972. case Enum_FunUnlockType::mainChallengeGate_State:
  973. $str = explode(',', $paras);
  974. $uGateId = $str[0];
  975. $gateState = $str[1];
  976. if (StlUtil::dictHasProperty(ctx()->gates->GateList, $uGateId) && ctx()->gates->GateList->$uGateId->tz_state >= $gateState) {
  977. $funUnlock = true;
  978. }
  979. break;
  980. default:
  981. break;
  982. }
  983. return $funUnlock;
  984. }
  985. /**
  986. * 次级功能解锁数据初始化
  987. */
  988. static function SubFunDateInit_FunUnlock($type) {
  989. $dic = GameConfig::subfun_unlock();
  990. foreach ($dic as $id => $mo) {
  991. if ($mo->funTypeId != $type) {
  992. continue;
  993. }
  994. if ($mo->funTypeId == 6 && $mo->id == Enum_SubFunType::Day7_Happy) {
  995. TaskProc::Day7TaskReset();
  996. }
  997. if ($mo->funTypeId == 5 && $mo->id == Enum_SubFunType::DailyTask) {
  998. TaskProc::DailyTaskReset(true);
  999. }
  1000. if ($mo->funTypeId == 5 && $mo->id == Enum_SubFunType::WeekTask) {
  1001. TaskProc::WeekTaskReset(true);
  1002. }
  1003. if ($mo->funTypeId == 5 && $mo->id == Enum_SubFunType::Day7_Sign) {
  1004. ActiveProc::DailyResetDay7Task(true);
  1005. }
  1006. if ($mo->funTypeId == 21 && $mo->id == Enum_SubFunType::Day7_Sign_NewPlayer) {
  1007. ActiveProc::InitDay7_Sign_NewPlayer(true);
  1008. ctx()->privateState->day7_drawed_newPlayer_startTs = now();
  1009. }
  1010. }
  1011. }
  1012. /**
  1013. * 次级功能解锁数据初始化
  1014. */
  1015. static function SubFunDateInit_Config() {
  1016. $dic = GameConfig::subfun_unlock();
  1017. foreach ($dic as $id => $mo) {
  1018. if ($mo->type == 3 && $mo->id == Enum_SubFunType::LimitTsSale && ctx()->privateState->nextDayLogin == 0 && now() >= $mo->startTs) {
  1019. ActiveProc::ResetLimitTsBuy();
  1020. }
  1021. if ($mo->type == 3 && $mo->id == Enum_SubFunType::ActivePoint_BattlePass && ctx()->privateState->battlePass_activePoint_refersh_ts == 0 && now() >= $mo->startTs) {
  1022. ctx()->privateState->battlePass_activePoint_refersh_ts = TimeUtil::getNextDayTs($mo->startTs, $mo->ts);
  1023. ctx()->privateData(true)->battlePass_activePoint_cost_ts = 0;
  1024. ctx()->privateData(true)->battlePass_taskPoint = 0;
  1025. ActiveProc::ResetBattlePassReward(Enum_SubFunType::ActivePoint_BattlePass);
  1026. }
  1027. if ($mo->type == 3 && $mo->id == Enum_SubFunType::Tili_BattleBass && ctx()->privateState->battlePass_tili_refersh_ts == 0 && now() >= $mo->startTs) {
  1028. ctx()->privateState->battlePass_tili_refersh_ts = TimeUtil::getNextDayTs($mo->startTs, $mo->ts);
  1029. ctx()->privateData(true)->battlePass_tili_cost_ts = 0;
  1030. ctx()->privateData(true)->battlePass_tili = 0;
  1031. ActiveProc::ResetBattlePassReward(Enum_SubFunType::Tili_BattleBass);
  1032. }
  1033. }
  1034. }
  1035. // </editor-fold>
  1036. // <editor-fold defaultstate="collapsed" desc="技能解锁">
  1037. /**
  1038. * 检测技能解锁的 1 关卡解锁,游玩到一定关卡解锁技能
  1039. * @param type $resultType
  1040. * @param type $gateId
  1041. * @return type
  1042. */
  1043. static function skillUnlock_gate($resultType, $gateId) {
  1044. $dic = GameConfig::skills();
  1045. $gateIndex = Ins_GateInfo::gateNum($gateId);
  1046. foreach ($dic as $id => $mo) {
  1047. if ($mo->unlock_acc_id_new == null) {
  1048. continue;
  1049. }
  1050. $strList = explode(':', $mo->unlock_acc_id_new);
  1051. $unlockType = $strList[0];
  1052. $unlockId = $strList[1];
  1053. if ($unlockType == 1 && $unlockId == $gateIndex && $resultType == true && ctx()->gates->GateList->$gateId->pass == 0 && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1054. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1055. }
  1056. }
  1057. }
  1058. /**
  1059. * 检测技能解锁的 2://皮肤解锁,获取到人物解锁后对应皮肤技能
  1060. * @param type $resultType
  1061. * @param type $gateId
  1062. * @return type
  1063. */
  1064. static function skillUnlock_heroUnlock($heroId) {
  1065. $dic = GameConfig::skills();
  1066. foreach ($dic as $id => $mo) {
  1067. if ($mo->unlock_acc_id_new == null) {
  1068. continue;
  1069. }
  1070. $strList = explode(':', $mo->unlock_acc_id_new);
  1071. $unlockType = $strList[0];
  1072. $unlockId = $strList[1];
  1073. if ($unlockType != 2) {
  1074. continue;
  1075. }
  1076. $heroMo = GameConfig::hero_getItem($heroId);
  1077. $heroTypeId = $heroMo->typeID;
  1078. $isUnlock = ctx()->heros->Dic->$heroId->isUnlock;
  1079. if ($unlockId == $heroTypeId && $isUnlock == 0 && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1080. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1081. }
  1082. }
  1083. }
  1084. /**
  1085. * 检测技能解锁的 3://玩家失败X次后解锁
  1086. * @param type $resultType
  1087. * @param type $gateId
  1088. * @return type
  1089. */
  1090. static function skillUnlock_fightNum($resultType) {
  1091. if ($resultType) {
  1092. return;
  1093. }
  1094. $GateList = ctx()->gates->GateList;
  1095. $num = 0;
  1096. foreach ($GateList as $gateId => $Ins_GateInfo) {
  1097. $num += $Ins_GateInfo->fightNum_fail;
  1098. }
  1099. $dic = GameConfig::skills();
  1100. foreach ($dic as $id => $mo) {
  1101. if ($mo->unlock_acc_id_new == null) {
  1102. continue;
  1103. }
  1104. $strList = explode(':', $mo->unlock_acc_id_new);
  1105. $unlockType = $strList[0];
  1106. $unlockId = $strList[1];
  1107. if ($unlockType != 3) {
  1108. continue;
  1109. }
  1110. if ($num == $unlockId && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1111. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1112. }
  1113. }
  1114. }
  1115. /**
  1116. * 玩家等级解锁技能
  1117. * @param type $curLevel
  1118. */
  1119. static function skillUnlock_userLevel($curLevel) {
  1120. $dic = GameConfig::skills();
  1121. foreach ($dic as $id => $mo) {
  1122. if ($mo->unlock_acc_id_new == null) {
  1123. continue;
  1124. }
  1125. $strList = explode(':', $mo->unlock_acc_id_new);
  1126. $unlockType = $strList[0];
  1127. $unlockId = $strList[1];
  1128. if ($unlockType != 5) { // 玩家等级
  1129. continue;
  1130. }
  1131. if ($unlockId == $curLevel && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1132. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1133. }
  1134. }
  1135. }
  1136. // </editor-fold>
  1137. // <editor-fold defaultstate="collapsed" desc="排行榜">
  1138. /**
  1139. * 参与主线关卡排行榜
  1140. * @param type $gateIndex
  1141. */
  1142. public static function Ranking_MainGateIndex($maxGateIndex) {
  1143. $memKey = MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid);
  1144. $mem = gMem();
  1145. $uid = req()->uid;
  1146. $score = self::GetRankScoreUid($uid, 1);
  1147. if ($maxGateIndex > $score) {
  1148. $arr = array();
  1149. $arr["$uid"] = self::createScore($maxGateIndex);
  1150. $mem->zadd($memKey, $arr);
  1151. }
  1152. $length = $mem->zlen($memKey);
  1153. if ($length > glc()->Rank_MainGateIndex_OnListRank) {
  1154. $num = $length - glc()->Rank_MainGateIndex_OnListRank;
  1155. $mem->zremrangebyrank($memKey, 0, $num - 1);
  1156. }
  1157. }
  1158. public static function createScore($score) {
  1159. if ($score > 0) {
  1160. $newScore = $score . '.' . (9999999999 - now());
  1161. return $newScore;
  1162. }
  1163. return 0;
  1164. }
  1165. /**
  1166. * 战力榜
  1167. * @param type $gateIndex
  1168. */
  1169. public static function Ranking_FightPower() {
  1170. $memKey = MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid);
  1171. $mem = gMem();
  1172. $uid = req()->uid;
  1173. $score = self::GetRankScoreUid($uid, 2);
  1174. //$power = self::countUserFightPower();
  1175. $power = FightPower_Calculate::GetFightPower();
  1176. $arr = array();
  1177. $arr["$uid"] = self::createScore($power);
  1178. $mem->zadd($memKey, $arr);
  1179. if ($power >= $score) {
  1180. self::IsAchievedFightPower_PassReward($power);
  1181. }
  1182. $length = $mem->zlen($memKey);
  1183. if ($length > glc()->Rank_FightPower_OnListRank) {
  1184. $num = $length - glc()->Rank_FightPower_OnListRank;
  1185. $mem->zremrangebyrank($memKey, 0, $num - 1);
  1186. }
  1187. }
  1188. public static function GetRankScoreUid($uid_rank, $type) {
  1189. if ($type == 1) {
  1190. $score = gMem()->zscore(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid_rank);
  1191. } else {
  1192. $score = gMem()->zscore(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid_rank);
  1193. }
  1194. if ($score == null) {
  1195. $score = 0;
  1196. }
  1197. return intval($score);
  1198. }
  1199. /**
  1200. * 6811 获取主线关卡排行榜信息
  1201. * @return type
  1202. */
  1203. public static function GetRankInfo() {
  1204. list($type) = req()->paras;
  1205. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  1206. $selfExtraInfo = 0;
  1207. $isExistFinishReward = 0;
  1208. $isExistFinishReward_other = 0;
  1209. if ($type == 1) {
  1210. $list = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  1211. $selfExtraInfo = ctx()->gates->maxPassGateNumId();
  1212. $isExistFinishReward = self::isExistNoDrawed_MainGate();
  1213. $isExistFinishReward_other = self::isExistNoDrawed_FightPower();
  1214. } else {
  1215. $list = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  1216. //$selfExtraInfo = self::countUserFightPower();
  1217. $selfExtraInfo = FightPower_Calculate::GetFightPower();
  1218. $isExistFinishReward = self::isExistNoDrawed_FightPower();
  1219. $isExistFinishReward_other = self::isExistNoDrawed_MainGate();
  1220. }
  1221. if ($isExistFinishReward == 1) {
  1222. $isExistFinishReward = true;
  1223. } else {
  1224. $isExistFinishReward = false;
  1225. }
  1226. if ($isExistFinishReward_other == 1) {
  1227. $isExistFinishReward_other = true;
  1228. } else {
  1229. $isExistFinishReward_other = false;
  1230. }
  1231. $selfRank = null;
  1232. $retArr = array();
  1233. if (count($list) > 0) {
  1234. foreach ($list as $uid => $score) {
  1235. $rankInfo = self::initOtherUidRankInfo($uid, $score, $type);
  1236. if ($rankInfo->uid == req()->uid) {
  1237. $selfIsHasRank = 1;
  1238. $selfRank = $rankInfo;
  1239. }
  1240. $retArr[] = $rankInfo;
  1241. }
  1242. }
  1243. if ($selfRank == null) {
  1244. $selfRank = self::initOtherUidRankInfo(req()->uid, $selfExtraInfo, $type);
  1245. }
  1246. UserProc::updateUserInfo();
  1247. $ret = array(
  1248. 'rankInfo' => $retArr,
  1249. 'selfRank' => $selfRank,
  1250. 'selfIsHasRank' => $selfIsHasRank,
  1251. 'isExistFinishReward' => $isExistFinishReward,
  1252. 'isExistFinishReward_other' => $isExistFinishReward_other,
  1253. );
  1254. return Resp::ok($ret);
  1255. }
  1256. /**
  1257. * 初始化玩家rank
  1258. * @param type $uid
  1259. * @param type $score
  1260. * @return \loyalsoft\Ins_rank
  1261. */
  1262. static function initOtherUidRankInfo($uid, $score, $type = null) {
  1263. $ins_rank = new Ins_rank();
  1264. if ($type == 1) {
  1265. $lv = gMem()->zrevrank(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  1266. } else if ($type == 2) {
  1267. $lv = gMem()->zrevrank(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
  1268. } elseif ($type == 3) {
  1269. $memKey = self::GetWorldBoss_DamageMemKey();
  1270. $lv = gMem()->zrevrank($memKey, $uid);
  1271. }
  1272. if ($lv === null) {
  1273. $lv = -1;
  1274. }
  1275. $ins_rank->rank = $lv + 1;
  1276. $ins_rank->uid = $uid;
  1277. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  1278. $ins_rank->name = $userInfo->baseInfo->name;
  1279. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  1280. $ins_rank->score = intval($score);
  1281. return $ins_rank;
  1282. }
  1283. /**
  1284. * 6812 获取排行榜内玩家的装备信息
  1285. * @return type
  1286. */
  1287. public static function GetUidEquipInfo_Rank() {
  1288. list($uid) = req()->paras;
  1289. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  1290. $store = $userInfo->store;
  1291. $heros = $userInfo->heros;
  1292. $gates = $userInfo->gates;
  1293. UserProc::updateUserInfo();
  1294. $ret = array(
  1295. 'store' => $store,
  1296. 'heros' => $heros,
  1297. 'gates' => $gates,
  1298. );
  1299. return Resp::ok($ret);
  1300. }
  1301. /**
  1302. * 通关奖励是否达成
  1303. * @param type $maxGateIndex
  1304. */
  1305. public static function IsAchievedMainGate_PassReward($maxGateIndex) {
  1306. $rewards = GameConfig::rank_passgatereward();
  1307. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1308. foreach ($rewards as $passGateId => $mo) {
  1309. if ($passGateId == $maxGateIndex && !gMem()->hexists($memKey, $maxGateIndex)) {
  1310. $ins_rank = new Ins_rank();
  1311. $ins_rank->uid = req()->uid;
  1312. $ins_rank->name = ctx()->baseInfo->name;
  1313. $ins_rank->headImg = ctx()->baseInfo->headImg;
  1314. $ins_rank->score = $passGateId;
  1315. gMem()->hset($memKey, $maxGateIndex, $ins_rank);
  1316. break;
  1317. }
  1318. }
  1319. }
  1320. /*
  1321. * 战力奖励是否达成
  1322. */
  1323. public static function IsAchievedFightPower_PassReward($power) {
  1324. $rewards = GameConfig::rank_fightpowerreward();
  1325. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1326. foreach ($rewards as $fightPower => $mo) {
  1327. if ($power >= $fightPower && !gMem()->hexists($memKey, $fightPower)) {
  1328. $ins_rank = new Ins_rank();
  1329. $ins_rank->uid = req()->uid;
  1330. $ins_rank->name = ctx()->baseInfo->name;
  1331. $ins_rank->headImg = ctx()->baseInfo->headImg;
  1332. $ins_rank->score = $fightPower;
  1333. gMem()->hset($memKey, $fightPower, $ins_rank);
  1334. }
  1335. }
  1336. }
  1337. public static function isExistNoDrawed_MainGate() {
  1338. $isExistFinishReward = 0;
  1339. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1340. $dic = gMem()->hgetall($memKey);
  1341. foreach ($dic as $gateId => $ins_rank) {
  1342. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  1343. $isExistFinishReward = 1;
  1344. break;
  1345. }
  1346. }
  1347. ctx()->privateData(true)->redTip_RewardMainGateRank = $isExistFinishReward;
  1348. return $isExistFinishReward;
  1349. }
  1350. public static function isExistNoDrawed_FightPower() {
  1351. $isExistFinishReward = 0;
  1352. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1353. $dic = gMem()->hgetall($memKey);
  1354. foreach ($dic as $fightPower => $ins_rank) {
  1355. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1356. $isExistFinishReward = 1;
  1357. break;
  1358. }
  1359. }
  1360. ctx()->privateData(true)->redTip_RewardFightPowerRank = $isExistFinishReward;
  1361. return $isExistFinishReward;
  1362. }
  1363. /**
  1364. * 6813
  1365. * @return type
  1366. */
  1367. public static function GetmainGate_RankRewardInfo() {
  1368. //list($type) = req()->paras;
  1369. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1370. $dic = gMem()->hgetall($memKey);
  1371. if ($dic == null) {
  1372. $dic = new \stdClass();
  1373. }
  1374. UserProc::updateUserInfo();
  1375. $ret = array(
  1376. 'rankReward' => $dic,
  1377. );
  1378. return Resp::ok($ret);
  1379. }
  1380. /**
  1381. * 6814
  1382. * @return type
  1383. */
  1384. public static function GetFightPower_RankRewardInfo() {
  1385. //list($type) = req()->paras;
  1386. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1387. $dic = gMem()->hgetall($memKey);
  1388. if ($dic == null) {
  1389. $dic = new \stdClass();
  1390. }
  1391. UserProc::updateUserInfo();
  1392. $ret = array(
  1393. 'rankReward' => $dic,
  1394. );
  1395. return Resp::ok($ret);
  1396. }
  1397. /**
  1398. * 6815 领取通关荣誉榜奖励
  1399. * @return type
  1400. */
  1401. public static function ReceiveRankReward_MainGate() {
  1402. list($gateId) = req()->paras;
  1403. my_Assert(!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate), ErrCode::rankReward_HasReceive);
  1404. $mo = GameConfig::rank_passgatereward_getItem($gateId);
  1405. my_Assert($mo != null, ErrCode::err_const_no);
  1406. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1407. if (gMem()->hexists($memKey, $gateId)) {
  1408. StoreProc::AddMultiItemInStore($mo->reward);
  1409. ctx()->privateData(true)->rankReward_drawed_MainGate[] = $gateId;
  1410. TaskProc::OnRankPrize_Num();
  1411. }
  1412. $tag = self::isExistNoDrawed_MainGate();
  1413. UserProc::updateUserInfo();
  1414. $ret = array('redTip' => $tag, 'task' => ctx()->task, 'store' => ctx()->store, 'cash' => ctx()->baseInfo->cash, 'reward' => StoreProc::$reward);
  1415. return Resp::ok($ret);
  1416. }
  1417. /**
  1418. * 6816 领取战力荣誉榜奖励
  1419. * @return type
  1420. */
  1421. public static function ReceiveRankReward_FightPower() {
  1422. list($fightPower) = req()->paras;
  1423. my_Assert(!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower), ErrCode::rankReward_HasReceive);
  1424. $mo = GameConfig::rank_fightpowerreward_getItem($fightPower);
  1425. my_Assert($mo != null, ErrCode::err_const_no);
  1426. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1427. if (gMem()->hexists($memKey, $fightPower)) {
  1428. StoreProc::AddMultiItemInStore($mo->reward);
  1429. ctx()->privateData(true)->rankReward_drawed_fightPower[] = $fightPower;
  1430. TaskProc::OnFightRankPrize_Num();
  1431. }
  1432. $tag = self::isExistNoDrawed_FightPower();
  1433. UserProc::updateUserInfo();
  1434. $ret = array('redTip' => $tag, 'task' => ctx()->task, 'store' => ctx()->store, 'cash' => ctx()->baseInfo->cash, 'reward' => StoreProc::$reward);
  1435. return Resp::ok($ret);
  1436. }
  1437. /**
  1438. * 6824 排行奖励一键领取
  1439. */
  1440. static function ReceiveRankReward() {
  1441. list($type) = req()->paras; # 解锁数量
  1442. if ($type == 1) {
  1443. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1444. $dic = gMem()->hgetall($memKey);
  1445. foreach ($dic as $gateId => $ins_rank) {
  1446. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  1447. $mo = GameConfig::rank_passgatereward_getItem($gateId);
  1448. StoreProc::AddMultiItemInStore($mo->reward);
  1449. ctx()->privateData(true)->rankReward_drawed_MainGate[] = $gateId;
  1450. TaskProc::OnRankPrize_Num();
  1451. }
  1452. }
  1453. } else {
  1454. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1455. $dic2 = gMem()->hgetall($memKey2);
  1456. foreach ($dic2 as $fightPower => $ins_rank) {
  1457. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1458. $mo = GameConfig::rank_fightpowerreward_getItem($fightPower);
  1459. StoreProc::AddMultiItemInStore($mo->reward);
  1460. ctx()->privateData(true)->rankReward_drawed_fightPower[] = $fightPower;
  1461. TaskProc::OnFightRankPrize_Num();
  1462. }
  1463. }
  1464. }
  1465. UserProc::updateUserInfo();
  1466. $ret = array('redTip' => 0,
  1467. 'task' => ctx()->task,
  1468. 'store' => ctx()->store,
  1469. 'cash' => ctx()->baseInfo->cash,
  1470. 'reward' => StoreProc::$reward,
  1471. 'rankReward_drawed_fightPower' => ctx()->privateState->rankReward_drawed_fightPower,
  1472. 'rankReward_drawed_MainGate' => ctx()->privateState->rankReward_drawed_MainGate,
  1473. );
  1474. return Resp::ok($ret);
  1475. }
  1476. /**
  1477. * 6817
  1478. */
  1479. public static function IsExistRankReward() {
  1480. //list($type) = req()->paras;
  1481. $type = 0;
  1482. $isExistFinishReward = false;
  1483. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1484. $dic = gMem()->hgetall($memKey);
  1485. foreach ($dic as $gateId => $ins_rank) {
  1486. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  1487. $isExistFinishReward = true;
  1488. $type = 1;
  1489. break;
  1490. }
  1491. }
  1492. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1493. $dic2 = gMem()->hgetall($memKey2);
  1494. foreach ($dic2 as $fightPower => $ins_rank) {
  1495. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1496. $isExistFinishReward = true;
  1497. $type = 2;
  1498. break;
  1499. }
  1500. }
  1501. UserProc::updateUserInfo();
  1502. $ret = array(
  1503. 'isExistFinishReward' => $isExistFinishReward,
  1504. 'type' => $type,
  1505. );
  1506. return Resp::ok($ret);
  1507. }
  1508. /*
  1509. * 删除排行榜内注销账号的玩家
  1510. */
  1511. public static function DeleteRankInvalidUser($uid2) {
  1512. $dic1 = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  1513. foreach ($dic1 as $uid => $score) {
  1514. if ($uid == $uid2) {
  1515. gMem()->zrem(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  1516. break;
  1517. }
  1518. }
  1519. $dic2 = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  1520. foreach ($dic2 as $uid => $score) {
  1521. if ($uid == $uid2) {
  1522. gMem()->zrem(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
  1523. break;
  1524. }
  1525. }
  1526. self::DeleteWorldBossRankInvalidUser($uid2);
  1527. }
  1528. /*
  1529. * 删除世界boss排行榜内注销账号的玩家
  1530. */
  1531. public static function DeleteWorldBossRankInvalidUser($uid2) {
  1532. $rankKey = self::GetWorldBoss_DamageMemKey();
  1533. $score = gMem()->zscore($rankKey, $uid2);
  1534. if($score > 0){
  1535. gMem()->zrem($rankKey, $uid2);
  1536. }
  1537. }
  1538. /*
  1539. * 排行玩家修改昵称
  1540. */
  1541. public static function UpdateRankUserName($uid, $newName) {
  1542. $memKey1 = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1543. $dic = gMem()->hgetall($memKey1);
  1544. foreach ($dic as $gateId => $ins_rank) {
  1545. if ($ins_rank->uid == $uid) {
  1546. $ins_rank->name = $newName;
  1547. gMem()->hset($memKey1, $gateId, $ins_rank);
  1548. }
  1549. }
  1550. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1551. $dic2 = gMem()->hgetall($memKey2);
  1552. foreach ($dic2 as $fightPower => $ins_rank) {
  1553. if ($ins_rank->uid == $uid) {
  1554. $ins_rank->name = $newName;
  1555. gMem()->hset($memKey2, $fightPower, $ins_rank);
  1556. }
  1557. }
  1558. }
  1559. /*
  1560. * 排行玩家头像变动
  1561. */
  1562. public static function UpdateRankUserHeadImg($uid, $headImg) {
  1563. $memKey1 = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1564. $dic = gMem()->hgetall($memKey1);
  1565. foreach ($dic as $gateId => $ins_rank) {
  1566. if ($ins_rank->uid == $uid) {
  1567. $ins_rank->headImg = $headImg;
  1568. gMem()->hset($memKey1, $gateId, $ins_rank);
  1569. }
  1570. }
  1571. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1572. $dic2 = gMem()->hgetall($memKey2);
  1573. foreach ($dic2 as $fightPower => $ins_rank) {
  1574. if ($ins_rank->uid == $uid) {
  1575. $ins_rank->headImg = $headImg;
  1576. gMem()->hset($memKey2, $fightPower, $ins_rank);
  1577. }
  1578. }
  1579. }
  1580. /*
  1581. * 统计战力 战斗力=攻击x(生命-伤害减免值)x(1+暴击率/100x(暴击伤害倍率-1))改为 //战斗力=攻击x(生命-伤害减免值)x(1+暴击率 x(暴击伤害倍率-1))2024-8-30
  1582. */
  1583. public static function countUserFightPower() {
  1584. $CurrentHeroId = ctx()->heros->CurrentHeroId;
  1585. //$hero = ctx()->heros->Dic->$CurrentHeroId;
  1586. list($addHp, $addAtk, $addDecDamage, $addEatFood) = ctx()->gates()->GetEnvovleBuffs(); // 启灵加成
  1587. $mo = GameConfig::hero_getItem($CurrentHeroId);
  1588. my_Assert($mo != null, ErrCode::err_const_no);
  1589. $heroBashAttack = $mo->attack;
  1590. $heroBashHp = $mo->hp;
  1591. $attck = 0;
  1592. $hp = 0;
  1593. $equipDic = ctx()->store->equipLocation;
  1594. foreach ($equipDic as $index => $equipUid) {
  1595. $ins_Equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  1596. if ($ins_Equip->mo()->position % 2 == 1) {
  1597. $attck += GameConfig::equip_levelupgrade_getItem($ins_Equip->mo()->rarity, $ins_Equip->qual, $ins_Equip->mo()->position, $ins_Equip->level)->attckNum;
  1598. } elseif ($ins_Equip->mo()->position % 2 == 0) {
  1599. $hp += GameConfig::equip_levelupgrade_getItem($ins_Equip->mo()->rarity, $ins_Equip->qual, $ins_Equip->mo()->position, $ins_Equip->level)->hpNum;
  1600. }
  1601. }
  1602. // $equipDic = ctx()->store->equipPosition;
  1603. // $attck = 0;
  1604. // $hp = 0;
  1605. // foreach ($equipDic as $index => $ins_equip) {
  1606. // $Ins_Equip = new Ins_EquipPosition($ins_equip);
  1607. // if ($Ins_Equip->mo()->upgradeType == 1) {//攻击力
  1608. // $attck += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->attckNum;
  1609. // } elseif ($Ins_Equip->mo()->upgradeType == 2) {
  1610. // $hp += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->hpNum;
  1611. // } else {
  1612. // $attck += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->attckNum;
  1613. // $hp += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->hpNum;
  1614. // }
  1615. // }
  1616. $heroAttck = $heroBashAttack + $attck + $addAtk; # 英雄基础攻击力+装备宝石词条攻击力+启灵攻击力
  1617. $heroHp = $heroBashHp + $hp + $addHp; # 英雄基础hp + 装备宝石词条hp + 启灵hp
  1618. $pag = ctx()->store->equipPag;
  1619. $gemDic = ctx()->store->gemEquip->$pag; //Dictionary<E_EquipPosition, Dictionary<int, Ins_Gem>>
  1620. $per = 0;
  1621. $parasVal = 0;
  1622. $per_hp = 0;
  1623. $parasVal_hp = 0;
  1624. foreach ($equipDic as $index => $ins_equip) {
  1625. if (StlUtil::dictHasProperty($gemDic, $index)) {
  1626. $dic = $gemDic->$index;
  1627. foreach ($dic as $k => $gem) {
  1628. $ins_Gem = new Ins_Gem($gem);
  1629. if ($ins_Gem->predicateMo()->actionType == "mulDamage") {
  1630. $per += $ins_Gem->predicateMo()->actionParam1;
  1631. } elseif ($ins_Gem->predicateMo()->actionType == "addDamage") {
  1632. $parasVal += $ins_Gem->predicateMo()->actionParam1;
  1633. } elseif ($ins_Gem->predicateMo()->actionType == "mulHp") {
  1634. $per_hp += $ins_Gem->predicateMo()->actionParam1;
  1635. } elseif ($ins_Gem->predicateMo()->actionType == "addHp") {
  1636. $parasVal_hp += $ins_Gem->predicateMo()->actionParam1;
  1637. }
  1638. }
  1639. }
  1640. }
  1641. if ($per != 0) {
  1642. $heroAttck = round($heroAttck + $heroAttck * $per);
  1643. }
  1644. if ($parasVal != 0) {
  1645. $heroAttck += $parasVal;
  1646. }
  1647. if ($per_hp != 0) {
  1648. $heroHp = round($heroHp + $heroHp * $per_hp);
  1649. }
  1650. if ($parasVal_hp != 0) {
  1651. $heroHp += $parasVal_hp;
  1652. }
  1653. $dec_demage = $mo->dec_demage + $addDecDamage; # 英雄基础减伤 + 启灵减伤
  1654. $bigHit_Val = $mo->bigHit_Val;
  1655. $bigHit_rate = $mo->bigHit_rate;
  1656. $val = $heroAttck * ($heroHp - $dec_demage) * (1 + $bigHit_rate * ($bigHit_Val - 1));
  1657. return intval($val);
  1658. }
  1659. // </editor-fold>
  1660. // <editor-fold defaultstate="collapsed" desc=" 世界boss 排行榜">
  1661. /**
  1662. * 结算世界boss排行奖励[定时发放奖励接口]
  1663. */
  1664. public static function triggerSettleRankReward_worldBoss() {
  1665. //校验下是否处在发放奖励信息的时间点 【每个轮次最后一天的最后10分钟】
  1666. $mo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::WorldBoss);
  1667. if ($mo == null) {
  1668. return;
  1669. }
  1670. if (now() < $mo->startTs) {
  1671. return;
  1672. }
  1673. echo '----发放世界boss的排行奖励程序开始运行-----';
  1674. $curDay = TimeUtil::totalDays();
  1675. $turnNum = self::GetCurTurnNum();
  1676. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  1677. if ($turnnumMo != null) {
  1678. $lastDay = TimeUtil::totalDays($turnnumMo->endTs);
  1679. if ($curDay == $lastDay && $turnnumMo->endTs - now() < 600) {
  1680. $damageMemKey = self::GetWorldBoss_DamageMemKey();
  1681. echo '发放奖励的menkey===============:';
  1682. echo "$damageMemKey";
  1683. $mem = gMem();
  1684. if ($mem->exists($damageMemKey)) {
  1685. FightProc::settleRankReward_worldBoss();
  1686. }
  1687. }
  1688. }
  1689. echo '----世界boss的排行奖励-发放完成----';
  1690. }
  1691. public static function settleRankReward_worldBoss() {
  1692. echo '----开始发放世界boss的排行奖励-----';
  1693. $dic = GameConfig::worldboss_rankreward();
  1694. if ($dic == null) {
  1695. return;
  1696. }
  1697. $turnNum = self::GetCurTurnNum();
  1698. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  1699. $orderId = $turnnumMo->orderId;
  1700. $itemMo = GameConfig::item_getItem($turnnumMo->gateId);
  1701. if ($itemMo == null) {
  1702. return;
  1703. }
  1704. $name = $itemMo->name;
  1705. $memKey = self::GetWorldBoss_DamageMemKey();
  1706. $index = 0;
  1707. foreach ($dic as $id => $mo) {
  1708. $list = gMem()->zrevrange($memKey, $mo->rank_start - 1, $mo->rank_end - 1, true);
  1709. if (count($list) == 0) {
  1710. continue;
  1711. }
  1712. foreach ($list as $uid => $score) {
  1713. $index += 1;
  1714. self::settleDamageReward_worldBoss($name,$orderId, $uid, $score);
  1715. EmailProc::SendWorldBossRewardMail(req()->zoneid, $uid, $mo->reward, $index,$name);
  1716. }
  1717. }
  1718. gMem()->delete($memKey);
  1719. // $list = gMem()->zrevrange($memKey, 0, GameConfig::glc2()->WorldBoss_RankRewardStatistics, true);
  1720. // if (count($list) <= 0) {
  1721. //
  1722. // }
  1723. }
  1724. public static function settleDamageReward_worldBoss($name,$orderId, $uid, $demageVal) {
  1725. $demageList = GameConfig::worldboss_demagereward_getItemArray($orderId);
  1726. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  1727. $worldBoss_received = $userInfo->privateState->worldBoss_received;
  1728. $dic = new \stdClass();
  1729. foreach ($demageList as $dMo) {
  1730. if ($demageVal >= $dMo->demageValId && !in_array($dMo->demageValId, $worldBoss_received)) {
  1731. if($dMo->reward != null){
  1732. $list = explode(';', $dMo->reward);
  1733. foreach ($list as $value) {
  1734. $arr = explode(',', $value);
  1735. $rewardId = $arr[0];
  1736. $rewardNum = $arr[1];
  1737. if(StlUtil::dictHasProperty($dic, $rewardId)){
  1738. $dic->$rewardId += $rewardNum;
  1739. } else {
  1740. $dic->$rewardId = $rewardNum;
  1741. }
  1742. }
  1743. }
  1744. }
  1745. }
  1746. $str = '';
  1747. foreach ($dic as $k => $val) {
  1748. $s = $k.','.$val;
  1749. if($str == ''){
  1750. $str = $s;
  1751. } else {
  1752. $str = $str.';'.$s;
  1753. }
  1754. }
  1755. if($str != null){
  1756. EmailProc::SendWorldBossDamageRewardMail(req()->zoneid, $uid,$str,$name);
  1757. }
  1758. }
  1759. /**
  1760. * 重置每个赛季的开始时间 一个重置每个赛季的开始时间赛季完成后 排名数据清理掉 同时轮次要改变 [定时接口]----废弃
  1761. */
  1762. public static function ResetWorldBossRank_StartTs() {
  1763. return;
  1764. // $mo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::WorldBoss);
  1765. // if ($mo == null) {
  1766. // return;
  1767. // }
  1768. // if (now() < $mo->startTs) {
  1769. // return;
  1770. // }
  1771. // echo '赛季的开始时间重置程序开始运行**********';
  1772. // $memKey = MemKey_GameRun::WorldBoss_StartTs(req()->zoneid);
  1773. // $mem = gMem();
  1774. //
  1775. // $ts = $mem->get($memKey);
  1776. // $durationTs = $mo->ts * 24 * 60 * 60;
  1777. // if ($ts == null && now() - $mo->startTs < $durationTs) {
  1778. // $mem->set($memKey, $mo->startTs);
  1779. // $ts = $mo->startTs;
  1780. // }
  1781. //
  1782. // if (now() - $ts > $durationTs) {
  1783. // $nextTs = TimeUtil::getNextDayTs($ts, $mo->ts);
  1784. // $mem->set($memKey, $nextTs); //下一轮赛季的开始时间回存
  1785. // echo '完成重置下一个赛季的开始时间';
  1786. // //清理排行榜
  1787. // self::ClearWorldBossRank();
  1788. // }
  1789. }
  1790. /**
  1791. * 清理世界boss排行榜数据
  1792. */
  1793. public static function ClearWorldBossRank() {
  1794. $mem = gMem();
  1795. $arr = array();
  1796. for ($i = 1; $i <= 9; $i++) {
  1797. $memKey = MemKey_GameRun::WorldBoss_Rank($i, req()->zoneid);
  1798. $arr[] = $memKey;
  1799. }
  1800. $mem->deleteMulti($arr);
  1801. }
  1802. /**
  1803. * 每天登录的时候 检测轮次变化
  1804. */
  1805. public static function ResetTurnNum() {
  1806. if (!FightProc::isFunUnlock(25)) {
  1807. return;
  1808. }
  1809. $subMo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::WorldBoss);
  1810. if (ctx()->privateState->worldBoss_turnNum < 0) {
  1811. ctx()->privateState->worldBoss_turnNum = 0;
  1812. }
  1813. if (now() < $subMo->startTs) {
  1814. return;
  1815. }
  1816. $num = self::GetCurTurnNum();
  1817. if ($num != ctx()->privateState->worldBoss_turnNum) {
  1818. ctx()->privateState->worldBoss_turnNum = $num;
  1819. ctx()->privateState->worldBoss_received = array();
  1820. }
  1821. }
  1822. /**
  1823. * 当前所在世界boss 的轮次 //当前轮次可以算出来
  1824. */
  1825. public static function GetCurTurnNum() {
  1826. $dic = GameConfig::worldboss_turnnum();
  1827. foreach ($dic as $turnId => $mo) {
  1828. if (now() >= $mo->startTs && now() < $mo->endTs) {
  1829. return $turnId;
  1830. }
  1831. }
  1832. return 0;
  1833. // $memKey = MemKey_GameRun::WorldBoss_StartTs(req()->zoneid);
  1834. // $mem = gMem();
  1835. // $ts = $mem->get($memKey);
  1836. //
  1837. // $curDay = TimeUtil::totalDays(now());
  1838. // $lastDay = TimeUtil::totalDays($ts);
  1839. //
  1840. // $val = $curDay - $lastDay;
  1841. // $num = intval($val / 3);
  1842. //
  1843. // return $num + 1;
  1844. }
  1845. /**
  1846. * 世界boss排名榜 memkey
  1847. * @return type
  1848. */
  1849. public static function GetWorldBoss_DamageMemKey() {
  1850. $num = self::GetCurTurnNum();
  1851. $memKey = MemKey_GameRun::WorldBoss_Rank($num, req()->zoneid);
  1852. return $memKey;
  1853. }
  1854. /**
  1855. * 世界boss榜 伤害值入榜
  1856. * @param type $gateIndex
  1857. */
  1858. public static function Ranking_DamageVal($damageVal) {
  1859. //$num = self::GetCurTurnNum();
  1860. $memKey = self::GetWorldBoss_DamageMemKey(); // MemKey_GameRun::WorldBoss_Rank($num, req()->zoneid);
  1861. $mem = gMem();
  1862. $uid = req()->uid;
  1863. $val = gMem()->zscore($memKey, $uid);
  1864. if ($damageVal > $val) {
  1865. $arr = array();
  1866. $arr["$uid"] = self::createScore($damageVal);
  1867. $mem->zadd($memKey, $arr);
  1868. }
  1869. $length = $mem->zlen($memKey);
  1870. if ($length > GameConfig::glc2()->WorldBoss_RankRewardStatistics) {
  1871. $num = $length - GameConfig::glc2()->WorldBoss_RankRewardStatistics;
  1872. $mem->zremrangebyrank($memKey, 0, $num - 1);
  1873. }
  1874. }
  1875. /**
  1876. * 6826 世界boss的排名信息
  1877. * @return type
  1878. */
  1879. public static function GetWorldBoss_RankInfo() {
  1880. //list() = req()->paras;
  1881. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  1882. //$num = self::GetCurTurnNum();
  1883. //$memKey = MemKey_GameRun::WorldBoss_Rank($num, req()->zoneid);
  1884. $memKey = self::GetWorldBoss_DamageMemKey();
  1885. $list = gMem()->zrevrange($memKey, 0, GameConfig::glc2()->WorldBoss_RankRewardStatistics, true);
  1886. $rankStatistics = GameConfig::glc2()->WorldBoss_RankStatistics;
  1887. $selfRank = null;
  1888. $retArr = array();
  1889. $index = 0;
  1890. if (count($list) > 0) {
  1891. foreach ($list as $uid => $score) {
  1892. $index += 1;
  1893. $rankInfo = self::initOtherUidRankInfo($uid, $score, 3);
  1894. if ($rankInfo->uid == req()->uid && $index <= $rankStatistics) {
  1895. $selfIsHasRank = 1;
  1896. $selfRank = $rankInfo;
  1897. }
  1898. $retArr[] = $rankInfo;
  1899. }
  1900. }
  1901. if ($selfRank == null) {
  1902. $selfRank = self::initOtherUidRankInfo(req()->uid, 0);
  1903. }
  1904. UserProc::updateUserInfo();
  1905. $ret = array(
  1906. 'rankInfo' => $retArr,
  1907. 'selfRank' => $selfRank,
  1908. 'selfIsHasRank' => $selfIsHasRank,
  1909. );
  1910. return Resp::ok($ret);
  1911. }
  1912. /**
  1913. * 6827 当前轮次下 自己的最高伤害值
  1914. * @return type
  1915. */
  1916. public static function GetWorldBoss_RankDamageVal() {
  1917. $val = gMem()->zscore(self::GetWorldBoss_DamageMemKey(), req()->uid);
  1918. if ($val == null) {
  1919. $val = 0;
  1920. }
  1921. UserProc::updateUserInfo();
  1922. $ret = array(
  1923. 'DamageVal' => intval($val),
  1924. );
  1925. return Resp::ok($ret);
  1926. }
  1927. /**
  1928. * 6828 获取自己的排名信息
  1929. * @return type
  1930. */
  1931. public static function GetWorldBoss_GetSelfRank() {
  1932. // $lv = gMem()->zrevrank(self::GetWorldBoss_DamageMemKey(), req()->uid);
  1933. // if($lv == null){
  1934. // $lv = 0;
  1935. // }
  1936. $damageval = gMem()->zscore(self::GetWorldBoss_DamageMemKey(), req()->uid);
  1937. if ($damageval == null) {
  1938. $damageval = 0;
  1939. }
  1940. $ins_rank = self::initOtherUidRankInfo(req()->uid, $damageval, 3);
  1941. //$tsMemKey = MemKey_GameRun::WorldBoss_StartTs(req()->zoneid);
  1942. //$ts = gMem()->get($tsMemKey);
  1943. //ctx()->privateState->worldBoss_startTs = $ts;
  1944. UserProc::updateUserInfo();
  1945. $ret = array(
  1946. 'selfRank' => $ins_rank,
  1947. );
  1948. return Resp::ok($ret);
  1949. }
  1950. /**
  1951. * 6829 领取世界boss奖励
  1952. * @return type
  1953. */
  1954. public static function GetWorldBoss_ClaimRewards() {
  1955. list($damageValId) = req()->paras;
  1956. my_Assert(!in_array($damageValId, ctx()->privateState->worldBoss_received), ErrCode::active_hasgetted);
  1957. $val = gMem()->zscore(self::GetWorldBoss_DamageMemKey(), req()->uid);
  1958. if ($val == null) {
  1959. $val = 0;
  1960. }
  1961. my_Assert($damageValId <= $val, ErrCode::active_worldBoss_notClaimRewards);
  1962. $turnNum = self::GetCurTurnNum();
  1963. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  1964. my_Assert($turnnumMo != null, ErrCode::err_const_no);
  1965. $list = GameConfig::worldboss_demagereward_getItemArray($turnnumMo->orderId);
  1966. foreach ($list as $key => $mo) {
  1967. if ($mo->demageValId == $damageValId && $mo->orderId == $turnnumMo->orderId) {
  1968. StoreProc::AddMultiItemInStore($mo->reward);
  1969. break;
  1970. }
  1971. }
  1972. ctx()->privateState->worldBoss_received[] = $damageValId;
  1973. UserProc::updateUserInfo();
  1974. $ret = array(
  1975. 'store' => ctx()->store,
  1976. 'cash' => ctx()->baseInfo->cash,
  1977. 'reward' => StoreProc::$reward,
  1978. 'reward_Gem' => StoreProc::$reward_Gem,
  1979. 'reward_equip' => StoreProc::$reward_equip,
  1980. );
  1981. return Resp::ok($ret);
  1982. }
  1983. /**
  1984. * 6830 世界boss结算
  1985. */
  1986. public static function WorldBoss_settle() {
  1987. list($damageNum) = req()->paras; //战斗结束伤害值
  1988. //校验每个轮次最后10分钟, 不能战斗
  1989. my_Assert(FightProc::isFunUnlock(25), ErrCode::active_funUnlock);
  1990. $tag = true;
  1991. $curDay = TimeUtil::totalDays();
  1992. $turnNum = self::GetCurTurnNum();
  1993. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  1994. if ($turnnumMo != null) {
  1995. $lastDay = TimeUtil::totalDays($turnnumMo->endTs);
  1996. if ($curDay == $lastDay && $turnnumMo->endTs - now() < 600) {
  1997. $tag = false;
  1998. }
  1999. }
  2000. if (ctx()->privateState->worldBoss_turnNum != $turnNum) {
  2001. ctx()->privateState->worldBoss_turnNum = $turnNum;
  2002. ctx()->privateState->worldBoss_received = array();
  2003. $tag = false;
  2004. }
  2005. if ($tag) {
  2006. self::Ranking_DamageVal($damageNum);
  2007. }
  2008. UserProc::updateUserInfo();
  2009. return Resp::ok(array());
  2010. }
  2011. // </editor-fold>
  2012. }