hxp
2024-11-15 789490b7d362160f7fca4580df6176498e1eb271
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
#!/usr/bin/python
# -*- coding: GBK -*-
#
#
##@package Operate_PlayerBuyZhenQi
# @todo:ÆíÔ¸
# @author sgj
# @date 2017-10-31 11:30
# @version 1.0
#
 
#------------------------------------------------------------------------------ 
#"""Version = 2017-10-31 11:30"""
#------------------------------------------------------------------------------ 
# µ¼Èë
import GameWorld
import ChConfig
import PlayerControl
import NetPackCommon
import ChPyNetSendPack
import IPY_GameWorld
import IpyGameDataPY
import PlayerVip
import time
import ShareDefine
import GameFuncComm
import ItemCommon
import PlayerSuccess
import PlayerActivity
import PlayerBossReborn
import PlayerFairyCeremony
import PlayerNewFairyCeremony
import PlayerFeastTravel
import PlayerActLogin
import PlayerActTask
import PlayerWeekParty
import EventShell
#------------------------------------------------------------------------------ 
 
#»ñÈ¡½ð±ÒÆíÔ¸½±Àø
def GetMoneyPrayAward():
    return IpyGameDataPY.GetFuncCfg("MoneyPray", 2)
#»ñÈ¡½ð±ÒÆíÔ¸ÏûºÄ
def GetMoneyPrayCost():
    return IpyGameDataPY.GetFuncCfg("MoneyPray", 1)
#»ñÈ¡¾­ÑéÆíÔ¸½±Àø
def GetExpPrayAward():
    return IpyGameDataPY.GetFuncCfg("ExpPray", 2)
#»ñÈ¡¾­ÑéÆðÑÛÏûºÄ
def GetExpPrayCost():
    return IpyGameDataPY.GetFuncCfg("ExpPray", 1)
 
 
