xdh
2019-01-28 c060aabfb4621e897f7b69d6e537fc3ccf59d860
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package GameWorldActionTeHui
#
# @todo:ÌØ»Ý»î¶¯
# @author hxp
# @date 2014-06-21
# @version 1.7
#
# @change: "2014-09-28 17:30" hxp Ôö¼Ó³äÖµÅÅÐл´¦Àí
# @change: "2014-10-11 12:30" hxp ÐÞ¸´³äÖµÅÅÐн±ÀøÖ»ÄܸøÇ°Á½ÃûµÄbug
# @change: "2014-12-06 16:30" hxp Ôö¼ÓºÏ·þÕÛ¿ÛµêÖ§³Ö£¬Ôö¼ÓGMÖØÖÃÌØ»Ý»î¶¯Êý¾Ý(·½±ã²âÊÔ)
# @change: "2014-12-11 22:00" hxp ÐÞ¸Äͬ²½µØÍ¼ÕÛ¿Û״̬Âß¼­(È¡²»µ½ÖµÊ±²ÅȡͨÓüǼÖеÄÖµ)
# @change: "2015-08-21 14:30" hxp Ôö¼Ó¼Ç¼ÉÏÒ»ÆÚ³äÖµÌØ»ÝÅÅÐаñ°ñµ¥ÐÅÏ¢
# @change: "2017-03-24 15:00" hxp Æô¶¯Ê±³õʼ»¯»î¶¯Êý¾Ý״ֵ̬
# @change: "2017-06-14 11:00" hxp »¹Ô­ÌØ»ÝÏû·Ñ·µÀû°ñ
#
# ÏêϸÃèÊö: Ìػݻ
#
#---------------------------------------------------------------------
"""Version = 2017-06-14 11:00"""
 
import GameWorld
import ShareDefine
import ChPyNetSendPack
import NetPackCommon
import GameWorldShopItem
import PlayerDBGSEvent
import PlayerCompensation
import PlayerBillboard
import DataRecordPack
import ReadChConfig
import ChConfig
 
## GMÖØÖÃÌØ»ÝÊý¾Ý£¬·½±ã²âÊÔ
#  @param None
#  @return None
def OnGMClearTeHui():
    # Çå³ý³äÖµÌØ»ÝÅÅÐаñ
    PlayerBillboard.ClearBillboardByIndex(ShareDefine.Def_BT_RechargeTeHui)
    PlayerBillboard.ClearBillboardByIndex(ShareDefine.Def_BT_RechargeTeHuiLast)
    # Çå³ýÏû·ÑÌØ»ÝÅÅÐаñ
    PlayerBillboard.ClearBillboardByIndex(ShareDefine.Def_BT_CostTeHui)
    PlayerBillboard.ClearBillboardByIndex(ShareDefine.Def_BT_CostTeHuiLast)
    
    gameWorld = GameWorld.GetGameWorld()
    for dictName in ShareDefine.TeHuiTypeKeyDict.values():
    
        beginTime, endTime = 0, 0
        signID = 0
        #DZ¹æÔò£ºÔÚChConfig»î¶¯Ïà¹ØÉèÖÃÖУ¬ÌáÈ¡ÁË×ÖµäÃû
        gameWorld.SetDict(dictName, signID)
        gameWorld.SetDict(ShareDefine.Def_Notify_WorldKey_DayAction_BeginTime % dictName, beginTime)
        gameWorld.SetDict(ShareDefine.Def_Notify_WorldKey_DayAction_EndTime % dictName, endTime)
        # ±ê¼Ç»î¶¯Î¨Ò»id
        actionIDKey = ShareDefine.Def_Notify_WorldKey_DayAction_ID % dictName
        gameWorld.SetDict(actionIDKey, beginTime)
        
        #֪ͨMapserver,ÉèÖÃ×Öµä
        GameWorld.SendMapServerMsgEx(actionIDKey, beginTime)
        GameWorld.SendMapServerMsgEx(dictName, signID)
        PlayerDBGSEvent.SetDBGSTrig_ByKey(actionIDKey, beginTime)
        PlayerDBGSEvent.SetDBGSTrig_ByKey(dictName, signID)
        PlayerDBGSEvent.SetDBGSTrig_ByKey(ShareDefine.Def_Notify_WorldKey_DayAction_BeginTime % dictName, beginTime)
        PlayerDBGSEvent.SetDBGSTrig_ByKey(ShareDefine.Def_Notify_WorldKey_DayAction_EndTime % dictName, endTime)
        
    PlayerDBGSEvent.DelDBGSTrig_ByKey(PlayerDBGSEvent.Def_TeHuiRepeatOrderKey)
    PlayerDBGSEvent.DelDBGSTrig_ByKey(PlayerDBGSEvent.Def_TeHuiRepeatNumKey)
    return
 
