ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Item/ItemControler.py
@@ -33,7 +33,10 @@
import Operate_EquipStone
import Operate_EquipSuitCompose
import IpyGameDataPY
import DataRecordPack
import EventShell
import math
#---------------------------------------------------------------------
## 放不下主角背包放入万能背包的逻辑, curGiveItem 要先 SetCount
#  @param curPlayer 当前玩家
@@ -876,9 +879,10 @@
                return -1
        curPlayer = self.__Player
        #equipPack = self.__PlayerEquip
        #equipItem = equipPack.GetAt(packEquipIndex)
        equipPack = self.__PlayerEquip
        equipItem = equipPack.GetAt(packEquipIndex)
        desItemID, desUserData = [0, ''] if equipItem.IsEmpty() else [equipItem.GetItemTypeID(), equipItem.GetUserData()]
        srcItemID, srcUserData = curItem.GetItemTypeID(), curItem.GetUserData()
        # 装备绑定处理 在 DoLogic_ItemBindType函数有处理,此处注释掉
#        if not curItem.GetIsBind():
#            SetItemIsBind(curItem, True)
@@ -893,6 +897,9 @@
            Operate_EquipStone.DoMoveEquipStone(curPlayer, packEquipIndex)
            #套装降级处理
            Operate_EquipSuitCompose.CheckEquipSuitReduce(curPlayer, packEquipIndex)
            EventShell.EventRespons_EquipStar(curPlayer)
            dataDict = {'dotype':'EquipItem', 'desItemID':desItemID, 'desUserData':desUserData,'srcItemID':srcItemID,'srcUserData':srcUserData}
            DataRecordPack.Cache_FightPowerChangeInfo(curPlayer, ChConfig.PowerDownType_EquipChange, dataDict)
            
        self.RefreshStartEquipCount()
        return packEquipIndex if result else -1
@@ -953,7 +960,7 @@
            return
        
        equipID = curEquip.GetItemTypeID()
        userData = curEquip.GetUserData()
        #该物品锁定不执行==============================================
        if curEquip.GetIsLocked():
            PlayerControl.NotifyCode(curPlayer, "RescannotEquip")
@@ -990,6 +997,9 @@
        self.RefreshStartEquipCount()
        #套装降级处理
        Operate_EquipSuitCompose.CheckEquipSuitReduce(curPlayer, equipIndex)
        EventShell.EventRespons_EquipStar(curPlayer)
        dataDict = {'dotype':'UnEquipItem', 'equipID':equipID, 'userData':userData}
        DataRecordPack.Cache_FightPowerChangeInfo(curPlayer, ChConfig.PowerDownType_EquipChange, dataDict)
#===============================================================================
#        #destItemPlace = 卸下物品的位置        
#        destItemPlace = curPack.GetAt(packIndex)
@@ -1009,7 +1019,7 @@
#    小心, 小心, 小心, 小心, 小心
#    eggxp
#===============================================================================
    def __PutItemInVPack(self, packIndex, tagItem, event):
    def PutItemInVPack(self, packIndex, tagItem, event=["", False, {}]):
        # 虚拟背包, 默认不做叠加
        curPlayer = self.__Player
        canPutInCnt = 1
@@ -1017,7 +1027,10 @@
        eventName, isForceEvent, addDict = event
        isNeedRecord = isForceEvent or ItemNeedRecord(tagItem)
        if packIndex == ShareDefine.rptRune:
            setItemKeyData = GetRuneItemKeyData(tagItem.GetItemTypeID(), tagItem.GetUserAttr(ShareDefine.Def_IudetRuneLV))
            runeSource = tagItem.GetUserAttr(ShareDefine.Def_IudetRuneSource) or 1
            setItemKeyData = GetRuneItemKeyData(tagItem.GetItemTypeID(), tagItem.GetUserAttr(ShareDefine.Def_IudetRuneLV), source=runeSource)
        elif packIndex == ShareDefine.rptGatherSoul:
            setItemKeyData = GetGatherSoulItemKeyData(tagItem.GetItemTypeID(), tagItem.GetUserAttr(ShareDefine.Def_IudetGatherSoulLV))
        refreshPlaceList = []
        for place in xrange(ItemCommon.GetVPackCnt(packIndex)):
@@ -1044,11 +1057,11 @@
            Sync_VPackItem_Refresh(curPlayer, packIndex, refreshPlaceList)
        if tagItem and not tagItem.IsEmpty():
            tagItem.Clear()
            #tagItem.Clear()
            return False
        return True
    
    def __DoTransformItem(self, curPlayer, tagItem):
    def DoTransformItem(self, curPlayer, tagItem):
        ## 将特殊物品转化为对应数值
        itemID = tagItem.GetItemTypeID()
        if itemID not in ChConfig.Def_TransformItemIDList:
