xdh
2019-05-31 a69e35d211da29d739187385383741ba34202c08
7034 【后端】【2.0】宝石合成
1个文件已修改
445 ■■■■■ 已修改文件
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_EquipStone.py 445 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_EquipStone.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
#
##@package Event.EventSrc.Operate_EquipStone
#
@@ -11,9 +11,9 @@
#
# 详细描述: 装备宝石
#
#-------------------------------------------------------------------------------
#"""Version = 2017-07-29 12:00"""
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# """Version = 2017-07-29 12:00"""
# -------------------------------------------------------------------------------
import GameWorld
import ItemCommon
@@ -31,11 +31,13 @@
import PlayerWeekParty
import ShareDefine
import EventShell
#import EquipZhuXian
g_stoneCanPlaceList = [] #可镶嵌的位置
# import EquipZhuXian
#def OnLogin(curPlayer):
g_stoneCanPlaceList = []  # 可镶嵌的位置
# def OnLogin(curPlayer):
#    ###登录发包同步客户端宝石信息
#    Sycn_StoneHoleInfo(curPlayer)
#    return
@@ -45,15 +47,15 @@
    global g_stoneCanPlaceList
    if g_stoneCanPlaceList:
        return g_stoneCanPlaceList
    #获得宝石类型数量
    # 获得宝石类型数量
    GemTypeCount = IpyGameDataPY.GetFuncCfg("GemTypeCount")
    #获得所有可镶嵌宝石装备位
    g_stoneCanPlaceList = []
    # 获得所有可镶嵌宝石装备位
    g_stoneCanPlaceList = []
    for stoneTypeIndex in xrange(1, GemTypeCount + 1):
        #循环宝石类型对应的装备位
        # 循环宝石类型对应的装备位
        placeList = IpyGameDataPY.GetFuncEvalCfg("GemType%s" % stoneTypeIndex, 1)
        for place in placeList:
            ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'EquipPlace':place}, True)
            ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'EquipPlace': place}, True)
            if not ipyDataList:
                continue
            for ipyData in ipyDataList:
@@ -62,161 +64,171 @@
                    g_stoneCanPlaceList.append(gridIndex)
    return g_stoneCanPlaceList
def GetAllEquipPlaceHoleIndex():
    ### 得到装备位所有孔位
    gemOpenNeedStarList = IpyGameDataPY.GetFuncEvalCfg("GemOpen", 1)
    maxEquipHoleCnt = len(gemOpenNeedStarList) # 最大装备阶级开放孔数
    maxEquipHoleCnt = len(gemOpenNeedStarList)  # 最大装备阶级开放孔数
    gemOpenVipList = IpyGameDataPY.GetFuncEvalCfg("GemOpenVip", 1)
    maxHoleVipCnt = len(gemOpenVipList)# 最大Vip开放孔数
    maxHoleVipCnt = len(gemOpenVipList)  # 最大Vip开放孔数
    return range(maxEquipHoleCnt) + range(ChConfig.Def_Stone_VipHole, ChConfig.Def_Stone_VipHole + maxHoleVipCnt)
def GetEquipIndexStoneIDList(curPlayer, equipIndex):
    ### 装备位孔位宝石ID列表
    holeIndexList = GetAllEquipPlaceHoleIndex()
    holeStoneIDList = []
    for holeIndex in holeIndexList:
        stoneID = GetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex) [0]
        stoneID = GetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex)[0]
        holeStoneIDList.append(stoneID)
    return holeStoneIDList
def GetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex):
    '''获得装备位孔位宝石ID和绑定信息
    @return: stoneID, stoneIsBind
    '''
    #获得装备位孔索引宝石存储信息
    stoneInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipPartStoneID % (equipIndex, holeIndex))
    #获取装备位孔位上宝石ID
    # 获得装备位孔索引宝石存储信息
    stoneInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipPartStoneID % (equipIndex, holeIndex))
    # 获取装备位孔位上宝石ID
    stoneID = stoneInfo / ChConfig.Def_Stone_SaveStoneInfoXNumber
    #获取装备位孔位上宝石是否绑定状态
    stoneIsBind = stoneInfo % ChConfig.Def_Stone_SaveStoneInfoXNumber
    # 获取装备位孔位上宝石是否绑定状态
    stoneIsBind = stoneInfo % ChConfig.Def_Stone_SaveStoneInfoXNumber
    return stoneID, stoneIsBind
def SetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex, changeStoneID, isBind):
    ### 保存装备位孔位宝石ID和绑定信息
    befStoneID, befIsBind = GetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex)
    if befStoneID == changeStoneID and befIsBind == isBind:
        return
    isBind = 0 #现绑定无用,默认存0
    isBind = 0  # 现绑定无用,默认存0
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EquipPartStoneID % (equipIndex, holeIndex),
                                       changeStoneID * ChConfig.Def_Stone_SaveStoneInfoXNumber + isBind)
    # 同步更新宝石总等级
    gameData = GameWorld.GetGameData()
    befStoneLV = 0
    if befStoneID:
        befGem = gameData.GetItemByTypeID(befStoneID)
        befStoneLV = 0 if not befGem else befGem.GetEffectByIndex(0).GetEffectValue(1)
    aftStoneLV = 0
    if changeStoneID:
        aftGem = gameData.GetItemByTypeID(changeStoneID)
        aftStoneLV = 0 if not aftGem else aftGem.GetEffectByIndex(0).GetEffectValue(1)
    befTotalStoneLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalStoneLV)
    updTotalStoneLV = max(0, befTotalStoneLV + aftStoneLV - befStoneLV)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TotalStoneLV, updTotalStoneLV)
    GameWorld.DebugLog("设置宝石等级: equipIndex=%s,holeIndex=%s,befStoneLV=%s,aftStoneLV=%s,befTotalStoneLV=%s,updTotalStoneLV=%s"
                       % (equipIndex, holeIndex, befStoneLV, aftStoneLV, befTotalStoneLV, updTotalStoneLV))
    GameWorld.DebugLog(
        "设置宝石等级: equipIndex=%s,holeIndex=%s,befStoneLV=%s,aftStoneLV=%s,befTotalStoneLV=%s,updTotalStoneLV=%s"
        % (equipIndex, holeIndex, befStoneLV, aftStoneLV, befTotalStoneLV, updTotalStoneLV))
    return
def GetPackTypeByEquipPlace(equipPlace):
    ##目前支持镶嵌普通装备、诛仙装备
#    if equipPlace in ShareDefine.ZhuXianEquipPlace:
#        equipPackType = ShareDefine.rptZhuXianEquip
#        stonePackType = ShareDefine.rptZhuXianItem
#        placeIndex = EquipZhuXian.GetZhuXianEquipIndexByPlace(equipPlace)
#    else:
    #    if equipPlace in ShareDefine.ZhuXianEquipPlace:
    #        equipPackType = ShareDefine.rptZhuXianEquip
    #        stonePackType = ShareDefine.rptZhuXianItem
    #        placeIndex = EquipZhuXian.GetZhuXianEquipIndexByPlace(equipPlace)
    #    else:
    equipPackType = IPY_GameWorld.rptEquip
    stonePackType = IPY_GameWorld.rptItem
    placeIndex = equipPlace
    return equipPackType, stonePackType, placeIndex