def OnGameServerInitOK():
    # ¶ÁÈ¡Êý¾Ý¿âÖеÄÖµ³õʼ»¯µ½ÄÚ´æÖÐ
    GameWorld.Log("³õʼ»¯Ìػݻֵ...")
    gameWorld = GameWorld.GetGameWorld()
    for dictName in ShareDefine.TeHuiTypeKeyDict.values():
        actionIDKey = ShareDefine.Def_Notify_WorldKey_DayAction_ID % dictName
        beginTimeKey = ShareDefine.Def_Notify_WorldKey_DayAction_BeginTime % dictName
        endTimeKey = ShareDefine.Def_Notify_WorldKey_DayAction_EndTime % dictName
        
        actionValue = PlayerDBGSEvent.GetDBGSTrig_ByKey(dictName)
        actionID = PlayerDBGSEvent.GetDBGSTrig_ByKey(actionIDKey)
        beginTime = PlayerDBGSEvent.GetDBGSTrig_ByKey(beginTimeKey)
        endTIme = PlayerDBGSEvent.GetDBGSTrig_ByKey(endTimeKey)
        
        gameWorld.SetDict(dictName, actionValue)
        gameWorld.SetDict(actionIDKey, actionID)
        gameWorld.SetDict(beginTimeKey, beginTime)
        gameWorld.SetDict(endTimeKey, endTIme)
        GameWorld.Log("    dictName=%s,actionValue=%s,actionID=%s,beginTime=%s,endTIme=%s" 
                      % (dictName, actionValue, actionID, beginTime, endTIme))
    return
 
def OnMapServerInitOK():
    SendTeHuiActionInfo()
    return
 
## ·¢ËÍMapServerÌØ»Ý»î¶¯ÐÅÏ¢
#  @param None
#  @return None
def SendTeHuiActionInfo():
    gameWorld = GameWorld.GetGameWorld()
    for actionKey in ShareDefine.TeHuiTypeKeyDict.values():
        actionIDKey = ShareDefine.Def_Notify_WorldKey_DayAction_ID % actionKey
 
        actionID = gameWorld.GetDictByKey(actionIDKey)
        actionValue = gameWorld.GetDictByKey(actionKey)
        
        # Èç¹ûûÓÐÖµ£¬ÔòÈ¡¼Ç¼ÖеÄÖµ
        if actionID <= 0:
            actionID = PlayerDBGSEvent.GetDBGSTrig_ByKey(actionIDKey)
            actionValue = PlayerDBGSEvent.GetDBGSTrig_ByKey(actionKey)
            
        GameWorld.SendMapServerMsgEx(actionIDKey, actionID)
        GameWorld.SendMapServerMsgEx(actionKey, actionValue)
    return
 
 
