| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerActGubao  | 
| #  | 
| # @todo:¹Å±¦Ñø³É»î¶¯  | 
| # @author hxp  | 
| # @date 2024-08-12  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¹Å±¦Ñø³É»î¶¯  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2024-08-12 19:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PyGameData  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import CrossRealmPlayer  | 
| import FunctionNPCCommon  | 
| import PlayerBillboard  | 
| import ChPyNetSendPack  | 
| import PlayerZhanling  | 
| import NetPackCommon  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| def OnMixFirstLogin(curPlayer):  | 
|       | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         if not actInfo.get(ShareDefine.ActKey_State):  | 
|             continue  | 
|         score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)  | 
|         if not score:  | 
|             continue  | 
|         GameWorld.Log("¹Å±¦Ñø³ÉºÏ·þÊ×µÇͬ²½»ý·Ö°ñµ¥: actNum=%s,score=%s" % (actNum, score), curPlayer.GetPlayerID())  | 
|         PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_GubaoScore, score, autoSort=True)  | 
|         break  | 
|       | 
|     return  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|       | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         isReset = __CheckPlayerGubaoAction(curPlayer, actNum)  | 
|         if not isReset:  | 
|             # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|             if actInfo.get(ShareDefine.ActKey_State):  | 
|                 Sync_GubaoActionInfo(curPlayer, actNum)  | 
|                 Sync_GubaoPlayerInfo(curPlayer, actNum)  | 
|                   | 
|     if not __CheckPlayerCrossActGubao(curPlayer):  | 
|         Sync_CrossActGubaoActionInfo(curPlayer)  | 
|           | 
|     return  | 
|   | 
| def RefreshGubaoActionInfo(actNum):  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if not GameWorld.IsNormalPlayer(curPlayer):  | 
|             continue  | 
|         __CheckPlayerGubaoAction(curPlayer, actNum)  | 
|     return  | 
|   | 
| def __CheckPlayerGubaoAction(curPlayer, actNum):  | 
|     ## ¼ì²éÍæ¼Ò»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Gubao, actNum)  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoID % actNum) # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("¹Å±¦Ñø³É»î¶¯ID²»±ä£¬²»´¦Àí£¡actNum=%s,actID=%s" % (actNum, actID), playerID)  | 
|         return  | 
|       | 
|     GameWorld.DebugLog("¹Å±¦Ñø³ÉÖØÖÃ! actNum=%s,actID=%s,playerActID=%s,state=%s,cfgID=%s"   | 
|                        % (actNum, actID, playerActID, state, cfgID), playerID)  | 
|     score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)  | 
|     PlayerZhanling.ResetZhanling(curPlayer, PlayerZhanling.ZhanlingType_GubaoTrain, score)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActGubaoID % actNum, actID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActGubaoScore % actNum, 0)  | 
|       | 
|     if state:  | 
|         cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|         ipyData = IpyGameDataPY.GetIpyGameData("ActGubao", cfgID)  | 
|         if ipyData and ipyData.GetActShopType():  | 
|             FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, [ipyData.GetActShopType()])  | 
|         Sync_GubaoActionInfo(curPlayer, actNum)  | 
|         Sync_GubaoPlayerInfo(curPlayer, actNum)  | 
|     return True  | 
|   | 
| def RefreshCrossActGubaoInfo():  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if not GameWorld.IsNormalPlayer(curPlayer):  | 
|             continue  | 
|         __CheckPlayerCrossActGubao(curPlayer)  | 
|           | 
|     return  | 
|   | 
| def __CheckPlayerCrossActGubao(curPlayer):  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_Gubao)  | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|     dayIndex = actInfo.get(ShareDefine.ActKey_DayIndex, 0)  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_GubaoID) # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("¿ç·þ¹Å±¦Ñø³É»î¶¯ID²»±ä£¬²»´¦Àí£¡cfgID=%s,dayIndex=%s,actID=%s" % (cfgID, dayIndex, actID), playerID)     | 
|         return  | 
|     GameWorld.DebugLog("¿ç·þ¹Å±¦Ñø³É»î¶¯ÖØÖÃ! cfgID=%s,actID=%s,playerActID=%s,state=%s" % (cfgID, actID, playerActID, state), playerID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_GubaoID, actID)  | 
|       | 
|     if not state:  | 
|         CrossRealmPlayer.NotifyCrossActEnd(curPlayer, ShareDefine.CrossActName_Gubao)  | 
|           | 
|     Sync_CrossActGubaoActionInfo(curPlayer)  | 
|     return True  | 
|   | 
| def OnGubaoCost(curPlayer, costPieceInfo, costItemList):  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         if not actInfo.get(ShareDefine.ActKey_State):  | 
|             continue  | 
|           | 
|         cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|         ipyData = IpyGameDataPY.GetIpyGameData("ActGubao", cfgID)  | 
|         if not ipyData:  | 
|             continue  | 
|           | 
|         if ipyData.GetIsRelationCrossAct():  | 
|             crossActInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_Gubao)  | 
|             if crossActInfo.get(ShareDefine.ActKey_State, 0):  | 
|                 if crossActInfo.get(ShareDefine.ActKey_StateJoin) != ShareDefine.ActStateJoin_Start:  | 
|                     GameWorld.Log("¿ç·þ¹Å±¦Ñø³É·Ç²ÎÓë»î¶¯ÖÐ: actNum=%s" % actNum, playerID)  | 
|                     continue  | 
|         else:  | 
|             if actInfo.get(ShareDefine.ActKey_StateJoin) != ShareDefine.ActStateJoin_Start:  | 
|                 GameWorld.Log("¹Å±¦Ñø³É·Ç²ÎÓë»î¶¯ÖÐ: actNum=%s" % actNum, playerID)  | 
|                 continue  | 
|               | 
|         addGubaoScore = 0  | 
|         pieceQualityScoreDict = IpyGameDataPY.GetFuncEvalCfg("GubaoAct", 1, {})  | 
|         for pieceID, pieceCount in costPieceInfo.items():  | 
|             gbIpyData = IpyGameDataPY.GetIpyGameData("Gubao", pieceID)  | 
|             if not gbIpyData:  | 
|                 continue  | 
|             quality = gbIpyData.GetGubaoQuality()  | 
|             if str(quality) not in pieceQualityScoreDict:  | 
|                 continue  | 
|             qualityScore = pieceQualityScoreDict[str(quality)] * pieceCount  | 
|             addGubaoScore += qualityScore  | 
|             GameWorld.DebugLog("¹Å±¦»î¶¯Ë鯬»ý·Öͳ¼Æ: actNum=%s,pieceID=%s,quality=%s,pieceCount=%s,qualityScore=%s, %s"   | 
|                                % (actNum, pieceID, quality, pieceCount, qualityScore, addGubaoScore))  | 
|               | 
|         otherAddScore = IpyGameDataPY.GetFuncCfg("GubaoAct", 2)  | 
|         for itemID, costCount in costItemList:  | 
|             otherScore = costCount * otherAddScore  | 
|             addGubaoScore += otherScore  | 
|             GameWorld.DebugLog("¹Å±¦»î¶¯ÆäËû»ý·Öͳ¼Æ: actNum=%s,itemID=%s,costCount=%s,otherScore=%s, %s"   | 
|                                % (actNum, itemID, costCount, otherScore, addGubaoScore))  | 
|               | 
|         if addGubaoScore <= 0:  | 
|             continue  | 
|           | 
|         AddPlayerScore(curPlayer, actNum, addGubaoScore, ipyData.GetIsRelationCrossAct())  | 
|           | 
|     return  | 
|   | 
| def AddPlayerScore(curPlayer, actNum, addScore, isRelationCrossAct):  | 
|     if addScore <= 0:  | 
|         return 0  | 
|     score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)  | 
|     updScore = score + addScore  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActGubaoScore % actNum, updScore)  | 
|     GameWorld.DebugLog("¹Å±¦»î¶¯Ôö¼Ó»ý·Ö: actNum=%s,addScore=%s,updScore=%s" % (actNum, addScore, updScore))  | 
|     Sync_GubaoPlayerInfo(curPlayer, actNum)  | 
|     PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_GubaoTrainScore, addScore, "ActGubaoTrain")  | 
|     PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_GubaoScore, updScore, autoSort=True)  | 
|     SendToGameServer_Gubao(curPlayer, "AddGubaoScore", [addScore, updScore, isRelationCrossAct])  | 
|     return updScore  | 
|   | 
| def SendToGameServer_Gubao(curPlayer, msgType, dataMsg=""):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     msgList = str([msgType, dataMsg])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "ActGubao", msgList, len(msgList))  | 
|     GameWorld.Log("¹Å±¦Ñø³É·¢ËÍGameServer: %s, %s" % (msgType, dataMsg), playerID)  | 
|     return  | 
|   | 
| def GetActGubaoTrainScore(curPlayer):  | 
|     ## »ñÈ¡»î¶¯ÖÐÑø³É»ý·Ö  | 
|     actScore = 0  | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         if not actInfo.get(ShareDefine.ActKey_State):  | 
|             continue  | 
|         score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)  | 
|         actScore = max(score, actScore)  | 
|     return actScore  | 
|   | 
| def Sync_GubaoActionInfo(curPlayer, actNum):  | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Gubao, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActGubao", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     personalTempID = ipyData.GetPersonalTemplateID()  | 
|     personalTempIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGubaoBillTemp", personalTempID) if personalTempID else []  | 
|       | 
|     startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCActGubaoInfo()  | 
|     clientPack.ActNum = actNum  | 
|     clientPack.StartDate = startDateStr  | 
|     clientPack.EndtDate = endDateStr  | 
|     clientPack.JoinStartTime = ipyData.GetJoinStartTime()  | 
|     clientPack.JoinEndTime = ipyData.GetJoinEndTime()  | 
|     clientPack.LimitLV = ipyData.GetLVLimit()  | 
|     clientPack.ShopType = ipyData.GetActShopType()  | 
|       | 
|     clientPack.PersonalBillboardInfoList = __GetTempRankBillPackList(personalTempIpyDataList)  | 
|     clientPack.PersonalBillCount = len(clientPack.PersonalBillboardInfoList)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   | 
| def Sync_GubaoPlayerInfo(curPlayer, actNum):  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Gubao, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCActGubaoPlayerInfo()  | 
|     clientPack.ActNum = actNum  | 
|     clientPack.Score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   | 
| def Sync_CrossActGubaoActionInfo(curPlayer):  | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢  | 
|     actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_Gubao)  | 
|     if not actInfo:  | 
|         return  | 
|       | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})  | 
|     if not ipyDataDict:  | 
|         return  | 
|       | 
|     personalTempID = ipyDataDict.get("PersonalTemplateID", 0)  | 
|     personalTempIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGubaoBillTemp", personalTempID) if personalTempID else []  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCCrossActGubaoInfo()  | 
|     clientPack.ServerIDRangeInfo = str(actInfo.get(ShareDefine.ActKey_ServerIDRangeList, []))  | 
|     clientPack.ServerInfoLen = len(clientPack.ServerIDRangeInfo)  | 
|     clientPack.GroupValue1 = ipyDataDict.get("ZoneID", 0)  | 
|     clientPack.StartDate = ipyDataDict.get("StartDate", "")  | 
|     clientPack.EndtDate = ipyDataDict.get("EndDate", "")  | 
|     clientPack.JoinStartTime = ipyDataDict.get("JoinStartTime", "")  | 
|     clientPack.JoinEndTime = ipyDataDict.get("JoinEndTime", "")  | 
|       | 
|     clientPack.PersonalBillboardInfoList = __GetTempRankBillPackList(personalTempIpyDataList)  | 
|     clientPack.PersonalBillCount = len(clientPack.PersonalBillboardInfoList)  | 
|       | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   | 
| def __GetTempRankBillPackList(ipyDataList):  | 
|     packBillList = []  | 
|     if not ipyDataList:  | 
|         return packBillList  | 
|     for tempIpyData in ipyDataList:  | 
|         rankInfo = ChPyNetSendPack.tagMCActGubaoBillard()  | 
|         rankInfo.Rank = tempIpyData.GetRank()  | 
|           | 
|         rankInfo.AwardItemList = []  | 
|         awardItemList = tempIpyData.GetAwardItemList()  | 
|         for itemID, itemCount, isAuctionItem in awardItemList:  | 
|             item = ChPyNetSendPack.tagMCActGubaoItem()  | 
|             item.Clear()  | 
|             item.ItemID = itemID  | 
|             item.ItemCount = itemCount  | 
|             item.IsBind = isAuctionItem  | 
|             rankInfo.AwardItemList.append(item)  | 
|         rankInfo.Count = len(rankInfo.AwardItemList)  | 
|           | 
| #        rankInfo.MemAwardItemList = []  | 
| #        memAwardItemList = tempIpyData.GetMemAwardItemList()  | 
| #        for itemID, itemCount, isAuctionItem in memAwardItemList:  | 
| #            item = ChPyNetSendPack.tagMCActGubaoItem()  | 
| #            item.Clear()  | 
| #            item.ItemID = itemID  | 
| #            item.ItemCount = itemCount  | 
| #            item.IsBind = isAuctionItem  | 
| #            rankInfo.MemAwardItemList.append(item)  | 
| #        rankInfo.MemCount = len(rankInfo.MemAwardItemList)  | 
|           | 
|         rankInfo.NeedScore = tempIpyData.GetNeedScore()  | 
|         rankInfo.AwardItemExList = []  | 
|         scoreAwardEx = tempIpyData.GetScoreAwardEx()  | 
|         scoreExList = scoreAwardEx.keys()  | 
|         scoreExList.sort()  | 
|         for scoreEx in scoreExList:  | 
|             itemExList = scoreAwardEx[scoreEx]  | 
|             awardEx = ChPyNetSendPack.tagMCActGubaoAwardEx()  | 
|             awardEx.NeedScore = scoreEx  | 
|             awardEx.AwardItemList = []  | 
|             for itemID, itemCount, isAuctionItem in itemExList:  | 
|                 item = ChPyNetSendPack.tagMCActGubaoItem()  | 
|                 item.Clear()  | 
|                 item.ItemID = itemID  | 
|                 item.ItemCount = itemCount  | 
|                 item.IsBind = isAuctionItem  | 
|                 awardEx.AwardItemList.append(item)  | 
|             awardEx.Count = len(awardEx.AwardItemList)  | 
|               | 
|             rankInfo.AwardItemExList.append(awardEx)  | 
|         rankInfo.CountEx = len(rankInfo.AwardItemExList)  | 
|           | 
|         packBillList.append(rankInfo)  | 
|     return packBillList  |