hch
2018-09-20 a8d160566fcad719e98b6ac1ad6354fb6ddb1dc5
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------------------
##@package Operate_EquipSuitCompose.py
# @todo: Ì××°ºÏ³É
#
# @author: xdh
# @date 2017-08-15
# @version 1.0
#
## ÏêϸÃèÊö
#
#
#---------------------------------------------------------------------
#"""Version = 2017-08-15 21:00"""
#------------------------------------------------------------------------------
import IPY_GameWorld
import GameWorld
import ItemCommon
import PlayerControl
import ShareDefine
import ChConfig
import ChEquip
import PlayerSuccess
import ItemControler
import IpyGameDataPY
import EventShell
 
 
#//A3 17 Ì××°ºÏ³É#tagCMSuitCompose
#struct tagCMSuitCompose
#{
#    tagHead Head;
#    BYTE    SuiteType;    // Ì××°ÀàÐÍ1ÆÕͨ 2Ç¿»¯
#    BYTE    EquipPlace;    // ×°±¸Î»ÖÃ
#};
 
## Ì××°ºÏ³É
#  @param playerIndex, clientData, tick
#  @return None
def OnEquipSuitCompose(playerIndex, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)
    equipPlace = clientData.EquipPlace
    suiteType = clientData.SuiteType
    #È¡³öÖ÷×°±¸
    mainEquipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
    
    mainEquip = mainEquipPack.GetAt(equipPlace)
    if not ItemCommon.CheckItemCanUse(mainEquip):
        GameWorld.DebugLog('    Ì××°ºÏ³É ¸ÃλÖÃû´©×°±¸£¡ equipPlace=%s'%equipPlace)
        return
    
    
    curSuiteLV = ChEquip.GetEquipPartSuiteLV(curPlayer, equipPlace, suiteType)
    tagSuitLV = curSuiteLV + 1
    
    needColorStarDict = IpyGameDataPY.GetFuncEvalCfg('EquipSuitColorStar')
    if str(suiteType) not in needColorStarDict:
        return
    needColor, needQuality = needColorStarDict[str(suiteType)]
    if mainEquip.GetItemColor() < needColor or mainEquip.GetItemQuality() < needQuality:
        GameWorld.DebugLog(' ¸Ã×°±¸²»Âú×ãÆ·ÖÊ»òÐǼ¶ÒªÇ󠣡needColor=%s, needQuality=%s'%(needColor, needQuality))
        return
    #×°±¸½×¼¶²»ÄܵÍÓÚÌ××°µÈ¼¶
    equipClassLV = ItemCommon.GetItemClassLV(mainEquip)
    if equipClassLV < tagSuitLV:
        GameWorld.DebugLog('µ±Ç°×°±¸½×¼¶²»ÄܵÍÓÚÌ××°µÈ¼¶')
        return
    #²»ÄܸßÓڵͼ¶Ì××°ÀàÐ͵ĵȼ¶
    for stype in xrange(1, suiteType):
        if tagSuitLV > ChEquip.GetEquipPartSuiteLV(curPlayer, equipPlace, stype):
            GameWorld.DebugLog('²»ÄܸßÓڵͼ¶Ì××°ÀàÐ͵ĵȼ¶')
            return
    
    stuffItemDict = __GetStuffItem(curPlayer, suiteType, equipPlace, tagSuitLV)
   
    if not stuffItemDict:
        return
    
    hasEnough, useItemList = __GetNeedItemIndexList(curPlayer, stuffItemDict)    
    if not hasEnough:
        #²ÄÁϲ»×ã
        GameWorld.DebugLog('OnEquipSuitCompose stuff no enough stuffItemDict=%s' % stuffItemDict)
        return
    # É¾³ý²ÄÁÏ
    for costItemCount, costItemIndexList, bindCnt, unBindCnt in useItemList:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, costItemCount, 
                                     ChConfig.ItemDel_EquipSuit, {"EquipPlace":equipPlace})
 
    #¸üÐÂ×°±¸Ì××°Æ·ÖÊ
    ChEquip.SetEquipPartSuiteLV(curPlayer, equipPlace, suiteType, tagSuitLV)
    
    #֪ͨµÈ¼¶
    ChEquip.NotifyEquipPartSuiteLV(curPlayer, equipPlace)
    
    #ÏÈË¢×°±¸BUFF ÔÙ¼ÆËãÊôÐÔ
    ChEquip.RefreshPlayerEquipAttribute(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    __DoSuiteSuccess(curPlayer)
    GameWorld.DebugLog('    Ì××°Éý¼¶³É¹¦ equipPlace=%s,suiteType=%s, tagSuitLV=%s, useItemList=%s'%(equipPlace, suiteType, tagSuitLV, useItemList))
    
    # ºÏ³É½á¹û֪ͨ
    curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitSuiteCompound, ChConfig.Def_ComposeState_Sucess)
    return
 
 
 
