| #!/usr/bin/python | 
| # -*- coding: GBK -*- | 
| #------------------------------------------------------------------------------- | 
| # | 
| ##@package PlayerActFamilyCTGAssist | 
| # | 
| # @todo:ÏÉÃ˳äÖµ»¥Öú | 
| # @author hxp | 
| # @date 2024-06-21 | 
| # @version 1.0 | 
| # | 
| # ÏêϸÃèÊö: ÏÉÃ˳äÖµ»¥Öú | 
| # | 
| #------------------------------------------------------------------------------- | 
| #"""Version = 2024-06-21 19:30""" | 
| #------------------------------------------------------------------------------- | 
|   | 
| import GameWorld | 
| import PlayerFamilyAction | 
| import ShareDefine | 
| import PlayerFamily | 
| import ChConfig | 
|   | 
| ActionType = ShareDefine.Def_ActionType_FamilyCTGAssist | 
|     | 
| def GetFAActNum(actionData): return actionData.GetValue1() | 
| def SetFAActNum(actionData, actNum): return actionData.SetValue1(actNum) | 
|   | 
| def GetFAActPlayerIDInfo(actionData): | 
|     playerIDInfo = [[], {}] | 
|     useData = actionData.GetUseData() | 
|     if useData: | 
|         try: | 
|             playerIDInfo = eval(useData) | 
|         except: | 
|             playerIDInfo = [[], {}] | 
|     return playerIDInfo | 
| def SetFAActPlayerIDInfo(actionData, ctgPlayerIDList, getAwardPlayerCountDict): | 
|     useData = str([ctgPlayerIDList, getAwardPlayerCountDict]).replace(" ", "") | 
|     actionData.SetUseData(useData, len(useData)) | 
|     return | 
| def ClearFAActPlayerIDInfo(actionData): | 
|     SetFAActPlayerIDInfo(actionData, [], {}) | 
|     return | 
|   | 
| def GetFamilyCTGAssistActionData(familyID, actNum): | 
|     ## »ñÈ¡Action | 
|     findActionData = None | 
|     familyAction = GameWorld.GetFamilyActionManager().GetFamilyAction(familyID, ActionType) | 
|     for index in range(0, familyAction.Count()): | 
|         actionData = familyAction.At(index) | 
|         if GetFAActNum(actionData) == actNum: | 
|             findActionData = actionData | 
|             break | 
|          | 
|     if not findActionData: | 
|         findActionData = familyAction.AddAction() | 
|         findActionData.SetFamilyId(familyID) | 
|         findActionData.SetActionType(ActionType) | 
|         SetFAActNum(findActionData, actNum) | 
|         ClearFAActPlayerIDInfo(findActionData) | 
|          | 
|     return findActionData | 
|   | 
| def OnActStart(actNum): | 
|     ## »î¶¯¿ªÆô | 
|      | 
|     familyManager = GameWorld.GetFamilyManager() | 
|     for i in range(0, familyManager.GetCount()): | 
|         family = familyManager.GetAt(i) | 
|         familyID = family.GetID() | 
|         actionData = GetFamilyCTGAssistActionData(familyID, actNum) | 
|         ClearFAActPlayerIDInfo(actionData) # ÖØÖóäÖµ¼´ÁìÈ¡ÈËÔ±ID¼Ç¼ | 
|          | 
|         PlayerFamilyAction.SendFamilyActionInfo(None, familyID, ActionType) | 
|          | 
|     return | 
|   | 
| def MapServer_FamilyCTGAssist(curPlayer, msgList): | 
|     mapID = curPlayer.GetRealMapID() | 
|     playerID = curPlayer.GetPlayerID() | 
|     GameWorld.DebugLog("MapServer_FamilyCTGAssist mapID=%s,msgList=%s" % (mapID, msgList), playerID) | 
|     if not msgList: | 
|         return | 
|      | 
|     msgType, dataMsg = msgList | 
|     ret = None | 
|      | 
|     if msgType == "PlayerCTG": | 
|         ret = __OnPlayerCTG(curPlayer, dataMsg) | 
|          | 
|     elif msgType == "FamilyCTGAssistAward": | 
|         ret = __OnFamilyCTGAssistAward(curPlayer, dataMsg) | 
|          | 
|     if ret == None: | 
|         return | 
|     return msgList + (ret if isinstance(ret, list) else [ret]) | 
|   | 
| def __OnPlayerCTG(curPlayer, dataMsg): | 
|     ## ÓÐÍæ¼Ò³äÖµ | 
|     actNumList = dataMsg[0] | 
|     familyID = curPlayer.GetFamilyID() | 
|     if not familyID: | 
|         return | 
|      | 
|     isChange = False | 
|     playerID = curPlayer.GetPlayerID() | 
|     for actNum in actNumList: | 
|         actionData = GetFamilyCTGAssistActionData(familyID, actNum) | 
|          | 
|         ctgPlayerIDList, getAwardPlayerCountDict = GetFAActPlayerIDInfo(actionData) | 
|         if playerID in ctgPlayerIDList: | 
|             continue | 
|          | 
|         isChange = True | 
|         ctgPlayerIDList.append(playerID) | 
|         SetFAActPlayerIDInfo(actionData, ctgPlayerIDList, getAwardPlayerCountDict) | 
|         GameWorld.Log("ÏÉÃ˳äÖµ»¥ÖúÈËÊý±ä¸ü: actNum=%s,familyID=%s,л¥ÖúÍæ¼Ò=%s,¸üл¥ÖúÈËÊý=%s, %s"  | 
|                       % (actNum, familyID, playerID, len(ctgPlayerIDList), ctgPlayerIDList)) | 
|          | 
|     if not isChange: | 
|         return | 
|      | 
|     PlayerFamilyAction.SendFamilyActionInfo(None, familyID, ActionType) | 
|     return | 
|   | 
| def __OnFamilyCTGAssistAward(curPlayer, dataMsg): | 
|     ## Íæ¼ÒÁì½± | 
|      | 
|     actNum, ctgPlayers, _, _ = dataMsg | 
|     familyID = curPlayer.GetFamilyID() | 
|     if not familyID: | 
|         return | 
|      | 
|     playerID = curPlayer.GetPlayerID() | 
|      | 
|     actionData = GetFamilyCTGAssistActionData(familyID, actNum) | 
|      | 
|     ctgPlayerIDList, getAwardPlayerCountDict = GetFAActPlayerIDInfo(actionData) | 
|      | 
|     if len(ctgPlayerIDList) < ctgPlayers: | 
|         GameWorld.DebugLog("ÏÉÃ˳äÖµ»¥ÖúËùÐè³äÖµÈËÊý²»×ã: actNum=%s,familyID=%s,ÒÑ»¥ÖúÈËÊý=%s < %s, %s"  | 
|                       % (actNum, familyID, len(ctgPlayerIDList), ctgPlayers, ctgPlayerIDList), playerID) | 
|         return | 
|      | 
|     curFamily = GameWorld.GetFamilyManager().FindFamily(familyID) | 
|     if not curFamily: | 
|         return | 
|     maxMemberCnt = PlayerFamily.GetFamilySetting(curFamily, ChConfig.Def_FamilySetting_MaxMemberCnt) | 
|      | 
|     getAwardPlayerCount = getAwardPlayerCountDict.get(str(ctgPlayers), 0) | 
|     if getAwardPlayerCount >= maxMemberCnt: | 
|         GameWorld.DebugLog("ÏÉÃ˳äÖµ»¥ÖúÁì½±ÈËÊýÒÑ´ïÉÏÏÞ: actNum=%s,familyID=%s,ctgPlayers=%s,getAwardPlayerCount=%s >= %s"  | 
|                            % (actNum, familyID, ctgPlayers, getAwardPlayerCount, maxMemberCnt), playerID) | 
|         return | 
|      | 
|     getAwardPlayerCount += 1 | 
|     getAwardPlayerCountDict[str(ctgPlayers)] = getAwardPlayerCount | 
|      | 
|     SetFAActPlayerIDInfo(actionData, ctgPlayerIDList, getAwardPlayerCountDict) | 
|     GameWorld.Log("ÏÉÃ˳äÖµ»¥ÖúÁì½±ÈËÊý¸üÐÂ: actNum=%s,familyID=%s,ctgPlayers=%s,getAwardPlayerCount=%s, %s"  | 
|                   % (actNum, familyID, ctgPlayers, getAwardPlayerCount, getAwardPlayerCountDict), playerID) | 
|      | 
|     PlayerFamilyAction.SendFamilyActionInfo(None, familyID, ActionType) | 
|     return True |