xdh
2018-08-21 80f11b590ece01d82d2af052876366bd2c1df2eb
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerCoat
#
# @todo:Íæ¼ÒʱװÍâÌ×
# @author hxp
# @date 2015-6-15
# @version 1.1
#
# @change: "2015-08-10 10:00" ljd Ï·¢ÖÜÎ§Íæ¼Òʱװ´©´÷״̬
# ÏêϸÃèÊö: Íæ¼ÒʱװÍâÌ×
#
#---------------------------------------------------------------------
"""Version = 2015-08-10 10:00"""
#---------------------------------------------------------------------
 
import ReadChConfig
import NetPackCommon
import IPY_GameWorld
import PlayerControl
import ItemControler
import ChPyNetSendPack
import ShareDefine
import ItemCommon
import EventReport
import GameWorld
import ChConfig
import ChEquip
 
import math
 
## µÇ¼
#  @param curPlayer
#  @return None
def OnLogin_Coat(curPlayer):
    Sync_ClothesCoatSkinInfo(curPlayer)
    return
 
 
## ¼¤»îʱװÒ·þƤ·ô
#  @param curPlayer
#  @return None
def ActivateClothesCoatSkinItem(curPlayer, clothesCoatSkinID):
    
    playerID = curPlayer.GetPlayerID()
    
    clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin")
    if clothesCoatSkinID not in clothesCoatSkinDict:
        GameWorld.ErrLog("¼¤»îʱװƤ·ôÒì³££¬ÎÞ¸ÃʱװƤ·ôÎïÆ·ÐÅÏ¢£¡ClothesCoatSkin.txt! ID=%s" % clothesCoatSkinID, playerID)
        return False
    
    clotherSkinInfo = clothesCoatSkinDict[clothesCoatSkinID]
    if not clotherSkinInfo:
        return False
 
    curSkinIndex = clotherSkinInfo[0]
    skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState)
    curSkinState = skinOpenState & pow(2, curSkinIndex)
    
    if curSkinState:
#        GameWorld.Log("¸ÃʱװƤ·ôÒѾ­¼¤»î¹ý£¡clothesCoatSkinID=%s,index=%s,skinOpenState=%s" 
#                      % (clothesCoatSkinID, curSkinIndex, skinOpenState), playerID)
#        PlayerControl.NotifyCode(curPlayer, "GeRen_hgg_850801")
        #µ±Ê¹ÓÃÒѼ¤»î¹ýµÄʱװ¼¤»îµÀ¾ßʱ£¬½«»ñµÃÒ»¶¨ÊýÁ¿µÄÎïÆ· ·µ»ØTure¿Û³ýÎïÆ·
        clothesCoatUpDict = ReadChConfig.GetEvalChConfig("ClothesCoatUp")
        if curSkinIndex not in clothesCoatUpDict:
            PlayerControl.NotifyCode(curPlayer, "GeRen_hgg_850801")
            return False
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, 1)
        if packSpace < 1:
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
            return False
        itemId, getItemCntList = clothesCoatUpDict[curSkinIndex]
        if not getItemCntList:
            return False
        getItemCnt = getItemCntList[0]
        
        packIndexList = [IPY_GameWorld.rptItem]
        ItemControler.GivePlayerItem(curPlayer, itemId, getItemCnt, True, packIndexList, True, showSysInfo=True)
        return True
 
    isOK = ItemControler.PutItemInTempSwap(curPlayer, clothesCoatSkinID)
    if not isOK:
        GameWorld.Log("ʱװ·ÅÈëÁÙʱ½»»»±³°üʧ°Ü£¡", playerID)
        return False
 
    #===========================================================================
    # # »ñµÃ·ÅÈëµÄʱװ
    # clothesItem = ItemCommon.FindItemInPackByItemID(curPlayer, clothesCoatSkinID,
    #                                                ShareDefine.rptTempSwap)
    # if not clothesItem:
    #    return False
    # 
    # tick = GameWorld.GetGameWorld().GetTick()
    # ChEquip.DoPlayerEquipItem(curPlayer, clothesItem, IPY_GameWorld.retClothesCoat, tick)
    #===========================================================================
    
    # ¸üлû¯×´Ì¬
    updSkinOpenState = skinOpenState | pow(2, curSkinIndex)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinOpenState, updSkinOpenState)
    Sync_ClothesCoatSkinInfo(curPlayer, curSkinIndex)
    GameWorld.Log("ʱװ¼¤»î³É¹¦£¡clothesCoatSkinID=%s,index=%s,skinOpenState=%s,updSkinOpenState=%s" 
                  % (clothesCoatSkinID, curSkinIndex, skinOpenState, updSkinOpenState), playerID)
 
    # Ë¢ÊôÐÔ
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    ClothesCoaSkinNotifyDict = ReadChConfig.GetEvalChConfig("ClothesCoaSkinNotify")
    if clothesCoatSkinID in ClothesCoaSkinNotifyDict:
        notifyMark = ClothesCoaSkinNotifyDict[clothesCoatSkinID]
        PlayerControl.WorldNotify(0, notifyMark, [curPlayer.GetPlayerName(), clothesCoatSkinID])
        
    return True
 
 
