/**
* 挑战记录最大条数
*/
const maxLogCount = 49;
/**
* 查找对手数量
*/
const matchCount = 5;
/**
* 竞技场赛季起始时间戳
*/
const pvpStartTs = 1588521600; # 2020年5月4日 0时0分0秒
/**
* 每个赛季持续时常
*/
const pvpSeasonLengt = 86400 * 14; # 2周
/**
* 竞技场初始积分
*/
const pvpBaseScore = 1000;
/**
* 竞技场 最大上榜人数
*/
const pvpMaxRank = 500;
//
/**
* [6803] 挑战 - 查询对手信息 等级、头像、昵称、战队信息(言灵师,等级,星级,武器,技能,言灵)
* @param req $req
*/
public static function GetChallengeAdversaryInfo($req) {
$targetUID = $req->paras[0]; # 参数: 对手的UID
$uinfo = UserProc::getUserInfo($req->mem, $req->zoneid, $targetUID); # 读取玩家信息
if (null == $uinfo) {
Err(ErrCode::user_no_err);
}
$team = JsonUtil::decode($uinfo->game->heroTeamConfig);
$heros = new \stdClass();
$curTeamId = $team->curUseTeamID;
$arr_nil = array();
var_dump($team->teamDic->$curTeamId);
foreach ($team->teamDic->$curTeamId->heros as $i => $hid) {
if ($hid > 0) {
$n_hid = $hid - 10000;
$heros->$n_hid = $uinfo->game->heros->collectHeros->$hid;
}
}
$adversary = array(# # 拼装玩家信息
'uid' => $targetUID,
'name' => my_null_default($uinfo->game->name, ""),
'level' => my_null_default($uinfo->game->level, 1),
'headImg' => my_null_default($uinfo->game->img, ""),
// 'skills' => null, # # skills暂时没有实例数据
'equipment' => array("equipments" => my_null_default($uinfo->game->store->equipment, new \stdClass())), # 武器
'yanling' => array("items" => my_null_default($uinfo->game->store->yanling, new \stdClass())), # 言灵
'heros' => my_null_default($heros, new \stdClass()), # # 英雄集合
);
$result = array(# # 拼装返回值
"adversaryInfo" => $adversary
);
return Resp::ok($result);
}
/**
* [6804] 挑战 - 记录挑战结果
* @param req $req
*/
static function LogChallengeInfo($req) {
// 参数: 对手uid,对手昵称,对手头像, 对战结果, 胜利者的留言(失败时无法留言"")
list($targetUID, $name, $headImg, $win, $msg) = $req->paras;
$key_mine = MemKey_User::OffensiveLog_zset($req->zoneid, $req->uid);
$key_target = MemKey_User::DefensiveLog_zset($req->zoneid, $targetUID);
$ts = now(); # 记录时间戳
$req->mem->zadd($key_mine, array(# # 组装被挑战对手信息
JsonUtil::encode(array(
'uid' => my_null_default($targetUID, "-"),
'name' => my_null_default($name, ""),
'headImg' => my_null_default($headImg, ""),
'win' => my_null_default($win, false),
'msg' => my_null_default($msg, ""),
'ts' => $ts
)) => $ts));
$req->mem->zremrangebyrank($key_mine, self::maxLogCount, -1); # 保留50条数据
$req->mem->zadd($key_target, array(# # 组装挑战者信息
JsonUtil::encode(array(
'uid' => $req->uid,
'name' => $req->userInfo->game->name,
'headImg' => $req->userInfo->game->img,
'win' => !my_null_default($win, false),
'msg' => my_null_default($msg, ""),
'ts' => $ts
)) => $ts));
$req->mem->zremrangebyrank($key_target, self::maxLogCount, -1); # 保留50条数据
// 暂无发放奖励流程
// 更新每日任务
// 返回
return Resp::ok(); # 返回成功
}
/**
* [6805] 挑战 - 拉取挑战记录
* @param req $req
*/
static function GetChagllengeLog($req) {
// 参数:无
$key_off = MemKey_User::OffensiveLog_zset($req->zoneid, $req->uid);
$key_def = MemKey_User::DefensiveLog_zset($req->zoneid, $req->uid);
// 拉取自己的挑战记录
$offLog = $req->mem->zrange($key_off, 0, self::maxLogCount);
$defLog = $req->mem->zrange($key_def, 0, self::maxLogCount);
// Ps. 挑战记录分为2个榜, 且按照时间戳记录,晚于指定时间戳的判定为未读消息,挑战记录最多记录50条
// if (!CommUtil::isPropertyExists($req->userInfo->game->privateState, "lastCheckDefLog")) {
$req->userInfo->game->privateState->lastCheckDefLog_ts = now(); # 记录时间戳
// }
UserProc::updateUserInfo(); # 回写数据
// 记录拉取时间戳(在主界面有个未读消息条数显示, 需要靠最后拉取时间戳对比, 时间戳之后的消息是未读消息)
// 回传数据记录
array_walk($offLog, function (&$i) {
$i = JsonUtil::decode($i);
});
array_walk($defLog, function (&$i) {
$i = JsonUtil::decode($i);
});
return Resp::ok(array(
'offLog' => $offLog,
'defLog' => $defLog
));
}
//
//
/**
* 取当前赛季的编号(从赛季起始开始算起)
* @return int
*/
public static function GetCurSeasonID() {
$n = ceil((now() - self::pvpStartTs ) / self::pvpSeasonLengt); # 进一取整
return $n;
}
/**
* 取指定赛季的结束时间戳
* @param int $seasonID
* @return int
*/
public static function GetSeasonEndTs($seasonID) {
$ts = self::pvpStartTs + $seasonID * self::pvpSeasonLengt; # 从起始点开始 + n个赛季时常
return $ts;
}
/**
* [6810] 竞技场 拉取主界面信息
* @param Req $req
*/
static function pvpMainInfo($req) {
$uid = $req->uid; # 快速访问UID
$zoneid = $req->zoneid; # 快速访问zoneid
$pvp = new UserPVPModel($req->userInfo->game->pvp); # 设计玩家pvp数据结构
$seasonId = self::GetCurSeasonID(); # 当前赛季ID
$key = MemKey_GameRun::Game_PVPScoreByZoneSeason_zset($zoneid, $seasonId); # 积分总榜
// 玩家数据
// 积分 + 排名
// 总战力
// 战报小红点
// 对手列表
// =======
// 检查昨日奖励是否发放
// 检查赛季奖励是否发放
// 返回
$score = self::_getScore_by_uid($uid, $key); # 玩家积分
$rank = self::_getRank_by_uid($uid, $key); # 玩家排名
$fPower = HeroProc::CalcUserFightPower($zoneid, $uid, $req->userInfo->game); # 玩家总战力?还是当前防守队伍的战斗力?
$bHasNewLog = true; // todo: 真正查询是否有新战报
$matches = self::getNewMatches($pvp, gMem(), $uid, $zoneid); # 获得新的匹配对手
if ($pvp->haventReward_season > 0 && $pvp->haventReward_season < $seasonId) { # 尚未发放上赛季奖励
$haventKey = MemKey_GameRun::Game_PVPScoreByZoneSeason_zset($zoneid, $pvp->haventReward_season);
// todo:发放上周奖励邮件
}
if ($pvp->haventReward_tsDay > 0 && $pvp->haventReward_tsDay < tsDay()) { # 尚未发放昨天奖励
$haventKey_day = MemKey_GameRun::Game_PVPScoreByZone_zset_Day($zoneid, $day);
if (gMem()->exists($haventKey_day)) { # 昨天的积分记录不存在
gMem()->zcopy($key, $haventKey_day); # 复制一份当前积分作为昨天的截止积分榜
}
// todo:发放昨天奖励
}
// 组装 返回值结构
$ret = array(
'score' => $score, # # 自己的积分
'rank' => $rank, # # 自己的排名
'pvpCoins' => $pvp->pvpCoins, # # 自己的竞技币
'fPower' => $fPower, # # 自己的总战力
'fightTicket' => $pvp->fightTicket, # # 自己的挑战票
'defTeam' => $pvp->defTeam, # # 自己的防守队伍
'bHasNewFightLog' => $bHasNewLog, # # 是否有战报刷新
'matches' => $matches, # # 对手列表
);
return Resp::ok($ret); # 返回
}
//
//
//
/**
* [6820] 竞技商店 主界面
* @param type $req
*/
public static function pvpShopMain($req) {
// 商品列表
// 检查刷新时间 刷新商品列表
// 返回
}
/**
* [6821] 竞技 商店 购买道具
* @param type $req
*/
public static function pvpShopBuy($req) {
// 查询物品配置数据
// 扣除竞技币
// 发放道具
// 回写数据
// 返回
}
/**
* [6822] 竞技 商店 刷新道具
* @param type $req
*/
public static function pvpShopRefresh($req) {
// 扣除刷新消耗
// 更新刷新时间
// 重刷道具
// 回写数据
// 返回
}
/**
* 【移动支付】获取神秘商城物品
* 刷新规则: 根据玩家拥有的英雄、装备、道具等数据进行刷新。(因英雄、道具、装备数量不足以支撑该刷新规则,目前先按照随机刷新做,几率平等)
* @param Req $req
*/
public static function m_pay_getDynamic($req) {
$user = $req->userInfo->game;
$userSecretshop = new userSecretshopModel($user->userSecretshop);
// 参数提取
$refreshType = $req->paras[0]; # 刷新类型(参数)0,不刷,1,免费刷,2,钻石刷
switch ($refreshType) {
case 1: # 免费刷
if (now() < $userSecretshop->lastRefreshTs + glc()->secretshop_refresh_interval) { // 检查是否达到免费刷新时间了, 执行自动更新
return Resp::err(ErrCode::pay_secretshopt_freeRefresh_Time);
}
break;
case 2: # 钻石刷
if (glc()->secretshop_refresh_maxtimes <= $userSecretshop->refreshedTimes) { // 检查刷新次数, 已达上限, 返回错误信息
return Resp::err(ErrCode::pay_refresh_times);
} # 可以继续刷新,
$cishu = $userSecretshop->refreshedTimes + 1; # 下次
$amt = GameConfig::secretshop_refresh_getItem($cishu)->price;
if (!UserGameModel::Consume_Cash($user, $amt)) { # 扣除本次所需费用, 余额不足, 返回错误信息
return Resp::err(ErrCode::notenough_cash_msg);
}
$userSecretshop->refreshedTimes++; # 增加当天付费刷新计数
break;
case 0: # 不刷
default : # 默认不刷
// do nothing.
break;
}
if ($refreshType != 0) { # 是否刷新
$err = self::refreshDynamicShopItems($req, $userSecretshop); # 更新物品表
if ($err) {
return Resp::err($err);
}
$user->userSecretshop = $userSecretshop;
$req->userInfo->game = $user;
UserProc::updateUserInfo();
}
// 返回最新物品表
return Resp::ok(array(# # 成功后将最新的玩家数据返回给客户端
'gold' => $user->gold,
'tili' => $user->tili,
'cash' => $user->cash,
'uss' => $userSecretshop, # # 当前神秘商城数据
));
}
/**
* 更新神秘商城物品
* @param Req $req
* @param UserSecretshopModel $userSecretshop Description
*/
private static function refreshDynamicShopItems($req, &$userSecretshop) {
$userSecretshop->lastRefreshTs = now();
// todo: 这里补完更新物品的函数, // 第一版: 随机
$userSecretshop->currentItems = ObjectInit();
for ($i = 1; $i <= 3; $i++) { # 3种类型的商品
$arr = GameConfig::secretshop_goodsType_getItem($i);
if (count($arr) > 0) {
$err = self::Dice(GameConfig::secretshop_goodsType_getItem($i), 1, $userSecretshop); # 一个种类一次1个物品
if ($err) {
return $err;
}
}
}
return ErrCode::ok;
}
// //
//
//
//
/**
* @deprecated since version 2020.5.8
* @param Req $req
* @param type $uid
* @param type $addValue Description
*/
private static function _addScore_by_uid($req, $uid, $addValue) {
if ($addValue <= 0) { # 防御
return;
}
$mem = $req->mem;
$zoneid = $req->zoneid;
$key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 积分榜
$score = $mem->zscore($key, $uid);
if (!$score || $score <= 0) { # 分数异常
$leagueScore = GameConfig::pvp_leaguescore_getItem(1); # 新手基础分
$score = $leagueScore->minScore;
$mem->zadd($key, array($uid => $score)); # 重置玩家积分
}
$newscore = $mem->zincrby($key, $uid, $addValue); # 返回最新值
$mem->zadd(MemKey_GameRun::Game_PVPScoreByZone_zset_curWeek($zoneid), array($uid => $newscore));
return $newscore;
}
/**
* @deprecated since version 2020.5.8
* @param type $req
* @param type $uid
* @param type $subValue
*/
private static function _subScore_by_uid($req, $uid, $subValue) {
if ($subValue >= 0) { # 防御异常数值
return;
}
$mem = $req->mem;
$zoneid = $req->zoneid;
$key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 积分榜
$score = $mem->zscore($key, $uid);
$leagueScore = GameConfig::pvp_leaguescore_getItem(1); # 新手基础分
if (!$score || $score <= 0 #
|| ($score + $subValue) <= $leagueScore->minScore) { # 分数异常
$score = $leagueScore->minScore; # 新手基础分
$mem->zadd($key, array($uid => $score)); # 重置玩家积分
} else {
$score = $mem->zincrby($key, $uid, $subValue); # 扣除积分并返回最新值
}
$mem->zadd(MemKey_GameRun::Game_PVPScoreByZone_zset_curWeek($zoneid), array($uid => $score)); # 同步记录
return $score;
}
/**
* 发送上周上榜奖励
* @param Req $req
*/
public static function sendLastRankReward($req) {
$mem = gMem();
$zoneid = $req->zoneid;
$tsweek = TimeUtil::tsWeek();
$key = MemKey_GameRun::Game_PVPRankRewardRecord_set($zoneid);
if (!$mem->sismember($key, $tsweek)) { # 上周榜单尚未处理, 每周只处理一次
// 上周是空的情况.
$lastKey = MemKey_GameRun::Game_PVPRankRewardRecord_byWeek_str($zoneid, $tsweek - 1);
$mem->sadd($key, $tsweek); # 添加处理记录
$key_total = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid); # 拉取上榜人员
$uids = $mem->zrevrange($key_total, 0, 99);
$rank = 0;
foreach ($uids as $uid) {
EmailProc::SendPvpRankReward($zoneid, $uid, ++$rank); # 发送奖励邮件
}
$mem->add($lastKey, $uids);
}
}
/**
* [6811] 竞技场 刷新对手
* @param Req $req
*/
static function pvp_Refresh($req) {
// 刷新无花费, 间隔时间3秒(客户端控制得了)
// 根据匹配规格获得5个对手即可(1. 排除自己, 2. 最好不要出现已经刷到过的对手)
// 低于玩家当前积分 -- 2个 -5%~-20%之间
// 与玩家当前积分基本持平 1个, ±5%之间
// 高于玩家当前积分 -- 2个 +5%~+40%之间
// $amt = $req->paras[0]; # 提取 params , 验证下花费
// $pvp = new UserPVPModel($req->userInfo->game->pvp);
// $ts = now();
// if ($amt <= 0) { # 免费情况
// if ($pvp->nextRefreshTs > $ts) { # 验证时间
// return Resp::err(ErrCode::pvp_refresh_time);
// }
// } else { # 扣除钻石刷新的情况
// $priceArr = explode(',', glc()->PVP_reFresh_Match_cost); # 价格
// if (count($priceArr) < $pvp->dailyRefreshMatchTimes) { # 超过最大刷新次数
// return Resp::err(ErrCode::pvp_refresh_max);
// }
// $costCash = $priceArr[$pvp->dailyRefreshMatchTimes++]; # 查找对应的定价, 并计次
// if ($costCash != $amt) { # 跟预期值不一致,
// return Resp::err(ErrCode::pvp_refresh_cost_ilegal);
// }
// if (!UserGameModel::Consume_Cash($req->userInfo->game, $costCash)) {# 扣除钻石失败
// return Resp::err(ErrCode::notenough_cash_msg);
// }
// }
//
// $pvp->curMatches = self::getNewMatches($pvp, $req->mem, $req->uid, $req->zoneid);
// $pvp->nextRefreshTs = now(glc()->PVP_refresh_Match_RecoverSeconds);
// $req->userInfo->game->pvp = $pvp;
// UserProc::updateUserInfo(); # 回写数据
//
// $ret = array(
// 'nextRefreshTs' => $pvp->nextRefreshTs, # # 下次免费刷新的时间戳
// 'dailyRefreshMatchTimes' => $pvp->dailyRefreshMatchTimes,
// 'curMatches' => $pvp->curMatches # # 当前对手清单
// );
return Resp::ok($ret);
}
/**
* [6812] 竞技场 挑战对手xx
* @param Req $req
*/
static function pvp_PK($req) {
$uid = $req->uid;
$target_uid = $req->paras[0]; # 对手id
$result = $req->paras[1]; # 胜负结果 0负,1胜
$pvp = $req->userInfo->game->pvp;
// 根据挑战结果, 计算双方积分变化
// 更新双方的积分变化
// redis->zincr 修改各自积分
// 返回
// if (!property_exists($pvp->curMatches, $target_uid)//
// or property_exists($pvp->curMatches->$target_uid, 'killed')) { # 对手已被ko
// return Resp::err(ErrCode::pvp_wrongMather);
// }
// $g = glc();
// if (now() - $pvp->tiliTs > $g->PVP_reCover_Tili_costSec * 5) { # 检查并扣除体力
// $pvp->tiliTs = now() - $g->PVP_reCover_Tili_costSec * 5;
// }
// if ($pvp->tiliExtra > 0) { # 优先扣除溢出值
// $pvp->tiliExtra--;
// } else {
// $pvp->tiliTs += $g->PVP_reCover_Tili_costSec;
// if ($pvp->tiliTs > now()) {
// return Resp::err(ErrCode::pvp_wrongtili);
// }
// }
//# 发放对应奖励并记录挑战记录
// $score = 0;
// if ($result) { # 1 胜, 奖金币、积分、pvp币
// UserGameModel::Add_Gold($req->userInfo->game, $g->PVP_PK_Win_Gold);
// # × 奖励积分的公式: 获胜基础奖励积分 + 积分差距修正系数 * 积分差
// # 挑战胜利, 积分改为固定值.
// $winnerGainScore = $g->PVP_PK_Win_Score; # 本局得分
// $score = self::_addScore_by_uid($req, $uid, intval($winnerGainScore)); # 增加积分
// $pvp->pvpCoins += $g->PVP_PK_Win_PvpCoin; # 发放金币
// self::_subScore_by_uid($req, $target_uid, -intval($g->PVP_PK_be_defeated_score)); # 给对手扣除积分
// $pvp->contWin++; # 连胜记录
// $pvp->winTimes++; # 获胜记录
// $all = true; # 全部战胜标记
// foreach ($pvp->curMatches as $pid => &$p) {
// if ($pid == $target_uid) { #
// $p->killed = 1; # 添加ko标志
// if (property_exists($p, 'fog')) {
// $score = self::_addScore_by_uid($req, $uid, intval($winnerGainScore)); # 神秘对手, 积分翻倍(再加一遍)
// }
// }
// if (!property_exists($p, 'killed')) {
// $all = false; # 尚未全部战胜
// }
// }
// if ($all) { # 全部战胜之后,刷新对手
// $pvp->curMatches = self::getNewMatches($pvp, $req->mem, $req->uid, $req->zoneid);
// $pvp->nextRefreshTs = now(glc()->PVP_refresh_Match_RecoverSeconds);
// }
// } else { # 0 挑战失败 只扣除积分
// # × 奖励积分的公式: 获胜基础奖励积分 + 积分差距修正系数 * 积分差
// # 挑战失败, 扣除固定积分
// $loserGainScore = $g->PVP_PK_Fail_Score;
// $score = self::_subScore_by_uid($req, $uid, -intval($loserGainScore)); # 扣除积分
// self::_addScore_by_uid($req, $target_uid, intval($g->PVP_PK_be_undefeated_score)); # 给对手发放积分
// $pvp->contWin = 0; # 连胜置零
// }
// if (property_exists($pvp->curMatches, $target_uid) && property_exists($pvp->curMatches->$target_uid, 'fog')) {
// unset($pvp->curMatches->$target_uid->fog);
// }
// $pvp->totalTimes++;
// $leagueid = self::GetLeagueByScore($score);
// if ($pvp->leagueId != $leagueid) {
// $pvp->leagueId = $leagueid;
// SystemProc::PVP_league($req->zoneid, $req->userInfo->game, $leagueid);
// }
// $pvp->actives++;
// $pvp->dailyPkCnt++;
// $req->userInfo->game->pvp = $pvp;
////todo: debuging...
// UserProc::updateUserInfo(); # 回写数据
// $ret = array(
// 'contWin' => $pvp->contWin,
// 'leagueId' => $pvp->leagueId,
// 'newscore' => $score, # # 返回最新积分
// );
return Resp::ok($ret);
}
/**
* [6813] 竞技场 设置防守队伍
* @param req $req
*/
public static function pvp_setTeam($req) {
$heros = $req->paras[0]; # para: 新阵容
$pvp = new UserPVPModel($req->userInfo->game->pvp);
if (is_array($heros)) { # 更新阵容
$pvp->defTeam->heros = $heros;
}
$req->userInfo->game->pvp = $pvp;
UserProc::updateUserInfo(); # 回存数据
return Resp::ok($pvp->defTeam); # 返回
}
/**
* [6814] 购买挑战票
* @param Req $req
* @return type
*/
static function pvp_buyticket($req) {
$amt = $req->paras[0]; # 验证下本次扣除的钻石数量
# 检查并扣除消耗
# 增加挑战票
# 回存数据
# 返回
// $pvp = new UserPVPModel($req->userInfo->game->pvp);
// $g = glc();
// $curTili = intval((now() - $pvp->tiliTs) / $g->PVP_reCover_Tili_costSec);
// if ($curTili > 5) {
// $curTili = 5;
// }
// if ($pvp->tiliExtra > 0) { # 体力溢出值大于0的时候不要购买
// return Resp::err(ErrCode::pvp_tili_chargenum);
// }
// $priceArr = explode(',', $g->PVP_recover_tili_cost_cash);
//
// if (count($priceArr) < $pvp->dailyBuyTiliTimes) {
// return Resp::err(ErrCode::pvp_tili_soldout);
// }
// $costCash = $priceArr[$pvp->dailyBuyTiliTimes++]; # 查找对应的定价, 并计次
// if ($costCash != $amt) { # 跟预期值不一致,
// return Resp::err(ErrCode::pvp_tili_cost_ilegal);
// }
// if (!UserGameModel::Consume_Cash($req->userInfo->game, $costCash)) { # 扣除钻石失败
// return Resp::err(ErrCode::notenough_cash_msg);
// }
// if ($curTili > 0) { # 增加溢出值
// $pvp->tiliExtra = $curTili;
// }
//
// $pvp->tiliTs = now() - ( 5 * $g->PVP_reCover_Tili_costSec); # 补满
// $req->userInfo->game->pvp = $pvp;
// UserProc::updateUserInfo(); # 回写玩家数据
// $ret = array(
// 'tiliTs' => $pvp->tiliTs,
// 'tiliExtra' => $pvp->tiliExtra,
// 'costCash' => $costCash,
// 'dailyBuyTiliTimes' => $pvp->dailyBuyTiliTimes,
// 'userCash' => $req->userInfo->game->cash
// );
return Resp::ok($ret); # 返回
}
/**
* [6815] 竞技场 拉取榜单数据
* @param Req $req
*/
static function pvp_getRank($req) {
$maxAmt = 10; # 一次最多取10个玩家信息
$zoneid = $req->zoneid;
$index = $req->paras[0]; # 起始(0)
$n = $req->paras[1]; # 数量, (n<=max)
// if ($n < 1 || $n > $maxAmt) { # 防御非法情况
// $n = $maxAmt;
// }
// $arr = self::getRankPlayers($req->mem, $zoneid, $index - 1, ($index + $n) - 1);
//
// $rankId = $index;
// $result = ObjectInit();
// if (count($arr)) {
// foreach ($arr as $key => $value) {//$value 的数据类型是array
// $value["uid"] = $key;
// $result->$rankId = $value;
// $rankId += 1;
// }
// }
// $ret = array(
// 'arr' => $result
// );
return Resp::ok($ret);
}
/**
* [6816] 竞技场 查看战报
* @param Req $req
*/
static function pvp_getFightLogs($req) {
// 提取主动挑战+被挑战记录
// 更新下刷新时间
// 返回
return Resp::ok($ret);
}
// ---------------- 辅助函数 -----------------------
//
/**
* 竞技场 查询玩家的积分
* @param type $uid
* @return int
*/
static function _getScore_by_uid($uid, $key) {
if ("" == $uid) {
CLog::err('"uid" is Null!');
return 10; # 记录错误并返回一个极低分
}
$mem = gMem();
$score = $mem->zscore($key, $uid);
if (!$score || $score <= 0) { # 分数异常
$score = self::pvpBaseScore; # 新手基础分
$mem->zadd($key, array($uid => $score)); # 更新玩家积分
}
return $score;
}
/**
* 竞技场 查询玩家的排名
* @param string $uid
* @param string $key
* @return int
*/
static function _getRank_by_uid($uid, $key) {
$rank = self::pvpMaxRank + 1; # 未上榜
if ("" == $uid) {
CLog::err('"uid" is Null!');
return $rank; # 记录错误并返回未上榜
}
$mem = gMem();
$r = $mem->zrevrank($key, $uid);
if (!is_null($r)) {
$rank = $r; # 有名次,更新
}
return $rank; # 返回
}
/**
* 清理每日计数器
* @deprecated since version 2020.5.8
* @param Req $req
*/
public static function ClearDailyPkcnt($req) {
$pvp = new UserPVPModel($req->userInfo->game->pvp);
$pvp->dailyPkCnt = 0;
$pvp->dailyBuyTiliTimes = 0;
$pvp->dailyRefreshMatchTimes = 0;
$pvp->dailyMatchRecord = array($req->uid); # 屏蔽自己
$pvp->curMatches = self::getNewMatches($pvp, $req->mem, $req->uid, $req->zoneid); # added by: 李宁,2017年8月1日 11:45:41
$pvp->nextRefreshTs = tsDay() * 86400 + glc()->PVP_refresh_Match_RecoverSeconds;
$req->userInfo->game->pvp = $pvp;
}
/**
* 依据积分获得所在阶段的id
* @deprecated since version 2020.5.8
* @param type $curScore
* @return int
*/
private static function GetLeagueByScore($curScore) {
foreach (GameConfig::pvp_leaguescore() as $id => $lg) {
isEditor() and $lg = new sm_pvp_leaguescore;
if ($lg->maxScore >= $curScore && $lg->minScore <= $curScore) {
return $id;
}
}
return 1; # 找不到对应所属阶段的时候,返回 默认值 1
}
/**
* 获取对手匹配结果
* @param UserPVPModel $pvp
* @param CRedisutil $mem
* @param type $uid
* @param type $zoneid
*/
private static function getNewMatches($pvp, $uid, $zoneid) {
$arr = array();
$seasonID = self::GetCurSeasonID();
$key = MemKey_GameRun::Game_PVPScoreByZoneSeason_zset($zoneid, $seasonID); # redis key
self::findmatcher($zoneid, $key, $uid, $pvp, $arr); # 积分榜查找
if (count($arr) < self::matchCount) { # 再不行, 准备机器人吧
// todo: 这里引入gm对手数据,
CLog::err('PVP刷对手数量不足, 赶快考虑加入机器人.', 'PVP');
}
$ret = self::GetPlayerInfosForPVP(gMem(), $zoneid, $arr);
return $ret;
}
/**
* 查找匹配的对手
* @param type $zoneid
* @param type $key
* @param type $uid
* @param UserPVPModel $pvp
* @param type $arr
*/
private static function findmatcher($zoneid, $key, $uid, &$pvp, &$arr) {
$mem = gMem();
$rank = $mem->zrevrank($key, $uid); # 直接查排名
$zlen = $mem->zlen($key); # 数据长度
$i = 0; # 计数器
$b = false; # 上下标志位
while (count($arr) < self::matchCount && $i < 50) { # 找够数量为止,或者查找超过100个位置, 跳出查找
$index = $rank + ($b ? - $i : $i);
$b = !$b;
if ($b) { # 变化查找方向
$i++; #
}
if ($index < 0 || $index >= $zlen) { # 跳过不合理位置
continue;
}
$back = $mem->zrevrange($key, $index, $index, true); # 取1个人
if (count($back) <= 0) {
continue; # 跳过
}
$us = array_keys($back);
$d_uid = $us[0];
if ($d_uid == $uid) { # 避开自己
continue;
}
$user = $mem->get(MemKey_User::Info_hash($zoneid, $d_uid));
if (null == $user) { # 找不到对手数据,跳过
continue;
}
// $fp = HeroProc::CalcTeamFightPower($zoneid, $d_uid, $user);
// if ($fp > 0) {
if (!in_array($d_uid, $pvp->dailyMatchRecord)) { # 已经匹配过的对手不在出现
$arr[$d_uid] = $back[$d_uid];
$pvp->dailyMatchRecord[] = $d_uid;
}
// }
}
}
/**
* 拉取玩家信息-pvp模块专用信息
* @param CredisUtil $mem
* @param type $zoneid
* @param type $retUidsWithScore
* @return type
*/
private static function GetPlayerInfosForPVP($mem, $zoneid, $retUidsWithScore) {
$retUids = array_keys($retUidsWithScore);
$keysOfUserInfo = array_map(function($u)use($zoneid) {
return MemKey_User::Info_hash($zoneid, $u);
}, $retUids);
$arrUserInfos = $mem->getMulti($keysOfUserInfo);
$arr = ArrayInit();
$i = 0;
foreach ($arrUserInfos as $userGameInfo) { # 遍历
isEditor() && $userGameInfo = new UserGameModel; # 语法辅助
$uid = $retUids[$i++]; # 当前UID
$teamConfig = $userGameInfo->pvp->defTeam; # 防守阵容
$heros = new \stdClass(); # 英雄集合
foreach ($teamConfig->heros as $i => $hid) {
if ($hid > 0) {
$n_hid = $hid - 10000;
$heros->$n_hid = $userGameInfo->game->heros->collectHeros->$hid;
}
}
$adversary = array(# # 拼装玩家信息
'uid' => $uid,
'name' => my_null_default($userGameInfo->game->name, ""),
'level' => my_null_default($userGameInfo->game->level, 1),
'headImg' => my_null_default($userGameInfo->game->img, ""),
// 'skills' => null, # # skills暂时没有实例数据
'equipment' => array("equipments" => my_null_default($userGameInfo->game->store->equipment, new \stdClass())), # 武器
'yanling' => array("items" => my_null_default($userGameInfo->game->store->yanling, new \stdClass())), # 言灵
'heros' => my_null_default($heros, new \stdClass()), # # 英雄集合
'score' => $retUidsWithScore[$uid], # # 积分
);
$arr[$uid] = $adversary;
}
if (count($arr) <= 0) {
$arr = null;
}
return $arr;
}
/**
* 获取榜单玩家
* @deprecated since version 2020.5.8
* @param Credisutil $mem
* @param int $zoneid
* @param int $start
* @param int $stop
* @return type
*/
private static function getRankPlayers($mem, $zoneid, $start, $stop) {
$key = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid);
$retUidsWithScore = $mem->zrevrange($key, $start, $stop, true);
return self::GetPlayerInfosForPVP($mem, $zoneid, $retUidsWithScore);
}
/**
* 提取英雄信息以供其他人使用
* @deprecated since version 2020.5.8
* @param type $userInfo
* @param type $heroId
* @return UserHeroModel
*/
public static function getHeroInfoForShare($userInfo, $heroId) {
if ($heroId) {
$heroInfo = $userInfo->heros->collectHeros->$heroId;
} else { // todo: 暂定如果没有设置共享英雄,默认取集合中第一个英雄, 征询策划是否修订规则
$coll = $userInfo->heros->collectHeros;
$keys = array_keys((array) $coll);
if (count($keys) <= 0) {
return null; // 暴力跳过, 防止出现更大的错误
}
$heroId = $keys[0];
$heroInfo = $userInfo->heros->collectHeros->$heroId;
}
// 额外将英雄的装备数据替换为实例数据
self::getArmor($userInfo, $heroInfo, 'weapon');
self::getArmor($userInfo, $heroInfo, 'armor');
self::getArmor($userInfo, $heroInfo, 'ring');
return $heroInfo;
}
/**
* @deprecated since version 2020.5.8
* @param type $userInfo
* @param type $hero
* @param type $armor
* @return type
*/
private static function getArmor($userInfo, $hero, $armor) {
if (isset($hero->equip->$armor)) {
if (property_exists($hero->equip->$armor, 'itemuid')) {
$armorid = $hero->equip->$armor->itemuid;
if ($armorid > 0 && isset($userInfo->store->equipment->$armorid)) {
$hero->equip->$armor = $userInfo->store->equipment->$armorid;
return; # 找到后直接跳出
}
}
}
$hero->equip->$armor = null;
}
//
//
//
//
}