FightProc.php 91 KB

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