## Ìػݻ±ä¸ü´¦Àí
#  @param dictName »î¶¯key
#  @param value Öµ
#  @return None
def OnTeHuiActionChange(dictName, value):
    gameWorld = GameWorld.GetGameWorld()
    actionIDKey = ShareDefine.Def_Notify_WorldKey_DayAction_ID % dictName
    startTimeKey = ShareDefine.Def_Notify_WorldKey_DayAction_BeginTime % dictName
    endTimeKey = ShareDefine.Def_Notify_WorldKey_DayAction_EndTime % dictName
    curActionID = gameWorld.GetDictByKey(actionIDKey)
    dbActionID = PlayerDBGSEvent.GetDBGSTrig_ByKey(actionIDKey)
    dbStartTime = PlayerDBGSEvent.GetDBGSTrig_ByKey(startTimeKey)
    dbEndTime = PlayerDBGSEvent.GetDBGSTrig_ByKey(endTimeKey)
    dbActionValue = PlayerDBGSEvent.GetDBGSTrig_ByKey(dictName)
        
    # Èç¹û²»ÊÇͬһ»î¶¯ID£¬Ôò¸üб£´æ
    GameWorld.Log("OnTeHuiActionChange dictName=%s,value=%s,dbActionValue=%s,curActionID=%s,dbActionID=%s" 
                       % (dictName, value, dbActionValue, curActionID, dbActionID))
    if curActionID != dbActionID:
        PlayerDBGSEvent.SetDBGSTrig_ByKey(actionIDKey, curActionID)
        curStartTime = gameWorld.GetDictByKey(startTimeKey)
        curEndTime = gameWorld.GetDictByKey(endTimeKey)
        PlayerDBGSEvent.SetDBGSTrig_ByKey(startTimeKey, curStartTime)
        PlayerDBGSEvent.SetDBGSTrig_ByKey(endTimeKey, curEndTime)
        PlayerDBGSEvent.SetDBGSTrig_ByKey(dictName, value)
        GameWorld.Log("    »î¶¯ID²»Ò»Ñù£¬¸üÐÂDBGSTrig...curActionID=%s,sTime=%s,eTime=%s,value=%s" 
                      % (curActionID, curStartTime, curEndTime, value))
        
        # Èç¹ûÊÇÕۿ۵꣬ÔòÐèÒªÖØÖÃÈ«·þÏÞ¹ºÊý¾Ý
        if dictName in [ShareDefine.Def_Notify_WorldKey_DayAction_DiscountShop,
                        ShareDefine.Def_Notify_WorldKey_DayAction_MixDiscountShop]:
            GameWorldShopItem.DoShopItemClearBuyCnt(value)
            GameWorld.Log("    ÕÛ¿ÛµêлID¿ªÆô£¬ÖØÖÃÈ«·þÏÞ¹º´ÎÊý£¡shopID=%s" % value)
        
        # ³äÖµÅÅÐÐÌØ»Ý
        elif dictName == ShareDefine.Def_Notify_WorldKey_DayAction_RechargeRank:
            # ¿½±´ÕâÒ»ÆÚµÄ×îÖÕ½á¹û±¸µµ
            PlayerBillboard.CopyBillboard(ShareDefine.Def_BT_RechargeTeHuiLast, ShareDefine.Def_BT_RechargeTeHui)
            DataRecordPack.DR_BillboardDataByDay(ShareDefine.Def_BT_RechargeTeHui)
            GameWorld.Log("    ³äÖµÅÅÐÐÌØ»Ý ¿½±´ÀúÊ·»î¶¯Êý¾Ý±¸µµ¡£¡£.")
            # ·¢Ëͽ±ÀøÓʼþ
            __DoSendRechargeRankTeHuiRewardMail(dbActionID, dbActionValue, dbStartTime, dbEndTime)
            GameWorld.Log("    ³äÖµÅÅÐÐÌØ»Ý ·¢Ëͽ±ÀøÓʼþ¡£¡£.")
            # Èç¹û¿ªÆôеÄÒ»ÆÚ£¬ÔòÖØÖÃÐÂÒ»ÆÚÅÅÐаñ
            if value > 0:
                PlayerBillboard.ClearBillboardByIndex(ShareDefine.Def_BT_RechargeTeHui)
                GameWorld.Log("    ³äÖµÅÅÐÐÌØ»Ý ÖØÖÃÐÂÒ»ÆÚÅÅÐаñ¡£¡£.")
        
        # Ïû·ÑÌØ»ÝÅÅÐаñ
        elif dictName == ShareDefine.Def_Notify_WorldKey_DayAction_CostRank:
            # ¿½±´ÕâÒ»ÆÚµÄ×îÖÕ½á¹û±¸µµ
            PlayerBillboard.CopyBillboard(ShareDefine.Def_BT_CostTeHuiLast, ShareDefine.Def_BT_CostTeHui)
            DataRecordPack.DR_BillboardDataByDay(ShareDefine.Def_BT_CostTeHui)
            __DoSendCostRankTeHuiRewardMail(dbActionID, dbActionValue, dbStartTime, dbEndTime)
            if value > 0:
                PlayerBillboard.ClearBillboardByIndex(ShareDefine.Def_BT_CostTeHui)
                
    Sync_TeHuiActivityToClient(None, 0)
    return
 
