xdh
2019-03-27 a572273422ce72347de0697eccc0c57fefb1f85d
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerMagicWeapon.py
@@ -9,7 +9,7 @@
# @date 2017-05-18
# @version 1.0
#
# 详细描述: 法宝系统
# 详细描述: 法宝系统 目前激活方式:1.任务接口激活 2.通关副本 3.获得某物品 4.仙宝寻主
#
#-------------------------------------------------------------------------------
#"""Version = 2017-05-18 12:00"""
@@ -38,15 +38,10 @@
import random
g_succInfoDict = {}
g_potentialsSkillDict = {}
##登录处理
# @param curPlayer 玩家
# @return None
def PlayerMagicWeaponLogin(curPlayer):
    NotifyMagicWeapon(curPlayer, True)
    SyncXBXZAwardRecord(curPlayer)
    Sycn_MagicWeaponLV(curPlayer)
    return
@@ -63,78 +58,61 @@
#    mwID = ipyData.GetID()
#    GameWorld.DebugLog("法宝功能开启 激活第一个法宝 mwID=%s"%mwID)
#    DoActiveMW(curPlayer, mwID)
#    NotifyMagicWeapon(curPlayer)
    return True
def GetIsActiveMagicWeapon(curPlayer, mwID, lv=0):
    #获取法宝是否激活
    #通过玩家字典值可直接判断是否已经激活,这里可不验证法宝ID是否存在,即使传入不存在的也是返回未激活
    #if not GetWMIpyData(mwID):
    #    return False
    if lv:
        curMWLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % mwID)
        return curMWLV >= lv
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsActive, mwID, True)
def GetIsActiveMagicWeapon(curPlayer, mwID, lv=1):
    #获取法宝是否达到X级
    curMWLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % mwID)
    return curMWLV >= lv
def SetMagicWeaponActiveState(curPlayer, mwID, isActive=True):
    #设置法宝激活状态
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsActive, mwID, isActive, True)
    return
def ActiveMagicWeapon(curPlayer, succID):
    ##激活法宝
    mwID = GetMWIDBySuccID(succID)
    if mwID == None:
        return
    isActive = GetIsActiveMagicWeapon(curPlayer, mwID)
    if isActive:
        return
    succIDList = GetNeedSuccIDByMWID(mwID)
    needExp = len(succIDList)
    curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponExp % mwID)
    if curExp >= needExp:
        return
    newExp = min(needExp, curExp + 1)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponExp % mwID, newExp)
    DataRecordPack.DR_MagicWeaponExp(curPlayer, mwID, succID, newExp, needExp)
    ipyData = GetWMIpyData(mwID)
    needItemDict = ipyData.GetNeedItem()
    #GameWorld.DebugLog('    激活法宝 mwID=%s,curExp=%s,succIDList=%s' % (mwID, newExp,succIDList))
    if newExp >= needExp and not needItemDict:
        #成就条件达成 激活法宝
def ActiveMagicWeaponByFB(curPlayer, mapID, lineID, passLV=0):
    ##通关副本激活法宝(人族、魔族法宝)
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('MagicWeaponFB', {'LineID':lineID, 'Level':passLV})
    if ipyData:
        mwID = ipyData.GetMWID()
        GameWorld.Log('更新魔族副本关卡 mwID=%s,level=%s' % (mwID, passLV), curPlayer.GetID())
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWFBPassLevel % mwID, passLV)
        Sycn_MagicWeaponLV(curPlayer, mwID)
        EventShell.EventRespons_MagicWeaponFBPassLV(curPlayer, mwID, passLV)
        ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('MagicWeaponFB', {'LineID':lineID}, True)
        maxLevel = ipyDataList[-1].GetLevel()
        if passLV >= maxLevel:
            DoActiveMW(curPlayer, mwID)
        else:
            CalcMagicWeaponAttr(curPlayer)
            PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    else:
        ipyData = IpyGameDataPY.GetIpyGameDataByCondition('Treasure', {'FBMapID':mapID, 'FBLineID':lineID})
        if not ipyData:
            return
        if curPlayer.GetLV() < ipyData.GetNeedLV():
            GameWorld.Log('通关副本激活法宝 ,等级不足!!!mwID=%s, needLV=%s' % (mwID, ipyData.GetNeedLV()))
            return
        mwID = ipyData.GetID()
        DoActiveMW(curPlayer, mwID)
    return
