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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/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