@@ -1070,8 +1083,29 @@
        elif itemID == ChConfig.Def_ItemID_BossReborn:
            msgStr = str(itemCount)
            GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, 'AddBossRebornPoint', msgStr, len(msgStr))
        elif itemID == ChConfig.Def_ItemID_Ysog:
            PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_Ysog, itemCount)
        elif itemID == ChConfig.Def_ItemID_SoulDust:
            PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_SoulDust, itemCount)
        elif itemID == ChConfig.Def_ItemID_SoulSplinters:
            PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_SoulSplinters, itemCount)
        elif itemID == ChConfig.Def_ItemID_SoulCore:
            PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_SoulCore, itemCount)
        elif itemID == ChConfig.Def_ItemID_Honor:
            PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_Honor, itemCount)
        return True
    def __CrossServerPutInItem(self, packIndex, tagItem, event=["", False, {}]):
        ## 跨服获得物品
        if packIndex not in [IPY_GameWorld.rptItem, ShareDefine.rptDogzItem, ShareDefine.rptZhuXianItem]:
            #GameWorld.DebugLog("跨服获得物品不同步, packIndex=%s" % (packIndex))
            return
        curPlayer = self.__Player
        serverGroupID = PlayerControl.GetPlayerServerGroupID(curPlayer)
        itemData = [tagItem.GetItemTypeID(), tagItem.GetCount(), tagItem.GetIsBind(), tagItem.GetUserData()]
        itemMsg = {"PlayerID":curPlayer.GetPlayerID(), "ItemData":itemData, "PackIndex":packIndex, "Event":event}
        GameWorld.SendMsgToClientServer(ShareDefine.CrossServerMsg_PutInItem, itemMsg, [serverGroupID])
        return
    
    ## 放入物品 
    #  @param packIndex 背包索引
@@ -1082,10 +1116,6 @@
    def PutInItem(self, packIndex, tagItem, defaultPile=True, event=["", False, {}]):
        curPlayer = self.__Player
        
        if self.__DoTransformItem(curPlayer, tagItem):
            tagItem.Clear() # 需清除,不然会导致内存泄露
            return True
        isEquip = ItemCommon.CheckItemIsEquip(tagItem)
        if isEquip:
            defaultPile = False # 装备默认不判断堆叠
@@ -1094,21 +1124,39 @@
        if not curItemData:
            return False
        
        vPackItemDict = ChConfig.Def_VPackItem_Dict
        if GameWorld.IsCrossServer():
            self.__CrossServerPutInItem(packIndex, tagItem, event)
            tagItem.Clear()
            return True
        if CheckChangeOldItem(curPlayer, tagItem):
            tagItem.Clear()
            return True
        packIndex = ChConfig.GetItemPackType(curItemData.GetType(), packIndex)
        
        for pack, itemTypeList in vPackItemDict.items():
            if curItemData.GetType() in itemTypeList:
                packIndex = pack
                break
        if not self.CanPutInItem(packIndex, tagItem.GetItemTypeID(), tagItem.GetCount(), tagItem.GetIsBind(), defaultPile):
            GameWorld.DebugLog("背包满,不能放入物品 count = %d"%tagItem.GetCount())
        if not self.CanPutInItem(packIndex, tagItem.GetItemTypeID(), GetItemCount(tagItem), tagItem.GetIsBind(), defaultPile):
            GameWorld.DebugLog("背包满,不能放入物品 count = %d"%GetItemCount(tagItem))
            tagItem.Clear()
            return False
        
        itemID = tagItem.GetItemTypeID()
        #激活成就的道具
        if tagItem.GetType() == ChConfig.Def_ItemType_SuccessItem:
            PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_GetSpecialItem, 1, [tagItem.GetEffectByIndex(0).GetEffectValue(0)])
            return True
        if itemID in ChConfig.Def_TransformItemIDList:
            # 直接转化为对应货币的物品仅在放入背包时直接转化,否则还是以真实物品的形式存在,但堆叠上限需要做特殊处理
            if packIndex == IPY_GameWorld.rptItem:
                self.DoTransformItem(curPlayer, tagItem)
                tagItem.Clear() # 需清除,不然会导致内存泄露
                return True
            defaultPile = True
            maxPackCount = ChConfig.Def_UpperLimit_DWord # 转化物品叠加上限不取物品表的, 暂定堆叠上限20亿
        else:
            maxPackCount = curItemData.GetPackCount()
        # 虚拟背包, 默认不做叠加
        if packIndex in ShareDefine.Def_VPack_TypeList:
            return self.__PutItemInVPack(packIndex, tagItem, event)
            return self.PutItemInVPack(packIndex, tagItem, event)
        
        eventName, isForceEvent, addDict = event
@@ -1122,7 +1170,7 @@
        isBind = tagItem.GetIsBind()
        isNeedRecord = False
        # 目前暂只记录放入背包的
        if packIndex in [IPY_GameWorld.rptItem, ShareDefine.rptTreasure, ShareDefine.rptRune]:
        if packIndex in [IPY_GameWorld.rptItem, ShareDefine.rptTreasure, ShareDefine.rptRune, ShareDefine.rptGatherSoul]:
            isNeedRecord = ItemNeedRecord(tagItem) or isForceEvent
        putResult = False
        
@@ -1141,9 +1189,9 @@
                if item.GetIsLocked() == True:
                    continue
                
                packItemCount = item.GetCount()
                curItemCount = tagItem.GetCount()
                canPutinCount = tagItem.GetPackCount() - packItemCount
                packItemCount = GetItemCount(item)
                curItemCount = GetItemCount(tagItem)
                canPutinCount = maxPackCount - packItemCount
                if canPutinCount <= 0:
                    continue    
                #可以摆放
