| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.CrossRealmPlayer  | 
| #  | 
| # @todo:¿ç·þÍæ¼Ò  | 
| # @author hxp  | 
| # @date 2018-12-21  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¿ç·þÍæ¼Ò  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2018-12-21 18:00"""  | 
| #-------------------------------------------------------------------------------  | 
| import GameWorld  | 
| import ReadChConfig  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import IPY_GameWorld  | 
| import ShareDefine  | 
| import ChConfig  | 
| import FBLogic  | 
|   | 
| # »ñÈ¡Íæ¼Ò¿ç·þ·þÎñÆ÷ÉϵÄÃû×Ö  | 
| def GetCrossPlayerName(curPlayer):  | 
|     # Í¨¹ýÓÎÏ·Õ˺ÅÖÐµÄÆ½Ì¨±êÖ¾»ñÈ¡Ãû³Æ£¬Ä¿Ç°Îªspid  | 
|     playerName = curPlayer.GetPlayerName()  | 
|       | 
|     opName = ReadChConfig.GetPyMongoConfig("Merge", "OpName_%s_%s" % (GameWorld.GetPlayerPlatform(curPlayer),   | 
|                                            GameWorld.GetPlayerServerSID(curPlayer)))  | 
|       | 
|     if not opName:  | 
|         return playerName  | 
|       | 
|     return opName.decode('gbk').encode(GameWorld.GetCharacterEncoding()) + playerName  | 
|   | 
| def GetCrossCommZoneIpyDataByServerGroupID(serverGroupID):  | 
|     ## »ñÈ¡¿ç·þ³£¹æ·ÖÇø  | 
|     crossZoneName = GameWorld.GetCrossZoneName()  | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("CrossZoneComm", {"CrossZoneName":crossZoneName}, True)  | 
|     if not ipyDataList:  | 
|         return  | 
|     for ipyData in ipyDataList:  | 
|         serverGroupIDList = ipyData.GetServerGroupIDList()  | 
|         for serverGroupIDInfo in serverGroupIDList:  | 
|             if (isinstance(serverGroupIDInfo, tuple) and serverGroupIDInfo[0] <= serverGroupID <= serverGroupIDInfo[1]) \  | 
|                 or (isinstance(serverGroupIDInfo, int) and serverGroupIDInfo == serverGroupID):  | 
|                 return ipyData  | 
|     return  | 
|   | 
| def GetServerCrossZoneMapIpyData(mapID, serverGroupID=0):  | 
|     ## »ñÈ¡±¾·þ¶ÔÓ¦¿ç·þÍæ·¨·ÖÇøµØÍ¼ÐÅÏ¢  | 
|     if mapID not in ChConfig.Def_CrossZoneMapTableName:  | 
|         return  | 
|     tableName = ChConfig.Def_CrossZoneMapTableName[mapID]  | 
|     if not serverGroupID:  | 
|         if GameWorld.IsCrossServer():  | 
|             return  | 
|         serverGroupID = GameWorld.GetServerGroupID()  | 
|     zoneIpyData = GetCrossCommZoneIpyDataByServerGroupID(serverGroupID)  | 
|     if not zoneIpyData:  | 
|         return  | 
|     commZoneID = zoneIpyData.GetZoneID()  | 
|     return IpyGameDataPY.GetIpyGameDataByCondition(tableName, {"ZoneID":commZoneID})  | 
|   | 
| def IsCrossServerOpen():  | 
|     ## ¿ç·þ·þÎñÆ÷ÊÇ·ñ¿ª·ÅÖÐ  | 
|     return GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_CrossServerOpen)  | 
|   | 
| def SetCrossPlayerAttrValue(curPlayer, setDict, isDelay=True):  | 
|     ''' ÅúÁ¿ÉèÖÃÍæ¼ÒÊôÐÔÖµ  | 
|         @param setDict: ÉèÖÃÊôÐÔ×Öµä {attrName:attrValue, ...}  | 
|         @param isDelay: ÊÇ·ñÑÓ³Ùͬ²½£¬±ÈÈçOnDay¸üеÄÊýÖµ£¬¿ÉÄܶà¸öÍæ¼Òͬʱ¸üжà¸öÊôÐÔÖµ£¬ËùÒÔÐèÒªÉèÖÃÑÓ³Ùͳһͬ²½£¬ÆäËû¾ßÌå¸ù¾Ý¹¦ÄÜÐèҪѡÔñÊÇ·ñÑÓ³Ù  | 
|     '''  | 
|     if not setDict or not PlayerControl.GetCrossMapID(curPlayer):  | 
|         return  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     setType = "PlayerAttr"  | 
|     msgList = str([playerID, setType, setDict, isDelay])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, "SetCrossPlayerAttrValue", msgList, len(msgList))  | 
|     GameWorld.DebugLog("¸üпç·þÍæ¼ÒÊôÐÔ: isDelay=%s,%s" % (isDelay, setDict), playerID)  | 
|     return  | 
|   | 
| def SetCrossPlayerNomalDict(curPlayer, setDict, isDelay=True):  | 
|     ''' ÅúÁ¿ÉèÖÃÍæ¼Ò×ÖµäÖµ  | 
|         @param setDict: ÉèÖÃ×Öµä, ÎÞ dictType ÐÅϢʱĬÈÏÀàÐÍ0 {dictKey:dictValue, dictKey:[dictValue, dictType], ...}  | 
|         @param isDelay: ÊÇ·ñÑÓ³Ùͬ²½£¬±ÈÈçOnDay¸üеÄÊýÖµ£¬¿ÉÄܶà¸öÍæ¼Òͬʱ¸üжà¸öÊôÐÔÖµ£¬ËùÒÔÐèÒªÉèÖÃÑÓ³Ùͳһͬ²½£¬ÆäËû¾ßÌå¸ù¾Ý¹¦ÄÜÐèҪѡÔñÊÇ·ñÑÓ³Ù  | 
|     '''  | 
|     if not setDict or not PlayerControl.GetCrossMapID(curPlayer):  | 
|         return  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     setType = "PlayerDict"  | 
|     msgList = str([playerID, setType, setDict, isDelay])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, "SetCrossPlayerAttrValue", msgList, len(msgList))  | 
|     GameWorld.DebugLog("¸üпç·þÍæ¼Ò×Öµä: isDelay=%s,%s" % (isDelay, setDict), playerID)  | 
|     return  | 
|   | 
| def ClientServerMsg_SetPlayerAttrValue(curPlayer, playerSetInfoList):  | 
|     ## ÊÕµ½×Ó·þͬ²½µÄÉèÖÿç·þÍæ¼ÒÊôÐÔÖµ  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     GameWorld.DebugLog("ÊÕµ½×Ó·þͬ²½µÄÉèÖÿç·þÍæ¼ÒÊôÐÔÖµ: %s" % playerSetInfoList, playerID)  | 
|     for setType, setDict in playerSetInfoList:  | 
|         if setType == "PlayerDict":  | 
|             for dictKey, valeInfo in setDict.items():  | 
|                 if isinstance(valeInfo, int):  | 
|                     dictValue, dictType = valeInfo, 0  | 
|                 else:                      | 
|                     dictValue, dictType = valeInfo  | 
|                 PlayerControl.NomalDictSetProperty(curPlayer, dictKey, dictValue, dictType)  | 
|                 GameWorld.DebugLog("    NomalDictSetProperty dictKey=%s, dictValue=%s, dictType=%s" % (dictKey, dictValue, dictType), playerID)  | 
|         else:  | 
|             for attrName, attrValue in setDict.items():  | 
|                 if hasattr(curPlayer, attrName):  | 
|                     getattr(curPlayer, attrName)(attrValue)  | 
|                     GameWorld.DebugLog("    curPlayer.%s(%s)" % (attrName, attrValue))  | 
|                 elif hasattr(PlayerControl, attrName):  | 
|                     getattr(PlayerControl, attrName)(curPlayer, attrValue)  | 
|                     GameWorld.DebugLog("    PlayerControl.%s(curPlayer, %s)" % (attrName, attrValue), playerID)  | 
|     return  | 
|   | 
| #// C1 04 Ö÷¶¯Í˳ö¿ç·þ #tagCMExitCrossRealm  | 
| #  | 
| #struct    tagCMExitCrossRealm  | 
| #{  | 
| #    tagHead        Head;  | 
| #};  | 
| def OnExitCrossRealm(index, curPackData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|       | 
|     if not GameWorld.IsCrossServer():  | 
|         return  | 
|       | 
|     FBLogic.DoPlayerLeaveFB(curPlayer, tick)  | 
|       | 
|     PlayerExitCrossServer(curPlayer)  | 
|     return  | 
|   | 
| def PlayerExitCrossServer(curPlayer):  | 
|     ## Íæ¼ÒÍ˳ö¿ç·þ·þÎñÆ÷  | 
|       | 
|     # Í¨Öª×Ó·þÍæ¼ÒÍ˳ö¿ç·þ·þÎñÆ÷  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     serverGroupID = PlayerControl.GetPlayerServerGroupID(curPlayer)  | 
|     GameWorld.SendMsgToClientServer(ShareDefine.CrossServerMsg_ExitCrossServer, playerID, [serverGroupID])  | 
|       | 
|     # ÉèÖ÷ǿç·þ״̬£¬ÌßÏÂÏß  | 
|     PlayerControl.SetCrossMapID(curPlayer, 0)  | 
|     curPlayer.Kick(IPY_GameWorld.disMapServerClose)  | 
|     GameWorld.Log("PlayerExitCrossServer...", curPlayer.GetPlayerID())  | 
|     return  | 
|   | 
| def DoEnterCrossRealm(curPlayer):  | 
|     ## Íæ¼Ò½øÈë¿ç·þ´¦Àí£¬±¾·þµÄÂß¼´¦Àí  | 
|     curPlayer.SetCanAttack(False)  | 
|     curPlayer.SetVisible(False)  | 
|     curPlayer.SetSight(0)  | 
|     curPet = curPlayer.GetPetMgr().GetFightPet()  | 
|     if curPet:  | 
|         curPet.SetVisible(False)  | 
|     return  | 
|   | 
| def DoExitCrossRealm(curPlayer):  | 
|     ## Íæ¼ÒÍ˳ö¿ç·þ´¦Àí£¬±¾·þµÄÂß¼´¦Àí  | 
|     GameWorld.Log("DoExitCrossRealm...", curPlayer.GetPlayerID())  | 
|     curPlayer.SetCanAttack(True)  | 
|     curPlayer.SetVisible(True)  | 
|     curPlayer.SetSight(1)  | 
|     curPlayer.RefreshView()  | 
|     curPlayer.SetSight(ChConfig.Def_PlayerSight_Default)  | 
|     curPlayer.RefreshView()  | 
|     curPet = curPlayer.GetPetMgr().GetFightPet()  | 
|     if curPet:  | 
|         curPet.SetVisible(True)  | 
|     if PlayerControl.GetCrossMapID(curPlayer):  | 
|         PlayerControl.SetCrossMapID(curPlayer, 0)  | 
|     return  |