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. UserProc::updateUserInfo();
  813. $ret = array(
  814. 'gates' => ctx()->gates,
  815. 'store' => ctx()->store,
  816. 'task' => ctx()->task,
  817. 'baseInfo' => ctx()->base(),
  818. 'gold' => $gold + $waveMo->rewardGold,
  819. 'exp' => $waveMo->rewardExp,
  820. //'rewardStr' => $pickups
  821. 'reward' => StoreProc::$reward,
  822. 'reward_Gem' => StoreProc::$reward_Gem,
  823. 'reward_equip' => StoreProc::$reward_equip,
  824. 'oldLevel' => $oldLevel,
  825. 'newLevel' => $newLevel,
  826. //'funUnlockRecord' => ctx()->privateState->funUnlockRecord,
  827. //'funUnlockRecord_2' => ctx()->privateState->funUnlockRecord_2,
  828. //'LoginDays'=> ctx()->privateState->LoginDays,
  829. //'skillUnlockRecord' => ctx()->privateState->skillUnlockRecord,
  830. 'heros' => ctx()->heros,
  831. 'privateState' => ctx()->privateState,
  832. );
  833. return Resp::ok($ret);
  834. }
  835. /**
  836. * 装备概率结算
  837. * @param type $equipStr
  838. */
  839. private static function EquipSettle($equipStr) {
  840. StoreProc::DistributeItemsBox($itemId);
  841. }
  842. // <editor-fold defaultstate="collapsed" desc="功能解锁">
  843. /**
  844. * 检测功能解锁的 关卡
  845. * @param type $resultType
  846. * @param type $gateId
  847. * @return type
  848. */
  849. static function funUnlock_Gate($resultType, $gateId) {
  850. $dic = GameConfig::fun_unlock();
  851. foreach ($dic as $id => $mo) {
  852. $tag = false;
  853. if ($mo->unlockType1 != null) {
  854. //1:参与战斗结束即可 2战斗胜利 3某场战斗参加N次数才行
  855. switch ($mo->unlockType1) {
  856. case Enum_FunUnlockType::battle_Gate:
  857. if ($mo->unlockParas1 == $gateId && ctx()->gates->GateList->$gateId->fightNum == 0) {
  858. $tag = true;
  859. }
  860. break;
  861. case Enum_FunUnlockType::passBattle_Gate:
  862. if ($resultType == true && $mo->unlockParas1 == $gateId && ctx()->gates->GateList->$gateId->pass == 0) {
  863. $tag = true;
  864. }
  865. break;
  866. default:
  867. break;
  868. }
  869. }
  870. if ($mo->unlockType2 != null) {
  871. //1:参与战斗结束即可 2战斗胜利 3某场战斗参加N次数才行
  872. switch ($mo->unlockType2) {
  873. case Enum_FunUnlockType::battle_Gate:
  874. if ($mo->unlockParas2 == $gateId && ctx()->gates->GateList->$gateId->fightNum == 0) {
  875. $tag = true;
  876. }
  877. break;
  878. case Enum_FunUnlockType::passBattle_Gate:
  879. if ($resultType == true && $mo->unlockParas2 == $gateId && ctx()->gates->GateList->$gateId->pass == 0) {
  880. $tag = true;
  881. }
  882. break;
  883. default:
  884. break;
  885. }
  886. }
  887. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  888. if ($mo->unlockTip == 1) {
  889. ctx()->privateData(true)->funUnlockRecord[] = $id;
  890. }
  891. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  892. if ($id == 13 || $id == 16 || $id == 14) {
  893. //self::unlockGuideType($id);
  894. GuideProc::Qingling_EquipWear_Guide_Trigger($id);
  895. }
  896. self::SubFunDateInit_FunUnlock($id);
  897. }
  898. }
  899. }
  900. // public static function unlockGuideType($id) {
  901. //
  902. // }
  903. /**
  904. * 初次得到装备 功能解锁
  905. */
  906. static function funUnlock_equip_firstTime() {
  907. $dic = GameConfig::fun_unlock();
  908. foreach ($dic as $id => $mo) {
  909. $tag = false;
  910. if ($mo->unlockType1 != null && $mo->unlockType1 == Enum_FunUnlockType::equip_firstTime && count(StlUtil::dictToArray(ctx()->store->equip)) == 0) {
  911. $tag = true;
  912. }
  913. if ($mo->unlockType2 != null && $mo->unlockType2 == Enum_FunUnlockType::equip_firstTime && count(StlUtil::dictToArray(ctx()->store->equip)) == 0) {
  914. $tag = true;
  915. }
  916. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  917. if ($mo->unlockTip == 1) {
  918. ctx()->privateData(true)->funUnlockRecord[] = $id;
  919. }
  920. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  921. if ($id == 13 || $id == 16 || $id == 14) {
  922. GuideProc::Qingling_EquipWear_Guide_Trigger($id);
  923. //ctx()->privateData(true)->funUnlockRecord_3[] =
  924. }
  925. self::SubFunDateInit_FunUnlock($id);
  926. }
  927. }
  928. }
  929. /**
  930. * 玩家等级要求 功能解锁
  931. */
  932. static function funUnlock_userLv($level) {
  933. $dic = GameConfig::fun_unlock();
  934. foreach ($dic as $id => $mo) {
  935. $tag = false;
  936. if ($mo->unlockType1 != null && $mo->unlockType1 == Enum_FunUnlockType::userLv && $mo->unlockParas1 == $level) {
  937. $tag = true;
  938. }
  939. if ($mo->unlockType2 != null && $mo->unlockType2 == Enum_FunUnlockType::userLv && $mo->unlockParas2 == $level) {
  940. $tag = true;
  941. }
  942. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  943. if ($mo->unlockTip == 1) {//$mo->unlockGateId == $gateId
  944. ctx()->privateData(true)->funUnlockRecord[] = $id;
  945. }
  946. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  947. if ($id == 13 || $id == 16 || $id == 14) {
  948. GuideProc::Qingling_EquipWear_Guide_Trigger($id);
  949. //ctx()->privateData(true)->funUnlockRecord_3[] = self::unlockGuideType($id);
  950. }
  951. self::SubFunDateInit_FunUnlock($id);
  952. }
  953. }
  954. }
  955. /**
  956. * 主线挑战 功能解锁
  957. */
  958. static function funUnlock_mainChallengeGate_State($result, $gateId, $state) {
  959. $dic = GameConfig::fun_unlock();
  960. foreach ($dic as $id => $mo) {
  961. $tag = false;
  962. if ($mo->unlockType1 != null && $result = true && $mo->unlockType1 == Enum_FunUnlockType::mainChallengeGate_State) {
  963. $str = explode(',', $mo->unlockParas1);
  964. $uGateId = $str[0];
  965. $gateState = $str[1];
  966. if ($uGateId == $gateId && StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId) && ctx()->gates->GateList->$gateId->tz_state == $gateState - 1) {
  967. $tag = true;
  968. }
  969. }
  970. if ($mo->unlockType2 != null && $result = true && $mo->unlockType2 == Enum_FunUnlockType::mainChallengeGate_State) {
  971. $str = explode(',', $mo->unlockParas2);
  972. $uGateId = $str[0];
  973. $gateState = $str[1];
  974. if ($uGateId == $gateId && StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId) && ctx()->gates->GateList->$gateId->tz_state == $gateState - 1) {
  975. $tag = true;
  976. }
  977. }
  978. if ($tag && !in_array($id, ctx()->privateState->funUnlockRecord_2)) {
  979. if ($mo->unlockTip == 1) {//$mo->unlockGateId == $gateId
  980. ctx()->privateData(true)->funUnlockRecord[] = $id;
  981. }
  982. ctx()->privateData(true)->funUnlockRecord_2[] = $id;
  983. if ($id == 13 || $id == 16 || $id == 14) {
  984. GuideProc::Qingling_EquipWear_Guide_Trigger($id);
  985. //ctx()->privateData(true)->funUnlockRecord_3[] = self::unlockGuideType($id);
  986. }
  987. self::SubFunDateInit_FunUnlock($id);
  988. }
  989. }
  990. }
  991. /**
  992. * 查看某功能是否解锁
  993. * @param type $id
  994. */
  995. static function isFunUnlock($id) {
  996. $funMo = GameConfig::fun_unlock_getItem($id);
  997. if ($funMo->unlockType1 != null && self::unlockCondition($funMo->unlockType1, $funMo->unlockParas1)) {
  998. return true;
  999. }
  1000. if ($funMo->unlockType2 != null && self::unlockCondition($funMo->unlockType2, $funMo->unlockParas2)) {
  1001. return true;
  1002. }
  1003. return false;
  1004. }
  1005. /**
  1006. * 解锁条件id
  1007. * @param type $conditionId
  1008. */
  1009. static function unlockCondition($conditionId, $paras) {
  1010. $funUnlock = false;
  1011. switch ($conditionId) {
  1012. case Enum_FunUnlockType::battle_Gate:
  1013. $gateId = $paras;
  1014. if (ctx()->gates->GateList->$gateId->fightNum > 0) {
  1015. $funUnlock = true;
  1016. }
  1017. break;
  1018. case Enum_FunUnlockType::passBattle_Gate:
  1019. $gateId = $paras;
  1020. if(StlUtil::dictHasProperty(ctx()->gates->GateList, $gateId) && ctx()->gates->GateList->$gateId->pass >= 1){
  1021. $funUnlock = true;
  1022. }
  1023. // if (ctx()->gates->GateList->$gateId->pass >= 1) {
  1024. //
  1025. // }
  1026. break;
  1027. case Enum_FunUnlockType::equip_firstTime:
  1028. if (ctx()->store->equip != null) {
  1029. $funUnlock = true;
  1030. }
  1031. break;
  1032. case Enum_FunUnlockType::userLv:
  1033. if (ctx()->baseInfo->level >= $paras) {
  1034. $funUnlock = true;
  1035. }
  1036. break;
  1037. case Enum_FunUnlockType::mainChallengeGate_State:
  1038. $str = explode(',', $paras);
  1039. $uGateId = $str[0];
  1040. $gateState = $str[1];
  1041. if (StlUtil::dictHasProperty(ctx()->gates->GateList, $uGateId) && ctx()->gates->GateList->$uGateId->tz_state >= $gateState) {
  1042. $funUnlock = true;
  1043. }
  1044. break;
  1045. default:
  1046. break;
  1047. }
  1048. return $funUnlock;
  1049. }
  1050. /**
  1051. * 次级功能解锁数据初始化
  1052. */
  1053. static function SubFunDateInit_FunUnlock($type) {
  1054. $dic = GameConfig::subfun_unlock();
  1055. foreach ($dic as $id => $mo) {
  1056. if ($mo->funTypeId != $type) {
  1057. continue;
  1058. }
  1059. if ($mo->funTypeId == 6 && $mo->id == Enum_SubFunType::Day7_Happy) {
  1060. TaskProc::Day7TaskReset();
  1061. }
  1062. if ($mo->funTypeId == 5 && $mo->id == Enum_SubFunType::DailyTask) {
  1063. TaskProc::DailyTaskReset(true);
  1064. }
  1065. if ($mo->funTypeId == 5 && $mo->id == Enum_SubFunType::WeekTask) {
  1066. TaskProc::WeekTaskReset(true);
  1067. }
  1068. if ($mo->funTypeId == 5 && $mo->id == Enum_SubFunType::Day7_Sign) {
  1069. ActiveProc::DailyResetDay7Task(true);
  1070. }
  1071. if ($mo->funTypeId == 21 && $mo->id == Enum_SubFunType::Day7_Sign_NewPlayer) {
  1072. ActiveProc::InitDay7_Sign_NewPlayer(true);
  1073. ctx()->privateState->day7_drawed_newPlayer_startTs = now();
  1074. }
  1075. if ($mo->funTypeId == Enum_FunType::FlipCardLottery && $mo->id == Enum_SubFunType::FlipCardLottery) {
  1076. ActiveProc::ClearFlipCardInfo();
  1077. }
  1078. }
  1079. }
  1080. /**
  1081. * 次级功能解锁数据初始化
  1082. */
  1083. static function SubFunDateInit_Config() {
  1084. $dic = GameConfig::subfun_unlock();
  1085. foreach ($dic as $id => $mo) {
  1086. if ($mo->type == 3 && $mo->id == Enum_SubFunType::LimitTsSale && ctx()->privateState->nextDayLogin == 0 && now() >= $mo->startTs) {
  1087. ActiveProc::ResetLimitTsBuy();
  1088. }
  1089. if ($mo->type == 3 && $mo->id == Enum_SubFunType::ActivePoint_BattlePass && ctx()->privateState->battlePass_activePoint_refersh_ts == 0 && now() >= $mo->startTs) {
  1090. ctx()->privateState->battlePass_activePoint_refersh_ts = TimeUtil::getNextDayTs($mo->startTs, $mo->ts);
  1091. ctx()->privateData(true)->battlePass_activePoint_cost_ts = 0;
  1092. ctx()->privateData(true)->battlePass_taskPoint = 0;
  1093. ActiveProc::ResetBattlePassReward(Enum_SubFunType::ActivePoint_BattlePass);
  1094. }
  1095. if ($mo->type == 3 && $mo->id == Enum_SubFunType::Tili_BattleBass && ctx()->privateState->battlePass_tili_refersh_ts == 0 && now() >= $mo->startTs) {
  1096. ctx()->privateState->battlePass_tili_refersh_ts = TimeUtil::getNextDayTs($mo->startTs, $mo->ts);
  1097. ctx()->privateData(true)->battlePass_tili_cost_ts = 0;
  1098. ctx()->privateData(true)->battlePass_tili = 0;
  1099. ActiveProc::ResetBattlePassReward(Enum_SubFunType::Tili_BattleBass);
  1100. }
  1101. }
  1102. }
  1103. // </editor-fold>
  1104. // <editor-fold defaultstate="collapsed" desc="技能解锁">
  1105. /**
  1106. * 检测技能解锁的 1 关卡解锁,游玩到一定关卡解锁技能
  1107. * @param type $resultType
  1108. * @param type $gateId
  1109. * @return type
  1110. */
  1111. static function skillUnlock_gate($resultType, $gateId) {
  1112. $dic = GameConfig::skills();
  1113. $gateIndex = Ins_GateInfo::gateNum($gateId);
  1114. foreach ($dic as $id => $mo) {
  1115. if ($mo->unlock_acc_id_new == null) {
  1116. continue;
  1117. }
  1118. $strList = explode(':', $mo->unlock_acc_id_new);
  1119. $unlockType = $strList[0];
  1120. $unlockId = $strList[1];
  1121. if ($unlockType == 1 && $unlockId == $gateIndex && $resultType == true && ctx()->gates->GateList->$gateId->pass == 0 && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1122. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1123. }
  1124. }
  1125. }
  1126. /**
  1127. * 检测技能解锁的 2://皮肤解锁,获取到人物解锁后对应皮肤技能
  1128. * @param type $resultType
  1129. * @param type $gateId
  1130. * @return type
  1131. */
  1132. static function skillUnlock_heroUnlock($heroId) {
  1133. $dic = GameConfig::skills();
  1134. foreach ($dic as $id => $mo) {
  1135. if ($mo->unlock_acc_id_new == null) {
  1136. continue;
  1137. }
  1138. $strList = explode(':', $mo->unlock_acc_id_new);
  1139. $unlockType = $strList[0];
  1140. $unlockId = $strList[1];
  1141. if ($unlockType != 2) {
  1142. continue;
  1143. }
  1144. $heroMo = GameConfig::hero_getItem($heroId);
  1145. $heroTypeId = $heroMo->typeID;
  1146. $isUnlock = ctx()->heros->Dic->$heroId->isUnlock;
  1147. if ($unlockId == $heroTypeId && $isUnlock == 0 && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1148. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1149. }
  1150. }
  1151. }
  1152. /**
  1153. * 检测技能解锁的 3://玩家失败X次后解锁
  1154. * @param type $resultType
  1155. * @param type $gateId
  1156. * @return type
  1157. */
  1158. static function skillUnlock_fightNum($resultType) {
  1159. if ($resultType) {
  1160. return;
  1161. }
  1162. $GateList = ctx()->gates->GateList;
  1163. $num = 0;
  1164. foreach ($GateList as $gateId => $Ins_GateInfo) {
  1165. $num += $Ins_GateInfo->fightNum_fail;
  1166. }
  1167. $dic = GameConfig::skills();
  1168. foreach ($dic as $id => $mo) {
  1169. if ($mo->unlock_acc_id_new == null) {
  1170. continue;
  1171. }
  1172. $strList = explode(':', $mo->unlock_acc_id_new);
  1173. $unlockType = $strList[0];
  1174. $unlockId = $strList[1];
  1175. if ($unlockType != 3) {
  1176. continue;
  1177. }
  1178. if ($num == $unlockId && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1179. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1180. }
  1181. }
  1182. }
  1183. /**
  1184. * 玩家等级解锁技能
  1185. * @param type $curLevel
  1186. */
  1187. static function skillUnlock_userLevel($curLevel) {
  1188. $dic = GameConfig::skills();
  1189. foreach ($dic as $id => $mo) {
  1190. if ($mo->unlock_acc_id_new == null) {
  1191. continue;
  1192. }
  1193. $strList = explode(':', $mo->unlock_acc_id_new);
  1194. $unlockType = $strList[0];
  1195. $unlockId = $strList[1];
  1196. if ($unlockType != 5) { // 玩家等级
  1197. continue;
  1198. }
  1199. if ($unlockId == $curLevel && !in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  1200. ctx()->privateData(true)->skillUnlockRecord[] = $mo->typeId;
  1201. }
  1202. }
  1203. }
  1204. // </editor-fold>
  1205. // <editor-fold defaultstate="collapsed" desc="排行榜">
  1206. /**
  1207. * 参与主线关卡排行榜
  1208. * @param type $gateIndex
  1209. */
  1210. public static function Ranking_MainGateIndex($maxGateIndex) {
  1211. $memKey = MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid);
  1212. $mem = gMem();
  1213. $uid = req()->uid;
  1214. $score = self::GetRankScoreUid($uid, 1);
  1215. if ($maxGateIndex > $score) {
  1216. $arr = array();
  1217. $arr["$uid"] = self::createScore($maxGateIndex);
  1218. $mem->zadd($memKey, $arr);
  1219. }
  1220. $length = $mem->zlen($memKey);
  1221. if ($length > glc()->Rank_MainGateIndex_OnListRank) {
  1222. $num = $length - glc()->Rank_MainGateIndex_OnListRank;
  1223. $mem->zremrangebyrank($memKey, 0, $num - 1);
  1224. }
  1225. }
  1226. public static function createScore($score) {
  1227. if ($score > 0) {
  1228. $newScore = $score . '.' . (9999999999 - now());
  1229. return $newScore;
  1230. }
  1231. return 0;
  1232. }
  1233. /**
  1234. * 战力榜
  1235. * @param type $gateIndex
  1236. */
  1237. public static function Ranking_FightPower() {
  1238. $memKey = MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid);
  1239. $mem = gMem();
  1240. $uid = req()->uid;
  1241. $score = self::GetRankScoreUid($uid, 2);
  1242. //$power = self::countUserFightPower();
  1243. $power = FightPower_Calculate::GetFightPower();
  1244. $arr = array();
  1245. $arr["$uid"] = self::createScore($power);
  1246. $mem->zadd($memKey, $arr);
  1247. if ($power >= $score) {
  1248. self::IsAchievedFightPower_PassReward($power);
  1249. }
  1250. $length = $mem->zlen($memKey);
  1251. if ($length > glc()->Rank_FightPower_OnListRank) {
  1252. $num = $length - glc()->Rank_FightPower_OnListRank;
  1253. $mem->zremrangebyrank($memKey, 0, $num - 1);
  1254. }
  1255. }
  1256. public static function GetRankScoreUid($uid_rank, $type) {
  1257. if ($type == 1) {
  1258. $score = gMem()->zscore(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid_rank);
  1259. } else {
  1260. $score = gMem()->zscore(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid_rank);
  1261. }
  1262. if ($score == null) {
  1263. $score = 0;
  1264. }
  1265. return intval($score);
  1266. }
  1267. /**
  1268. * 6811 获取主线关卡排行榜信息
  1269. * @return type
  1270. */
  1271. public static function GetRankInfo() {
  1272. list($type) = req()->paras;
  1273. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  1274. $selfExtraInfo = 0;
  1275. $isExistFinishReward = 0;
  1276. $isExistFinishReward_other = 0;
  1277. if ($type == 1) {
  1278. $list = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  1279. $selfExtraInfo = ctx()->gates->maxPassGateNumId();
  1280. $isExistFinishReward = self::isExistNoDrawed_MainGate();
  1281. $isExistFinishReward_other = self::isExistNoDrawed_FightPower();
  1282. } else {
  1283. $list = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  1284. //$selfExtraInfo = self::countUserFightPower();
  1285. $selfExtraInfo = FightPower_Calculate::GetFightPower();
  1286. $isExistFinishReward = self::isExistNoDrawed_FightPower();
  1287. $isExistFinishReward_other = self::isExistNoDrawed_MainGate();
  1288. }
  1289. if ($isExistFinishReward == 1) {
  1290. $isExistFinishReward = true;
  1291. } else {
  1292. $isExistFinishReward = false;
  1293. }
  1294. if ($isExistFinishReward_other == 1) {
  1295. $isExistFinishReward_other = true;
  1296. } else {
  1297. $isExistFinishReward_other = false;
  1298. }
  1299. $selfRank = null;
  1300. $retArr = array();
  1301. if (count($list) > 0) {
  1302. foreach ($list as $uid => $score) {
  1303. $rankInfo = self::initOtherUidRankInfo($uid, $score, $type);
  1304. if ($rankInfo->uid == req()->uid) {
  1305. $selfIsHasRank = 1;
  1306. $selfRank = $rankInfo;
  1307. }
  1308. $retArr[] = $rankInfo;
  1309. }
  1310. }
  1311. if ($selfRank == null) {
  1312. $selfRank = self::initOtherUidRankInfo(req()->uid, $selfExtraInfo, $type);
  1313. }
  1314. UserProc::updateUserInfo();
  1315. $ret = array(
  1316. 'rankInfo' => $retArr,
  1317. 'selfRank' => $selfRank,
  1318. 'selfIsHasRank' => $selfIsHasRank,
  1319. 'isExistFinishReward' => $isExistFinishReward,
  1320. 'isExistFinishReward_other' => $isExistFinishReward_other,
  1321. );
  1322. return Resp::ok($ret);
  1323. }
  1324. /**
  1325. * 初始化玩家rank
  1326. * @param type $uid
  1327. * @param type $score
  1328. * @return \loyalsoft\Ins_rank
  1329. */
  1330. static function initOtherUidRankInfo($uid, $score, $type = null) {
  1331. $ins_rank = new Ins_rank();
  1332. if ($type == 1) {
  1333. $lv = gMem()->zrevrank(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  1334. } else if ($type == 2) {
  1335. $lv = gMem()->zrevrank(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
  1336. } elseif ($type == 3) {
  1337. $memKey = self::GetWorldBoss_DamageMemKey();
  1338. $lv = gMem()->zrevrank($memKey, $uid);
  1339. }
  1340. if ($lv === null) {
  1341. $lv = -1;
  1342. }
  1343. $ins_rank->rank = $lv + 1;
  1344. $ins_rank->uid = $uid;
  1345. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  1346. $ins_rank->name = $userInfo->baseInfo->name;
  1347. $ins_rank->headImg = $userInfo->baseInfo->headImg;
  1348. $ins_rank->score = intval($score);
  1349. return $ins_rank;
  1350. }
  1351. /**
  1352. * 6812 获取排行榜内玩家的装备信息
  1353. * @return type
  1354. */
  1355. public static function GetUidEquipInfo_Rank() {
  1356. list($uid) = req()->paras;
  1357. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  1358. $store = $userInfo->store;
  1359. $heros = $userInfo->heros;
  1360. $gates = $userInfo->gates;
  1361. UserProc::updateUserInfo();
  1362. $ret = array(
  1363. 'store' => $store,
  1364. 'heros' => $heros,
  1365. 'gates' => $gates,
  1366. );
  1367. return Resp::ok($ret);
  1368. }
  1369. /**
  1370. * 通关奖励是否达成
  1371. * @param type $maxGateIndex
  1372. */
  1373. public static function IsAchievedMainGate_PassReward($maxGateIndex) {
  1374. $rewards = GameConfig::rank_passgatereward();
  1375. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1376. foreach ($rewards as $passGateId => $mo) {
  1377. if ($passGateId == $maxGateIndex && !gMem()->hexists($memKey, $maxGateIndex)) {
  1378. $ins_rank = new Ins_rank();
  1379. $ins_rank->uid = req()->uid;
  1380. $ins_rank->name = ctx()->baseInfo->name;
  1381. $ins_rank->headImg = ctx()->baseInfo->headImg;
  1382. $ins_rank->score = $passGateId;
  1383. gMem()->hset($memKey, $maxGateIndex, $ins_rank);
  1384. break;
  1385. }
  1386. }
  1387. }
  1388. /*
  1389. * 战力奖励是否达成
  1390. */
  1391. public static function IsAchievedFightPower_PassReward($power) {
  1392. $rewards = GameConfig::rank_fightpowerreward();
  1393. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1394. foreach ($rewards as $fightPower => $mo) {
  1395. if ($power >= $fightPower && !gMem()->hexists($memKey, $fightPower)) {
  1396. $ins_rank = new Ins_rank();
  1397. $ins_rank->uid = req()->uid;
  1398. $ins_rank->name = ctx()->baseInfo->name;
  1399. $ins_rank->headImg = ctx()->baseInfo->headImg;
  1400. $ins_rank->score = $fightPower;
  1401. gMem()->hset($memKey, $fightPower, $ins_rank);
  1402. }
  1403. }
  1404. }
  1405. public static function isExistNoDrawed_MainGate() {
  1406. $isExistFinishReward = 0;
  1407. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1408. $dic = gMem()->hgetall($memKey);
  1409. foreach ($dic as $gateId => $ins_rank) {
  1410. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  1411. $isExistFinishReward = 1;
  1412. break;
  1413. }
  1414. }
  1415. ctx()->privateData(true)->redTip_RewardMainGateRank = $isExistFinishReward;
  1416. return $isExistFinishReward;
  1417. }
  1418. public static function isExistNoDrawed_FightPower() {
  1419. $isExistFinishReward = 0;
  1420. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1421. $dic = gMem()->hgetall($memKey);
  1422. foreach ($dic as $fightPower => $ins_rank) {
  1423. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1424. $isExistFinishReward = 1;
  1425. break;
  1426. }
  1427. }
  1428. ctx()->privateData(true)->redTip_RewardFightPowerRank = $isExistFinishReward;
  1429. return $isExistFinishReward;
  1430. }
  1431. /**
  1432. * 6813
  1433. * @return type
  1434. */
  1435. public static function GetmainGate_RankRewardInfo() {
  1436. //list($type) = req()->paras;
  1437. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1438. $dic = gMem()->hgetall($memKey);
  1439. if ($dic == null) {
  1440. $dic = new \stdClass();
  1441. }
  1442. UserProc::updateUserInfo();
  1443. $ret = array(
  1444. 'rankReward' => $dic,
  1445. );
  1446. return Resp::ok($ret);
  1447. }
  1448. /**
  1449. * 6814
  1450. * @return type
  1451. */
  1452. public static function GetFightPower_RankRewardInfo() {
  1453. //list($type) = req()->paras;
  1454. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1455. $dic = gMem()->hgetall($memKey);
  1456. if ($dic == null) {
  1457. $dic = new \stdClass();
  1458. }
  1459. UserProc::updateUserInfo();
  1460. $ret = array(
  1461. 'rankReward' => $dic,
  1462. );
  1463. return Resp::ok($ret);
  1464. }
  1465. /**
  1466. * 6815 领取通关荣誉榜奖励
  1467. * @return type
  1468. */
  1469. public static function ReceiveRankReward_MainGate() {
  1470. list($gateId) = req()->paras;
  1471. my_Assert(!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate), ErrCode::rankReward_HasReceive);
  1472. $mo = GameConfig::rank_passgatereward_getItem($gateId);
  1473. my_Assert($mo != null, ErrCode::err_const_no);
  1474. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1475. if (gMem()->hexists($memKey, $gateId)) {
  1476. StoreProc::AddMultiItemInStore($mo->reward);
  1477. ctx()->privateData(true)->rankReward_drawed_MainGate[] = $gateId;
  1478. TaskProc::OnRankPrize_Num();
  1479. }
  1480. $tag = self::isExistNoDrawed_MainGate();
  1481. UserProc::updateUserInfo();
  1482. $ret = array('redTip' => $tag, 'task' => ctx()->task, 'store' => ctx()->store, 'cash' => ctx()->baseInfo->cash, 'reward' => StoreProc::$reward);
  1483. return Resp::ok($ret);
  1484. }
  1485. /**
  1486. * 6816 领取战力荣誉榜奖励
  1487. * @return type
  1488. */
  1489. public static function ReceiveRankReward_FightPower() {
  1490. list($fightPower) = req()->paras;
  1491. my_Assert(!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower), ErrCode::rankReward_HasReceive);
  1492. $mo = GameConfig::rank_fightpowerreward_getItem($fightPower);
  1493. my_Assert($mo != null, ErrCode::err_const_no);
  1494. $memKey = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1495. if (gMem()->hexists($memKey, $fightPower)) {
  1496. StoreProc::AddMultiItemInStore($mo->reward);
  1497. ctx()->privateData(true)->rankReward_drawed_fightPower[] = $fightPower;
  1498. TaskProc::OnFightRankPrize_Num();
  1499. }
  1500. $tag = self::isExistNoDrawed_FightPower();
  1501. UserProc::updateUserInfo();
  1502. $ret = array('redTip' => $tag, 'task' => ctx()->task, 'store' => ctx()->store, 'cash' => ctx()->baseInfo->cash, 'reward' => StoreProc::$reward);
  1503. return Resp::ok($ret);
  1504. }
  1505. /**
  1506. * 6824 排行奖励一键领取
  1507. */
  1508. static function ReceiveRankReward() {
  1509. list($type) = req()->paras; # 解锁数量
  1510. if ($type == 1) {
  1511. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1512. $dic = gMem()->hgetall($memKey);
  1513. foreach ($dic as $gateId => $ins_rank) {
  1514. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  1515. $mo = GameConfig::rank_passgatereward_getItem($gateId);
  1516. StoreProc::AddMultiItemInStore($mo->reward);
  1517. ctx()->privateData(true)->rankReward_drawed_MainGate[] = $gateId;
  1518. TaskProc::OnRankPrize_Num();
  1519. }
  1520. }
  1521. } else {
  1522. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1523. $dic2 = gMem()->hgetall($memKey2);
  1524. foreach ($dic2 as $fightPower => $ins_rank) {
  1525. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1526. $mo = GameConfig::rank_fightpowerreward_getItem($fightPower);
  1527. StoreProc::AddMultiItemInStore($mo->reward);
  1528. ctx()->privateData(true)->rankReward_drawed_fightPower[] = $fightPower;
  1529. TaskProc::OnFightRankPrize_Num();
  1530. }
  1531. }
  1532. }
  1533. UserProc::updateUserInfo();
  1534. $ret = array('redTip' => 0,
  1535. 'task' => ctx()->task,
  1536. 'store' => ctx()->store,
  1537. 'cash' => ctx()->baseInfo->cash,
  1538. 'reward' => StoreProc::$reward,
  1539. 'rankReward_drawed_fightPower' => ctx()->privateState->rankReward_drawed_fightPower,
  1540. 'rankReward_drawed_MainGate' => ctx()->privateState->rankReward_drawed_MainGate,
  1541. );
  1542. return Resp::ok($ret);
  1543. }
  1544. /**
  1545. * 6817
  1546. */
  1547. public static function IsExistRankReward() {
  1548. //list($type) = req()->paras;
  1549. $type = 0;
  1550. $isExistFinishReward = false;
  1551. $memKey = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1552. $dic = gMem()->hgetall($memKey);
  1553. foreach ($dic as $gateId => $ins_rank) {
  1554. if (!in_array($gateId, ctx()->privateState->rankReward_drawed_MainGate)) {
  1555. $isExistFinishReward = true;
  1556. $type = 1;
  1557. break;
  1558. }
  1559. }
  1560. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1561. $dic2 = gMem()->hgetall($memKey2);
  1562. foreach ($dic2 as $fightPower => $ins_rank) {
  1563. if (!in_array($fightPower, ctx()->privateState->rankReward_drawed_fightPower)) {
  1564. $isExistFinishReward = true;
  1565. $type = 2;
  1566. break;
  1567. }
  1568. }
  1569. UserProc::updateUserInfo();
  1570. $ret = array(
  1571. 'isExistFinishReward' => $isExistFinishReward,
  1572. 'type' => $type,
  1573. );
  1574. return Resp::ok($ret);
  1575. }
  1576. /*
  1577. * 删除排行榜内注销账号的玩家
  1578. */
  1579. public static function DeleteRankInvalidUser($uid2) {
  1580. $dic1 = gMem()->zrevrange(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), 0, glc()->Rank_MainGateIndex_OnListRank, true);
  1581. foreach ($dic1 as $uid => $score) {
  1582. if ($uid == $uid2) {
  1583. gMem()->zrem(MemKey_GameRun::Rank_MainGateIndex_Zone_zset(req()->zoneid), $uid);
  1584. break;
  1585. }
  1586. }
  1587. $dic2 = gMem()->zrevrange(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), 0, glc()->Rank_FightPower_OnListRank, true);
  1588. foreach ($dic2 as $uid => $score) {
  1589. if ($uid == $uid2) {
  1590. gMem()->zrem(MemKey_GameRun::Rank_FightPower_Zone_zset(req()->zoneid), $uid);
  1591. break;
  1592. }
  1593. }
  1594. self::DeleteWorldBossRankInvalidUser($uid2);
  1595. }
  1596. /*
  1597. * 删除世界boss排行榜内注销账号的玩家
  1598. */
  1599. public static function DeleteWorldBossRankInvalidUser($uid2) {
  1600. $rankKey = self::GetWorldBoss_DamageMemKey();
  1601. $score = gMem()->zscore($rankKey, $uid2);
  1602. if ($score > 0) {
  1603. gMem()->zrem($rankKey, $uid2);
  1604. }
  1605. }
  1606. /*
  1607. * 排行玩家修改昵称
  1608. */
  1609. public static function UpdateRankUserName($uid, $newName) {
  1610. $memKey1 = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1611. $dic = gMem()->hgetall($memKey1);
  1612. foreach ($dic as $gateId => $ins_rank) {
  1613. if ($ins_rank->uid == $uid) {
  1614. $ins_rank->name = $newName;
  1615. gMem()->hset($memKey1, $gateId, $ins_rank);
  1616. }
  1617. }
  1618. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1619. $dic2 = gMem()->hgetall($memKey2);
  1620. foreach ($dic2 as $fightPower => $ins_rank) {
  1621. if ($ins_rank->uid == $uid) {
  1622. $ins_rank->name = $newName;
  1623. gMem()->hset($memKey2, $fightPower, $ins_rank);
  1624. }
  1625. }
  1626. }
  1627. /*
  1628. * 排行玩家头像变动
  1629. */
  1630. public static function UpdateRankUserHeadImg($uid, $headImg) {
  1631. $memKey1 = MemKey_GameRun::RankReward_MainGateIndex_Zone_hash(req()->zoneid);
  1632. $dic = gMem()->hgetall($memKey1);
  1633. foreach ($dic as $gateId => $ins_rank) {
  1634. if ($ins_rank->uid == $uid) {
  1635. $ins_rank->headImg = $headImg;
  1636. gMem()->hset($memKey1, $gateId, $ins_rank);
  1637. }
  1638. }
  1639. $memKey2 = MemKey_GameRun::RankReward_FightPower_Zone_hash(req()->zoneid);
  1640. $dic2 = gMem()->hgetall($memKey2);
  1641. foreach ($dic2 as $fightPower => $ins_rank) {
  1642. if ($ins_rank->uid == $uid) {
  1643. $ins_rank->headImg = $headImg;
  1644. gMem()->hset($memKey2, $fightPower, $ins_rank);
  1645. }
  1646. }
  1647. }
  1648. /*
  1649. * 统计战力 战斗力=攻击x(生命-伤害减免值)x(1+暴击率/100x(暴击伤害倍率-1))改为 //战斗力=攻击x(生命-伤害减免值)x(1+暴击率 x(暴击伤害倍率-1))2024-8-30
  1650. */
  1651. public static function countUserFightPower() {
  1652. $CurrentHeroId = ctx()->heros->CurrentHeroId;
  1653. //$hero = ctx()->heros->Dic->$CurrentHeroId;
  1654. list($addHp, $addAtk, $addDecDamage, $addEatFood) = ctx()->gates()->GetEnvovleBuffs(); // 启灵加成
  1655. $mo = GameConfig::hero_getItem($CurrentHeroId);
  1656. my_Assert($mo != null, ErrCode::err_const_no);
  1657. $heroBashAttack = $mo->attack;
  1658. $heroBashHp = $mo->hp;
  1659. $attck = 0;
  1660. $hp = 0;
  1661. $equipDic = ctx()->store->equipLocation;
  1662. foreach ($equipDic as $index => $equipUid) {
  1663. $ins_Equip = new Ins_Equip(ctx()->store->equip->$equipUid);
  1664. if ($ins_Equip->mo()->position % 2 == 1) {
  1665. $attck += GameConfig::equip_levelupgrade_getItem($ins_Equip->mo()->rarity, $ins_Equip->qual, $ins_Equip->mo()->position, $ins_Equip->level)->attckNum;
  1666. } elseif ($ins_Equip->mo()->position % 2 == 0) {
  1667. $hp += GameConfig::equip_levelupgrade_getItem($ins_Equip->mo()->rarity, $ins_Equip->qual, $ins_Equip->mo()->position, $ins_Equip->level)->hpNum;
  1668. }
  1669. }
  1670. // $equipDic = ctx()->store->equipPosition;
  1671. // $attck = 0;
  1672. // $hp = 0;
  1673. // foreach ($equipDic as $index => $ins_equip) {
  1674. // $Ins_Equip = new Ins_EquipPosition($ins_equip);
  1675. // if ($Ins_Equip->mo()->upgradeType == 1) {//攻击力
  1676. // $attck += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->attckNum;
  1677. // } elseif ($Ins_Equip->mo()->upgradeType == 2) {
  1678. // $hp += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->hpNum;
  1679. // } else {
  1680. // $attck += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->attckNum;
  1681. // $hp += GameConfig::equip_levelupgrade_getItem($ins_equip->level)->hpNum;
  1682. // }
  1683. // }
  1684. $heroAttck = $heroBashAttack + $attck + $addAtk; # 英雄基础攻击力+装备宝石词条攻击力+启灵攻击力
  1685. $heroHp = $heroBashHp + $hp + $addHp; # 英雄基础hp + 装备宝石词条hp + 启灵hp
  1686. $pag = ctx()->store->equipPag;
  1687. $gemDic = ctx()->store->gemEquip->$pag; //Dictionary<E_EquipPosition, Dictionary<int, Ins_Gem>>
  1688. $per = 0;
  1689. $parasVal = 0;
  1690. $per_hp = 0;
  1691. $parasVal_hp = 0;
  1692. foreach ($equipDic as $index => $ins_equip) {
  1693. if (StlUtil::dictHasProperty($gemDic, $index)) {
  1694. $dic = $gemDic->$index;
  1695. foreach ($dic as $k => $gem) {
  1696. $ins_Gem = new Ins_Gem($gem);
  1697. if ($ins_Gem->predicateMo()->actionType == "mulDamage") {
  1698. $per += $ins_Gem->predicateMo()->actionParam1;
  1699. } elseif ($ins_Gem->predicateMo()->actionType == "addDamage") {
  1700. $parasVal += $ins_Gem->predicateMo()->actionParam1;
  1701. } elseif ($ins_Gem->predicateMo()->actionType == "mulHp") {
  1702. $per_hp += $ins_Gem->predicateMo()->actionParam1;
  1703. } elseif ($ins_Gem->predicateMo()->actionType == "addHp") {
  1704. $parasVal_hp += $ins_Gem->predicateMo()->actionParam1;
  1705. }
  1706. }
  1707. }
  1708. }
  1709. if ($per != 0) {
  1710. $heroAttck = round($heroAttck + $heroAttck * $per);
  1711. }
  1712. if ($parasVal != 0) {
  1713. $heroAttck += $parasVal;
  1714. }
  1715. if ($per_hp != 0) {
  1716. $heroHp = round($heroHp + $heroHp * $per_hp);
  1717. }
  1718. if ($parasVal_hp != 0) {
  1719. $heroHp += $parasVal_hp;
  1720. }
  1721. $dec_demage = $mo->dec_demage + $addDecDamage; # 英雄基础减伤 + 启灵减伤
  1722. $bigHit_Val = $mo->bigHit_Val;
  1723. $bigHit_rate = $mo->bigHit_rate;
  1724. $val = $heroAttck * ($heroHp - $dec_demage) * (1 + $bigHit_rate * ($bigHit_Val - 1));
  1725. return intval($val);
  1726. }
  1727. // </editor-fold>
  1728. // <editor-fold defaultstate="collapsed" desc=" 世界boss 排行榜">
  1729. /**
  1730. * 结算世界boss排行奖励[定时发放奖励接口]
  1731. */
  1732. public static function triggerSettleRankReward_worldBoss() {
  1733. //校验下是否处在发放奖励信息的时间点 【每个轮次最后一天的最后10分钟】
  1734. $mo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::WorldBoss);
  1735. if ($mo == null) {
  1736. return;
  1737. }
  1738. if (now() < $mo->startTs) {
  1739. return;
  1740. }
  1741. echo '----发放世界boss的排行奖励程序开始运行-----';
  1742. $curDay = TimeUtil::totalDays();
  1743. $turnNum = self::GetCurTurnNum();
  1744. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  1745. if ($turnnumMo != null) {
  1746. $lastDay = TimeUtil::totalDays($turnnumMo->endTs);
  1747. if ($curDay == $lastDay && $turnnumMo->endTs - now() < 600) {
  1748. $damageMemKey = self::GetWorldBoss_DamageMemKey();
  1749. echo '发放奖励的menkey===============:';
  1750. echo "$damageMemKey";
  1751. $mem = gMem();
  1752. if ($mem->exists($damageMemKey)) {
  1753. FightProc::settleRankReward_worldBoss();
  1754. }
  1755. }
  1756. }
  1757. echo '----世界boss的排行奖励-发放完成----';
  1758. }
  1759. public static function settleRankReward_worldBoss() {
  1760. echo '----开始发放世界boss的排行奖励-----';
  1761. $dic = GameConfig::worldboss_rankreward();
  1762. if ($dic == null) {
  1763. return;
  1764. }
  1765. $turnNum = self::GetCurTurnNum();
  1766. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  1767. $orderId = $turnnumMo->orderId;
  1768. $gateMo = GameConfig::gate_getItem($turnnumMo->gateId);
  1769. if ($gateMo == null) {
  1770. return;
  1771. }
  1772. $name = $gateMo->gateName;
  1773. $memKey = self::GetWorldBoss_DamageMemKey();
  1774. $index = 0;
  1775. foreach ($dic as $id => $mo) {
  1776. $list = gMem()->zrevrange($memKey, $mo->rank_start - 1, $mo->rank_end - 1, true);
  1777. if (count($list) == 0) {
  1778. continue;
  1779. }
  1780. foreach ($list as $uid => $score) {
  1781. $index += 1;
  1782. self::settleDamageReward_worldBoss($name, $orderId, $uid, $score);
  1783. EmailProc::SendWorldBossRewardMail(req()->zoneid, $uid, $mo->reward, $index, $name);
  1784. }
  1785. }
  1786. gMem()->delete($memKey);
  1787. // $list = gMem()->zrevrange($memKey, 0, GameConfig::glc2()->WorldBoss_RankRewardStatistics, true);
  1788. // if (count($list) <= 0) {
  1789. //
  1790. // }
  1791. }
  1792. public static function settleDamageReward_worldBoss($name, $orderId, $uid, $demageVal) {
  1793. $demageList = GameConfig::worldboss_demagereward_getItemArray($orderId);
  1794. $strkey = MemKey_User::Info_hash(req()->zoneid, $uid);
  1795. if (!gMem()->exists($strkey)) {
  1796. return;
  1797. }
  1798. $userInfo = UserProc::getUserGame(req()->zoneid, $uid);
  1799. $worldBoss_received = $userInfo->privateState->worldBoss_received;
  1800. $dic = new \stdClass();
  1801. foreach ($demageList as $dMo) {
  1802. if ($demageVal >= $dMo->demageValId && !in_array($dMo->demageValId, $worldBoss_received)) {
  1803. if ($dMo->reward != null) {
  1804. $list = explode(';', $dMo->reward);
  1805. foreach ($list as $value) {
  1806. $arr = explode(',', $value);
  1807. $rewardId = $arr[0];
  1808. $rewardNum = $arr[1];
  1809. if (StlUtil::dictHasProperty($dic, $rewardId)) {
  1810. $dic->$rewardId += $rewardNum;
  1811. } else {
  1812. $dic->$rewardId = $rewardNum;
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. $str = '';
  1819. foreach ($dic as $k => $val) {
  1820. $s = $k . ',' . $val;
  1821. if ($str == '') {
  1822. $str = $s;
  1823. } else {
  1824. $str = $str . ';' . $s;
  1825. }
  1826. }
  1827. if ($str != null) {
  1828. EmailProc::SendWorldBossDamageRewardMail(req()->zoneid, $uid, $str, $name);
  1829. }
  1830. }
  1831. /**
  1832. * 重置每个赛季的开始时间 一个重置每个赛季的开始时间赛季完成后 排名数据清理掉 同时轮次要改变 [定时接口]----废弃
  1833. */
  1834. public static function ResetWorldBossRank_StartTs() {
  1835. return;
  1836. // $mo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::WorldBoss);
  1837. // if ($mo == null) {
  1838. // return;
  1839. // }
  1840. // if (now() < $mo->startTs) {
  1841. // return;
  1842. // }
  1843. // echo '赛季的开始时间重置程序开始运行**********';
  1844. // $memKey = MemKey_GameRun::WorldBoss_StartTs(req()->zoneid);
  1845. // $mem = gMem();
  1846. //
  1847. // $ts = $mem->get($memKey);
  1848. // $durationTs = $mo->ts * 24 * 60 * 60;
  1849. // if ($ts == null && now() - $mo->startTs < $durationTs) {
  1850. // $mem->set($memKey, $mo->startTs);
  1851. // $ts = $mo->startTs;
  1852. // }
  1853. //
  1854. // if (now() - $ts > $durationTs) {
  1855. // $nextTs = TimeUtil::getNextDayTs($ts, $mo->ts);
  1856. // $mem->set($memKey, $nextTs); //下一轮赛季的开始时间回存
  1857. // echo '完成重置下一个赛季的开始时间';
  1858. // //清理排行榜
  1859. // self::ClearWorldBossRank();
  1860. // }
  1861. }
  1862. /**
  1863. * 清理世界boss排行榜数据
  1864. */
  1865. public static function ClearWorldBossRank() {
  1866. $mem = gMem();
  1867. $arr = array();
  1868. for ($i = 1; $i <= 9; $i++) {
  1869. $memKey = MemKey_GameRun::WorldBoss_Rank($i, req()->zoneid);
  1870. $arr[] = $memKey;
  1871. }
  1872. $mem->deleteMulti($arr);
  1873. }
  1874. /**
  1875. * 每天登录的时候 检测轮次变化
  1876. */
  1877. public static function ResetTurnNum() {
  1878. if (!FightProc::isFunUnlock(25)) {
  1879. return;
  1880. }
  1881. $subMo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::WorldBoss);
  1882. if (ctx()->privateState->worldBoss_turnNum < 0) {
  1883. ctx()->privateState->worldBoss_turnNum = 0;
  1884. }
  1885. if (now() < $subMo->startTs) {
  1886. return;
  1887. }
  1888. $num = self::GetCurTurnNum();
  1889. if ($num != ctx()->privateState->worldBoss_turnNum) {
  1890. ctx()->privateState->worldBoss_turnNum = $num;
  1891. ctx()->privateState->worldBoss_received = array();
  1892. }
  1893. }
  1894. /**
  1895. * 当前所在世界boss 的轮次 //当前轮次可以算出来
  1896. */
  1897. public static function GetCurTurnNum() {
  1898. $dic = GameConfig::worldboss_turnnum();
  1899. foreach ($dic as $turnId => $mo) {
  1900. if (now() >= $mo->startTs && now() < $mo->endTs) {
  1901. return $turnId;
  1902. }
  1903. }
  1904. return 0;
  1905. // $memKey = MemKey_GameRun::WorldBoss_StartTs(req()->zoneid);
  1906. // $mem = gMem();
  1907. // $ts = $mem->get($memKey);
  1908. //
  1909. // $curDay = TimeUtil::totalDays(now());
  1910. // $lastDay = TimeUtil::totalDays($ts);
  1911. //
  1912. // $val = $curDay - $lastDay;
  1913. // $num = intval($val / 3);
  1914. //
  1915. // return $num + 1;
  1916. }
  1917. /**
  1918. * 世界boss排名榜 memkey
  1919. * @return type
  1920. */
  1921. public static function GetWorldBoss_DamageMemKey() {
  1922. $num = self::GetCurTurnNum();
  1923. $memKey = MemKey_GameRun::WorldBoss_Rank($num, req()->zoneid);
  1924. return $memKey;
  1925. }
  1926. /**
  1927. * 世界boss榜 伤害值入榜
  1928. * @param type $gateIndex
  1929. */
  1930. public static function Ranking_DamageVal($damageVal) {
  1931. //$num = self::GetCurTurnNum();
  1932. $memKey = self::GetWorldBoss_DamageMemKey(); // MemKey_GameRun::WorldBoss_Rank($num, req()->zoneid);
  1933. $mem = gMem();
  1934. $uid = req()->uid;
  1935. $val = gMem()->zscore($memKey, $uid);
  1936. if ($damageVal > $val) {
  1937. $arr = array();
  1938. $arr["$uid"] = self::createScore($damageVal);
  1939. $mem->zadd($memKey, $arr);
  1940. }
  1941. $length = $mem->zlen($memKey);
  1942. if ($length > GameConfig::glc2()->WorldBoss_RankRewardStatistics) {
  1943. $num = $length - GameConfig::glc2()->WorldBoss_RankRewardStatistics;
  1944. $mem->zremrangebyrank($memKey, 0, $num - 1);
  1945. }
  1946. }
  1947. /**
  1948. * 6826 世界boss的排名信息
  1949. * @return type
  1950. */
  1951. public static function GetWorldBoss_RankInfo() {
  1952. //list() = req()->paras;
  1953. $selfIsHasRank = 0; //本人是否上榜 0未上榜没有排名 1上榜则selfRank就是排名
  1954. //$num = self::GetCurTurnNum();
  1955. //$memKey = MemKey_GameRun::WorldBoss_Rank($num, req()->zoneid);
  1956. $memKey = self::GetWorldBoss_DamageMemKey();
  1957. $list = gMem()->zrevrange($memKey, 0, GameConfig::glc2()->WorldBoss_RankRewardStatistics, true);
  1958. $rankStatistics = GameConfig::glc2()->WorldBoss_RankStatistics;
  1959. $selfRank = null;
  1960. $retArr = array();
  1961. $index = 0;
  1962. if (count($list) > 0) {
  1963. foreach ($list as $uid => $score) {
  1964. $index += 1;
  1965. $rankInfo = self::initOtherUidRankInfo($uid, $score, 3);
  1966. if ($rankInfo->uid == req()->uid && $index <= $rankStatistics) {
  1967. $selfIsHasRank = 1;
  1968. $selfRank = $rankInfo;
  1969. }
  1970. $retArr[] = $rankInfo;
  1971. }
  1972. }
  1973. if ($selfRank == null) {
  1974. $selfRank = self::initOtherUidRankInfo(req()->uid, 0);
  1975. }
  1976. UserProc::updateUserInfo();
  1977. $ret = array(
  1978. 'rankInfo' => $retArr,
  1979. 'selfRank' => $selfRank,
  1980. 'selfIsHasRank' => $selfIsHasRank,
  1981. );
  1982. return Resp::ok($ret);
  1983. }
  1984. /**
  1985. * 6827 当前轮次下 自己的最高伤害值
  1986. * @return type
  1987. */
  1988. public static function GetWorldBoss_RankDamageVal() {
  1989. $val = gMem()->zscore(self::GetWorldBoss_DamageMemKey(), req()->uid);
  1990. if ($val == null) {
  1991. $val = 0;
  1992. }
  1993. UserProc::updateUserInfo();
  1994. $ret = array(
  1995. 'DamageVal' => intval($val),
  1996. );
  1997. return Resp::ok($ret);
  1998. }
  1999. /**
  2000. * 6828 获取自己的排名信息
  2001. * @return type
  2002. */
  2003. public static function GetWorldBoss_GetSelfRank() {
  2004. // $lv = gMem()->zrevrank(self::GetWorldBoss_DamageMemKey(), req()->uid);
  2005. // if($lv == null){
  2006. // $lv = 0;
  2007. // }
  2008. $damageval = gMem()->zscore(self::GetWorldBoss_DamageMemKey(), req()->uid);
  2009. if ($damageval == null) {
  2010. $damageval = 0;
  2011. }
  2012. $ins_rank = self::initOtherUidRankInfo(req()->uid, $damageval, 3);
  2013. //$tsMemKey = MemKey_GameRun::WorldBoss_StartTs(req()->zoneid);
  2014. //$ts = gMem()->get($tsMemKey);
  2015. //ctx()->privateState->worldBoss_startTs = $ts;
  2016. UserProc::updateUserInfo();
  2017. $ret = array(
  2018. 'selfRank' => $ins_rank,
  2019. );
  2020. return Resp::ok($ret);
  2021. }
  2022. /**
  2023. * 6829 领取世界boss奖励
  2024. * @return type
  2025. */
  2026. public static function GetWorldBoss_ClaimRewards() {
  2027. list($damageValId) = req()->paras;
  2028. my_Assert(!in_array($damageValId, ctx()->privateState->worldBoss_received), ErrCode::active_hasgetted);
  2029. $val = gMem()->zscore(self::GetWorldBoss_DamageMemKey(), req()->uid);
  2030. if ($val == null) {
  2031. $val = 0;
  2032. }
  2033. my_Assert($damageValId <= $val, ErrCode::active_worldBoss_notClaimRewards);
  2034. $turnNum = self::GetCurTurnNum();
  2035. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  2036. my_Assert($turnnumMo != null, ErrCode::err_const_no);
  2037. $list = GameConfig::worldboss_demagereward_getItemArray($turnnumMo->orderId);
  2038. foreach ($list as $key => $mo) {
  2039. if ($mo->demageValId == $damageValId && $mo->orderId == $turnnumMo->orderId) {
  2040. StoreProc::AddMultiItemInStore($mo->reward);
  2041. break;
  2042. }
  2043. }
  2044. ctx()->privateState->worldBoss_received[] = $damageValId;
  2045. UserProc::updateUserInfo();
  2046. $ret = array(
  2047. 'store' => ctx()->store,
  2048. 'cash' => ctx()->baseInfo->cash,
  2049. 'reward' => StoreProc::$reward,
  2050. 'reward_Gem' => StoreProc::$reward_Gem,
  2051. 'reward_equip' => StoreProc::$reward_equip,
  2052. );
  2053. return Resp::ok($ret);
  2054. }
  2055. /**
  2056. * 6830 世界boss结算
  2057. */
  2058. public static function WorldBoss_settle() {
  2059. list($damageNum) = req()->paras; //战斗结束伤害值
  2060. //校验每个轮次最后10分钟, 不能战斗
  2061. my_Assert(FightProc::isFunUnlock(25), ErrCode::active_funUnlock);
  2062. $tag = true;
  2063. $curDay = TimeUtil::totalDays();
  2064. $turnNum = self::GetCurTurnNum();
  2065. $turnnumMo = GameConfig::worldboss_turnnum_getItem($turnNum);
  2066. if ($turnnumMo != null) {
  2067. $lastDay = TimeUtil::totalDays($turnnumMo->endTs);
  2068. if ($curDay == $lastDay && $turnnumMo->endTs - now() < 600) {
  2069. $tag = false;
  2070. }
  2071. }
  2072. if (ctx()->privateState->worldBoss_turnNum == 0) {
  2073. ctx()->privateState->worldBoss_turnNum = $turnNum;
  2074. }
  2075. if (ctx()->privateState->worldBoss_turnNum != $turnNum) {
  2076. ctx()->privateState->worldBoss_turnNum = $turnNum;
  2077. ctx()->privateState->worldBoss_received = array();
  2078. $tag = false;
  2079. }
  2080. if ($tag) {
  2081. self::Ranking_DamageVal($damageNum);
  2082. }
  2083. UserProc::updateUserInfo();
  2084. return Resp::ok(array());
  2085. }
  2086. // </editor-fold>
  2087. }