hxp
2021-02-20 71a5b8c236d7538053a3a893adccaa0d59798521
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerWing
#
# @todo:³á°òϵͳ
# @author sgj
# @date 2017-8-19
# @version 1.0
#
# ÏêϸÃèÊö: ³á°òϵͳ
#
#-------------------------------------------------------------------------------
#"""Version = 2017-8-19 ÏÂÎç06:02:33"""
#-------------------------------------------------------------------------------
import IPY_GameWorld
import GameWorld
import PlayerControl
import IpyGameDataPY
import ChConfig
import ShareDefine
import ItemCommon
import GameFuncComm
import PlayerSuccess
import ItemControler
import ChEquip
 
import random
 
 
#A3 2E ÓðÒí¾«Á¶ #tagCMWingup
# struct    tagCMWingUp
#{
#    tagHead        Head;
#    BYTE           Count;    //Ë÷Òý¸öÊý
#    BYTE           WingIndexList[Count]; //²ÄÁϳá°òÔÚ±³°üÖеÄË÷ÒýÁбí
# }; 
 
 
#===============================================================================
 
#  @param index: Íæ¼ÒË÷Òý
#  @param clientData: ·â°ü½á¹¹Ìå
#  @param tick: Ê±¼ä´Á
#  @return: None
def OnWingJingLian(index, clientData, tick):
    
    # ¸ù¾Ý²ß»®ÐèÒª,¿ÉÒÔÑ¡ÔñÊÇ·ñ¿ç·þ·þÎñÆ÷¹¦ÄÜÏÞÖÆ
#    if GameWorld.IsCrossServer():
#        return
    
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    #»ñÈ¡·â°üÐÅÏ¢
    materialMessageList = clientData.WingIndexList
    #count = clientData.Count
    GameWorld.DebugLog("ÓðÒí¾«Á¶:WingIndexList=%s" % materialMessageList, curPlayer.GetPlayerID())
    
    #Åжϵȼ¶ÊÇ·ñÂú×ã
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_Wing):
        GameWorld.DebugLog("µÈ¼¶²»×㣬²»Äܾ«Á¶³á°ò")
        return
    
    ##ÅжÏÊÇ·ñ×°±¸³á°ò retWing
    equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
    curWing = equipPack.GetAt(ShareDefine.retWing)
    
    if not ItemCommon.CheckItemCanUse(curWing):
        GameWorld.Log("³á°ò²»ºÏ·¨£¬»òÕßûÓдø³á°ò")
        return
    
    #Åжϵ±Ç°³á°òÊÇ·ñ¿ÉÒÔ¾«Á¶
    if not __WingCanJingLian(curWing):
        #Ìáʾµ±Ç°³á°ò¾«Á¶ÒѾ­´ïµ½ÉÏÏÞ
        #PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        GameWorld.DebugLog("¸Ã³á°ò²»ÐèÒª¾«Á¶")
        return    
    
    materialInfo = __ReduceMaterial(curPlayer, curWing, materialMessageList)
    if not materialInfo:
        return
    totalPoint, materialItemDict = materialInfo
    if not totalPoint:
        GameWorld.DebugLog("ûÓо«Á¶Öµ")
        return
    WingProgressUP(curWing, totalPoint, materialItemDict, curPlayer)
    ChEquip.RefreshPlayerLingQiEquipAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_WingRefine, 1)
    return
 
def __WingCanJingLian(curWing):
    #Åжϳá°òÊÇ·ñ¿ÉÒÔ¾«Á¶
    wingAttrIpyData = GetWingRefineAttrData(curWing.GetItemTypeID())
    if wingAttrIpyData == None:
        return False
    maxWingProgress = wingAttrIpyData.GetMaxRefineExp()
    curProgress = curWing.GetUserAttr(ShareDefine.Def_IudetWingProgressValue)
    return curProgress < maxWingProgress
 
 