@@ -1179,19 +1227,17 @@
            if item.IsEmpty() != True:
                continue
            
            packItemCount = item.GetCount() # Ϊ0
            curItemCount = tagItem.GetCount()
            canPutinCount = tagItem.GetPackCount() - packItemCount
            packItemCount = GetItemCount(item) # Ϊ0
            curItemCount = GetItemCount(tagItem)
            canPutinCount = maxPackCount - packItemCount
            if canPutinCount <= 0:
                continue
            #可以摆放
            if curItemCount > canPutinCount:
                #需要创建新物品放入
                curCreateItem = ItemCommon.CreateSingleItem(tagItem.GetItemTypeID())
                curCreateItem = GetOutPutItemObj(tagItem.GetItemTypeID(), canPutinCount, isBind)
                #注意: 不能在这里AssignItem, 否则会有2个物品指针指向同一个物品实例 . 巨大的错误在这一句 : curCreateItem.Assign(tagItem)
                SetItemCount(curCreateItem, canPutinCount)
                SetItemIsBind(curCreateItem, isBind)
                #此处不做装备拆解,如有需求外传for处理
                #如果是装备,那么 maxPackCount 为1 这里会循环自动创建新物品,所以直接 GetOutPutItemObj 即可, 暂不支持定制装备拆解
                
                item.AssignItem(curCreateItem)
                SetItemCount(tagItem, curItemCount - canPutinCount)
@@ -1201,6 +1247,9 @@
                    ItemCommon.DR_GetItem(curPlayer, packIndex, eventName, itemNoteDict, addDict)
            else:
                #可以放下
                if isEquip:
                    self.CheckEquipAttr(packIndex, tagItem)
                if tagItem.GetGameWorldItemType() == IPY_GameWorld.gwitRoleItem:
                    item.PutIn(tagItem)
                elif tagItem.GetGameWorldItemType() == IPY_GameWorld.gwitSingleItem:
@@ -1210,13 +1259,93 @@
                putResult = True
                
                if isNeedRecord:
                    itemNoteDict = ItemCommon.GetItemNoteDict(item, curItemCount, packItemCount, item.GetCount())
                    itemNoteDict = ItemCommon.GetItemNoteDict(item, curItemCount, packItemCount, GetItemCount(item))
                    ItemCommon.DR_GetItem(curPlayer, packIndex, eventName, itemNoteDict, addDict)
                break
                                                
        #放入东西
        return putResult
    
    def CheckEquipAttr(self, packType, curItem):
        legendAttrIDCount = curItem.GetUserAttrCount(ShareDefine.Def_IudetLegendAttrID)
        legendAttrValueCount = curItem.GetUserAttrCount(ShareDefine.Def_IudetLegendAttrValue)
        if legendAttrIDCount and legendAttrValueCount and legendAttrIDCount == legendAttrValueCount:
            return
        legendAttrInfo = GetAddEquipLegendAttr(curItem)
        if not legendAttrInfo:
            return
        curPlayer = self.__Player
        srcScore = ItemCommon.GetEquipGearScore(curItem)
        legendAttrIDList, legendAttrValueList = legendAttrInfo
        curItem.ClearUserAttr(ShareDefine.Def_IudetLegendAttrID)
        curItem.ClearUserAttr(ShareDefine.Def_IudetLegendAttrValue)
        for i in xrange(len(legendAttrIDList)):
            curItem.AddUserAttr(ShareDefine.Def_IudetLegendAttrID, legendAttrIDList[i])
            curItem.AddUserAttr(ShareDefine.Def_IudetLegendAttrValue, legendAttrValueList[i])
        ItemCommon.MakeEquipGS(curItem)
        updScore = ItemCommon.GetEquipGearScore(curItem)
        GameWorld.ErrLog("传奇属性异常,重新刷新一次属性: packType=%s,itemID=%s,legendAttrIDList=%s,legendAttrValueList=%s,srcScore=%s,updScore=%s"
                         % (packType, curItem.GetItemTypeID(), legendAttrIDList, legendAttrValueList, srcScore, updScore), curPlayer.GetPlayerID())
        return
    def CheckRolePackEquipAttr(self):
        ''' 玩家上线修复装备属性bug
                    版本1:邮件给装备没有传奇属性,检查无传奇属性装备
                    版本2:绝版属性数值调整,已获得的装备重新刷下
        '''
        curPlayer = self.__Player
        checkVersion = 20190103
        key = "LoginCheckEquipAttr"
        curVersion = curPlayer.NomalDictGetProperty(key)
        if curVersion == checkVersion:
            return
        playerID = curPlayer.GetPlayerID()
        GameWorld.Log("玩家上线处理装备属性! curVersion=%s,checkVersion=%s" % (curVersion, checkVersion), playerID)
        outOfPrintAttrItemDict = {} # 有绝版属性的定制物品属性信息 {itemID:[绝版属性ID列表, 绝版属性数值列表], ...}
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetAppointItemCount()):
            ipyData = ipyDataMgr.GetAppointItemByIndex(i)
            outOfPrintAttrList = ipyData.GetOutOfPrintAttr()
            outOfPrintAttrValueList = ipyData.GetOutOfPrintAttrValue()
            if not outOfPrintAttrList or len(outOfPrintAttrList) != len(outOfPrintAttrValueList):
                continue
            itemID = GetAppointItemRealID(ipyData.GetID())
            if not itemID:
                continue
            outOfPrintAttrItemDict[itemID] = [outOfPrintAttrList, outOfPrintAttrValueList]
        checkPackList = [IPY_GameWorld.rptEquip, IPY_GameWorld.rptItem, IPY_GameWorld.rptWarehouse]
        for packType in checkPackList:
            curPack = curPlayer.GetItemManager().GetPack(packType)
            for i in xrange(curPack.GetCount()):
                curItem = curPack.GetAt(i)
                #GameWorld.DebugLog("packType=%s,i=%s" % (packType, i))
                if curItem.IsEmpty():
                    continue
                isEquip = ItemCommon.CheckItemIsEquip(curItem)
                if not isEquip:
                    continue
                itemID = curItem.GetItemTypeID()
                self.CheckEquipAttr(packType, curItem)
                # 重刷绝版属性
                if itemID in outOfPrintAttrItemDict:
                    outOfPrintAttrList, outOfPrintAttrValueList = outOfPrintAttrItemDict[itemID]
                    curItem.ClearUserAttr(ShareDefine.Def_IudetOutOfPrintAttrID)
                    curItem.ClearUserAttr(ShareDefine.Def_IudetOutOfPrintAttrValue)
                    for outOfPrintAttrIndex in xrange(len(outOfPrintAttrList)):
                        curItem.AddUserAttr(ShareDefine.Def_IudetOutOfPrintAttrID, outOfPrintAttrList[outOfPrintAttrIndex])
                        curItem.AddUserAttr(ShareDefine.Def_IudetOutOfPrintAttrValue, outOfPrintAttrValueList[outOfPrintAttrIndex])
                    GameWorld.Log("    玩家登录重刷装备绝版属性: packType=%s,i=%s,itemID=%s,outOfPrintAttrList=%s,outOfPrintAttrValueList=%s"
                                  % (packType, i, itemID, outOfPrintAttrList, outOfPrintAttrValueList), playerID)
        PlayerControl.NomalDictSetProperty(curPlayer, key, checkVersion)
        return
    ## 是否能放入物品 
    #  @param packIndex 背包索引
    #  @param curItemID 当前物品ID
