#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package DB.StructData.DBFamily
|
#
|
# @todo:DB¼Ò×åÏà¹Ø
|
# @author hxp
|
# @date 2025-05-09
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: DB¼Ò×åÏà¹Ø
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2025-05-09 12:20"""
|
#-------------------------------------------------------------------------------
|
|
import DBStruct
|
import CommFunc
|
import GameWorld
|
import ShareDefine
|
import PlayerControl
|
import PlayerViewCache
|
import PyMongoMain
|
import DBDataMgr
|
import ChConfig
|
import DBComm
|
|
import time
|
|
FamilyUpperLimitCount = 2000
|
|
class FamilyActionData():
|
|
def __init__(self, dbData=None, dataToJson=False):
|
self.__dbData = DBStruct.tagDBFamilyAction() if not dbData else dbData
|
self.__dataDict = DBComm.UserDataDict(self.__dbData, "Data", "DataLen", dataToJson)
|
return
|
|
def GetFamilyID(self): return self.__dbData.FamilyID
|
def GetActionType(self): return self.__dbData.ActionType
|
def GetName(self): return self.__dbData.Name
|
def SetName(self, name): self.__dbData.Name = name
|
def GetTime(self): return self.__dbData.Time
|
def SetTime(self, setTime): self.__dbData.Time = setTime
|
def GetValue1(self): return self.__dbData.Value1
|
def SetValue1(self, value1): self.__dbData.Value1 = value1
|
def GetValue2(self): return self.__dbData.Value2
|
def SetValue2(self, value2): self.__dbData.Value2 = value2
|
def GetValue3(self): return self.__dbData.Value3
|
def SetValue3(self, value3): self.__dbData.Value3 = value3
|
def GetValue4(self): return self.__dbData.Value4
|
def SetValue4(self, value4): self.__dbData.Value4 = value4
|
def GetValue5(self): return self.__dbData.Value5
|
def SetValue5(self, value5): self.__dbData.Value5 = value5
|
def GetValue6(self): return self.__dbData.Value6
|
def SetValue6(self, value6): self.__dbData.Value6 = value6
|
def GetUserDict(self): return self.__dataDict.GetData()
|
def GetUserData(self): return self.__dataDict.ToString()
|
def SetUserData(self, value): self.__dataDict.SetData(value)
|
def GetBuffer(self):
|
self.__dataDict.ToString()
|
return self.__dbData.getBuffer()
|
|
class FamilyAction():
|
|
def __init__(self):
|
self.familyID = 0
|
self.actionType = 0
|
self.__actionDataList = []
|
return
|
|
def InitActionInstance(self, dbData):
|
'''³õʼ»¯¹¦ÄÜÊý¾ÝʵÀý£¬´´½¨»ò¼ÓÔØÊý¾ÝʱͨÓ㬹¦ÄÜÒ»°ã²»µ÷ÓÃ
|
@param dbData: ʵÀý¶ÔÓ¦°ó¶¨µÄdbData
|
@return: ³É¹¦·µ»ØÊµÀý¶ÔÏó£¬Ê§°Ü·µ»ØNone
|
'''
|
dataToJson = False
|
# Èç¹ûÐèÒª dataToJson£¬¿É¸ù¾ÝActionTypeÔÚÕâÀï´¦Àí
|
if dbData.ActionType in []:
|
dataToJson = True
|
actionData = FamilyActionData(dbData, dataToJson)
|
self.__actionDataList.append(actionData)
|
return actionData
|
|
def AddAction(self, maxCount=None):
|
## Ìí¼ÓÏÉÃËActionÊý¾Ý
|
# @param maxCount: ¿É´«ÈëÓÉÅäÖþö¶¨µÄ×î´óÌõÊý£¬Èç¹ûΪNoneÔò½øÒ»²½È¡³ÌÐòĬÈÏÉ趨µÄ×î´óÌõÊý£¬¶¼Ã»ÅäÖõϰĬÈϲ»ÏÞÌõÊý
|
|
fullClear = True
|
if maxCount == None:
|
maxCount = ShareDefine.ActionTypeSaveCnt.get(self.actionType, 0)
|
actionData = None
|
if maxCount and self.Count() >= maxCount:
|
if not fullClear:
|
#³¬¹ý¼Ç¼¼Ç¼²»ÁËÁË
|
return actionData
|
self.SortByTime() # °´Ê±¼äÉýÐò
|
self.DelAction(0) # ɾ³ýµÚÒ»¸ö
|
|
dbData = DBStruct.tagDBFamilyAction()
|
dbData.FamilyID = self.familyID
|
dbData.ActionType = self.actionType
|
dbData.Time = int(time.time())
|
|
actionData = self.InitActionInstance(dbData)
|
return actionData
|
|
def SortByTime(self):
|
self.__actionDataList.sort(key=lambda f: (f.GetTime()))
|
return
|
|
def DelAction(self, index):
|
if 0 <= index < len(self.__actionDataList):
|
self.__actionDataList.pop(index)
|
return
|
|
def GetOneAction(self, isAdd=False):
|
## »ñȡһ¸öactionÊý¾Ý£¬½öÕë¶ÔÖ»´æÒ»ÌõÊý¾ÝµÄÀàÐÍ
|
aData = None
|
if self.Count():
|
aData = self.At(0)
|
elif isAdd:
|
aData = self.AddAction()
|
return aData
|
|
def Count(self): return len(self.__actionDataList)
|
def At(self, index):
|
aData = None
|
if 0 <= index < len(self.__actionDataList):
|
aData = self.__actionDataList[index]
|
elif False:
|
aData = FamilyActionData()
|
return aData
|
|
class FamilyActionMgr():
|
|
def __init__(self):
|
self.__familyActionDict = {} # ÏÉÃËactionÐÅÏ¢ {familyID:{actionType:FamilyAction, ...}, ...}
|
return
|
|
def GetFamilyAction(self, familyID, actionType):
|
if familyID not in self.__familyActionDict:
|
self.__familyActionDict[familyID] = {}
|
actionDict = self.__familyActionDict[familyID]
|
if actionType in actionDict:
|
action = actionDict[actionType]
|
else:
|
action = FamilyAction()
|
action.familyID = familyID
|
action.actionType = actionType
|
actionDict[actionType] = action
|
return action
|
|
def DelFamilyAction(self, familyID, actionType):
|
if familyID not in self.__familyActionDict:
|
return
|
actionDict = self.__familyActionDict[familyID]
|
actionDict.pop(actionType, None)
|
return
|
|
def ClearFamilyAction(self, familyID):
|
self.__familyActionDict.pop(familyID, None)
|
return
|
|
def GetActionTypeList(self, familyID):
|
## »ñÈ¡ÓÐÊý¾ÝµÄactionÀàÐÍÁбí
|
return self.__familyActionDict.get(familyID, {}).keys()
|
|
class FamilyMem():
|
|
def __init__(self, dbData=None):
|
self.__dbData = DBStruct.tagDBFamilyMem() if not dbData else dbData
|
return
|
|
def GetPlayerID(self): return self.__dbData.PlayerID
|
def GetFamilyID(self): return self.__dbData.FamilyID
|
def GetJoinTime(self): return self.__dbData.JoinTime
|
def GetPlayerName(self): return self.__dbData.PlayerName
|
def SetPlayerName(self, playerName): self.__dbData.PlayerName = playerName
|
def GetLV(self): return self.__dbData.LV
|
def SetLV(self, lv): self.__dbData.LV = lv
|
def GetJob(self): return self.__dbData.Job
|
def SetJob(self, job): self.__dbData.Job = job
|
def GetRealmLV(self): return self.__dbData.RealmLV
|
def SetRealmLV(self, realmLV): self.__dbData.RealmLV = realmLV
|
def GetFace(self): return self.__dbData.Face
|
def SetFace(self, face): self.__dbData.Face = face
|
def GetFacePic(self): return self.__dbData.FacePic
|
def SetFacePic(self, facePic): self.__dbData.FacePic = facePic
|
def GetFightPower(self): return self.__dbData.FightPower
|
def GetFightPowerEx(self): return self.__dbData.FightPowerEx
|
def GetFightPowerTotal(self): return self.__dbData.FightPowerEx * ChConfig.Def_PerPointValue + self.__dbData.FightPower
|
def SetFightPowerTotal(self, fightPowerTotal):
|
self.__dbData.FightPower = fightPowerTotal % ChConfig.Def_PerPointValue
|
self.__dbData.FightPowerEx = fightPowerTotal / ChConfig.Def_PerPointValue
|
return
|
def GetServerID(self): return self.__dbData.ServerID
|
def SetServerID(self, serverID): self.__dbData.ServerID = serverID
|
def GetOffTime(self): return self.__dbData.OffTime
|
def SetOffTime(self, offTime): self.__dbData.OffTime = offTime
|
def GetFmLV(self): return self.__dbData.FmLV
|
def SetFmLV(self, fmLV): self.__dbData.FmLV = fmLV
|
def GetContribTotal(self): return self.__dbData.ContribTotal
|
def SetContribTotal(self, contribTotal): self.__dbData.ContribTotal = contribTotal
|
def GetContribWeek(self): return self.__dbData.ContribWeek
|
def SetContribWeek(self, contribWeek): self.__dbData.ContribWeek = contribWeek
|
def GetBuffer(self): return self.__dbData.getBuffer()
|
|
def RefreshMemberByID(self, playerID):
|
## ¸ù¾ÝÍæ¼ÒID¸üгÉÔ±Êý¾Ý£¬Ò»°ãÓÃÓÚÀëÏß¹¦ÄÜ£¬ÈçÌí¼ÓÀëÏß³ÉÔ±£¬Ö±½ÓʹÓò鿴»º´æ¸üÐÂ
|
if playerID != self.GetPlayerID():
|
return
|
viewCache = PlayerViewCache.FindViewCache(playerID)
|
if not viewCache:
|
return
|
self.SetPlayerName(viewCache.GetPlayerName())
|
self.SetLV(viewCache.GetLV())
|
self.SetJob(viewCache.GetJob())
|
self.SetRealmLV(viewCache.GetRealmLV())
|
self.SetFace(viewCache.GetFace())
|
self.SetFacePic(viewCache.GetFacePic())
|
self.SetServerID(viewCache.GetServerID())
|
fpChange = False
|
fightPowerTotal = viewCache.GetFightPowerTotal()
|
if self.GetFightPowerTotal() < fightPowerTotal:
|
self.SetFightPowerTotal(fightPowerTotal)
|
fpChange = True
|
return fpChange
|
|
def RefreshMember(self, curPlayer):
|
'''ˢгÉÔ±ÐÅÏ¢£¬ÏÉÃ˳ÉÔ±ÊôÓÚÓÀ¾Ã¹¦ÄÜÊý¾Ý£¬³ý·ÇÏÉÃ˽âÉ¢£¬ËùÒÔµ¥¶À´æÒ»·Ý³ÉÔ±»ù´¡ÐÅÏ¢£¬·ÀÖ¹¹ý¶ÈÒÀÀµ²é¿´»º´æÊý¾ÝÒý·¢µÄÎÊÌâ
|
@return: Õ½Á¦ÊÇ·ñ±ä¸ü
|
'''
|
if not curPlayer or curPlayer.GetPlayerID() != self.GetPlayerID():
|
return
|
self.SetPlayerName(curPlayer.GetPlayerName())
|
self.SetLV(curPlayer.GetLV())
|
self.SetJob(curPlayer.GetJob())
|
self.SetRealmLV(curPlayer.GetOfficialRank())
|
self.SetFace(curPlayer.GetFace())
|
self.SetFacePic(curPlayer.GetFacePic())
|
self.SetServerID(GameWorld.GetPlayerServerID(curPlayer))
|
fightPowerTotal = PlayerControl.GetFightPower(curPlayer)
|
fpChange = self.GetFightPowerTotal() != fightPowerTotal
|
self.SetFightPowerTotal(fightPowerTotal)
|
return fpChange
|
|
class Family():
|
|
def __init__(self, dbData=None):
|
self.__dbData = DBStruct.tagDBFamily() if not dbData else dbData
|
self.__memberList = [] # [FamilyMem, ...]
|
self.__memberDict = {} # ³ÉÔ±×Öµä {playerID:FamilyMem, ...}
|
self.__familyMgr = DBDataMgr.GetFamilyMgr()
|
self.__actionMgr = DBDataMgr.GetFamilyActionMgr()
|
self.__memFightPowerChange = None # ³ÉÔ±Õ½Á¦ÊÇ·ñÓб仯£¬Ä¬ÈÏNone£¬´ú±íδ´¦Àí¹ý
|
return
|
|
def GetID(self): return self.__dbData.ID
|
def GetCreateTime(self): return self.__dbData.CreateTime
|
def GetServerID(self): return self.__dbData.ServerID
|
def GetName(self): return self.__dbData.Name
|
def SetName(self, name): self.__dbData.Name = name
|
def GetLeaderID(self): return self.__dbData.LeaderID
|
def SetLeaderID(self, leaderID): self.__dbData.LeaderID = leaderID
|
def GetLV(self): return self.__dbData.LV
|
def SetLV(self, lv): self.__dbData.LV = lv
|
def GetExp(self): return self.__dbData.Exp
|
def SetExp(self, exp): self.__dbData.Exp = exp
|
def GetJoinReview(self): return self.__dbData.JoinReview # ³ÉÔ±¼ÓÈëÊÇ·ñÐèÒªÉóºË£¬Ä¬ÈÏ0×Ô¶¯¼ÓÈë
|
def SetJoinReview(self, joinReview): self.__dbData.JoinReview = joinReview
|
def GetJoinLVMin(self): return self.__dbData.JoinLVMin
|
def SetJoinLVMin(self, JoinLVMin): self.__dbData.JoinLVMin = JoinLVMin
|
def GetBroadcast(self): return self.__dbData.Broadcast
|
def SetBroadcast(self, broadcast):
|
self.__dbData.Broadcast = broadcast
|
self.__dbData.BroadcastLen = len(self.__dbData.Broadcast)
|
return
|
def GetFightPower(self): return self.__dbData.FightPower
|
def GetFightPowerEx(self): return self.__dbData.FightPowerEx
|
def GetFightPowerTotal(self): return self.__dbData.FightPowerEx * ChConfig.Def_PerPointValue + self.__dbData.FightPower
|
def SetFightPowerTotal(self, fightPowerTotal):
|
self.__dbData.FightPower = fightPowerTotal % ChConfig.Def_PerPointValue
|
self.__dbData.FightPowerEx = fightPowerTotal / ChConfig.Def_PerPointValue
|
return
|
def GetEmblemID(self): return self.__dbData.EmblemID
|
def SetEmblemID(self, emblemID): self.__dbData.EmblemID = emblemID
|
def GetBuffer(self): return self.__dbData.getBuffer()
|
|
## ------------------------------------------------
|
def InitMemberInstance(self, dbData):
|
'''³õʼ»¯¹¦ÄÜÊý¾ÝʵÀý£¬´´½¨»ò¼ÓÔØÊý¾ÝʱͨÓ㬹¦ÄÜÒ»°ã²»µ÷ÓÃ
|
@param dbData: ʵÀý¶ÔÓ¦°ó¶¨µÄdbData
|
@return: ³É¹¦·µ»ØÊµÀý¶ÔÏó£¬Ê§°Ü·µ»ØNone
|
'''
|
member = FamilyMem(dbData)
|
playerID = member.GetPlayerID()
|
if playerID in self.__memberDict:
|
return
|
self.__memberDict[playerID] = member
|
self.__memberList.append(member)
|
return member
|
|
def GetMemberIDList(self): return self.__memberDict.keys()
|
|
def AddMember(self, playerID):
|
member = None
|
if playerID in self.__memberDict:
|
member = self.__memberDict[playerID]
|
else:
|
dbData = DBStruct.tagDBFamilyMem()
|
dbData.PlayerID = playerID
|
dbData.FamilyID = self.GetID()
|
dbData.JoinTime = int(time.time())
|
member = self.InitMemberInstance(dbData)
|
if not member and False:
|
member = FamilyMem()
|
self.__memFightPowerChange = True
|
return member
|
|
def DeleteMember(self, playerID):
|
delMem = self.__memberDict.pop(playerID, None)
|
if delMem in self.__memberList:
|
self.__memberList.remove(delMem)
|
self.__memFightPowerChange = True
|
return delMem
|
|
def FindMember(self, playerID):
|
mem = None
|
if playerID in self.__memberDict:
|
mem = self.__memberDict[playerID]
|
elif False:
|
mem = FamilyMem()
|
return mem
|
|
def GetCount(self): return len(self.__memberList)
|
def GetAt(self, index):
|
mem = None
|
if 0 <= index < len(self.__memberList):
|
mem = self.__memberList[index]
|
elif False:
|
mem = FamilyMem()
|
return mem
|
|
def RefreshFamilyMember(self, curPlayer):
|
## Ë¢ÐÂÔÚÏß³ÉÔ±ÐÅÏ¢
|
playerID = curPlayer.GetPlayerID()
|
familyID = curPlayer.GetFamilyID()
|
if self.GetID() != familyID:
|
return
|
member = self.FindMember(playerID)
|
if not member:
|
return
|
if member.RefreshMember(curPlayer):
|
self.__memFightPowerChange = True
|
return
|
|
def RefrshFightPowerTotal(self, checkChange=False):
|
## Ë¢ÐÂ×ÜÕ½Á¦
|
if checkChange and self.__memFightPowerChange == False: # ĬÈÏNone£¬Ê״αØË¢ÐÂ
|
#GameWorld.DebugLog("ûÓгÉÔ±Õ½Á¦±ä»¯¿É²»Ë¢ÐÂÏÉÃË×ÜÕ½Á¦! familyID=%s" % self.GetID())
|
return
|
familyFightPowerTotal = 0
|
for index in range(self.GetCount()):
|
member = self.GetAt(index)
|
if not member:
|
continue
|
familyFightPowerTotal += member.GetFightPowerTotal()
|
self.SetFightPowerTotal(familyFightPowerTotal)
|
#GameWorld.DebugLog("Ë¢ÐÂÏÉÃË×ÜÕ½Á¦! familyID=%s" % self.GetID())
|
self.__memFightPowerChange = False
|
return familyFightPowerTotal
|
|
def GetReqJoinPlayerInfo(self):
|
## »ñÈ¡ÉêÇë¼ÓÈëµÄÍæ¼ÒÐÅÏ¢
|
# @return: {playerID:ÉêÇëʱ¼ä´Á, ...}
|
joinAction = self.__actionMgr.GetFamilyAction(self.GetID(), ShareDefine.Def_ActionType_FamilyAdd)
|
actionData = joinAction.GetOneAction(True)
|
dataDict = actionData.GetUserDict()
|
if "ReqJoin" not in dataDict:
|
dataDict["ReqJoin"] = {}
|
return dataDict["ReqJoin"]
|
|
def AddReqJoinPlayerID(self, playerID):
|
reqPlayerIDDict = self.GetReqJoinPlayerInfo()
|
reqPlayerIDDict[playerID] = int(time.time()) # ÉêÇëʱ¼ä´Á
|
self.__familyMgr.AddPlayerReqJoinFamilyID(playerID, self.GetID())
|
return
|
|
def DelReqJoinPlayerID(self, playerID):
|
reqPlayerIDDict = self.GetReqJoinPlayerInfo()
|
if playerID in reqPlayerIDDict:
|
reqPlayerIDDict.pop(playerID)
|
self.__familyMgr.DelPlayerReqJoinFamilyID(playerID, self.GetID())
|
return
|
|
def DelReqJoinPlayerAll(self):
|
reqPlayerIDDict = self.GetReqJoinPlayerInfo()
|
for playerID in reqPlayerIDDict.keys():
|
reqPlayerIDDict.pop(playerID)
|
self.__familyMgr.DelPlayerReqJoinFamilyID(playerID, self.GetID())
|
return
|
|
def OnDelete(self):
|
self.DelReqJoinPlayerAll()
|
self.__actionMgr.ClearFamilyAction(self.GetID())
|
return
|
|
class FamilyMgr():
|
|
def __init__(self):
|
self.__familyList = [] # ÏÉÃ˶ÔÏóÁÐ±í£¬¿É½øÐÐÅÅÐò [Family, ...]
|
self.__familyIDDict = {} # ÏÉÃËID¶ÔÏó×Öµä, {familyID:Family, ...}
|
self.__familyNameDict = {} # ÏÉÃËÃû³Æ¶ÔÏó×Öµä, {familyName:Family, ...}
|
self.__actionMgr = FamilyActionMgr()
|
self.__playerReqJoinDict = None # Íæ¼ÒÉêÇë¼ÓÈëÏÉÃËÁбí {playerID:[familyID, ...], ...}
|
return
|
|
def InitFamilyInstance(self, dbData):
|
'''³õʼ»¯¹¦ÄÜÊý¾ÝʵÀý£¬´´½¨»ò¼ÓÔØÊý¾ÝʱͨÓ㬹¦ÄÜÒ»°ã²»µ÷ÓÃ
|
@param dbData: ʵÀý¶ÔÓ¦°ó¶¨µÄdbData
|
@return: ³É¹¦·µ»ØÊµÀý¶ÔÏó£¬Ê§°Ü·µ»ØNone
|
'''
|
family = Family(dbData)
|
familyID = family.GetID()
|
if familyID in self.__familyIDDict:
|
return
|
self.__familyList.append(family)
|
self.__familyIDDict[familyID] = family
|
self.__familyNameDict[family.GetName()] = family
|
return family
|
|
def Sort(self):
|
''' ĬÈÏÅÅÐòµ¹Ðò£¬°´ ÏÉÃË×ÜÕ½Á¦ -> ÏÉÃ˵ȼ¶
|
'''
|
self.__familyList.sort(key=lambda f: (f.GetFightPowerTotal(), f.GetLV()), reverse=True)
|
return
|
|
def AddFamily(self, familyName, serverID, familyID=None):
|
## ´´½¨ÐÂÏÉÃË
|
newFamily = None
|
if familyID == None:
|
familyID = PyMongoMain.GetUserCtrlDB().GetNewFamilyID()
|
if familyID <= 0:
|
GameWorld.ErrLog("´´½¨ÏÉÃËʱÉú³ÉÐÂIDÒì³£!")
|
return newFamily
|
if familyID in self.__familyIDDict:
|
GameWorld.ErrLog("´´½¨ÏÉÃËʱIDÒÑ´æÔÚ! familyID=%s" % familyID)
|
return newFamily
|
if familyName in self.__familyNameDict:
|
GameWorld.ErrLog("´´½¨ÏÉÃËʱÃû³ÆÒÑ´æÔÚ! familyName=%s" % familyName)
|
return newFamily
|
if len(self.__familyList) >= FamilyUpperLimitCount:
|
GameWorld.ErrLog("µ¥·þÏÞÖÆ´´½¨ÏÉÃËÊýÒÑ´ïÉÏÏÞ!")
|
return newFamily
|
|
dbData = DBStruct.tagDBFamily()
|
dbData.ID = familyID
|
dbData.Name = familyName
|
dbData.ServerID = serverID
|
dbData.CreateTime = int(time.time())
|
|
newFamily = self.InitFamilyInstance(dbData)
|
if not newFamily and False: # ²»Ö´ÐУ¬ÎªÁË´úÂëÌáʾ
|
newFamily = Family()
|
return newFamily
|
|
def FindFamily(self, familyID):
|
family = None
|
if familyID in self.__familyIDDict:
|
family = self.__familyIDDict[familyID]
|
elif False:
|
family = Family()
|
return family
|
|
def FindFamilyByName(self, familyName):
|
family = None
|
if familyName in self.__familyNameDict:
|
family = self.__familyNameDict[familyName]
|
elif False:
|
family = Family()
|
return family
|
|
def DelFamily(self, familyID):
|
family = self.FindFamily(familyID)
|
if family:
|
self.__familyNameDict.pop(family.GetName(), None)
|
if family in self.__familyList:
|
self.__familyList.remove(family)
|
family.OnDelete()
|
self.__familyIDDict.pop(familyID, None)
|
if familyID > ShareDefine.FackFamilyIDMax:
|
PyMongoMain.GetUserCtrlDB().FreeFamilyID(familyID) # ¹é»¹ÏÉÃËID£¬Öظ´Ê¹ÓÃ
|
return family
|
|
def DelAllFamily(self):
|
for index in range(self.GetCount())[::-1]:
|
family = self.GetAt(index)
|
familyID = family.GetID()
|
self.DelFamily(familyID)
|
return
|
|
def GetCount(self): return len(self.__familyList)
|
def GetAt(self, index):
|
family = None
|
if 0 <= index < len(self.__familyList):
|
family = self.__familyList[index]
|
elif False:
|
family = Family()
|
return family
|
|
def GetPlayerFamilyID(self, playerID):
|
## »ñÈ¡Íæ¼Òµ±Ç°ËùÊôµÄÏÉÃËID
|
for index in range(self.GetCount()):
|
family = self.GetAt(index)
|
if family.FindMember(playerID):
|
return family.GetID()
|
return 0
|
|
def GetFamilyActionMgr(self): return self.__actionMgr
|
|
def GetPlayerReqJoinFamilyIDList(self, playerID):
|
## »ñÈ¡Íæ¼ÒÉêÇë¼ÓÈëµÄÏÉÃËIDÁбí
|
if self.__playerReqJoinDict == None:
|
self.__playerReqJoinDict = {}
|
for index in xrange(self.GetCount()):
|
family = self.GetAt(index)
|
familyID = family.GetID()
|
reqPlayerIDDict = family.GetReqJoinPlayerInfo()
|
for reqID in reqPlayerIDDict.keys():
|
if reqID not in self.__playerReqJoinDict:
|
self.__playerReqJoinDict[reqID] = []
|
reqFamilyIDList = self.__playerReqJoinDict[reqID]
|
if familyID not in reqFamilyIDList:
|
reqFamilyIDList.append(familyID)
|
|
if playerID not in self.__playerReqJoinDict:
|
self.__playerReqJoinDict[playerID] = []
|
return self.__playerReqJoinDict[playerID]
|
|
def AddPlayerReqJoinFamilyID(self, playerID, familyID):
|
## Ìí¼ÓÍæ¼ÒÉêÇë¼ÓÈëÄ¿±êÏÉÃ˼Ǽ
|
# @return: ÊÇ·ñÓÐÔö¼Ó¼Ç¼
|
reqFamilyIDList = self.GetPlayerReqJoinFamilyIDList(playerID)
|
if familyID not in reqFamilyIDList:
|
reqFamilyIDList.append(familyID)
|
return True
|
return False
|
|
def DelPlayerReqJoinFamilyID(self, playerID, familyID):
|
## ɾ³ýÍæ¼ÒÉêÇë¼ÓÈëÄ¿±êÏÉÃ˼Ǽ
|
# @return: ÊÇ·ñÓÐɾ³ý¼Ç¼
|
reqFamilyIDList = self.GetPlayerReqJoinFamilyIDList(playerID)
|
if familyID in reqFamilyIDList:
|
reqFamilyIDList.remove(familyID)
|
return True
|
return False
|
|
def DelPlayerReqJoinFamilyIDAll(self, playerID):
|
## ɾ³ýÍæ¼ÒËùÓеÄÉêÇë¼ÓÈëÏÉÃ˼Ǽ
|
reqFamilyIDList = self.GetPlayerReqJoinFamilyIDList(playerID)
|
for familyID in reqFamilyIDList[::-1]:
|
family = self.FindFamily(familyID)
|
if not family:
|
continue
|
family.DelReqJoinPlayerID(playerID)
|
return
|
|
# ±£´æÊý¾Ý ´æÊý¾Ý¿âºÍrealtimebackup
|
def GetSaveData(self):
|
|
familyDataCnt, familySavaData = 0, ""
|
membreDataCnt, memberSavaData = 0, ""
|
actionDataCnt, actionSavaData = 0, ""
|
for family in self.__familyList:
|
familyID = family.GetID()
|
familySavaData += family.GetBuffer()
|
familyDataCnt += 1
|
|
for memIndex in range(family.GetCount()):
|
member = family.GetAt(memIndex)
|
memberSavaData += member.GetBuffer()
|
membreDataCnt += 1
|
|
for actionType in self.__actionMgr.GetActionTypeList(familyID):
|
action = self.__actionMgr.GetFamilyAction(familyID, actionType)
|
for aIndex in range(action.Count()):
|
actionData = action.At(aIndex)
|
actionSavaData += actionData.GetBuffer()
|
actionDataCnt += 1
|
|
saveData = ""
|
|
saveData += CommFunc.WriteDWORD("", familyDataCnt) + familySavaData
|
GameWorld.Log("Save DBFamily count :%s len=%s" % (familyDataCnt, len(familySavaData)))
|
|
saveData += CommFunc.WriteDWORD("", membreDataCnt) + memberSavaData
|
GameWorld.Log("Save DBFamilyMem count :%s len=%s" % (membreDataCnt, len(memberSavaData)))
|
|
saveData += CommFunc.WriteDWORD("", actionDataCnt) + actionSavaData
|
GameWorld.Log("Save DBFamilyAction count :%s len=%s" % (actionDataCnt, len(actionSavaData)))
|
|
return saveData
|
|
# ´ÓÊý¾Ý¿âÔØÈëÊý¾Ý
|
def LoadPyGameData(self, datas, pos, dataslen):
|
# ÏÉÃË
|
cnt, pos = CommFunc.ReadDWORD(datas, pos)
|
GameWorld.Log("Load DBFamily count :%s" % cnt)
|
for _ in xrange(cnt):
|
dbData = DBStruct.tagDBFamily()
|
pos += dbData.readData(datas, pos, dataslen)
|
self.InitFamilyInstance(dbData)
|
self.Sort()
|
|
# ³ÉÔ±
|
cnt, pos = CommFunc.ReadDWORD(datas, pos)
|
GameWorld.Log("Load DBFamilyMem count :%s" % cnt)
|
for _ in xrange(cnt):
|
dbData = DBStruct.tagDBFamilyMem()
|
pos += dbData.readData(datas, pos, dataslen)
|
|
familyID = dbData.FamilyID
|
family = self.FindFamily(familyID)
|
if not family:
|
continue
|
family.InitMemberInstance(dbData)
|
|
# ÐÐΪ
|
cnt, pos = CommFunc.ReadDWORD(datas, pos)
|
GameWorld.Log("Load DBFamilyAction count :%s" % cnt)
|
for _ in xrange(cnt):
|
dbData = DBStruct.tagDBFamilyAction()
|
pos += dbData.readData(datas, pos, dataslen)
|
|
familyID = dbData.FamilyID
|
actionType = dbData.ActionType
|
family = self.FindFamily(familyID)
|
if not family:
|
continue
|
action = self.__actionMgr.GetFamilyAction(familyID, actionType)
|
action.InitActionInstance(dbData)
|
|
PyMongoMain.GetUserCtrlDB().OnFamilyIDInit(self.__familyIDDict.keys())
|
return pos
|
|
def OnMinute():
|
|
familyMgr = DBDataMgr.GetFamilyMgr()
|
# ÿ·ÖÖÓË¢ÐÂÏÂÏÉÃËÕ½Á¦ÅÅÐò
|
isSort = False
|
for index in range(familyMgr.GetCount()):
|
family = familyMgr.GetAt(index)
|
if not family:
|
continue
|
if family.RefrshFightPowerTotal(True):
|
isSort = True
|
if isSort:
|
familyMgr.Sort()
|
|
return
|
|
|