#//A3 04 宝石镶嵌或替换 #tagCMEquipEnchase
#struct    tagCMEquipEnchase
#{
# //A3 04 宝石镶嵌或替换 #tagCMEquipEnchase
# struct    tagCMEquipEnchase
# {
#    tagHead        Head;
#    BYTE        EquipIndex;        //装备位索引
#    BYTE        StoneIndex;        //宝石所在玩家物品背包索引
#    BYTE        HoleIndex;        //选择的孔索引
#};
# };
def OnEquipEnchase(playerIndex, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)
    playerID = curPlayer.GetPlayerID()
    # 验证背包类型合法性
    equipPackIndex = clientData.EquipIndex
    stoneIndex = clientData.StoneIndex
    holeIndex = clientData.HoleIndex
    GameWorld.DebugLog("宝石镶嵌: equipPackIndex=%s,stoneIndex=%s,holeIndex=%s" % (equipPackIndex, stoneIndex, holeIndex), playerID)
    GameWorld.DebugLog("宝石镶嵌: equipPackIndex=%s,stoneIndex=%s,holeIndex=%s" % (equipPackIndex, stoneIndex, holeIndex),
                       playerID)
    equipPackType, stonePackType, placeIndex = GetPackTypeByEquipPlace(equipPackIndex)
    #获得装备位装备实例
    # 获得装备位装备实例
    equipPack = curPlayer.GetItemManager().GetPack(equipPackType)
    curEquip = equipPack.GetAt(placeIndex)
    if not ItemCommon.CheckItemCanUse(curEquip):
        GameWorld.Log("目标装备为空或不可用,无法镶嵌!", playerID)
        return
    #获得宝石实例
    # 获得宝石实例
    itemPack = curPlayer.GetItemManager().GetPack(stonePackType)
    curStone = itemPack.GetAt(stoneIndex)
    if not ItemCommon.CheckItemCanUse(curStone) or ItemControler.GetIsAuctionItem(curStone):
        GameWorld.Log("目标宝石为空或不可用,无法镶嵌!", playerID)
        return
    stoneItemID = curStone.GetItemTypeID()
    isBind = curStone.GetIsBind()
    curStoneEff = curStone.GetEffectByIndex(0)
    curEffID = curStoneEff.GetEffectID()
    if curEffID != ChConfig.Def_Effect_EquipStone:
        GameWorld.Log("不是宝石,无法镶嵌!stoneIndex=%s,stoneItemID=%s,curEffID=%s != %s"
        GameWorld.Log("不是宝石,无法镶嵌!stoneIndex=%s,stoneItemID=%s,curEffID=%s != %s"
                      % (stoneIndex, stoneItemID, curEffID, ChConfig.Def_Effect_EquipStone), playerID)
        return
    stoneEffType = curStoneEff.GetEffectValue(0)
    stoneCanPlaceList = IpyGameDataPY.GetFuncEvalCfg("GemType%s" % stoneEffType, 1)
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'GridIndex':equipPackIndex})
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'GridIndex': equipPackIndex})
    if not ipyData:
        return
    classLV = ipyData.GetClassLV()
    if ipyData.GetEquipPlace() not in stoneCanPlaceList:
        GameWorld.Log("该宝石不可镶嵌在该装备位!stoneItemID=%s,stoneEffType=%s,stoneCanPlaceList=%s,equipPackIndex=%s"
        GameWorld.Log("该宝石不可镶嵌在该装备位!stoneItemID=%s,stoneEffType=%s,stoneCanPlaceList=%s,equipPackIndex=%s"
                      % (stoneItemID, stoneEffType, stoneCanPlaceList, equipPackIndex), playerID)
        return
    equipStar = ChEquip.GetEquipPartStarByRank(curPlayer, placeIndex, curEquip)
    if not __CheckStoneHoleCanUse(curPlayer, equipStar, holeIndex, equipPackType):
        return
    # 扣除宝石
    ItemCommon.DelItem(curPlayer, curStone, 1, True, ChConfig.ItemDel_EquipEnchase, {"equipPackIndex":equipPackIndex, "HoleIndex":holeIndex})
    ItemCommon.DelItem(curPlayer, curStone, 1, True, ChConfig.ItemDel_EquipEnchase,
                       {"equipPackIndex": equipPackIndex, "HoleIndex": holeIndex})
    isBind = 1 if isBind else 0
    # 变更宝石孔宝石信息
    __DoChangeEquipHoleStone(curPlayer, equipPackIndex, holeIndex, stoneItemID, isBind, "EquipStone", True)
#    #镶嵌成功
#    if not curEquip.GetIsBind():
#        ItemControler.SetItemIsBind(curEquip, True)
    #    #镶嵌成功
    #    if not curEquip.GetIsBind():
    #        ItemControler.SetItemIsBind(curEquip, True)
    # 刷新属性
    RefreshAttrByStoneAction(curPlayer, equipPackType, True, classLV)
    #同步客户端
    # 同步客户端
    Sycn_StoneHoleInfo(curPlayer, [equipPackIndex])
    #成就
    # 成就
    DoStoneSuccess(curPlayer)
    EventShell.EventRespons_InlayStone(curPlayer)
    return
def DoStoneSuccess(curPlayer):
    PlayerSuccess.ResetSuccessByType(curPlayer, ShareDefine.SuccType_InlayStone1)
@@ -227,39 +239,40 @@
    packType = IPY_GameWorld.rptEquip
    playerEquip = curPlayer.GetItemManager().GetPack(packType)
    for equipIndex in xrange(playerEquip.GetCount()):
        if equipIndex not in ShareDefine.RoleEquipType :
        if equipIndex not in ShareDefine.RoleEquipType:
            continue
        for holeIndex in holeIndexList:
            curGemID = GetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex)[0]
            if curGemID == 0:
                continue
            curGem = gameData.GetItemByTypeID(curGemID)
            if not curGem:
                continue
                continue
            gemEffect = curGem.GetEffectByIndex(0)
            gemType, gemLV = gemEffect.GetEffectValue(0), gemEffect.GetEffectValue(1)
            if gemType == 1:#生命宝石
            if gemType == 1:  # 生命宝石
                PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_InlayStone1, 1, [gemLV])
            elif gemType == 2:#毁灭宝石
            elif gemType == 2:  # 毁灭宝石
                PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_InlayStone2, 1, [gemLV])
            totalStoneLV += gemLV
    # 记录开服活动宝石总等级
    OpenServerCampaign.UpdOpenServerCampaignRecordData(curPlayer, ShareDefine.Def_Campaign_Type_StoneLV, totalStoneLV)
    PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_StoneTotalLV, totalStoneLV)
    PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_Stone, totalStoneLV, False, True)
    return
