hxp
2 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerCoat
#
# @todo:Íæ¼ÒʱװÍâÌ×
# @author xdh
# @date 2019-01-07
# @version 1.0
#
# ÏêϸÃèÊö: Íæ¼ÒʱװÍâÌ×
#
#---------------------------------------------------------------------
"""Version = 2019-01-07 10:00"""
#---------------------------------------------------------------------
 
import NetPackCommon
import IPY_GameWorld
import PlayerControl
import ItemControler
import ChPyNetSendPack
import ShareDefine
import ItemCommon
import DataRecordPack
import IpyGameDataPY
import GameWorld
import ChConfig
 
import math
 
## µÇ¼
#  @param curPlayer
#  @return None
def OnLogin_Coat(curPlayer):
    Sync_ClothesCoatSkinInfo(curPlayer)
    return
 
#// 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
    ipyData = IpyGameDataPY.GetIpyGameData('Coat', coatIndex)
    if not ipyData:
        return
    
    curSkinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatIndex)
    if curSkinLV >= ipyData.GetMaxLV():
        GameWorld.DebugLog("¸ÃʱװÒÑÂú¼¶£¬ÎÞ·¨Éý¼¶!coatIndex=%s,curSkinLV=%s" % (coatIndex, curSkinLV), playerID)
        return
    needCntList = ipyData.GetCostItemCnt()
    if curSkinLV >= len(needCntList):
        return
    plusCost = needCntList[curSkinLV]
    costItemID = ipyData.GetUnlockItemID()
    curPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    hasEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(costItemID, curPack, plusCost)
    if not hasEnough:
        GameWorld.DebugLog("OnPlayerCoatUp() Ê±×°Éý¼¶²ÄÁϲ»×ã, coatIndex=%s, costItemID=%s, needCnt=%s" % (coatIndex, costItemID, plusCost))
        return
 
    reduceCnt = plusCost
    aftlv = curSkinLV + 1
      
    #¿Û³ýÎïÆ·
    ItemCommon.ReduceItem(curPlayer, curPack, itemIndexList, reduceCnt, True, 'CoatUp')
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesSkinLV % coatIndex, aftlv)
       
    Sync_ClothesCoatSkinInfo(curPlayer, coatIndex)
    # Ë¢ÊôÐÔ
    CalcClothesCoatSkinAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    extraInfoDict = {"coatID":coatIndex}
    DataRecordPack.DR_ClassUpSystem(curPlayer, "CoatUp", aftlv, extraInfoDict)
    
    GameWorld.DebugLog("ʱװÉý¼¶!coatIndex=%s,curSkinLV=%s,reduceCnt=%s,aftlv=%s" 
                       % (coatIndex, curSkinLV, reduceCnt, aftlv), playerID)
    return
 
