hxp
2026-01-16 750ff5ee6204bb088713b0ce10d53d05f22679e0
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerMingge
#
# @todo:Ãü¸ñ
# @author hxp
# @date 2026-01-13
# @version 1.0
#
# ÏêϸÃèÊö: Ãü¸ñ
#
#-------------------------------------------------------------------------------
#"""Version = 2026-01-13 11:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import PlayerPreset
import PlayerControl
import ItemControler
import IpyGameDataPY
import ChPyNetSendPack
import NetPackCommon
import PlayerOnline
import ShareDefine
import ItemCommon
import ChConfig
 
import random
 
def OnPlayerLogin(curPlayer):
    Sync_MinggeInfo(curPlayer)
    return
 
def DoMinggeOpen(curPlayer):
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MGGanwuLV, 1)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MGGanwuExp, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MGLingying, 0)
    Sync_MinggeInfo(curPlayer)
    return
 
#// B2 50 Ãü¸ñÍÆÑÝ #tagCSMinggeTuiyan
#
#struct    tagCSMinggeTuiyan
#{
#    tagHead        Head;
#    BYTE        Count;    //ÍÆÑݸöÊý
#};
def OnMinggeTuiyan(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    tyCount = clientData.Count
    DoMinggeTuiyan(curPlayer, tyCount)
    return
 
def GetMGColorRateList(curPlayer):
    ## »ñÈ¡Ãü¸ñÍÆÑÝµÄÆ·ÖʸÅÂʱýͼ
    
    playerID = curPlayer.GetPlayerID()
    curLingying = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MGLingying)
    
    curIpyData, nextIpyData = None, None
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetMGLingyingQualityCount()):
        ipyData = ipyDataMgr.GetMGLingyingQualityByIndex(index)
        lingying = ipyData.GetLingying()
        if curLingying >= lingying:
            curIpyData = ipyData
        else:
            nextIpyData = ipyData
            break
        
    if not curIpyData:
        return []
    
    minggeRateList = []
    if not nextIpyData:
        rate = 0
        weightList = curIpyData.GetItemColorWeightList()
        for quality, weight in enumerate(weightList, 1):
            if not weight:
                continue
            rate += weight
            minggeRateList.append([rate, quality])
        GameWorld.DebugLog("ÁéÓ¦Âú¼¶ÁË: curLingying=%s,%s" % (curLingying, minggeRateList), playerID)
    else:
        rate = 0
        curIpyLingying = curIpyData.GetLingying()
        nextIpyLingying = nextIpyData.GetLingying()
        lingyingDiffMax = nextIpyLingying - curIpyLingying # ÁéÓ¦²îÖµ¶Î
        lingyingDiffNow = curLingying - curIpyLingying # µ±Ç°ÁéÓ¦²îÖµ
        diffPer = lingyingDiffNow / float(lingyingDiffMax) # ²îÖµÕ¼±È
        curWeightList = curIpyData.GetItemColorWeightList()
        nextWeightList = nextIpyData.GetItemColorWeightList()
        #GameWorld.DebugLog("ÁéӦƷÖʱýͼ¼ÆËã: curLingying=%s,curIpyLingying=%s,nextIpyLingying=%s" % (curLingying, curIpyLingying, nextIpyLingying), playerID)
        #GameWorld.DebugLog("    lingyingDiffNow=%s,lingyingDiffMax=%s,diffPer=%s" % (lingyingDiffNow, lingyingDiffMax, diffPer), playerID)
        #GameWorld.DebugLog("    curWeightList =%s" % (curWeightList), playerID)
        #GameWorld.DebugLog("    nextWeightList=%s" % (nextWeightList), playerID)
        for quality, nextWeight in enumerate(nextWeightList, 1):
            curWeight = curWeightList[quality - 1] if len(curWeightList) >= quality else 0
            diffWeight = int(round((nextWeight - curWeight) * diffPer))
            nowWeight = max(0, curWeight + diffWeight)
            rate += nowWeight
            #GameWorld.DebugLog("    quality=%s,rate=%s,nowWeight=%s,curWeight=%s,nextWeight=%s,diffPer=%s,diffWeight=%s" 
            #                   % (quality, rate, nowWeight, curWeight, nextWeight, diffPer, diffWeight), playerID)
            if nowWeight:
                minggeRateList.append([rate, quality])
        GameWorld.DebugLog("×îÖÕÁéӦƷÖʱýͼ: curLingying=%s,%s" % (curLingying, minggeRateList), playerID)
        
    return minggeRateList
 
