xdh
2019-07-12 2e3f2507646fe547606923137c2ff526b54c25e4
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerRefineStove.py
@@ -37,7 +37,7 @@
import copy
import time
DefStoveType1 = 1 #1灵丹
DefStoveType1 = 1 #1灵丹
DefStoveType2 = 2 #2仙丹
@@ -76,7 +76,7 @@
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_RefineStove):
        GameWorld.DebugLog("炼丹炉功能未开启!", playerID)
        return
    refineTimes = max(1, clientPack.AlchemyTimes)
    alchemyID = clientPack.AlchemyID
    doType = clientPack.DoType
    GameWorld.DebugLog("玩家炼丹: alchemyID=%s, doType=%s" % (alchemyID, doType), playerID)
@@ -91,7 +91,7 @@
    curAlchemyItemID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyItemID % alchemType)  #正在炼的丹
    curLuckValue = curPlayer.GetLuckValue()
    curTime = int(time.time())
    if doType == 0:
        if hasLearn:
            GameWorld.DebugLog('丹方已学习!,不可重复学')
@@ -100,9 +100,9 @@
        if alchemyLV < learnNeedAlchemLV:
            GameWorld.DebugLog('丹方学习需要炼丹等级 %s' % learnNeedAlchemLV)
            return
        learnNeedLuck = alchemyIpyData.GetLearnNeedLuck()
        if curLuckValue < learnNeedLuck:
            GameWorld.DebugLog('丹方学习需要慧根 %s' % learnNeedLuck)
        learnNeedLingGenPoint = alchemyIpyData.GetLearnNeedLingGenPoint()
        if PlayerControl.GetTotalLingGenPoint(curPlayer) < learnNeedLingGenPoint:
            GameWorld.DebugLog('丹方学习需要总灵根点 %s' % learnNeedLingGenPoint)
            return
        learnNeedItemID = alchemyIpyData.GetLearnNeedItemID()
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
@@ -119,25 +119,28 @@
        if curAlchemyItemID:
            GameWorld.DebugLog('当前丹类型已在炼丹中! curAlchemyItemID=%s' % curAlchemyItemID)
            return
        if refineTimes < 1:
            return
        # 基础固定消耗
        needMaterialDict = alchemyIpyData.GetMaterial()
        needMaterialDict = {itemID:itemCnt*refineTimes for itemID, itemCnt in needMaterialDict.items()}
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
        lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needMaterialDict, itemPack, False)
        if lackItemDict:
            GameWorld.DebugLog("配方材料不足!alchemyID=%s,needMaterialDict=%s,lackItemDict=%s,hasItemDict=%s"
            GameWorld.DebugLog("配方材料不足!alchemyID=%s,needMaterialDict=%s,lackItemDict=%s,hasItemDict=%s"
                               % (alchemyItemID, needMaterialDict, lackItemDict, delInfoDict), playerID)
            return
        #扣消耗
        ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, ChConfig.ItemDel_Alchemy)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyItemID % alchemType, alchemyItemID)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyStartTime % alchemyID, curTime)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyTimes % alchemyID, refineTimes)
        Sycn_AlchemyMsg(curPlayer, alchemyID, False)
        #日常任务
        costItemCnt = sum(needMaterialDict.values())
        PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_RefineStove, costItemCnt)
        #PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_RefineStove, costItemCnt)
    elif doType == 2:
        if curAlchemyItemID != alchemyItemID:
            GameWorld.DebugLog('停止丹药ID错误 curAlchemyItemID=%s' % curAlchemyItemID)
