hxp
2019-03-26 5ad2bd52bfbdf91a93ecf3a6c98c5e578edabb2b
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerCostVIP
#
# @todo:Ïû·ÑVIP
# @author ljd
# @date 2015-04-21 11:30
# @version 1.7
#
# @change: "2015-08-18 15:50" ljd ÌØÊâ´¦ÀíÊýÖµÅä´í,VIPµÈ¼¶¾­Ñéµ÷С,ÌØÊâ´¦ÀíÍâÍøÒÑÉý¼¶VIPÍæ¼Ò,²¹»ØVIPµÈ¼¶
# @change: "2016-01-26 15:00" hxp PY±íÖ§³ÖÖØ¶Á
# @change: "2016-06-15 12:00" hxp ³èÎïÊØ»¤Î»½âËø
# @change: "2016-07-02 16:30" hxp VIPÌØÈ¨buff¸ÄΪ±»¶¯¼¼ÄܼÓÕ½¶·Á¦
# @change: "2016-10-17 16:00" hxp Ôö¼Ó¾­Ñ鸱±¾¡¢½ð±Ò¸±±¾ÊÕÒæÌØÈ¨
# @change: "2017-04-01 10:30" xdh CostVIP.txtÈ¥³ýÖ°ÒµÇø±ð
# @change: "2017-05-24 16:08" xdh Ôö¼ÓVIP³É³¤½±Àø
#
# ÏêϸÃèÊö: Ïû·Ñ×êʯÊýÔö¼ÓVIPµÈ¼¶,¸ù¾ÝVIPµÈ¼¶Ôö¼ÓÌØÈ¨ºÍ¸øÓè½±Àø
#
#---------------------------------------------------------------------
#"""Version = 2017-05-24 16:08"""
#---------------------------------------------------------------------
import IPY_GameWorld
import GameWorld
import ChConfig
import ReadChConfig
import PyMapTable
import ItemControler
import PlayerControl
import DataRecordPack
import ShareDefine
import ChPyNetSendPack
import NetPackCommon
import ChPlayer
import SkillCommon
import BuffSkill
import EventShell
 
import Operate_PlayerBuyZhenQi
 
 
# Ïû·ÑVIPÐÅÏ¢±íÁбêʶ
CostVIPData_LV = "LV"               # VIPµÈ¼¶
CostVIPData_Exp = "EXP"             # Éý¼¶ËùÐè¾­Ñé
# ----- Íâµ÷ÔÙ·â×°º¯ÊýʹÓà-----
CostVIPData_PrayNum = "PrayNum"         # Æíµ»´ÎÊý
CostVIPData_ArenaNum = "ArenaNum"       # ¾º¼¼³¡Ôö¼Ó´ÎÊý
CostVIPData_RoundReward = "RoundReward" # »·ÈÎÎñ½±Àø¼Ó³É <°Ù·ÖÂÊ>
CostVIPData_RoundStar = "RoundStar"     # »·ÈÎÎñ×ÖµäÐǼ¶
CostVIPData_BZZDExpAddRate = "BZZDExpAddRate"     # ¾­ÑéÃØ¾³¾­Ñé¼Ó³É
CostVIPData_RedPacketGrabCnt = "RedPacketGrabCnt"     # ÇÀºì°üÿÈÕ¿ÉÇÀ´ÎÊýÔö¼Ó
CostVIPData_KillWorldBossAddCnt = "KillWorldBossAddCnt"     # »÷ɱÊÀ½çboss´ÎÊýÔö¼Ó
 
# Ïû·ÑVIPÐÅÏ¢±í½±ÀøÅäÖøñʽ
(
Reward_Item_Type,   # ÎïÆ·ÀàÐÍ
Reward_Item_Id,     # ÎïÆ·ID
Reward_Item_Num,    # ÎïÆ·ÊýÁ¿
Reward_Item_Bind,   # ÊÇ·ñ°ó¶¨
) = range(4)
 
