| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Event.EventSrc.Operate_EquipEvolve  | 
| #  | 
| # @todo:×°±¸Éñ×°½ø½×  | 
| # @author hxp  | 
| # @date 2021-06-17  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ×°±¸Éñ×°½ø½×  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-06-17 18:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import GameWorld  | 
| import ItemCommon  | 
| import IPY_GameWorld  | 
| import PlayerControl  | 
| import IpyGameDataPY  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import ItemControler  | 
| import ShareDefine  | 
| import ChConfig  | 
| import ChEquip  | 
|   | 
| import math  | 
| import json  | 
|   | 
|   | 
| #// A3 30 ×°±¸Éñ×°½ø½× #tagCMEquipEvolve  | 
| #  | 
| #struct    tagCMEquipEvolve  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        EquipIndex;    // Òª½ø½×µÄ×°±¸ÔÚ×°±¸±³°üÖÐË÷Òý  | 
| #};  | 
| def OnEquipEvolve(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     equipIndex = clientData.EquipIndex  | 
|     GameWorld.DebugLog("Éñ×°½ø½×: equipIndex=%s" % equipIndex)  | 
|     equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)  | 
|     curEquip = equipPack.GetAt(equipIndex)  | 
|     if not ItemCommon.CheckItemCanUse(curEquip):  | 
|         return  | 
|     equipItemID = curEquip.GetItemTypeID()  | 
|     equipClassLV = ItemCommon.GetItemClassLV(curEquip)  | 
|     GameWorld.DebugLog("    equipItemID=%s,equipClassLV=%s" % (equipItemID, equipClassLV))  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("EquipShenEvolve", equipItemID)  | 
|     if not ipyData:  | 
|         return  | 
|     evolveEquipID = ipyData.GetEvolveEquipID()  | 
|     needItemIDInfoList = ipyData.GetEvolveNeedItemIDInfo()  | 
|       | 
|     evolveEquipItemData = GameWorld.GetGameData().GetItemByTypeID(evolveEquipID)  | 
|     if not evolveEquipItemData:  | 
|         return  | 
|       | 
|     itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|     lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemIDInfoList, itemPack)  | 
|     if lackItemDict:  | 
|         GameWorld.DebugLog("    ËùÐè½ø½×²ÄÁϲ»×㣡equipItemID=%s,evolveEquipID=%s,needItemIDInfoList=%s,lackItemDict=%s"  | 
|                            % (equipItemID, evolveEquipID, needItemIDInfoList, lackItemDict), playerID)  | 
|         return  | 
|       | 
|     #¿ÛÏûºÄ  | 
|     infoDict = {ChConfig.Def_Cost_Reason_SonKey:evolveEquipID}  | 
|     ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, "EquipEvolve", infoDict)  | 
|       | 
|     # Ô×°±¸Ìæ»»³É½ø½××°±¸  | 
|     evolveEquip = ItemControler.GetOutPutItemObj(evolveEquipID, curPlayer=curPlayer)  | 
|     if not evolveEquip:  | 
|         return  | 
|     curEquip.AssignItem(evolveEquip)  | 
|     curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitEquipEvolve, ChConfig.Def_ComposeState_Sucess)  | 
|     GameWorld.Log("½ø½×Éñ×°³É¹¦! equipItemID=%s,evolveEquipID=%s" % (equipItemID, evolveEquipID), playerID)  | 
|       | 
|     #Ë¢ÐÂÊôÐÔ  | 
|     ChEquip.RefreshPlayerEquipAttribute(curPlayer, equipClassLV)  | 
|     playControl = PlayerControl.PlayerControl(curPlayer)  | 
|     playControl.RefreshPlayerAttrState()  | 
|     return  | 
|   | 
|   | 
| #// A3 31 ×°±¸Éñ×°²ð½â #tagCMEquipShenDecompose  | 
| #  | 
| #struct    tagCMEquipShenDecompose  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        Count;        //ËùÔÚ±³°üË÷ÒýµÄÊýÁ¿  | 
| #    WORD        IndexList[Count];    //ËùÔÚ±³°üË÷ÒýÁÐ±í  | 
| #};  | 
| def OnEquipShenDecompose(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     indexList = clientData.IndexList  | 
|       | 
|     GameWorld.DebugLog("Éñ×°·Ö½â: indexList=%s" % indexList)  | 
|       | 
|     isAuctionItem = 0  | 
|     decomposeEquipIDList = [] # ÒÑ·Ö½âµÄÉñ×°×°±¸IDÁÐ±í  | 
|     getItemCountDict = {} # ·Ö½âºó»ñµÃµÄÎïÆ·ÁÐ±í  | 
|     itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|     for index in indexList:  | 
|         curEquip = itemPack.GetAt(index)  | 
|           | 
|         if not ItemCommon.CheckItemCanUse(curEquip):  | 
|             continue  | 
|           | 
|         getItemIDCountDict = {}  | 
|         equipItemID = curEquip.GetItemTypeID()  | 
|         GameWorld.DebugLog("    ¼ì²é·Ö½âÉñ×°: index=%s,equipItemID=%s" % (index, equipItemID))  | 
|         getEquipItemID = CheckEquipShenDecompose(equipItemID, getItemIDCountDict)  | 
|         if equipItemID == getEquipItemID:  | 
|             continue  | 
|           | 
|         getItemList = [[itemID, itemCount, isAuctionItem] for itemID, itemCount in getItemIDCountDict.items()]  | 
|         GameWorld.DebugLog("        ·Ö½âºó¿É»ñµÃ×°±¸: getEquipItemID=%s, getItemList=%s" % (getEquipItemID, getItemList))  | 
|         if not ItemControler.CheckPackSpaceEnough(curPlayer, getItemList):  | 
|             break  | 
|           | 
|         getEquipObj = ItemControler.GetOutPutItemObj(getEquipItemID, curPlayer=curPlayer)  | 
|         if not getEquipObj:  | 
|             continue  | 
|           | 
|         # ¸ø·Ö½âºóµÄÎïÆ·¼°²ÄÁÏ  | 
|         curEquip.AssignItem(getEquipObj)  | 
|         for itemID, itemCount, isAuctionItem in getItemList:  | 
|             ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem],  | 
|                                          event=["EquipShenDecompose", False, {"equipItemID":equipItemID}])  | 
|             getItemCountDict[itemID] = getItemCountDict.get(itemID, 0) + itemCount  | 
|               | 
|         # Í³¼ÆÀÛ¼Ó  | 
|         decomposeEquipIDList.append(equipItemID)  | 
|         getItemCountDict[getEquipItemID] = getItemCountDict.get(getEquipItemID, 0) + 1  | 
|           | 
|           | 
|     ## Í¨Öª·Ö½â½á¹û  | 
|     if not getItemCountDict:  | 
|         return  | 
|       | 
|     getItemDataList = [[itemID, itemCount, isAuctionItem] for itemID, itemCount in getItemCountDict.items()]  | 
|     GameWorld.DebugLog("    ÒÑ·Ö½â×°±¸ID: %s" % decomposeEquipIDList)  | 
|     GameWorld.DebugLog("    »ñµÃÎïÆ·Áбí: %s" % getItemDataList)  | 
|       | 
|     getItemInfo = json.dumps(getItemDataList, ensure_ascii=False)  | 
|     clientPack = ChPyNetSendPack.tagMCEquipDecomposeRet()  | 
|     clientPack.Clear()  | 
|     clientPack.DecomposeEquipIDList = decomposeEquipIDList  | 
|     clientPack.DecomposeEquipIDCount = len(clientPack.DecomposeEquipIDList)  | 
|     clientPack.GetItemData = str(getItemInfo)  | 
|     clientPack.GetItemLen = len(clientPack.GetItemData)  | 
|     NetPackCommon.SendFakePack(curPlayer, clientPack)   | 
|     return  | 
|   | 
| def CheckEquipShenDecompose(equipItemID, getItemIDCountDict):  | 
|     # ·ÇÉñ×°ÎÞ·¨·Ö½â  | 
|     ipyData = IpyGameDataPY.GetIpyGameDataNotLog("EquipShenAttr", equipItemID)  | 
|     if not ipyData:  | 
|         GameWorld.DebugLog("        ·ÇÉñ×°£¬ÎÞ·¨·Ö½â£¡equipItemID=%s" % equipItemID)  | 
|         return equipItemID  | 
|       | 
|     EquipShenDecomposeIDMap = GetEquipShenDecomposeIDMap()  | 
|     if equipItemID not in EquipShenDecomposeIDMap:  | 
|         GameWorld.DebugLog("        Î´ÕÒµ½Ô½ø»¯×°±¸£¬ÎÞ·¨·Ö½â£¡equipItemID=%s" % equipItemID)  | 
|         return equipItemID  | 
|       | 
|     decomposeID = EquipShenDecomposeIDMap[equipItemID]  | 
|     evolveIpyData = IpyGameDataPY.GetIpyGameData("EquipShenEvolve", decomposeID)  | 
|     if not evolveIpyData:  | 
|         return equipItemID  | 
|       | 
|     getItemIDInfoList = evolveIpyData.GetEvolveNeedItemIDInfo()  | 
|     decomposeGetItemPer = IpyGameDataPY.GetFuncCfg("EquipShenDecompose", 1)  | 
|     GameWorld.DebugLog("        ¿É·Ö½âÉñ×°: equipItemID=%s,decomposeID=%s,getItemIDInfoList=%s"   | 
|                        % (equipItemID, decomposeID, getItemIDInfoList))  | 
|       | 
|     # ·Ö½â»ñµÃ80%Ô²ÄÁÏ£¬¸öÊýÏòÉÏÈ¡Õû  | 
|     for getItemID, srcCount in getItemIDInfoList:  | 
|         getCount = int(math.ceil(srcCount * decomposeGetItemPer / 100.0))  | 
|         getItemIDCountDict[getItemID] = getItemIDCountDict.get(getItemID, 0) + getCount  | 
|           | 
|     return CheckEquipShenDecompose(decomposeID, getItemIDCountDict)  | 
|   | 
| def GetEquipShenDecomposeIDMap():  | 
|     key = "EquipShenDecomposeIDMap"  | 
|     EquipShenDecomposeIDMap = IpyGameDataPY.GetConfigEx(key)  | 
|     if not EquipShenDecomposeIDMap:  | 
|         EquipShenDecomposeIDMap = {}  | 
|         ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|         for index in xrange(ipyDataMgr.GetEquipShenEvolveCount()):  | 
|             ipyData = ipyDataMgr.GetEquipShenEvolveByIndex(index)  | 
|             equipID = ipyData.GetEquipItemID()  | 
|             evolveEquipID = ipyData.GetEvolveEquipID()  | 
|             EquipShenDecomposeIDMap[evolveEquipID] = equipID # ·Ö½âµÄÔò·´ÏòÓ³Éä  | 
|         IpyGameDataPY.SetConfigEx(key, EquipShenDecomposeIDMap)  | 
|     return EquipShenDecomposeIDMap  | 
|   |