@@ -149,82 +152,113 @@
        if curAlchemyItemID != alchemyItemID:
            GameWorld.DebugLog('开炉丹药ID错误 curAlchemyItemID=%s' % curAlchemyItemID)
            return
        refineTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyTimes % alchemyID)
        refineTimes = max(1, refineTimes)
        startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyStartTime % alchemyID)
        passTime = max(0, curTime - startTime)
        if passTime < alchemyIpyData.GetNeedTime():
        if passTime < alchemyIpyData.GetNeedTime() * refineTimes:
            GameWorld.DebugLog('开炉丹药,时间未到  passTime=%s' % passTime)
            return
        alchemyQuality = alchemyIpyData.GetAlchemyQuality()
        #成功率
        if alchemType == DefStoveType2:
            successRate = ShareDefine.Def_MaxRateValue  #仙丹必定成功
        else:
            #灵丹成功率公式 参数 curLuckValue:慧根  alchemyLV:炼丹等级 alchemyQuality:丹药等级  qualityNeedLuck:要求慧根
            qualityNeedLuck = IpyGameDataPY.GetFuncEvalCfg('alchemySuccess', 2, {}).get(str(alchemyQuality), 0)
            successRate = eval(IpyGameDataPY.GetFuncCompileCfg('alchemySuccess'))
        isSuccess = GameWorld.CanHappen(successRate)
        alchemyAppointCntDict = {} #定制配置 {次数:[数量,成功率]}
        alchemyCustomizedDict = IpyGameDataPY.GetFuncEvalCfg('alchemyCustomized', 1, {})
        if alchemyID in alchemyCustomizedDict:
            alchemyCnt = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_AlchemyCnt, alchemyID, False)
            alchemyAppointCntDict = alchemyCustomizedDict[alchemyID]
        resultIpyData = IpyGameDataPY.InterpolationSearch('AlchemyResult', 'LuckValue', curLuckValue, {'AlchemyQuality':alchemyIpyData.GetAlchemyQuality()})
        if not resultIpyData:
            GameWorld.ErrLog('AlchemyResult 配置错误 未找到该丹方数量 alchemyItemID=%s' % alchemyItemID, playerID)
            return
        makeItemData = GameWorld.GetGameData().GetItemByTypeID(alchemyItemID)
        if not makeItemData:
            return
        #灵丹成功率公式 参数 curLuckValue:慧根  alchemyLV:炼丹等级 alchemyQuality:丹药等级  qualityNeedLuck:要求慧根
        qualityNeedLuck = IpyGameDataPY.GetFuncEvalCfg('alchemySuccess', 2, {}).get(str(alchemyQuality), 0)
        nomalsuccessRate = eval(IpyGameDataPY.GetFuncCompileCfg('alchemySuccess'))
        resultCnt = 0  #丹药数量 0代表失败
        if isSuccess:
        for i in xrange(refineTimes):
            #成功率
            appointInfo = [] #[数量,成功率]
            if alchemyAppointCntDict and alchemyCnt+1+i in alchemyAppointCntDict:
                appointInfo = alchemyAppointCntDict[alchemyCnt+1+i]
            if appointInfo:
                successRate = appointInfo[1]
            elif alchemType == DefStoveType2:
                successRate = ShareDefine.Def_MaxRateValue  #仙丹必定成功
            elif alchemType == DefStoveType1:
                successRate = nomalsuccessRate
            else:
                return
            isSuccess = GameWorld.CanHappen(successRate)
            if isSuccess:
                if alchemType == DefStoveType2:
                    resultCnt += 1 #仙丹必定为1
                elif alchemType == DefStoveType1:
                    if appointInfo:
                        resultCnt += appointInfo[0]
                    else:
                        resultCnt += GameWorld.GetResultByRandomList(resultIpyData.GetCntRateList())
                if not resultCnt:
                    GameWorld.ErrLog('AlchemyResult 配置错误 未随机出该丹方数量alchemyItemID=%s' % alchemyItemID, playerID)
                    return
        if resultCnt:
            needSpace = 1
            packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
            if needSpace > packSpace:
                PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
                return
            if alchemType == DefStoveType2:
                resultCnt = 1 #仙丹必定为1
            else:
                ipyData = IpyGameDataPY.InterpolationSearch('AlchemyResult', 'LuckValue', curLuckValue, {'AlchemyQuality':alchemyIpyData.GetAlchemyQuality()})
                if not ipyData:
                    GameWorld.ErrLog('AlchemyResult 配置错误 未找到该丹方数量 alchemyItemID=%s' % alchemyItemID, playerID)
                    return
                resultCnt = GameWorld.GetResultByRandomList(ipyData.GetCntRateList())
            if not resultCnt:
                GameWorld.ErrLog('AlchemyResult 配置错误 未随机出该丹方数量alchemyItemID=%s' % alchemyItemID, playerID)
                return
            makeItemData = GameWorld.GetGameData().GetItemByTypeID(alchemyItemID)
            if not makeItemData:
                return
            ItemControler.GivePlayerItem(curPlayer, alchemyItemID, resultCnt, 0, [IPY_GameWorld.rptItem],
                                     event=[ChConfig.ItemGive_Refine, False, {}])
                                      event=[ChConfig.ItemGive_Refine, False, {}])
            #紫色及以上全服广播
            notifyColor = IpyGameDataPY.GetFuncCfg("AlchemyNotify", 1)
            needNotifyItemIDList = IpyGameDataPY.GetFuncEvalCfg("AlchemyNotify", 2)
            notNotifyItemIDList = IpyGameDataPY.GetFuncEvalCfg("AlchemyNotify", 3)
            if alchemyItemID not in notNotifyItemIDList and (alchemyItemID in needNotifyItemIDList or makeItemData.GetItemColor() >= notifyColor):
                PlayerControl.WorldNotify(0, "AchemyGreatSuccess", [curPlayer.GetPlayerName(), alchemyItemID])
            #任务
            EventShell.EventRespons_RefineItem(curPlayer, alchemyQuality)
        #任务
        for _ in xrange(refineTimes):
            EventShell.EventRespons_RefineItem(curPlayer, alchemyQuality, alchemyItemID)
        #重置
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyItemID % alchemType, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyStartTime % alchemyID, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyTimes % alchemyID, 0)
        #加经验
        addExp = alchemyIpyData.GetAlchemyExp()
        addExp = alchemyIpyData.GetAlchemyExp() * refineTimes
        AddRefineExp(curPlayer, addExp, alchemyLV)
        GameWorld.DebugLog('炼丹结果 alchemyItemID=%s,successRate=%s,isSuccess=%s,resultCnt=%s' % (alchemyItemID, successRate, isSuccess, resultCnt), playerID)
        #加次数
        if alchemyID in alchemyCustomizedDict:
            GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_AlchemyCnt, alchemyID, min(alchemyCnt + refineTimes, 9), False)
        GameWorld.DebugLog('炼丹结果 alchemyItemID=%s,refineTimes=%s,isSuccess=%s,resultCnt=%s' % (alchemyItemID, refineTimes, isSuccess, resultCnt), playerID)
    
        Sycn_AlchemyMsg(curPlayer, alchemyID, False, alchemyItemID, resultCnt)
        #完成1次炼丹成就
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_RefineItem, 1)
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_RefineItem, refineTimes)
        #完成1次X品质物品炼丹成就
        #PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_RefineStoveColor, 1, [makeItemData.GetItemColor()])
        PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_RefineStove, 1)
        PlayerNewFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_RefineStove, 1)
        PlayerActLogin.AddLoginAwardActionCnt(curPlayer, ChConfig.Def_LoginAct_Alchemy, 1)
    return
        PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_RefineStove, refineTimes)
        PlayerNewFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_RefineStove, refineTimes)
        PlayerActLogin.AddLoginAwardActionCnt(curPlayer, ChConfig.Def_LoginAct_Alchemy, refineTimes)
    return
