hxp
2024-06-20 61bae8814450e86b1851cb892086b7081a675ff1
ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossActionControl.py
@@ -22,6 +22,7 @@
import PlayerControl
import IpyGameDataPY
import CrossActCTGBillboard
import PlayerActBossTrial
import CrossRealmMsg
import PyGameData
import ChConfig
@@ -57,6 +58,7 @@
                # 非活动中的,已经结算过了,不需要存储
                continue
            state = actInfo.get(ShareDefine.ActKey_State, 0)
            stateJoin = actInfo.get(ShareDefine.ActKey_StateJoin, 0)
            actID = actInfo.get(ShareDefine.ActKey_ID, 0)
            templateID = actInfo.get(ShareDefine.ActKey_TemplateID, 0)
            serverIDRangeList = actInfo.get(ShareDefine.ActKey_ServerIDRangeList, "")
@@ -67,8 +69,9 @@
            recData.SetValue2(state)
            recData.SetValue3(actID)
            recData.SetValue4(templateID)
            GameWorld.Log("    actName=%s,cfgID=%s,state=%s,actID=%s,templateID=%s,serverIDRangeList=%s"
                          % (actName, cfgID, state, actID, templateID, serverIDRangeList))
            recData.SetValue5(stateJoin)
            GameWorld.Log("    actName=%s,cfgID=%s,state=%s,stateJoin=%s,actID=%s,templateID=%s,serverIDRangeList=%s"
                          % (actName, cfgID, state, stateJoin, actID, templateID, serverIDRangeList))
            
    return
@@ -112,14 +115,24 @@
    GameWorld.DebugLog("找不到服务器组ID对应跨服活动分区! actName=%s, serverGroupID=%s" % (actName, serverGroupID))
    return
def GetCrossActInfoByCfgID(actName, cfgID):
def GetCrossActInfoByCfgID(actName, cfgID, zoneID=None):
    ## 获取cfgID对应的跨服活动状态信息,可选验证zoneID是否匹配
    crossActInfoDict = GetCrossActInfoDict()
    if actName not in crossActInfoDict:
        return
    curActInfoDict = crossActInfoDict[actName]
    if cfgID not in curActInfoDict:
        return
    return curActInfoDict[cfgID]
    actInfo = curActInfoDict[cfgID]
    if zoneID:
        # 验证分区ID是否正确
        ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})
        if not ipyDataDict:
            return
        ipyZoneID = ipyDataDict.get("ZoneID", 0)
        if zoneID != ipyZoneID:
            return
    return actInfo
def GetCrossActInfoDict():
    if PyGameData.g_crossActInfoDict == None:
@@ -137,6 +150,7 @@
            state = recData.GetValue2()
            actID = recData.GetValue3()
            templateID = recData.GetValue4()
            stateJoin = recData.GetValue5()
            if not state:
                continue
            if actName not in PyGameData.g_crossActInfoDict:
@@ -144,7 +158,8 @@
            actInfoDict = PyGameData.g_crossActInfoDict[actName]
            # 活动ID、状态、模板信息单独存储,重置活动判断用
            dbInfo = {ShareDefine.ActKey_ID:actID, ShareDefine.ActKey_State:state, ShareDefine.ActKey_TemplateID:templateID, 
                      ShareDefine.ActKey_CfgID:cfgID, ShareDefine.ActKey_ServerIDRangeList:serverIDRangeList}
                      ShareDefine.ActKey_CfgID:cfgID, ShareDefine.ActKey_ServerIDRangeList:serverIDRangeList,
                      ShareDefine.ActKey_StateJoin:stateJoin}
            actInfo = {}
            actInfo.update(dbInfo)
            actInfo[ShareDefine.ActKey_DBInfo] = dbInfo
