xdh
2018-09-25 7db53f547e9093ad323343d28282e40413c13a6d
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Event/EventSrc/Operate_ItemCompound.py
@@ -25,10 +25,14 @@
import IpyGameDataPY
import ChConfig
import PlayerSuccess
import DataRecordPack
import PlayerWing
import PlayerDogz
import EventShell
import random
import math
#//A3 03 物品合成 #tagCMItemCompound
@@ -89,7 +93,6 @@
    successRate = ipyData.GetSuccessRate()
    successRateMax = ipyData.GetSuccessRateMax()
    addonsCountMax = ipyData.GetAddonsCountMax() # 可叠加的算叠加数量
    msgMark = ipyData.GetSysMark()
    # 可使用非固定道具 或 附加道具的 单次合成数默认为1
    if unfixedItemIDList or addonsCountMax > 0:
        compoundCnt = 1
@@ -101,13 +104,21 @@
    
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    wingItemExpInfo = None #材料翅膀精炼信息
    dogzEquipPlusExp = 0 #神兽装备强化熟练度
    # 检查不固定消耗道具
    if unfixedItemIDList:
        unfixedItemCostInfo = __CheckUnfixedItem(playerID, compoundID, makeItemData, itemPack, unfixedItemIndexList,
        unfixedItem = GameWorld.GetGameData().GetItemByTypeID(unfixedItemIDList[0])
        if not unfixedItem:
            return
        if ItemCommon.GetIsDogzEquip(unfixedItem):
            unfixedItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)
        else:
            unfixedItemPack = itemPack
        unfixedItemCostInfo = __CheckUnfixedItem(playerID, compoundID, makeItemData, unfixedItemPack, unfixedItemIndexList,
                                                 unfixedItemIDList, needUnfixedItemCount)
        if not unfixedItemCostInfo:
            return
        unfixedItemCostList, wingItemExpInfo = unfixedItemCostInfo
        unfixedItemCostList, wingItemExpInfo, dogzEquipPlusExp = unfixedItemCostInfo
    
    # 检查固定消耗道具
    if fixedItemIDList:
@@ -117,11 +128,12 @@
        fixedItemIndexDict, fixedItemNeedCntDict, compoundBindCnt = fixedItemInfo
    
    # 检查附加道具增加成功率消耗
    addSuccRate = 0
    addSuccRate, addSuccRateItemInfo = 0, []
    if addonsCountMax > 0:
        addSuccRate = __CheckAddonsItem(playerID, compoundID, itemPack, addonsItemIndexList, addonsItemCountList, addonsCountMax)
        if addSuccRate == None:
        addSuccRateInfo = __CheckAddonsItem(playerID, compoundID, itemPack, addonsItemIndexList, addonsItemCountList, addonsCountMax)
        if addSuccRateInfo == None:
            return
        addSuccRate, addSuccRateItemInfo = addSuccRateInfo
    
    # 扣铜钱
    PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, totalNeedMoney, ChConfig.Def_Cost_ItemProduce, 