#ÆíÔ¸ÀàÐÍÁбí
TotalPrayList = [ChConfig.VIPPrivilege_MoneyPray, ChConfig.VIPPrivilege_ExpPray]
 
 
#struct    tagCMBuySomething
#{
#    tagHead        Head;
#    BYTE        Type;  //14Í­Ç®£¬15¾­Ñé
#};
## A5 30 Íæ¼ÒÆíÔ¸
#  @param index: Íæ¼ÒË÷Òý
#  @param clientData: ¿Í»§¶Ë·â°üÊý¾Ý
#  @param tick: Ê±¼ä´Á
#  @return: None
def OnPlayerBuySomething(index, clientData, tick):
    
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    buyType = clientData.Type  #¹ºÂòµÄÀàÐÍ
    #ÆíÔ¸ÀàÐÍ´íÎ󣬲»´¦Àí
    if buyType not in TotalPrayList:
        GameWorld.DebugLog("ÆíÔ¸ÀàÐÍ´íÎó---buyType:%s" % buyType)
        return
    if buyType == ChConfig.VIPPrivilege_MoneyPray:
        if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_RefineMoney):
            GameWorld.DebugLog("½ð±ÒÆíÔ¸¹¦ÄÜ먦Æô")
            return
    elif buyType == ChConfig.VIPPrivilege_ExpPray:
        if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_RefineExp):
            GameWorld.DebugLog("¾­ÑéÆíÔ¸¹¦ÄÜ먦Æô")
            return
    
    totalCnt = PlayerVip.GetPrivilegeValue(curPlayer, buyType)
    curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HasPrayCnt % buyType)
    cnt = curCnt + 1 #²ÎÊýÓÃ
    #½ð±ÒÆíÔ¸
    if buyType == ChConfig.VIPPrivilege_MoneyPray:
        historyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HistoryPrayCnt % buyType)
        #ÅжÏÃâ·ÑÆíÔ¸CDʱ¼ä
        needTime = __GetFreeCD(curPlayer)
        if needTime:
            itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
            needItemID = IpyGameDataPY.GetFuncCfg('FreeExpPrayItem', 2)
            hasEnough, itemList = ItemCommon.GetItem_FromPack_ByID(needItemID, itemPack, 1)
            if not hasEnough and totalCnt <= curCnt:
                GameWorld.DebugLog("½ð±ÒÆíÔ¸´ÎÊýÒѾ­ÓÃÍ꣬µ±Ç°´ÎÊý:%s,ÿÈÕ×î´ó´ÎÊý:%s" % (curCnt, totalCnt))
                return
            isCostItem = False #ÊÇ·ñʹÓÃÁËÎïÆ·
            if hasEnough:
                #ÓÅÏÈÓÃÎïÆ·
                isCostItem = True
                ItemCommon.ReduceItem(curPlayer, itemPack, itemList, 1, False)
            else:
            
                infoDict = {ChConfig.Def_Cost_Reason_SonKey:buyType}
                needGold = eval(GetMoneyPrayCost())
                if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, needGold, ChConfig.Def_Cost_Pray, infoDict):
                    GameWorld.DebugLog("ÏÉÓñ²»×ã!costGold=%s" % needGold)
                    return
            if not isCostItem: #ÓÃÎïÆ·²»Ôö¼Ó´ÎÊý
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HasPrayCnt % buyType, curCnt + 1)
        else:
            curTime = int(time.time())
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FreePrayTime, curTime)
            
        preCnt, fixMoney = IpyGameDataPY.GetFuncEvalCfg("MoneyPray", 4)
        GameWorld.DebugLog('11111fixMoney=%s,historyCnt=%s,preCnt=%s' % (fixMoney, historyCnt, preCnt))
        if fixMoney and historyCnt < preCnt:
            addMoney = fixMoney
            #¸üÐÂÀúÊ·´ÎÊý£¨ÌØÊâÊÕÒæ´ÎÊý´ïµ½ºó²»ÔÙ¸üУ©
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HistoryPrayCnt % buyType, historyCnt + 1)
        else:
            addMoney = GetMoneyPrayAward()
        addDataDict = {ChConfig.Def_Give_Reason_SonKey:"MoneyPray"}
        #20190917 by hxp ÆíÔ¸½ð±Ò¸ÄΪ°óÓñ
        giveMoneyType = IPY_GameWorld.TYPE_Price_Gold_Paper
        PlayerControl.GiveMoney(curPlayer, giveMoneyType, addMoney, ChConfig.Def_GiveMoney_Pray, addDataDict, False)
        PlayerControl.NotifyCode(curPlayer, 'MoneyPray_HowMuch', [addMoney, giveMoneyType])
        PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_MoneyPray, 1)
        PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_MoneyPray)
        
    #¾­ÑéÆíÔ¸    
    elif buyType == ChConfig.VIPPrivilege_ExpPray:
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
        needItemID = IpyGameDataPY.GetFuncCfg('FreeExpPrayItem')
        hasEnough, itemList = ItemCommon.GetItem_FromPack_ByID(needItemID, itemPack, 1)
        if not hasEnough and totalCnt <= curCnt:
            GameWorld.DebugLog("¾­ÑéÆíÔ¸´ÎÊýÒѾ­ÓÃÍ꣬µ±Ç°´ÎÊý:%s,ÿÈÕ×î´ó´ÎÊý:%s" % (curCnt, totalCnt))
            return
        playerLV = curPlayer.GetLV()
        lvMsg = PlayerControl.GetPlayerLVIpyData(playerLV)
        if not lvMsg:
            GameWorld.DebugLog("Íæ¼ÒµÈ¼¶ÐÅÏ¢´íÎó")
            return
        isCostItem = False #ÊÇ·ñʹÓÃÁËÎïÆ·
        if hasEnough:
            #ÓÅÏÈÓÃÎïÆ·
            isCostItem = True
            ItemCommon.ReduceItem(curPlayer, itemPack, itemList, 1, False)
        else:
            infoDict = {ChConfig.Def_Cost_Reason_SonKey:buyType}
            needGold = eval(GetExpPrayCost())
            GameWorld.DebugLog("ÐèÒªÏÉÓñ--needGold--%s" % needGold)
            if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, needGold, ChConfig.Def_Cost_Pray, infoDict):
                GameWorld.DebugLog("ÏÉÓñ²»×ã!costGold=%s" % needGold)
                return   
    
        reExp = lvMsg.GetReExp()
        exp = PlayerControl.GetLVUPTotalExpNeed(lvMsg)
        addExp = eval(GetExpPrayAward())
        PlayerControl.PlayerControl(curPlayer).AddExp(addExp)
        PlayerControl.NotifyCode(curPlayer, 'ExpPray_HowMuch', [addExp])
        if not isCostItem: #ÓÃÎïÆ·²»Ôö¼Ó´ÎÊý
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HasPrayCnt % buyType, curCnt + 1)
        PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_ExpPray, 1)
        PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_ExpPray)
    else:
        return
    EventShell.EventRespons_Pray(curPlayer, buyType)
    #³É¾Í
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Pray, 1, [buyType])
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_FeastRedPack_Pray, 1)
    
    # Ã¿Èջ
    PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_Pray)
    PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_Pray, 1)
    PlayerNewFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_Pray, 1)
    PlayerActLogin.AddLoginAwardActionCnt(curPlayer, ChConfig.Def_LoginAct_Pray, 1)
    PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_Pray, 1)
    PlayerFeastTravel.AddFeastTravelTaskValue(curPlayer, ChConfig.Def_FeastTravel_Pray, 1)
    Sync_NotifyDataChange(curPlayer, [buyType])
    return
 
