hxp
2022-02-21 0c27822ef5e6c67782ed143a4ff03ecfbdfda1fb
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
#!/usr/bin/python
# -*- coding: GBK -*-
#
#
##@package PlayerCompensationTube.py
#
# @todo:GM²¹³¥¹ÜÀí µØÍ¼´¦Àí
#
# @author xmnathan
# @date 2010-01-01 10:00
# @version 1.4
# @note:
# @change: "2014-09-29 13:00" xmnathan GM²¹³¥¹ÜÀí
# @change: "2014-11-05 10:50" xmnathan Áìȡʧ°ÜÒ²»Ø°üGameServer£¬ÓÃÓÚÖØÖÃÁìȡ״̬
# @change: "2016-07-25 22:00" hxp Ôö¼ÓÁìÈ¡Óʼþʼþ»ã±¨
# @change: "2017-05-04 12:00" hxp Ôö¼Ó·ûÓ¡ÐéÄâ±³°üÖ§³Ö
#------------------------------------------------------------------------------ 
#"""Version = 2017-05-04 12:00"""
#------------------------------------------------------------------------------ 
import IPY_GameWorld
import GameWorld
import ShareDefine
import ChPyNetSendPack
import NetPackCommon
import ItemCommon
import ItemControler
import ChMapToGamePyPack
import ReadChConfig
import EventReport
import ChConfig
import PlayerControl
import IpyGameDataPY
import PlayerSuccess
import EventShell
 
import time
 
##A5 3B ÇëÇóÁìÈ¡²¹³¥#tagCMRequestCompensation
#  @param index, clientPack, tick
#  @return None
def OnCMRequestCompensation(index, clientPack, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    if not curPlayer:
        return
    GameWorld.DebugLog("#OnCMRequestCompensation in, PlayerID %s GUID %s"%(curPlayer.GetPlayerID(), clientPack.GUID))
    #±³°üûλÖÃ
    itemPackSpace = ItemControler.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
 
    #·¢ËÍÏà¹ØÊý¾Ý
    sendPack = ChMapToGamePyPack.tagMGRequestCompensation()
    sendPack.GUID = clientPack.GUID
    sendPack.PlayerID = curPlayer.GetPlayerID()
    sendPack.PackSpaceCount = itemPackSpace
    NetPackCommon.SendPyPackToGameServer(sendPack)
    return
 
 
##03 02 Íæ¼ÒÁìÈ¡²¹³¥½á¹û#tagGMRequestCompensationResult
#  @param curPackData, tick
#  @return None
def OnGMRequestCompensationResult(curPackData, tick):
    GameWorld.DebugLog("OnGMRequestCompensationResult in")
    
    curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(curPackData.PlayerID)
    if not curPlayer:
        #·¢ËÍÏà¹ØÊý¾Ý  »Ø±¨²¹³¥·¢·Å½á¹û
        sendPack = ChMapToGamePyPack.tagMGGiveCompensationResult()
        sendPack.GUID = curPackData.GUID
        sendPack.PlayerID = curPackData.PlayerID
        sendPack.CompensationType = curPackData.CompensationType
        sendPack.Result = 0
        NetPackCommon.SendPyPackToGameServer(sendPack)
        GameWorld.DebugLog("    PlayerID %s no found "%curPackData.PlayerID)
        return
    
    hasAuctionItem = False
    needPackSpaceDict = {}
    isPackSpaceEnough = True
    # ÏÈ»ã×ÜÎïÆ·ËùÊô±³°ü
    for i in xrange(curPackData.Count):
        curPackItem = curPackData.Items[i]
        itemID = curPackItem.ItemID
        curItemData = GameWorld.GetGameData().GetItemByTypeID(itemID)
        if not curItemData:
            continue
        
        isAuctionItem = curPackItem.IsBind
        packType = ChConfig.GetItemPackType(curItemData)
        needSpace = ItemControler.GetItemNeedPackCount(packType, curItemData, curPackItem.Count, isAuctionItem)
        needPackSpaceDict[packType] = needPackSpaceDict.get(packType, 0) + needSpace
        if isAuctionItem:
            hasAuctionItem = True
            
    GameWorld.DebugLog("    hasAuctionItem=%s,needPackSpaceDict=%s" % (hasAuctionItem, needPackSpaceDict))
    for packType, needSpace in needPackSpaceDict.items():
        if needSpace > ItemCommon.GetItemPackSpace(curPlayer, packType, needSpace):
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [packType])
            isPackSpaceEnough = False
            break
        
    auctionItemTimeout = False
    auctionItemCreateTime = 0
    # 20201223 Ö÷¸ÉÈ¡ÏûÅÄÆ·ÓÐЧʱ³¤É趨