# ÎïÆ·ÀàÐÍ
(
Item_Type_Common,   # Ò»°ãÎïÆ·±í
Item_Type_Appoint,  # ÌØÊâ¶¨ÖÆÎïÆ·
) = range(2)
 
 
## Ôö¼ÓÏû·ÑVIP¾­Ñé
#  @param curPlayer
#  @param costType Ïû·ÑÀàÐÍ
#  @param costGold Ïû·Ñ×êʯÊý
#  @return
def AddCostVIPExp(curPlayer, costType, costGold):
    GameWorld.DebugLog("==[PlayerCostVIP]== In->AddCostVIPExp() player(%s)" % curPlayer.GetPlayerName())
    
    if costGold <= 0:
        GameWorld.DebugLog("AddCostVIPExp() no cost(%s) gold" % costType)
        return
    if costType in ChConfig.CostVIP_CostType:
        GameWorld.DebugLog("AddCostVIPExp() no use cost(%s) type" % costType)
        return
    
    moneyToExpScale = eval(ReadChConfig.GetEvalChConfig('CostVIPMoneyToExp'))
    addExp = int(costGold * moneyToExpScale)
    if addExp <= 0:
        GameWorld.DebugLog("AddCostVIPExp() no add EXP")
        return
    curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostVIPExp)
    lastLV = curPlayer.GetVIPLv()
    __AddCostVIPExp(curPlayer, addExp)
    
    
    if lastLV != curPlayer.GetVIPLv():
        DataRecordPack.DR_PlayerCostVIPLV(curPlayer, lastLV, curExp, addExp, costType, costGold)
    
    return
 
## Ôö¼ÓÏû·ÑVIP¾­Ñé
def __AddCostVIPExp(curPlayer, addExp):
    curLV = curPlayer.GetVIPLv()
    needExp = __GetCostVIPData(curPlayer, curLV, CostVIPData_Exp)
    if not needExp:
        GameWorld.DebugLog("__AddCostVIPExp() EXP no configuration vipLV(%s)" % curLV)
        return
    
    curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostVIPExp)
    newExp = curExp + addExp
 
    while needExp and newExp >= needExp:
        curLV += 1
        __SetVIPLV(curPlayer, curLV)
        
        newExp -= needExp
        needExp = __GetCostVIPData(curPlayer, curLV, CostVIPData_Exp)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostVIPExp, newExp if needExp else 0)
    
    Sync_CostVIPInfo(curPlayer)
    
    GameWorld.DebugLog("    __AddCostVIPExp() LV(%s) EXP(%s)" % (curLV, newExp))
    return
 
## Ïû·ÑVIPµÇ½
#  @param curPlayer
#  @param tick
#  @return
def CostVIPOnLogin(curPlayer, tick):
    
    Sync_CostVIPInfo(curPlayer)
    Sync_CostVIPAwardState(curPlayer)
    Sync_CostVIPGrowUpAwardState(curPlayer)
    return
 