@@ -281,6 +296,13 @@
                startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
                GameWorld.Log("        星期X转化为日期: %s ~ %s" % (startDateStr, endDateStr))
                
            if hasattr(ipyData, "GetJoinStartTime") and hasattr(ipyData, "GetJoinEndTime"):
                joinStartTimeStr = ipyData.GetJoinStartTime()
                joinEndTimeStr = ipyData.GetJoinEndTime()
            else:
                joinStartTimeStr = ""
                joinEndTimeStr = ""
            if hasattr(ipyData, "GetStartTimeList") and hasattr(ipyData, "GetEndTimeList"):
                startHMStrList = ipyData.GetStartTimeList()
                endHMStrList = ipyData.GetEndTimeList()
@@ -296,6 +318,7 @@
                GameWorld.ErrLog("        活动配置开始及结束时间个数不匹配! actName=%s,cfgID=%s,startHMStrList=%s,endHMStrList=%s" 
                                 % (actName, cfgID, startHMStrList, endHMStrList))
                
            isDayReset = 0 if not hasattr(ipyData, "GetIsDayReset") else ipyData.GetIsDayReset()
            resetType = 0 if not hasattr(ipyData, "GetResetType") else ipyData.GetResetType() # 重置类型,0-0点重置;1-5点重置
            if resetType == 1:
                startDayDate = datetime.datetime.strptime("%s 05:00:00" % (startDateStr), ChConfig.TYPE_Time_Format)
@@ -353,6 +376,17 @@
            GameWorld.Log("        startList=%s" % (startList))
            GameWorld.Log("        end  List=%s" % (endList))
            
            joinStartTimeList, joinEndTimeList = [], [] # 可指定活动可参与的时间点,不影响活动状态,只影响活动某些功能的参与时机,如上榜类
            if joinStartTimeStr:
                if isDayReset:
                    joinStartTimeList.append(datetime.datetime.strptime("%d-%d-%d %s:00" % (curDateTime.year, curDateTime.month, curDateTime.day, joinStartTimeStr), ChConfig.TYPE_Time_Format))
                    joinEndTimeList.append(datetime.datetime.strptime("%d-%d-%d %s:00" % (curDateTime.year, curDateTime.month, curDateTime.day, joinEndTimeStr), ChConfig.TYPE_Time_Format))
                else:
                    joinStartTimeList.append(datetime.datetime.strptime("%s %s:00" % (startDateStr, joinStartTimeStr), ChConfig.TYPE_Time_Format))
                    joinEndTimeList.append(datetime.datetime.strptime("%s %s:00" % (endDateStr, joinEndTimeStr), ChConfig.TYPE_Time_Format))
            GameWorld.Log("        joinStartTimeList=%s" % (joinStartTimeList))
            GameWorld.Log("        joinEndTime  List=%s" % (joinEndTimeList))
            for dtIndex, startDateTime in enumerate(startList):
                endDateTime = endList[dtIndex]
                # 广播 - 相对实际开始时间
@@ -391,7 +425,7 @@
                
            if actName not in actTimeInfoDict:
                actTimeInfoDict[actName] = {}
            actTimeInfoDict[actName][cfgID] = [ipyData, startList, endList, notifyDict]
            actTimeInfoDict[actName][cfgID] = [ipyData, startList, endList, notifyDict, joinStartTimeList, joinEndTimeList]
            if actName not in actCfgIDInfoDict:
                actCfgIDInfoDict[actName] = [[], []]
            endCfgIDList, actCfgIDList = actCfgIDInfoDict[actName]
@@ -445,7 +479,6 @@
                    
                dayIndex = (curDateTime - startDayDate).days
                actIDDateTime = startDayDate
                isDayReset = 0 if not hasattr(ipyData, "GetIsDayReset") else ipyData.GetIsDayReset()
                # 按时段开的默认每天重置
                if isDayReset or (startHMStrList and endHMStrList):
                    actIDDateTime += datetime.timedelta(days=dayIndex)
@@ -504,10 +537,11 @@
        for cfgID in cfgIDList:
            if cfgID not in timeInfoDict:
                continue
            ipyData, startList, endList, notifyDict = timeInfoDict[cfgID]
            ipyData, startList, endList, notifyDict, joinStartTimeList, joinEndTimeList = timeInfoDict[cfgID]
            
            isEnd = True
            state = 0 # 默认关闭
            stateJoin = 0 # 可参与状态
            cfgID = ipyData.GetCfgID()
            groupName = ipyData.GetActGroupName()
            zoneID = ipyData.GetZoneID()
