1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/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