@@ -133,7 +145,7 @@
    # 扣不固定消耗物品
    if unfixedItemIDList:
        bindUnfixedIndexList, unbindUnfixedIndexList = unfixedItemCostList
        hasBind = ItemCommon.ReduceItem(curPlayer, itemPack, bindUnfixedIndexList + unbindUnfixedIndexList, needUnfixedItemCount,
        hasBind = ItemCommon.ReduceItem(curPlayer, unfixedItemPack, bindUnfixedIndexList + unbindUnfixedIndexList, needUnfixedItemCount,
                                        False, ChConfig.ItemDel_ItemCompound, drDict)
        makeItemBind = True if hasBind else makeItemBind
    
@@ -172,9 +184,33 @@
            GameWorld.DebugLog("首次合成一代翅膀,必定成功!totalSuccRate=%s" % totalSuccRate, playerID)
            
    # 合成成功
    if GameWorld.CanHappen(totalSuccRate, ShareDefine.Def_MaxRateValue):
    maxRateValue = ShareDefine.Def_MaxRateValue
    randValue = random.randint(1, maxRateValue)
    canHappen = randValue <= totalSuccRate
    GameWorld.DebugLog("canHappen=%s,randValue=%s,totalSuccRate=%s,maxRateValue=%s"
                       % (canHappen, randValue, totalSuccRate, maxRateValue), playerID)
    # 不是百分百成功的记录合成流向
    if successRate != maxRateValue:
        drDict = {"PlayerID":curPlayer.GetPlayerID(), "AccID":curPlayer.GetAccID(), "ID":compoundID, "MakeItemID":makeItemID, "IsSuccess":canHappen,
                  "RateInfo":{"totalSuccRate":"%s(%s+%s)" % (totalSuccRate, successRate, addSuccRate), "randValue":randValue, "maxRateValue":maxRateValue},
                  "AddSuccRateItemInfo":addSuccRateItemInfo
                  }
        DataRecordPack.SendEventPack("ItemCompound", drDict, curPlayer)
    if canHappen:
        GameWorld.DebugLog("合成成功: makeItemID=%s,compoundCnt=%s,compoundBindCnt=%s" % (makeItemID, compoundCnt, compoundBindCnt), playerID)
        GiveNewCompoundItem(curPlayer, makeItemID, compoundCnt, compoundBindCnt, wingItemExpInfo, msgMark)
        userData = GiveNewCompoundItem(curPlayer, makeItemID, compoundCnt, compoundBindCnt, wingItemExpInfo, dogzEquipPlusExp)
        msgMark = ipyData.GetSysMark()
        paramType = ipyData.GetSysMarkParamType()
        if msgMark not in ['0', '', '-']:
            if paramType == 2 and fixedItemIDList and fixedItemCountList:
                PlayerControl.WorldNotify(0, msgMark, [curPlayer.GetName(), fixedItemCountList[0], fixedItemIDList[0], makeItemID, userData])
            else:
                PlayerControl.WorldNotify(0, msgMark, [curPlayer.GetName(), makeItemID, userData])
        # 通知合成成功
        ItemCommon.SyncMakeItemAnswer(curPlayer, ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Sucess, makeItemID)
        #成功合成1个物品成就
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_CompoundItemEx, compoundCnt, [makeItemID])
        #合成X阶X颜色X星级以上装备
@@ -182,10 +218,11 @@
        itemColor = makeItemData.GetItemColor()
        itemQuality = makeItemData.GetItemQuality()
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_CompoundEquip, compoundCnt, [classLV, itemColor, itemQuality])
        EventShell.EventRespons_CompoundEquip(curPlayer, itemColor, itemQuality)
    # 合成失败
    else:
        GameWorld.DebugLog("合成失败!")
        __SendDogzEquipRemainExpMail(playerID, dogzEquipPlusExp, False)
        ItemCommon.SyncMakeItemAnswer(curPlayer, ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Fail, 0)
        #curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Fail)
@@ -198,6 +235,7 @@
def __CheckUnfixedItem(playerID, compoundID, makeItemData, itemPack, unfixedItemIndexList, unfixedItemIDList, needUnfixedItemCount):
    ## 检查不固定消耗道具, 只要客户端提交的数据有不符合要求的,则直接返回 None
    wingItemExpInfo = None
    dogzEquipPlusExp = 0
    unfixedItemTotalCount = 0
    unfixedItemCostList = [[], []] # [[绑定索引], [非绑定索引]]
    maxPackCount = itemPack.GetCount()
