hxp
2025-05-30 8a445fc0209a334d0d5e263d6986328d965c668f
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerLuckyCloudBuy
#
# @todo:ÐÒÔËÔÆ¹º
# @author hxp
# @date 2021-10-21
# @version 1.0
#
# ÏêϸÃèÊö: ÐÒÔËÔÆ¹º
#
#-------------------------------------------------------------------------------
#"""Version = 2021-10-21 17:00"""
#-------------------------------------------------------------------------------
 
import ChConfig
import PyGameData
import ShareDefine
import PlayerControl
import IpyGameDataPY
import CrossRealmPlayer
import ChPyNetSendPack
import IPY_GameWorld
import NetPackCommon
import ItemControler
import ItemCommon
import GameWorld
 
def OnPlayerLogin(curPlayer):
    
    if GameWorld.IsCrossServer():
        return
    
    if not CrossRealmPlayer.IsCrossServerOpen():
        return
    
    __CheckLuckyCloudBuyID(curPlayer)
    Sync_LuckyCloudBuyPlayerInfo(curPlayer)
    return
 
def OnLuckyCloudBuyChange():
    
    if GameWorld.IsCrossServer():
        return
    
    if not CrossRealmPlayer.IsCrossServerOpen():
        return
    
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckLuckyCloudBuyID(curPlayer)
        Sync_LuckyCloudBuyPlayerInfo(curPlayer) # ¸Ã¹¦ÄÜÊÕµ½¾Íͬ²½£¬²»ÂÛÓÐûÓÐÖØÖã¬ÒòΪ¿ÉÄÜÓÉ¿ç·þ¹Ø±Õ±äΪ¿ªÆôʱµÄÊý¾Ýͬ²½
        
    return
 
def __CheckLuckyCloudBuyID(curPlayer):
    
    roundID = PyGameData.g_luckyCloudBuyInfo.get("idTime", 0)
    playerRoundID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_RoundID) # Íæ¼ÒÉíÉϵĻID
    if playerRoundID == roundID:
        GameWorld.DebugLog("ÐÒÔËÔÆ¹º½±ÀøÆÚIDÏàͬ£¬²»ÖØÖÃ! playerRoundID=%s,roundID=%s" % (playerRoundID, roundID), curPlayer.GetPlayerID())
        return
    GameWorld.DebugLog("ÐÒÔËÔÆ¹º½±ÀøÆÚID±ä¸ü£¬ÖØÖÃ! playerRoundID=%s,roundID=%s" % (playerRoundID, roundID), curPlayer.GetPlayerID())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LuckyCloudBuy_RoundID, roundID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LuckyCloudBuy_BuyCount, 0)
    return True
 