## Ö´Ðз¢ËÍÏû·ÑÌØ»ÝÅÅÐаñÓʼþ
#  @param None
#  @return None
def __DoSendCostRankTeHuiRewardMail(dbActionID, dbActionValue, dbStartTime, dbEndTime):
    GameWorld.Log("Ö´Ðз¢ËÍÏû·ÑÌØ»ÝÅÅÐаñÓʼþ...dbActionID=%s,dbActionValue=%s,dbStartTime=%s,dbEndTime=%s" 
                  % (dbActionID, dbActionValue, dbStartTime, dbEndTime))
    # ·¢Ëͽ±ÀøÓʼþ
    billboard = GameWorld.GetBillboard().FindBillboard(ShareDefine.Def_BT_CostTeHui)
    if not billboard:
        GameWorld.ErrLog("    ÕÒ²»µ½Ïû·ÑÌØ»ÝÅÅÐаñ!!!")
        return
    
    costRankInfoDict = ReadChConfig.GetEvalChConfig("TeHuiAction_CostRank")
    
    if dbActionValue not in costRankInfoDict:
        GameWorld.ErrLog("    »î¶¯±àºÅ²»ÔÚÅÅÐн±ÀøÅäÖÃÀ±àºÅ=%s" % (dbActionValue))
        return
    
    costRankInfoList = costRankInfoDict[dbActionValue]
    
    if len(costRankInfoList) < 5:
        GameWorld.ErrLog("    ÅÅÐн±ÀøÅäÖÃÐÅÏ¢´íÎó!!!")
        return
    
    startTimeStr = GameWorld.ChangeTimeNumToStr(dbStartTime)
    endTimeStr = GameWorld.ChangeTimeNumToStr(dbEndTime)
    rewardMailInfoList = costRankInfoList[1:]
    mailTitle, contentTemple, getDays, rewardDict = rewardMailInfoList
    mailLimitTime = str(GameWorld.GetDatetimeByDiffDays(getDays))
    mailLimitTime = mailLimitTime.split(".")[0]
    
    billboardCnt = billboard.GetCount()
    #maxOrder = max(rewardDict)
    for index in range(0, billboardCnt):
        #if index < 0 or index >= billboardCnt:
        #    continue
        
        objBillboard = billboard.At(index)
        playerID = objBillboard.GetID()
        curJob = objBillboard.GetType2()
        curJobType = ChConfig.JOB_TYPE_DICT.get(curJob) # »ñȡְҵ´óÀà
        jobRewardDict = __GetAwardByJob(curJobType, rewardDict)
       
        if not jobRewardDict:
            GameWorld.ErrLog("Ïû·ÑÅÅÐÐÌØ»Ý ·¢Ëͽ±Àø£¬ÕÒ²»µ½Ö°Òµ¶ÔÓ¦½±ÀøÅäÖÃ, jobType=%s" % curJobType)
            continue
        
        order = index + 1
        
        rewardItemList = GameWorld.GetDictValueByRangeKey(jobRewardDict, order)
        if not rewardItemList:
            GameWorld.ErrLog("Ïû·ÑÅÅÐÐÌØ»Ý ·¢Ëͽ±Àø£¬order=%s not in jobRewardDict=%s" % (order, str(jobRewardDict)))
            continue
        
        mailContent = contentTemple % (startTimeStr, endTimeStr, order)
        GUID = PlayerCompensation.SendPersonalItemMail(mailTitle, mailContent, mailLimitTime, [playerID], rewardItemList)
        DataRecordPack.DR_SendCostRankTeHuiRewardMail(playerID, GUID, dbActionID, dbActionValue, order, rewardItemList)
        
    return
    