## »ñµÃÐèÒªµÄÎïÆ·Ë÷Òý×Öµä
#  @param itemDict: ÐèÒªÎïÆ·ÊýÁ¿
#  @param curPack: ±³°ü
#  @return ÊÇ·ñ×ã¹»,[itemID, itemCnt, indexList, hasBind, lackCnt]
def __GetNeedItemIndexList(curPlayer, itemDict):
    itemIndexList = []
    isEnough = True
    # ÐèÇóÎïÆ·×Öµä{id,ÊýÁ¿}
    for itemID, itemCnt in itemDict.items():
        costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, itemID)
        if (bindCnt + unBindCnt) < itemCnt:
            isEnough = False
        
        itemIndexList.append([itemCnt, costItemIndexList, bindCnt, unBindCnt])
    
    return isEnough, itemIndexList
 
def GetEquipCanDoMaxSuiteLV(curPlayer, curEquip, suiteType, groupType=-1):
    #»ñÈ¡¸Ã×°±¸¿É¶ÍÔìÖÁ×î¸ßÌ××°µÈ¼¶
    equipPlace = curEquip.GetEquipPlace()
    if groupType == -1:
        groupType = ChEquip.GetEquipPartSuiteGroupType(curPlayer, equipPlace)
        
    equipClassLV = ItemCommon.GetItemClassLV(curEquip)
    needColorStarDict = IpyGameDataPY.GetFuncEvalCfg('EquipSuitColorStar')
    if str(suiteType) not in needColorStarDict:
        return 0
    needColor, needQuality = needColorStarDict[str(suiteType)]
    if curEquip.GetItemColor() < needColor or curEquip.GetItemQuality() < needQuality:
        return 0
    return equipClassLV
 