#// A5 0B Íæ¼ÒʱװÉý¼¶ #tagCMCoatUp
#
#struct    tagCMCoatUp
#{
#    tagHead        Head;
#    BYTE        CoatIndex; // Ê±×°Ë÷Òý
#};
def OnPlayerCoatUp(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    coatIndex = clientData.CoatIndex
    clothesCoatUpDict = ReadChConfig.GetEvalChConfig("ClothesCoatUp")
    if coatIndex not in clothesCoatUpDict:
        GameWorld.DebugLog("clothesCoatUpDict.txt Î´ÅäÖøÃË÷Òý coatIndex=%s" % (coatIndex), playerID)
        return
    
    skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState)
    if not skinOpenState & pow(2, coatIndex):
        GameWorld.DebugLog("¸Ãʱװδ¼¤»î, ÎÞ·¨Éý¼¶! coatIndex=%s" % (coatIndex), playerID)
        return
    costItemID, needCntList = clothesCoatUpDict[coatIndex]
    
    curSkinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatIndex)
 
    
    if curSkinLV >= len(needCntList) - 1:
        GameWorld.DebugLog("¸ÃʱװÒÑÂú¼¶£¬ÎÞ·¨Éý¼¶!coatIndex=%s,curSkinLV=%s" % (coatIndex, curSkinLV), playerID)
        return
    plusCost = needCntList[curSkinLV + 1]
    curBless = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % coatIndex)
    lackCnt = plusCost - curBless
    
    curPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    hasEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(costItemID, curPack, lackCnt)
    if not itemIndexList:
        GameWorld.DebugLog("OnPlayerCoatUp() Ê±×°Éý¼¶²ÄÁϲ»×ã, needCnt=%s" % (lackCnt))
        return
    if hasEnough:
        reduceCnt = lackCnt
        aftBless = 0 #Éý¼¶ºóµÄ¾­ÑéÖµ
        aftlv = curSkinLV + 1
    else:
        reduceCnt = 0
        for itemIndex in itemIndexList:
            curItem = curPack.GetAt(itemIndex)
            itemCount = curItem.GetCount()
            reduceCnt += itemCount
            
        aftBless = curBless + reduceCnt
        aftlv = curSkinLV
        
    #¿Û³ýÎïÆ·
    ItemCommon.ReduceItem(curPlayer, curPack, itemIndexList, reduceCnt, True)
    if aftlv != curSkinLV:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinLV % coatIndex, aftlv)
    if aftBless != curBless:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinCurBless % coatIndex, aftBless)
    
    Sync_ClothesCoatSkinInfo(curPlayer, coatIndex)
    # Ë¢ÊôÐÔ
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    clothesID = GetClothesIDByIndex(coatIndex)
    itemData = GameWorld.GetGameData().GetItemByTypeID(clothesID)
    coatName = clothesID if not itemData else itemData.GetName()
    EventReport.WriteEvent_coat_lv(curPlayer, coatName, curSkinLV, curBless, reduceCnt, aftlv, aftBless)
    GameWorld.DebugLog("ʱװÉý¼¶!coatIndex=%s,coatName=%s,curSkinLV=%s,curBless=%s,reduceCnt=%s,aftlv=%s,aftBless=%s" 
                       % (coatIndex, coatName, curSkinLV, curBless, reduceCnt, aftlv, aftBless), playerID)
    return
 
 