def AddRefineExp(curPlayer, addExp, alchemyLV):
    #增加炼丹炉经验
    if addExp <= 0:
        return
    alchemyExp = min(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyExp) + addExp, ShareDefine.Def_UpperLimit_DWord)
    GameWorld.DebugLog("增加炼丹经验: alchemyLV=%s,addExp=%s,alchemyExp=%s" % (alchemyLV, addExp, alchemyExp), curPlayer.GetPlayerID())
    isLVUp = False
    stoveIpyData = IpyGameDataPY.GetIpyGameDataNotLog("RefineStove", alchemyLV)
    while stoveIpyData and stoveIpyData.GetUpNeedExp() and alchemyExp >= stoveIpyData.GetUpNeedExp():
@@ -234,7 +268,7 @@
        if not stoveIpyData:
            GameWorld.DebugLog("没有下一级数据了,已满级!不可升级!", curPlayer.GetPlayerID())
            break
        alchemyExp -= needExp
        alchemyLV += 1
        GameWorld.DebugLog("    炼丹升级: alchemyLV=%s,alchemyExp=%s" % (alchemyLV, alchemyExp), curPlayer.GetPlayerID())
@@ -243,7 +277,7 @@
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyExp, alchemyExp)
    if not isLVUp:
        return False
    GameWorld.DebugLog("升级后剩余经验: %s" % alchemyExp, curPlayer.GetPlayerID())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyLV, alchemyLV)
    PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_AlchemyLV, alchemyLV)
