xdh
2019-01-14 e7e1e93c2d2237f5fdcb94e4053e7c7584dbc7bf
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#
#---------------------------------------------------------------------
##@package PlayerFamilyRedPacket
# @todo: Íæ¼Ò¼Ò×åºì°ü
#
# @author: xdh
# @date 2017-08-31
# @version 1.0
#
#---------------------------------------------------------------------
#"""Version = 2017-08-31 16:00"""
#---------------------------------------------------------------------
import GameWorld
import PlayerControl
import ChConfig
import IpyGameDataPY
import IPY_GameWorld
import ChPyNetSendPack
import NetPackCommon
import PlayerVip
import ShareDefine
 
import time
#---------------------------------------------------------------------
 
Def_GoldPacket = 0 #Ö÷¶¯·¢×êʯºì°ü
 
 
(
State_NoSend, #δ·¢
State_NoGot, #δÁìÈ¡
State_HasGot, #ÒÑÁìÈ¡
State_HasAllGot, #È«²¿ÁìÍê
) = range(4)
 
 
## Íæ¼ÒµÇ¼
def OnPlayerLogin(curPlayer):
    __NotifyGoldLimt(curPlayer)
    NotifyOSRedPacket(curPlayer)
    return
 
## OnDay´¦Àí
#  @param curPlayer
#  @return None
def RedPacketOnDay(curPlayer, onEventType):
    if onEventType == ShareDefine.Def_OnEventType:
        #·¢×êʯºì°ü¶î¶ÈÖØÖÃ
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyRedPacketGoldLimit, 0)
        __NotifyGoldLimt(curPlayer)
    elif onEventType == ShareDefine.Def_OnEventTypeEx:
        oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg')
        openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)
        if openServerDay < oscDay:
            grabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0)
            sendCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 5)
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketCanGrabCnt, grabCnt+sendCnt)
            NotifyOSRedPacket(curPlayer)
    return
 
def CreatCacheRedPacktet(curPlayer):
    #¼ÓÈëÏÉÃ˺󣬷¢·Å´ý·¢µÄºì°ü
    ipyMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyMgr.GetFamilyRedPackCount()):
        ipyData = ipyMgr.GetFamilyRedPackByIndex(i)
        redPacketID = ipyData.GetID()
        if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_FamilyRedPacketCache, redPacketID):
            CreatRedPacketByID(curPlayer, redPacketID)
            GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_FamilyRedPacketCache, redPacketID, 0)
    return
 
 
def CreatRedPacketByID(curPlayer, redPacketID, state=State_NoSend, data=0):
    #¸ù¾Ýºì°üIDÉú³Éºì°ü
    ipyData = IpyGameDataPY.GetIpyGameData('FamilyRedPack', redPacketID)
    if not ipyData:
        return
    getType = ipyData.GetGetType()
    if getType == IpyGameDataPY.GetFuncCfg('OpenServerRedPacketType'):
        oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg')
        openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)
        if openServerDay >= oscDay:
            GameWorld.DebugLog('    ·¢¿ª·þºì°ü,»î¶¯Òѹý£¬²»¿É·¢ËÍ£¡')
            return
    else:
        if not curPlayer.GetFamilyID():
            #û¼Ò×å ÏÈ´æÆðÀ´£¬µÈ½øÏÉÃËʱÔÙ²¹·¢
            GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_FamilyRedPacketCache, redPacketID, 1)
            return
    
    DoCreatFamilyRedPacket(curPlayer, getType, ipyData.GetMoneyType(), ipyData.GetMoneyNum(), ipyData.GetPacketCnt(), state, '', data)
    return
 
