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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package PlayerStore
#
# @todo:É̳Ç
# @author xdh
# @date 2018-10-09
# @version 1.0
#
#
# ÏêϸÃèÊö: É̳ÇÈ«·þÏÞ¹º´¦Àí
#
#---------------------------------------------------------------------
"""Version = 2018-10-09 17:00"""
 
import GameWorld
import ShareDefine
import PlayerControl
import IpyGameDataPY
import ChPyNetSendPack
import NetPackCommon
 
RecType = ShareDefine.Def_UniversalGameRecType_StoreServerCntRecord
 
## Íæ¼ÒµÇ¼
#  @param None
#  @return None
def OnPlayerLogin(curPlayer):
    SyncStoreServerBuyInfo(curPlayer)
    return
 
 
## É̳ÇÈ«·þÏÞ¹º²éѯ½á¹û
#  @param curPlayer Íæ¼ÒʵÀý
#  @param msgList ÐÅÏ¢Áбí
#  @return awardID
def DoStoreServerBuyQueryResult(curPlayer, msgList):
    goodsID = msgList[0]
    serverLimitCnt = msgList[1]
    buyCount = msgList[2]
    
    curGotCnt = 0
    
    universalRecMgr = GameWorld.GetUniversalRecMgr()
    recTypeListData = universalRecMgr.GetTypeList(RecType)
    findRecData = None 
    for index in range(recTypeListData.Count()):
        recData = recTypeListData.At(index)
        curGoodsID = recData.GetValue1()
        if goodsID == curGoodsID:
            findRecData = recData
            curGotCnt = recData.GetValue2()
            break
    
    if curGotCnt + buyCount > serverLimitCnt:
        GameWorld.Log('    ¹ºÂòÉÌÆ· È«·þ¹ºÂò´ÎÊý²»¹» goodsID=%s,curGotCnt=%s,buyCount=%s,serverLimitCnt=%s'%(goodsID, curGotCnt, buyCount, serverLimitCnt))
        return
    if not findRecData:
        findRecData = recTypeListData.AddRec()
        findRecData.SetValue1(goodsID)
    newBuyCnt = curGotCnt+buyCount
    findRecData.SetValue2(newBuyCnt)
    #֪ͨ
    SyncStoreServerBuyInfo(None, {goodsID:newBuyCnt})
    return msgList
 
def DoResetStoreServerBuyCnt(shopTypeList):
    '''¸ù¾ÝÉ̵êÀàÐÍÖØÖÃÈ«·þ¹ºÂò´ÎÊý'''
    universalRecMgr = GameWorld.GetUniversalRecMgr()
    recTypeListData = universalRecMgr.GetTypeList(RecType)
    
    delCnt = 0
    syncDict = {}
    for index in xrange(recTypeListData.Count()):
        dataIndex = index - delCnt
        recData = recTypeListData.At(dataIndex)
        curGoodsID = recData.GetValue1()
        ipyData = IpyGameDataPY.GetIpyGameData("Store", curGoodsID)
        if not ipyData:
            continue
        if ipyData.GetShopType() not in shopTypeList:
            continue
        syncDict[curGoodsID] = 0
        recTypeListData.Delete(dataIndex)
        delCnt +=1
        
    GameWorld.DebugLog('    ¸ù¾ÝÉ̵êÀàÐÍÖØÖÃÈ«·þ¹ºÂò´ÎÊý shopTypeList=%s'%shopTypeList)
    if delCnt:
        SyncStoreServerBuyInfo(None, syncDict)
        
    return
 
 
def ResetFlashSaleBuyCnt(ipyData):
    #ÖØÖÃÏÞʱÇÀ¹ºÉ̵êÈ«·þ¹ºÂò´ÎÊý
    dayShopRangeDict = ipyData.GetShopTypeList()
    
    resetTypeList = []
    for shopTypeList in dayShopRangeDict.values():
        for dayShopList in shopTypeList:
            for shopType in dayShopList:
                if shopType not in resetTypeList:
                    resetTypeList.append(shopType)
    if resetTypeList:
        DoResetStoreServerBuyCnt(resetTypeList)
    return
 
def SyncStoreServerBuyInfo(curPlayer, syncCntDict={}):
    #֪ͨÉÌÆ·È«·þ¹ºÂò´ÎÊý
    sendPack = ChPyNetSendPack.tagGCStoreServerBuyCntInfo()
    sendPack.Clear()
    sendPack.InfoList = []
    if syncCntDict:
        for goodsID, buyCnt in syncCntDict.items():
            buyInfo = ChPyNetSendPack.tagGCStoreServerBuyCnt()
            buyInfo.GoodsID = goodsID
            buyInfo.BuyCnt = buyCnt
            sendPack.InfoList.append(buyInfo)
    else:
        universalRecMgr = GameWorld.GetUniversalRecMgr()
        recTypeListData = universalRecMgr.GetTypeList(RecType)
        for index in xrange(recTypeListData.Count()):
            recData = recTypeListData.At(index)
            buyInfo = ChPyNetSendPack.tagGCStoreServerBuyCnt()
            buyInfo.GoodsID = recData.GetValue1()
            buyInfo.BuyCnt = recData.GetValue2()
            sendPack.InfoList.append(buyInfo)
    sendPack.Count = len(sendPack.InfoList)
    if not curPlayer:
        playerManager = GameWorld.GetPlayerManager()
        for i in xrange(playerManager.GetActivePlayerCount()):
            curPlayer = playerManager.GetActivePlayerAt(i)
            if curPlayer == None or not curPlayer.GetInitOK():
                continue
            if PlayerControl.GetIsTJG(curPlayer):
                continue
            NetPackCommon.SendFakePack(curPlayer, sendPack)
    else:
        if PlayerControl.GetIsTJG(curPlayer):
            return
        NetPackCommon.SendFakePack(curPlayer, sendPack)
    return