#//A3 05 宝石摘取 #tagCMEquipStonePick
#struct    tagCMEquipStonePick
#{
# //A3 05 宝石摘取 #tagCMEquipStonePick
# struct    tagCMEquipStonePick
# {
#    tagHead        Head;
#    BYTE        EquipIndex;        //装备位在背包中索引
#    BYTE        HoleIndex;        //装备位的孔索引
#};
# };
def OnEquipStonePick(playerIndex, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)
    playerID = curPlayer.GetPlayerID()
@@ -267,49 +280,51 @@
    equipPackIndex = clientData.EquipIndex
    holeIndex = clientData.HoleIndex
    GameWorld.DebugLog("宝石摘除: equipPackIndex=%s,holeIndex=%s" % (equipPackIndex, holeIndex), playerID)
    equipPackType, stonePackType, placeIndex = GetPackTypeByEquipPlace(equipPackIndex)
    #获得装备位装备实例
    # 获得装备位装备实例
    equipPack = curPlayer.GetItemManager().GetPack(equipPackType)
    curEquip = equipPack.GetAt(placeIndex)
    if not ItemCommon.CheckItemCanUse(curEquip):
        GameWorld.Log("目标装备为空或不可用,无法镶嵌!", playerID)
        return
    #验证背包空间
    # 验证背包空间
    if not ItemCommon.CheckPackHasSpace(curPlayer, stonePackType, True):
        return
    # 验证宝石
    stoneID = GetEquipIndexStoneIDAndIsBand(curPlayer, equipPackIndex, holeIndex)[0]
    if not stoneID:
        GameWorld.DebugLog("孔为空或不存在宝石!")
        return
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'GridIndex':equipPackIndex})
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'GridIndex': equipPackIndex})
    if not ipyData:
        return
    classLV = ipyData.GetClassLV()
    __DoChangeEquipHoleStone(curPlayer, equipPackIndex, holeIndex, 0, 0, "StonePick", True)
    # 刷新属性
    RefreshAttrByStoneAction(curPlayer, equipPackType, False, classLV)
    #同步客户端
    # 同步客户端
    Sycn_StoneHoleInfo(curPlayer, [equipPackIndex])
    totalStoneLV = GetTotalStoneLV(curPlayer)
    # 记录开服活动宝石总等级
    OpenServerCampaign.UpdOpenServerCampaignRecordData(curPlayer, ShareDefine.Def_Campaign_Type_StoneLV, totalStoneLV)
    PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_Stone, totalStoneLV, False, True)
    return
def GetTotalStoneLV(curPlayer):
    ##宝石总等级
    return curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalStoneLV)
def GetStoneCntByLV(curPlayer, stoneLV):
    ##指定等级的宝石数量
@@ -330,63 +345,66 @@
                cnt += 1
    return cnt
#// A3 06 宝石升级 #tagCMEquipStoneUpgrade
#struct    tagCMEquipStoneUpgrade
#{
# // A3 06 宝石升级 #tagCMEquipStoneUpgrade
# struct    tagCMEquipStoneUpgrade
# {
#    tagHead        Head;
#    BYTE        EquipIndex;        //装备位在装备背包中的索引
#    BYTE        HoleIndex;        //装备位中宝石孔索引
#    BYTE        UpWay;        //升级方式 0:仙玉 1:宝石
#};
# };
def OnEquipStoneUpgrade(playerIndex, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)
    playerID = curPlayer.GetPlayerID()
    # 验证背包类型合法性
    equipPackIndex = clientData.EquipIndex
    holeIndex = clientData.HoleIndex
    upWay = clientData.UpWay
    GameWorld.DebugLog("宝石升级: equipPackIndex=%s,holeIndex=%s" % (equipPackIndex, holeIndex), playerID)
    equipPackType, stonePackType, placeIndex = GetPackTypeByEquipPlace(equipPackIndex)
    #获得装备位装备实例
    # 获得装备位装备实例
    equipPack = curPlayer.GetItemManager().GetPack(equipPackType)
    curEquip = equipPack.GetAt(placeIndex)
    if not ItemCommon.CheckItemCanUse(curEquip):
        GameWorld.Log("目标装备为空或不可用,无法镶嵌!", playerID)
        return
    #升级宝石ID
    # 升级宝石ID
    stoneID, stoneIsBind = GetEquipIndexStoneIDAndIsBand(curPlayer, equipPackIndex, holeIndex)
    if stoneID == 0:
        GameWorld.DebugLog("孔为空或不存在宝石!")
        return
    stoneItemData = GameWorld.GetGameData().GetItemByTypeID(stoneID)
        GameWorld.DebugLog("孔为空或不存在宝石!")
        return
    stoneItemData = GameWorld.GetGameData().GetItemByTypeID(stoneID)
    stoneItemID = stoneItemData.GetItemTypeID()
    curStoneEff = stoneItemData.GetEffectByIndex(0)
    curEffID = curStoneEff.GetEffectID()
    if curEffID != ChConfig.Def_Effect_EquipStone:
        GameWorld.Log("不是宝石,无法升级!stoneIndex=%s,stoneItemID=%s,curEffID=%s"
        GameWorld.Log("不是宝石,无法升级!stoneIndex=%s,stoneItemID=%s,curEffID=%s"
                      % (holeIndex, stoneItemID, curEffID), playerID)
        return
        return
    stoneEffType = curStoneEff.GetEffectValue(0)
    level = curStoneEff.GetEffectValue(1)
    upgradeStoneID = curStoneEff.GetEffectValue(2)
    GameWorld.DebugLog("stoneEffType=%s,level=%s,upgradeStoneID=%s" % (stoneEffType, level, upgradeStoneID))
    if not upgradeStoneID:
        GameWorld.Log("该宝石已是最大级,不能升级!stoneIndex=%s,stoneItemID=%s,curEffID=%s,upgradeStoneID=%s"
                      % (holeIndex, stoneItemID, curEffID, upgradeStoneID), playerID)
        return
    needCount = IpyGameDataPY.GetFuncCfg("GemUpCostFormula", 2) # 合成下一级所需宝石个数
    needCount = IpyGameDataPY.GetFuncCfg("GemUpCostFormula", 2)  # 合成下一级所需宝石个数
    if not needCount:
        return
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'GridIndex':equipPackIndex})
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('EquipPlaceIndexMap', {'GridIndex': equipPackIndex})
    if not ipyData:
        return
    # 额外材料
    extraItemInfoDict = IpyGameDataPY.GetFuncEvalCfg("GemUpCostFormula", 3, {})
    classLV = ipyData.GetClassLV()
    if upWay == 0: #仙玉
    if upWay == 0:  # 仙玉
        stoneTypeItemIDDict = IpyGameDataPY.GetFuncEvalCfg("GemUpCostFormula", 1)
        if stoneEffType not in stoneTypeItemIDDict:
            return