def DoMinggeTuiyan(curPlayer, tyCount):
    ## Ãü¸ñÍÆÑÝ
    playerID = curPlayer.GetPlayerID()
    colorRateList = GetMGColorRateList(curPlayer)
    if not colorRateList:
        return
    
    useCount = tyCount
    useItemID = IpyGameDataPY.GetFuncCfg("MinggeCfg", 2)
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, useItemID, useCount)
    lackCnt = useCount - bindCnt - unBindCnt
    if lackCnt > 0:
        useCount -= lackCnt # ²»×ãʱÓжàÉÙÓöàÉÙ
        
    if useCount <= 0:
        GameWorld.DebugLog("ÍÆÑݵÀ¾ß²»×ã! useItemID=%s,lackCnt=%s" % (useItemID, lackCnt), playerID)
        return
    
    lastColorCnt = IpyGameDataPY.GetFuncCfg("ItemRecordEquip", 1) # Óвú³öµÄ×îºó¼¸¸öÆ·ÖÊÐèÒª¼Ç¼£¬Ì×ÓÃÖ÷Ïß×°±¸ÅäÖÃ
    needRecordColorMin = colorRateList[-1][1] - lastColorCnt + 1
    
    gameData = GameWorld.GetGameData()
    succCount = 0
    useCount = ItemCommon.GetItemPackSpace(curPlayer, ShareDefine.rptMGTuiyan, useCount)
    for _ in range(useCount):
        itemColor = GameWorld.GetResultByRandomList(colorRateList)
        if not itemColor:
            continue
        
        itemType = random.choice(ChConfig.Def_MGGuayuType)
        randItemID = 0
        gameData.FilterItemByType(itemType)
        for i in xrange(gameData.GetFilterItemCount()):
            itemData = gameData.GetFilterItem(i)
            if itemData.GetItemColor() == itemColor:
                randItemID = itemData.GetItemTypeID()
                break
            
        GameWorld.DebugLog("Ãü¸ñÍÆÑÝ: itemColor=%s,itemType=%s,randItemID=%s,colorRateList=%s" % (itemColor, itemType, randItemID, colorRateList), playerID)
        curItem = ItemControler.GetOutPutItemObj(randItemID, 1, False, curPlayer=curPlayer)
        if curItem == None:
            continue
        
        isForceDR = (needRecordColorMin and curItem.GetItemColor() >= needRecordColorMin) # ¼Ç¼Á÷Ïò
        if not ItemControler.DoLogic_PutItemInPack(curPlayer, curItem, event=["MinggeTuiyan", isForceDR, {}], packIndexList=[ShareDefine.rptMGTuiyan]):
            continue
        
        succCount += 1
        
    if succCount <= 0:
        return
    
    ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, succCount, "MinggeTuiyan")
    addGWExp = succCount
    
    ganwuLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MGGanwuLV)
    ganwuExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MGGanwuExp)
    updLV = ganwuLV
    updExp = ganwuExp + addGWExp
    GameWorld.DebugLog("¸üиÐÎò¾­Ñé: ganwuLV=%s,addGWExp=%s,updExp=%s" % (ganwuLV, addGWExp, updExp))
    ipyData = IpyGameDataPY.GetIpyGameData("MGGanwuLV", ganwuLV)
    nexpIpyData = IpyGameDataPY.GetIpyGameDataNotLog("MGGanwuLV", ganwuLV + 1)
    while nexpIpyData and ipyData and updExp >= ipyData.GetNextNeedExp():
        updExp -= ipyData.GetNextNeedExp()
        updLV += 1
        GameWorld.DebugLog("    Éý¼¶: updLV=%s,updExp=%s" % (updLV, updExp))
        ipyData = nexpIpyData
        nexpIpyData = IpyGameDataPY.GetIpyGameDataNotLog("MGGanwuLV", updLV + 1)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MGGanwuLV, updLV)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MGGanwuExp, updExp)
    Sync_MinggeInfo(curPlayer)
    return
 