def DoActiveMW(curPlayer, mwID, mwLV=0):
def DoActiveMW(curPlayer, mwID, mwLV=1):
    if not GetWMIpyData(mwID):
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponLV % mwID, mwLV)
    if mwLV == 0:
        SetMagicWeaponActiveState(curPlayer, mwID)
        #֪ͨ
        NotifyMagicWeapon(curPlayer)
    if mwLV == 1:
        if mwID in IpyGameDataPY.GetFuncEvalCfg('UnblockTreasure'):
            PlayerControl.NotifyCode(curPlayer, 'UnblockTreasure', [curPlayer.GetName(), mwID])
        else:
            sysMark = IpyGameDataPY.GetFuncEvalCfg('UnblockTreasure', 2, {}).get(mwID, 'UnblockTreasure')
            PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), mwID])
        
        #任务
        EventShell.EventRespons_OnActiveMagicWeapon(curPlayer, mwID)
    else:
        #通知客户端等级
        Sycn_MagicWeaponLV(curPlayer, mwID)
        EventShell.EventRespons_MagicWeaponLV(curPlayer, mwID, mwLV)
    EventShell.EventRespons_MagicWeaponLV(curPlayer, mwID, mwLV)
    #通知客户端等级
    Sycn_MagicWeaponLV(curPlayer, mwID)
    #成就
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_GetMagicWeapon, 1, [mwID, mwLV])
@@ -145,25 +123,7 @@
    skillIDList = upIpyData.GetUnLockSkill()
    for skillID in skillIDList:
        GiveSkill(curPlayer, skillID, GameWorld.GetGameWorld().GetTick())
    #物品奖励
    itemAward = upIpyData.GetItemAward()
    if itemAward:
        itemID, itemCnt, isBind = itemAward
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, 1)
        if 1 > packSpace:
            PlayerControl.SendMailByKey('TreasureWakeUp', [curPlayer.GetID()], [itemAward])
        else:
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem], event=["MWAward", False, {"mwID":mwID}])
    activeMWID = upIpyData.GetActiveMWID()
    if activeMWID == mwID:
        GameWorld.ErrLog('    TreasureUp.txt 配置异常 不可激活自身法宝 mwID=%s' % mwID)
    elif activeMWID:
        DoActiveMW(curPlayer, activeMWID)
    #激活魂
#    activeSoulID = upIpyData.GetActiveSoulID()
#    if activeSoulID:
#        __DoActiveMWSoul(curPlayer, activeSoulID, False)
    
    CalcMagicWeaponAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
@@ -181,32 +141,6 @@
def GetWMIpyData(mwID):return IpyGameDataPY.GetIpyGameData('Treasure', mwID)
def GetNeedSuccIDByMWID(mwID, ipyData=None):
    ##获取法宝ID开启需要完成的成就ID
    if not ipyData:
        ipyData = GetWMIpyData(mwID)
        if not ipyData:
            return []
    succIDList = list(ipyData.GetSuccID())
    return succIDList
def GetMWIDBySuccID(succID):
    global g_succInfoDict
    if not g_succInfoDict:
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetTreasureCount()):
            ipyData = ipyDataMgr.GetTreasureByIndex(i)
            mwID = ipyData.GetID()
            succIDList = GetNeedSuccIDByMWID(mwID, ipyData)
            for succid in succIDList:
                if succid in g_succInfoDict:
                    GameWorld.ErrLog('    存在相同成就激活条件的法宝 %s 和 %s' % (mwID, g_succInfoDict[succid]))
                g_succInfoDict[succid] = mwID
    return g_succInfoDict.get(succID)