@@ -223,13 +261,19 @@
        #记录翅膀精炼值
        if curItem.GetType() == ChConfig.Def_ItemType_retWing:
            wingItemExpInfo = PlayerWing.GetWingItemChangeExp(curItem, ItemCommon.GetItemClassLV(makeItemData))
        elif ItemCommon.GetIsDogzEquip(curItem):
            equipExpEff = ItemCommon.GetItemEffectByEffectID(curItem, ChConfig.Def_Effect_DogzEquipPlusExp)
            baseExp = 0 if not equipExpEff else equipExpEff.GetEffectValue(0)
            plusExp = curItem.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 1)
            dogzEquipPlusExp += (baseExp + plusExp)
            GameWorld.DebugLog("    神兽合成材料: index=%s,itemID=%s,baseExp=%s,plusExp=%s" % (index, itemID, baseExp, plusExp))
    if unfixedItemTotalCount < needUnfixedItemCount:
        GameWorld.Log("不固定消耗道具不足,无法合成!ID=%s,unfixedItemIDList=%s,needUnfixedItemCount=%s > unfixedItemTotalCount=%s" 
                      % (compoundID, unfixedItemIDList, needUnfixedItemCount, unfixedItemTotalCount), playerID)
        return
    
    return unfixedItemCostList, wingItemExpInfo
    return unfixedItemCostList, wingItemExpInfo, dogzEquipPlusExp
def __CheckFixedItem(playerID, compoundID, itemPack, fixedItemIndexList, fixedItemIDList, fixedItemCountList, compoundCnt):
@@ -350,6 +394,7 @@
#    ComposeAddonsQuality    4|2    0    0    0    0        阶数和颜色
#    ComposeAddonsFormula    level*10    0    0    0    0        计算合成时附加材料增加的几率公式
    addSuccRateItemInfo = []
    composeAddonsTypeList = IpyGameDataPY.GetFuncEvalCfg("ComposeAddonsType")
    classLV, color = IpyGameDataPY.GetFuncEvalCfg("ComposeAddonsQuality", 1)
    ComposeAddonsFormula = IpyGameDataPY.GetFuncCfg("ComposeAddonsFormula")
@@ -401,8 +446,9 @@
        
        addSuccRate = eval(FormulaControl.GetCompileFormula("ComposeAddonsFormula", ComposeAddonsFormula))
        addTotalSuccRate += (addSuccRate*costCount)
        addSuccRateItemInfo.append({"ItemID":itemID, "ItemColor":itemColor, "ItemClassLV":itemClassLV, "addSuccRate":addSuccRate, "costCount":costCount})
        
    return int(addTotalSuccRate)
    return int(addTotalSuccRate), addSuccRateItemInfo
def __CheckItemCanUseCompound(playerID, index, curItem):
@@ -429,30 +475,19 @@
#  @param newItem: 新物品
#  @param itemCount: 合成数量
#  @return None
def GiveNewCompoundItem(curPlayer, newItemID, itemCount, compoundBindCnt, wingItemExpInfo, msgMark):
def GiveNewCompoundItem(curPlayer, newItemID, itemCount, compoundBindCnt, wingItemExpInfo, dogzEquipPlusExp):
    compoundUnBindCnt = itemCount - compoundBindCnt
    
    if compoundBindCnt > 0:
        userData = __GivePlayerCompoundItem(curPlayer, newItemID, compoundBindCnt, True, wingItemExpInfo)
        userData = __GivePlayerCompoundItem(curPlayer, newItemID, compoundBindCnt, True, wingItemExpInfo, dogzEquipPlusExp)
    if compoundUnBindCnt > 0:
        userData = __GivePlayerCompoundItem(curPlayer, newItemID, compoundUnBindCnt, False, wingItemExpInfo)
        userData = __GivePlayerCompoundItem(curPlayer, newItemID, compoundUnBindCnt, False, wingItemExpInfo, dogzEquipPlusExp)
        
    if userData == None:
        return
    if msgMark not in ['0', '', '-']:
        PlayerControl.WorldNotify(0, msgMark, [curPlayer.GetName(), newItemID, userData])
    # 您获得了物品XX XX个
    #PlayerControl.NotifyCode(curPlayer, "ObtainRes01", [newItemID, itemCount])
    # 通知放入特效
    #curPlayer.Sync_GetItemView(newItemID, itemCount)
    # 通知合成成功
    ItemCommon.SyncMakeItemAnswer(curPlayer, ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Sucess, newItemID)
    #curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitItemCompound, ChConfig.Def_ComposeState_Sucess)
    return True
    if not userData:
        return ""
    return userData