## Ö´Ðз¢ËͳäÖµÅÅÐн±ÀøÓʼþ
#  @param None
#  @return None
def __DoSendRechargeRankTeHuiRewardMail(dbActionID, dbActionValue, dbStartTime, dbEndTime):
    GameWorld.Log("Ö´Ðз¢ËͳäÖµÅÅÐн±ÀøÓʼþ...dbActionID=%s,dbActionValue=%s,dbStartTime=%s,dbEndTime=%s" 
                  % (dbActionID, dbActionValue, dbStartTime, dbEndTime))
    # ·¢Ëͽ±ÀøÓʼþ
    billboard = GameWorld.GetBillboard().FindBillboard(ShareDefine.Def_BT_RechargeTeHui)
    if not billboard:
        GameWorld.ErrLog("    ÕÒ²»µ½³äÖµÅÅÐаñ!!!")
        return
    
    RechargeRankInfoDict = ReadChConfig.GetEvalChConfig("TeHuiAction_RechargeRank")
    
    if dbActionValue not in RechargeRankInfoDict:
        GameWorld.ErrLog("    »î¶¯±àºÅ²»ÔÚÅÅÐн±ÀøÅäÖÃÀ±àºÅ=%s" % (dbActionValue))
        return
    
    rechargeRankInfoList = RechargeRankInfoDict[dbActionValue]
    
    if len(rechargeRankInfoList) < 5:
        GameWorld.ErrLog("    ÅÅÐн±ÀøÅäÖÃÐÅÏ¢´íÎó!!!")
        return
    
    startTimeStr = GameWorld.ChangeTimeNumToStr(dbStartTime)
    endTimeStr = GameWorld.ChangeTimeNumToStr(dbEndTime)
    rewardMailInfoList = rechargeRankInfoList[1:]
    mailTitle, contentTemple, getDays, rewardDict = rewardMailInfoList
    mailLimitTime = str(GameWorld.GetDatetimeByDiffDays(getDays))
    mailLimitTime = mailLimitTime.split(".")[0]
    
    billboardCnt = billboard.GetCount()
    #maxOrder = max(rewardDict)
    for index in range(0, billboardCnt):
        #if index < 0 or index >= billboardCnt:
        #    continue
        
        objBillboard = billboard.At(index)
        playerID = objBillboard.GetID()
        curJob = objBillboard.GetType2()
        curJobType = ChConfig.JOB_TYPE_DICT.get(curJob) # »ñȡְҵ´óÀà
        jobRewardDict = __GetAwardByJob(curJobType, rewardDict)
       
        if not jobRewardDict:
            GameWorld.ErrLog("³äÖµÅÅÐÐÌØ»Ý ·¢Ëͽ±Àø£¬ÕÒ²»µ½Ö°Òµ¶ÔÓ¦½±ÀøÅäÖÃ, jobType=%s" % curJobType)
            continue
        
        order = index + 1
        
        rewardItemList = GameWorld.GetDictValueByRangeKey(jobRewardDict, order)
        if not rewardItemList:
            GameWorld.ErrLog("³äÖµÅÅÐÐÌØ»Ý ·¢Ëͽ±Àø£¬order=%s not in jobRewardDict=%s" % (order, str(jobRewardDict)))
            continue
        
        mailContent = contentTemple % (startTimeStr, endTimeStr, order)
        GUID = PlayerCompensation.SendPersonalItemMail(mailTitle, mailContent, mailLimitTime, 
                                                        [playerID], rewardItemList)
        DataRecordPack.DR_SendRechareRankTeHuiRewardMail(playerID, GUID, dbActionID, 
                                                         dbActionValue, order, rewardItemList)
        
    return
 