## ¼ÆËãʱװÊôÐÔ
#  @param curPlayer Íæ¼Ò
#  @param allAttrList ÊôÐÔÁбí
#  @return None
def CalcClothesCoatSkinAttr(curPlayer, allAttrList):
    skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState)
    
    if not skinOpenState:
        return
    
    clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin")
    clothesCoatUpDict = ReadChConfig.GetEvalChConfig("ClothesCoatUp")
    for clothesInfo in clothesCoatSkinDict.values():
        curIndex, attrDict = clothesInfo
        
        if not skinOpenState & pow(2, curIndex):
            continue
        skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % curIndex)
        curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % curIndex)
        if curIndex not in clothesCoatUpDict:
            expPer = 0
        else:
            itemCntList = clothesCoatUpDict[curIndex][1]
            maxExp = itemCntList[skinLV + 1] if skinLV + 1 < len(itemCntList) else 0
            expPer = float(curExp) / maxExp if maxExp != 0 else 0
        for attrName, attrLVList in attrDict.items():
            attrValue = attrLVList[skinLV] if skinLV < len(attrLVList) else attrLVList[-1]
            nextValue = attrLVList[skinLV + 1] if skinLV + 1 < len(attrLVList) else attrLVList[-1]
            addValue = int(math.ceil((nextValue-attrValue) * expPer))
            PlayerControl.CalcAttrDict_Type(attrName, attrValue + addValue, allAttrList)
            GameWorld.DebugLog('    Ê±×°ÊôÐÔcurIndex=%s attrName=%s,expPer=%s,attrValue=%s,addValue=%s' % (curIndex, attrName, expPer, attrValue, addValue))
        
    return
 
 