#»ñÈ¡Ãâ·Ñ½ð±ÒÆíÔ¸CD
def __GetFreeCD(curPlayer):
    lastTime = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FreePrayTime)
    curTime = int(time.time())
    passTime = curTime - lastTime
    cdTime = IpyGameDataPY.GetFuncCfg("MoneyPray", 3)
    needTime = max(0, cdTime - passTime)
    return needTime
    
## OnDay²Ù×÷£¬Í¨Öª¿Í»§¶Ë£¬¹ºÂò´ÎÊý±äÁË
#  @param curPlayer: Íæ¼ÒʵÀý
#  @return None
def PlayerOnDay(curPlayer):
    needSyncList = []
    for prayType in TotalPrayList:
        hasPrayCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HasPrayCnt % prayType)
        if not hasPrayCnt:
            continue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HasPrayCnt % prayType, 0)
        needSyncList.append(prayType)
    Sync_NotifyDataChange(curPlayer, needSyncList)
    return
        
 
## Í¨Öª¿Í»§¶Ë£¬¹ºÂò´ÎÊý±äÁË
#  @param curPlayer: Íæ¼ÒʵÀý
#  @return None
def Sync_NotifyDataChange(curPlayer, prayType=[]):
    if prayType == []:
        prayList = TotalPrayList
    else:
        prayList = prayType
    pack = ChPyNetSendPack.tagMCBuySomething()
    for buyType in prayList:
        subPack = ChPyNetSendPack.tagMCSingleBuySomethingInfo()
        subPack.Type = buyType
        subPack.BuyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HasPrayCnt % buyType)
        subPack.HistoryBuyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HistoryPrayCnt % buyType)
        
        if buyType == ChConfig.VIPPrivilege_MoneyPray:
            subPack.LastFreeTime = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FreePrayTime)
        pack.Infos.append(subPack)
        GameWorld.DebugLog("֪ͨÆíÔ¸´ÎÊý--buyType:%s--BuyCnt:%s--LastFreeTime%s" % (subPack.Type, subPack.BuyCnt, subPack.LastFreeTime))
    pack.Cnt = len(pack.Infos)
    NetPackCommon.SendFakePack(curPlayer, pack)
    
 
## Íæ¼ÒµÇ¼ʱ֪ͨ
#  @param curPlayer: Íæ¼ÒʵÀý
#  @return None
def DoPlayerLogin(curPlayer):
    Sync_NotifyDataChange(curPlayer)
    return