#// C1 10 ÐÒÔËÔÆ¹º¹ºÂò #tagCMLuckyCloudBuy
#
#struct    tagCMLuckyCloudBuy
#{
#    tagHead        Head;
#    BYTE        BuyCount;    // ¹ºÂò´ÎÊý
#};
def OnLuckyCloudBuy(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    accID = curPlayer.GetAccID()
    playerID = curPlayer.GetPlayerID()
    buyCount = clientData.BuyCount
    
    if GameWorld.IsCrossServer():
        return
    
    if not CrossRealmPlayer.IsCrossServerOpen():
        PlayerControl.NotifyCode(curPlayer, "CrossMatching18")
        return
    
    unLimitHour, unLimitMinute = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 3)
    crossServerDateTime = GameWorld.ChangeStrToDatetime(GameWorld.GetCrossServerTimeStr())
    unLimitDateTime = GameWorld.ChangeStrToDatetime("%d-%d-%d %d:%d:00" \
                                % (crossServerDateTime.year, crossServerDateTime.month, crossServerDateTime.day, unLimitHour, unLimitMinute))
    
    if crossServerDateTime >= unLimitDateTime:
        GameWorld.DebugLog("µ±Ç°¿ç·þ·þÎñÆ÷ʱ¼ä²»ÏÞÖÆÐÒÔËÔÆ¹º¹ºÂò´ÎÊýÁË! crossServerDateTime=%s,unLimitHour=%s,unLimitMinute=%s" 
                           % (crossServerDateTime, unLimitHour, unLimitMinute))
    else:
        hadBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_BuyCount)
        vipLV = curPlayer.GetVIPLv()
        gmLVLimitBuyCountList = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 2)
        maxBuyCount = gmLVLimitBuyCountList[vipLV] if len(gmLVLimitBuyCountList) > vipLV else gmLVLimitBuyCountList[-1]
        if hadBuyCount + buyCount > maxBuyCount:
            GameWorld.DebugLog("ÐÒÔËÔÆ¹º¹ºÂò´ÎÊýÏÞÖÆ! hadBuyCount=%s,buyCount=%s,vipLV=%s,maxBuyCount=%s,crossServerDateTime=%s" 
                               % (hadBuyCount, buyCount, vipLV, maxBuyCount, crossServerDateTime))
            return
        
    buyCountCostMoneyDict = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 1, {})
    if str(buyCount) not in buyCountCostMoneyDict:
        return
    costMoneyType, costMoneyValue = buyCountCostMoneyDict[str(buyCount)]
    if not PlayerControl.HaveMoney(curPlayer, costMoneyType, costMoneyValue):
        return
    
    needSpace = min(buyCount, 10)
    emptySpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
    if needSpace > emptySpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_202580")
        return
    
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_LuckyCloudBuy, tick):
        PlayerControl.NotifyCode(curPlayer, "RequestLater")
        return
    
    GameWorld.Log("ÐÒÔËÔÆ¹º¹ºÂò: buyCount=%s" % (buyCount), playerID)
    
    dataMsg = {"accID":accID,
               "playerID":playerID,
               "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),
               "buyCount":buyCount,
               "roundID":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_RoundID),
               }
    GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_LuckyCloudBuy, dataMsg)
    return
 
def GameServer_LuckyCloudBuy(curPlayer, msgData):
    msgType = msgData[0]
    if msgType == "LuckyCloudBuyNum":
        CrossServerMsg_LuckyCloudBuyNum(curPlayer, msgData)
        
    return
 
def CrossServerMsg_LuckyCloudBuyNum(curPlayer, msgData):
        
    playerID = curPlayer.GetPlayerID()
    _, roundID, buyCount, awardItemList = msgData
    
    # ÏûºÄÇ®¼°½±Àø±ØÐëÖ´ÐУ¬Ôö¼Ó´ÎÊýÐèͬһ¸öÂÖ´ÎID
    playerRoundID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_RoundID)
    hadBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_BuyCount)
    GameWorld.Log("µØÍ¼Íæ¼ÒÊÕµ½ÐÒÔËÔÆ¹º¹ºÂò½áËãÐÅÏ¢! playerRoundID=%s,hadBuyCount=%s, roundID=%s,buyCount=%s" 
                  % (playerRoundID, hadBuyCount, roundID, buyCount), playerID)
    
    buyCountCostMoneyDict = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 1, {})
    if str(buyCount) not in buyCountCostMoneyDict:
        return
    costMoneyType, costMoneyValue = buyCountCostMoneyDict[str(buyCount)]
    
    if not PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, "LuckyCloudBuy"):
        return
    
    if roundID == playerRoundID:
        updBuyCount = hadBuyCount + buyCount
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LuckyCloudBuy_BuyCount, updBuyCount)
        GameWorld.Log("    ¸üÐÂÐÒÔËÔÆ¹º¹ºÂò´ÎÊý: updBuyCount=%s" % (updBuyCount), playerID)
        
    GameWorld.Log("    ½áËãÐÒÔËÔÆ¹º¹ºÂò½±Àø: awardItemList=%s" % str(awardItemList), playerID)
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["LuckyCloudBuy", False, {}])
    
    Sync_LuckyCloudBuyPlayerInfo(curPlayer)
    return
 
def Sync_LuckyCloudBuyPlayerInfo(curPlayer):
    clientPack = ChPyNetSendPack.tagMCLuckyCloudBuyPlayerInfo()
    clientPack.BuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_BuyCount)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return