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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActGrowupBuy
#
# @todo:ÔËÓª»î¶¯ - ³É³¤±ØÂò
# @author hxp
# @date 2020-11-23
# @version 1.0
#
# ÏêϸÃèÊö: ÔËÓª»î¶¯ - ³É³¤±ØÂò
#
#-------------------------------------------------------------------------------
#"""Version = 2020-11-23 21:00"""
#-------------------------------------------------------------------------------
 
 
import PyGameData
import ShareDefine
import PlayerControl
import IpyGameDataPY
import ChPyNetSendPack
import NetPackCommon
import GameWorld
import ChConfig
 
def OnPlayerLogin(curPlayer):
    isReset = __CheckPlayerGrowupBuyAction(curPlayer)
    if not isReset:
        actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if actInfo.get(ShareDefine.ActKey_State):
            Sync_GrowupActionInfo(curPlayer)
    return
 
def RefreshGrowupBuyActionInfo():
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if curPlayer.GetID() == 0:
            continue
        __CheckPlayerGrowupBuyAction(curPlayer)
    return
 
def __CheckPlayerGrowupBuyAction(curPlayer):
    ## ¼ì²éÍæ¼Ò³äÖµ·µÀû»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyID) # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("³É³¤±ØÂò»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())
        return
    GameWorld.DebugLog("³É³¤±ØÂòÖØÖÃ! actID=%s,playerActID=%s,state=%s" % (actID, playerActID, state), playerID)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrowupBuyID, actID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrowupBuyState, 0)
    
    Sync_GrowupActionInfo(curPlayer)
    return True
 
def DoUpdateGrowupBuyStateOnDay(curPlayer):
    ## ³É³¤±ØÂò¹ýÌì¸üйºÂò״̬
    
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})
    if not actInfo:
        return
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActGrowupBuy", cfgID)
    if not ipyData:
        return
    ctgIDGroupList = ipyData.GetCTGIDGroupList()
    
    buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyState)
    GameWorld.DebugLog("¸üгɳ¤±ØÂò½ñÈտɹºÂòÀñ°üË÷Òý! buyState=%s,ctgIDGroupList=%s" % (buyState, ctgIDGroupList))
    
    for i, ctgIDList in enumerate(ctgIDGroupList):
        
        buyIndex = GameWorld.GetDataByDigitPlace(buyState, i)
        updBuyIndex = 0
        yestodayCtgID = ctgIDList[buyIndex]
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCount % yestodayCtgID):
            updBuyIndex = 0
            GameWorld.DebugLog("    ×òÈÕÀñ°üûÂò£¬ÖØÖã¡yestodayCtgID=%s" % yestodayCtgID)
        else:
            if buyIndex >= len(ctgIDList) - 1:
                updBuyIndex = len(ctgIDList) - 1
                GameWorld.DebugLog("    ×òÈÕÀñ°üÒÑÂò£¬×îºóÒ»µµÀñ°ü±£³Ö²»±ä£¡ yestodayCtgID=%s,updBuyIndex=%s" % (yestodayCtgID, updBuyIndex))
            else:
                updBuyIndex = buyIndex + 1
                GameWorld.DebugLog("    ×òÈÕÀñ°üÒÑÂò£¬¸üкóÐøÀñ°üË÷Òý£¡ yestodayCtgID=%s,updBuyIndex=%s" % (yestodayCtgID, updBuyIndex))
                
        buyState = GameWorld.ChangeDataByDigitPlace(buyState, i, updBuyIndex)
        GameWorld.DebugLog("    updState=%s" % buyState)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GrowupBuyState, buyState)
    Sync_GrowupActionInfo(curPlayer)
    return
 
def CheckGrowupBuyState(curPlayer, ctgID):
    ## ¼ì²éÊÇ·ñ¿É¹ºÂò³É³¤±ØÂòÀñ°üID
    # @return: ÊÇ·ñ¿ÉÂò, ²»¿ÉÂòÔ­Òò˵Ã÷
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})
    if not actInfo:
        return False, "not grow up buy action info!"
    if not actInfo.get(ShareDefine.ActKey_State):
        return False, "grow up buy action state is 0!"
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActGrowupBuy", cfgID)
    if not ipyData:
        return False, "not grow up buy action ipyData cfgID(%s)!" % cfgID
    ctgIDGroupList = ipyData.GetCTGIDGroupList()
    buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyState)
    curCTGIDList = []
    playerBuyIndex = -1
    for i, ctgIDList in enumerate(ctgIDGroupList):
        if ctgID in ctgIDList:
            curCTGIDList = ctgIDList
            playerBuyIndex = GameWorld.GetDataByDigitPlace(buyState, i)
            break
    if not curCTGIDList:
        return False, "ctgID(%s) is not in this grow up buy action ctgIDGroupList(%s)!" % (ctgID, ctgIDGroupList)
    ctgIDIndex = curCTGIDList.index(ctgID)
    if playerBuyIndex != ctgIDIndex:
        return False, "ctgIDIndex(%s) is not equal to playerBuyIndex(%s) !" % (ctgIDIndex, playerBuyIndex)
    
    return True, ""
 
def Sync_GrowupActionInfo(curPlayer):
    ## Í¨Öª»î¶¯ÐÅÏ¢  - ³É³¤±ØÂò
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_GrowupBuy, {})
    if not actInfo:
        return
    
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    
    ipyData = IpyGameDataPY.GetIpyGameData("ActGrowupBuy", cfgID)
    if not ipyData:
        return
    ctgIDGroupList = ipyData.GetCTGIDGroupList()
    if not ctgIDGroupList:
        return
    
    import PlayerCoin
    buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GrowupBuyState)
    
    startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
    actPack = ChPyNetSendPack.tagMCActGrowupBuyInfo()
    actPack.StartDate = startDateStr
    actPack.EndtDate = endDateStr
    actPack.LimitLV = ipyData.GetLVLimit()
    actPack.GroupList = []
    for i, ctgIDList in enumerate(ctgIDGroupList):
        groupInfo = ChPyNetSendPack.tagMCActGrowupBuyGroup()
        groupInfo.BuyCTGIDList = []
        for ctgID in ctgIDList:
            ctgIpyData = IpyGameDataPY.GetIpyGameData("CTG", ctgID)
            ctgGiveItemList = PlayerCoin.GetCTGGiveItemList(ctgIpyData)
            ctgInfo = ChPyNetSendPack.tagMCActGrowupBuyCTGInfo()
            ctgInfo.CTGID = ctgID
            ctgInfo.GainItemList = []
            for itemID, itemCount, isAuctionItem in ctgGiveItemList:
                ctgItem = ChPyNetSendPack.tagMCActGrowupBuyCTGItem()
                ctgItem.ItemID = itemID
                ctgItem.ItemCount = itemCount
                ctgItem.IsBind = isAuctionItem
                ctgInfo.GainItemList.append(ctgItem)
            ctgInfo.GainItemCount = len(ctgInfo.GainItemList)
            groupInfo.BuyCTGIDList.append(ctgInfo)
        groupInfo.BuyCount = len(groupInfo.BuyCTGIDList)
        groupInfo.PlayerBuyIndex = GameWorld.GetDataByDigitPlace(buyState, i)
        actPack.GroupList.append(groupInfo)
    actPack.GroupCount = len(actPack.GroupList)
    NetPackCommon.SendFakePack(curPlayer, actPack)
    return