PVPProc.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * PVPProc pvp 战斗模块, 挑战玩家镜像
  5. * @version
  6. * 1.0.0 Created at 2017-6-26. by --gwang
  7. * @author gwang (mail@wanggangzero.cn)
  8. * @copyright ? 2017-6-26, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  9. */
  10. class PVPProc {
  11. /**
  12. * [6803] 挑战 - 查询对手信息 等级、头像、昵称、战队信息(言灵师,等级,星级,武器,技能,言灵)
  13. * @param req $req
  14. */
  15. public static function GetChallengeAdversaryInfo($req) {
  16. $targetUID = $req->paras[0]; # 参数: 对手的UID
  17. $uinfo = UserProc::getUserInfo($req->mem, $req->zoneid, $targetUID); # 读取玩家信息
  18. if (null == $uinfo) {
  19. Err(ErrCode::user_no_err);
  20. }
  21. $team = JsonUtil::decode($uinfo->game->heroTeamConfig);
  22. $heros = new \stdClass();
  23. $curTeamId = $team->curUseTeamID;
  24. foreach ($team->teamDic->$curTeamId->heros as $hid) {
  25. if ($hid > 0) {
  26. $n_hid = $hid - 10000;
  27. $heros->$n_hid = $uinfo->game->heros->collectHeros->$hid;
  28. }
  29. }
  30. $adversary = array(# # 拼装玩家信息
  31. 'uid' => $targetUID,
  32. 'name' => my_null_default($uinfo->game->name, ""),
  33. 'level' => my_null_default($uinfo->game->level, 1),
  34. 'headImg' => my_null_default($uinfo->game->img, ""),
  35. // 'skills' => null, # # skills暂时没有实例数据
  36. 'equipment' => array("equipments" => my_null_default($uinfo->game->store->equipment, new \stdClass())), # 武器
  37. 'yanling' => array("items" => my_null_default($uinfo->game->store->yanling, new \stdClass())), # 言灵
  38. 'heros' => my_null_default($heros, new \stdClass()), # # 英雄集合
  39. );
  40. $result = array(# # 拼装返回值
  41. "adversaryInfo" => $adversary
  42. );
  43. return Resp::ok($result);
  44. }
  45. const maxLogCount = 49;
  46. /**
  47. * [6804] 挑战 - 记录挑战结果
  48. * @param req $req
  49. */
  50. static function LogChallengeInfo($req) {
  51. // 参数: 对手uid,对手昵称,对手头像, 对战结果, 胜利者的留言(失败时无法留言"")
  52. list($targetUID, $name, $headImg, $win, $msg) = $req->paras;
  53. $key_mine = MemKey_User::OffensiveLog_zset($req->zoneid, $req->uid);
  54. $key_target = MemKey_User::DefensiveLog_zset($req->zoneid, $targetUID);
  55. $ts = now(); # 记录时间戳
  56. $req->mem->zadd($key_mine, array(# # 组装被挑战对手信息
  57. JsonUtil::encode(array(
  58. 'uid' => $targetUID,
  59. 'name' => $name,
  60. 'headImg' => $headImg,
  61. 'win' => $win,
  62. 'msg' => $msg,
  63. 'ts' => $ts
  64. )) => $ts));
  65. $req->mem->zremrangebyrank($key_mine, self::maxLogCount, -1); # 保留50条数据
  66. $req->mem->zadd($key_target, array(# # 组装挑战者信息
  67. JsonUtil::encode(array(
  68. 'uid' => $req->uid,
  69. 'name' => $req->userInfo->game->name,
  70. 'headImg' => $req->userInfo->game->img,
  71. 'win' => !$win,
  72. 'msg' => $msg,
  73. 'ts' => $ts
  74. )) => $ts));
  75. $req->mem->zremrangebyrank($key_target, self::maxLogCount, -1); # 保留50条数据
  76. // 暂无发放奖励流程
  77. // 更新每日任务
  78. // 返回
  79. return Resp::ok(); # 返回成功
  80. }
  81. /**
  82. * [6805] 挑战 - 拉取挑战记录
  83. * @param req $req
  84. */
  85. static function GetChagllengeLog($req) {
  86. // 参数:无
  87. $key_off = MemKey_User::OffensiveLog_zset($req->zoneid, $req->uid);
  88. $key_def = MemKey_User::DefensiveLog_zset($req->zoneid, $req->uid);
  89. // 拉取自己的挑战记录
  90. $offLog = $req->mem->zrange($key_off, 0, self::maxLogCount);
  91. $defLog = $req->mem->zrange($key_def, 0, self::maxLogCount);
  92. // Ps. 挑战记录分为2个榜, 且按照时间戳记录,晚于指定时间戳的判定为未读消息,挑战记录最多记录50条
  93. // if (!CommUtil::isPropertyExists($req->userInfo->game->privateState, "lastCheckDefLog")) {
  94. $req->userInfo->game->privateState->lastCheckDefLog_ts = now(); # 记录时间戳
  95. // }
  96. UserProc::updateUserInfo(); # 回写数据
  97. // 记录拉取时间戳(在主界面有个未读消息条数显示, 需要靠最后拉取时间戳对比, 时间戳之后的消息是未读消息)
  98. // 回传数据记录
  99. return Resp::ok(array(
  100. 'offLog' => $offLog,
  101. 'defLog' => $defLog
  102. ));
  103. }
  104. //
  105. // <editor-fold defaultstate="collapsed" desc=" 旧版PVP 681x ">
  106. //
  107. // /**
  108. // * 查找对手数量
  109. // */
  110. // const matchCount = 5;
  111. //
  112. // /**
  113. // * [6810] pvp 拉取主界面信息
  114. // * @param Req $req
  115. // */
  116. // static function pvpMainInfo($req) {
  117. // $mem = gMem();
  118. // $uid = $req->uid;
  119. // $zoneid = $req->zoneid;
  120. // $pvp = new UserPVPModel($req->userInfo->game->pvp); # 设计玩家pvp数据结构
  121. // $key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 积分总榜
  122. // $key_last = MemKey_GameRun::Game_PVPScoreByZone_zset_lastWeek($zoneid); # 上周积分榜
  123. // $score = self::_getScore_by_uid($req, $uid); # 取玩家当前pvp积分
  124. // $tsLastWeek = TimeUtil::tsWeek() - 1;
  125. // $lastWeekScore = $mem->zscore($key_last, $uid);
  126. // if (!in_array($tsLastWeek, $pvp->weeklyRewardRecords) # 尚未发放上周奖励
  127. // && $lastWeekScore) { # 并且上周活跃
  128. // $pvp->weeklyRewardRecords[] = $tsLastWeek; # 添加发奖记录
  129. // $leagueid = self::GetLeagueByScore($lastWeekScore); # 上周积分所处阶段
  130. // EmailProc::SendPvpLeagueReward($zoneid, $uid, $leagueid); # 阶段奖励
  131. // $pvp->clearWeekData(); # 每周清理胜率数据
  132. // $pvp->curMatches = self::getNewMatches($pvp, $mem, $uid, $zoneid); # 更新对手列表
  133. // $req->userInfo->game->pvp = $pvp;
  134. // UserProc::updateUserInfo();
  135. // }
  136. // self::sendLastRankReward($req); # 发放每周上榜人员奖励
  137. // self::UpdateChanlianInfo($req); # 更新蝉联数据(并发奖)
  138. // $pvp->score = $score; # 插入score数据
  139. // $rank = $mem->zrevrank($key, $uid); # 提取总榜排行信息
  140. // $pvp->rank = (is_null($rank) ? -1 : $rank + 1);
  141. // return Resp::ok($pvp); # 返回pvp数据
  142. // }
  143. //
  144. // /**
  145. // *
  146. // * @param Req $req
  147. // * @param type $uid
  148. // */
  149. // static function _getScore_by_uid($req, $uid) {
  150. // if ("" == $uid) {
  151. // CLog::err('"uid" is Null!');
  152. // return 10;
  153. // }
  154. // $mem = $req->mem;
  155. // $zoneid = $req->zoneid;
  156. // $key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 积分榜
  157. // $score = $mem->zscore($key, $uid);
  158. // if (!$score || $score <= 0) { # 分数异常
  159. // $leagueScore = GameConfig::pvp_leaguescore_getItem(1); # 新手基础分
  160. // $score = $leagueScore->minScore;
  161. // $mem->zadd($key, array($uid => $score)); # 更新玩家积分
  162. // $mem->zadd(MemKey_GameRun::Game_PVPScoreByZone_zset_curWeek($zoneid), array($uid => $score));
  163. // }
  164. // return $score;
  165. // }
  166. //
  167. // /**
  168. // *
  169. // * @param Req $req
  170. // * @param type $uid
  171. // * @param type $addValue Description
  172. // */
  173. // private static function _addScore_by_uid($req, $uid, $addValue) {
  174. // if ($addValue <= 0) { # 防御
  175. // return;
  176. // }
  177. // $mem = $req->mem;
  178. // $zoneid = $req->zoneid;
  179. // $key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 积分榜
  180. // $score = $mem->zscore($key, $uid);
  181. // if (!$score || $score <= 0) { # 分数异常
  182. // $leagueScore = GameConfig::pvp_leaguescore_getItem(1); # 新手基础分
  183. // $score = $leagueScore->minScore;
  184. // $mem->zadd($key, array($uid => $score)); # 重置玩家积分
  185. // }
  186. // $newscore = $mem->zincrby($key, $uid, $addValue); # 返回最新值
  187. // $mem->zadd(MemKey_GameRun::Game_PVPScoreByZone_zset_curWeek($zoneid), array($uid => $newscore));
  188. // return $newscore;
  189. // }
  190. //
  191. // /**
  192. // *
  193. // * @param type $req
  194. // * @param type $uid
  195. // * @param type $subValue
  196. // */
  197. // private static function _subScore_by_uid($req, $uid, $subValue) {
  198. // if ($subValue >= 0) { # 防御异常数值
  199. // return;
  200. // }
  201. // $mem = $req->mem;
  202. // $zoneid = $req->zoneid;
  203. // $key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 积分榜
  204. // $score = $mem->zscore($key, $uid);
  205. // $leagueScore = GameConfig::pvp_leaguescore_getItem(1); # 新手基础分
  206. // if (!$score || $score <= 0 #
  207. // || ($score + $subValue) <= $leagueScore->minScore) { # 分数异常
  208. // $score = $leagueScore->minScore; # 新手基础分
  209. // $mem->zadd($key, array($uid => $score)); # 重置玩家积分
  210. // } else {
  211. // $score = $mem->zincrby($key, $uid, $subValue); # 扣除积分并返回最新值
  212. // }
  213. // $mem->zadd(MemKey_GameRun::Game_PVPScoreByZone_zset_curWeek($zoneid), array($uid => $score)); # 同步记录
  214. // return $score;
  215. // }
  216. //
  217. // /**
  218. // * 发送上周上榜奖励
  219. // * @param Req $req
  220. // */
  221. // public static function sendLastRankReward($req) {
  222. // $mem = gMem();
  223. // $zoneid = $req->zoneid;
  224. // $tsweek = TimeUtil::tsWeek();
  225. // $key = MemKey_GameRun::Game_PVPRankRewardRecord_set($zoneid);
  226. // if (!$mem->sismember($key, $tsweek)) { # 上周榜单尚未处理, 每周只处理一次
  227. // // 上周是空的情况.
  228. // $lastKey = MemKey_GameRun::Game_PVPRankRewardRecord_byWeek_str($zoneid, $tsweek - 1);
  229. // $mem->sadd($key, $tsweek); # 添加处理记录
  230. // $key_total = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 拉取上榜人员
  231. // $uids = $mem->zrevrange($key_total, 0, 99);
  232. // $rank = 0;
  233. // foreach ($uids as $uid) {
  234. // EmailProc::SendPvpRankReward($zoneid, $uid, ++$rank); # 发送奖励邮件
  235. // }
  236. // $mem->add($lastKey, $uids);
  237. // }
  238. // }
  239. //
  240. // /**
  241. // * [6819] pvp - 拉取蝉联信息
  242. // * @param Req $req
  243. // */
  244. // static function getChanlianINfo($req) {
  245. // $zoneid = $req->zoneid;
  246. // $key = MemKey_GameRun::Game_PVP_Chanlian_normal($zoneid);
  247. // $pvpChanlian = new GamePvpChanlian(gMem()->get($key));
  248. // $pvpHistory = gMem()->hgetall(MemKey_GameRun::Game_PVP_Chanlian_History_hash($zoneid));
  249. // return Resp::ok(array(
  250. // 'info' => $pvpChanlian,
  251. // 'history' => array_values((array) $pvpHistory)
  252. // ));
  253. // }
  254. //
  255. // /**
  256. // * [6811] pvp 挑战对手xx
  257. // * @param Req $req
  258. // */
  259. // static function pvp_PK($req) {
  260. // $uid = $req->uid;
  261. // $target_uid = $req->paras[0]; # 对手id
  262. // $result = $req->paras[1]; # 胜负结果 0负,1胜
  263. // $pvp = $req->userInfo->game->pvp;
  264. // if (!property_exists($pvp->curMatches, $target_uid)//
  265. // or property_exists($pvp->curMatches->$target_uid, 'killed')) { # 对手已被ko
  266. // return Resp::err(ErrCode::pvp_wrongMather);
  267. // }
  268. // $g = glc();
  269. // if (now() - $pvp->tiliTs > $g->PVP_reCover_Tili_costSec * 5) { # 检查并扣除体力
  270. // $pvp->tiliTs = now() - $g->PVP_reCover_Tili_costSec * 5;
  271. // }
  272. // if ($pvp->tiliExtra > 0) { # 优先扣除溢出值
  273. // $pvp->tiliExtra--;
  274. // } else {
  275. // $pvp->tiliTs += $g->PVP_reCover_Tili_costSec;
  276. // if ($pvp->tiliTs > now()) {
  277. // return Resp::err(ErrCode::pvp_wrongtili);
  278. // }
  279. // }
  280. //# 发放对应奖励并记录挑战记录
  281. // $score = 0;
  282. // if ($result) { # 1 胜, 奖金币、积分、pvp币
  283. // UserGameModel::Add_Gold($req->userInfo->game, $g->PVP_PK_Win_Gold);
  284. // # × 奖励积分的公式: 获胜基础奖励积分 + 积分差距修正系数 * 积分差
  285. // # 挑战胜利, 积分改为固定值.
  286. // $winnerGainScore = $g->PVP_PK_Win_Score; # 本局得分
  287. // $score = self::_addScore_by_uid($req, $uid, intval($winnerGainScore)); # 增加积分
  288. // $pvp->pvpCoins += $g->PVP_PK_Win_PvpCoin; # 发放金币
  289. // self::_subScore_by_uid($req, $target_uid, -intval($g->PVP_PK_be_defeated_score)); # 给对手扣除积分
  290. // $pvp->contWin++; # 连胜记录
  291. // $pvp->winTimes++; # 获胜记录
  292. // $all = true; # 全部战胜标记
  293. // foreach ($pvp->curMatches as $pid => &$p) {
  294. // if ($pid == $target_uid) { #
  295. // $p->killed = 1; # 添加ko标志
  296. // if (property_exists($p, 'fog')) {
  297. // $score = self::_addScore_by_uid($req, $uid, intval($winnerGainScore)); # 神秘对手, 积分翻倍(再加一遍)
  298. // }
  299. // }
  300. // if (!property_exists($p, 'killed')) {
  301. // $all = false; # 尚未全部战胜
  302. // }
  303. // }
  304. // if ($all) { # 全部战胜之后,刷新对手
  305. // $pvp->curMatches = self::getNewMatches($pvp, $req->mem, $req->uid, $req->zoneid);
  306. // $pvp->nextRefreshTs = now(glc()->PVP_refresh_Match_RecoverSeconds);
  307. // }
  308. // } else { # 0 挑战失败 只扣除积分
  309. // # × 奖励积分的公式: 获胜基础奖励积分 + 积分差距修正系数 * 积分差
  310. // # 挑战失败, 扣除固定积分
  311. // $loserGainScore = $g->PVP_PK_Fail_Score;
  312. // $score = self::_subScore_by_uid($req, $uid, -intval($loserGainScore)); # 扣除积分
  313. // self::_addScore_by_uid($req, $target_uid, intval($g->PVP_PK_be_undefeated_score)); # 给对手发放积分
  314. // $pvp->contWin = 0; # 连胜置零
  315. // }
  316. // if (property_exists($pvp->curMatches, $target_uid) && property_exists($pvp->curMatches->$target_uid, 'fog')) {
  317. // unset($pvp->curMatches->$target_uid->fog);
  318. // }
  319. // $pvp->totalTimes++;
  320. // $leagueid = self::GetLeagueByScore($score);
  321. // if ($pvp->leagueId != $leagueid) {
  322. // $pvp->leagueId = $leagueid;
  323. // SystemProc::PVP_league($req->zoneid, $req->userInfo->game, $leagueid);
  324. // }
  325. // $pvp->actives++;
  326. // $pvp->dailyPkCnt++;
  327. // $req->userInfo->game->pvp = $pvp;
  328. ////todo: debuging...
  329. // UserProc::updateUserInfo(); # 回写数据
  330. // $ret = array(
  331. // 'contWin' => $pvp->contWin,
  332. // 'leagueId' => $pvp->leagueId,
  333. // 'newscore' => $score, # # 返回最新积分
  334. // );
  335. // return Resp::ok($ret);
  336. // }
  337. //
  338. // /**
  339. // * [6812] pvp 刷新对手
  340. // * @param Req $req
  341. // */
  342. // static function pvp_Refresh($req) {
  343. // $amt = $req->paras[0]; # 提取 params , 验证下花费
  344. // $pvp = new UserPVPModel($req->userInfo->game->pvp);
  345. // $ts = now();
  346. // if ($amt <= 0) { # 免费情况
  347. // if ($pvp->nextRefreshTs > $ts) { # 验证时间
  348. // return Resp::err(ErrCode::pvp_refresh_time);
  349. // }
  350. // } else { # 扣除钻石刷新的情况
  351. // $priceArr = explode(',', glc()->PVP_reFresh_Match_cost); # 价格
  352. // if (count($priceArr) < $pvp->dailyRefreshMatchTimes) { # 超过最大刷新次数
  353. // return Resp::err(ErrCode::pvp_refresh_max);
  354. // }
  355. // $costCash = $priceArr[$pvp->dailyRefreshMatchTimes++]; # 查找对应的定价, 并计次
  356. // if ($costCash != $amt) { # 跟预期值不一致,
  357. // return Resp::err(ErrCode::pvp_refresh_cost_ilegal);
  358. // }
  359. // if (!UserGameModel::Consume_Cash($req->userInfo->game, $costCash)) {# 扣除钻石失败
  360. // return Resp::err(ErrCode::notenough_cash_msg);
  361. // }
  362. // }
  363. //
  364. // $pvp->curMatches = self::getNewMatches($pvp, $req->mem, $req->uid, $req->zoneid);
  365. // $pvp->nextRefreshTs = now(glc()->PVP_refresh_Match_RecoverSeconds);
  366. // $req->userInfo->game->pvp = $pvp;
  367. // UserProc::updateUserInfo(); # 回写数据
  368. //
  369. // $ret = array(
  370. // 'nextRefreshTs' => $pvp->nextRefreshTs, # # 下次免费刷新的时间戳
  371. // 'dailyRefreshMatchTimes' => $pvp->dailyRefreshMatchTimes,
  372. // 'curMatches' => $pvp->curMatches # # 当前对手清单
  373. // );
  374. // return Resp::ok($ret);
  375. // }
  376. //
  377. // /**
  378. // * [6813] 购买体力 v2.0 阶梯定价.
  379. // * @param Req $req
  380. // * @return type
  381. // */
  382. // static function pvp_buytili($req) {
  383. // $amt = $req->paras[0]; # 验证下本次扣除的钻石数量
  384. // $pvp = new UserPVPModel($req->userInfo->game->pvp);
  385. // $g = glc();
  386. // $curTili = intval((now() - $pvp->tiliTs) / $g->PVP_reCover_Tili_costSec);
  387. // if ($curTili > 5) {
  388. // $curTili = 5;
  389. // }
  390. // if ($pvp->tiliExtra > 0) { # 体力溢出值大于0的时候不要购买
  391. // return Resp::err(ErrCode::pvp_tili_chargenum);
  392. // }
  393. // $priceArr = explode(',', $g->PVP_recover_tili_cost_cash);
  394. //
  395. // if (count($priceArr) < $pvp->dailyBuyTiliTimes) {
  396. // return Resp::err(ErrCode::pvp_tili_soldout);
  397. // }
  398. // $costCash = $priceArr[$pvp->dailyBuyTiliTimes++]; # 查找对应的定价, 并计次
  399. // if ($costCash != $amt) { # 跟预期值不一致,
  400. // return Resp::err(ErrCode::pvp_tili_cost_ilegal);
  401. // }
  402. // if (!UserGameModel::Consume_Cash($req->userInfo->game, $costCash)) { # 扣除钻石失败
  403. // return Resp::err(ErrCode::notenough_cash_msg);
  404. // }
  405. // if ($curTili > 0) { # 增加溢出值
  406. // $pvp->tiliExtra = $curTili;
  407. // }
  408. //
  409. // $pvp->tiliTs = now() - ( 5 * $g->PVP_reCover_Tili_costSec); # 补满
  410. // $req->userInfo->game->pvp = $pvp;
  411. // UserProc::updateUserInfo(); # 回写玩家数据
  412. // $ret = array(
  413. // 'tiliTs' => $pvp->tiliTs,
  414. // 'tiliExtra' => $pvp->tiliExtra,
  415. // 'costCash' => $costCash,
  416. // 'dailyBuyTiliTimes' => $pvp->dailyBuyTiliTimes,
  417. // 'userCash' => $req->userInfo->game->cash
  418. // );
  419. // return Resp::ok($ret); # 返回
  420. // }
  421. //
  422. // /**
  423. // * [6814] pvp 拉取榜单数据
  424. // * @param Req $req
  425. // */
  426. // static function pvp_getRank($req) {
  427. // $maxAmt = 10; # 一次最多取10个玩家信息
  428. // $zoneid = $req->zoneid;
  429. // $index = $req->paras[0]; # 起始(0)
  430. // $n = $req->paras[1]; # 数量, (n<=max)
  431. //
  432. // if ($n < 1 || $n > $maxAmt) { # 防御非法情况
  433. // $n = $maxAmt;
  434. // }
  435. // $arr = self::getRankPlayers($req->mem, $zoneid, $index - 1, ($index + $n) - 1);
  436. //
  437. // $rankId = $index;
  438. // $result = ObjectInit();
  439. // if (count($arr)) {
  440. // foreach ($arr as $key => $value) {//$value 的数据类型是array
  441. // $value["uid"] = $key;
  442. // $result->$rankId = $value;
  443. // $rankId += 1;
  444. // }
  445. // }
  446. // $ret = array(
  447. // 'arr' => $result
  448. // );
  449. // return Resp::ok($ret);
  450. // }
  451. //
  452. // /**
  453. // * [6815] pvp 领取活跃度奖励
  454. // * @param Req $req
  455. // */
  456. // static function pvp_drawacitverewards($req) {
  457. // $rewardId = $req->paras[0]; # 提取参数
  458. // $reward = GameConfig::pvp_activityreward_getItem($rewardId);
  459. // if (!$reward) {
  460. // return Resp::err(ErrCode::err_const_no);
  461. // }
  462. // $pvp = new UserPVPModel($req->userInfo->game->pvp);
  463. // if ($reward->activityNum > $pvp->actives) {
  464. // return Resp::err(ErrCode::pvp_activenotenough);
  465. // }
  466. // $pvp->actives = 0; # 活跃记录直接清零
  467. // $req->userInfo->game->pvp = $pvp; # 回写pvp数据
  468. // $err = StoreProc::AddMultiItemInStore($req, $reward->reward1); # 发放奖励
  469. // if ($err) {
  470. // return Resp::err($err);
  471. // }
  472. // UserProc::updateUserInfo(); # 回写玩家数据
  473. // $ret = array(# # 返回值
  474. // 'actives' => $pvp->actives, // # 最新的 活跃度值
  475. // 'store' => $req->userInfo->game->store, // # 获得奖励之后的玩家仓库信息
  476. // 'hero' => $req->userInfo->game->heros, // # 获得奖励之后的玩家英雄信息
  477. // 'reward' => $reward->reward1,
  478. // );
  479. // return Resp::ok($ret);
  480. // }
  481. //
  482. //// ---------------- 辅助函数 -----------------------
  483. //
  484. // /**
  485. // * 清理每日计数器
  486. // * @param Req $req
  487. // */
  488. // public static function ClearDailyPkcnt($req) {
  489. // $pvp = new UserPVPModel($req->userInfo->game->pvp);
  490. // $pvp->dailyPkCnt = 0;
  491. // $pvp->dailyBuyTiliTimes = 0;
  492. // $pvp->dailyRefreshMatchTimes = 0;
  493. // $pvp->dailyMatchRecord = array($req->uid); # 屏蔽自己
  494. // $pvp->curMatches = self::getNewMatches($pvp, $req->mem, $req->uid, $req->zoneid); # added by: 李宁,2017年8月1日 11:45:41
  495. // $pvp->nextRefreshTs = tsDay() * 86400 + glc()->PVP_refresh_Match_RecoverSeconds;
  496. // $req->userInfo->game->pvp = $pvp;
  497. // }
  498. //
  499. // /**
  500. // * 更新蝉联信息(并发奖,如果有)
  501. // * @param Req $req
  502. // */
  503. // private static function UpdateChanlianInfo($req) {
  504. // $zoneid = $req->zoneid;
  505. // $tsWeek = TimeUtil::tsWeek();
  506. // $key = MemKey_GameRun::Game_PVP_Chanlian_normal($zoneid);
  507. //// $key_lastWeek = MemKey_GameRun::Game_PVPScoreByZone_zset_lastWeek($zoneid);
  508. // $pvpChanlian = new GamePvpChanlian(gMem()->get($key));
  509. // if ($pvpChanlian->tsWeek == $tsWeek) {
  510. // return; # 已处理
  511. // }
  512. // $pvpChanlian->tsWeek = $tsWeek;
  513. // $arr_1 = gMem()->zrevrange(MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid), 0, 0);
  514. // $uid = $arr_1[0]; # 取上次第一
  515. // if ($uid == $pvpChanlian->uid) { # 蝉联了
  516. // $pvpChanlian->times++;
  517. // if ($pvpChanlian->times == 3) { # 达到3次, 完成蝉联, 发放奖励
  518. // EmailProc::SendPvpChanlianReward($zoneid, $uid); # 发放奖励
  519. // $historyKey = MemKey_GameRun::Game_PVP_Chanlian_History_hash($zoneid);
  520. // gMem()->hset($historyKey, $tsWeek, $pvpChanlian->userInfo); # 进入历届榜
  521. // }
  522. // if ($pvpChanlian->times > 3) { # 第四次蝉联的时候
  523. // $pvpChanlian->times -= 3; # 循环蝉联计数信息
  524. // }
  525. // } else { # 替换掉上一届
  526. // $arr = self::GetPlayerInfosForPVP(gMem(), $zoneid, array($uid => 100)); # 提取玩家信息
  527. // $pvpChanlian->userInfo = $arr[$uid]; # 更新蝉联玩家信息
  528. // $pvpChanlian->uid = $uid; # 玩家ID
  529. // $pvpChanlian->times = 1; # 首次
  530. // }
  531. // gMem()->set($key, $pvpChanlian); # 回写数据
  532. // }
  533. //
  534. // <editor-fold defaultstate="collapsed" desc=" 辅助 函数 ">
  535. //
  536. // /**
  537. // * 依据积分获得所在阶段的id
  538. // * @param type $curScore
  539. // * @return int
  540. // */
  541. // private static function GetLeagueByScore($curScore) {
  542. // foreach (GameConfig::pvp_leaguescore() as $id => $lg) {
  543. // isEditor() and $lg = new sm_pvp_leaguescore;
  544. // if ($lg->maxScore >= $curScore && $lg->minScore <= $curScore) {
  545. // return $id;
  546. // }
  547. // }
  548. // return 1; # 找不到对应所属阶段的时候,返回 默认值 1
  549. // }
  550. //
  551. // /**
  552. // * 获取对手匹配结果
  553. // * @param UserPVPModel $pvp
  554. // * @param CRedisutil $mem
  555. // * @param type $uid
  556. // * @param type $zoneid
  557. // */
  558. // private static function getNewMatches($pvp, $mem, $uid, $zoneid) {
  559. // $arr = array();
  560. // $key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid);
  561. // self::findmatcher($zoneid, $key, $uid, $pvp, $arr); # 积分榜查找
  562. // if (count($arr) < self::matchCount) { # 如果没有凑足人数,战斗力候补来源,
  563. // $keyfp = MemKey_GameRun::Game_FightPowerRank_zset($zoneid);
  564. // self::findmatcher($zoneid, $keyfp, $uid, $pvp, $arr); # 从战斗力榜找
  565. // }
  566. // if (count($arr) < self::matchCount) { # 再不行, 准备机器人吧
  567. //// todo: 这里引入gm对手数据,
  568. // CLog::err('PVP刷对手数量不足, 赶快考虑加入机器人.', 'PVP');
  569. // }
  570. // $ret = self::GetPlayerInfosForPVP($mem, $zoneid, $arr);
  571. // $keys = array_keys($ret);
  572. // $k = $keys[0];
  573. // $v = $ret[$k];
  574. // $v['fog'] = true;
  575. // $ret[$k] = $v;
  576. //// var_dump($v);
  577. //// echoLine(JsonUtil::encode($ret[$k]));
  578. // return $ret;
  579. // }
  580. //
  581. // /**
  582. // * 查找匹配的对手
  583. // * @param type $zoneid
  584. // * @param type $key
  585. // * @param type $uid
  586. // * @param UserPVPModel $pvp
  587. // * @param type $arr
  588. // */
  589. // private static function findmatcher($zoneid, $key, $uid, &$pvp, &$arr) {
  590. // $mem = gMem();
  591. // $rank = $mem->zrevrank($key, $uid); # 直接查排名
  592. // $zlen = $mem->zlen($key); # 数据长度
  593. // $i = 0; # 计数器
  594. // $b = false; # 上下标志位
  595. // while (count($arr) < self::matchCount && $i < 50) { # 找够数量为止,或者查找超过100个位置, 跳出查找
  596. // $index = $rank + ($b ? - $i : $i);
  597. //// todo: 这里引入连胜/连负修正系数.
  598. // $b = !$b;
  599. // if ($b) { # 变化查找方向
  600. // $i++; #
  601. // }
  602. // if ($index < 0 || $index >= $zlen) { # 跳过不合理位置
  603. // continue;
  604. // }
  605. // $back = $mem->zrevrange($key, $index, $index, true); # 取1个人
  606. // if (count($back) <= 0) {
  607. // continue;
  608. // }
  609. // $us = array_keys($back);
  610. // $d_uid = $us[0];
  611. // if ($d_uid == $uid) { # 避开自己
  612. // continue;
  613. // }
  614. // $user = $mem->get(MemKey_User::Info_hash($zoneid, $d_uid));
  615. // if (null == $user) {
  616. // continue;
  617. // }
  618. // $fp = HeroProc::CalcTeamFightPower($zoneid, $d_uid, $user);
  619. // if ($fp > 0) {
  620. //// $pvp->dailyMatchRecord
  621. // if (!in_array($d_uid, $pvp->dailyMatchRecord)) { # 已经匹配过的对手不在出现
  622. // $arr[$d_uid] = $back[$d_uid];
  623. // $pvp->dailyMatchRecord[] = $d_uid;
  624. // }
  625. // }
  626. // }
  627. // }
  628. //
  629. // /**
  630. // * 获取榜单玩家
  631. // * @param Credisutil $mem
  632. // * @param int $zoneid
  633. // * @param int $start
  634. // * @param int $stop
  635. // * @return type
  636. // */
  637. // private static function getRankPlayers($mem, $zoneid, $start, $stop) {
  638. // $key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid);
  639. // $retUidsWithScore = $mem->zrevrange($key, $start, $stop, true);
  640. // return self::GetPlayerInfosForPVP($mem, $zoneid, $retUidsWithScore);
  641. // }
  642. //
  643. // /**
  644. // * 拉取玩家信息-pvp模块专用信息
  645. // * @param CredisUtil $mem
  646. // * @param type $zoneid
  647. // * @param type $retUidsWithScore
  648. // * @return type
  649. // */
  650. // private static function GetPlayerInfosForPVP($mem, $zoneid, $retUidsWithScore) {
  651. //// var_dump($retUidsWithScore);
  652. // $retUids = array_keys($retUidsWithScore);
  653. // $keysOfUserInfo = array_map(function($u)use($zoneid) {
  654. // return MemKey_User::Info_hash($zoneid, $u);
  655. // }, $retUids);
  656. // $arrUserInfos = $mem->getMulti($keysOfUserInfo);
  657. // $arr = ArrayInit();
  658. // $i = 0;
  659. // foreach ($arrUserInfos as $userGameInfo) {
  660. // isEditor() && $userGameInfo = new UserGameModel;
  661. // $uid = $retUids[$i++];
  662. //// $sharedHeroId = $userGameInfo->heros->firendSupportHeroUID;
  663. // $team = JsonUtil::decode('{"teamLeader": 0,"heros":{}}');
  664. // $teamConfig = JsonUtil::decode($userGameInfo->heroTeamConfig);
  665. // if ($teamConfig && $teamConfig->curUseTeamID > 0) {
  666. // $heros = ObjectInit();
  667. // $teamid = $teamConfig->curUseTeamID;
  668. // $heros_uid = $teamConfig->teamDic->$teamid->heros;
  669. // $m = 0;
  670. // foreach ($heros_uid as $heroid) {
  671. // $m++;
  672. // $heros->$m = $heroid ? self::getHeroInfoForShare($userGameInfo, $heroid) : null;
  673. // }
  674. // $team = array(
  675. // 'teamLeader' => $teamConfig->teamDic->$teamid->teamLeader,
  676. // 'heros' => $heros
  677. // );
  678. // }
  679. //
  680. // $pvp = StlUtil::array2class(array('contWin' => '', 'totalTimes' => '', 'winTimes' => '', 'leagueId' => ''));
  681. // CommUtil::loadObject($userGameInfo->pvp, $pvp); # 提取pvp数据
  682. // $arr[$uid] = array(
  683. // 'img' => $userGameInfo->img,
  684. // 'imgBorderId' => $userGameInfo->imgBorderId,
  685. //// 'sharedHero' => self::getHeroInfoForShare($userGameInfo, $sharedHeroId),
  686. // 'lastLoginTs' => isset($userGameInfo->lastLogin) ? $userGameInfo->lastLogin : 0,
  687. // 'nickname' => $userGameInfo->name,
  688. // 'pvp' => $pvp,
  689. // 'score' => $retUidsWithScore[$uid],
  690. // 'level' => $userGameInfo->level,
  691. // 'uid' => $uid,
  692. // 'heroTeamConfig' => $team # 战队配置
  693. // );
  694. // }
  695. // if (count($arr) <= 0) {
  696. // $arr = null;
  697. // }
  698. // return $arr;
  699. // }
  700. //
  701. // /**
  702. // * 提取英雄信息以供其他人使用
  703. // * @param type $userInfo
  704. // * @param type $heroId
  705. // * @return UserHeroModel
  706. // */
  707. // public static function getHeroInfoForShare($userInfo, $heroId) {
  708. // if ($heroId) {
  709. // $heroInfo = $userInfo->heros->collectHeros->$heroId;
  710. // } else { // todo: 暂定如果没有设置共享英雄,默认取集合中第一个英雄, 征询策划是否修订规则
  711. // $coll = $userInfo->heros->collectHeros;
  712. // $keys = array_keys((array) $coll);
  713. // if (count($keys) <= 0) {
  714. // return null; // 暴力跳过, 防止出现更大的错误
  715. // }
  716. // $heroId = $keys[0];
  717. // $heroInfo = $userInfo->heros->collectHeros->$heroId;
  718. // }
  719. //// 额外将英雄的装备数据替换为实例数据
  720. // self::getArmor($userInfo, $heroInfo, 'weapon');
  721. // self::getArmor($userInfo, $heroInfo, 'armor');
  722. // self::getArmor($userInfo, $heroInfo, 'ring');
  723. // return $heroInfo;
  724. // }
  725. //
  726. // private static function getArmor($userInfo, $hero, $armor) {
  727. // if (isset($hero->equip->$armor)) {
  728. // if (property_exists($hero->equip->$armor, 'itemuid')) {
  729. // $armorid = $hero->equip->$armor->itemuid;
  730. // if ($armorid > 0 && isset($userInfo->store->equipment->$armorid)) {
  731. // $hero->equip->$armor = $userInfo->store->equipment->$armorid;
  732. // return; # 找到后直接跳出
  733. // }
  734. // }
  735. // }
  736. // $hero->equip->$armor = null;
  737. // }
  738. // </editor-fold>
  739. //
  740. // </editor-fold>
  741. //
  742. }