hxp
2 天以前 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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActRechargeRebateGold
#
# @todo:ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯
# @author hxp
# @date 2020-10-15
# @version 1.0
#
# ÏêϸÃèÊö: ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯£¨»î¶¯½áÊøÓʼþ·¢·Å£¬Ö»Ëã×î¸ßÒ»µµ£©
#
#-------------------------------------------------------------------------------
#"""Version = 2020-10-15 12:00"""
#-------------------------------------------------------------------------------
 
import ChConfig
import ShareDefine
import PlayerControl
import PyGameData
import GameWorld
import NetPackCommon
import ChPyNetSendPack
import IpyGameDataPY
 
def OnPlayerLogin(curPlayer):
    isReset = __CheckPlayerRechargeRebateGoldAction(curPlayer)
    if not isReset:
        actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if actInfo.get(ShareDefine.ActKey_State):
            Sync_RechargeRebateGoldActionInfo(curPlayer)
            Sync_RechargeRebateGoldPlayerInfo(curPlayer)
    return
 
def RefreshRechargeRebateGoldActionInfo():
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckPlayerRechargeRebateGoldAction(curPlayer)
    return
 
def __CheckPlayerRechargeRebateGoldAction(curPlayer):
    ## ¼ì²éÍæ¼ÒÀۼƳäÖµ»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldID) # Íæ¼ÒÉíÉϵĻID
    templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))
    playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldTemplateID)
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯ID²»±ä£¬²»´¦Àí£¡", playerID)
        if state:
            if playerTemplateID != templateID and templateID:
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldTemplateID, templateID)
                GameWorld.DebugLog("    »î¶¯Ä£°åID±ä¸ü£¬¸üÐÂÍæ¼ÒÉíÉÏÄ£°åID¼Ç¼£¡playerTemplateID=%s,updTemplateID=%s" 
                                   % (playerTemplateID, templateID), playerID)
        return
    
    GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯ÖØÖÃ! actID=%s,playerActID=%s,state=%s" % (actID, playerActID, state), playerID)
    
    totalRMB = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldRMB)
    if playerActID and playerTemplateID and totalRMB > 0:
        __SendRebateGoldMail(curPlayer, playerTemplateID, totalRMB)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldID, actID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldTemplateID, templateID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldRMB, 0)
    
    Sync_RechargeRebateGoldActionInfo(curPlayer)
    Sync_RechargeRebateGoldPlayerInfo(curPlayer)
    return True
 
def GetTemplateID(cfgID, dayIndex):
    if cfgID == None or dayIndex == None:
        return 0
    ipyData = IpyGameDataPY.GetIpyGameData("ActRechargeRebateGold", cfgID)        
    if not ipyData:
        return 0
    templateIDList = ipyData.GetTemplateIDList()
    templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex]
    return templateID
 
def __SendRebateGoldMail(curPlayer, playerTemplateID, totalRMB):
    ## ·¢ËÍ·µÀû½±ÀøÓʼþ£¬È¡×î´ó½±Àøµµ·¢½±Àø
    
    playerID = curPlayer.GetPlayerID()
    GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ·¢Ëͽ±ÀøÓʼþ! playerTemplateID=%s,totalRMB=%s" % (playerTemplateID, totalRMB), playerID)
    
    ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargeRebateGoldTemplate", playerTemplateID)
    if not ipyDataList:
        return
    
    rebateIpyData = None
    for ipyData in ipyDataList:
        rmbMin = ipyData.GetRMBMin()
        rmbMax = ipyData.GetRMBMax()
        if (rmbMin <= totalRMB <= rmbMax) or (rmbMin <= totalRMB and rmbMax == 0):
            rebateIpyData = ipyData
            break
        
    if not rebateIpyData:
        GameWorld.DebugLog("Íæ¼ÒÎÞ·µÀûÏÉÓñ½±Àø!", playerID)
        return
    
    rebateRate = rebateIpyData.GetRebateRate()
    addItemList = []
    paramList = [totalRMB, rebateRate]
    gold = min(int(totalRMB * rebateRate / 100.0), ShareDefine.Def_UpperLimit_DWord)
    GameWorld.DebugLog("    ·µÀûÏÉÓñ°Ù·Ö±È=%s%%, gold=%s" % (rebateRate, gold), playerID)
    PlayerControl.SendMailByKey("RechargeRebateGold", [playerID], addItemList, paramList, gold)
    return
 
def AddRechargeRebateGoldRMB(curPlayer, addRMB):
    ## Ôö¼Ó»î¶¯ÒÑÀۼƳäÖµRMB£¬ Ö÷¸É·ÖÖ§¼Ç¼µÄÊÇÏÉÓñ£¬Ö»ËãÖ±³ä£¬Ö÷¸ÉûÓÐRMB¶ÔÓ¦±ÈÀýÅäÖã¬Ö±½Ó¼Ç¼ÏÉÓñ
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})    
    if not actInfo:
        return
    
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    totalRMB = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldRMB) + addRMB
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldRMB, totalRMB)
    
    GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯Ôö¼ÓÍæ¼ÒÀۼƳäÖµRMB: addRMB=%s,totalRMB=%s" % (addRMB, totalRMB), curPlayer.GetPlayerID())
    Sync_RechargeRebateGoldPlayerInfo(curPlayer)
    return
 
 
def Sync_RechargeRebateGoldPlayerInfo(curPlayer):
    ## Í¨ÖªÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯Íæ¼ÒÊý¾ÝÐÅÏ¢
    playerActInfo = ChPyNetSendPack.tagMCRechargeRebateGoldPlayerInfo()
    playerActInfo.RechargeRMBTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldRMB)
    NetPackCommon.SendFakePack(curPlayer, playerActInfo)
    return
 
def Sync_RechargeRebateGoldActionInfo(curPlayer):
    ## Í¨ÖªÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯ÐÅÏ¢
    
    actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})    
    if not actInfo:
        return
    
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActRechargeRebateGold", cfgID)
    if not ipyData:
        return
    
    templateIDList = ipyData.GetTemplateIDList()
    if not templateIDList:
        return
    
    startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
    actInfo = ChPyNetSendPack.tagMCActRechargeRebateGoldInfo()
    actInfo.StartDate = startDateStr
    actInfo.EndtDate = endDateStr
    actInfo.LimitLV = ipyData.GetLVLimit()
    actInfo.IsDayReset = ipyData.GetIsDayReset()
    actInfo.RebateDayInfo = []
    for templateID in templateIDList:
        ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargeRebateGoldTemplate", templateID)
        if not ipyDataList:
            continue
        
        dayInfo = ChPyNetSendPack.tagMCActRechargeRebateDay()
        dayInfo.RebateInfo = []
        for dayIpyData in ipyDataList:
            rebateInfo = ChPyNetSendPack.tagMCActRechargeRebate()
            rebateInfo.RMBMin = dayIpyData.GetRMBMin()
            rebateInfo.RMBMax = dayIpyData.GetRMBMax()
            rebateInfo.RebateRate = dayIpyData.GetRebateRate()
            dayInfo.RebateInfo.append(rebateInfo)
            
        dayInfo.Rebates = len(dayInfo.RebateInfo)
        actInfo.RebateDayInfo.append(dayInfo)
        
    actInfo.RebateDays = len(actInfo.RebateDayInfo)
    NetPackCommon.SendFakePack(curPlayer, actInfo)
    return