FightProc.php 91 KB

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