@@ -526,6 +560,15 @@
                if endList:
                    isEnd = (curDateTime >= endList[-1])
                    
                if joinStartTimeList:
                    for jIndex, joinStartDateTime in enumerate(joinStartTimeList):
                        endJoinDateTime = joinEndTimeList[jIndex]
                        if joinStartDateTime <= curDateTime < endJoinDateTime:
                            stateJoin = state
                            break
                else:
                    stateJoin = state
            serverIDRangeList = actInfoDict.get(ShareDefine.ActKey_ServerIDRangeList)
            # 全服广播提示信息
            if curDateTime in notifyDict:
@@ -539,6 +582,7 @@
                
            dbInfo = actInfoDict.get(ShareDefine.ActKey_DBInfo, {})
            dbState = dbInfo.get(ShareDefine.ActKey_State, 0)
            dbStateJoin = dbInfo.get(ShareDefine.ActKey_StateJoin, 0)
            dbCfgID = dbInfo.get(ShareDefine.ActKey_CfgID, 0)
            dbActID = dbInfo.get(ShareDefine.ActKey_ID, 0)
            dbTemplateID = dbInfo.get(ShareDefine.ActKey_TemplateID, 0)
@@ -550,7 +594,7 @@
                
            actID = actInfoDict.get(ShareDefine.ActKey_ID, 0)
            templateID = actInfoDict.get(ShareDefine.ActKey_TemplateID, 0)
            if not isReload and dbState == state and dbActID == actID and not forceReset:
            if not isReload and dbState == state and dbStateJoin == stateJoin and dbActID == actID and not forceReset:
                #已经是这个状态了
                continue
            GameWorld.Log("跨服运营活动状态: actName=%s,cfgID=%s,groupName=%s,zoneID=%s,dbState=%s -> state=%s,isEnd=%s, dbActID=%s -> actID=%s,forceReset=%s" 
@@ -558,8 +602,10 @@
            
            # 更新状态
            actInfoDict[ShareDefine.ActKey_State] = state
            actInfoDict[ShareDefine.ActKey_StateJoin] = stateJoin
            dbInfo = {ShareDefine.ActKey_ID:actID, ShareDefine.ActKey_State:state, ShareDefine.ActKey_TemplateID:templateID, 
                      ShareDefine.ActKey_CfgID:cfgID, ShareDefine.ActKey_ServerIDRangeList:serverIDRangeList}
                      ShareDefine.ActKey_CfgID:cfgID, ShareDefine.ActKey_ServerIDRangeList:serverIDRangeList,
                      ShareDefine.ActKey_StateJoin:stateJoin}
            actInfoDict[ShareDefine.ActKey_DBInfo] = dbInfo
            #GameWorld.Log("    活动状态同步信息: actName=%s,cfgID=%s,groupName=%s,zoneID=%s,actInfoDict=%s" % (actName, cfgID, groupName, zoneID, actInfoDict))
            if actName not in sysnCrossActInfoDict:
@@ -572,6 +618,9 @@
                
                if actName == ShareDefine.CrossActName_CTGBillboard:
                    CrossActCTGBillboard.OnActIDChange(cfgID, dbTemplateID, state)
                if actName == ShareDefine.CrossActName_BossTrial:
                    PlayerActBossTrial.OnCrossActIDChange(cfgID, state)
                    
                else:
                    actChangeList.append([actName, ipyData, state, cfgID, groupName, zoneID, dbActID, actID, forceReset, dbTemplateID])
@@ -586,6 +635,7 @@
                              % (actName, cfgID, groupName, zoneID, dbState, state, actIDChange, dbTemplateID))
                actStateChangeList.append([actName, ipyData, dbState, state, cfgID, groupName, zoneID, actIDChange, dbTemplateID])
                
            GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CrossActInfo % actName, crossActInfoDict[actName])
            # 非活动中的处理完关闭后,最后删除
            if not state and isEnd:
                del crossActInfoDict[actName][cfgID]