def __GivePlayerCompoundItem(curPlayer, newItemID, itemCount, isBind, wingItemExpInfo):
def __GivePlayerCompoundItem(curPlayer, newItemID, itemCount, isBind, wingItemExpInfo, dogzEquipPlusExp):
    playerID = curPlayer.GetPlayerID()
    curSingleItem = ItemControler.GetOutPutItemObj(newItemID, itemCount, isBind)
    if not curSingleItem:
@@ -475,6 +510,15 @@
        
    if wingFinalExp:#继承翅膀精炼值
        PlayerWing.WingProgressUP(curSingleItem, wingFinalExp, materialItemDict)
    if dogzEquipPlusExp:#继承神兽装备熟练度
        dogzEquipLV, dogzEquipExp = PlayerDogz.GetDogzEquipPlusLVExpInfo(curSingleItem.GetItemColor(), curSingleItem.GetEquipPlace(), dogzEquipPlusExp)
        curSingleItem.AddUserAttr(ShareDefine.Def_IudetDogzEquipPlus, dogzEquipLV)
        curSingleItem.AddUserAttr(ShareDefine.Def_IudetDogzEquipPlus, dogzEquipExp)
        remainExp = max(0, dogzEquipPlusExp - dogzEquipExp)
        GameWorld.DebugLog("合成神兽装备成功, dogzEquipLV=%s,dogzEquipExp=%s,remainExp=%s,总EXP=%s"
                           % (dogzEquipLV, dogzEquipExp, remainExp, dogzEquipPlusExp), playerID)
        __SendDogzEquipRemainExpMail(playerID, remainExp, True)
    userData = curSingleItem.GetUserData()
    if not ItemControler.PlayerItemControler(curPlayer).PutInItem(IPY_GameWorld.rptItem, curSingleItem, 
                                                                  event=[ChConfig.ItemGive_ItemCompound, False, {}]):
@@ -484,3 +528,34 @@
    
    return userData
def __SendDogzEquipRemainExpMail(playerID, remainExp, isSucc):
    if not remainExp:
        return
    expItemID = IpyGameDataPY.GetFuncCfg("DogzAssist", 5)
    itemData = GameWorld.GetGameData().GetItemByTypeID(expItemID)
    if not itemData:
        return
    effect = ItemCommon.GetItemEffectByEffectID(itemData, ChConfig.Def_Effect_DogzEquipPlusExp)
    if not effect:
        GameWorld.ErrLog("神兽装备合成返回熟练度物品ID错误! expItemID=%s,remainExp=%s" % (expItemID, remainExp), playerID)
        return
    baseExp = effect.GetEffectValue(0)
    if not baseExp:
        GameWorld.ErrLog("神兽装备合成返回熟练度物品ID错误! expItemID=%s,baseExp=%s,remainExp=%s"
                         % (expItemID, baseExp, remainExp), playerID)
        return
    giveItemCount = int(remainExp/baseExp)
    if giveItemCount <= 0:
        return
    mailTypeKey = "DogzComposeSuc" if isSucc else "DogzComposeLose"
    GameWorld.DebugLog("合成神兽装备, 返还强化熟练度=%s,baseExp=%s,expItemID=%s,giveItemCount=%s"
                       % (remainExp, baseExp, expItemID, giveItemCount), playerID)
    isBind = 1
    PlayerControl.SendMailByKey(mailTypeKey, [playerID], [[expItemID, giveItemCount, isBind]])
    return