| #!/usr/bin/python | 
| # -*- coding: GBK -*- | 
| #------------------------------------------------------------------------------- | 
| # | 
| ##@package Player.PlayerActFamilyCTGAssist | 
| # | 
| # @todo:ÏÉÃ˳äÖµÐÖú | 
| # @author hxp | 
| # @date 2024-06-21 | 
| # @version 1.0 | 
| # | 
| # ÏêϸÃèÊö: ÏÉÃ˳äÖµÐÖú | 
| # | 
| #------------------------------------------------------------------------------- | 
| #"""Version = 2024-06-21 19:30""" | 
| #------------------------------------------------------------------------------- | 
|   | 
| import PyGameData | 
| import ShareDefine | 
| import PlayerControl | 
| import IpyGameDataPY | 
| import ChPyNetSendPack | 
| import DataRecordPack | 
| import NetPackCommon | 
| import ItemControler | 
| import IPY_GameWorld | 
| import GameWorld | 
| import ChConfig | 
|   | 
| def OnPlayerLogin(curPlayer): | 
|      | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FamilyCTGAssist, {}).values(): | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0) | 
|         isReset = __CheckPlayerFamilyCTGAssistAction(curPlayer, actNum) | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢ | 
|         if not isReset and actInfo.get(ShareDefine.ActKey_State): | 
|             Sync_FamilyCTGAssistActionInfo(curPlayer, actNum) | 
|             Sync_FamilyCTGAssistPlayerInfo(curPlayer, actNum) | 
|              | 
|     return | 
|   | 
| def RefreshFamilyCTGAssistActionInfo(actNum): | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢ | 
|     playerManager = GameWorld.GetPlayerManager() | 
|     for index in xrange(playerManager.GetPlayerCount()): | 
|         curPlayer = playerManager.GetPlayerByIndex(index) | 
|         if curPlayer.GetID() == 0: | 
|             continue | 
|         __CheckPlayerFamilyCTGAssistAction(curPlayer, actNum) | 
|     return | 
|   | 
|   | 
| def __CheckPlayerFamilyCTGAssistAction(curPlayer, actNum): | 
|     ## ¼ì²éÍæ»î¶¯Êý¾ÝÐÅÏ¢ | 
|      | 
|     playerID = curPlayer.GetPlayerID() | 
|      | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_FamilyCTGAssist, actNum) | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0) | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0) | 
|     #cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0) | 
|     #dayIndex = actInfo.get(ShareDefine.ActKey_DayIndex, 0) | 
|      | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyCTGAssistID % actNum) # Íæ¼ÒÉíÉϵĻID | 
|      | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí | 
|     if actID == playerActID: | 
|         GameWorld.DebugLog("ÏÉÃ˳äÖµÐÖú»î¶¯ID²»±ä£¬²»´¦Àí£¡ actNum=%s,actID=%s" % (actNum, actID), curPlayer.GetPlayerID()) | 
|         return | 
|     GameWorld.DebugLog("ÏÉÃ˳äÖµÐÖú»î¶¯ÖØÖÃ! actNum=%s,actID=%s,playerActID=%s,state=%s" % (actNum, actID, playerActID, state), playerID) | 
|      | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyCTGAssistID % actNum, actID) | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyCTGAssistAward % actNum, 0) | 
|      | 
|     if state: | 
|         Sync_FamilyCTGAssistActionInfo(curPlayer, actNum) | 
|         Sync_FamilyCTGAssistPlayerInfo(curPlayer, actNum) | 
|          | 
|     return True | 
|   | 
| def OnPlayerCTG(curPlayer): | 
|     if not curPlayer.GetFamilyID(): | 
|         return | 
|      | 
|     actNumList = [] | 
|     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FamilyCTGAssist, {}).values(): | 
|         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0) | 
|         if actInfo.get(ShareDefine.ActKey_State): | 
|             actNumList.append(actNum) | 
|              | 
|     if not actNumList: | 
|         return | 
|      | 
|     SendToGameServer_FamilyCTGAssist(curPlayer, "PlayerCTG", [actNumList]) | 
|     return | 
|   | 
| def GetFamilyCTGAssistAward(curPlayer, ctgPlayers, actNum): | 
|     '''»î¶¯Ãâ·Ñ½±Àø | 
|     @param ctgPlayers: ÒªÁìÈ¡µÄ³äÖµÈËÊý½±Àø | 
|     @param actNum: »î¶¯±àºÅ£¬Èç11 »ò  12 ´ú±í²»Í¬µÄ»î¶¯ | 
|     ''' | 
|     playerID = curPlayer.GetPlayerID() | 
|      | 
|     actNum = GameWorld.ToIntDef(actNum, 0) | 
|     if actNum <= 0: | 
|         GameWorld.Log("ûÓÐÖ¸¶¨ÁìÈ¡µÄ»î¶¯±àºÅ! actNum=%s" % actNum, playerID) | 
|         return | 
|      | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_FamilyCTGAssist, actNum) | 
|     if not actInfo.get(ShareDefine.ActKey_State): | 
|         GameWorld.Log("ÏÉÃ˳äÖµÐÖú·Ç»î¶¯ÖÐÎÞ·¨ÁìÈ¡½±Àø! actNum=%s" % actNum, playerID) | 
|         return | 
|      | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID) | 
|     dayIndex = actInfo.get(ShareDefine.ActKey_DayIndex, 0) | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActFamilyCTGAssist", cfgID) | 
|     if not ipyData: | 
|         return | 
|     templateID = GameWorld.GetTemplateID(ipyData, cfgID, dayIndex) | 
|     if not templateID: | 
|         return | 
|      | 
|     tempIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActFamilyCTGAssistTemp", templateID) | 
|     if not tempIpyDataList: | 
|         return | 
|      | 
|     recordIndex = None | 
|     awardItemList = [] | 
|      | 
|     for tempIpyData in tempIpyDataList: | 
|         if ctgPlayers != tempIpyData.GetNeedCTGPlayers(): | 
|             continue | 
|         recordIndex = tempIpyData.GetRecordIndex() | 
|         awardItemList = tempIpyData.GetAwardItemList() | 
|         break | 
|      | 
|     if recordIndex == None: | 
|         GameWorld.ErrLog("ÏÉÃ˳äÖµÐÖú»î¶¯Ã»Óиý±ÀøÐÅÏ¢! actNum=%s,cfgID=%s,templateID=%s,ctgPlayers=%s"  | 
|                          % (actNum, cfgID, templateID, ctgPlayers), playerID) | 
|         return | 
|      | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyCTGAssistAward % actNum) | 
|     if awardRecord & pow(2, recordIndex): | 
|         GameWorld.Log("ÏÉÃ˳äÖµÐÖú»î¶¯ÒѾÁìÈ¡¹ý¸ÃÃâ·Ñ½±Àø! actNum=%s,cfgID=%s,templateID=%s,ctgPlayers=%s,recordIndex=%s"  | 
|                       % (actNum, cfgID, templateID, ctgPlayers, recordIndex), playerID) | 
|         return | 
|      | 
|     # ¼ì²é±³°ü | 
|     if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList): | 
|         return | 
|      | 
|     tick = GameWorld.GetGameWorld().GetTick() | 
|     if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_FamilyCTGAssist, tick): | 
|         GameWorld.DebugLog("ÇëÇóCDÖÐ...", playerID) | 
|         return | 
|      | 
|     SendToGameServer_FamilyCTGAssist(curPlayer, "FamilyCTGAssistAward", [actNum, ctgPlayers, recordIndex, awardItemList]) | 
|     return | 
|   | 
| def __DoGiveFamilyCTGAssistAward(curPlayer, dataMsg): | 
|     actNum, ctgPlayers, recordIndex, awardItemList = dataMsg | 
|      | 
|     playerID = curPlayer.GetPlayerID() | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyCTGAssistAward % actNum) | 
|     if awardRecord & pow(2, recordIndex): | 
|         GameWorld.DebugLog("·µ»ØÊ±ÏÉÃ˳äÖµÐÖú»î¶¯ÒѾÁìÈ¡¹ý¸ÃÃâ·Ñ½±Àø! actNum=%s,ctgPlayers=%s,recordIndex=%s"  | 
|                            % (actNum, ctgPlayers, recordIndex), playerID) | 
|         return | 
|      | 
|     awardRecord |= pow(2, recordIndex) | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyCTGAssistAward % actNum, awardRecord) | 
|     Sync_FamilyCTGAssistPlayerInfo(curPlayer, actNum) | 
|      | 
|     for itemID, itemCount, isAuctionItem in awardItemList: | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem]) | 
|          | 
|     addDataDict = {"actNum":actNum, "ctgPlayers":ctgPlayers, "recordIndex":recordIndex, "awardItemList":awardItemList} | 
|     DataRecordPack.DR_FuncGiveItem(curPlayer, "ActFamilyCTGAssist", addDataDict) | 
|     GameWorld.Log("ÏÉÃ˳äÖµÐÖú»î¶¯ÁìÈ¡½±Àø! actNum=%s,ctgPlayers=%s,recordIndex=%s,updAwardRecord=%s,awardItemList=%s"  | 
|                   % (actNum, ctgPlayers, recordIndex, awardRecord, awardItemList), playerID) | 
|     return | 
|   | 
| def SendToGameServer_FamilyCTGAssist(curPlayer, msgType, dataMsg=""): | 
|     playerID = curPlayer.GetPlayerID() | 
|     msgList = str([msgType, dataMsg]) | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "FamilyCTGAssist", msgList, len(msgList)) | 
|     GameWorld.Log("ÏÉÃ˳äÖµ»¥Öú·¢ËÍGameServer: %s, %s" % (msgType, dataMsg), playerID) | 
|     return | 
|   | 
| def GameServer_FamilyCTGAssist(curPlayer, msgData, tick): | 
|      | 
|     msgType, dataMsg, ret = msgData | 
|      | 
|     if not ret: | 
|         return | 
|      | 
|     if msgType == "FamilyCTGAssistAward": | 
|         __DoGiveFamilyCTGAssistAward(curPlayer, dataMsg) | 
|          | 
|     return | 
|   | 
| def Sync_FamilyCTGAssistPlayerInfo(curPlayer, actNum): | 
|     ## Í¨ÖªÍæ¼ÒÊý¾ÝÐÅÏ¢ | 
|     clientPack = ChPyNetSendPack.tagMCActFamilyCTGAssistPlayerInfo() | 
|     clientPack.ActNum = actNum | 
|     clientPack.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyCTGAssistAward % actNum) | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack) | 
|     return | 
|   | 
| def Sync_FamilyCTGAssistActionInfo(curPlayer, actNum): | 
|     ## Í¨Öª»î¶¯ÐÅÏ¢ | 
|      | 
|     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_FamilyCTGAssist, actNum) | 
|     if not actInfo.get(ShareDefine.ActKey_State): | 
|         return | 
|      | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID) | 
|     dayIndex = actInfo.get(ShareDefine.ActKey_DayIndex, 0) | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActFamilyCTGAssist", cfgID) | 
|     if not ipyData: | 
|         return | 
|     templateID = GameWorld.GetTemplateID(ipyData, cfgID, dayIndex) | 
|     if not templateID: | 
|         return | 
|     tempIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActFamilyCTGAssistTemp", templateID) | 
|     if not tempIpyDataList: | 
|         return | 
|      | 
|     startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData) | 
|     startDateSync = actInfo.get(ShareDefine.ActKey_StartDateSync, startDateStr) | 
|     actInfo = ChPyNetSendPack.tagMCActFamilyCTGAssistInfo() | 
|     actInfo.ActNum = actNum | 
|     actInfo.StartDate = startDateSync | 
|     actInfo.EndtDate = endDateStr | 
|     actInfo.LimitLV = ipyData.GetLVLimit() | 
|     actInfo.IsDayReset = ipyData.GetIsDayReset() | 
|     actInfo.AwardInfoList = [] | 
|      | 
|     for tempIpyData in tempIpyDataList: | 
|         award = ChPyNetSendPack.tagMCActFamilyCTGAssistAward() | 
|         award.NeedCTGPlayers = tempIpyData.GetNeedCTGPlayers() | 
|         award.RecordIndex = tempIpyData.GetRecordIndex() | 
|         award.AwardItemList = [] | 
|          | 
|         for itemID, itemCount, isAuctionItem in tempIpyData.GetAwardItemList(): | 
|             item = ChPyNetSendPack.tagMCActFamilyCTGAssistItem() | 
|             item.ItemID = itemID | 
|             item.ItemCount = itemCount | 
|             item.IsBind = isAuctionItem | 
|             award.AwardItemList.append(item) | 
|         award.Count = len(award.AwardItemList) | 
|          | 
|         actInfo.AwardInfoList.append(award) | 
|          | 
|     actInfo.AwardCount = len(actInfo.AwardInfoList) | 
|     NetPackCommon.SendFakePack(curPlayer, actInfo) | 
|     return |