#// B2 51 Ãü¸ñ·Ö½â #tagCSMinggeDecompose
#
#struct    tagCSMinggeDecompose
#{
#    tagHead        Head;
#    BYTE        Count;
#    BYTE        IndexList[Count];    // ÍÆÑݱ³°üÖеÄÎïÆ·¸ñ×ÓË÷ÒýÁбí
#};
def OnMinggeDecompose(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    __doDecomposeMingge(curPlayer, clientData.IndexList)
    return
 
def __doDecomposeMingge(curPlayer, itemIndexList):
    playerID = curPlayer.GetPlayerID()
    itemID, itemCount = IpyGameDataPY.GetFuncEvalCfg("MinggeTY", 1)
    GameWorld.DebugLog("·Ö½âÃü¸ñ: itemIndexList=%s,itemID=%s,itemCount=%s" % (itemIndexList, itemID, itemCount), playerID)
    if not itemID or not itemCount:
        return
        
    needRecordColorMin = 0
    colorRateList = GetMGColorRateList(curPlayer)
    if colorRateList:
        lastColorCnt = IpyGameDataPY.GetFuncCfg("ItemRecordEquip", 1) # Óвú³öµÄ×îºó¼¸¸öÆ·ÖÊÐèÒª¼Ç¼£¬Ì×ÓÃÖ÷Ïß×°±¸ÅäÖÃ
        needRecordColorMin = colorRateList[-1][1] - lastColorCnt + 1
        
    GameWorld.DebugLog("needRecordColorMin=%s,colorRateList=%s" % (needRecordColorMin, colorRateList), playerID)
    decomposeCnt = 0
    
    mgTuiyanPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptMGTuiyan)
    for itemIndex in itemIndexList:
        if itemIndex < 0 or itemIndex >= mgTuiyanPack.GetCount():
            continue
        curEquip = mgTuiyanPack.GetAt(itemIndex)
        if not ItemCommon.CheckItemCanUse(curEquip):
            GameWorld.DebugLog("ÎïÆ·Îª¿Õ»ò²»¿ÉÓÃ: itemIndex=%s" % itemIndex, playerID)
            continue
        isForceDR = (needRecordColorMin and curEquip.GetItemColor() >= needRecordColorMin) # ¼Ç¼·Ö½âÁ÷Ïò
        ItemCommon.DelItem(curPlayer, curEquip, curEquip.GetCount(), True, "MinggeDecompose", isForceDR=isForceDR)
        decomposeCnt += 1
        
    if not decomposeCnt:
        return
    itemList = [[itemID, itemCount * decomposeCnt]]
    ItemControler.GivePlayerItemOrMail(curPlayer, itemList, event=["MinggeDecompose", False, {}], isNotifyAward=False)
    return
 
