#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#---------------------------------------------------------------------  
 | 
#  
 | 
#---------------------------------------------------------------------  
 | 
##@package PlayerFamilyTech  
 | 
# @todo: Íæ¼Ò¼Ò×å¿Æ¼¼  
 | 
#  
 | 
# @author: panwei  
 | 
# @date 2011-06-16  
 | 
# @version 1.2  
 | 
#  
 | 
# @change: "2016-06-08 16:00" hxp ÓÀºãÕ½Ã˿Ƽ¼°æ±¾  
 | 
# @change: "2016-10-31 16:00" hxp ¸ÄΪ´¿µØÍ¼´¦Àíģʽ  
 | 
#---------------------------------------------------------------------  
 | 
#"""Version = 2016-10-31 16:00"""  
 | 
#---------------------------------------------------------------------  
 | 
import GameWorld  
 | 
#import ReadChConfig  
 | 
import GameFuncComm  
 | 
import ChPyNetSendPack  
 | 
import PlayerControl  
 | 
import NetPackCommon  
 | 
import ShareDefine  
 | 
import ChConfig  
 | 
import IpyGameDataPY  
 | 
import PlayerSuccess  
 | 
#---------------------------------------------------------------------  
 | 
def __GetTechIpyData(techID, lv=1):  
 | 
    keyStr = techID*1000+lv  
 | 
    return IpyGameDataPY.GetIpyGameData('FamilyTech', keyStr)  
 | 
  
 | 
#// A6 07  ×ÔÉí¼Ò×å¿Æ¼¼µÈ¼¶ÌáÉý #tagCMFamilyTechLVUP  
 | 
#  
 | 
#struct     tagCMFamilyTechLVUP  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#    DWORD        TechID;    // ¿Æ¼¼ID  
 | 
#};  
 | 
def OnPlayerFamilyTechLVUP(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    techID = clientData.TechID  
 | 
      
 | 
    familyID = curPlayer.GetFamilyID()  
 | 
    if familyID <= 0:  
 | 
        GameWorld.DebugLog("ûÓÐÕ½ÃË, ÎÞ·¨Éý¼¶Õ½Ã˿Ƽ¼!")  
 | 
        return  
 | 
    if curPlayer.GetFamilyLV() < IpyGameDataPY.GetFuncCfg('TechFamilyLV'):  
 | 
        return  
 | 
    curTechLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyTechLV % techID)  
 | 
    tagTechLV = curTechLV + 1  
 | 
    ipyData = __GetTechIpyData(techID, tagTechLV)  
 | 
    if not ipyData:  
 | 
        GameWorld.DebugLog("Õ½Ã˿Ƽ¼ID²»´æÔÚ»òÒÑÂú¼¶! techID=%s, tagTechLV=%s" % (techID, tagTechLV))  
 | 
        return  
 | 
     
 | 
      
 | 
    needContribution = ipyData.GetContribution()  
 | 
    if not needContribution:  
 | 
        GameWorld.DebugLog("ÕÒ²»µ½Éý¼¶¿Æ¼¼µÈ¼¶¶ÔÓ¦ÏûºÄ techID=%s,tagTechLV=%s" % (techID, tagTechLV))   
 | 
        return  
 | 
  
 | 
    #dataDict = {"techID":techID, "curTechLV":curTechLV, "tagTechLV":tagTechLV}  
 | 
    isPayOK = PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_Family_Contribution, needContribution)  
 | 
       
 | 
    if not isPayOK:  
 | 
        GameWorld.DebugLog("Íæ¼Òµ±Ç°¹±Ï׶Ȳ»×㣬ÎÞ·¨Éý¼¶Õ½Ã˿Ƽ¼£¡needContribution=%s" % (needContribution))  
 | 
        return  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyTechLV % techID, tagTechLV)  
 | 
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_FamilyTechLV, 1, [techID])  
 | 
    PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_660051", [techID, tagTechLV])  
 | 
    Sync_PlayerFamilyTechLV(curPlayer)  
 | 
    #Ë¢ÐÂËùÓÐÊôÐÔ  
 | 
    CalcFamilyTechAttr(curPlayer)  
 | 
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  
 | 
    return  
 | 
  
 | 
#    if curPlayer.GetDictByKey(ChConfig.Def_PDict_QueryTechLVUPState):  
 | 
#        #ÒѾÔÚ²éѯÖÐ  
 | 
#        GameWorld.DebugLog("OnPlayerFamilyTechLVUP ÒѾÔÚ²éѯÖÐ...")  
 | 
#        return  
 | 
#      
 | 
#    if techID not in ReadChConfig.GetEvalChConfig("FamilyTechAttr"):  
 | 
#        GameWorld.DebugLog("Õ½Ã˿Ƽ¼ID²»´æÔÚ! techID=%s" % techID)  
 | 
#        return  
 | 
#      
 | 
#    curPlayer.SetDict(ChConfig.Def_PDict_QueryTechLVUPState, 1)  
 | 
#    curTechLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyTechLV % techID)  
 | 
#    cmdStr = str([techID, curTechLV])  
 | 
