ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEquipDecompose.py
@@ -51,10 +51,11 @@
#struct    tagCMEquipDecompose
#{
#    tagHead        Head;
#    BYTE        IndexCount;        //材料所在背包索引的数量
#    BYTE        IndexList[IndexCount];    //材料所在背包索引列表
#    BYTE        Count;        //材料所在背包索引的数量
#    WORD        IndexList[Count];    //材料所在背包索引列表
#    DWORD        ItemIDList[Count];    //材料所在背包物品ID列表
#    BYTE        IsAuto;        //是否自动分解
#};
## 玩家分解装备封包 A5 08
#  @param playerIndex 玩家索引  
#  @param clientData 客户端封包  
@@ -62,23 +63,26 @@
#  @return None
def OnDoEquipDecompose(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    if not clientData.Count:
        return
    eatIndexList = clientData.IndexList
    EatItems(curPlayer, eatIndexList)
    eatItemIDList = clientData.ItemIDList
    isAuto = clientData.IsAuto
    EatItems(curPlayer, eatIndexList, eatItemIDList, isAuto)
    return
# 吞噬物品, 返回被吞数量
def EatItems(curPlayer, eatIndexList):
    eatItemList, totalAddExp = __GetCanEatItemInfo(curPlayer, eatIndexList)
def EatItems(curPlayer, eatIndexList, eatItemIDList, isAuto=False):
    if len(eatIndexList) != len(eatItemIDList):
        return 0, 0
    drDelItemList, totalAddExp, delAllCnt = __GetCanEatItemInfo(curPlayer, eatIndexList, eatItemIDList)
    if not totalAddExp:
        GameWorld.DebugLog("    装备吸收 没有可吞噬物品!")
        return 0, 0
    LV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeLV)
    Exp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeExp)
    reduceTotalExp, updLV, updExp = __GetEatItemResult(curPlayer, LV, Exp, totalAddExp)
    # 扣除吞噬物品
    drDelItemList, delAllCnt = __DelEatItem(curPlayer, reduceTotalExp, eatItemList)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EquipDecomposeExp, updExp)
    if LV != updLV:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EquipDecomposeLV, updLV)
@@ -117,7 +121,7 @@
    Sync_EDLVInfo(curPlayer, jsonItemList)
    # 流向
    saveDataDict = {"ExpBefore":Exp, "AddTotalExp":reduceTotalExp, "ExpAfter":updExp,
                    "DelItemList(ItemID,delCnt,baseExp,addExp)":drDelItemList}
                    "DelItemList(ItemID,delCnt,baseExp,addExp)":drDelItemList, 'isAuto':isAuto}
    DataRecordPack.DR_ClassUpSystem(curPlayer, "EquipDecomposeUp", updLV, saveDataDict)
    
    #EventReport.WriteEvent__lv(curPlayer, LV, updLV, Exp, updExp)
@@ -126,22 +130,26 @@
##获取可以吞噬的物品信息
#  @param curPlayer: 玩家实例
#  @return [可吞噬的物品列表], 最大可提供的经验
def __GetCanEatItemInfo(curPlayer, expIndexList):
def __GetCanEatItemInfo(curPlayer, expIndexList, eatItemIDList):
    eatItemList = []
    totalAddExp = 0
    allitemCnt = 0
    petEatItemAddExpPer = PlayerVip.GetPrivilegeValue(curPlayer, ChConfig.VIPPrivilege_EatItem)
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    for index in expIndexList:
    for i, index in enumerate(expIndexList):
        eatItem = itemPack.GetAt(index)
        
        if not eatItem or eatItem.IsEmpty():
            continue
        eatItemID = eatItem.GetItemTypeID()
        if eatItemIDList[i] != eatItemID:
            GameWorld.ErrLog('    装备分解客户端发的物品索引与实际物品ID不对应  index=%s,eatItemID=%s,wantEatItemID=%s'%(index, eatItemID, eatItemIDList[i]))
            continue
        if eatItem.GetType() == ChConfig.Def_ItemType_EquipDecomposeExp:
            curEff = eatItem.GetEffectByIndex(0)
            baseExp = curEff.GetEffectValue(0)
        else:
        elif ItemCommon.CheckItemIsEquip(eatItem):
            itemColor = eatItem.GetItemColor()
            itemClass = eatItem.GetLV()
            ipyData = IpyGameDataPY.GetIpyGameData("PetEatEquip", itemColor, itemClass)