@@ -396,107 +414,130 @@
            return
        costCount = pow(needCount, level - 1) * (needCount - 1)
        costGold = costCount * unitPrice
        # 额外材料
        costExtraItemDict = {}
        i, cnt =0, 1
        for lv in xrange(level+1, 1, -1):
            cnt =1 if i is 0 else pow(needCount, i-1)
            i+=1
            extraItemInfo = extraItemInfoDict.get(str(lv))
            if extraItemInfo:
                extraItemID, extraItemCnt = extraItemInfo
                extraItemPrice = ItemCommon.GetShopItemPrice(extraItemID, IPY_GameWorld.TYPE_Price_Gold_Money)
                if not extraItemPrice:
                    return
                costGold += extraItemPrice * extraItemCnt * cnt
                costExtraItemDict[extraItemID] = costExtraItemDict.get(extraItemID, 0) + extraItemCnt * cnt
        if costGold <= 0:
            return
        infoDict = {"StoneItemID":stoneItemID, "CurStoneIDLV":level, "UpgradeStoneID":upgradeStoneID, "CostCount":costCount, "UnitPrice":unitPrice}
        if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, costGold, ChConfig.Def_Cost_EquipStone, infoDict):
        infoDict = {"StoneItemID": stoneItemID, "CurStoneIDLV": level, "UpgradeStoneID": upgradeStoneID,
                    "CostCount": costCount, "UnitPrice": unitPrice, 'costExtraItemDict':costExtraItemDict}
        if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, costGold,
                                      ChConfig.Def_Cost_EquipStone, infoDict):
            GameWorld.DebugLog("仙玉不足!costGold=%s" % costGold)
            return
    else:
        #同级宝石
        costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, stoneItemID, packType=stonePackType)
        if bindCnt + unBindCnt < needCount-1:
            GameWorld.DebugLog("同级宝石不足 %s!" % (needCount-1))
            return
        if stoneIsBind:
            costIndexList = (costItemIndexList[0]+costItemIndexList[1])[:2]
        else:
            costIndexList = (costItemIndexList[1]+costItemIndexList[0])[:2]
        costItemDict = {stoneItemID:needCount - 1}
        if str(level + 1) in extraItemInfoDict:
            extraItemID, extraItemCnt = extraItemInfoDict[str(level + 1)]
            costItemDict[extraItemID] = extraItemCnt
        itemPack = curPlayer.GetItemManager().GetPack(stonePackType)
        hasBind = ItemCommon.ReduceItem(curPlayer, itemPack, costIndexList, needCount-1, False, ChConfig.ItemDel_StoneUpgrade,
                                        {"equipPackIndex":equipPackIndex, "HoleIndex":holeIndex})
        if hasBind:
            stoneIsBind = True
    __DoChangeEquipHoleStone(curPlayer, equipPackIndex, holeIndex, upgradeStoneID, stoneIsBind, "StoneUpgrade", False)
        delItemList = []
        for itemID, itemCnt in costItemDict.items():
            hasEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(itemID, itemPack, itemCnt)
            if not hasEnough:
                GameWorld.DebugLog("材料不足 itemID=%s!,needCnt=%s" % (itemID, itemCnt))
                return
            delItemList.append([itemIndexList, itemCnt])
        for delItemIndexList, delCnt in delItemList:
            ItemCommon.ReduceItem(curPlayer, itemPack, delItemIndexList, delCnt, False,
                                  ChConfig.ItemDel_StoneUpgrade,
                                  {"equipPackIndex": equipPackIndex, "HoleIndex": holeIndex})
    __DoChangeEquipHoleStone(curPlayer, equipPackIndex, holeIndex, upgradeStoneID, False, "StoneUpgrade", False)
    # 刷新属性
    RefreshAttrByStoneAction(curPlayer, equipPackType, False, classLV)
    #同步客户端
    # 同步客户端
    Sycn_StoneHoleInfo(curPlayer, [equipPackIndex])
    DoStoneSuccess(curPlayer)
    return