def GetMWActiveCntTotal(curPlayer):
@@ -270,26 +204,6 @@
    PlayerControl.PlayerControl(curPlayer).RefreshSkillFightPowerEx(skillResID, 0)
    return
def NotifyMagicWeapon(curPlayer, isLogin=False):
    #通知法宝信息
    packData = ChPyNetSendPack.tagMCMagicWeaponData()
    packData.Clear()
    packData.MagicWeaponID = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetTreasureCount()):
        ipyData = ipyDataMgr.GetTreasureByIndex(i)
        magicWeaponID = ipyData.GetID()
        isActive = GetIsActiveMagicWeapon(curPlayer, magicWeaponID)
        if not isActive:
            continue
        packData.MagicWeaponID.append(magicWeaponID)
    packData.Num = len(packData.MagicWeaponID)
    if packData.Num or isLogin:
        NetPackCommon.SendFakePack(curPlayer, packData)
    return
##--------------------------------------------------------------------------------------------------
@@ -386,11 +300,7 @@
    if isActive:
        GameWorld.DebugLog('    该法宝已开启! mwID=%s' % mwID)
        return
    succIDList = GetNeedSuccIDByMWID(mwID)
    curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponExp % mwID)
    if curExp < len(succIDList):
        GameWorld.DebugLog('    该法宝所需成就未完成! mwID=%s, curExp=%s, succIDList=%s' % (mwID, curExp, succIDList))
        return
    #消耗物品判断
    ipyData = GetWMIpyData(mwID)
    needItemDict = ipyData.GetNeedItem()
@@ -602,16 +512,15 @@
    for mwID in needCalList:
        mwLv = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % mwID)
        curUpExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponUpExp % mwID)
        state = GetIsClickMagicWeapon(curPlayer, mwID)
        FBPassLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWFBPassLevel % mwID)
        isWear = GetIsWearMagicWeapon(curPlayer, mwID)
        if isAll and not mwLv and not curUpExp and not state and not FBPassLV and not isWear:
        if isAll and not mwLv and not curUpExp and not FBPassLV and not isWear:
            continue
        pack = ChPyNetSendPack.tagMCMagicWeaponInfo()
        pack.MWID = mwID
        pack.LV = mwLv
        pack.Exp = curUpExp
        pack.State = state
        pack.FBPassLV = FBPassLV
        pack.IsWear = isWear
        sendPack.InfoList.append(pack)
@@ -620,34 +529,6 @@
        NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
#// A5 16 法宝状态记录 #tagCMMagicWeaponState
#
#struct    tagCMMagicWeaponState
#
#{
#    tagHead        Head;
#    DWORD        MWID;    //法宝ID
#};
def SaveMagicWeaponState(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    mwID = clientData.MWID
    if GetIsClickMagicWeapon(curPlayer, mwID):
        return
    SetMagicWeaponClickState(curPlayer, mwID)
    Sycn_MagicWeaponLV(curPlayer, mwID)
    return
def GetIsClickMagicWeapon(curPlayer, mwID):
    #获取法宝是否点击认主
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsClick, mwID, True)
def SetMagicWeaponClickState(curPlayer, mwID, state=1):
    #设置法宝是否点击认主状态
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsClick, mwID, state, True)
    return
#// A5 1D 法宝佩戴 #tagCMWearMagicWeapon
@@ -691,13 +572,3 @@
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsWear, mwID, state, True)
    return
def UptateMWFBPasslv(curPlayer, mwID, passLV):
    GameWorld.Log('更新关卡 mwID=%s,level=%s' % (mwID, passLV), curPlayer.GetID())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWFBPassLevel % mwID, passLV)
    CalcMagicWeaponAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    Sycn_MagicWeaponLV(curPlayer, mwID)
    EventShell.EventRespons_MagicWeaponFBPassLV(curPlayer, mwID, passLV)
    return