@@ -1226,6 +1355,8 @@
    #  @return True or False
    #  @remarks 函数详细说明.
    def CanPutInItem(self, packIndex, curItemID, curItemCount, isBind, defaultPile=True):
        if GameWorld.IsCrossServer():
            return True
        checkRet, putIndex = self.CanPutInItemEx(packIndex, curItemID, curItemCount, isBind, defaultPile)
        return checkRet
    
@@ -1246,14 +1377,19 @@
            return False, 0 
        
        if curItemID in ChConfig.Def_TransformItemIDList:
            #特殊物品无需判断数量
            return True, 0
        maxPackCount = curItemData.GetPackCount()
            # 货币直接转换的物品如果是放入背包的则直接转化,无需暂用格子
            if packIndex == IPY_GameWorld.rptItem:
                return True, 0
            maxPackCount = ChConfig.Def_UpperLimit_DWord # 转化物品叠加上限不取物品表的, 暂定堆叠上限20亿
        else:
            maxPackCount = curItemData.GetPackCount()
        if maxPackCount == 0:
            GameWorld.Log("策划填表错误 %s -> maxPackCount = %s" % (curItemID , maxPackCount))
            return False, 0
        # 特殊处理不同的物品放入不同的背包,如神兽背包
        packIndex = ChConfig.GetItemPackType(curItemData.GetType(), packIndex)
        
        maxCanPutItem = 0
        curPlayer = self.__Player
@@ -1271,7 +1407,7 @@
        
        itemIndex = -1
        curPack = self.__PlayerItemManager.GetPack(packIndex)
        for i in range(0, curPack.GetCount()):
        for i in xrange(curPack.GetCount()):
            item = curPack.GetAt(i)
            if item.IsEmpty():
@@ -1285,10 +1421,10 @@
                        continue
    
                    if (CanPackItemByItemType(item.GetItemTypeID(), item.GetIsBind(), curItemID, isBind) and
                        maxPackCount > item.GetCount()):
                        maxPackCount > GetItemCount(item)):
                        #该物品锁定不执行==============================================
                        #可堆叠
                        maxCanPutItem += maxPackCount - item.GetCount()
                        maxCanPutItem += maxPackCount - GetItemCount(item)
                        if itemIndex == -1:
                            itemIndex = i
            
@@ -1300,14 +1436,23 @@
        return True, itemIndex
    
#==============================================================================
# 符印物品存储字典数值数据结构: 前5位为物品ID, 6~8位为强化等级, 第10位为是否锁定
def GetRuneItemKeyData(itemID, RuneLV, lockState=0):
# 符印物品存储字典数值数据结构: 前5位为物品ID, 6~8位为强化等级, 第9位为来源(老号0,默认1,合成2),第10位为是否锁定
def GetRuneItemKeyData(itemID, RuneLV, lockState=0, source=1):
    lockState = 1 if lockState > 0 else 0
    return lockState * 1000000000 + min(RuneLV, 999) * 100000 + itemID
    return lockState * 1000000000 + source * 100000000 + min(RuneLV, 999) * 100000 + itemID
def GetRuneItemID(keyData): return keyData % 100000
def GetRuneItemPlusLV(keyData): return keyData % 100000000 / 100000
def GetRuneItemIsLock(keyData): return keyData / 1000000000
def GetRuneItemSource(keyData): return keyData % 1000000000 / 100000000
def IsRuneItemNeedRecord(curItem, plusLV):
    return plusLV > 0 or curItem.GetItemColor() >= ChConfig.Def_Quality_Orange
