#!/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