From 466edcd49de033afca96312a4291116fa282f8c3 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 15 五月 2023 20:11:45 +0800
Subject: [PATCH] 4075 【BT8】【BT9】【主干】限时抢购修复多活动同时开时导致相互重置活动记录bug;(比如常规和合服活动都开放的时候)

---
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossActionControl.py |  235 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 229 insertions(+), 6 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossActionControl.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossActionControl.py
index 0129fbc..be85cb0 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossActionControl.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossActionControl.py
@@ -483,7 +483,7 @@
     curDateTime = GameWorld.GetServerTime()
     curDateTime = datetime.datetime.strptime("%d-%d-%d %d:%d:00" % (curDateTime.year, curDateTime.month, curDateTime.day,
                                                                     curDateTime.hour, curDateTime.minute), ChConfig.TYPE_Time_Format)
-    
+    actChangeList = []
     sysnCrossActInfoDict = {}
     for actName in ShareDefine.CrossActNameList:
         if actName not in actTimeInfoDict or actName not in crossActInfoDict or actName not in actCfgIDInfoDict:
@@ -562,9 +562,8 @@
                 if actName == ShareDefine.CrossActName_CTGBillboard:
                     CrossActCTGBillboard.OnActIDChange(cfgID, dbTemplateID, state)
                     
-                elif actName == ShareDefine.CrossActName_LuckyCloudBuy:
-                    import CrossLuckyCloudBuy
-                    CrossLuckyCloudBuy.OnLuckyCloudBuyReset(ipyData, state)
+                else:
+                    actChangeList.append([actName, ipyData, state, cfgID, groupName, zoneID, dbActID, actID, forceReset, dbTemplateID])
                     
             # 非活动中的处理完关闭后,最后删除
             if not state:
@@ -574,8 +573,23 @@
                 #GameWorld.Log("    移除结束的活动: actName=%s,cfgID=%s,crossActInfoDict=%s" % (actName, cfgID, crossActInfoDict))
                 
     # 同步子服务器
-    serverGroupIDList = []
-    CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossActInfo, sysnCrossActInfoDict, serverGroupIDList)
+    if sysnCrossActInfoDict:
+        serverGroupIDList = []
+        CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossActInfo, sysnCrossActInfoDict, serverGroupIDList)
+    
+    # 需要等活动等同步到子服后才处理以下逻辑,不然可能导致子服没有活动时间明细引起活动异常
+    for changeInfo in actChangeList:
+        actName, ipyData, state, cfgID, groupName, zoneID, dbActID, actID, forceReset, dbTemplateID = changeInfo
+        GameWorld.Log("    活动ID变更: actName=%s,cfgID=%s,groupName=%s,zoneID=%s,dbActID=%s -> actID=%s,forceReset=%s,dbTemplateID=%s" 
+                      % (actName, cfgID, groupName, zoneID, dbActID, actID, forceReset, dbTemplateID))
+        
+        if actName == ShareDefine.CrossActName_LuckyCloudBuy:
+            import CrossLuckyCloudBuy
+            CrossLuckyCloudBuy.OnLuckyCloudBuyReset(ipyData, state)
+        elif actName == ShareDefine.CrossActName_AllRecharge:
+            import CrossActAllRecharge
+            CrossActAllRecharge.OnActIDChange(ipyData, state)
+            
     return
 
 def Sync_CrossActInfoToClientServer(serverGroupID=0):
@@ -624,6 +638,28 @@
                 
     return
 
+def GetPlayerCrossActInfo(curPlayer, actName):
+    ## 获取跨服玩家对应的跨服活动信息
+    if PyGameData.g_crossActInfoDict == None:
+        return {}
+    actInfoDict = PyGameData.g_crossActInfoDict.get(actName, {})
+    if not actInfoDict:
+        return {}
+    playerServerID = GameWorld.GetPlayerServerID(curPlayer)
+    for actInfo in actInfoDict.values():
+        if not actInfo.get(ShareDefine.ActKey_State, 0):
+            continue
+        if ShareDefine.ActKey_ServerIDRangeList not in actInfo:
+            continue
+        serverIDRangeList = actInfo[ShareDefine.ActKey_ServerIDRangeList]
+        if not serverIDRangeList:
+            # 全服开启
+            return actInfo
+        for serverIDA, serverIDB in serverIDRangeList:
+            if serverIDA <= playerServerID <= serverIDB:
+                return actInfo
+    return {}
+
 def SendMapServerCrossActionState():
     # 地图启动成功时通知跨服活动相关状态  - 本服地图,跨服地图不需要通知
     