## ¹ºÂòÏû·ÑVIPÎïÆ·
#  @param index
#  @param clientPack <VIPLV-VIPµÈ¼¶>
#  @param tick
#  @return
def BuyCostVIPItem(index, clientPack, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    GameWorld.DebugLog("==[PlayerCostVIP]== In->BuyCostVIPItem(), Name:%s" % curPlayer.GetPlayerName())
    
    getVIPLV = clientPack.VIPLV
    
    if getVIPLV > curPlayer.GetVIPLv():
        GameWorld.DebugLog("BuyCostVIPItem() VIP LV(%s) no buy LV(%s)" % (curPlayer.GetVIPLv(), getVIPLV))
        return
    
    buyItemStateKey = ChConfig.Def_PDict_CostVIPBuyItem
    buyItemState = curPlayer.NomalDictGetProperty(buyItemStateKey)
    if buyItemState & pow(2, getVIPLV):
        GameWorld.DebugLog("BuyCostVIPItem() had buy reward(%s)" % getVIPLV)
        return
    
    VIPBuyItemCfg = ReadChConfig.GetEvalChConfig('VIPBuyItemCfg')
    if getVIPLV not in VIPBuyItemCfg:
        GameWorld.DebugLog("VIPBuyItemCfg.txt Î´ÅäÖùºÂòÐÅÏ¢ vip=%s" % getVIPLV)
        return
    buyItemInfo = VIPBuyItemCfg[getVIPLV]
    if len(buyItemInfo) !=3:
        return
    itemPrice, needSpace, itemList = buyItemInfo
    packSpace = ItemControler.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    if packSpace < needSpace:
        GameWorld.DebugLog("BuyCostVIPItem() no enough(%s) pack space(%s)" % (needSpace, packSpace))
        return
    
    moneyType = IPY_GameWorld.TYPE_Price_Gold_Money
    if itemPrice > 0:
        if not PlayerControl.HaveMoney(curPlayer, moneyType, itemPrice, True):
            GameWorld.DebugLog("BuyCostVIPItem() no enough money(%s)" % itemPrice)
            return
    
    PlayerControl.NomalDictSetProperty(curPlayer, buyItemStateKey, buyItemState | pow(2, getVIPLV))
    
    if itemPrice > 0:
        infoDict = {"getVIPLV":getVIPLV, ChConfig.Def_Cost_Reason_SonKey:"VIP%s"%getVIPLV}
        PlayerControl.PayMoney(curPlayer, moneyType, itemPrice, ChConfig.Def_Cost_BuyVIPItem, infoDict)
            
    __GiveItem(curPlayer, itemList)
    
    Sync_CostVIPInfo(curPlayer)
    GameWorld.DebugLog("==[PlayerCostVIP]== Out->BuyCostVIPItem()")
    return
 
## ÁìÈ¡Ïû·ÑVIP½±Àø
#  @param curPlayer
#  @param getVIPLV ÁìÈ¡µÄVIPµÈ¼¶
#  @return
def GetCostVIPAward(curPlayer, getVIPLV):
    if getVIPLV > curPlayer.GetVIPLv():
        GameWorld.DebugLog("GetCostVIPAward() VIP LV(%s) no buy LV(%s)" % (curPlayer.GetVIPLv(), getVIPLV))
        return
    
    rewardStateKey = ChConfig.Def_PDict_CostVIPLVReward
    rewardState = curPlayer.NomalDictGetProperty(rewardStateKey)
    if rewardState & pow(2, getVIPLV):
        GameWorld.DebugLog("GetCostVIPAward() had got reward(%s)" % getVIPLV)
        return
    
    VIPAwardCfg = ReadChConfig.GetEvalChConfig('VIPAwardCfg')
    if getVIPLV not in VIPAwardCfg:
        GameWorld.DebugLog("VIPAwardCfg.txt Î´ÅäÖý±ÀøÐÅÏ¢ vip=%s" % getVIPLV)
        return
    rewardList = VIPAwardCfg[getVIPLV]
    
    packSpace = ItemControler.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    if packSpace < rewardList[0]:
        GameWorld.DebugLog("GetCostVIPAward() no enough(%s) pack space(%s)" % (rewardList[0], packSpace))
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, rewardStateKey, rewardState | pow(2, getVIPLV))
    
    __GiveItem(curPlayer, rewardList[1:])
    
    Sync_CostVIPAwardState(curPlayer)
    return
 
## ÁìÈ¡VIP³É³¤½±Àø
def GetVIPGrowUpAward(curPlayer, index):
    growUpAwardDict = ReadChConfig.GetEvalChConfig('VIPGrowUpAward')
    if index not in growUpAwardDict:
        return
    
    rewardStateKey = ChConfig.Def_PDict_CostVIPGrowUpReward
    rewardState = curPlayer.NomalDictGetProperty(rewardStateKey)
    if rewardState & pow(2, index):
        GameWorld.DebugLog("    ÁìÈ¡VIP³É³¤½±Àø had got reward(%s)" % index)
        return
    
    needLV, vipExp, itemList = growUpAwardDict[index]
    if curPlayer.GetLV() < needLV:
        GameWorld.DebugLog('    ÁìÈ¡VIP³É³¤½±Àøindex=%s, Íæ¼ÒµÈ¼¶²»×ã%s'%(index, needLV))
        return
    
    packSpace = ItemControler.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    
    if packSpace < len(itemList):
        GameWorld.DebugLog("ÁìÈ¡VIP³É³¤½±Àø no enough(%s) pack space(%s)" % (len(itemList), packSpace))
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, rewardStateKey, rewardState | pow(2, index))
    
    __AddCostVIPExp(curPlayer, vipExp)
    PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_437683", [vipExp])
    __GiveItem(curPlayer, itemList)
    
    Sync_CostVIPGrowUpAwardState(curPlayer)
    return
 