#// A5 20 Ê±×°·Ö½â #tagCMCoatDecompose
#
#struct    tagCMCoatDecompose
#{
#    tagHead        Head;
#    BYTE        Count;        //²ÄÁÏËùÔÚ±³°üË÷ÒýµÄÊýÁ¿
#    WORD        IndexList[Count];    //²ÄÁÏËùÔÚ±³°üË÷ÒýÁбí
#    DWORD        ItemIDList[Count];    //²ÄÁÏËùÔÚ±³°üÎïÆ·IDÁбí
#};
def OnCoatDecompose(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    indexList = clientData.IndexList
    ItemIDList = clientData.ItemIDList
 
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    addExp = 0
    for i, index in enumerate(indexList):
        eatItem = itemPack.GetAt(index)
        if not eatItem or eatItem.IsEmpty():
            continue
        eatItemID = eatItem.GetItemTypeID()
        if eatItemID != ItemIDList[i]:
            GameWorld.Log('ʱװ·Ö½â ·¢µÄÎïÆ·ID²»¶ÔÓ¦index=%s eatItemID=%s,ItemIDList[i]=%s'%(index, eatItemID, ItemIDList[i]), playerID)
            continue
        itemData = GameWorld.GetGameData().GetItemByTypeID(eatItemID)
        if not itemData:
            continue
        curEff = itemData.GetEffectByIndex(0)
        coatID = curEff.GetEffectValue(0)
        ipyData = IpyGameDataPY.GetIpyGameData('Coat', coatID)
        if not ipyData:
            continue
        curSkinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID)
        if curSkinLV < ipyData.GetMaxLV():
            continue
        itemCnt = eatItem.GetCount()
        addExp += itemCnt * curEff.GetEffectValue(1)
        ItemCommon.DelItem(curPlayer, eatItem, itemCnt, True, ChConfig.ItemDel_CoatDecompose)
    if not addExp:
        GameWorld.Log(' Ê±×°·Ö½â, Ã»ÓпɷֽâµÄItemIDList=%s'%ItemIDList, playerID)
        return
    totalExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestEXP) + addExp
    curChestLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestLV)
    updChestLV = curChestLV
    maxChestLV = IpyGameDataPY.IPY_Data().GetCoatChestUpByIndex(IpyGameDataPY.IPY_Data().GetCoatChestUpCount() - 1).GetLV()
    for chestLV in xrange(curChestLV + 1, maxChestLV + 1):
        ipyData = IpyGameDataPY.GetIpyGameData('CoatChestUp', chestLV)
        if not ipyData:
            break
        needExp = ipyData.GetNeedExp()
        if totalExp < needExp:
            break
        updChestLV = chestLV
        totalExp -= needExp
    if updChestLV != curChestLV:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesChestLV, updChestLV)
        # Ë¢ÊôÐÔ
        CalcClothesCoatSkinAttr(curPlayer)
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ClothesChestEXP, min(totalExp, ChConfig.Def_UpperLimit_DWord))
        
    Sync_ClothesCoatSkinInfo(curPlayer, coatID)
    return
 
def GetCoatQualityLVInfo(curPlayer):
    costQualityLVDict = {}
    ipyMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyMgr.GetCoatCount()):
        ipyData = ipyMgr.GetCoatByIndex(i)
        coatID = ipyData.GetCoatID()
        costQuality = ipyData.GetCostQuality()
        skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID)
        if not skinLV:
            continue
        costQualityLVDict[costQuality] = costQualityLVDict.get(costQuality, 0) + skinLV
    return costQualityLVDict
 
## ¼ÆËãʱװÊôÐÔ
#  @param curPlayer Íæ¼Ò
#  @param allAttrList ÊôÐÔÁбí
#  @return None
def CalcClothesCoatSkinAttr(curPlayer):
    initFPAdd = 0 #³õʼսÁ¦
    allAttrList = [{} for _ in range(4)]
    ipyMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyMgr.GetCoatCount()):
        ipyData = ipyMgr.GetCoatByIndex(i)
        coatID = ipyData.GetCoatID()
        skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID)
        if not skinLV:
            continue
        initFPAdd += ipyData.GetInitFightPower()
        starAttrDict = ipyData.GetStarAttr()
        if str(skinLV) not in starAttrDict:
            continue
        for attrID, attrValue in starAttrDict[str(skinLV)].items():
            PlayerControl.CalcAttrDict_Type(int(attrID), attrValue, allAttrList)
    #ʱװ¹ñÊôÐÔ
    curChestLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestLV)
    ipyData = IpyGameDataPY.GetIpyGameDataNotLog('CoatChestUp', curChestLV)
    if ipyData:
        for attrID, attrValue in ipyData.GetAddAttr().items():
            PlayerControl.CalcAttrDict_Type(int(attrID), attrValue, allAttrList)
    
    # ±£´æ¼ÆËãÖµ
    PlayerControl.SetMFPExFightPower(curPlayer, ShareDefine.Def_MFPType_Coat, initFPAdd)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Coat, allAttrList)
    return
 
 