# 聚魂物品存储字典数值数据结构: 前5位为物品ID, 6~8位为强化等级
def GetGatherSoulItemKeyData(itemID, GatherSoulLV):
    return min(GatherSoulLV, 999) * 100000 + itemID
def GetGatherSoulItemID(keyData): return keyData % 100000
def GetGatherSoulItemPlusLV(keyData): return keyData % 100000000 / 100000
def IsGatherSoulItemNeedRecord(curItem, plusLV):
    return plusLV > 0 or curItem.GetItemColor() >= ChConfig.Def_Quality_Orange
def SetVPackItemKeyData(curPlayer, packIndex, place, keyData, isSync=True):
@@ -1365,7 +1510,7 @@
    DropItemToOtherPack(curPlayer, clientData.SrcBackpack, clientData.DesBackPack, clientData.SrcIndex, clientData.IsAll)
    return
def DropItemToOtherPack(curPlayer, fromPackIndex, toPackIndex, index, isAll=False):
def DropItemToOtherPack(curPlayer, fromPackIndex, desPackIndex, index, isAll=False):
    '''拖动某个背包物品到玩家物品背包
    '''
    movePack = curPlayer.GetItemManager().GetPack(fromPackIndex)
@@ -1376,26 +1521,46 @@
    
    #整个背包转移
    if isAll:
        fullPackList = []
        for itemIndex in xrange(movePack.GetCount()):
            curItem = movePack.GetAt(itemIndex)
            if not curItem or curItem.IsEmpty():
                continue
            toPackIndex = ChConfig.GetItemPackType(curItem.GetType(), desPackIndex)
            if toPackIndex in fullPackList:
                continue
            if not __DoDropItemToOtherPack(curPlayer, itemControl, fromPackIndex, toPackIndex, itemIndex, curItem):
                return
                if toPackIndex not in fullPackList:
                    fullPackList.append(toPackIndex)
        for fullPackIndex in fullPackList:
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [fullPackIndex])
            
    #单个物品转移
    else:
        curItem = movePack.GetAt(index)
        if not curItem or curItem.IsEmpty():
            return
        toPackIndex = ChConfig.GetItemPackType(curItem.GetType(), desPackIndex)
        __DoDropItemToOtherPack(curPlayer, itemControl, fromPackIndex, toPackIndex, index, curItem)
    return
def __DoDropItemToOtherPack(curPlayer, itemControl, fromPackIndex, toPackIndex, itemIndex, curItem):
    if itemControl.DoTransformItem(curPlayer, curItem):
        curItem.Clear()
        return True
    curItemTypeID = curItem.GetItemTypeID()
    #curItemGUID = curItem.GetGUID()
    curItemCount = curItem.GetCount()
    curItemIsBind = curItem.GetIsBind()
    #toPackIndex = ChConfig.GetItemPackType(curItem.GetType(), toPackIndex)
    # 常规物品转移到虚拟符印背包
    if toPackIndex == ShareDefine.rptRune:
        if not ItemCommon.CheckPackHasSpace(curPlayer, toPackIndex, True):
            return False
        return itemControl.PutItemInVPack(toPackIndex, curItem)
    checkRet, putIndex = itemControl.CanPutInItemEx(toPackIndex, curItemTypeID, curItemCount, curItemIsBind)
    if not checkRet:
        return False
@@ -1576,6 +1741,8 @@
    itemList = []   # 非装备普通物品
    equipGSGreaterList = [] # 属于本职业的高评分装备
    equipGSLesserList = []  # 低评分装备和非本职业
    runeItemList = []   # 符印
    #EquipGSTypeForSort
    equipPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
    #组合列表
@@ -1596,7 +1763,9 @@
                equipGS = 1
                cmpEquipGS = 2
                
            if equipGS == 0:
            if tmpItem.GetType() in [ChConfig.Def_ItemType_Rune, ChConfig.Def_ItemType_RuneExp]:
                runeItemList.append(tmpItem)
            elif equipGS == 0:
                itemList.append(tmpItem)
            elif equipGS > cmpEquipGS:
                equipGSGreaterList.append(tmpItem)
@@ -1606,7 +1775,8 @@
    equipGSGreaterList.sort(__CmpRolePack)
    itemList.sort(__CmpRolePack)
    equipGSLesserList.sort(__CmpRolePack)
    runeItemList.sort(__CmpRolePack)
    #===========================================================================
    # GameWorld.DebugLog("equipGSGreaterList")
    # for item in equipGSGreaterList:
@@ -1641,36 +1811,68 @@
    for item in equipGSLesserList:
        curPack.GetAt(putPlace).AssignItem(item, False)
        putPlace += 1
    for item in runeItemList:
        curPack.GetAt(putPlace).AssignItem(item, False)
        putPlace += 1
    return