@@ -270,11 +304,12 @@
                syncItemIDList.append(alchemyID)
    elif alchemyID and GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_AlchemyLearnState, alchemyID):
        syncItemIDList = [alchemyID]
    for alchemyID in syncItemIDList:
        StoveInfo = ChPyNetSendPack.tagMCPlayerStoveInfo()
        StoveInfo.AlchemyID = alchemyID
        StoveInfo.StartTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyStartTime % alchemyID)
        StoveInfo.AlchemyTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyTimes % alchemyID)
        pack.InfoList.append(StoveInfo)
    pack.StoveCnt = len(pack.InfoList)
    NetPackCommon.SendFakePack(curPlayer, pack)
@@ -310,13 +345,13 @@
    if prayCnt >= limitCnt:
        GameWorld.DebugLog('今日祈福丹药次数已满!prayCnt=%s' % prayCnt)
        return
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, 1)
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, 1)
    if not packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    alchemyItemList = IpyGameDataPY.GetFuncEvalCfg('GodAlchemy')
    newItemInfoList = []
    for itemInfo in alchemyItemList:
        itemID = itemInfo[1]
@@ -330,17 +365,17 @@
    if not newItemInfoList:
        GameWorld.DebugLog('祈福丹药,没有丹药可产出!!')
        return
    makeItemInfo = GameWorld.GetResultByWeightList(newItemInfoList)
    if not makeItemInfo:
        GameWorld.DebugLog("祈福丹药, 结果错误!")
        return
    makeItemID, itemCount = makeItemInfo
    makeItemData = GameWorld.GetGameData().GetItemByTypeID(makeItemID)
    if not makeItemData:
        return
    costMoney = IpyGameDataPY.GetFuncCfg('GodAlchemy', 2)
    if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, costMoney, ChConfig.Def_Cost_AlchemyPray):
        return
@@ -348,14 +383,14 @@
    ItemControler.GivePlayerItem(curPlayer, makeItemID, itemCount, 0, [IPY_GameWorld.rptItem],
                                 event=[ChConfig.ItemGive_Refine, False, {}])
    #GameWorld.DebugLog('makeItemID=%s,newItemInfoList=%s'%(makeItemID, newItemInfoList))
    #紫色及以上全服广播
    notifyColor = IpyGameDataPY.GetFuncCfg("AlchemyNotify", 1)
    needNotifyItemIDList = IpyGameDataPY.GetFuncEvalCfg("AlchemyNotify", 2)
    notNotifyItemIDList = IpyGameDataPY.GetFuncEvalCfg("AlchemyNotify", 3)
    if makeItemID not in notNotifyItemIDList and (makeItemID in needNotifyItemIDList or makeItemData.GetItemColor() >= notifyColor):
        PlayerControl.WorldNotify(0, "BlastfurnaceBlessing", [curPlayer.GetPlayerName(), makeItemID])
    #更新次数
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_AlchemyPrayCnt, prayCnt + 1)
    Sycn_AlchemyPrayMsg(curPlayer, makeItemID)