#// B2 52 Ãü¸ñ×°±¸Ìæ»» #tagCSMinggeEquip
#
#struct    tagCSMinggeEquip
#{
#    tagHead        Head;
#    BYTE        MGNum;    // ×°µ½ÄÄÒ»Ì×Ãü¸ñ£¬Ä¿Ç°Ö§³Ö3Ì×£¬´Ó1¿ªÊ¼
#    BYTE        Index;    // ÍÆÑݱ³°üÖеÄÎïÆ·¸ñ×ÓË÷Òý
#    BYTE        AutoDec;    // ÊÇ·ñ×Ô¶¯·Ö½â
#};
def OnMinggeEquip(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    mgNum = clientData.MGNum
    itemIndex = clientData.Index
    isAutoDec = clientData.AutoDec
    GameWorld.DebugLog("Ãü¸ñ×°±¸Ìæ»»: mgNum=%s,itemIndex=%s,isAutoDec=%s" % (mgNum, itemIndex, isAutoDec), playerID)
    
    if not PlayerPreset.GetFuncPresetIDState(curPlayer, mgNum, ShareDefine.FuncPreset_Mingge):
        GameWorld.DebugLog("Ãü¸ñÌ×·½°¸Î´½âËø! mgNum=%s" % mgNum, playerID)
        return
    
    mgTuiyanPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptMGTuiyan)
    if itemIndex < 0 or itemIndex >= mgTuiyanPack.GetCount():
        return
    curEquip = mgTuiyanPack.GetAt(itemIndex)
    if not ItemCommon.CheckItemCanUse(curEquip):
        GameWorld.DebugLog("    Ãü¸ñÎïÆ·Îª¿Õ»ò²»¿ÉÓÃ: itemIndex=%s" % itemIndex, playerID)
        return
    
    itemID = curEquip.GetItemTypeID()
    itemType = curEquip.GetType()
    
    if itemType not in ChConfig.Def_MGGuayuType:
        return
    
    #Ö§³Ö¶àÌ×£¬Ã¿Ì×12¼þ£¬Ä¿Ç°Ö§³Ö3Ì×£¬Ì×±àºÅ 1~3
    #¶ÔÓ¦ØÔÓñ±³°üË÷Òý = (Ì×±àºÅ-1)*12+×°±¸Î»-1
    typeIpyData = IpyGameDataPY.GetIpyGameData("MGGuayuType", itemType)
    if not typeIpyData:
        return
    equipPlace = typeIpyData.GetEquipPlace() # ×°±¸Î»
    equipPlaceIndex = (mgNum - 1) * len(ChConfig.Def_MGGuayuType) + equipPlace - 1 # ×°ÔÚÃü¸ñ±³°üÖеÄË÷Òý
    
    GameWorld.DebugLog("    itemIndex=%s,itemID=%s,itemType=%s,equipPlace=%s,equipPlaceIndex=%s" 
                       % (itemIndex, itemID, itemType, equipPlace, equipPlaceIndex), playerID)
    
    equipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptMGGuayu)
    if equipPlaceIndex < 0 or equipPlaceIndex >= equipPack.GetCount():
        GameWorld.ErrLog("Ãü¸ñØÔÓñ¶ÔӦװ±¸Î»ÖÃË÷ÒýÒì³£: itemIndex=%s,mgNum=%s,itemType=%s,equipPlace=%s,equipPlaceIndex=%s" 
                         % (itemIndex, mgNum, itemType, equipPlace, equipPlaceIndex), playerID)
        return
    destEquip = equipPack.GetAt(equipPlaceIndex)
    canDecomp = ItemCommon.CheckItemCanUse(destEquip)
    
    if not ItemCommon.DoLogicSwitchItem(curPlayer, curEquip, destEquip, ShareDefine.rptMGGuayu):
        return
    
    if isAutoDec and canDecomp:
        __doDecomposeMingge(curPlayer, [itemIndex])
        
    # Ë¢ÊôÐÔ
    RefreshMinggeAttr(curPlayer, mgNum)
    return
 
#// B2 53 Ãü¸ñÆíÁé#tagCSMinggeQiling
#
#struct    tagCSMinggeQiling
#{
#    tagHead        Head;
#    DWORD        UseCount;    //ʹÓøöÊý
#};
def OnMinggeQiling(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    #playerID = curPlayer.GetPlayerID()
    useCount = clientData.UseCount
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    dataCount = ipyDataMgr.GetMGLingyingQualityCount()
    if not dataCount:
        return
    lastIpyData = ipyDataMgr.GetMGLingyingQualityByIndex(dataCount - 1)
    if not lastIpyData:
        return
    maxLingying = lastIpyData.GetLingying()
    curLingying = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MGLingying)
    if curLingying >= maxLingying:
        GameWorld.DebugLog("ÁéÓ¦ÖµÒÑ´ï×î´óÖµ! curLingying=%s >= %s" % (curLingying, maxLingying))
        return
    useCount = min(useCount, maxLingying - curLingying)
    GameWorld.DebugLog("Ãü¸ñÆíÁé: useCount=%s,curLingying=%s,maxLingying=%s" % (useCount, curLingying, maxLingying))
    
    useItemID = IpyGameDataPY.GetFuncCfg("MinggeCfg", 3)
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, useItemID, useCount)
    lackCnt = useCount - bindCnt - unBindCnt
    if lackCnt > 0:
        useCount -= lackCnt # ²»×ãʱÓжàÉÙÓöàÉÙ    
    if useCount <= 0:
        GameWorld.DebugLog("ÆíÁéµÀ¾ß²»×ã! useItemID=%s,lackCnt=%s" % (useItemID, lackCnt))
        return
    ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, useCount, "MinggeQiling")
    addLingying = useCount # Ã¿¸öÔݹ̶¨Ôö¼Ó1µã
    
    updLingying = curLingying + addLingying
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MGLingying, updLingying)
    GameWorld.DebugLog("    updLingying=%s,useCount=%s" % (updLingying, useCount))
    Sync_MinggeInfo(curPlayer)
    return
 
