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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package PlayerFamilyEmblem
#
# @todo:ÏÉÃË»ÕÕÂ
# @author hxp
# @date 2024-09-09
# @version 1.0
#
# ÏêϸÃèÊö: ÏÉÃË»ÕÕÂ
#
#-------------------------------------------------------------------------------
#"""Version = 2024-09-09 15:30"""
#-------------------------------------------------------------------------------
 
import GameWorld
import ShareDefine
import PlayerFamilyAction
import IpyGameDataPY
import PlayerFamily
 
import random
import time
 
def GetActionEmblemID(emblemActionObj): return emblemActionObj.GetValue1()
def SetActionEmblemID(emblemActionObj, emblemID): return emblemActionObj.SetValue1(emblemID)
def GetActionEmblemExpireTimes(emblemActionObj): return emblemActionObj.GetValue2()
def SetActionEmblemExpireTimes(emblemActionObj, endTime): return emblemActionObj.SetValue2(endTime)
 
def GetDefaultFamilyEmblemIDList():
    ## »ñȡĬÈϵÄÏÉÃË»ÕÕÂIDÁÐ±í£¬¼´ËùÓнâËøµÈ¼¶Îª1µÄ»ÕÕÂID
    defaultEmblemIDList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetFamilyEmblemCount()):
        ipyData = ipyDataMgr.GetFamilyEmblemByIndex(index)
        emblemID = ipyData.GetEmblemID()
        if ipyData.GetUnlockFamilyLV() == 1:
            defaultEmblemIDList.append(emblemID)
    return defaultEmblemIDList
 
def CheckExpireEmblem():
    ## ¼ì²é¹ýÆÚµÄÑ«ÕÂ
    
    defaultEmblemIDList = []
    curTime = int(time.time())
    actionType = ShareDefine.Def_ActionType_FamilyEmblem
    familyManager = GameWorld.GetFamilyManager()
    familyActionMgr = GameWorld.GetFamilyActionManager()
    for i in xrange(familyManager.GetCount()):
        family = familyManager.GetAt(i)
        if not family:
            continue
        familyID = family.GetID()
        familyAction = familyActionMgr.GetFamilyAction(familyID, actionType)
        for index in range(familyAction.Count())[::-1]: # ¿ÉÄÜ´¥·¢É¾³ý£¬µ¹Ðò±éÀú
            emblemActionObj = familyAction.At(index)
            emblemID = GetActionEmblemID(emblemActionObj)
            isExpired, endTime = IsEmblemExpired(emblemActionObj, curTime)
            if not isExpired:
                #GameWorld.Log("¼ì²éÏÉÃË»ÕÕÂδ¹ýÆÚ! familyID=%s,emblemID=%s,endTime=%s" % (familyID, emblemID, endTime))
                continue
            familyAction.DelAction(index)
            GameWorld.Log("ɾ³ý¹ýÆÚÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s,endTime=%s" % (familyID, emblemID, endTime))
            if PlayerFamily.GetFamilyEmblemID(family) == emblemID:
                if not defaultEmblemIDList:
                    defaultEmblemIDList = GetDefaultFamilyEmblemIDList()
                updEmblemID = random.choice(defaultEmblemIDList) if defaultEmblemIDList else 0
                GameWorld.Log("ÏÉÃËÅå´÷»ÕÕ¹ýÆÚ»Ö¸´Ëæ»úĬÈÏ»ÕÕÂ! familyID=%s,emblemID=%s,endTime=%s,updEmblemID=%s" % (familyID, emblemID, endTime, updEmblemID))
                PlayerFamily.SetFamilyEmblemID(family, updEmblemID)
                family.Broadcast_FamilyChange()
    return
 
def IsEmblemExpired(emblemActionObj, curTime):
    ## Ñ«ÕÂÊÇ·ñ¹ýÆÚ
    # @return: ÊÇ·ñ¹ýÆÚ, endTime
        
    endTime = -1
    if not emblemActionObj:
        return True, endTime
    
    createTime = emblemActionObj.GetTime()
    expireTimes = GetEmblemExpireTimes(emblemActionObj)
    if expireTimes == 0:
        # ÓÀ¾ÃµÄ
        return False, 0
    
    if expireTimes > 0:
        endTime = createTime + expireTimes
        if endTime >= curTime:
            # Î´¹ýÆÚ
            return False, endTime
        
    return True, endTime
 
def GetEmblemExpireTimes(emblemActionObj):
    ## »ñȡѫÕÂÓÐЧʱ³¤£¬Ãë
    # @return: 0-ÓÀ¾Ã£»-1-ÎÞЧ£»>0-ÓÐЧÃëÊý
    expireTimes = GetActionEmblemExpireTimes(emblemActionObj) # ÓÐЧʱ³¤£¬Ãë
    if not expireTimes:
        emblemID = GetActionEmblemID(emblemActionObj)
        ipyData = IpyGameDataPY.GetIpyGameData("FamilyEmblem", emblemID)
        if not ipyData:
            return -1
        expireTimes = ipyData.GetExpireMinutes() * 60
    return expireTimes
 
def GetFamilyEmblemActionData(familyID, emblemID):
    ## »ñÈ¡ÏÉÃËʱЧ»ÕÕÂActionÊý¾Ý
    actionType = ShareDefine.Def_ActionType_FamilyEmblem
    familyAction = GameWorld.GetFamilyActionManager().GetFamilyAction(familyID, actionType)
    for index in range(familyAction.Count()):
        familyActionObj = familyAction.At(index)
        if emblemID == familyActionObj.GetValue1():
            return familyActionObj
    return
 