@@ -149,19 +157,26 @@
                GameWorld.DebugLog("    tagPetEatEquip.txt,未配置该物品! eatItemID=%s, EquipColor=%s,EquipClass=%s" % (eatItemID, itemColor, itemClass))
                continue
            baseExp = ipyData.GetExp()
        if petEatItemAddExpPer:
            baseExp += baseExp * petEatItemAddExpPer / ChConfig.Def_MaxRateValue
        else:
            GameWorld.ErrLog('    不可分解的道具index=%s eatItemID=%s'%(index, eatItemID))
            continue
        itemCnt = eatItem.GetCount() # 装备一般默认1,如是经验道具则一般可叠加
        addExp = baseExp * itemCnt
        
        totalAddExp += addExp
        allitemCnt += itemCnt
        ItemCommon.DelItem(curPlayer, eatItem, itemCnt, True, ChConfig.ItemDel_EquipDecompose)
        
        GameWorld.DebugLog("    i=%s,baseExp=%s,itemCnt=%s,addExp=%s,totalAddExp=%s"
        GameWorld.DebugLog("    吸收 删除物品 i=%s,baseExp=%s,itemCnt=%s,addExp=%s,totalAddExp=%s"
                           % (index, baseExp, itemCnt, addExp, totalAddExp))
        # 先检索可吃列表,防止升级过程中吃掉原来不可吃的[index, 物品实例, 基础经验]
        eatItemList.append([index, eatItem, baseExp])
    return eatItemList, totalAddExp
        eatItemList.append([eatItemID, itemCnt, baseExp, addExp])
    if petEatItemAddExpPer:
        totalAddExp += totalAddExp * petEatItemAddExpPer / ChConfig.Def_MaxRateValue
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_DecomposeEquip, allitemCnt)
    return eatItemList, totalAddExp, allitemCnt
##获取吞噬结果
@@ -170,12 +185,17 @@
def __GetEatItemResult(curPlayer, LV, Exp, totalAddExp):
    remainExp = totalAddExp # 剩余可用经验
    reduceTotalExp = 0 # 真正需要扣除的经验
    ipyMgr = IpyGameDataPY.IPY_Data()
    maxLV = ipyMgr.GetEquipDecomposeByIndex(ipyMgr.GetEquipDecomposeCount()-1).GetLV()
    # 经验检查
    while remainExp > 0:
        if LV +1 >= maxLV:
            break
        maxExp = __GetLvUpNeedExp(LV)
        
        if not maxExp:
            break
        needExp = max(0, maxExp - Exp)
        if remainExp >= needExp:
            Exp = 0
@@ -187,46 +207,19 @@
            reduceTotalExp += remainExp
            remainExp = 0
            
    #等级满后也可以分解加经验,故所有装备都分解
    Exp += remainExp
    reduceTotalExp = totalAddExp
    GameWorld.DebugLog("总可加经验=%s,实际总扣除经验=%s,newLV=%s,最终经验=%s" % 
                       (totalAddExp, reduceTotalExp, LV, Exp))
    return reduceTotalExp, LV, Exp
##扣除吞噬物品
#  @param curPlayer: 玩家实例
#  @return
def __DelEatItem(curPlayer, reduceTotalExp, eatItemList):
    drDelItemList = []
    delAllCnt = 0 #删除物品总个数
    # 扣物品
    for index, eatItem, baseExp in eatItemList:
        eatItemID = eatItem.GetItemTypeID()
        curItemCnt = eatItem.GetCount()
        curItemTotalExp = baseExp * curItemCnt
        if reduceTotalExp >= curItemTotalExp:
            delCnt = curItemCnt
            reduceTotalExp -= curItemTotalExp
        else:
            delCnt = int(math.ceil(reduceTotalExp / float(baseExp)))
            reduceTotalExp = 0
        addExp = delCnt * baseExp
        delAllCnt += delCnt
        # 这里不记录流向, 在外部统一记录
        ItemCommon.DelItem(curPlayer, eatItem, delCnt, True, ChConfig.ItemDel_EquipDecompose)
        GameWorld.DebugLog("        吸收 删除物品 i=%s,delCnt=%s,addExp=%s" % (index, delCnt, addExp))
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_DecomposeEquip, delCnt)
        drDelItemList.append((eatItemID, delCnt, baseExp, addExp))
        if reduceTotalExp <= 0:
            break
    return drDelItemList, delAllCnt
def __GetLvUpNeedExp(lv):
    """获取装备分解升级需要经验"""
    lv += 1 #配置的等级从1开始
    ipyData = IpyGameDataPY.GetIpyGameData("EquipDecompose", lv)
    #配置的等级从1开始
    ipyData = IpyGameDataPY.GetIpyGameData("EquipDecompose", lv+1)
    if not ipyData:
        return 0
    return ipyData.GetUpNeedExp()