| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerActHorsePetTrain  | 
| #  | 
| # @todo:Æï³èÑø³É»î¶¯  | 
| # @author hxp  | 
| # @date 2024-08-14  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: Æï³èÑø³É»î¶¯  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2024-08-14 16:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PyGameData  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import CrossRealmPlayer  | 
| import FunctionNPCCommon  | 
| import PlayerBillboard  | 
| import ChPyNetSendPack  | 
| import PlayerZhanling  | 
| import NetPackCommon  | 
| import PlayerActTask  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| def OnMixFirstLogin(curPlayer):  | 
|       | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HorsePetTrain, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         if not actInfo.get(ShareDefine.ActKey_State):  | 
|             continue  | 
|         score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHorsePetTrainScore % actNum)  | 
|         if not score:  | 
|             continue  | 
|         GameWorld.Log("Æï³èÑø³ÉºÏ·þÊ×µÇͬ²½»ý·Ö°ñµ¥: actNum=%s,score=%s" % (actNum, score), curPlayer.GetPlayerID())  | 
|         PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_HorsePetTrainScore, score, autoSort=True)  | 
|         break  | 
|       | 
|     return  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|       | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HorsePetTrain, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         isReset = __CheckPlayerHorsePetTrainAction(curPlayer, actNum)  | 
|         if not isReset:  | 
|             # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|             if actInfo.get(ShareDefine.ActKey_State):  | 
|                 Sync_HorsePetTrainActionInfo(curPlayer, actNum)  | 
|                 Sync_HorsePetTrainPlayerInfo(curPlayer, actNum)  | 
|                   | 
|     if not __CheckPlayerCrossActHorsePetTrain(curPlayer):  | 
|         Sync_CrossActHorsePetTrainActionInfo(curPlayer)  | 
|           | 
|     return  | 
|   | 
| def RefreshHorsePetTrainActionInfo(actNum):  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerHorsePetTrainAction(curPlayer, actNum)  | 
|     return  | 
|   | 
| def __CheckPlayerHorsePetTrainAction(curPlayer, actNum):  | 
|     ## ¼ì²éÍæ¼Ò»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HorsePetTrain, 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_ActHorsePetTrainID % 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_ActHorsePetTrainScore % actNum)  | 
|     PlayerZhanling.ResetZhanling(curPlayer, PlayerZhanling.ZhanlingType_HorsePetTrain, score)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHorsePetTrainID % actNum, actID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHorsePetTrainScore % actNum, 0)  | 
|       | 
|     if state:  | 
|         cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|         ipyData = IpyGameDataPY.GetIpyGameData("ActHorsePetTrain", cfgID)  | 
|         if ipyData and ipyData.GetActShopType():  | 
|             FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, [ipyData.GetActShopType()])  | 
|         Sync_HorsePetTrainActionInfo(curPlayer, actNum)  | 
|         Sync_HorsePetTrainPlayerInfo(curPlayer, actNum)  | 
|     return True  | 
|   | 
| def RefreshCrossActHorsePetTrainInfo():  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerCrossActHorsePetTrain(curPlayer)  | 
|           | 
|     return  | 
|   | 
| def __CheckPlayerCrossActHorsePetTrain(curPlayer):  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_HorsePetTrain)  | 
|     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_HorsePetTrainID) # Íæ¼ÒÉíÉϵĻ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_HorsePetTrainID, actID)  | 
|       | 
|     if not state:  | 
|         CrossRealmPlayer.NotifyCrossActEnd(curPlayer, ShareDefine.CrossActName_HorsePetTrain)  | 
|           | 
|     Sync_CrossActHorsePetTrainActionInfo(curPlayer)  | 
|     return True  | 
|   | 
| def OnHorsePetTrainCost(curPlayer, costItemDict):  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HorsePetTrain, {}).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("ActHorsePetTrain", cfgID)  | 
|         if not ipyData:  | 
|             continue  | 
|           | 
|         if ipyData.GetIsRelationCrossAct():  | 
|             crossActInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_HorsePetTrain)  | 
|             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  | 
|               | 
|         addActScore = 0  | 
|         itemScoreDict = IpyGameDataPY.GetFuncEvalCfg("HorsePetTrainAct", 1, {})  | 
|         for itemID, costCount in costItemDict.items():  | 
|             if str(itemID) not in itemScoreDict:  | 
|                 continue  | 
|             itemScore = costCount * itemScoreDict[str(itemID)]  | 
|             addActScore += itemScore  | 
|             GameWorld.DebugLog("Æï³èÑø³É»î¶¯ÏûºÄÎïÆ·»ý·Öͳ¼Æ: actNum=%s,itemID=%s,costCount=%s,itemScore=%s, %s"   | 
|                                % (actNum, itemID, costCount, itemScore, addActScore))  | 
|               | 
|         if addActScore <= 0:  | 
|             continue  | 
|           | 
|         AddPlayerScore(curPlayer, actNum, addActScore, ipyData.GetIsRelationCrossAct())  | 
|           | 
|     return  | 
|   | 
| def AddPlayerScore(curPlayer, actNum, addScore, isRelationCrossAct):  | 
|     if addScore <= 0:  | 
|         return 0  | 
|     score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHorsePetTrainScore % actNum)  | 
|     updScore = score + addScore  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActHorsePetTrainScore % actNum, updScore)  | 
|     GameWorld.DebugLog("Æï³èÑø³É»î¶¯Ôö¼Ó»ý·Ö: actNum=%s,addScore=%s,updScore=%s" % (actNum, addScore, updScore))  | 
|     Sync_HorsePetTrainPlayerInfo(curPlayer, actNum)  | 
|     PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_HorsePetTrainScore, addScore, "ActHorsePetTrain")  | 
|     PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_HorsePetActScore, addScore)  | 
|     PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_HorsePetTrainScore, updScore, autoSort=True)  | 
|     SendToGameServer_HorsePetTrain(curPlayer, "AddHorsePetTrainScore", [addScore, updScore, isRelationCrossAct])  | 
|     return updScore  | 
|   | 
| def SendToGameServer_HorsePetTrain(curPlayer, msgType, dataMsg=""):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     msgList = str([msgType, dataMsg])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "ActHorsePetTrain", msgList, len(msgList))  | 
|     GameWorld.Log("Æï³èÑø³É»î¶¯·¢ËÍGameServer: %s, %s" % (msgType, dataMsg), playerID)  | 
|     return  | 
|   | 
| def GetActHorsePetTrainScore(curPlayer):  | 
|     ## »ñÈ¡»î¶¯ÖÐÑø³É»ý·Ö  | 
|     actScore = 0  | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_HorsePetTrain, {}).values():  | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)  | 
|         if not actInfo.get(ShareDefine.ActKey_State):  | 
|             continue  | 
|         score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHorsePetTrainScore % actNum)  | 
|         actScore = max(score, actScore)  | 
|     return actScore  | 
|   | 
| def Sync_HorsePetTrainActionInfo(curPlayer, actNum):  | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HorsePetTrain, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActHorsePetTrain", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     personalTempID = ipyData.GetPersonalTemplateID()  | 
|     personalTempIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActHorsePetTrainBillTemp", personalTempID) if personalTempID else []  | 
|       | 
|     startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCActHorsePetTrainInfo()  | 
|     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_HorsePetTrainPlayerInfo(curPlayer, actNum):  | 
|       | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_HorsePetTrain, actNum)  | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCActHorsePetTrainPlayerInfo()  | 
|     clientPack.ActNum = actNum  | 
|     clientPack.Score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActHorsePetTrainScore % actNum)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|     return  | 
|   | 
| def Sync_CrossActHorsePetTrainActionInfo(curPlayer):  | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢  | 
|     actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_HorsePetTrain)  | 
|     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("ActHorsePetTrainBillTemp", personalTempID) if personalTempID else []  | 
|       | 
|     clientPack = ChPyNetSendPack.tagMCCrossActHorsePetTrainInfo()  | 
|     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.tagMCActHorsePetTrainBillard()  | 
|         rankInfo.Rank = tempIpyData.GetRank()  | 
|           | 
|         rankInfo.AwardItemList = []  | 
|         awardItemList = tempIpyData.GetAwardItemList()  | 
|         for itemID, itemCount, isAuctionItem in awardItemList:  | 
|             item = ChPyNetSendPack.tagMCActHorsePetTrainItem()  | 
|             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.tagMCActHorsePetTrainItem()  | 
| #            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.tagMCActHorsePetTrainAwardEx()  | 
|             awardEx.NeedScore = scoreEx  | 
|             awardEx.AwardItemList = []  | 
|             for itemID, itemCount, isAuctionItem in itemExList:  | 
|                 item = ChPyNetSendPack.tagMCActHorsePetTrainItem()  | 
|                 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  |