#// A3 08 Ì××°²ð½â #tagCMSuiteDecompose
#
#struct    tagCMSuiteDecompose
#{
#    tagHead        Head;
#    BYTE    EquipPlace;  //²¿Î»Ë÷Òý
#    BYTE    SuiteType; //Ì××°ÀàÐÍ 0´ú±íÈ«²¿ÀàÐÍ
#}; 
def OnDecomposeSuite(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    equipPlace = clientData.EquipPlace
    resetSuiteType = clientData.SuiteType
    
    __DoDecomposeSuite(curPlayer, equipPlace, resetSuiteType, 0)
    
    return
 
def __DoDecomposeSuite(curPlayer, equipPlace, resetSuiteType, downByEquip=False):
    #Ö´ÐÐÌ××°½µ¼¶¡¢²ð½â  resetSuiteTypeÌ××°ÀàÐÍ 0´ú±íÈ«²¿ÀàÐÍ  downByEquip¸ù¾ÝÒÑ´©×°±¸×î¸ßÌ××°µÈ¼¶À´½µ¼¶
    giveItemDict = {}
    maxSuiteType = IpyGameDataPY.GetFuncCfg('EquipSuitColorStar', 2)
    
    
    equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
    curEquip = equipPack.GetAt(equipPlace)
    hasEquip = ItemCommon.CheckItemCanUse(curEquip)
 
    for suiteType in range(1, maxSuiteType+1):
        if resetSuiteType and resetSuiteType != suiteType:
            continue
        curSuiteLV = ChEquip.GetEquipPartSuiteLV(curPlayer, equipPlace, suiteType)
        toSuiteLV = 0
        if downByEquip and hasEquip:
            maxSuiteLV = GetEquipCanDoMaxSuiteLV(curPlayer, curEquip, suiteType)
            toSuiteLV = min(maxSuiteLV, curSuiteLV)
        if toSuiteLV == curSuiteLV:
            continue
        for suiteLV in range(toSuiteLV+1, curSuiteLV+1):
            stuffItemDict = __GetStuffItem(curPlayer, suiteType, equipPlace, suiteLV)
            if not stuffItemDict:
                GameWorld.ErrLog('    ²ð½âÌ××°,ûÕÒµ½²ÄÁÏ£¡')
                return
            
            for itemID, itemCnt in stuffItemDict.items():
                giveItemDict[itemID] = giveItemDict.get(itemID, 0) + itemCnt
        
        ChEquip.SetEquipPartSuiteLV(curPlayer, equipPlace, suiteType, toSuiteLV)
    
    if not giveItemDict:
        return
    GameWorld.DebugLog('    ²ð½âÌ××° equipPlace=%s,resetSuiteType=%s,giveItemDict=%s'%(equipPlace, resetSuiteType, giveItemDict))
    
    needSpace = len(giveItemDict)
    emptySpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
    if emptySpace < needSpace:
        prizeItemList = [(itemID, itemCnt, 1) for itemID, itemCnt in giveItemDict.items()]
        PlayerControl.SendMailByKey('DefaultLackSpace', [curPlayer.GetPlayerID()], prizeItemList)
    else:
        for itemID, itemCnt in giveItemDict.items():
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, True, [IPY_GameWorld.rptItem], True, 
                                         event=[ChConfig.ItemGive_EquipSuit, False, {"EquipPlace":equipPlace}])
    
    #֪ͨµÈ¼¶
    ChEquip.NotifyEquipPartSuiteLV(curPlayer, equipPlace)
    
    #ÏÈË¢×°±¸BUFF ÔÙ¼ÆËãÊôÐÔ
    ChEquip.RefreshPlayerEquipAttribute(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    __DoSuiteSuccess(curPlayer)
    return
 
def CheckEquipSuitReduce(curPlayer, equipIndex):
    ##ÓÉÓÚ×°±¸¸ü»»£¬Ì××°½µ¼¶¼ì²é
    __DoDecomposeSuite(curPlayer, equipIndex, 0, True)
    
    
    return
 
 
 
def __GetStuffItem(curPlayer, suiteType, equipPlace, tagSuitLV):
    job = curPlayer.GetJob() if equipPlace not in ChConfig.BaseEquipPlace_Relics else 0
    ipyData = IpyGameDataPY.GetIpyGameData('EquipSuitCompound', suiteType, equipPlace, tagSuitLV, job)
    if not ipyData:
        return {}
    costItemIDList = ipyData.GetCostItemID()
    costItemCntList = ipyData.GetCostItemCnt()
    stuffItemDict = {}
    for i, itemid in enumerate(costItemIDList):
        stuffItemDict[itemid] = stuffItemDict.get(itemid, 0) + costItemCntList[i]
    return stuffItemDict
 
 
 
def __DoSuiteSuccess(curPlayer):
    PlayerSuccess.ResetSuccessByType(curPlayer, ShareDefine.SuccType_EquipSuit)
    equipSuitTypeDict = IpyGameDataPY.GetFuncEvalCfg('EquipSuitType')
    groupCnt = 0 #2½×Ç¿»¯·À¾ßÌ××°¼þÊý
    for groupType, equipIndexList in equipSuitTypeDict.items():
        for i in equipIndexList:
            suiteInfo = ChEquip.GetSuiteInfoByPlace(curPlayer, i)
            for suiteType, lv in suiteInfo.items():
                if lv >= 2 and int(groupType) == 1 and suiteType == 2:
                    groupCnt +=1
                for j in xrange(1,lv+1):
                    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_EquipSuit, 1, [j, suiteType, int(groupType)])
    #GameWorld.DebugLog('2½×Ç¿»¯·À¾ßÌ××°¼þÊý=%s'%groupCnt)
    EventShell.EventRespons_SuitPlus(curPlayer, groupCnt)
    return