| | |
| | | import NetPackCommon
|
| | | import ChPyNetSendPack
|
| | | import IpyGameDataPY
|
| | | import IPY_GameWorld
|
| | | import ShareDefine
|
| | | import TurnAttack
|
| | | import DBDataMgr
|
| | | import GameObj
|
| | |
|
| | | import random
|
| | | import time
|
| | |
| | | return
|
| | |
|
| | | def OnPlayerLogout(curPlayer):
|
| | | if curPlayer.GetLV() < 10:
|
| | | if curPlayer.GetLV() < IpyGameDataPY.GetFuncCfg("PlayerViewCache", 1):
|
| | | return
|
| | |
|
| | | curCache = UpdPlayerViewCache(curPlayer)
|
| | | if curCache and not IsSaveDBViewCache(curCache):
|
| | | playerID = curPlayer.GetPlayerID()
|
| | | curCache = FindViewCache(playerID)
|
| | | if not curCache:
|
| | | return
|
| | | |
| | | UpdPlayerViewCache(curPlayer, True)
|
| | | if not IsSaveDBViewCache(curCache):
|
| | | DBDataMgr.GetPlayerViewCacheMgr().DelPlayerViewCache(curPlayer.GetPlayerID())
|
| | | |
| | | return
|
| | | |
| | | return
|
| | |
|
| | | def DelOutofTimeViewCacheData():
|
| | |
| | | for index in range(viewCacheMgr.GetCount())[::-1]: # 有删除需倒序遍历
|
| | | viewCache = viewCacheMgr.At(index)
|
| | | playerID = viewCache.GetPlayerID()
|
| | | if playerID < ShareDefine.RealPlayerIDStart:
|
| | | continue
|
| | | curPlayer = playerManager.FindPlayerByID(playerID)
|
| | | if curPlayer:
|
| | | continue
|
| | |
| | | return False
|
| | |
|
| | | playerID = viewCache.GetPlayerID()
|
| | | if playerID < ShareDefine.RealPlayerIDStart:
|
| | | #非真实玩家不入库
|
| | | return False
|
| | |
|
| | | #某个功能中不能删除的
|
| | | #...
|
| | |
| | |
|
| | | return False
|
| | |
|
| | | def FindViewCache(playerID, isAdd=False):
|
| | | def FindViewCache(playerID):
|
| | | '''查找玩家缓存,如果不存在,则会有额外逻辑,如从redis、db直接找,
|
| | | 本服玩家理论上一定有查看缓存,因为如果不存在会直接从db读,除非该玩家数据被删除
|
| | | 跨服玩家理论上也一定有缓存,只是通过跨服或从子服查询,延迟获得
|
| | |
| | | curCache = updCache
|
| | |
|
| | | # 真实玩家
|
| | | elif playerID > ShareDefine.FackPlayerIDMax:
|
| | | elif playerID >= ShareDefine.RealPlayerIDStart:
|
| | | curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
|
| | | # 本服在线玩家,直接生成新数据
|
| | | if curPlayer:
|
| | |
| | | # 跨服玩家,去子服拉取数据,理论上也一定有,但是如果需要拉数据,有一定延迟
|
| | | # 逻辑待扩展
|
| | |
|
| | | # 机器人
|
| | | elif ShareDefine.RobotIDStart <= playerID <= ShareDefine.RobotIDMax:
|
| | | curCache = UpdRobotViewCache(playerID)
|
| | | |
| | | # 假玩家,默认添加
|
| | | elif ShareDefine.FackPlayerIDStart <= playerID <= ShareDefine.FackPlayerIDMax:
|
| | | serverID = playerID % 100 + 1 # 1 ~ 100 服
|
| | |
| | | return curCache
|
| | |
|
| | | def __CheckUpdViewCache(playerID):
|
| | | if playerID <= ShareDefine.FackPlayerIDMax:
|
| | | if playerID < ShareDefine.RealPlayerIDStart:
|
| | | return
|
| | | curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
|
| | | if not curPlayer:
|
| | |
| | | curCache.SetRealmLV(curPlayer.GetOfficialRank())
|
| | | curCache.SetFace(curPlayer.GetFace())
|
| | | curCache.SetFacePic(curPlayer.GetFacePic())
|
| | | curCache.SetModelMark(curPlayer.GetModelMark())
|
| | | curCache.SetFamilyID(curPlayer.GetFamilyID())
|
| | | curCache.SetFamilyName(curPlayer.GetFamilyName())
|
| | | curCache.SetFamilyEmblemID(PlayerControl.GetFamilyEmblemID(curPlayer))
|
| | |
| | | if isOffline:
|
| | | curCache.SetOffTime(int(time.time()))
|
| | |
|
| | | plusDict = curCache.GetPlusDict()
|
| | | # 装备
|
| | | equipDict = {}
|
| | | equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
|
| | | for equipPlace in ChConfig.Def_MainEquipPlaces:
|
| | | equipIndex = equipPlace - 1
|
| | | if equipIndex < 0 or equipIndex >= equipPack.GetCount():
|
| | | continue
|
| | | curEquip = equipPack.GetAt(equipIndex)
|
| | | if not curEquip or curEquip.IsEmpty():
|
| | | continue
|
| | | equipDict["%s" % equipIndex] = {"ItemID":curEquip.GetItemTypeID(), "UserData":curEquip.GetUserData()}
|
| | |
|
| | | #战斗属性
|
| | | plusDict.update({
|
| | | "MinAtk":curPlayer.GetMinAtk(),
|
| | | "MaxAtk":curPlayer.GetMaxAtk(),
|
| | | "Def":curPlayer.GetDef(),
|
| | | "MaxHP":GameObj.GetMaxHP(curPlayer),
|
| | | "Hit":curPlayer.GetHit(),
|
| | | "Miss":curPlayer.GetMiss(),
|
| | | "SuperHitRate":curPlayer.GetSuperHitRate(), # 暴击率
|
| | | })
|
| | | |
| | | # 功能数据
|
| | | # 阵容
|
| | | lineupDict = {}
|
| | | for lineupID in ShareDefine.LineupList:
|
| | | lineupInfo = TurnAttack.GetPlayerLineupInfo(curPlayer, lineupID)
|
| | | if not lineupInfo:
|
| | | continue
|
| | | lineupDict["%s" % lineupID] = lineupInfo
|
| | |
|
| | | # 其他
|
| | | |
| | | plusDict= {"Equip":equipDict, "Lineup":lineupDict}
|
| | | curCache.SetPlusDict(plusDict)
|
| | |
|
| | | return curCache
|
| | |
|
| | |
| | | curCache.SetRealmLV(dbPlayer.OfficialRank)
|
| | | curCache.SetFace(dbPlayer.Face)
|
| | | curCache.SetFacePic(dbPlayer.FacePic)
|
| | | curCache.SetModelMark(dbPlayer.ModelMark)
|
| | | curCache.SetFamilyID(familyID)
|
| | | family = DBDataMgr.GetFamilyMgr().FindFamily(familyID)
|
| | | curCache.SetFamilyName(family.GetName() if family else "")
|
| | |
| | | curCache.SetFightPowerTotal(dbPlayer.FightPowerEx * ChConfig.Def_PerPointValue + dbPlayer.FightPower)
|
| | | curCache.SetServerID(GameWorld.GetAccIDServerID(dbPlayer.AccID))
|
| | | curCache.SetOffTime(GameWorld.ChangeTimeStrToNum(dbPlayer.LogoffTime) if dbPlayer.LogoffTime else 0)
|
| | | return curCache
|
| | |
|
| | | def GetRobotByViewCache(curCache):
|
| | | ## 根据缓存内容获取机器人数据
|
| | | if not curCache:
|
| | | return
|
| | | robotDict = {
|
| | | "PlayerName" : curCache.GetPlayerName(),
|
| | | "LV" : curCache.GetLV(),
|
| | | "Job" : curCache.GetJob(),
|
| | | "RealmLV" : curCache.GetRealmLV(),
|
| | | "Face" : curCache.GetFace(),
|
| | | "FacePic" : curCache.GetFacePic(),
|
| | | "ModelMark" : curCache.GetModelMark(),
|
| | | "FightPower" : curCache.GetFightPowerTotal(),
|
| | | "PlusData" : curCache.GetPlusDict(),
|
| | | }
|
| | | return robotDict
|
| | |
|
| | | def UpdRobotViewCache(robotID):
|
| | | ## 更新机器人查看缓存
|
| | | robotIpyData = IpyGameDataPY.GetIpyGameData("Robot", robotID)
|
| | | if not robotIpyData:
|
| | | return
|
| | | try:
|
| | | robotInfo = eval(robotIpyData.GetViewCache())
|
| | | except:
|
| | | return
|
| | | |
| | | viewCacheMgr = DBDataMgr.GetPlayerViewCacheMgr()
|
| | | curCache = viewCacheMgr.GetPlayerViewCache(robotID)
|
| | | if not curCache:
|
| | | curCache = viewCacheMgr.AddPlayerViewCache(robotID)
|
| | | #curCache.SetAccID(dbPlayer.AccID)
|
| | | |
| | | curCache.SetPlayerName(robotInfo.get("PlayerName", "p%s" % robotID))
|
| | | curCache.SetLV(robotInfo.get("LV", 1))
|
| | | curCache.SetJob(robotInfo.get("Job", 1))
|
| | | curCache.SetRealmLV(robotInfo.get("RealmLV", 0))
|
| | | curCache.SetFace(robotInfo.get("Face", 0))
|
| | | curCache.SetFacePic(robotInfo.get("FacePic", 0))
|
| | | curCache.SetModelMark(robotInfo.get("ModelMark", 0))
|
| | | #机器人暂定没有仙盟、称号
|
| | | #curCache.SetFamilyID(familyID)
|
| | | #family = DBDataMgr.GetFamilyMgr().FindFamily(familyID)
|
| | | #curCache.SetFamilyName(family.GetName() if family else "")
|
| | | #curCache.SetFamilyEmblemID(family.GetEmblemID() if family else 0)
|
| | | #curCache.SetTitleID(PlayerControl.GetTitleID(curPlayer))
|
| | | curCache.SetFightPowerTotal(robotInfo.get("FightPower", 1))
|
| | | curCache.SetServerID(GameWorld.GetGameWorld().GetServerID()) # 默认本服
|
| | | curCache.SetPlusDict(robotInfo.get("PlusData", {}))
|
| | | #curCache.SetOffTime(0)
|
| | | return curCache
|
| | |
|
| | | #//A2 12 查看玩家详细信息#tagCMViewPlayerInfo
|
| | |
| | | clientPack.RealmLV = curCache.GetRealmLV()
|
| | | clientPack.Face = curCache.GetFace()
|
| | | clientPack.FacePic = curCache.GetFacePic()
|
| | | clientPack.ModelMark = curCache.GetModelMark()
|
| | | clientPack.TitleID = curCache.GetTitleID()
|
| | | clientPack.ServerID = curCache.GetServerID()
|
| | | clientPack.FightPower = curCache.GetFightPower()
|