def __CheckStoneHoleCanUse(curPlayer, equipStar, holeIndex, equipPackType):
    ##验证孔合法性
    holeIndexList = GetAllEquipPlaceHoleIndex()
    if holeIndex not in holeIndexList:
        GameWorld.Log("镶嵌孔索引错误!holeIndex=%s, holeIndexList=%s" % (holeIndex, holeIndexList))
        return False
    openCommHoleCnt = 0 # 已经开放装备常规孔数
    openCommHoleCnt = 0  # 已经开放装备常规孔数
    gemOpenNeedStarList = IpyGameDataPY.GetFuncEvalCfg("GemOpen", 1)
    for holeCnt, openStar in enumerate(gemOpenNeedStarList, 1):
        if equipStar >= openStar:
            openCommHoleCnt = holeCnt
    # VIP孔
    if holeIndex >= ChConfig.Def_Stone_VipHole:
        if openCommHoleCnt <= 0:
            GameWorld.Log("装备未开启任何普通宝石孔,无法开启VIP孔位! equipStar=%s,openCommHoleCnt=%s" % (equipStar, openCommHoleCnt))
            return False
        gemOpenVipList = IpyGameDataPY.GetFuncEvalCfg("GemOpenVip", 1)
        openVIPHoleCnt = 0 # 已经开放装备VIP孔数
        openVIPHoleCnt = 0  # 已经开放装备VIP孔数
        curVipLV = curPlayer.GetVIPLv()
        for holeCnt, vipLv in enumerate(gemOpenVipList, 1):
            if curVipLV >= vipLv:
        for holeCnt, vipLv in enumerate(gemOpenVipList, 1):
            if curVipLV >= vipLv:
                openVIPHoleCnt = holeCnt
        if holeIndex >= openVIPHoleCnt + ChConfig.Def_Stone_VipHole:
            GameWorld.Log("装备VIP宝石孔未开放!curVipLV=%s,holeIndex=%s,openVIPHoleCnt=%s"
            GameWorld.Log("装备VIP宝石孔未开放!curVipLV=%s,holeIndex=%s,openVIPHoleCnt=%s"
                          % (curVipLV, holeIndex, openVIPHoleCnt), curPlayer.GetPlayerID())
            return False
        #不限制是否过期
        #if not PlayerVip.GetCurVIPTime(curPlayer):
        # 不限制是否过期
        # if not PlayerVip.GetCurVIPTime(curPlayer):
        #    GameWorld.Log("VIP已过期,无法使用VIP宝石孔!", curPlayer.GetPlayerID())
        #    return False
    # 常规孔
    elif holeIndex >= openCommHoleCnt:
        GameWorld.Log("该装备宝石孔为开放!equipStar=%s,holeIndex=%s,openCommHoleCnt=%s"
        GameWorld.Log("该装备宝石孔为开放!equipStar=%s,holeIndex=%s,openCommHoleCnt=%s"
                      % (equipStar, holeIndex, openCommHoleCnt), curPlayer.GetPlayerID())
        return False
    return True
def __DoChangeEquipHoleStone(curPlayer, equipPackIndex, holeIndex, changeStoneID, isBind, eventName, isPickoff):
    ## 变更玩家装备孔宝石
    #获得装备位孔索引宝石存储信息
    # 获得装备位孔索引宝石存储信息
    stoneID, stoneIsBind = GetEquipIndexStoneIDAndIsBand(curPlayer, equipPackIndex, holeIndex)
    #保存装备位孔位上宝石ID和绑定状态
    # 保存装备位孔位上宝石ID和绑定状态
    SetEquipIndexStoneIDAndIsBand(curPlayer, equipPackIndex, holeIndex, changeStoneID, isBind)
    if isPickoff and stoneID:
        equipPackType, stonePackType, placeIndex = GetPackTypeByEquipPlace(equipPackIndex)
        itemCount = 1
        # 摘除的宝石都绑定
        if ItemCommon.CheckPackHasSpace(curPlayer, stonePackType):
            ItemControler.GivePlayerItem(curPlayer, stoneID, itemCount, 0,
                                         [stonePackType],
                                         event=[ChConfig.ItemGive_StonePickoff, False, {"equipPackIndex":equipPackIndex, "HoleIndex":holeIndex}])
                                         [stonePackType],
                                         event=[ChConfig.ItemGive_StonePickoff, False,
                                                {"equipPackIndex": equipPackIndex, "HoleIndex": holeIndex}])
        else:
            PlayerControl.SendMailByKey("GemToPlayer", [curPlayer.GetPlayerID()], [[stoneID, 1, stoneIsBind]])
    DataRecordPack.DR_StoneItemChange(curPlayer, eventName, {'equipPackIndex':equipPackIndex,"holeIndex":holeIndex, "stoneID":stoneID, 'changeStoneID':changeStoneID})
    DataRecordPack.DR_StoneItemChange(curPlayer, eventName,
                                      {'equipPackIndex': equipPackIndex, "holeIndex": holeIndex, "stoneID": stoneID,
                                       'changeStoneID': changeStoneID})
    EventShell.EventRespons_StoneChange(curPlayer)
    return
@@ -505,78 +546,80 @@
    ## 宝石刷新属性
    # 装备等级改变,判断是否为玩家身上的装备,如果是的话刷新玩家属性
    if packType in [IPY_GameWorld.rptEquip]:
        #先刷装备BUFF 再计算属性
        # 先刷装备BUFF 再计算属性
        if isNeedNotify:
            curPlayer.SetDict(ChConfig.Def_PlayerKey_AttrActivatyNotify, ChConfig.Def_AttrActivatyNotify_Stone)
        ChEquip.RefreshPlayerEquipAttribute(curPlayer, classLV)
        #刷新所有属性
        # 刷新所有属性
        playControl = PlayerControl.PlayerControl(curPlayer)
        playControl.RefreshPlayerAttrState()
    #elif packType == ShareDefine.rptZhuXianEquip:
    # elif packType == ShareDefine.rptZhuXianEquip:
    #    EquipZhuXian.RefreshZhuXianAttr(curPlayer)
    return
def DoMoveEquipStone(curPlayer, equipPackIndex):
def DoMoveEquipStone(curPlayer, equipPackIndex):
    ###替换装备时宝石转移
    equipPackType, stonePackType, placeIndex = GetPackTypeByEquipPlace(equipPackIndex)
    equipPack = curPlayer.GetItemManager().GetPack(equipPackType)
    curEquip = equipPack.GetAt(placeIndex)
    if not ItemCommon.CheckItemCanUse(curEquip):
        return
    #获得装备星级孔信息
    # 获得装备星级孔信息
    gemOpenNeedStarList = IpyGameDataPY.GetFuncEvalCfg("GemOpen", 1)
    maxEquipHoleCnt = len(gemOpenNeedStarList) # 最大装备星级开放孔数
    openEquipHoleCnt = 0 # 已经开放孔数
    maxEquipHoleCnt = len(gemOpenNeedStarList)  # 最大装备星级开放孔数
    openEquipHoleCnt = 0  # 已经开放孔数
    partStar = ChEquip.GetEquipPartStarByRank(curPlayer, equipPackIndex, curEquip)
    for holeCnt, openStar in enumerate(gemOpenNeedStarList, 1):
        if partStar >= openStar:
            openEquipHoleCnt = holeCnt
    #需要拆卸宝石的孔列表
    # 需要拆卸宝石的孔列表
    pickoffHoleList = []
    #判断装备阶级宝石是否拆卸
    for holeIndex in xrange(maxEquipHoleCnt):
    # 判断装备阶级宝石是否拆卸
    for holeIndex in xrange(maxEquipHoleCnt):
        if holeIndex < openEquipHoleCnt:
            continue
        curGemID = GetEquipIndexStoneIDAndIsBand(curPlayer, equipPackIndex, holeIndex)[0]
        if curGemID == 0:
            continue
            continue
        pickoffHoleList.append([equipPackIndex, holeIndex])
    #没有开启普通装备孔,需摘除VIP孔
    # 没有开启普通装备孔,需摘除VIP孔
    if not openEquipHoleCnt:
        #获得VIP等级孔信息
        # 获得VIP等级孔信息
        gemOpenVipList = IpyGameDataPY.GetFuncEvalCfg("GemOpenVip", 1)
        maxVipHoleCnt = len(gemOpenVipList)# 最大VIP开放孔数
        #判断VIP等级孔信息
        for holeIndex in xrange(ChConfig.Def_Stone_VipHole, ChConfig.Def_Stone_VipHole + maxVipHoleCnt):
        maxVipHoleCnt = len(gemOpenVipList)  # 最大VIP开放孔数
        # 判断VIP等级孔信息
        for holeIndex in xrange(ChConfig.Def_Stone_VipHole, ChConfig.Def_Stone_VipHole + maxVipHoleCnt):
            curGemID = GetEquipIndexStoneIDAndIsBand(curPlayer, equipPackIndex, holeIndex)[0]
            if curGemID == 0:
            if curGemID == 0:
                continue
            pickoffHoleList.append([equipPackIndex, holeIndex])
    # 脱装备的外层刷属性, 这里不刷
    __DoSysPickoffEquipStone(curPlayer, equipPackType, stonePackType, pickoffHoleList, "EquipChange", False)
    return
def OnVIPTimeOut(curPlayer):
    ## VIP到期处理
    #过期一样有效,屏蔽该逻辑
    return
    # 过期一样有效,屏蔽该逻辑
    return
def __DoSysPickoffEquipStone(curPlayer, equipPackType, stonePackType, pickoffHoleList, eventName, isRefreshAttr):
    ## 系统摘除宝石
    if not pickoffHoleList:
        return
    GameWorld.DebugLog("系统摘除宝石: %s,pickoffHoleList=%s" % (eventName, pickoffHoleList), curPlayer.GetPlayerID())
    equipIndexList = []
    stoneCount = len(pickoffHoleList)
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, stonePackType, stoneCount)
@@ -586,39 +629,42 @@
            if equipIndex not in equipIndexList:
                equipIndexList.append(equipIndex)
    else:
        #邮件物品信息列表
        # 邮件物品信息列表
        mailItemInfoList = []
        for equipIndex, holeIndex in pickoffHoleList:
            stoneInfo = GetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex)
            mailItemInfoList.append([stoneInfo[0], 1, stoneInfo[1]])
            SetEquipIndexStoneIDAndIsBand(curPlayer, equipIndex, holeIndex, 0, 0)
            DataRecordPack.DR_StoneItemChange(curPlayer, eventName, {'changeStoneID':0,'equipIndex':equipIndex,"holeIndex":holeIndex, "stoneID":stoneInfo[0]})
            DataRecordPack.DR_StoneItemChange(curPlayer, eventName,
                                              {'changeStoneID': 0, 'equipIndex': equipIndex, "holeIndex": holeIndex,
                                               "stoneID": stoneInfo[0]})
            if equipIndex not in equipIndexList:
                equipIndexList.append(equipIndex)
        PlayerControl.SendMailByKey("GemToPlayer", [curPlayer.GetPlayerID()], mailItemInfoList)
    #目前只有脱装备会触发,暂时屏蔽,由脱装备触发刷属性
    #if isRefreshAttr:
    # 目前只有脱装备会触发,暂时屏蔽,由脱装备触发刷属性
    # if isRefreshAttr:
    #    RefreshAttrByStoneAction(curPlayer, equipPackType, False)
    if equipIndexList:
        Sycn_StoneHoleInfo(curPlayer, equipIndexList)
    return
def Sycn_StoneHoleInfo(curPlayer, equipIndexList=[]):
    ###同步客户端宝石信息
    #装备位所有孔位
    # 装备位所有孔位
    holeIndexList = GetAllEquipPlaceHoleIndex()
    maxHoleCount = len(holeIndexList)
    if not equipIndexList:
        equipIndexList = GetAllStoneEquipIndexList()
    sendPack = ChPyNetSendPack.tagMCStoneInfo()
    sendPack.InfoList = []
    for equipIndex in equipIndexList:
        stoneMsg = ChPyNetSendPack.tagMCStoneMsg()
        stoneMsg.EquipPlace = equipIndex
        stoneMsg.MaxStoneCount = maxHoleCount
        stoneMsg.MaxStoneCount = maxHoleCount
        stoneMsg.StoneInfo = GetEquipIndexStoneIDList(curPlayer, equipIndex)
        holeStoneBindList = []
        for holeIndex in holeIndexList:
@@ -626,7 +672,6 @@
            holeStoneBindList.append(isBind)
        stoneMsg.StoneBind = holeStoneBindList
        sendPack.InfoList.append(stoneMsg)
    sendPack.EquipCount = len(sendPack.InfoList)
    sendPack.EquipCount = len(sendPack.InfoList)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return