| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerPrestigeSys  | 
| #  | 
| # @todo:¾ôλϵͳ/ÉÙÄê¾³½ç  | 
| # @author hxp  | 
| # @date 2017-7-21  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¾ôλϵͳ/ÉÙÄê¾³½ç  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2017-10-10 14:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import ItemCommon  | 
| import GameFuncComm  | 
| import PlayerControl  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import IPY_GameWorld  | 
| import IpyGameDataPY  | 
| import ShareDefine  | 
| import GameWorld  | 
| import ChConfig  | 
| import PlayerSuccess  | 
| import ChEquip  | 
| import PlayerBillboard  | 
| import PassiveBuffEffMng  | 
| import EventShell  | 
| import DataRecordPack  | 
| import SkillCommon  | 
|   | 
| import time  | 
| #------------------------------------------------------------------------------  | 
|   | 
|   | 
| def DoOfficialOpen(curPlayer):  | 
|     #¹¦ÄÜ¿ªÆô  | 
| #    curRealmLV = curPlayer.GetOfficialRank()  | 
| #    if not curRealmLV:  | 
| #        DoRealmLVUpLogic(curPlayer)  | 
|     return True  | 
|   | 
|   | 
| def OnLogin(curPlayer):  | 
|     SyncRealmFBState(curPlayer)  | 
|     UpdateRealmExp(curPlayer, False)  | 
|     NotifyRealmExpInfo(curPlayer)  | 
|     return  | 
|   | 
|   | 
| def GetRealmIpyData(realmLV): return IpyGameDataPY.GetIpyGameData("Realm", realmLV)  | 
|   | 
|   | 
| #// A5 24 ¿ªÆô¶É½Ù #tagCMOpenRealmFB  | 
| #  | 
| #struct    tagCMOpenRealmFB  | 
| #{  | 
| #    tagHead        Head;  | 
| #};  | 
| def OpenRealmFB(index, clientData, tick):  | 
|     return  | 
|       | 
|   | 
| def SyncRealmFBState(curPlayer):  | 
|     #֪ͨ¿Í»§¶Ë¶É½Ù¸±±¾ÊÇ·ñ¿ªÆô  | 
|     if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_Official):  | 
|         return  | 
|     sendPack = ChPyNetSendPack.tagMCSyncRealmInfo()  | 
|     sendPack.IsPass = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmFBIsOpen)  | 
|     NetPackCommon.SendFakePack(curPlayer, sendPack)  | 
|     return  | 
|   | 
|   | 
| ## ¼ÆËã¾ôλÊôÐÔ  | 
| #  @param curPlayer Íæ¼Ò  | 
| #  @param allAttrList ÊôÐÔÁÐ±í  | 
| #  @return None  | 
| def CalcOfficialRankAttr(curPlayer):  | 
|     if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_Official):  | 
|         return  | 
|   | 
|     curRealmLV = curPlayer.GetOfficialRank()  | 
|     realmIpyData = GetRealmIpyData(curRealmLV)  | 
|     if not realmIpyData:  | 
|         return  | 
|      | 
|     addAttrIDList, addAttrValueList = realmIpyData.GetAddAttrType(), realmIpyData.GetAddAttrNum()  | 
|       | 
|     allAttrList = [{} for i in range(4)]  | 
|     for i, attrID in enumerate(addAttrIDList):  | 
|         PlayerControl.CalcAttrDict_Type(attrID, addAttrValueList[i], allAttrList)  | 
|           | 
|     # ±£´æ¼ÆËãÖµ  | 
|     PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Prestige, allAttrList)  | 
|     return  | 
|   | 
|   | 
| ## ÖØË¢ËùÓÐÊôÐÔ  | 
| #  @param curPlayer  | 
| #  @param isForceRefresh:Ç¿ÖÆË¢ÐÂÅÅÐаñ  | 
| #  @return Ö¸¶¨Êý¾Ý  | 
| def RefreshOfficialAttr(curPlayer):  | 
|     CalcOfficialRankAttr(curPlayer)  | 
|     PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  | 
|     return  | 
|   | 
|   | 
| #// A5 23 ÌáÉý¾³½çµÈ¼¶ # tagCMRealmLVUp  | 
| #  | 
| #struct    tagCMRealmLVUp  | 
| #{  | 
| #    tagHead        Head;  | 
| #};  | 
| def DoRealmLVUp(index, clientData, tick):  | 
|     #Éý¼¶¾³½ç  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     curRealmLV = curPlayer.GetOfficialRank()  | 
|     realmIpyData = GetRealmIpyData(curRealmLV)  | 
|     if not realmIpyData:  | 
|         GameWorld.ErrLog("ûÓиþ³½çµÈ¼¶Êý¾Ý! Lv=%s" % curRealmLV)  | 
|         return  | 
|     if realmIpyData.GetBossID():  | 
|         canLvUp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmFBIsOpen) == 1  | 
|         if not canLvUp:  | 
|             GameWorld.DebugLog('    ¸±±¾Î´¹ý¹Ø£¬²»ÄÜÉý¼¶¾³½ç')  | 
|             return  | 
|     #µÈ¼¶ÅÐ¶Ï  | 
|     if curPlayer.GetLV() < realmIpyData.GetNeedLV():  | 
|         return  | 
|     #×°±¸ÅÐ¶Ï  | 
|     needEquip = realmIpyData.GetNeedEquip()  | 
|     if needEquip and len(needEquip) == 4:  | 
|         classLV, star, isSuite, color = needEquip  | 
|         equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)  | 
|         for place in ChConfig.EquipPlace_Base:  | 
|             ipyData = IpyGameDataPY.GetIpyGameData('EquipPlaceIndexMap', classLV, place)  | 
|             if not ipyData:  | 
|                 return  | 
|             gridIndex = ipyData.GetGridIndex()  | 
|             curEquip = equipPack.GetAt(gridIndex)  | 
|             if not ItemCommon.CheckItemCanUse(curEquip):  | 
|                 return  | 
|             curPartStar = ChEquip.GetEquipPartStar(curPlayer, gridIndex)  | 
|             if curPartStar < star:  | 
|                 return  | 
|             if isSuite and not curEquip.GetSuiteID():  | 
|                 return  | 
|             if curEquip.GetItemColor() < color:  | 
|                 return  | 
|       | 
|     needItemID = realmIpyData.GetNeedItemID()  | 
|     needItemCount = realmIpyData.GetNeedItemCnt()  | 
|     # Ö§³Ö²»ÏûºÄÎïÆ·Éý¼¶  | 
|     if needItemID > 0 and needItemCount > 0:  | 
|         curPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|         hasEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(needItemID, curPack, needItemCount)  | 
|         if not hasEnough:  | 
|             GameWorld.DebugLog("¶É½Ù¿ªÆô, ²ÄÁϲ»×ã! Lv=%s, needItemID=%s,needItemCount=%s"   | 
|                                % (curRealmLV, needItemID, needItemCount))  | 
|             return  | 
|         #¿Û³ýÎïÆ·  | 
|         ItemCommon.ReduceItem(curPlayer, curPack, itemIndexList, needItemCount, True, "Realm")  | 
|       | 
|     DoRealmLVUpLogic(curPlayer)  | 
|     return  | 
|   | 
| # ÌáÉý1¼¶¾³½ç¼Óµã  | 
| def __DoRealmLVUpAddPoint(curPlayer):  | 
|     if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_AddPoint):  | 
|         # Î´¿ªÆôǰ²»¿É¼Óµã£¬ÒòΪDoAddPointOpen»áÒ»´ÎÐÔ²¹Æë£¬±ÜÃâÒâÍâÇé¿ö¶à¼ÓÁ˵ãÊý  | 
|         return  | 
|   | 
|     curFreePoint = curPlayer.GetFreePoint()  | 
|     addPoint = IpyGameDataPY.GetFuncCfg("LVUPAddPoint", 3)  | 
|     if addPoint != 0:  | 
|         setFreePoint = curFreePoint + addPoint  | 
|         DataRecordPack.DR_Freepoint(curPlayer, "RealmLVUp", addPoint)  | 
|         curPlayer.SetFreePoint(setFreePoint)  | 
|   | 
|     return  | 
|   | 
|   | 
| def DoRealmLVUpLogic(curPlayer, needSys=True):  | 
|     curRealmLV = curPlayer.GetOfficialRank()  | 
|     nextRealmLv = curRealmLV + 1  | 
|     GameWorld.DebugLog('    Éý¼¶¾³½çnextRealmLv=%s' % nextRealmLv)  | 
|     nextRealmIpyData = GetRealmIpyData(nextRealmLv)  | 
|     if not nextRealmIpyData:  | 
|         return  | 
|       | 
|     curPlayer.SetOfficialRank(nextRealmLv)  | 
|     # ÌáÉý1¼¶¾³½ç¼Óµã  | 
|     __DoRealmLVUpAddPoint(curPlayer)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmFBIsOpen, 0)  | 
|     if needSys:  | 
|         addBuffID = nextRealmIpyData.GetBuffID()  | 
|         if addBuffID:  | 
|             PlayerControl.WorldNotify(0, 'BigRealmUpSuccess', [curPlayer.GetName(), curPlayer.GetID(), nextRealmLv, IpyGameDataPY.GetFuncCfg('RadioExpRealm')])  | 
|             msgStr = str(addBuffID)  | 
|             GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, 'RealmUpAddBuff', msgStr, len(msgStr))  | 
|         else:  | 
|             PlayerControl.WorldNotify(0, 'RealmUpSuccess', [curPlayer.GetName(), curPlayer.GetID(), nextRealmLv])  | 
|               | 
|     if SkillCommon.GivePlayerSkillByJobSkill(curPlayer, nextRealmIpyData.GetLearnSkillIDInfo()):  | 
|         PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEffSet(curPlayer)  | 
|           | 
|     addFreePoint = nextRealmIpyData.GetAddFreePoint()  | 
|     if addFreePoint:  | 
|         updFreePoint = curPlayer.GetFreePoint() + addFreePoint  | 
|         curPlayer.SetFreePoint(updFreePoint)  | 
|         GameWorld.DebugLog("    addFreePoint=%s,updFreePoint=%s" % (addFreePoint, updFreePoint))  | 
|           | 
|     RefreshOfficialAttr(curPlayer)  | 
|     GameFuncComm.DoFuncOpenLogic(curPlayer)  | 
|     SyncRealmFBState(curPlayer)  | 
|     #¸üÐÂÐÞΪËÙÂÊ  | 
|     UpdateRealmExp(curPlayer, False, True)  | 
|     NotifyRealmExpInfo(curPlayer)  | 
|     #¾³½çÌáÉý³É¾Í  | 
|     PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_RealmlvUp, nextRealmLv)  | 
|     #¸üÐÂÅÅÐаñ  | 
|     PlayerBillboard.UpdateRealmBillboard(curPlayer)  | 
|     # ¼Ç¼¿ª·þ»î¶¯  | 
|     #OpenServerCampaign.UpdOpenServerCampaignRecordData(curPlayer, ShareDefine.Def_Campaign_Type_RealmLV, nextRealmLv)  | 
|     EventShell.EventRespons_RealmUp(curPlayer, nextRealmLv)  | 
|     #Á÷Ïò  | 
|     DataRecordPack.DR_RealmLVUp(curPlayer, nextRealmLv)  | 
|     return True  | 
|   | 
|   | 
| def DologicDujieFBPass(curPlayer, realmLV, star):  | 
|     #¶É½Ùͨ¹ýºó´¦Àí  | 
|     realmIpyData = GetRealmIpyData(realmLV)  | 
|     if not realmIpyData:  | 
|         return  | 
|     #DoRealmLVUpLogic(curPlayer)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmFBIsOpen, 1)  | 
|     SyncRealmFBState(curPlayer)  | 
|       | 
|     return  | 
|   | 
|   | 
| #// A5 21 ¾³½çÐÞΪ³ØÌáÈ¡ #tagCMTakeOutRealmExp  | 
| #  | 
| #struct    tagCMTakeOutRealmExp  | 
| #{  | 
| #    tagHead        Head;  | 
| #};  | 
| def OnTakeOutRealmExp(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     playerID = curPlayer.GetID()  | 
|     curTotalRealmExp = UpdateRealmExp(curPlayer, False)  | 
|     if curTotalRealmExp <= 0:  | 
|         GameWorld.DebugLog('¾³½çÐÞΪ³ØÌáÈ¡ Ã»ÓоÑé¿ÉÌáÈ¡', playerID)  | 
|         return  | 
|     playerControl = PlayerControl.PlayerControl(curPlayer)  | 
|     playerControl.AddExp(curTotalRealmExp)  | 
|     PlayerControl.NotifyCode(curPlayer, 'TakeOutRealmExp', [curTotalRealmExp])  | 
|     #  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBeginTime, int(time.time()))  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExp, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpPoint, 0)  | 
|   | 
|     NotifyRealmExpInfo(curPlayer)  | 
|     return  | 
|   | 
|   | 
| def UpdateRealmExp(curPlayer, isNotify=True, isRealmLVUP=False):  | 
|     ##¸üо³½çÐÞΪ³Ø  | 
|     curRealmLV = curPlayer.GetOfficialRank()  | 
|     ipyData = GetRealmIpyData(curRealmLV)  | 
|     if not ipyData:  | 
|         return 0  | 
|     if not ipyData.GetExpRate():  | 
|         return 0  | 
|     curTime = int(time.time())  | 
|     beginTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBeginTime)  | 
|     if not beginTime:  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBeginTime, curTime)  | 
|         return 0  | 
|     if isRealmLVUP:  | 
|         ipyData = GetRealmIpyData(curRealmLV-1)  | 
|               | 
|     curRealmExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExp)  | 
|     curRealmExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpPoint)  | 
|     curTotalExp = curRealmExpPoint * ChConfig.Def_PerPointValue + curRealmExp  | 
|     if curTotalExp >= ipyData.GetExpLimit():  | 
|         return curTotalExp  | 
|       | 
|     passSeconds = curTime - beginTime  | 
|     if passSeconds <= 0:  | 
|         return curTotalExp  | 
|     perRealmExpTime = IpyGameDataPY.GetFuncCfg('RealmExpTime')  | 
|     curExpRate = ipyData.GetExpRate()  | 
|     #buffÔö¼ÓµÄ¶îÍâ¾Ñé  | 
|     buffRemainTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffRemainTime)  | 
|     buffAddRate = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffAddRate)  | 
|       | 
|     buffTime = min(buffRemainTime, passSeconds)  | 
|       | 
|     addExp = buffTime /perRealmExpTime*(curExpRate*(ShareDefine.Def_MaxRateValue + buffAddRate)/ShareDefine.Def_MaxRateValue) + (passSeconds-buffTime)/perRealmExpTime*curExpRate  | 
|     #addExp = passSeconds / perRealmExpTime * curExpRate  | 
|     if addExp <= 0:  | 
|         return curTotalExp  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBeginTime, curTime)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBuffRemainTime, buffRemainTime - buffTime)  | 
|       | 
|     updTotalExp = min(curTotalExp + addExp, ipyData.GetExpLimit())  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExp, updTotalExp % ChConfig.Def_PerPointValue)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpPoint, updTotalExp / ChConfig.Def_PerPointValue)  | 
|     #֪ͨ  | 
|     if isNotify:  | 
|         NotifyRealmExpInfo(curPlayer)  | 
|     return updTotalExp  | 
|   | 
| def AddRealmExpBuffTime(curPlayer, addTime, addRate):  | 
|     ##Ôö¼Ó»áÁ鵤BUFFʱ¼ä  | 
|     UpdateRealmExp(curPlayer, False)  | 
|       | 
|     remainTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffRemainTime)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBuffRemainTime, remainTime + addTime)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RealmExpBuffAddRate, addRate)  | 
|     NotifyRealmExpInfo(curPlayer)  | 
|     return  | 
|   | 
| def NotifyRealmExpInfo(curPlayer):  | 
|     ##֪ͨÐÞΪ³ØÐÅÏ¢  | 
|     sendPack = ChPyNetSendPack.tagMCRealmExpInfo()  | 
|     sendPack.BeginTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBeginTime)  | 
|     sendPack.BuffTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffRemainTime)  | 
|     sendPack.BuffAddRate = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpBuffAddRate)  | 
|     sendPack.CurExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExp)  | 
|     sendPack.CurExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RealmExpPoint)  | 
|     NetPackCommon.SendFakePack(curPlayer, sendPack)  | 
|     return  | 
|   |