## Éú³Éºì°ü
def DoCreatFamilyRedPacket(curPlayer, getType, moneyType=2, awardNum=100, packetCnt=10, state=State_NoSend, wishInfo='', data=0):
 
        
    
    playerID = curPlayer.GetPlayerID()
    packetCnt = min(packetCnt, awardNum)
    
    if getType == Def_GoldPacket:
        goldLimit = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyRedPacketGoldLimit, 0)
        familyRedPacketGoldLimit = IpyGameDataPY.GetFuncCfg('FamilyRedPacketGoldLimit')
        if awardNum + goldLimit > familyRedPacketGoldLimit:
            GameWorld.DebugLog('    Ö÷¶¯·¢ÏÉÃË×êʯºì°ü£¬¶î¶ÈÒѳ¬%s,²»¿É·¢ËÍ£¡' % familyRedPacketGoldLimit, playerID)
            return
        if not PlayerControl.HaveMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney, awardNum):
            curBourseMoney = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney)
            GameWorld.Log(" ²»ÄÜ·¢×êʯºì°ü no enough bourse money! priceCount=%s,curBourseMoney=%s" 
                              % (awardNum, curBourseMoney), playerID)
            return
        if not PlayerControl.PayMoney(curPlayer, moneyType, awardNum, ChConfig.Def_Cost_FamilyRedPacket):
            return
        
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyRedPacketGoldLimit, goldLimit + awardNum)
        #֪ͨ
        __NotifyGoldLimt(curPlayer)
#    else:
#        commonCntLimit = IpyGameDataPY.GetFuncCfg('FamilyRedPacketCnt')
#        if packetCnt < commonCntLimit:
#            GameWorld.DebugLog('    ·¢ÆÕͨÏÉÃ˺ì°ü£¬ÊýÁ¿²»ÄÜÉÙÓÚ%s£¡' % commonCntLimit, playerID)
#            return
        
    #֪ͨGameserverÉú³Éºì°ü
    msg = str([playerID, getType, packetCnt, moneyType, awardNum, wishInfo, state, data])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "CreatFamilyRedPacket", msg, len(msg))
    GameWorld.DebugLog('    DoCreatFamilyRedPacket Í¨ÖªGameserverÉú³Éºì°ü msg=%s' % msg)
    return
 
 
#// A6 08 ·¢¼Ò×åºì°ü #tagCMSendFamilyRedPacket
#
#struct     tagCMSendFamilyRedPacket
#{
#    tagHead        Head;
#    DWORD        RedPacketID;    // ºì°üID,ûÓз¢0
#    WORD        PacketCnt;    // ºì°üÊýÁ¿
#    WORD        MoneyNum;    //½ðÇ®ÊýÁ¿
#    WORD        WishLen;            //×£¸£Óﳤ¶È
#    char        Wish[NameLen];        //size=WishLen
#};
## ·¢¼Ò×åºì°ü
def OnSendFamilyRedPacket(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    redPacketID = clientData.RedPacketID
    packetCnt = clientData.PacketCnt
    moneyNum = clientData.MoneyNum
    wishInfo = clientData.Wish
    if not redPacketID:
        #Ö÷¶¯·¢µÄ×êʯºì°ü vipÏÞÖÆ
        if not PlayerVip.GetPrivilegeValue(curPlayer, ChConfig.VIPPrivilege_FamilyGoldPack):
            GameWorld.DebugLog("Ö÷¶¯·¢µÄ×êʯºì°ü VIPȨÏÞ²»×ã")
            return
        DoCreatFamilyRedPacket(curPlayer, Def_GoldPacket, IPY_GameWorld.TYPE_Price_Gold_Money, moneyNum, packetCnt, State_NoGot, wishInfo)
    else:
        msg = str([curPlayer.GetPlayerID(), redPacketID, packetCnt])
        GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "SendFamilyRedPacket", msg, len(msg))
    return
 
 
 
## Í¨ÖªÇÀºì°ü×êʯ¶î¶È
def __NotifyGoldLimt(curPlayer):
    packData = ChPyNetSendPack.tagMCFamilyRedPacketGoldLimit()
    packData.Clear()
    packData.HasSendGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyRedPacketGoldLimit, 0)
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
## Í¨ÖªÇÀºì°ü´ÎÊý
def NotifyOSRedPacket(curPlayer):
    packData = ChPyNetSendPack.tagMCOpenServerRedPacketInfo()
    packData.Clear()
    packData.MoneyNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketGrabMoney, 0)
    packData.GrabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0)
    startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketStartTime, 0)
    if not startTime:
        createRoleTime = curPlayer.GetCreateRoleTime()
        startTime = GameWorld.ChangeTimeStrToNum(createRoleTime)
    packData.StartTime = startTime
    
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
 