## Í¨Öª³É³¤½±ÀøÁìȡ״̬
#  @param curPlayer
#  @return
def Sync_CostVIPGrowUpAwardState(curPlayer):
#    awardType = ShareDefine.Def_RewardType_CostVIPGrowUp
#    awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostVIPGrowUpReward)
#    ChPlayer.Sync_RewardGetRecordInfo(curPlayer, awardType, awardState)
    return
 
## Í¨ÖªÏû·ÑVIPÐÅÏ¢
#  @param curPlayer
#  @return
def Sync_CostVIPInfo(curPlayer):
    sendPack = ChPyNetSendPack.tagMCVIPInfo()
    sendPack.Clear()
    sendPack.Exp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostVIPExp)
    sendPack.BuyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostVIPBuyItem)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
## Í¨Öª½±ÀøÁìȡ״̬
#  @param curPlayer
#  @return
def Sync_CostVIPAwardState(curPlayer):
    #awardType = ShareDefine.Def_RewardType_CostVIPLV
    #awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostVIPLVReward)
    #ChPlayer.Sync_RewardGetRecordInfo(curPlayer, awardType, awardState)
    return
 
## Ïû·ÑVIPÉý¼¶VIP
#  @param curPlayer
#  @param vipLV Ïû·ÑVIPµÈ¼¶
#  @return
def __SetVIPLV(curPlayer, vipLV):
    curPlayer.SetVIPLv(vipLV)
    #vipµÈ¼¶¸Ä±ä´¥·¢ÈÎÎñ
    EventShell.EventResponse_OnVipLvUp(curPlayer)
    tick = GameWorld.GetGameWorld().GetTick()
    __AddBuff(curPlayer, tick)        
    __NtfChangeInfo(curPlayer, tick)
    return
 
## ¸øÓèÎïÆ·
#  @param curPlayer
#  @param itemList ÎïÆ·Áбí
#  @return
def __GiveItem(curPlayer, itemList):
    giveFailList = []
    for itemInfo in itemList:
        itemType = itemInfo[Reward_Item_Type]
        itemId = itemInfo[Reward_Item_Id]
        itemNum = itemInfo[Reward_Item_Num]
        itemIsBind = itemInfo[Reward_Item_Bind]
        if isinstance(itemId, dict):
            if curPlayer.GetJob() not in itemId:
                GameWorld.ErrLog(" PlayerCostVIP __GiveItem  itemId=%s, Ö°Òµ(%s)δÅäÖÃ" 
                                 % (itemId, curPlayer.GetJob()))
                continue
            itemId = itemId[curPlayer.GetJob()]
            
        if itemNum <= 0 or itemId <= 0:
            continue
        
        if itemType == Item_Type_Common:
            packIndexList = [IPY_GameWorld.rptItem, IPY_GameWorld.rptAnyWhere]
            if not ItemControler.GivePlayerItem(curPlayer, itemId, itemNum, 0, packIndexList):
                giveFailList.append(itemInfo)
            
        elif itemType == Item_Type_Appoint:
            if not ItemControler.GivePlayerAppointItem(curPlayer, itemId, False):
                giveFailList.append(itemInfo)
                
    if giveFailList:
        GameWorld.ErrLog("__GiveItem() give fail item(%s)" % str(giveFailList), curPlayer.GetPlayerID())
    return
 
## ¼ÓBuff
#  @param curPlayer
#  @param tick
#  @return ÊÇ·ñ¼Ó³É¹¦
def __AddBuff(curPlayer, tick):
    costVIPBuffTypeID = ChConfig.Def_SkillID_CostVipBuff
    curVIPLv = curPlayer.GetVIPLv()
    curSkill = GameWorld.GetGameData().FindSkillByType(costVIPBuffTypeID, curVIPLv)
    if not curSkill:
        return
    
    playerSkillManager = curPlayer.GetSkillManager()
    BuffSkill.DelBuffBySkillID(curPlayer, costVIPBuffTypeID, tick)
    playerSkillManager.DeleteSkillBySkillTypeID(costVIPBuffTypeID)
 
    skillID = curSkill.GetSkillID()
    playerSkillManager.LVUPSkillByID(skillID)
    SkillCommon.AddBuffBySkillType(curPlayer, costVIPBuffTypeID, tick, curVIPLv)
    return True
 