def __CmpRolePack(item1, item2):
    # 装备评分高  评分0  评分低,外层分列表
    # 颜色-星数 - 装备类型 - ID,内层比较 暂时不做时间判断
    if item1.GetItemColor() == item2.GetItemColor():
        if item1.GetItemQuality() == item2.GetItemQuality():
            itemType1 = item1.GetType()
            itemType2 = item2.GetType()
            if itemType1 == itemType2:
    #===========================================================================
    # # 颜色-星数 - 装备类型 - ID,内层比较 暂时不做时间判断
    #
    # if item1.GetItemColor() == item2.GetItemColor():
    #    if item1.GetItemQuality() == item2.GetItemQuality():
    #        itemType1 = item1.GetType()
    #        itemType2 = item2.GetType()
    #        if itemType1 == itemType2:
    #            return cmp(item1.GetItemTypeID(), item2.GetItemTypeID())
    #        else:
    #            #类型有定义配置顺序
    #            typeList = IpyGameDataPY.GetFuncEvalCfg("PackageSortPriority", 1)
    #            if itemType1 in typeList and itemType2 in typeList:
    #                return cmp(typeList.index(item1.GetType()), typeList.index(item2.GetType()))
    #            elif itemType1 in typeList:
    #                #排在前面
    #                return -1
    #            elif itemType2 in typeList:
    #                return 1
    #            else:
    #                return cmp(itemType1, itemType2)
    #    else:
    #        return cmp(0-item1.GetItemQuality(), 0-item2.GetItemQuality())
    # else:
    #    return cmp(0-item1.GetItemColor(), 0-item2.GetItemColor())
    #===========================================================================
    # 装备类型-颜色-星数 - ID,内层比较 暂时不做时间判断
    itemType1 = item1.GetType()
    itemType2 = item2.GetType()
    if itemType1 == itemType2:
        if item1.GetItemColor() == item2.GetItemColor():
            if item1.GetItemQuality() == item2.GetItemQuality():
                return cmp(item1.GetItemTypeID(), item2.GetItemTypeID())
            else:
                #类型有定义配置顺序
                typeList = IpyGameDataPY.GetFuncEvalCfg("PackageSortPriority", 1)
                if itemType1 in typeList and itemType2 in typeList:
                    return cmp(typeList.index(item1.GetType()), typeList.index(item2.GetType()))
                elif itemType1 in typeList:
                    #排在前面
                    return -1
                elif itemType2 in typeList:
                    return 1
                else:
                    return cmp(itemType1, itemType2)
                return cmp(0-item1.GetItemQuality(), 0-item2.GetItemQuality())
        else:
            return cmp(0-item1.GetItemQuality(), 0-item2.GetItemQuality())
            return cmp(0-item1.GetItemColor(), 0-item2.GetItemColor())
    else:
        return cmp(0-item1.GetItemColor(), 0-item2.GetItemColor())
        #类型有定义配置顺序
        typeList = IpyGameDataPY.GetFuncEvalCfg("PackageSortPriority", 1)
        if itemType1 in typeList and itemType2 in typeList:
            return cmp(typeList.index(item1.GetType()), typeList.index(item2.GetType()))
        elif itemType1 in typeList:
            #排在前面
            return -1
        elif itemType2 in typeList:
            return 1
        else:
            return cmp(itemType1, itemType2)
def __ResetItem_AddItemInList(curList, addItem):
    #把物品放到列表中, 要判断叠加
@@ -1877,16 +2079,10 @@
    if not curItemData:
        return False
    
    #激活成就的道具
    if curItemData.GetType() == ChConfig.Def_ItemType_SuccessItem:
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_GetSpecialItem, 1, [itemID])
        return True
    vPackItemDict = ChConfig.Def_VPackItem_Dict
    for pack, itemTypeList in vPackItemDict.items():
        if curItemData.GetType() in itemTypeList:
            packIndexList = [pack]
            break
    defaultPack = IPY_GameWorld.rptItem if not packIndexList else packIndexList[0]
    packIndex = ChConfig.GetItemPackType(curItemData.GetType(), defaultPack)
    if packIndex != defaultPack or not packIndexList:
        packIndexList = [packIndex]
    
    if not __Check_CanPutItemInPack(curPlayer, itemID, itemCount, itemIsBind, packIndexList, defaultPile):
        #不可放入
@@ -2127,7 +2323,21 @@
            errorInfo = "%s %s %s -- ItemControler->SetItemCount::" % (playerID, accID, playerName)
            GameWorld.ErrLog(errorInfo + str(traceback.extract_stack()) + "\n" + traceback.format_exc())
            raise
def GetItemCount(item):
    if item.GetItemTypeID() in ChConfig.Def_TransformItemIDList:
        return item.GetUserAttr(ShareDefine.Def_IudetItemCount)
    return item.GetCount()
def GetItemNeedPackCount(packType, itemData, itemCount):
    if itemData.GetItemTypeID() in ChConfig.Def_TransformItemIDList:
        # 货币直接转换的物品如果是放入背包的则不需要暂用格子,放入其他的背包的则按物品叠加上限算
        if packType == IPY_GameWorld.rptItem:
            return 0
        packCount = ChConfig.Def_UpperLimit_DWord # 转化物品叠加上限不取物品表的
    else:
        packCount = itemData.GetPackCount()
    return int(math.ceil(itemCount / float(packCount)))
## 双手武器,需要两只手才拿得动
#  @param curEquip
@@ -2168,10 +2378,10 @@
    #---无空位置,替换---
    return placeList[0]
def GetOutPutItemObj(itemID, itemCount=1, isBind=0):
def GetOutPutItemObj(itemID, itemCount=1, isBind=0, expireTime=0):
    ''' 获取功能产出的物品实例
    '''
    curItem = ItemCommon.CreateSingleItem(itemID, itemCount, isBind)
    curItem = ItemCommon.CreateSingleItem(itemID, itemCount, isBind, expireTime)
    if not curItem:
        GameWorld.ErrLog("产出物品异常,无法创建物品 = %s" % (itemID))
        return