#// A4 04 ÇÀ¼Ò×åºì°ü #tagCGGrabFamilyRedPacket
#
#struct    tagCGGrabFamilyRedPacket
#{
#    tagHead        Head;
#    DWORD        RedPaketID;         // ºì°üID
#};
## ÇÀºì°ü
def OnGrabFamilyRedPacket(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    redPacketID = clientData.RedPaketID
    OSCanGrabCnt = GetOSCanGrabCnt(curPlayer)
    msg = str([redPacketID, OSCanGrabCnt])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "GrabFamilyRedPacket", msg, len(msg))
    GameWorld.DebugLog('    ÇÀºì°ü OSCanGrabCnt=%s'%OSCanGrabCnt)
    return
 
 
def GetOSCanGrabCnt(curPlayer):
    #»ñÈ¡¿ª·þºì°ü¿ÉÇÀ´ÎÊý
#    oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg')
#    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)
#    if openServerDay >= oscDay:
#        return 0
    #curGrabCnt = 
    return curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0)
#    createRoleTime = curPlayer.GetCreateRoleTime()
#    createRoleTimeNum = GameWorld.ChangeTimeStrToNum(createRoleTime)
#    curTime = int(time.time())
#    rangeTime = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 3)
#    initCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 2)
#    return (curTime - createRoleTimeNum)/rangeTime + initCnt - curGrabCnt
    
def GrabOSRedPacketResult(curPlayer, moneyNum, isSelf):
    ##ÇÀ¿ª·þºì°ü½á¹û
    grabNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketGrabMoney, 0)
    newGrabNum = grabNum+moneyNum
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketGrabMoney, newGrabNum)
    #¹ã²¥
    needSysOSRAllMoneyList = IpyGameDataPY.GetFuncEvalCfg('OSRAllMoneySys')
    lastIndex = -1
    newIndex = -1
    for i, num in enumerate(needSysOSRAllMoneyList):
        if grabNum >= num:
            lastIndex = i
        if newGrabNum >= num:
            newIndex = i
    if newIndex != -1 and newIndex > lastIndex:
        PlayerControl.WorldNotify(0, 'OpenRedBag1', [curPlayer.GetName(), newGrabNum])
    
    if not isSelf: #ÇÀ×Ô¼ºµÄºì°ü²»¿Û´ÎÊý
        grabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketCanGrabCnt, max(0, grabCnt-1))
#        if grabCnt == IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 4):
#            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketStartTime, int(time.time()))
    
    
    #֪ͨ
    NotifyOSRedPacket(curPlayer)
    return
 
def ProcessOSRedPacket(curPlayer, tick):
    return
    #¿ª·þºì°ü»Ö¸´´ÎÊý
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_OSRedPacket, tick):
        return
    oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg')
    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)
    if openServerDay >= oscDay:
        return
    grabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0)
    limitCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 4)
    if grabCnt >= limitCnt:
        return
    startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketStartTime, 0)
    if not startTime:
        newCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 2)
        createRoleTime = curPlayer.GetCreateRoleTime()
        curTime = GameWorld.ChangeTimeStrToNum(createRoleTime)
    else:
        curTime = int(time.time())
        passTime = curTime - startTime
        rangeTime = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 3)
        addCnt = passTime / rangeTime
        if addCnt <= 0:#·ÀÖ¹²âÊÔµ÷ʱ¼äµ¼ÖÂÒì³£
            return
        newCnt = min(limitCnt, grabCnt+addCnt)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketCanGrabCnt, newCnt)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketStartTime, curTime)
    NotifyOSRedPacket(curPlayer)
    return