#¿Û³ý¾«Á¶²ÄÁÏ
def __ReduceMaterial(curPlayer, curWing, materialMessageList):
    totalPoint = 0
    materialItemDict = {} # ÌØÊ⾫Á¶²ÄÁϸöÊýÐÅÏ¢ {itemID:¸öÊý, ...}
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    needCount = 1
    wingClassLV = ItemCommon.GetItemClassLV(curWing)
    for index in materialMessageList:
        curItem = itemPack.GetAt(index)
        if not ItemCommon.CheckItemCanUse(curItem):
            GameWorld.DebugLog("Õâ¸ö¸ñ×ÓûÓкϷ¨²ÄÁÏ,index=%s" % index)
            continue
        curItemID = curItem.GetItemTypeID()
        wingAttrIpyData = IpyGameDataPY.GetIpyGameData("WingRefineExp", curItemID)
        if wingAttrIpyData == None:
            GameWorld.DebugLog("¸ÃÎïÆ·²»ÄÜ×÷ΪÓðÒí¾«Á¶µÄ²ÄÁÏ,index=%s,itemID=%s" % (index, curItemID))
            continue
        curItemCount = curItem.GetCount()
        if curItemCount < needCount:
            GameWorld.DebugLog("²ÄÁϲ»×ã")
            continue
        
        point = 0
        # ¸ù¾Ý´úÊý³É³¤µÄ¾«Á¶²ÄÁÏ
        expDict = wingAttrIpyData.GetExpMaterial()
        if expDict:
            if wingClassLV not in expDict:
                GameWorld.ErrLog("¾«Á¶²ÄÁÏûÓÐÅäÖöÔÓ¦³á°ò´úÊý¾«Á¶Öµ£¬ÎÞ·¨¾«Á¶!index=%s,curItemID=%s,wingClassLV=%s" 
                                 % (index, curItemID, wingClassLV), curPlayer.GetPlayerID())
                continue
            point += expDict[wingClassLV] * needCount
            materialItemDict[curItemID] = materialItemDict.get(curItemID, 0) + needCount
        else:
            point += random.randint(wingAttrIpyData.GetRandExpMin(), wingAttrIpyData.GetRandExpMax()) * needCount
        GameWorld.DebugLog("    index=%s,itemID=%s,baseExp=%s" % (index, curItemID, point))
        
        if curItem.GetType() == ChConfig.Def_ItemType_retWing:
            wingItemExpInfo = GetWingItemChangeExp(curItem, wingClassLV)
            if not wingItemExpInfo:
                GameWorld.ErrLog("³á°òÎïÆ·×ª»¯Îª¾«Á¶ÖµÒì³£,index=%s!" % index, curPlayer.GetPlayerID())
                continue
            changeTagWingExp, materialItemDictEx = wingItemExpInfo
            for materialItemID, count in materialItemDictEx.items():
                materialItemDict[materialItemID] = materialItemDict.get(materialItemID, 0) + count
            point += changeTagWingExp
            
        totalPoint += point
        GameWorld.DebugLog("    ¾«Á¶ÐÅÏ¢: index=%s,curItemID=%s,point=%s,totalPoint=%s,materialItemDict=%s" 
                           % (index, curItemID, point, totalPoint, materialItemDict))
        ItemCommon.DelItem(curPlayer, curItem, needCount, True, ChConfig.ItemDel_WingExp)
        
    return totalPoint, materialItemDict
 