## Í¨ÖªÐÅÏ¢±ä»¯
#  @param curPlayer
#  @param tick
#  @return None
def __NtfChangeInfo(curPlayer, tick):
    Operate_PlayerBuyZhenQi.Sync_NotifyDataChange(curPlayer)
    return
 
## »ñÈ¡Ïû·ÑVIPÅäÖÃÐÅÏ¢
#  @param curPlayer
#  @param vipLV VIPµÈ¼¶
#  @param dataKey ÏûÏ¢±íÁбí±êʶ
#  @return ·µ»Ø¶ÔÓ¦ÐÅÏ¢
def __GetCostVIPData(curPlayer, vipLV=-1, dataKey=''):
    if vipLV < 0:
        vipLV = curPlayer.GetVIPLv()
    
    searchDict = {CostVIPData_LV:str(vipLV)}
    costVIPTable = PyMapTable.GetPyMapTable("CostVIP")
    
    costVIPDataList = costVIPTable.GetRecordByDic(searchDict)
    if len(costVIPDataList) != 1:
        GameWorld.DebugLog("__GetCostVIPData() vipLV(%s) configuration repeat" % (vipLV))
        return
    
    if dataKey == '':
        return costVIPDataList[0]
    
    costVIPData = costVIPDataList[0].get(dataKey)
    if not costVIPData:
        GameWorld.DebugLog("__GetCostVIPData() %s no configuration vipLV(%s)" % (dataKey, vipLV))
        return
    
    return eval(costVIPData)
 
 
# ----- Íâµ÷ÔÙ·â×°º¯Êý -----
## »ñÈ¡Æíµ»´ÎÊýÁбí
def GetPrayNumList(curPlayer, default=[]):
    prayNumList = __GetCostVIPData(curPlayer, dataKey = CostVIPData_PrayNum)
    if not prayNumList:
        return default
    return prayNumList
# »ñÈ¡¾º¼¼³¡Ôö¼Ó´ÎÊý
def GetArenaNum(curPlayer, default=0):
    arenaNum = __GetCostVIPData(curPlayer, dataKey = CostVIPData_ArenaNum)
    if not arenaNum:
        return default
    return arenaNum
# »ñÈ¡»·ÈÎÎñ½±Àø¼Ó³É<°Ù·ÖÂÊ>
def GetRoundReward(curPlayer, default=0):
    roundReward = __GetCostVIPData(curPlayer, dataKey = CostVIPData_RoundReward)
    if not roundReward:
        return default
    return roundReward
# »ñÈ¡»·ÈÎÎñ×ÖµäÐǼ¶
def GetRoundStar(curPlayer, default=0):
    roundStar = __GetCostVIPData(curPlayer, dataKey = CostVIPData_RoundStar)
    if not roundStar:
        return default
    return roundStar
# ¾­ÑéÃØ¾³¾­Ñé¼Ó³É
def GetBZZDExpAddRate(curPlayer):
    addValue = __GetCostVIPData(curPlayer, dataKey = CostVIPData_BZZDExpAddRate)
    if not addValue:
        return 0
    return addValue
 
# ÇÀºì°üÿÈÕ¿ÉÇÀÔö¼Ó´ÎÊý
def GetRedPacketGrabCntAdd(curPlayer):
    addCnt = __GetCostVIPData(curPlayer, dataKey = CostVIPData_RedPacketGrabCnt)
    if not addCnt:
        return 0
    return addCnt
 
# »÷ɱÊÀ½çboss´ÎÊýÔö¼Ó
def GetKillWorldBossAddCnt(curPlayer):
    addCnt = __GetCostVIPData(curPlayer, dataKey = CostVIPData_KillWorldBossAddCnt)
    if not addCnt:
        return 0
    return addCnt