@@ -2206,12 +2416,21 @@
    if itemType == ChConfig.Def_ItemType_retWing:
        return __GetAddWingLegendAttr(curItem)
    
    isZhuXianEquip = ItemCommon.GetIsZhuXianEquip(curItem)
    if isZhuXianEquip:
        return __GetRandLegendAttr(curItem)
    itemColor = curItem.GetItemColor()
    itemClassLV = ItemCommon.GetItemClassLV(curItem)
    itemQuality = curItem.GetItemQuality()
    key = (itemColor, itemQuality)
    isDogzEquip = ItemCommon.GetIsDogzEquip(curItem)
    # {(颜色,星级):[一般属性条数, 追求属性条数, 固定属性条数], ...}
    legAttrCntDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrCount")
    if isDogzEquip:
        #神兽装备条数不一样
        legAttrCntDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrCount", 2)
    else:
        legAttrCntDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrCount")
    if key not in legAttrCntDict:
        #GameWorld.DebugLog("该装备品质没有传奇属性: itemColor=%s,itemQuality=%s" % (itemColor, itemQuality))
        return
@@ -2240,13 +2459,37 @@
    curLegAttrIDList = []
    curLegAttrValueList = []
    # {属性ID:{颜色:数值, ...}, ...}
    legAttrValueColorDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrValueByColor")
    if isDogzEquip:
        # 神兽装备数值不一样
        legAttrValueColorDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrValueByColor2", 1, {})
        legAttrValueClassLVColorDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrValueByColor2", 2, {})
    else:
        legAttrValueColorDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrValueByColor", 1, {})
        legAttrValueClassLVColorDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrValueByColor", 2, {})
    legAttrValueClassLVDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrValueByClassLV")
    for attrID in randAttrIDList:
        if attrID in legAttrValueColorDict:
            colorValueDict = legAttrValueColorDict[attrID]
            if itemColor not in colorValueDict:
                GameWorld.ErrLog("没有配置传奇属性ID装备颜色对应的数值, attrID=%s,itemColor=%s" % (attrID, itemColor))
                continue
            attrValue = colorValueDict[itemColor]
        # {属性ID:{阶:{颜色:数值, ...}, ...}, ...}
        elif attrID in legAttrValueClassLVColorDict:
            classLVColorValueDict = legAttrValueClassLVColorDict[attrID]
            if itemClassLV in classLVColorValueDict:
                colorValueDict = classLVColorValueDict[itemClassLV]
            else:
                minClassLV, maxClassLV = min(classLVColorValueDict), max(classLVColorValueDict)
                if itemClassLV <= minClassLV:
                    colorValueDict = classLVColorValueDict[minClassLV]
                elif itemClassLV >= maxClassLV:
                    colorValueDict = classLVColorValueDict[maxClassLV]
                else:
                    GameWorld.ErrLog("没有配置传奇属性ID装备阶级颜色对应的数值, attrID=%s,itemClassLV=%s" % (attrID, itemClassLV))
                    continue
            if itemColor not in colorValueDict:
                GameWorld.ErrLog("没有配置传奇属性ID装备阶级颜色对应的数值, attrID=%s,itemClassLV=%s,itemColor=%s" % (attrID, itemClassLV, itemColor))
                continue
            attrValue = colorValueDict[itemColor]
        elif attrID in legAttrValueClassLVDict:
@@ -2273,6 +2516,76 @@
#    GameWorld.DebugLog("commAttrList=%s, goodAttrList=%s, specAttrList=%s" % (commAttrList, goodAttrList, specAttrList))
#    GameWorld.DebugLog("randAttrIDList=%s,curLegAttrIDList=%s, curLegAttrValueList=%s" 
#                       % (randAttrIDList, curLegAttrIDList, curLegAttrValueList))
    return [curLegAttrIDList, curLegAttrValueList]