##´©ÉÏ/ÍÑÏÂʱװ
# @param curPlayer Íæ¼ÒʵÀý
# @param srcBackpack Æðµã±³°ü
# @param desBackPack Ä¿±ê±³°ü
# @param srcIndex ÆðµãË÷Òý
# @param destIndex Ä¿±êË÷Òý
# @return 
def SwitchCoat(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex):
    if not ((desBackPack == IPY_GameWorld.rptEquip and srcBackpack == ShareDefine.rptTempSwap and destIndex == IPY_GameWorld.retClothesCoat) \
    or (srcBackpack == IPY_GameWorld.rptEquip and desBackPack == ShareDefine.rptTempSwap and srcIndex == IPY_GameWorld.retClothesCoat)):
        return False
    
    #===============================================================================================
    # # ²»¿ÉÒÔ½»»»Ê±×°
    # if curPlayer.GetMapID() in [ChConfig.Def_FBMapID_RedFort]:
    #    PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_422737")
    #    return True
    #===============================================================================================
    
    playerID = curPlayer.GetPlayerID()
    clothesIndex = IPY_GameWorld.retClothesCoat
    
    # ´©Ê±×°
    if desBackPack == IPY_GameWorld.rptEquip:
        # ´©µÄʱºòsrcIndex´ú±íʱװµÄË÷Òý
        skinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState)
        if not skinOpenState & pow(2, srcIndex):
            GameWorld.Log("ʱװδ¼¤»î£¬²»ÄÜ´©£¡state=%s,srcIndex=%s" % (skinOpenState, srcIndex), playerID)
            return True
        
        findSwichClothesID = GetClothesIDByIndex(srcIndex)
            
        if findSwichClothesID <= 0:
            GameWorld.Log("ÕÒ²»µ½Ê±×°ID£¬²»ÄÜ´©£¡srcIndex=%s" % (srcIndex), playerID)
            return True
        
        # ÕÒµ½Ê±×°IDºó£¬srcIndexת»¯Îª½»»»ÎïÆ·µÄ¸ñ×ÓË÷Òý£¬Ä¬ÈÏ0
        srcIndex, destIndex = 0, clothesIndex
        
        # ¸øÁÙʱ½»»»ÎïÆ·
        if not ItemControler.PutItemInTempSwap(curPlayer, findSwichClothesID):
            GameWorld.Log("ʱװID(%s)·ÅÈëÁÙʱ½»»»±³°üʧ°Ü!" % (findSwichClothesID), playerID)
            return True
        
    # ÍÑʱװ
    else:
        ItemControler.ClearPack(curPlayer, ShareDefine.rptTempSwap)
        srcIndex, destIndex = clothesIndex, 0
    
    isOK = ItemCommon.DoLogicSwitchItemEx(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex)
    # Ï·¢ÖÜÎ§Íæ¼Òʱװ´©´÷״̬
    if isOK:
        if desBackPack == IPY_GameWorld.rptEquip:
            packIndex = IPY_GameWorld.rptEquip
            itemPlace = IPY_GameWorld.retClothesCoat
            itemPack = curPlayer.GetItemManager().GetPack(packIndex)
            curItem = itemPack.GetAt(itemPlace)
            itemId = curItem.GetItemTypeID()
            itemStarLV = 0#curItem.GetItemStarLV()
            itemHoleCnt = 0#curItem.GetCanPlaceStoneCount()
            itemStoneCnt = 0#curItem.GetUseStoneCount()
            itemUseData = curItem.GetUserData()
            curPlayer.ChangeEquip(itemId, itemPlace, itemStarLV, itemHoleCnt, itemStoneCnt, itemUseData)
        else:
            packIndex = ShareDefine.rptTempSwap
            itemPack = curPlayer.GetItemManager().GetPack(packIndex)
            curItem = itemPack.GetAt(0)
            if curItem:
                curPlayer.Sync_UnEquipItem(curItem.GetItemTypeID(), IPY_GameWorld.retClothesCoat)
    GameWorld.DebugLog("SwitchCoat isOK=%s" % isOK)
    return True
 
## ¸ù¾ÝË÷Òý»ñȡװ±¸Ê±×°ID
def GetClothesIDByIndex(coatIndex):
    findSwichClothesID = 0
    clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin")
    for clothesID, clothesInfo in clothesCoatSkinDict.items():
        index = clothesInfo[0]
        if index == coatIndex:
            findSwichClothesID = clothesID
            break
    return findSwichClothesID
 
## Í¨Öª¿Í»§¶Ëʱװ¿ªÆô״̬
#  @param curPlayer
#  @return None
def Sync_ClothesCoatSkinInfo(curPlayer, coatIndex= -1):
    stateData = ChPyNetSendPack.tagMCClothesCoatSkinState()
    stateData.Clear()
    stateData.SkinOpenState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinOpenState)
    stateData.CoatInfoList = []
 
    if coatIndex == -1:
        clothesCoatSkinDict = ReadChConfig.GetEvalChConfig("ClothesCoatSkin")
        for index in range(len(clothesCoatSkinDict)):
            coatInfo = ChPyNetSendPack.tagMCClothesCoatLVInfo()
            coatInfo.Clear()
            coatInfo.CoatIndex = index
            coatInfo.CoatLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % index)
            coatInfo.CoatExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % index)
            stateData.CoatInfoList.append(coatInfo)
    else:
        coatInfo = ChPyNetSendPack.tagMCClothesCoatLVInfo()
        coatInfo.Clear()
        coatInfo.CoatIndex = coatIndex
        coatInfo.CoatLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatIndex)
        coatInfo.CoatExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinCurBless % coatIndex)
        stateData.CoatInfoList.append(coatInfo)
    
    stateData.CoatNum = len(stateData.CoatInfoList)
    NetPackCommon.SendFakePack(curPlayer, stateData)
    return