#    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetPlayerID(), 0, 0, 'PlayerFamilyTechLVUP', cmdStr, len(cmdStr))  
 | 
#    GameWorld.DebugLog("Query PlayerFamilyTechLVUP cmdStr=%s" % cmdStr)  
 | 
    return  
 | 
  
 | 
## Ö´ÐÐÍæ¼ÒÕ½Ã˿Ƽ¼Éý¼¶  
 | 
def DoPlayerFamilyTechLVUP(curPlayer, resultList):  
 | 
    # [techID, curPlayerTechLV, needContribution]  
 | 
    if not resultList or len(resultList) < 3:  
 | 
        return  
 | 
          
 | 
    techID = resultList[0]  
 | 
    curPlayerTechLV = resultList[1]  
 | 
    needContribution = resultList[2]  
 | 
      
 | 
    curTechLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyTechLV % techID)  
 | 
    if curTechLV != curPlayerTechLV:  
 | 
        return  
 | 
      
 | 
    updTechLV = curTechLV + 1  
 | 
    #dataDict = {"techID":techID, "curTechLV":curTechLV, "updTechLV":updTechLV}  
 | 
    isPayOK = PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_Family_Contribution, needContribution)  
 | 
    if not isPayOK:  
 | 
        GameWorld.DebugLog("Íæ¼Òµ±Ç°¹±Ï׶Ȳ»×㣬ÎÞ·¨Éý¼¶Õ½Ã˿Ƽ¼£¡needContribution=%s" % (needContribution))  
 | 
        return  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FamilyTechLV % techID, updTechLV)  
 | 
    PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_660051", [techID, updTechLV])  
 | 
    Sync_PlayerFamilyTechLV(curPlayer)  
 | 
    #Ë¢ÐÂËùÓÐÊôÐÔ  
 | 
    CalcFamilyTechAttr(curPlayer)  
 | 
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  
 | 
    return  
 | 
  
 | 
## ¼ÆËãÕ½Ã˿Ƽ¼¸½¼ÓÊôÐÔ  
 | 
def CalcFamilyTechAttr(curPlayer):  
 | 
      
 | 
    allAttrList = [{} for _ in range(4)]  
 | 
    skillFPEx = 0 #¶îÍâÕ½Á¦  
 | 
    if GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_Family):  
 | 
        techNeedLVDict = IpyGameDataPY.GetFuncEvalCfg('FamilyTechNeedLV', 1, {})  
 | 
        techIDList = techNeedLVDict.keys()  
 | 
          
 | 
        #GameWorld.DebugLog("CalcFamilyTechAttr...techIDList=%s" % techIDList)  
 | 
          
 | 
        # ¼ÆËã×ÔÉíÊôÐÔ  
 | 
        for techID in techIDList:  
 | 
            techID = int(techID)  
 | 
            techLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyTechLV % techID)  
 | 
            if not techLV:  
 | 
                continue  
 | 
            ipyData = __GetTechIpyData(techID, techLV)  
 | 
            if not ipyData:  
 | 
                continue  
 | 
            attrID = ipyData.GetAttrType()  
 | 
            addValue = ipyData.GetAttrValue()  
 | 
            skillFPEx += ipyData.GetPowerEx()  
 | 
            #GameWorld.DebugLog("    techID=%s,lv=%s,attrID=%s,addValue=%s" % (techID, techLV, attrID, addValue))  
 | 
            PlayerControl.CalcAttrDict_Type(attrID, addValue, allAttrList)  
 | 
              
 | 
    #GameWorld.DebugLog("ÏÉÃËÐÄ·¨ÊôÐÔ: %s" % allAttrList)  
 | 
    # ±£´æ¼ÆËãÖµ  
 | 
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_FamilyTech, allAttrList)  
 | 
      
 | 
    curPlayer.SetDict(ChConfig.Def_PlayerKey_MFPEx % ShareDefine.Def_MFPType_Other, skillFPEx)  
 | 
    return  
 | 
  
 | 
  
 | 
## Í¬²½Íæ¼ÒÕ½Ã˿Ƽ¼µÈ¼¶  
 | 
def Sync_PlayerFamilyTechLV(curPlayer):  
 | 
    techInfoPack = ChPyNetSendPack.tagMCPlayerTechInfo()  
 | 
    techInfoPack.Clear()  
 | 
    techInfoPack.TechInfoList = []  
 | 
    techNeedLVDict = IpyGameDataPY.GetFuncEvalCfg('FamilyTechNeedLV', 1, {})  
 | 
    techIDList = techNeedLVDict.keys()  
 | 
    for techID in techIDList:  
 | 
        techInfo = ChPyNetSendPack.tagMCPlayerTech()  
 | 
        techInfo.Clear()  
 | 
        techInfo.TechID = techID  
 | 
        techInfo.TechLV = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FamilyTechLV % techID)  
 | 
        techInfoPack.TechInfoList.append(techInfo)  
 | 
    techInfoPack.TechCnt = len(techInfoPack.TechInfoList)  
 | 
    NetPackCommon.SendFakePack(curPlayer, techInfoPack)  
 | 
    return  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 |