From 2b59c17039cf4bcccc79a714f96ffea659a0e730 Mon Sep 17 00:00:00 2001 From: hxp <ale99527@vip.qq.com> Date: 星期三, 24 十一月 2021 16:55:39 +0800 Subject: [PATCH] 9341 【BT5】【主干】【后端】情缘系统(增加情缘副本;AB相互提亲优化聘礼ID取较高的; 主干冲突) --- ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py | 497 ++++++++++++++++++++++-------------------------------- 1 files changed, 202 insertions(+), 295 deletions(-) diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py index 8e2ef84..a8cf796 100644 --- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py +++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFBHelpBattle.py @@ -19,7 +19,7 @@ import IpyGameDataPY import PlayerViewCache import IPY_GameServer -import PlayerControl +import PlayerAssist import ShareDefine import PyGameData import GameWorld @@ -31,7 +31,6 @@ MaxRobotID = 100 # 最大机器人NPC定义ID Def_RecType_CheckInPlayer = ShareDefine.Def_UniversalGameRecType_FBHelpBattleCheckInPlayer -Def_RecType_HelpRecord = ShareDefine.Def_UniversalGameRecType_FBHelpBattleRecord ## 助战玩家简要信息 class HelpBattlePlayer(): @@ -48,21 +47,7 @@ self.checkInCount = 0 # 累计登记次数 self.checkInTime = 0 self.todayHelpCountDict = {} # 今天已助战次数 {(mapID, lineID):count, ...}, 通用次数时lineID默认为0 - self.todayXianyuanCoin = 0 # 今日已获得仙缘币 - return - -## 助战记录 - 目前只记录未通知玩家的助战信息 -class FBHelpBattleRecord(): - - def __init__(self): - self.callPlayerID = 0 # 召唤他的玩家ID - self.callPlayerName = "" - self.mapID = 0 - self.funcLineID = 0 - self.xianyuanCoinAdd = 0 # 0代表到达上限 - self.relation = 0 # 当时的关系 - self.vipLV = 0 # 当时的VIP等级 - self.recordTime = 0 # 记录的时间 + self.getThanksGiftCountDict = {} # 协助方今日接收该感谢礼盒次数 {itemID:count, ...} return def OnServerStart(): @@ -83,44 +68,28 @@ helpBattlePlayer.realmLV = int(str(value5)[-3:-1]) helpBattlePlayer.job = value5 % 10 helpBattlePlayer.playerName = recData.GetStrValue1() - helpBattlePlayer.todayXianyuanCoin = int(recData.GetStrValue2()) - helpCountDictStr = recData.GetStrValue3() + strValue3 = recData.GetStrValue3() + strValue3List = strValue3.split("|") + helpCountDictStr = strValue3List[0] if len(strValue3List) > 0 else "{}" + getThanksGiftCountDictStr = strValue3List[1] if len(strValue3List) > 1 else "{}" + if helpCountDictStr.startswith("{") and helpCountDictStr.endswith("}"): helpBattlePlayer.todayHelpCountDict = eval(helpCountDictStr) else: GameWorld.ErrLog("LoadCheckInPlayerError: helpCountDictStr=%s" % helpCountDictStr, playerID) + + if getThanksGiftCountDictStr.startswith("{") and getThanksGiftCountDictStr.endswith("}"): + helpBattlePlayer.getThanksGiftCountDict = eval(getThanksGiftCountDictStr) + else: + GameWorld.ErrLog("LoadCheckInPlayerError: getThanksGiftCountDictStr=%s" % getThanksGiftCountDictStr, playerID) PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] = helpBattlePlayer GameWorld.Log("加载助战登记玩家记录: %s" % len(PyGameData.g_fbHelpBattleCheckInPlayerDict)) - - helpRecordRecList = universalRecMgr.GetTypeList(Def_RecType_HelpRecord) - for index in xrange(helpRecordRecList.Count()): - recData = helpRecordRecList.At(index) - playerID = recData.GetValue1() - - helpRecord = FBHelpBattleRecord() - helpRecord.callPlayerID = int(recData.GetStrValue2()) - helpRecord.callPlayerName = recData.GetStrValue1() - helpRecord.mapID = recData.GetValue2() - helpRecord.funcLineID = recData.GetValue3() - helpRecord.xianyuanCoinAdd = recData.GetValue4() - helpRecord.relation = recData.GetValue5() % 10 - helpRecord.vipLV = recData.GetValue5() / 10 - helpRecord.recordTime = recData.GetTime() - - unNotifyRecordList = PyGameData.g_fbHelpBattleRecord.get(playerID, []) - unNotifyRecordList.append(helpRecord) - PyGameData.g_fbHelpBattleRecord[playerID] = unNotifyRecordList - - GameWorld.Log("加载玩家未同步助战: %s" % len(PyGameData.g_fbHelpBattleRecord)) - for playerID, helpList in PyGameData.g_fbHelpBattleRecord.items(): - GameWorld.Log("加载玩家未同步助战记录: %s" % (len(helpList)), playerID) return def OnServerClose(): GameWorld.Log("关服保存助战相关信息...") universalRecMgr = GameWorld.GetUniversalRecMgr() universalRecMgr.Delete(Def_RecType_CheckInPlayer) - universalRecMgr.Delete(Def_RecType_HelpRecord) GameWorld.Log("保存助战登记玩家记录: %s" % len(PyGameData.g_fbHelpBattleCheckInPlayerDict)) checkInPlayerRecList = universalRecMgr.GetTypeList(Def_RecType_CheckInPlayer) @@ -133,23 +102,10 @@ recData.SetValue4(checkInPlayer.checkInCount) recData.SetValue5(int("%d%02d%02d%d" % (checkInPlayer.playerLV, checkInPlayer.vipLV, checkInPlayer.realmLV, checkInPlayer.job))) recData.SetStrValue1(checkInPlayer.playerName) - recData.SetStrValue2(str(checkInPlayer.todayXianyuanCoin)) - recData.SetStrValue3(str(checkInPlayer.todayHelpCountDict).replace(" ", "")) + strValue3 = "%s|%s" % (str(checkInPlayer.todayHelpCountDict).replace(" ", ""), + str(checkInPlayer.getThanksGiftCountDict).replace(" ", "")) + recData.SetStrValue3(strValue3) - GameWorld.Log("保存助战未同步记录: %s" % len(PyGameData.g_fbHelpBattleRecord)) - helpRecordRecList = universalRecMgr.GetTypeList(Def_RecType_HelpRecord) - for playerID, helpList in PyGameData.g_fbHelpBattleRecord.items(): - GameWorld.Log("玩家未同步助战记录: %s" % (len(helpList)), playerID) - for helpRecord in helpList: - recData = helpRecordRecList.AddRec() - recData.SetTime(helpRecord.recordTime) - recData.SetValue1(playerID) - recData.SetValue2(helpRecord.mapID) - recData.SetValue3(helpRecord.funcLineID) - recData.SetValue4(helpRecord.xianyuanCoinAdd) - recData.SetValue5(helpRecord.vipLV*10+helpRecord.relation) - recData.SetStrValue1(helpRecord.callPlayerName) - recData.SetStrValue2(str(helpRecord.callPlayerID)) return def HelpBattleOnDay(): @@ -166,77 +122,7 @@ GameWorld.Log("清除超时助战登记玩家: curTime=%s,checkInTime=%s" % (curTime, checkInTime), playerID) continue checkInPlayer.todayHelpCountDict = {} - checkInPlayer.todayXianyuanCoin = 0 - return - -def OnHelpPlayerLogin(curPlayer): - playerID = curPlayer.GetPlayerID() - if playerID not in PyGameData.g_fbHelpBattleRecord: - return - unNotifyRecordList = PyGameData.g_fbHelpBattleRecord.pop(playerID) - SendMapServer_FBHelpBattleRecord(curPlayer, unNotifyRecordList, True) - return - -def OnMinuteProcess(): - ''' 每分钟处理 - 前X次登记后,分别在登记后的第X分钟赠送玩家宗门试炼一层的助战仙缘币,并伪造一份助战记录。 - 助战记录随机从助战登记库里随机挑选1名除自己外的玩家,如果没有玩家,该特殊逻辑不生效 - ''' - - if not PyGameData.g_fbHelpBattleCheckInPlayerDict: - return - helpPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys() - - curTime = int(time.time()) - - playerManager = GameWorld.GetPlayerManager() - newbieCheckInCount = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 2) # 新手前X次登记特殊逻辑 - sysAutoCallHelpDict = IpyGameDataPY.GetFuncEvalCfg("HelpBattleCheckIn", 3) # 系统自动召唤助战,默认功能线路0, {登记多少分钟后:[随机地图ID, ...], ...} - for playerID, checkInPlayer in PyGameData.g_fbHelpBattleCheckInPlayerDict.items(): - - curPlayer = playerManager.FindPlayerByID(playerID) - - if not curPlayer or PlayerControl.GetIsTJG(curPlayer): - #GameWorld.DebugLog(" 离线或脱机不处理, playerID=%s" % playerID) - continue - - checkInCount = checkInPlayer.checkInCount - if checkInCount > newbieCheckInCount: - #GameWorld.DebugLog(" 超过规定的登记次数,不处理, playerID=%s,checkInCount=%s > newbieCheckInCount=%s" - # % (playerID, checkInCount, newbieCheckInCount)) - continue - - checkInTime = checkInPlayer.checkInTime - checkInMinutes = (curTime - checkInTime) / 60 - if checkInMinutes not in sysAutoCallHelpDict: - #GameWorld.DebugLog(" 签到时间不满足,不处理, playerID=%s,checkInMinutes=%s not in %s" - # % (playerID, checkInMinutes, sysAutoCallHelpDict)) - continue - - randHelpMapList = sysAutoCallHelpDict[checkInMinutes] - # 随机一个不是自己的登记玩家 - for _ in xrange(20): - randPlayerID = random.choice(helpPlayerIDList) - if randPlayerID != playerID: - break - - # 只有自己不处理 - if randPlayerID == playerID: - #GameWorld.DebugLog(" 登记玩家只有自己,不处理, playerID=%s" % (playerID)) - continue - - randHelpMapID = random.choice(randHelpMapList) - lineID = 0 # 默认0 - - helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[randPlayerID] - relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer) - calledPlayerID = playerID # 因为这里是系统模拟玩家被召唤助战,所以被召唤玩家就是当前被处理的玩家ID - GameWorld.DebugLog(" 系统模拟召唤新手登记玩家: checkInMinutes=%s,playerID=%s,callPlayerID=%s" % (checkInMinutes, playerID, randPlayerID)) - - calledPlayerDict = {calledPlayerID:relation} - msgList = ["Call", randHelpMapID, lineID, calledPlayerDict] - __DoFBHelpBattleCall(randPlayerID, helpBattlePlayer.playerName, msgList) - + checkInPlayer.getThanksGiftCountDict = {} return ## 是否在助战登记列表里 @@ -266,7 +152,12 @@ # 扫荡召唤 elif cmd == "SweepCall": result = __DoFBHelpBattleSweepCall(curPlayer, msgList) - + + # 协助完成 + elif cmd == "AssistFinish": + __DoAssistFinish(curPlayer, msgList) + return + if result == None: return @@ -275,11 +166,11 @@ def __DoPlayerFBHelpBattleCheckIn(curPlayer, msgList): ## 玩家登记 checkInCount, fightPower = msgList[1:] + fightPower = min(fightPower, ChConfig.Def_UpperLimit_DWord) # 登记助战战力最高暂支持20E curTime = int(time.time()) playerID = curPlayer.GetPlayerID() - curCache = PlayerViewCache.ViewCacheMgr.FindCache(playerID) + curCache = PlayerViewCache.FindViewCache(playerID) haveViewCache = 1 if curCache else 0 - todayXianyuanCoin = PlayerControl.GetTodayXianyuanCoin(curPlayer) helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict.get(playerID) if not helpBattlePlayer: @@ -294,11 +185,10 @@ helpBattlePlayer.vipLV = curPlayer.GetVIPLv() helpBattlePlayer.checkInCount = checkInCount + 1 helpBattlePlayer.checkInTime = curTime - helpBattlePlayer.todayXianyuanCoin = todayXianyuanCoin isOK = 1 # 默认成功 - GameWorld.Log("玩家助战登记: playerLV=%s,fightPower=%s,familyID=%s,vipLV=%s,todayXianyuanCoin=%s,checkInCount=%s,haveViewCache=%s" - % (curPlayer.GetLV(), fightPower, curPlayer.GetFamilyID(), curPlayer.GetVIPLv(), todayXianyuanCoin, checkInCount + 1, haveViewCache), playerID) + GameWorld.Log("玩家助战登记: playerLV=%s,fightPower=%s,familyID=%s,vipLV=%s,checkInCount=%s,haveViewCache=%s" + % (curPlayer.GetLV(), fightPower, curPlayer.GetFamilyID(), curPlayer.GetVIPLv(), checkInCount + 1, haveViewCache), playerID) return [isOK, haveViewCache] def UpdateCheckInPlayerInfo(playerID, fightPower, familyID, playerName): @@ -320,8 +210,6 @@ helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] if refreshType == IPY_GameServer.CDBPlayerRefresh_LV: helpBattlePlayer.playerLV = value - elif refreshType == IPY_GameServer.CDBPlayerRefresh_ExAttr11: - helpBattlePlayer.todayXianyuanCoin = value elif refreshType == IPY_GameServer.CDBPlayerRefresh_VIPLv: helpBattlePlayer.vipLV = value else: @@ -355,7 +243,14 @@ GameWorld.Log("刷新助战列表: mapID=%s,funcLineID=%s,helpCountLineID=%s,isClientRefresh=%s,costMoneyList=%s,calledPlayerIDDict=%s" % (mapID, funcLineID, helpCountLineID, isClientRefresh, costMoneyList, calledPlayerIDDict), playerID) + onlyFree = False goldCallCount = 0 + nowFreeRelationCount, nowRelationCount, nowRobotCount = 0, 0, 0 + atleastFreeRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 1) # 至少免费社交人数,无社交则忽略 + atleastRelationCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 2) # 至少社交人数,无社交则忽略(人数包含免费社交人数) + atmostRobotCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 3) # 助战列表机器人至多数量 + allowNoRelation = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 4) # 助战列表是否出现非社交关系玩家 + GameWorld.DebugLog(" atleastFreeRelationCount=%s,atleastRelationCount=%s" % (atleastFreeRelationCount, atleastRelationCount)) #已经召唤的保留 for calledPlayerID, callInfo in calledPlayerIDDict.items(): @@ -366,8 +261,13 @@ helpBattlePlayerDict[calledPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, job, relation) if needGoldCall: goldCallCount += 1 + if relation: + nowRelationCount += 1 + if not needGoldCall: + nowFreeRelationCount += 1 # 机器人NPC elif 1 <= calledPlayerID <= MaxRobotID: + nowRobotCount += 1 helpBattlePlayerDict[calledPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, job) else: GameWorld.ErrLog("已召唤的助战玩家找不到镜像缓存!理论上不存在该情况,镜像缓存释放会比登记有效时长多半小时!") @@ -377,66 +277,147 @@ GameWorld.Log("已召唤的助战: %s" % str(helpBattlePlayerDict), playerID) curTime = int(time.time()) - maxHelpPlayerSelectCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 1) # 最大可以选择助战的玩家个数 + maxHelpPlayerSelectCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 1) # 最大可以选择助战的玩家个数 maxGoldHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 3) # 最大付费召唤人数 checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # 登记有效时长,小时 checkInValidSeconds = checkInValidHours * 3600 checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys() - random.shuffle(checkInPlayerIDList) # 刷新纯随机 + random.shuffle(checkInPlayerIDList) GameWorld.Log(" 登记助战人数=%s" % (len(checkInPlayerIDList)), playerID) - for checkInPlayerID in checkInPlayerIDList: - if checkInPlayerID == playerID: - GameWorld.DebugLog(" 自己不处理, checkInPlayerID=%s" % checkInPlayerID) - continue - if checkInPlayerID in helpBattlePlayerDict: - GameWorld.DebugLog(" 已经在助战里的不处理, checkInPlayerID=%s" % checkInPlayerID) - continue - if len(helpBattlePlayerDict) >= maxHelpPlayerSelectCount: - GameWorld.DebugLog(" 超过最大个数了不处理, checkInPlayerID=%s" % checkInPlayerID) - break - helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID] - checkInPlayerLV = helpBattlePlayer.playerLV - checkInPlayerFightPower = helpBattlePlayer.fightPower - checkInTime = helpBattlePlayer.checkInTime - if checkInPlayerLV < limitLV: - GameWorld.DebugLog(" 等级不足, checkInPlayerID=%s,checkInPlayerLV=%s < limitLV=%s" % (checkInPlayerID, checkInPlayerLV, limitLV)) - continue - if fightPowerMin and checkInPlayerFightPower < fightPowerMin: - GameWorld.DebugLog(" 战力不足, checkInPlayerID=%s,checkInPlayerFightPower=%s < fightPowerMin=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMin)) - continue - if fightPowerMax and checkInPlayerFightPower > fightPowerMax: - GameWorld.DebugLog(" 战力超出, checkInPlayerID=%s,checkInPlayerFightPower=%s > fightPowerMax=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMax)) - continue - passTime = curTime - checkInTime - if passTime > checkInValidSeconds: - GameWorld.DebugLog(" 登记超时, checkInPlayerID=%s,checkInTime=%s,passTime=%s > checkInValidSeconds=%s" % (checkInPlayerID, checkInTime, passTime, checkInValidSeconds)) - continue - needGoldCall = False - if dayFreeHelpCount: - todayHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) - needGoldCall = todayHelpCount >= dayFreeHelpCount - if needGoldCall and goldCallCount >= maxGoldHelpPlayerCount: - GameWorld.DebugLog(" 超过最大付费召唤人数, checkInPlayerID=%s,goldCallCount=%s > maxGoldHelpPlayerCount=%s" % (checkInPlayerID, goldCallCount, maxGoldHelpPlayerCount)) - continue - goldCallCount += 1 - relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer) - helpBattlePlayerDict[checkInPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation) + + if not allowNoRelation: + atleastRelationCount = maxHelpPlayerSelectCount + GameWorld.DebugLog("不允许出现非社交人数,默认设置至少社交人数为最大可选择人数! %s" % atleastRelationCount) - # 不足的机器人NPC补足 + # 1. 至少社交关系人数还不足的,先处理至少社交关系人数 + if nowRelationCount < atleastRelationCount: + relationIDList = [] + friendIDList = PlayerFriend.GetFriendStruct(playerID).GetSocialIDList() + relationIDList += friendIDList + #GameWorld.DebugLog(" 好友ID列表, friendIDList=%s" % friendIDList, playerID) + curFamily = curPlayer.GetFamily() + familyMemList = [] + if curFamily: + for index in xrange(curFamily.GetCount()): + member = curFamily.GetAt(index) + memberID = member.GetPlayerID() + familyMemList.append(memberID) + if memberID != playerID and memberID not in relationIDList: + relationIDList.append(memberID) + #GameWorld.DebugLog(" 盟友ID列表, familyMemList=%s" % familyMemList, playerID) + + random.shuffle(relationIDList) + #GameWorld.DebugLog(" 有社交的ID列表, relationIDList=%s" % relationIDList, playerID) + tempRelationHelpPlayerList = [] + for relationID in relationIDList: + if nowRelationCount >= atleastRelationCount: + break + if relationID not in checkInPlayerIDList: + continue + helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[relationID] + canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, relationID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, + checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree, goldCallCount, maxGoldHelpPlayerCount) + if not canHelp: + continue + + # 免费社交人数不足且免费 or 免费社交人数够了且总社交人数还不够 ; 都直接加入助战列表 + if (nowFreeRelationCount < atleastFreeRelationCount and not needGoldCall) \ + or (nowFreeRelationCount >= atleastFreeRelationCount and nowRelationCount < atleastRelationCount): + goldCallCount, nowRelationCount, nowFreeRelationCount = \ + __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount) + else: + lackRelationCount = atleastRelationCount - nowRelationCount + if len(tempRelationHelpPlayerList) < lackRelationCount: + tempRelationHelpPlayerList.append([helpBattlePlayer, needGoldCall]) + + lackRelationCount = atleastRelationCount - nowRelationCount + if lackRelationCount > 0: + for helpBattlePlayer, needGoldCall in tempRelationHelpPlayerList[:lackRelationCount]: + goldCallCount, nowRelationCount, nowFreeRelationCount = \ + __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount) + + # 2. 常规添加助战人数 + if allowNoRelation: + for checkInPlayerID in checkInPlayerIDList: + if len(helpBattlePlayerDict) >= maxHelpPlayerSelectCount: + GameWorld.DebugLog(" 超过最大个数了不处理, checkInPlayerID=%s" % checkInPlayerID) + break + helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID] + canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, + checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree, goldCallCount, maxGoldHelpPlayerCount) + if not canHelp: + continue + + goldCallCount, nowRelationCount, nowFreeRelationCount = \ + __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount) + + # 3. 不足的机器人NPC补足 openJobList = IpyGameDataPY.GetFuncEvalCfg("OpenJob", 1) # 开放的职业 lackCount = maxHelpPlayerSelectCount - len(helpBattlePlayerDict) robotID = 0 # 机器人NPC定义ID从1开始 - while lackCount > 0 and robotID < MaxRobotID: + while lackCount > 0 and robotID < MaxRobotID and nowRobotCount < atmostRobotCount: robotID += 1 if robotID in helpBattlePlayerDict: continue lackCount -= 1 + nowRobotCount += 1 randJob = random.choice(openJobList) helpBattlePlayerDict[robotID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, randJob) GameWorld.Log(" helpBattlePlayerDict=%s" % (helpBattlePlayerDict), playerID) return [helpBattlePlayerDict] + +def __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, + checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree=False, goldCallCount=0, maxGoldHelpPlayerCount=0): + ## 常规检查是否满足助战条件 + if checkInPlayerID == playerID: + GameWorld.DebugLog(" 自己不处理, checkInPlayerID=%s" % checkInPlayerID) + return False, False + if checkInPlayerID in helpBattlePlayerDict: + GameWorld.DebugLog(" 已经在助战里的不处理, checkInPlayerID=%s" % checkInPlayerID) + return False, False + checkInPlayerLV = helpBattlePlayer.playerLV + checkInPlayerFightPower = helpBattlePlayer.fightPower + checkInTime = helpBattlePlayer.checkInTime + if checkInPlayerLV < limitLV: + GameWorld.DebugLog(" 等级不足, checkInPlayerID=%s,checkInPlayerLV=%s < limitLV=%s" % (checkInPlayerID, checkInPlayerLV, limitLV)) + return False, False + if fightPowerMin and checkInPlayerFightPower < fightPowerMin: + GameWorld.DebugLog(" 战力不足, checkInPlayerID=%s,checkInPlayerFightPower=%s < fightPowerMin=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMin)) + return False, False + if fightPowerMax and checkInPlayerFightPower > fightPowerMax: + GameWorld.DebugLog(" 战力超出, checkInPlayerID=%s,checkInPlayerFightPower=%s > fightPowerMax=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMax)) + return False, False + passTime = curTime - checkInTime + if passTime > checkInValidSeconds: + GameWorld.DebugLog(" 登记超时, checkInPlayerID=%s,checkInTime=%s,passTime=%s > checkInValidSeconds=%s" % (checkInPlayerID, checkInTime, passTime, checkInValidSeconds)) + return False, False + todayHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + needGoldCall = dayFreeHelpCount and todayHelpCount >= dayFreeHelpCount + if needGoldCall: + if onlyFree: + GameWorld.DebugLog(" 不是免费, checkInPlayerID=%s,todayHelpCount=%s > dayFreeHelpCount=%s" % (checkInPlayerID, todayHelpCount, dayFreeHelpCount)) + return False, needGoldCall + if goldCallCount >= maxGoldHelpPlayerCount: + GameWorld.DebugLog(" 超过最大付费召唤人数, checkInPlayerID=%s,goldCallCount=%s > maxGoldHelpPlayerCount=%s" % (checkInPlayerID, goldCallCount, maxGoldHelpPlayerCount)) + return False, needGoldCall + return True, needGoldCall + +def __AddHelpPlayer(curPlayer, helpBattlePlayer, helpBattlePlayerDict, needGoldCall, goldCallCount, nowRelationCount, nowFreeRelationCount): + ## 添加助战玩家到助战列表 + if needGoldCall: + goldCallCount += 1 + relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer) + if relation: + nowRelationCount += 1 + if not needGoldCall: + nowFreeRelationCount += 1 + helpPlayerID = helpBattlePlayer.playerID + helpBattlePlayerDict[helpPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation) + GameWorld.DebugLog(" 助战列表添加玩家: helpPlayerID=%s,needGoldCall=%s,relation=%s,goldCallCount=%s,nowRelationCount=%s,nowFreeRelationCount=%s" + % (helpPlayerID, needGoldCall, relation, goldCallCount, nowRelationCount, nowFreeRelationCount)) + return goldCallCount, nowRelationCount, nowFreeRelationCount def __GetHelpBattleRelation(curPlayer, helpBattlePlayer): ## 获取助战社交关系 0-无,1-好友,2-盟友 @@ -472,7 +453,7 @@ def __DoFBHelpBattleSweepCall(curPlayer, msgList): ''' 扫荡助战列表刷新且直接召唤 - 随机选择免费的玩家、过滤仙缘币已达上限或溢出的玩家 + 随机选择免费的玩家 ''' mapID, funcLineID = msgList[1:] @@ -484,7 +465,7 @@ return [helpBattlePlayerDict] fightPowerMin = fbHelpIpyData.GetFightPowerMin() - fightPowerMax = fbHelpIpyData.GetFightPowerMax() + fightPowerMax = 0#fbHelpIpyData.GetFightPowerMax() # 扫荡暂不限制最高战力 limitLV = fbHelpIpyData.GetLVLimit() dayFreeHelpCountInfo = fbHelpIpyData.GetDayFreeHelpCount() # 每日免费助战次数,[每日免费助战次数, 是否所有层通用] dayFreeHelpCount = 0 # 0为无限制次数 @@ -496,135 +477,51 @@ helpCountKey = (mapID, helpCountLineID) playerID = curPlayer.GetPlayerID() - tagPlayerID = playerID - tagPlayerName = curPlayer.GetName() GameWorld.Log("扫荡刷新助战列表: mapID=%s,funcLineID=%s,helpCountLineID=%s" % (mapID, funcLineID, helpCountLineID), playerID) curTime = int(time.time()) - maxHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 2) # 最大助战人数 + maxHelpPlayerCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall", 2) # 最大助战人数 checkInValidHours = IpyGameDataPY.GetFuncCfg("HelpBattleCheckIn", 1) # 登记有效时长,小时 checkInValidSeconds = checkInValidHours * 3600 - xianyuanCoinUpper = IpyGameDataPY.GetFuncCfg("HelpBattlePoint", 1) # 每日仙缘币上限 - baseHelpPoint = fbFuncIpyData.GetHelpPoint() # 助战 - 基础仙缘币 - relationCoinAddDict = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 2, {}) # 社交关系加成 {"社交关系":[过关加成, 助战加成], ...} + atmostRobotCount = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 3) # 助战列表机器人至多数量 + allowNoRelation = IpyGameDataPY.GetFuncCfg("HelpBattleCall2", 4) # 助战列表是否出现非社交关系玩家 - isSweep = True + onlyFree = True checkInPlayerIDList = PyGameData.g_fbHelpBattleCheckInPlayerDict.keys() random.shuffle(checkInPlayerIDList) # 刷新纯随机 GameWorld.Log(" 登记助战人数=%s" % (len(checkInPlayerIDList)), playerID) for checkInPlayerID in checkInPlayerIDList: - if checkInPlayerID == playerID: - GameWorld.DebugLog(" 自己不处理, checkInPlayerID=%s" % checkInPlayerID) - continue - if checkInPlayerID in helpBattlePlayerDict: - GameWorld.DebugLog(" 已经在助战里的不处理, checkInPlayerID=%s" % checkInPlayerID) - continue if len(helpBattlePlayerDict) >= maxHelpPlayerCount: GameWorld.DebugLog(" 超过最大个数了不处理, checkInPlayerID=%s" % checkInPlayerID) break helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[checkInPlayerID] - checkInPlayerLV = helpBattlePlayer.playerLV - checkInPlayerFightPower = helpBattlePlayer.fightPower - checkInTime = helpBattlePlayer.checkInTime - if checkInPlayerLV < limitLV: - GameWorld.DebugLog(" 等级不足, checkInPlayerID=%s,checkInPlayerLV=%s < limitLV=%s" % (checkInPlayerID, checkInPlayerLV, limitLV)) + canHelp, needGoldCall = __CheckCanHelpComm(playerID, helpBattlePlayerDict, checkInPlayerID, helpBattlePlayer, limitLV, fightPowerMin, fightPowerMax, + checkInValidSeconds, curTime, helpCountKey, dayFreeHelpCount, onlyFree) + if not canHelp: continue - if fightPowerMin and checkInPlayerFightPower < fightPowerMin: - GameWorld.DebugLog(" 战力不足, checkInPlayerID=%s,checkInPlayerFightPower=%s < fightPowerMin=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMin)) - continue - if fightPowerMax and checkInPlayerFightPower > fightPowerMax: - GameWorld.DebugLog(" 战力超出, checkInPlayerID=%s,checkInPlayerFightPower=%s > fightPowerMax=%s" % (checkInPlayerID, checkInPlayerFightPower, fightPowerMax)) - continue - passTime = curTime - checkInTime - if passTime > checkInValidSeconds: - GameWorld.DebugLog(" 登记超时, checkInPlayerID=%s,checkInTime=%s,passTime=%s > checkInValidSeconds=%s" % (checkInPlayerID, checkInTime, passTime, checkInValidSeconds)) - continue - needGoldCall = False - todayHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) - if dayFreeHelpCount: - needGoldCall = todayHelpCount >= dayFreeHelpCount - if needGoldCall: - GameWorld.DebugLog(" 不是免费, checkInPlayerID=%s,todayHelpCount=%s > dayFreeHelpCount=%s" % (checkInPlayerID, todayHelpCount, dayFreeHelpCount)) - continue - relation = __GetHelpBattleRelation(curPlayer, helpBattlePlayer) - if not __DoCallHelpPlayer(tagPlayerID, tagPlayerName, helpBattlePlayer, relation, mapID, funcLineID, helpCountKey, isSweep, - curTime, xianyuanCoinUpper, relationCoinAddDict, baseHelpPoint): + if not allowNoRelation and not relation: continue - + helpBattlePlayer.todayHelpCountDict[helpCountKey] = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + 1 helpBattlePlayerDict[checkInPlayerID] = __GetNotifyMapServerHelpPlayerInfoDict(helpBattlePlayer, needGoldCall, helpBattlePlayer.job, relation) + nowRobotCount = 0 # 不足的机器人NPC补足 openJobList = IpyGameDataPY.GetFuncEvalCfg("OpenJob", 1) # 开放的职业 lackCount = maxHelpPlayerCount - len(helpBattlePlayerDict) robotID = 0 # 机器人NPC定义ID从1开始 - while lackCount > 0 and robotID < MaxRobotID: + while lackCount > 0 and robotID < MaxRobotID and nowRobotCount < atmostRobotCount: robotID += 1 if robotID in helpBattlePlayerDict: continue lackCount -= 1 + nowRobotCount += 1 randJob = random.choice(openJobList) helpBattlePlayerDict[robotID] = __GetNotifyMapServerHelpPlayerInfoDict(None, False, randJob) GameWorld.Log(" helpBattlePlayerDict=%s" % (helpBattlePlayerDict), playerID) return [helpBattlePlayerDict] - -def __DoCallHelpPlayer(callPlayerID, callPlayerName, helpBattlePlayer, relation, mapID, funcLineID, helpCountKey, isSweep, curTime, - xianyuanCoinUpper, relationCoinAddDict, baseHelpPoint): - - calledPlayerID = helpBattlePlayer.playerID - addCoinRate = 10000 # 基础倍率 - playerXianyuanCoinUpper = xianyuanCoinUpper - relationAddList = relationCoinAddDict.get(str(relation), []) - relationAdd = relationAddList[1] if len(relationAddList) == 2 else 0 - - todayXianyuanCoin = helpBattlePlayer.todayXianyuanCoin # 今日已获得仙缘币 - vipLV = helpBattlePlayer.vipLV - if vipLV: - xianyuanCoinUpperAdd = PlayerControl.GetPrivilegeValue(vipLV, ChConfig.VIPPrivilege_XianyuanCoinUpperAdd) - xianyuanCoinAddPer = PlayerControl.GetPrivilegeValue(vipLV, ChConfig.VIPPrivilege_XianyuanCoinAddPer) - - playerXianyuanCoinUpper += xianyuanCoinUpperAdd - addCoinRate += xianyuanCoinAddPer - - # 仙缘币公式=(通关仙缘币或助战仙缘币+社交关系加成)*VIP倍数 - coinAdd = int((baseHelpPoint + relationAdd) * addCoinRate / 10000.0) - canAddMax = max(playerXianyuanCoinUpper - todayXianyuanCoin, 0) - - # 扫荡不可溢出 - if isSweep and coinAdd > canAddMax: - GameWorld.DebugLog(" 今日仙缘币已达上限, calledPlayerID=%s,coinAdd=%s > canAddMax=%s" % (calledPlayerID, coinAdd, canAddMax)) - return - coinAddReal = min(coinAdd, canAddMax) # 实际加仙缘币 - - todayMapHelpCount = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + 1 - helpBattlePlayer.todayHelpCountDict[helpCountKey] = todayMapHelpCount - GameWorld.DebugLog(" 助战增加仙缘币: todayXianyuanCoin=%s,coinUpper=%s,canAddMax=%s,coinAdd=%s,coinAddReal=%s,todayMapHelpCount=%s" - % (todayXianyuanCoin, playerXianyuanCoinUpper, canAddMax, coinAdd, coinAddReal, todayMapHelpCount), calledPlayerID) - - # GameServer 直接先加 - helpBattlePlayer.todayXianyuanCoin += coinAddReal - - helpRecord = FBHelpBattleRecord() - helpRecord.callPlayerID = callPlayerID # 召唤他的玩家ID - helpRecord.callPlayerName = callPlayerName - helpRecord.mapID = mapID - helpRecord.funcLineID = funcLineID - helpRecord.xianyuanCoinAdd = coinAddReal - helpRecord.relation = relation - helpRecord.vipLV = vipLV - helpRecord.recordTime = curTime - - calledPlayer = GameWorld.GetPlayerManager().FindPlayerByID(calledPlayerID) - # 非脱机在线直接通知地图 - if calledPlayer and not PlayerControl.GetIsTJG(calledPlayer): - SendMapServer_FBHelpBattleRecord(calledPlayer, [helpRecord]) - else: - unNotifyRecordList = PyGameData.g_fbHelpBattleRecord.get(calledPlayerID, []) - unNotifyRecordList.append(helpRecord) - PyGameData.g_fbHelpBattleRecord[calledPlayerID] = unNotifyRecordList - return True def __DoFBHelpBattleCall(callPlayerID, callPlayerName, msgList): ''' 助战召唤,不管最终过关与否,被召唤方都直接算助战成功,这里处理被召唤的,主动方在地图直接处理 @@ -644,31 +541,41 @@ helpCountLineID = 0 helpCountKey = (mapID, helpCountLineID) - curTime = int(time.time()) - xianyuanCoinUpper = IpyGameDataPY.GetFuncCfg("HelpBattlePoint", 1) # 每日仙缘币上限 - baseHelpPoint = fbFuncIpyData.GetHelpPoint() # 助战 - 基础仙缘币 - relationCoinAddDict = IpyGameDataPY.GetFuncEvalCfg("HelpBattlePoint", 2, {}) # 社交关系加成 {"社交关系":[过关加成, 助战加成], ...} GameWorld.DebugLog("召唤助战: mapID=%s, funcLineID=%s, helpCountKey=%s, calledPlayerDict=%s" % (mapID, funcLineID, helpCountKey, calledPlayerDict), callPlayerID) - isSweep = False - for calledPlayerID, relation in calledPlayerDict.items(): + for calledPlayerID in calledPlayerDict.keys(): if calledPlayerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: continue helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[calledPlayerID] - __DoCallHelpPlayer(callPlayerID, callPlayerName, helpBattlePlayer, relation, mapID, funcLineID, helpCountKey, isSweep, - curTime, xianyuanCoinUpper, relationCoinAddDict, baseHelpPoint) + helpBattlePlayer.todayHelpCountDict[helpCountKey] = helpBattlePlayer.todayHelpCountDict.get(helpCountKey, 0) + 1 return -def SendMapServer_FBHelpBattleRecord(curPlayer, syncHelpRecordList, isLogin=False): - if not syncHelpRecordList: - return +def __DoAssistFinish(curPlayer, msgList): + ## 协助完成 - helpRecordList = [] - for record in syncHelpRecordList: - helpRecordList.append([record.callPlayerID, record.callPlayerName, record.mapID, record.funcLineID, - record.xianyuanCoinAdd, record.relation, record.vipLV, record.recordTime]) - addXianyuanCoinMsg = str(["HelpRecord", helpRecordList, isLogin]) - curPlayer.MapServer_QueryPlayerResult(0, 0, 'FBHelpBattle', addXianyuanCoinMsg, len(addXianyuanCoinMsg)) - GameWorld.DebugLog(" MapServer_QueryPlayerResult %s" % addXianyuanCoinMsg, curPlayer.GetPlayerID()) + liheItemID, mapID, lineID, assistPlayerIDList = msgList[1:] + + assistPlayerDict = {} + for assistPlayerID in assistPlayerIDList: + if assistPlayerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: + continue + helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[assistPlayerID] + assistPlayerDict[assistPlayerID] = {"PlayerName":helpBattlePlayer.playerName, "Job":helpBattlePlayer.job, + "LV":helpBattlePlayer.playerLV, "RealmLV":helpBattlePlayer.realmLV, + "TodayGiftCount":helpBattlePlayer.getThanksGiftCountDict.get(liheItemID, 0)} + + # 插入新协助感谢 + PlayerAssist.AddNewAssistThanks(curPlayer, liheItemID, mapID, lineID, assistPlayerDict) + return + +def UpdateGetThanksGiftCountDict(curPlayer, itemID, updateTodayGiftCount): + ## 更新今日接收感谢礼盒次数 + + playerID = curPlayer.GetPlayerID() + if playerID not in PyGameData.g_fbHelpBattleCheckInPlayerDict: + return + helpBattlePlayer = PyGameData.g_fbHelpBattleCheckInPlayerDict[playerID] + helpBattlePlayer.getThanksGiftCountDict[itemID] = updateTodayGiftCount + GameWorld.DebugLog(" 更新镜像协助今日接收感谢礼盒次数: itemID=%s,updateTodayGiftCount=%s" % (itemID, updateTodayGiftCount), playerID) return -- Gitblit v1.8.0