hxp
3 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
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
#!/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 PlayerFeastRedPacket
import NetPackCommon
import PlayerVip
import ShareDefine
import CommFunc
 
#---------------------------------------------------------------------
 
(
State_NoSend, #δ·¢
State_NoGot, #δÁìÈ¡
State_HasGot, #ÒÑÁìÈ¡
State_HasAllGot, #È«²¿ÁìÍê
) = range(4)
 
 
## Íæ¼ÒµÇ¼
def OnPlayerLogin(curPlayer):
    __NotifyGoldLimt(curPlayer)
    return
 
## OnDay´¦Àí
#  @param curPlayer
#  @return None
def RedPacketOnDay(curPlayer, onEventType):
    if onEventType == ShareDefine.Def_OnEventType:
        #·¢×êʯºì°ü¶î¶ÈÖØÖÃ
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyRedPacketGoldLimit):
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyRedPacketGoldLimit, 0)
            __NotifyGoldLimt(curPlayer)
            
    elif onEventType == ShareDefine.Def_OnEventTypeEx:
        pass
    
    return
 
def GetRedPackGetWayType(getWay):
    ## »ñÈ¡ºì°ügetWayËùÊôºì°ü·ÖÀà
    getWayTypeDict = IpyGameDataPY.GetFuncEvalCfg("RedPacketClassify", 1, {})
    for getWayType, getWayList in getWayTypeDict.items():
        if getWay in getWayList:
            return getWayType
    return ShareDefine.RedPackWayType_Family
 
def OnPlayerRecharge(curPlayer, orderCoin):
    ## Íæ¼Ò³äÖµ
    
    todayCoin = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TodayCTGCoinTotal)
    # Ã¿ÈÕÊ׳äºì°ü
    if todayCoin - orderCoin == 0:
        dayFirstRedPacketID = IpyGameDataPY.GetFuncCfg("RechargeRedPacket", 1)
        GameWorld.DebugLog("ÿÈÕÊ׳äºì°ü: dayFirstRedPacketID=%s" % dayFirstRedPacketID)
        if dayFirstRedPacketID:
            CreatRedPacketByID(curPlayer, dayFirstRedPacketID)
    #else:
    #    GameWorld.DebugLog("·ÇÿÈÕÊ׳ä: todayCoin=%s" % todayCoin)
        
    # µ¥±Ê³äÖµºì°ü
    rmbRedPacketID = 0
    rmbRedPackIDDict = IpyGameDataPY.GetFuncEvalCfg("RechargeRedPacket", 2, {})
    rmbList = rmbRedPackIDDict.keys()
    rmbList.sort()
    for rmb in rmbList:
        if orderCoin <= CommFunc.RMBToCoin(rmb):
            rmbRedPacketID = rmbRedPackIDDict[rmb]
            break
        
    if rmbRedPacketID:
        GameWorld.DebugLog("µ¥±Ê³äÖµºì°ü: orderRMB=%s,rmbRedPacketID=%s" % (orderCoin, rmbRedPacketID))
        CreatRedPacketByID(curPlayer, rmbRedPacketID)
    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, wishInfo=""):
    '''¸ù¾Ýºì°üIDÉú³Éºì°ü - Íⲿ¹¦Äܵ÷ÓýӿÚ
    '''
    ipyData = IpyGameDataPY.GetIpyGameData('FamilyRedPack', redPacketID)
    if not ipyData:
        return
    getType = ipyData.GetGetType()
    if not getType:
        return
    isFamilyRedPacket = False
    getWayType = GetRedPackGetWayType(getType)
    if getWayType == ShareDefine.RedPackWayType_Feast:
        if not PlayerFeastRedPacket.GetFeastRedPacketState():
            GameWorld.DebugLog('    ·Ç½ÚÈÕºì°ü»î¶¯ÖУ¬²»¿É·¢ËÍ£¡')
            return
    elif getWayType == ShareDefine.RedPackWayType_Server:
        pass
    else:
        if not curPlayer.GetFamilyID():
            #û¼Ò×å ÏÈ´æÆðÀ´£¬µÈ½øÏÉÃËʱÔÙ²¹·¢
            GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_FamilyRedPacketCache, redPacketID, 1)
            return
        isFamilyRedPacket = True
        
    return __DoCreatRedPacket(curPlayer, getType, ipyData.GetMoneyType(), ipyData.GetMoneyNum(), ipyData.GetPacketCnt(), state, wishInfo, data, isFamilyRedPacket)
 