#    if hasAuctionItem:
#        auctionItemValidTimesMax = IpyGameDataPY.GetFuncCfg("AuctionItem", 1) * 3600 # ÅÄÆ·ÓÐЧʱ³¤
#        auctionItemValidTimesMail = IpyGameDataPY.GetFuncCfg("AuctionItem", 2) * 3600 # ÓʼþÅÄÆ·¸½¼ÓÓÐЧʱ³¤
#        auctionItemValidTimesTotal = auctionItemValidTimesMail + auctionItemValidTimesMax
#        mailCreateTimeStr = curPackData.CreateTime
#        mailCreateTime = GameWorld.ChangeTimeStrToNum(mailCreateTimeStr)
#        curTime = int(time.time())
#        passTime = curTime - mailCreateTime
#        if passTime <= auctionItemValidTimesMail:
#            GameWorld.DebugLog("ÓʼþÅÄÆ·Áìȡʱ¼äÔÚ¸½¼Ó±£»¤Ê±³¤ÄÚ£¬ÅÄÆ·´´½¨Ê±¼ä¼´ÁìÈ¡Óʼþʱ¼ä¿ªÊ¼Ëã!passTime(%s) <= auctionItemValidTimesMail(%s)" % (passTime, auctionItemValidTimesMail))
#            pass
#        elif auctionItemValidTimesMail < passTime < auctionItemValidTimesTotal:
#            auctionItemCreateTime = curTime - (passTime - auctionItemValidTimesMail)
#            GameWorld.DebugLog("ÓʼþÅÄÆ·Áìȡʱ¼ä³¬¹ýÓʼþ±£»¤Ê±¼ä£¬ÅÄÆ·´´½¨Ê±¼äÐè¿Û³ýÁìȡʱµÄÒç³öʱ¼ä!auctionItemValidTimesMail(%s) < passTime(%s) < auctionItemValidTimesTotal(%s), auctionItemCreateTime=%s" 
#                               % (auctionItemValidTimesMail, passTime, auctionItemValidTimesTotal, GameWorld.ChangeTimeNumToStr(auctionItemCreateTime)))
#        elif passTime >= auctionItemValidTimesMax:
#            auctionItemTimeout = True
#            GameWorld.DebugLog("ÓʼþÖеÄÅÄÆ·ÒѹýÆÚ£¬½«×Ô¶¯×ªÎª·ÇÅÄÆ·!passTime(%s) >= auctionItemValidTimesMax(%s)" 
#                               % (passTime, auctionItemValidTimesMax))
            
    #±³°ü¿Õ¼ä²»×ã
    if not isPackSpaceEnough:
        GameWorld.DebugLog("    itemPack no space")
        sendMCPack = ChPyNetSendPack.tagMCGiveCompensationResult()
        sendMCPack.GUID = curPackData.GUID
        sendMCPack.Result = 0
        NetPackCommon.SendFakePack(curPlayer, sendMCPack)
        #·¢ËÍÏà¹ØÊý¾Ý  »Ø±¨²¹³¥·¢·Å½á¹û
        sendPack = ChMapToGamePyPack.tagMGGiveCompensationResult()
        sendPack.GUID = curPackData.GUID
        sendPack.PlayerID = curPackData.PlayerID
        sendPack.CompensationType = curPackData.CompensationType
        sendPack.Result = 0
        NetPackCommon.SendPyPackToGameServer(sendPack)
        return
    
    Text = curPackData.Text
    _, _, content = Text.split("<$_$>")
    isPaimaiMail = "<MailTemplate>PaimaiMail3</MailTemplate>" in content
    
    for i in xrange(curPackData.Count):
        curPackItem = curPackData.Items[i]
        itemID = curPackItem.ItemID
        isAuctionItem = curPackItem.IsBind and not auctionItemTimeout
        if ItemControler.GetAppointItemRealID(itemID):
            curCreateItem = ItemControler.GetItemByData(ItemControler.GetAppointItemDictData(itemID, isAuctionItem))
        else:
            curCreateItem = ItemCommon.CreateSingleItem(itemID, curPackItem.Count, isAuctionItem)
        if not curCreateItem:
            GameWorld.ErrLog("OnGMRequestCompensationResult CreateSingleItem %s Err "%itemID)
            continue
        
        ##UserData°üº¬ÁË×·¼ÓÊôÐÔ²»ÍêÕû£¬ÕâÀïÐèÒª²¹Æë
        userDataCreateTime = 0
        if curPackItem.UserDataLen: 
            UserDataDict = eval(curPackItem.UserData)
            #ÉèÖÃUserData
            UserData = "%s"%UserDataDict
            curCreateItem.SetUserData(UserData, len(UserData))
            userDataCreateTime = curCreateItem.GetUserAttr(ShareDefine.Def_IudetAuctionItemCreateTime)
            
        if isAuctionItem and auctionItemCreateTime and not userDataCreateTime:
            curCreateItem.SetUserAttr(ShareDefine.Def_IudetAuctionItemCreateTime, auctionItemCreateTime)
            
        ItemCommon.MakeEquipGS(curCreateItem)
        
        if isPaimaiMail and ItemCommon.CheckItemIsEquip(curCreateItem):
            EventShell.EventRespons_BuyAuctionEquip(curPlayer, curCreateItem.GetItemColor())
            
        #·ÅÈëÍæ¼Ò±³°ü
        ItemControler.PlayerItemControler(curPlayer).PutInItem(IPY_GameWorld.rptItem, curCreateItem, 
                                                               event=[ChConfig.ItemGive_Mail, False, {"MailGUID":curPackData.GUID}])
    moneySource = curPackData.MoneySource + ChConfig.Def_GiveMoney_Unknown # ´æÖµÊ±ÎªbyteÀàÐÍ£¬Ê¹ÓÃʱÐ軹ԭ»ØÀ´
    if curPackData.Gold != 0:
        PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, curPackData.Gold, moneySource)
    
    if curPackData.GoldPaper != 0:
        PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Paper, curPackData.GoldPaper, moneySource)
    
    if curPackData.Silver != 0:
        PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, curPackData.Silver, moneySource)
    
    #·¢ËÍÏà¹ØÊý¾Ý  »Ø±¨²¹³¥·¢·Å½á¹û
    sendPack = ChMapToGamePyPack.tagMGGiveCompensationResult()
    sendPack.GUID = curPackData.GUID
    sendPack.PlayerID = curPackData.PlayerID
    sendPack.CompensationType = curPackData.CompensationType
    sendPack.Result = 1
    NetPackCommon.SendPyPackToGameServer(sendPack)
    #¸æË߿ͻ§¶Ë²¹³¥ÒÑÁìÈ¡
    sendMCPack = ChPyNetSendPack.tagMCGiveCompensationResult()
    sendMCPack.GUID = curPackData.GUID
    sendMCPack.Result = 1
    NetPackCommon.SendFakePack(curPlayer, sendMCPack)
    
    #<MailTemplate>Ä£°å±àºÅ</MailTemplate>[%s,%s]
    lSign, rSign = "<MailTemplate>", "</MailTemplate>"
    if lSign in content and rSign in content:
        mailKey = content[content.index(lSign) + len(lSign):content.index(rSign)]
        try:
            mailParamList = eval(content[content.index(rSign) + len(rSign):])
        except:
            mailParamList = []
        if mailKey in ["CrossBattlefieldEnterOrderWeek", "CrossBattlefieldCallOrderWeek", "CrossBattlefieldScoreOrderWeek"]:
            GameWorld.DebugLog("¹ÅÉñÕ½³¡ÖܰñÓʼþ´¦Àí³É¾Í: mailKey=%s,mailParamList=%s" % (mailKey, mailParamList), curPlayer.GetPlayerID())
            if mailParamList and mailParamList[0] == 1:
                PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_BillFirst, 1)
            PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_BillIn, 1)
            
    #===========================================================================
    # #ÁìÈ¡²¹³¥Ê¼þ¼Ç¼
    # Text = curPackData.Text
    # #%s<$_$>%s
    # sender, title, content = Text.split("<$_$>")
    # #<MailTemplate>Ä£°å±àºÅ</MailTemplate>[%s,%s]
    # if "</MailTemplate>" in content:
    #    mailContentList = content.split("</MailTemplate>")
    #    mailTemplateNO = GameWorld.ToIntDef(mailContentList[0][14:], None)
    #    EventMailInfo = ReadChConfig.GetEvalChConfig("EventMailInfo")
    #    if mailTemplateNO not in EventMailInfo:
    #        return
    #    title, content = EventMailInfo[mailTemplateNO]
    #    
    #    mailParamStr = mailContentList[1]
    #    mailParamStr = mailParamStr.replace(" ", "")
    #    if mailParamStr.startswith("[") and mailParamStr.endswith("]") and len(mailParamStr) > 2:
    #        content = content % tuple(eval(mailParamStr))
    #    
    # comments = "%s: %s, %s; %s" % (title, curPackData.GUID, eventItemInfo, content)
    # EventReport.WriteEvent_custom_events(curPlayer, EventReport.Def_Custom_Events_GetMail, comments)
    #===========================================================================
    return