def GetWingItemChangeExp(curItem, tagWingClassLV):
    '''»ñÈ¡³á°òÎïÆ·×ª»¯ÎªÄ¿±ê´úÊý³á°ò¾«Á¶Öµ
    @return: None-Òì³££¬Ö®ºóµÄ¹¦Äܲ»ÄÜ×ö´¦Àí
             ×ª»¯µÄ¾«Á¶Öµ, ÌØÊ⾫Á¶²ÄÁϼ°¸öÊý{itemID:¸öÊý, ...}
    '''
    curExp = curItem.GetUserAttr(ShareDefine.Def_IudetWingProgressValue)
    materialItemIDList = [curItem.GetUserAttrByIndex(ShareDefine.Def_IudetWingMaterialItemID, i) \
                          for i in range(curItem.GetUserAttrCount(ShareDefine.Def_IudetWingMaterialItemID))]
    if not materialItemIDList:
        return curExp, {}
    
    materialItemCountList = [curItem.GetUserAttrByIndex(ShareDefine.Def_IudetWingMaterialItemCount, i) \
                             for i in range(curItem.GetUserAttrCount(ShareDefine.Def_IudetWingMaterialItemCount))]
    if len(materialItemIDList) != len(materialItemCountList):
        GameWorld.ErrLog("ÓðÒí¾«Á¶²ÄÁϼǼÒì³£!wingItemID=%s,UserData=%s" % (curItem.GetItemTypeID(), curItem.GetUserData()))
        return
    
    curLVMaterialExp = 0
    tagLVMaterialExp = 0
    materialItemDict = {}
    curWingClassLV = ItemCommon.GetItemClassLV(curItem)
    for i, materialItemID in enumerate(materialItemIDList):
        wingAttrIpyData = IpyGameDataPY.GetIpyGameData("WingRefineExp", materialItemID)
        if wingAttrIpyData == None:
            GameWorld.ErrLog("¸ÃÎïÆ·ID·ÇÓðÒí¾«Á¶²ÄÁÏ!materialItemID=%s" % materialItemID)
            return
        
        # ¸ù¾Ý´úÊý³É³¤µÄ¾«Á¶²ÄÁÏ
        expDict = wingAttrIpyData.GetExpMaterial()
        if not expDict:
            GameWorld.ErrLog("¾«Á¶²ÄÁÏûÓÐÅäÖôúÊý¶ÔÓ¦¾«Á¶Öµ!materialItemID=%s" % materialItemID) 
            return
        
        if curWingClassLV not in expDict or tagWingClassLV not in expDict:
            GameWorld.ErrLog("¾«Á¶²ÄÁÏûÓÐÅäÖôúÊý¶ÔÓ¦¾«Á¶Öµ!materialItemID=%s,curWingClassLV=%s,tagWingClassLV=%s,expDict=%s" 
                             % (materialItemID, curWingClassLV, tagWingClassLV, expDict)) 
            return
        materialItemCount = materialItemCountList[i]
        curLVMaterialExp += (expDict[curWingClassLV] * materialItemCount)
        tagLVMaterialExp += (expDict[tagWingClassLV] * materialItemCount)
        materialItemDict[materialItemID] = materialItemCount
        
    curWingBaseExp = max(0, curExp - curLVMaterialExp)
    changeTagWingExp = curWingBaseExp + tagLVMaterialExp # ×ª»¯Ä¿±ê´úÊý³á°ò¾«Á¶Öµ
    GameWorld.DebugLog("    ³á°òת»¯Îª¾«Á¶Öµ:curExp=%s,curWingClassLV-EXP=(%s-%s),tagWingClassLV-EXP=(%s-%s),changeTagWingExp=%s,materialItemDict=%s" 
                       % (curExp, curWingClassLV, curLVMaterialExp, tagWingClassLV, tagLVMaterialExp, changeTagWingExp, materialItemDict))
    return changeTagWingExp, materialItemDict
 
def WingProgressUP(curWing, addExp, materialItemDict={}, curPlayer=None):
    #Ôö¼Ó¾«Á¶Öµ
    if not addExp:
        return
    
    wingProgress = curWing.GetUserAttr(ShareDefine.Def_IudetWingProgressValue)
    updWingProgress = wingProgress + addExp 
    curWing.SetUserAttr(ShareDefine.Def_IudetWingProgressValue, updWingProgress)
    
    GameWorld.DebugLog("Ôö¼Ó³á°ò¾«Á¶Öµ: curExp=%s,addExp=%s,updExp=%s,materialItemDict=%s" 
                       % (wingProgress, addExp, updWingProgress, materialItemDict))
    # ¸üÐÂÌØÊâ²ÄÁϸöÊý
    if materialItemDict:
        materialItemIDList = [curWing.GetUserAttrByIndex(ShareDefine.Def_IudetWingMaterialItemID, i) \
                              for i in range(curWing.GetUserAttrCount(ShareDefine.Def_IudetWingMaterialItemID))]
        for materialItemID, materialItemCount in materialItemDict.items():
            if materialItemID in materialItemIDList:
                index = materialItemIDList.index(materialItemID)
                updCount = curWing.GetUserAttrByIndex(ShareDefine.Def_IudetWingMaterialItemCount, index) + materialItemCount
                curWing.UpdataUserAttrByIndex(ShareDefine.Def_IudetWingMaterialItemCount, index, updCount)
                GameWorld.DebugLog("    ¸üгá°òÌØÊ⾫Á¶²ÄÁϸöÊý: materialItemID=%s,updCount=%s" % (materialItemID, updCount))
            else:
                curWing.AddUserAttr(ShareDefine.Def_IudetWingMaterialItemID, materialItemID)
                curWing.AddUserAttr(ShareDefine.Def_IudetWingMaterialItemCount, materialItemCount)
                GameWorld.DebugLog("    ÐÂÔö³á°òÌØÊ⾫Á¶²ÄÁϸöÊý: materialItemID=%s,materialItemCount=%s" % (materialItemID, materialItemCount))
                
    UpdWingColor(curPlayer, curWing, wingProgress, updWingProgress)
    return
 