def __GetRandLegendAttr(curItem):
    # 纯随机类型及数值的规则
    itemType = curItem.GetType()
    equipTypeRandGroupDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrRandRule", 2, {}) # 随机传奇属性类型组配置: {(装备类型1, 装备类型2, ...):[传奇属性类型组1, ...], ...}
    if itemType in equipTypeRandGroupDict:
        randGroupList = equipTypeRandGroupDict[itemType]
    else:
        randGroupList = []
        for typeTuple, groupList in equipTypeRandGroupDict.items():
            if not isinstance(typeTuple, tuple):
                continue
            if itemType in typeTuple:
                randGroupList = groupList
                break
    if not randGroupList:
        GameWorld.ErrLog("该物品类型没有传奇属性!itemType=%s" % itemType)
        return
    randLegendAttrIDLsit = []
    legendAttrGroupDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrRandRule", 1, {}) # 传奇类型组 {1:[传奇属性类型ID组], ...}
    for groupType in randGroupList:
        if groupType not in legendAttrGroupDict:
            GameWorld.ErrLog("没有配置传奇属性组对应传奇属性类型列表! groupType=%s" % groupType)
            continue
        randLegendAttrIDLsit += legendAttrGroupDict[groupType]
    if not randLegendAttrIDLsit:
        return
    itemClassLV = ItemCommon.GetItemClassLV(curItem)
    itemQuality = curItem.GetItemQuality()
    randCountKey = (itemClassLV, itemQuality)
    randCountDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrRandRule", 3) # 随机条数: {(阶,星):[随机条数A, 随机条数B]], ...}
    if randCountKey not in randCountDict:
        GameWorld.ErrLog("没有配置装备阶星对应随机传奇属性条数: itemClassLV=%s, itemQuality=%s" % (itemClassLV, itemQuality))
        return
    randCountList = randCountDict[randCountKey]
    if not randCountList or len(randCountList) != 2:
        return
    legAttrCnt = random.randint(randCountList[0], randCountList[1])
    legAttrCnt = min(len(randLegendAttrIDLsit), legAttrCnt)
    curLegAttrIDList = random.sample(randLegendAttrIDLsit, legAttrCnt)
    curLegAttrValueList = []
    randValueListDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrRandRule", 4) # 随机数值: {传奇属性类型:[随机数值1, 数值2, ...], ...}
    maxValueMinCountDict = IpyGameDataPY.GetFuncEvalCfg("LegendAttrRandRule", 5) # 保底最大数值条数: {(阶,星):条数, ...], ...}  没配置的默认0
    maxValueMinCount = maxValueMinCountDict.get((itemClassLV, itemQuality), 0)
    if legAttrCnt < maxValueMinCount:
        GameWorld.ErrLog("传奇属性条数少于保底最大数值条数: itemClassLV=%s, itemQuality=%s, legAttrCnt=%s, maxValueMinCount=%s"
                         % (itemClassLV, itemQuality, legAttrCnt, maxValueMinCount))
        return
    for i, attrID in enumerate(curLegAttrIDList):
        if attrID not in randValueListDict:
            GameWorld.ErrLog("传奇属性没有配置随机数值范围或配置错误: attrID=%s" % (attrID))
            return
        randValueList = randValueListDict[attrID]
        if i < maxValueMinCount:
            randValue = max(randValueList)
        else:
            randValue = random.choice(randValueList)
        curLegAttrValueList.append(randValue)
#    GameWorld.DebugLog("itemType=%s,itemClassLV=%s,itemQuality=%s,randLegendAttrIDLsit=%s" % (itemType, itemClassLV, itemQuality, randLegendAttrIDLsit))
#    GameWorld.DebugLog("legAttrCnt=%s,maxValueMinCount=%s" % (legAttrCnt, maxValueMinCount))
#    GameWorld.DebugLog("curLegAttrIDList=%s,curLegAttrValueList=%s" % (curLegAttrIDList, curLegAttrValueList))
    return [curLegAttrIDList, curLegAttrValueList]
def __GetAddWingLegendAttr(curItem):
@@ -2393,3 +2706,54 @@
    return
def CheckChangeOldItem(curPlayer, tagItem):
    ##替换旧物品
    itemID = tagItem.GetItemTypeID()
    changeOldItemDict = IpyGameDataPY.GetFuncEvalCfg('ChangeOldItem', 1, {})
    if itemID not in changeOldItemDict:
        return
    itemCnt = GetItemCount(tagItem)
    isBind = tagItem.GetIsBind()
    toItemID, toCnt, mailKey = changeOldItemDict[itemID]
    giveCnt = itemCnt * toCnt
    PlayerControl.SendMailByKey(mailKey, [curPlayer.GetPlayerID()], [[toItemID, giveCnt, isBind]])
    return True
def LoginCheckChangeOldItem(curPlayer):
    ##登录检查替换旧物品
    if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_VersionFix, ChConfig.Def_VerFix_GodWeaponItem):
        return
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_VersionFix, ChConfig.Def_VerFix_GodWeaponItem, 1)
    giveItemDict = {}
    mailDict = {}
    for packIndex in [IPY_GameWorld.rptItem, IPY_GameWorld.rptWarehouse, ShareDefine.rptTreasure]:
        curPack = curPlayer.GetItemManager().GetPack(packIndex)
        for i in xrange(curPack.GetCount()):
            curItem = curPack.GetAt(i)
            if not curItem:
                continue
            itemID = curItem.GetItemTypeID()
            changeOldItemDict = IpyGameDataPY.GetFuncEvalCfg('ChangeOldItem', 1, {})
            if itemID not in changeOldItemDict:
                continue
            isBind = curItem.GetIsBind()
            itemCount = curItem.GetCount()
            toItemID, toCnt, mailKey = changeOldItemDict[itemID]
            giveCnt = itemCount * toCnt
            keyStr = '%s_%s'%(toItemID, isBind)
            giveItemDict[keyStr] = giveItemDict.get(keyStr, 0) + giveCnt
            ItemCommon.DelItem(curPlayer, curItem, itemCount, False, "ChangeOldItem")
            if mailKey not in mailDict:
                mailDict[mailKey] = [keyStr]
            if keyStr not in mailDict[mailKey]:
                mailDict[mailKey].append(keyStr)
    for mailKey, keyStrList in mailDict.items():
        itemList = []
        for keyStr in keyStrList:
            if keyStr not in giveItemDict:
                continue
            giveCnt = giveItemDict[keyStr]
            itemID, isBind = keyStr.split('_')
            itemList.append([int(itemID), giveCnt, int(isBind)])
        PlayerControl.SendMailByKey(mailKey, [curPlayer.GetID()], itemList)
    return