##´©ÉÏ/ÍÑÏÂʱװ
# @param curPlayer Íæ¼ÒʵÀý
# @param srcBackpack Æðµã±³°ü
# @param desBackPack Ä¿±ê±³°ü
# @param srcIndex ÆðµãË÷Òý
# @param destIndex Ä¿±êË÷Òý
# @return 
def SwitchCoat(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex):
    clothesPlaceList = [6,7,8]#[ShareDefine.retWeaponSkin, ShareDefine.retClothesSkin, ShareDefine.retWeapon2Skin]
    if not ((desBackPack == IPY_GameWorld.rptEquip and srcBackpack == ShareDefine.rptTempSwap and destIndex in clothesPlaceList) \
    or (srcBackpack == IPY_GameWorld.rptEquip and desBackPack == ShareDefine.rptTempSwap and srcIndex in clothesPlaceList)):
        return False
    
    #===============================================================================================
    # # ²»¿ÉÒÔ½»»»Ê±×°
    # if curPlayer.GetMapID() in [ChConfig.Def_FBMapID_RedFort]:
    #    PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_422737")
    #    return True
    #===============================================================================================
    
    playerID = curPlayer.GetPlayerID()
    
    # ´©Ê±×°
    if desBackPack == IPY_GameWorld.rptEquip:
        # ´©µÄʱºòsrcIndex´ú±íʱװµÄË÷Òý
        skinLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV%srcIndex)
        if skinLV <= 0:
            GameWorld.Log("ʱװδ¼¤»î£¬²»ÄÜ´©£¡srcIndex=%s" % (srcIndex), playerID)
            return True
        ipyData = IpyGameDataPY.GetIpyGameData('Coat', srcIndex)
        if not ipyData:
            return True
        EquipItemIDList = ipyData.GetEquipItemID()
        job = curPlayer.GetJob()
        if job > len(EquipItemIDList):
            GameWorld.Log("ÕÒ²»µ½¸ÃְҵʱװÅäÖ㬲»ÄÜ´©£¡srcIndex=%s,job=%s" % (srcIndex, job), playerID)
            return True
        equipItemID = EquipItemIDList[job-1]
        # ÕÒµ½Ê±×°IDºó£¬srcIndexת»¯Îª½»»»ÎïÆ·µÄ¸ñ×ÓË÷Òý£¬Ä¬ÈÏ0
        srcIndex= 0
        
        # ¸øÁÙʱ½»»»ÎïÆ·
        if not ItemControler.PutItemInTempSwap(curPlayer, equipItemID):
            GameWorld.Log("ʱװID(%s)·ÅÈëÁÙʱ½»»»±³°üʧ°Ü!" % (equipItemID), playerID)
            return True
        
    # ÍÑʱװ
    else:
        ItemControler.ClearPack(curPlayer, ShareDefine.rptTempSwap)
        destIndex = 0
    
    isOK = ItemCommon.DoLogicSwitchItemEx(curPlayer, srcBackpack, desBackPack, srcIndex, destIndex)
    # Ï·¢ÖÜÎ§Íæ¼Òʱװ´©´÷״̬
    if isOK:
        if desBackPack == IPY_GameWorld.rptEquip:
            packIndex = IPY_GameWorld.rptEquip
            itemPlace = destIndex
            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(), srcIndex)
    GameWorld.DebugLog("SwitchCoat isOK=%s" % isOK)
    return True
 
 
## Í¨Öª¿Í»§¶Ëʱװ¿ªÆô״̬
#  @param curPlayer
#  @return None
def Sync_ClothesCoatSkinInfo(curPlayer, coatIndex= -1):
    stateData = ChPyNetSendPack.tagMCClothesCoatSkinState()
    stateData.Clear()
    stateData.CoatChestExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestEXP)
    stateData.CoatChestLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesChestLV)
    stateData.CoatInfoList = []
    if coatIndex == -1:
        coatIDList =[]
        ipyMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyMgr.GetCoatCount()):
            ipyData = ipyMgr.GetCoatByIndex(i)
            coatID = ipyData.GetCoatID()
            coatIDList.append(coatID)
    else:
        coatIDList = [coatIndex]
        
    for coatID in coatIDList:
        coatInfo = ChPyNetSendPack.tagMCClothesCoatLVInfo()
        coatInfo.Clear()
        coatInfo.CoatIndex = coatID
        coatInfo.CoatLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ClothesSkinLV % coatID)
        stateData.CoatInfoList.append(coatInfo)
    stateData.CoatNum = len(stateData.CoatInfoList)
    NetPackCommon.SendFakePack(curPlayer, stateData)
    return