## Éú³Éºì°ü£¬×¢ÒâÍⲿ²»¿ÉÖ±½Óµ÷Óøú¯Êý
def __DoCreatRedPacket(curPlayer, getType, moneyType=2, awardNum=100, packetCnt=10, state=State_NoSend, wishInfo='', data=0, isFamilyRedPacket=True):
    playerID = curPlayer.GetPlayerID()
    packetCnt = min(packetCnt, awardNum)
    
    if isFamilyRedPacket and not curPlayer.GetFamilyID():
        GameWorld.DebugLog("Íæ¼ÒÎÞÏÉÃË£¬ÎÞ·¨·¢·Å¹éÊôÏÉÃ˵ĺì°ü!getType=%s" % (getType), playerID)
        return
    
    if getType == ShareDefine.RedPackType_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)
        
    #֪ͨGameserverÉú³Éºì°ü
    msg = str([playerID, getType, packetCnt, moneyType, awardNum, wishInfo, state, data, isFamilyRedPacket])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "MapServer_CreatRedPacket", msg, len(msg))
    GameWorld.DebugLog('    Í¨ÖªGameserverÉú³Éºì°ü msg=%s' % msg)
    return True
 
#// A6 08  ·¢¼Ò×åºì°ü #tagCMSendFamilyRedPacket
#
#struct     tagCMSendFamilyRedPacket
#{
#    tagHead        Head;
#    DWORD        RedPacketID;    // ºì°üID,ûÓз¢0
#    WORD        PacketCnt;    // ºì°üÊýÁ¿
#    WORD        MoneyNum;    //½ðÇ®ÊýÁ¿
#    char        Wish[33];        //×£¸£Óï
#    BYTE        IsAnonymous;    //ÊÇ·ñÄäÃû
#};
## ·¢¼Ò×åºì°ü
def OnSendFamilyRedPacket(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    redPacketID = clientData.RedPacketID
    packetCnt = clientData.PacketCnt
    moneyNum = clientData.MoneyNum
    wishInfo = clientData.Wish
    isAnonymous = clientData.IsAnonymous
    if not redPacketID:
        #Ö÷¶¯·¢µÄ×êʯºì°ü vipÏÞÖÆ
        if not PlayerVip.GetPrivilegeValue(curPlayer, ChConfig.VIPPrivilege_FamilyGoldPack):
            GameWorld.DebugLog("Ö÷¶¯·¢µÄ×êʯºì°ü VIPȨÏÞ²»×ã")
            return
        __DoCreatRedPacket(curPlayer, ShareDefine.RedPackType_GoldPacket, IPY_GameWorld.TYPE_Price_Gold_Money, moneyNum, packetCnt, State_NoGot, wishInfo)
    else:
        # ×¢Ò⣺¸Ãº¯Êý·¢·ÅµÄÊÇÒÑ´´½¨µÄºì°ü£¬¸Ã²Ù×÷Ö»ÊǰѸúì°ü¿ª·Å¸øÍæ¼Ò¿ÉÇÀ
        msg = str([curPlayer.GetPlayerID(), redPacketID, packetCnt, isAnonymous])
        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)
    packData.ServerGrabCnt = 0
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
#// AB 12 ÇÀºì°ü #tagCMGrabFamilyRedPacket
#
#struct    tagCMGrabFamilyRedPacket
#{
#    tagHead        Head;
#    DWORD        RedPaketID;         // ºì°üID
#    BYTE        GetWay;            //»ñµÃ;¾¶
#};
def OnGrabFamilyRedPacket(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    redPacketID = clientData.RedPaketID
    reqGetWay = clientData.GetWay
    if reqGetWay == ShareDefine.RedPackType_FeastSucc:
        canGrabCnt = PlayerFeastRedPacket.GetFeastSuccRedPacketCanGrabCnt(curPlayer)
    else:
        canGrabCnt = -1
    msg = str([redPacketID, reqGetWay, canGrabCnt])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "GrabFamilyRedPacket", msg, len(msg))
    GameWorld.DebugLog('    ÇÀºì°ü redPacketID=%s,getWay=%s,canGrabCnt=%s' % (redPacketID, reqGetWay, canGrabCnt))
    return
 
def GrabServerRedPacketResult(curPlayer, moneyNum, isSelf):
    ##ÇÀÈ«·þºì°ü½á¹û
    return