## ¸ù¾ÝÖ°Òµ»ñÈ¡½±Àø
#  @param curPlayer£ºÍæ¼ÒʵÀý
#  @param qqRewardDict£º½±ÀøÎïÆ·ÅäÖÃ×Öµä
#  @return None
def __GetAwardByJob(jobtype, rewardDict):
    if jobtype in rewardDict:
        return rewardDict[jobtype]
    infoKey = () # Ä¬ÈÏkey
    for jobkey in rewardDict.keys():
        # Èç¹ûÍæ¼ÒÖ°ÒµÔÚÅäÖõÄkeyÀÔòȡָ¶¨µÄkeyÐÅÏ¢
        if isinstance(jobkey, tuple) and jobtype in jobkey:
            infoKey = jobkey
            break
    return rewardDict.get(infoKey)
    
## ²éÑ¯ÌØ»Ý»î¶¯ÐÅÏ¢
#  @param index Íæ¼ÒʵÀý
#  @param clientData ·â°ü½á¹¹Ìå
#  @param tick Ê±¼ä´Á
#  @return None
def ClientRequestTeHuiActivity(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    activityType = clientData.ActivityType    
    GameWorld.DebugLog("ClientRequestTeHuiActivity activityType=%s" % activityType)
    Sync_TeHuiActivityToClient(curPlayer, activityType)
    return
 
 
## Í¬²½ÌػݻÐÅÏ¢
#  @param curPlayer 
#  @param tick Ê±¼ä´Á
#  @return None
def Sync_TeHuiActivityToClient(curPlayer, activityType):
    gameWorld = GameWorld.GetGameWorld()
    
    tehuiPack = ChPyNetSendPack.tagGCTeHuiActivityInfoList()
    tehuiPack.Clear()
    tehuiPack.ActivityInfoList = []
    
    for teHuiType, dictKey in ShareDefine.TeHuiTypeKeyDict.items():
        
        if activityType not in [0, teHuiType]:
            continue
        
        tehuiInfo = ChPyNetSendPack.tagGCTeHuiActivityInfo()
        tehuiInfo.Clear()
        tehuiInfo.ActivityType = teHuiType
        tehuiInfo.ActivityValue = gameWorld.GetDictByKey(dictKey)
        startTime = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_DayAction_BeginTime % dictKey)
        tehuiInfo.StartDate = startTime
        endTime = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_DayAction_EndTime % dictKey)
        tehuiInfo.EndDate = endTime
        tehuiPack.ActivityInfoList.append(tehuiInfo)
    
    tehuiPack.ActivityCount = len(tehuiPack.ActivityInfoList)
    
    # Í¨Öª¿Í»§¶Ëͬ²½Ê±¼ä        
    if not curPlayer:
        # È«·þ¹ã²¥ÔÚÏßÍæ¼Ò
        playerManager = GameWorld.GetPlayerManager()
        for i in range(0, playerManager.GetPlayerCount()):
            curPlayer = playerManager.GetPlayerByIndex(i)
            if curPlayer == None or not curPlayer.GetInitOK():
                continue
            
            NetPackCommon.SendFakePack(curPlayer, tehuiPack)
    else:
        NetPackCommon.SendFakePack(curPlayer, tehuiPack)
    return