def UpdWingColor(curPlayer, curWing, wingProgress, updWingProgress):
    curItemID = curWing.GetItemTypeID()
    wingAttrIpyData = GetWingRefineAttrData(curItemID)
    if not wingAttrIpyData:
        return
    
    # ¸üгá°ò¾«Á¶ÑÕÉ«
    wingColorDict = wingAttrIpyData.GetItemColorInfo()
    curColor = curWing.GetUserAttr(ShareDefine.Def_IudetItemColor)
    #isColorChange = False
    for color in wingColorDict:
        if updWingProgress >= wingColorDict[color] and color > curColor:
            curColor = color
            curWing.SetUserAttr(ShareDefine.Def_IudetItemColor, curColor)
            GameWorld.DebugLog("    ¸üгá°òÑÕÉ«: updWingProgress=%s,curColor=%s" % (updWingProgress, curColor))
            #isColorChange = True
    maxRefineExp = wingAttrIpyData.GetMaxRefineExp()
    if curPlayer and wingProgress < maxRefineExp <= updWingProgress:
        PlayerControl.WorldNotify(0, "WingsRefinePerfect", [curPlayer.GetPlayerName(), curItemID, curWing.GetUserData()])
    #if curPlayer and isColorChange:
    #    PlayerSuccess.DoEquipSuccessLogic(curPlayer)
    return
 
def GetWingRefineAttrData(itemID):
    wingData = GameWorld.GetGameData().GetItemByTypeID(itemID)
    if not wingData:
        return
    wingClassLV = ItemCommon.GetItemClassLV(wingData)
    return IpyGameDataPY.GetIpyGameDataNotLog("WingRefineAttr", wingClassLV)
 
def GetWingProgressPerValueByID(itemID, per):
    ## »ñÈ¡³á°ò¾«Á¶°Ù·Ö±È¶ÔÓ¦µÄ¾«Á¶Öµ
    if per <= 0:
        return 0
    wingAttrIpyData = GetWingRefineAttrData(itemID)
    if not wingAttrIpyData:
        return 0
    return int(wingAttrIpyData.GetMaxRefineExp() * per / 100.0)
 
## ³á°ò¹¦ÄÜ¿ªÆô
def DoWingOpen(curPlayer):
    GameWorld.DebugLog("³á°ò¾«Á¶¿ªÆô")
    return True
            
    
## ¼ÆËãÊôÐÔ
#  @param curPlayer Íæ¼Ò
#  @param allAttrList ÊôÐÔÁбí
#  @return None
def CalcWingAttrEx(curPlayer, curWing, allAttrList):
    
    # ¾«Á¶ÊôÐÔ
    wingAttrIpyData = GetWingRefineAttrData(curWing.GetItemTypeID())
    if wingAttrIpyData:
        curProgress = curWing.GetUserAttr(ShareDefine.Def_IudetWingProgressValue)
        maxWingProgress = wingAttrIpyData.GetMaxRefineExp()
        fujiaValueDict = wingAttrIpyData.GetAttrInfo()
        
        rate = round(float(curProgress) / float(maxWingProgress), 3) if curProgress <= maxWingProgress else 1
    
        for effID, value in fujiaValueDict.items():
            PlayerControl.CalcAttrDict_Type(effID, int(value * rate), allAttrList)
    #GameWorld.DebugLog("    ¾«Á¶ÊôÐÔ: %s" % allAttrList)
    return