FightProc.php 90 KB

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