def RefreshMinggeAttr(curPlayer, mgNum=0):
    CalcMinggeAttr(curPlayer, mgNum)
    PlayerOnline.GetOnlinePlayer(curPlayer).RefreshByFuncPreset(ShareDefine.FuncPreset_Mingge, mgNum)
    return
 
def GetMGNumPackIndexList(mgNum):
    mgCnt = len(ChConfig.Def_MGGuayuType)
    startIndex = (mgNum - 1) * mgCnt
    endIndex = startIndex + mgCnt
    return range(startIndex, endIndex)
 
def CalcMinggeAttr(curPlayer, mgNum=0):
    
    playerID = curPlayer.GetPlayerID()
    funcPresetType = ShareDefine.FuncPreset_Mingge
    if not mgNum:
        ipyDataList = IpyGameDataPY.GetIpyGameDataList("PresetUnlock", funcPresetType)
        mgPresetIDList = range(1, 1 + len(ipyDataList)) if ipyDataList else []
    else:
        mgPresetIDList = [mgNum]
        
    olPlayer = PlayerOnline.GetOnlinePlayer(curPlayer)
    equipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptMGGuayu)
    for mgPresetID in mgPresetIDList:
        
        attrDict, skillLVDict = {}, {}
        if not PlayerPreset.GetFuncPresetIDState(curPlayer, mgPresetID, funcPresetType):
            olPlayer.SetCalcAttr(ChConfig.Def_CalcAttr_Mingge, attrDict, skillLVDict, presetID=mgPresetID)
            continue
        
        for index in GetMGNumPackIndexList(mgPresetID):
            if index < 0 or index >= equipPack.GetCount():
                continue
            curEquip = equipPack.GetAt(index)
            if not curEquip or curEquip.IsEmpty():
                continue
            
            legendAttrIDCnt = curEquip.GetUserAttrCount(ShareDefine.Def_IudetLegendAttrID)
            legendAttrValueCnt = curEquip.GetUserAttrCount(ShareDefine.Def_IudetLegendAttrValue)
            for i in xrange(min(legendAttrIDCnt, legendAttrValueCnt)):
                attrID = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetLegendAttrID, i)
                attrValue = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetLegendAttrValue, i)
                attrDict[attrID] = attrDict.get(attrID, 0) + attrValue
                
            for i in xrange(curEquip.GetUserAttrCount(ShareDefine.Def_IudetAddSkillID)):
                skillID = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetAddSkillID, i)
                if skillID:
                    skillLVDict[skillID] = skillLVDict.get(skillID, 0) + 1
                    
        GameWorld.DebugLog("Ãü¸ñÊôÐÔ: %s,skillLVDict=%s,mgPresetID=%s" % (attrDict, skillLVDict, mgPresetID), playerID)
        olPlayer.SetCalcAttr(ChConfig.Def_CalcAttr_Mingge, attrDict, skillLVDict, presetID=mgPresetID)
        
    return
 
def Sync_MinggeInfo(curPlayer):
    ganwuLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MGGanwuLV)
    if not ganwuLV:
        return
    clientPack = ChPyNetSendPack.tagSCMinggeInfo()
    clientPack.GanwuLV = ganwuLV
    clientPack.GanwuExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MGGanwuExp)
    clientPack.Lingying = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MGLingying)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return