@@ -637,3 +673,190 @@
         
     return
 
+## ================================================================================================
+
+def __GetTodayCrossDailyActionInfo():
+    # 获取本日待处理的日常活动信息
+    key = "TodayCrossDailyActionInfo"
+    curTime = int(time.time())
+    curDateStr = GameWorld.ChangeTimeNumToStr(curTime, ChConfig.TYPE_Time_YmdFormat) # 当天日期
+    loadSign = curDateStr
+    TodayDailyActionInfo = IpyGameDataPY.GetConfigEx(key)
+    if TodayDailyActionInfo and TodayDailyActionInfo[0] == loadSign:
+        GameWorld.DebugLog("已经加载过本日跨服日常活动处理信息!loadSign=%s" % loadSign)
+        return TodayDailyActionInfo[1]
+    
+    todayActionInfo = []
+    
+    dayTime = GameWorld.GetServerTime()
+    weekDay = str(dayTime.weekday() + 1) # 格式为json, 当前星期几, 1代表星期1
+    
+    GameWorld.Log("===== 加载今天跨服日常活动信息 =====")
+    GameWorld.Log("当前星期%s" % weekDay)
+    
+    dailyTimeInfoList = []
+    
+    ipyDataMgr = IpyGameDataPY.IPY_Data()
+    for i in xrange(ipyDataMgr.GetCrossDailyActionCount()):
+        dailyIpyData = ipyDataMgr.GetCrossDailyActionByIndex(i)
+        dailyID = dailyIpyData.GetDailyID()
+        
+        openTimeDict = dailyIpyData.GetOpenTimeDict()
+        # 没有时间控制的,代表永久开放
+        if not openTimeDict:
+            todayActionInfo.append([dailyID])
+            GameWorld.Log("    增加本日常开跨服日常活动信息: dailyID=%s" % dailyID)
+            continue
+        
+        #如果星期key中存在 "0" 代表每日都开启
+        if "0" not in openTimeDict and weekDay not in openTimeDict:
+            GameWorld.Log("    不是跨服日常活动开启星期: dailyID=%s,openWeekLimit=%s" % (dailyID, openTimeDict.keys()))
+            continue
+        openTimeList = openTimeDict["0"] if "0" in openTimeDict else openTimeDict[weekDay]
+        dailyTimeInfoList.append([openTimeList, dailyIpyData])
+        
+    GameWorld.Log("    -----------------------")
+    for openTimeList, ipyData in dailyTimeInfoList:
+        dailyID = ipyData.GetDailyID()
+        notifyInfoDict = ipyData.GetNotifyInfo()
+        
+        openList = [] # [(时,分), ...]
+        overList = [] # [(时,分), ...]
+        goonStateDict = {} # {状态:[(aDateTime, bDateTime)], ...}
+        notifyDict = {} # {(时,分):[notifyKey, [参数]], ...}
+        OpenState = 1 # 定义开启状态为1
+        
+        for hour, minute in openTimeList:  
+            openTimeStr = "%s %02d:%02d:%02d" % (curDateStr, hour, minute, 0)
+            
+            # 精确开启时间
+            openDateTime = datetime.datetime.strptime(openTimeStr, ChConfig.TYPE_Time_Format)
+            openList.append((openDateTime.hour, openDateTime.minute))
+            
+            # 精确关闭时间
+            overDateTime = openDateTime + datetime.timedelta(minutes=ipyData.GetDuration())
+            overList.append((overDateTime.hour, overDateTime.minute))
+            
+            # goon 开启状态
+            openStateTimeList = goonStateDict.get(OpenState, [])
+            openStateTimeList.append((openDateTime, overDateTime))
+            goonStateDict[OpenState] = openStateTimeList
+            
+            # goon 其他状态,待扩展
+            # ...
+            
+            # 广播
+            for notifyMinute, notifyInfo in notifyInfoDict.items():
+                notifyDateTime = openDateTime + datetime.timedelta(minutes=notifyMinute)
+                notifyDict[(notifyDateTime.hour, notifyDateTime.minute)] = notifyInfo
+                
+        todayActionInfo.append([dailyID, openList, overList, goonStateDict, notifyDict])
+        GameWorld.Log("    增加本日跨服日常活动信息: dailyID=%s,openList=%s,overList=%s,goonStateDict=%s,notifyDict=%s" 
+                      % (dailyID, openList, overList, goonStateDict, notifyDict))
+        
+    TodayDailyActionInfo = IpyGameDataPY.SetConfigEx(key, [loadSign, todayActionInfo])
+    GameWorld.Log("本日跨服日常活动信息加载完毕! loadSign=%s" % loadSign)
+    GameWorld.Log("=============================================================")
+    return TodayDailyActionInfo[1]
+
+def Dispose_CrossDailyActionState():
+    # 跨服日常活动状态变更检查处理
+    
+    todayDailyActionInfo = __GetTodayCrossDailyActionInfo()
+    if not todayDailyActionInfo:
+        return
+    
+    gameWorld = GameWorld.GetGameWorld()
+    dayTime = GameWorld.GetServerTime()
+    curHourMinute = (dayTime.hour, dayTime.minute)
+    
+    sysnCrossDailyActionStateDict = {}
+    
+    for actionInfo in todayDailyActionInfo:
+        dailyActionID = actionInfo[0]
+        state = 0 # 默认关闭
+        
+        # 长度为1的代表常开的活动
+        if len(actionInfo) == 1:
+            state = 1
+        else:
+            #openList = [] # [(时,分), ...]
+            #overList = [] # [(时,分), ...]
+            #goonStateDict = {} # {状态:[(aDateTime, bDateTime)], ...}
+            #notifyDict = {} # {(时,分):[notifyKey, [参数]], ...}
+            openList, overList, goonStateDict, notifyDict = actionInfo[1:]
+            
+            # 精确匹配开启
+            if curHourMinute in openList:
+                state = 1
+            # 精确匹配关闭
+            elif curHourMinute in overList:
+                state = 0
+            # goon 状态
+            else:
+                for goonState, openStateTimeList in goonStateDict.items():
+                    for dateTimeInfo in openStateTimeList:
+                        if dateTimeInfo[0] < dayTime < dateTimeInfo[1]:
+                            state = goonState
+                            break
+                        
+            # 全服广播提示信息
+            if curHourMinute in notifyDict:
+                notifyKey, paramList = notifyDict[curHourMinute]
+                serverGroupIDList = []
+                PlayerControl.WorldNotifyCross(serverGroupIDList, 0, notifyKey, paramList)
+                
+        dictName = ShareDefine.Def_Notify_WorldKey_CrossDailyActionState % dailyActionID
+        beforeState = gameWorld.GetDictByKey(dictName)
+        if beforeState == state:
+            #已经是这个状态了
+            continue
+        
+        if state:
+            if dailyActionID == ShareDefine.CrossDailyActionID_YaomoBoss:
+                GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_ActionBossRebornSign % dailyActionID, int(time.time()))
+                
+        sysnCrossDailyActionStateDict[dailyActionID] = state
+        #通知Mapserver,设置字典
+        GameWorld.SendMapServerMsgEx(dictName, state)
+        #更新字典值
+        gameWorld.SetDict(dictName, state)
+        GameWorld.Log("跨服日常活动状态变更: dailyActionID=%s,state=%s,dictName=%s" % (dailyActionID, state, dictName))
+        
+    # 同步子服务器
+    if sysnCrossDailyActionStateDict:
+        serverGroupIDList = []
+        CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_CrossDailyActionState, sysnCrossDailyActionStateDict, serverGroupIDList)
+        
+    return
+
+def SendMapServerCrossDailyActionState():
+    # 地图启动成功时通知本日进行中的日常活动状态
+    
+    todayDailyActionInfo = __GetTodayCrossDailyActionInfo()
+    if not todayDailyActionInfo:
+        return
+    
+    gameWorld = GameWorld.GetGameWorld()
+    for actionInfo in todayDailyActionInfo:
+        dailyActionID = actionInfo[0]
+        dictName = ShareDefine.Def_Notify_WorldKey_CrossDailyActionState % dailyActionID 
+        state = gameWorld.GetDictByKey(dictName)
+        if state:
+            GameWorld.SendMapServerMsgEx(dictName, state)
+            
+    return
+
+def CrossServerMsg_CrossDailyActionState(msgData):
+    
+    gameWorld = GameWorld.GetGameWorld()
+    for dailyActionID, state in msgData.items():
+        dictName = ShareDefine.Def_Notify_WorldKey_CrossDailyActionState % dailyActionID
+        #通知Mapserver,设置字典
+        GameWorld.SendMapServerMsgEx(dictName, state)
+        #更新字典值
+        gameWorld.SetDict(dictName, state)
+        GameWorld.Log("收到跨服日常活动状态变更: dailyActionID=%s,state=%s,dictName=%s" % (dailyActionID, state, dictName))
+        
+    return
+

--
Gitblit v1.8.0