def AddFamilyEmblem(familyID, emblemID, setExpireTimes=None):
    ## Ìí¼ÓÏÉÃË»ÕÕÂ
    # @param setExpireTimes: Ö¸¶¨µÄÓÐЧʱ³¤Ã룬0-ÓÀ¾Ã£¬>0-ÓÐЧʱ³¤Ã룻ûÓÐÖ¸¶¨Ê±Ö±½Ó¶ÁÅäÖýøÐÐÀÛ¼Ó
    
    ipyData = IpyGameDataPY.GetIpyGameData("FamilyEmblem", emblemID)
    if not ipyData:
        return
    if ipyData.GetCustomFamilyID():
        GameWorld.Log("ÏÉÃ˶¨ÖÆ»ÕÕ²»ÐèÒªÌí¼Ó! familyID=%s,emblemID=%s" % (familyID, emblemID))
        return
    unlockFamilyLV = ipyData.GetUnlockFamilyLV()
    if unlockFamilyLV:
        GameWorld.Log("ÏÉÃ˽âËøµÄ»ÕÕ²»ÐèÒªÌí¼Ó! familyID=%s,emblemID=%s" % (familyID, emblemID))
        return
    if setExpireTimes >= 0:
        expireTimes = setExpireTimes
    else:        
        expireTimes = ipyData.GetExpireMinutes() * 60
    GameWorld.Log("Ìí¼ÓÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s,setExpireTimes=%s,expireTimes=%s" 
                  % (familyID, emblemID, setExpireTimes, expireTimes))
    
    curTime = int(time.time())
    emblemActionObj = GetFamilyEmblemActionData(familyID, emblemID)
    if not emblemActionObj:
        actionType = ShareDefine.Def_ActionType_FamilyEmblem
        familyAction = GameWorld.GetFamilyActionManager().GetFamilyAction(familyID, actionType)
        emblemActionObj = familyAction.AddAction()
        emblemActionObj.SetTime(curTime)
        emblemActionObj.SetFamilyId(familyID)
        emblemActionObj.SetActionType(actionType)
    else:
        isExpired, endTime = IsEmblemExpired(emblemActionObj, curTime)
        if setExpireTimes >= 0:
            emblemActionObj.SetTime(curTime)
            GameWorld.Log("Ö±½ÓÉèÖÃÑ«ÕÂÊ£Óàʱ³¤£¬ÖØÐÂÉèÖûñµÃʱ¼ä! familyID=%s,emblemID=%s" % (familyID, emblemID))
        elif isExpired:
            emblemActionObj.SetTime(curTime)
            GameWorld.Log("»ñµÃÑ«ÕÂʱÒѹýÆÚ£¬ÖØÐÂÉèÖûñµÃʱ¼ä! familyID=%s,emblemID=%s,endTime=%s" % (familyID, emblemID, endTime))
        else:
            # Î´¹ýÆÚ£¬·ÇÓÀ¾ÃµÄÖ±½ÓÀÛ¼Óʱ³¤
            if expireTimes > 0:
                expireTimes += GetActionEmblemExpireTimes(emblemActionObj)
                GameWorld.Log("»ñµÃÑ«ÕÂʱδ¹ýÆÚ£¬ÀÛ¼ÓÓÐЧʱ³¤! familyID=%s,emblemID=%s,expireTimes=%s" % (familyID, emblemID, expireTimes))
                
    SetActionEmblemID(emblemActionObj, emblemID)
    SetActionEmblemExpireTimes(emblemActionObj, expireTimes)
    
    # Í¨Öª
    PlayerFamilyAction.SendFamilyAction(emblemActionObj)
    return emblemActionObj
 
def OnChangeFamilyEmblem(curPlayer, emblemID):
    ## ÐÞ¸ÄÏÉÃË»ÕÕÂ
    playerID = curPlayer.GetPlayerID()
    curFamily = curPlayer.GetFamily()
    if not curFamily:
        return
    familyID = curFamily.GetID()
    
    if curFamily.GetLeaderID() != playerID:
        GameWorld.DebugLog("Ö»ÓÐÃËÖ÷¿ÉÒÔÐ޸ĻÕÕÂ!", playerID)
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("FamilyEmblem", emblemID)
    if not ipyData:
        return
    unlockFamilyLV = ipyData.GetUnlockFamilyLV()
    customFamilyID = ipyData.GetCustomFamilyID()
    
    if customFamilyID:
        if familyID != customFamilyID:
            GameWorld.DebugLog("²»ÊǸö¨ÖÆ»ÕÕÂËùÊôÏÉÃË£¬ÎÞ·¨Ê¹ÓøûÕÕÂ! emblemID=%s,customFamilyID=%s != %s" 
                               % (emblemID, customFamilyID, familyID), playerID)
            return
        
    elif unlockFamilyLV:
        if curFamily.GetLV() < unlockFamilyLV:
            GameWorld.DebugLog("ÏÉÃ˵ȼ¶²»×㣬ÎÞ·¨Ê¹ÓøûÕÕÂ! emblemID=%s,unlockFamilyLV=%s" 
                               % (emblemID, unlockFamilyLV), playerID)
            return
    else:
        emblemActionObj = GetFamilyEmblemActionData(familyID, emblemID)
        isExpired, endTime = IsEmblemExpired(emblemActionObj, int(time.time()))
        if isExpired:
            GameWorld.DebugLog("¸Ã»ÕÕ²»´æÔÚ»òÒѹýÆÚ! emblemID=%s,endTime=%s" % (emblemID, endTime), playerID)
            return
        
    GameWorld.DebugLog("¸ü»»ÏÉÃË»ÕÕÂ! familyID=%s,emblemID=%s" % (familyID, emblemID), playerID)
    PlayerFamily.SetFamilyEmblemID(curFamily, emblemID)
    PlayerFamily.SendPack_MapServer_PlayerFamilyRefresh(curFamily)
    curFamily.Broadcast_FamilyChange()
    return