#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#-------------------------------------------------------------------------------  
 | 
#  
 | 
##@package Player.PlayerDogz  
 | 
#  
 | 
# @todo:ÉñÊÞϵͳ  
 | 
# @author hxp  
 | 
# @date 2018-08-20  
 | 
# @version 1.0  
 | 
#  
 | 
# ÏêϸÃèÊö: ÉñÊÞϵͳ  
 | 
#  
 | 
#-------------------------------------------------------------------------------  
 | 
#"""Version = 2018-08-20 17:00"""  
 | 
#-------------------------------------------------------------------------------  
 | 
  
 | 
import GameWorld  
 | 
import ItemCommon  
 | 
import ShareDefine  
 | 
import PlayerControl  
 | 
import ChPyNetSendPack  
 | 
import NetPackCommon  
 | 
import IPY_GameWorld  
 | 
import IpyGameDataPY  
 | 
import ChConfig  
 | 
import ChEquip  
 | 
  
 | 
'''  
 | 
ÉñÊÞ±àºÅ: 1~20£¬ÉÏÏߺ󲻿ÉÐÞ¸Ä  
 | 
ÉñÊÞ×°±¸Î»: 101~105 ÎïÆ·±íÖеÄ×°±¸Î»ÅäÖà  
 | 
ÉñÊÞ×°±¸ÀàÐÍ£º119~123£¬²ß»®Ëµ´òËÀ²»»áÔÙ¼ÓÀàÐÍÁË£¬¹Ì¶¨5¸öÉñÊÞ×°±¸ÀàÐÍ  
 | 
  
 | 
ÉñÊÞÎïÆ·±³°ü£¨ÀàÐÍ32,ÔÝ¿ª·Å100¸ñ£©£¬´æ·ÅÉñÊÞ×°±¸(ÀàÐÍ119~123)£¬¼°Ç¿»¯²ÄÁÏ£¨ÀàÐÍ70£©£¬  
 | 
ÉñÊÞ×°±¸±³°ü£¨ÀàÐÍ33,ÔÝ¿ª·Å100¸ñ£©£¬ËùÓÐÉñÊÞ¹²Óã¬Ã¿Ö»ÉñÊÞ5¸ñ£¬(¸ñ×ÓË÷Òý/5)+1=¶ÔÓ¦ÉñÊÞ±àºÅ£¬(¸ñ×ÓË÷Òý%5)+100+1=¶ÔÓ¦ÉñÊÞ×°±¸Î»  
 | 
'''  
 | 
  
 | 
DogzEquipCount = 5 # ÉñÊÞ×°±¸Î»ÊýÁ¿£¬¹Ì¶¨5¸ö£¬²ß»®Ëµ´òËÀÒ²²»¸Ä  
 | 
  
 | 
def GetDogzEquipPlaceIndex(equipPlace):  
 | 
    ## »ñÈ¡ÉñÊÞ×°±¸Î»¶ÔÓ¦µÄË÷Òý  
 | 
    return equipPlace - 1 - 100  
 | 
  
 | 
def GetDogzEquipPackIndex(dogzID, equipPlaceIndex):  
 | 
    ## »ñÈ¡ÉñÊÞ×°±¸ÔÚÉñÊÞ×°±¸±³°üÖеĹ̶¨Î»ÖÃË÷Òý  
 | 
    return (dogzID - 1) * DogzEquipCount + equipPlaceIndex  
 | 
  
 | 
def GetDogzIsHelpFight(curPlayer, dogzID):  
 | 
    ## ÉñÊÞÊÇ·ñÖúս״̬  
 | 
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, dogzID - 1)  
 | 
  
 | 
def SetDogzIsHelpFight(curPlayer, dogzID, isFight):  
 | 
    ## ÉèÖÃÉñÊÞÊÇ·ñÖúս״̬  
 | 
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, dogzID - 1, 1 if isFight else 0)  
 | 
    Sync_DogzHelpbattleState(curPlayer, dogzID, isFight)  
 | 
    return  
 | 
  
 | 
  
 | 
def OnPlayerLogin(curPlayer):  
 | 
      
 | 
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount):  
 | 
        Sync_DogzInfo(curPlayer)  
 | 
          
 | 
    ipyDataMgr = IpyGameDataPY.IPY_Data()  
 | 
    for i in xrange(ipyDataMgr.GetDogzCount()):  
 | 
        ipyData = ipyDataMgr.GetDogzByIndex(i)  
 | 
        if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, i):  
 | 
            Sync_DogzHelpbattleState(curPlayer, ipyData.GetDogzID(), 1)  
 | 
              
 | 
    return  
 | 
  
 | 
#// A5 C0 ÉñÊÞ´©´÷×°±¸ #tagCMDogzEquipItem  
 | 
#  
 | 
#struct    tagCMDogzEquipItem  
 | 
#  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#    BYTE        DogzID;    // ÉñÊÞID  
 | 
#    BYTE        EquipIndex;    //ÉñÊÞ×°±¸ËùÔÚÉñÊÞ±³°üË÷Òý  
 | 
#};  
 | 
def OnDogzEquipItem(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
    dogzID = clientData.DogzID  
 | 
    equipIndex = clientData.EquipIndex  
 | 
      
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("Dogz", dogzID)  
 | 
    if not ipyData:  
 | 
        return  
 | 
      
 | 
    dogzItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)  
 | 
    curEquip = dogzItemPack.GetAt(equipIndex)  
 | 
    if not ItemCommon.CheckItemCanUse(curEquip):  
 | 
        GameWorld.DebugLog("ÎïÆ·²»¿ÉÓÃ: equipIndex=%s" % equipIndex)  
 | 
        return  
 | 
    if not ItemCommon.GetIsDogzEquip(curEquip):  
 | 
        GameWorld.DebugLog("·ÇÉñÊÞ×°±¸: equipIndex=%s" % equipIndex)  
 | 
        return  
 | 
      
 | 
    equipPlace = curEquip.GetEquipPlace()  
 | 
    equipPlaceIndex = GetDogzEquipPlaceIndex(equipPlace)  
 | 
    equipPlaceColorList = ipyData.GetEquipPlaceColorList()  
 | 
    if equipPlaceIndex < 0 or equipPlaceIndex >= len(equipPlaceColorList):  
 | 
        GameWorld.ErrLog("ÉñÊÞ×°±¸Î»Òì³£: equipPlace=%s,equipPlaceIndex=%s" % (equipPlace, equipPlaceIndex))  
 | 
        return  
 | 
      
 | 
    dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)  
 | 
    equipPackIndex = GetDogzEquipPackIndex(dogzID, equipPlaceIndex)  
 | 
    if equipPackIndex < 0 or equipPackIndex >= dogzEquipPack.GetCount():  
 | 
        GameWorld.ErrLog("ÉñÊÞ×°±¸±³°üË÷ÒýÒì³£: dogzID=%s,equipPlace=%s,equipPackIndex=%s" % (dogzID, equipPlace, equipPackIndex))  
 | 
        return  
 | 
      
 | 
    equipColor = curEquip.GetItemColor()  
 | 
    limitColor = equipPlaceColorList[equipPlaceIndex]  
 | 
    if equipColor < limitColor:  
 | 
        GameWorld.Log("ÉñÊÞ×°±¸Î»´©´÷ÑÕÉ«ÏÞÖÆ£ºdogzID=%s,equipPlaceIndex=%s,limitColor=%s > equipColor=%s"   
 | 
                      % (dogzID, equipPlaceIndex, limitColor, equipColor), playerID)  
 | 
        return  
 | 
      
 | 
    destEquip = dogzEquipPack.GetAt(equipPackIndex)  
 | 
    isOK = ItemCommon.DoLogicSwitchItem(curPlayer, curEquip, destEquip, ShareDefine.rptDogzEquip)  
 | 
    if not isOK:  
 | 
        return  
 | 
      
 | 
    # Öúս״̬»»×°ÐèҪˢÊôÐÔ  
 | 
    if GetDogzIsHelpFight(curPlayer, dogzID):  
 | 
        RefreshDogzAttr(curPlayer)  
 | 
          
 | 
    return  
 | 
  
 | 
  
 | 
#// A5 C1 ÉñÊÞжÏÂ×°±¸ #tagCMDogzUnEquipItem  
 | 
#  
 | 
#struct    tagCMDogzUnEquipItem  
 | 
#  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#    BYTE        DogzID;    // ÉñÊÞID  
 | 
#    BYTE        EquipPlace;    //жϵÄ×°±¸Î», 0´ú±íжÏÂÈ«²¿  
 | 
#};  
 | 
def OnDogzUnEquipItem(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
    dogzID = clientData.DogzID  
 | 
    equipPlace = clientData.EquipPlace  
 | 
      
 | 
    if equipPlace and equipPlace not in ShareDefine.DogzEquipPlace:  
 | 
        GameWorld.DebugLog("·ÇÉñÊÞ×°±¸Î»£¬ÎÞ·¨Ð¶ÏÂ!equipPlace=%s" % equipPlace, playerID)  
 | 
        return  
 | 
      
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("Dogz", dogzID)  
 | 
    if not ipyData:  
 | 
        return  
 | 
      
 | 
    # Ð¶ÏÂÈ«²¿  
 | 
    if equipPlace == 0:  
 | 
        unEquipIndexList = [] # ÐèÒªÍÑϵÄÉñÊÞ×°±¸Ë÷Òý  
 | 
        dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)  
 | 
        equipPackCount = dogzEquipPack.GetCount()  
 | 
        startIndex = (dogzID - 1) * DogzEquipCount  
 | 
        for i in range(startIndex, startIndex + DogzEquipCount):  
 | 
            if i < 0 or i >= equipPackCount:  
 | 
                return  
 | 
            curItem = dogzEquipPack.GetAt(i)              
 | 
            if not curItem.IsEmpty():  
 | 
                unEquipIndexList.append(i)  
 | 
                  
 | 
        if not unEquipIndexList:  
 | 
            GameWorld.DebugLog("ûÓд©´÷ÉñÊÞ×°±¸!dogzID=%s" % dogzID, playerID)  
 | 
            return  
 | 
          
 | 
        unEquipCount = len(unEquipIndexList)  
 | 
        emptyIndexList = []  
 | 
          
 | 
        dogzItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)  
 | 
        for i in xrange(dogzItemPack.GetCount()):  
 | 
            curItem = dogzItemPack.GetAt(i)  
 | 
            if curItem.IsEmpty():  
 | 
                emptyIndexList.append(i)  
 | 
                if len(emptyIndexList) >= unEquipCount:  
 | 
                    break  
 | 
                  
 | 
        if len(emptyIndexList) < unEquipCount:  
 | 
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [ShareDefine.rptDogzItem])  
 | 
            #GameWorld.DebugLog("ÉñÊÞ±³°ü¿Õ¸ñ²»×㣬ÎÞ·¨ÍÑÏÂËùÓÐ×°±¸")  
 | 
            return  
 | 
          
 | 
        for i in xrange(unEquipCount):  
 | 
            ItemCommon.DoLogicSwitchItemEx(curPlayer, ShareDefine.rptDogzEquip, ShareDefine.rptDogzItem,  
 | 
                                           unEquipIndexList[i], emptyIndexList[i])  
 | 
              
 | 
    else:  
 | 
        equipPackIndex = GetDogzEquipPackIndex(dogzID, GetDogzEquipPlaceIndex(equipPlace))  
 | 
        emptyIndex = ItemCommon.GetEmptyIndexInPack(curPlayer, ShareDefine.rptDogzItem)  
 | 
          
 | 
        if not ItemCommon.DoLogicSwitchItemEx(curPlayer, ShareDefine.rptDogzEquip, ShareDefine.rptDogzItem, equipPackIndex, emptyIndex):  
 | 
            GameWorld.DebugLog("ÉñÊÞжÏÂ×°±¸Ê§°Ü: dogzID=%s,equipPlace=%s" % (dogzID, equipPlace), playerID)  
 | 
            return  
 | 
      
 | 
    # Öúս״̬»»×°ÐèҪˢÊôÐÔ  
 | 
    if GetDogzIsHelpFight(curPlayer, dogzID):  
 | 
        SetDogzIsHelpFight(curPlayer, dogzID, False) # ÒòΪÍÑÏÂÁË״̬£¬ËùÒÔ±ØÐëÉèÖÃΪ·ÇÖúս״̬  
 | 
        RefreshDogzAttr(curPlayer)  
 | 
          
 | 
    return  
 | 
  
 | 
  
 | 
#// A5 C2 ÉñÊÞ±ä¸üÖúս״̬ #tagCMDogzBattleStateChange  
 | 
#  
 | 
#struct    tagCMDogzBattleStateChange  
 | 
#  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#    BYTE        DogzID;    // ÉñÊÞID  
 | 
#    BYTE        BatteState;    //Öúս״̬£¬0-Õٻأ¬1-ÖúÕ½  
 | 
#};  
 | 
def OnDogzBattleStateChange(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
    dogzID = clientData.DogzID  
 | 
    batteState = clientData.BatteState  
 | 
      
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("Dogz", dogzID)  
 | 
    if not ipyData:  
 | 
        return  
 | 
      
 | 
    curState = GetDogzIsHelpFight(curPlayer, dogzID)  
 | 
    if curState == batteState:  
 | 
        GameWorld.DebugLog("ÉñÊÞÒѾÊǸÃ״̬£¬ÎÞÐè±ä¸üÖúս״̬! dogzID=%s,batteState=%s,curState=%s"   
 | 
                           % (dogzID, batteState, curState), playerID)  
 | 
        return  
 | 
      
 | 
    # ±äΪÖúս״̬Ðè¼ì²éÉñÊÞ×°±¸ÊÇ·ñ´©Âú  
 | 
    if batteState:  
 | 
        helpbattleInitCount = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 1)[0]  
 | 
        helpbattleBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount)  
 | 
        canHelpFightCount = helpbattleInitCount + helpbattleBuyCount  
 | 
          
 | 
        curHelpFightCount = 0  
 | 
        dogzCount = IpyGameDataPY.IPY_Data().GetDogzCount()  
 | 
        for i in xrange(dogzCount):  
 | 
            if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, i):  
 | 
                curHelpFightCount += 1  
 | 
                  
 | 
        if curHelpFightCount >= canHelpFightCount:  
 | 
            GameWorld.DebugLog("µ±Ç°ÉñÊÞÖúÕ½ÊýÒÑÂú£¬ÎÞ·¨ÖúÕ½!canHelpFightCount=%s <= curHelpFightCount=%s"   
 | 
                               % (canHelpFightCount, curHelpFightCount), playerID)  
 | 
            return  
 | 
          
 | 
        dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)  
 | 
        equipPackCount = dogzEquipPack.GetCount()  
 | 
        startIndex = (dogzID - 1) * DogzEquipCount  
 | 
        for i in range(startIndex, startIndex + DogzEquipCount):  
 | 
            if i < 0 or i >= equipPackCount:  
 | 
                return  
 | 
            curItem = dogzEquipPack.GetAt(i)              
 | 
            if curItem.IsEmpty():  
 | 
                GameWorld.DebugLog("ÉñÊÞÓÐ×°±¸Î´´©´÷£¬ÎÞ·¨ÖúÕ½£¡dogzID=%s,packIndex=%s" % (dogzID, i), playerID)  
 | 
                return  
 | 
              
 | 
    isFight = True if batteState else False  
 | 
    GameWorld.DebugLog("ÉñÊÞÖúս״̬±ä¸ü£¡dogzID=%s,isFight=%s" % (dogzID, isFight), playerID)  
 | 
    SetDogzIsHelpFight(curPlayer, dogzID, isFight)  
 | 
    RefreshDogzAttr(curPlayer)  
 | 
    return  
 | 
  
 | 
  
 | 
#// A5 C3 ÉñÊÞ¹ºÂòÖúսλ #tagCMDogzBuyBatteCount  
 | 
#  
 | 
#struct    tagCMDogzBuyBatteCount  
 | 
#  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#};  
 | 
def OnDogzBuyBatteCount(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
      
 | 
    helpbattleInitCount, helpbattleMaxCount = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 1)  
 | 
    helpbattleBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount)  
 | 
    curHelpFightCount = helpbattleInitCount + helpbattleBuyCount  
 | 
    if curHelpFightCount >= helpbattleMaxCount:  
 | 
        GameWorld.DebugLog("Òѳ¬¹ý×î´óÉñÊÞÖúÕ½Êý£¬ÎÞ·¨¹ºÂò£¡curHelpFightCount=%s,helpbattleMaxCount=%s"   
 | 
                           % (curHelpFightCount, helpbattleMaxCount), playerID)  
 | 
        return  
 | 
      
 | 
    needItemID = IpyGameDataPY.GetFuncCfg("DogzAssist", 2)  
 | 
    needCountList = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 3)  
 | 
    needCount = needCountList[-1] if helpbattleBuyCount >= len(needCountList) else needCountList[helpbattleBuyCount]  
 | 
      
 | 
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, needItemID)  
 | 
    if bindCnt + unBindCnt < needCount:  
 | 
        GameWorld.DebugLog("¹ºÂòÉñÊÞÖúսλËùÐèµÀ¾ß²»×ã !needItemID=%s,needCount=%s" % (needItemID, needCount), playerID)  
 | 
        return  
 | 
    ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, needCount, "DogzBuyHelpFight")  
 | 
      
 | 
    updBuyCount = helpbattleBuyCount + 1  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DogzBuyHelpbattleCount, updBuyCount)  
 | 
    GameWorld.DebugLog("¹ºÂòÉñÊÞÖúսλ! updBuyCount=%s" % updBuyCount, playerID)  
 | 
      
 | 
    Sync_DogzInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
  
 | 
#// A5 C4 ÉñÊÞ×°±¸Ç¿»¯ #tagCMDogzEquipPlus  
 | 
#  
 | 
#struct    tagCMDogzEquipPlus  
 | 
#  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#    BYTE        EquipIndex;    //ÉñÊÞ×°±¸±³°üÖÐË÷Òý  
 | 
#    BYTE        IndexCount;        //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷ÒýµÄÊýÁ¿  
 | 
#    BYTE        IndexList[IndexCount];    //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷ÒýÁÐ±í  
 | 
#    BYTE        IsDouble;        //ÊÇ·ñË«±¶Ç¿»¯  
 | 
#};  
 | 
def OnDogzEquipPlus(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
    equipIndex = clientData.EquipIndex  
 | 
    indexList = clientData.IndexList  
 | 
    isDouble = clientData.IsDouble  
 | 
    GameWorld.DebugLog("ÉñÊÞ×°±¸Ç¿»¯: equipIndex=%s,indexList=%s,isDouble=%s" % (equipIndex, indexList, isDouble), playerID)  
 | 
      
 | 
    dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)  
 | 
    curEquip = dogzEquipPack.GetAt(equipIndex)  
 | 
    if not ItemCommon.CheckItemCanUse(curEquip) or not ItemCommon.GetIsDogzEquip(curEquip):  
 | 
        GameWorld.DebugLog("    ·ÇÉñÊÞ×°±¸£¬ÎÞ·¨Ç¿»¯£¡equipIndex=%s,itemID=%s"   
 | 
                           % (equipIndex, curEquip.GetItemTypeID()), playerID)  
 | 
        return  
 | 
      
 | 
    equipColor = curEquip.GetItemColor()  
 | 
    colorPlusMaxLVDict = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 4) # {ÑÕÉ«:µÈ¼¶ÉÏÏÞ, ...}  
 | 
    if equipColor not in colorPlusMaxLVDict:  
 | 
        return  
 | 
    maxPlusLV = colorPlusMaxLVDict[equipColor]  
 | 
      
 | 
    equipPlace = curEquip.GetEquipPlace()  
 | 
    curPlusLV = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)  
 | 
    curPlusExpTotal = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 1)  
 | 
    if curPlusLV >= maxPlusLV:  
 | 
        GameWorld.Log("ÉñÊÞ×°±¸ÒÑÂú¼¶, ÎÞ·¨Ç¿»¯£¡equipColor=%s,curPlusLV=%s,maxPlusLV=%s" % (equipColor, curPlusLV, maxPlusLV), playerID)  
 | 
        return  
 | 
      
 | 
    ipyData = IpyGameDataPY.GetIpyGameData("DogzEquipPlus", equipPlace, curPlusLV)  
 | 
    if not ipyData:  
 | 
        return  
 | 
    lvUPTotalExp = ipyData.GetPlusLVUPTotalExp()  
 | 
    if not lvUPTotalExp:  
 | 
        GameWorld.Log("ÉñÊÞ×°±¸Éý¼¶ËùÐè×ܾÑéΪ0, ÎÞ·¨Ç¿»¯£¡equipPlace=%s,curPlusLV=%s" % (equipPlace, curPlusLV), playerID)  
 | 
        return  
 | 
          
 | 
    costGoldTotal = 0  
 | 
    addExpTotal = 0  
 | 
    delItemList = []  
 | 
    dogzItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)  
 | 
    dogzItemPackCount = dogzItemPack.GetCount()  
 | 
    for i in indexList:  
 | 
        if i < 0 or i >= dogzItemPackCount:  
 | 
            GameWorld.ErrLog("ÉñÊÞ±³°üË÷Òý²»´æÔÚ£¬ÎÞ·¨Ç¿»¯£¡i=%s" % (i), playerID)  
 | 
            return  
 | 
        curItem = dogzItemPack.GetAt(i)  
 | 
        if curItem.IsEmpty():  
 | 
            GameWorld.ErrLog("ÉñÊÞ±³°üÎïÆ·Îª¿Õ£¬ÎÞ·¨Ç¿»¯£¡i=%s" % (i), playerID)  
 | 
            return  
 | 
        effect = ItemCommon.GetItemEffectByEffectID(curItem, ChConfig.Def_Effect_DogzEquipPlusExp)  
 | 
        if not effect:  
 | 
            GameWorld.ErrLog("ÉñÊÞ±³°üÎïÆ·ÎÞ¾ÑéЧ¹û£¬ÎÞ·¨Ç¿»¯£¡i=%s,itemID=%s" % (i, curItem.GetItemTypeID()), playerID)  
 | 
            return  
 | 
          
 | 
        baseExp = effect.GetEffectValue(0)  
 | 
        doubleCostGold = effect.GetEffectValue(1)  
 | 
          
 | 
        addExp = baseExp  
 | 
        plusInfoCount = curItem.GetUserAttrCount(ShareDefine.Def_IudetDogzEquipPlus)  
 | 
        if not plusInfoCount:  
 | 
            if isDouble and doubleCostGold:  
 | 
                addExp = (baseExp * 2)  
 | 
                costGoldTotal += doubleCostGold  
 | 
            GameWorld.DebugLog("    Ç¿»¯: addExp=%s,baseExp=%s,isDouble=%s,doubleCostGold=%s,costGoldTotal=%s"   
 | 
                               % (addExp, baseExp, isDouble, doubleCostGold, costGoldTotal), playerID)  
 | 
        else:  
 | 
            #plusLV = curItem.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)  
 | 
            plusExpTotal = curItem.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 1)  
 | 
            addExp += plusExpTotal  
 | 
            GameWorld.DebugLog("    Ç¿»¯: addExp=%s,baseExp=%s,plusExpTotal=%s" % (addExp, baseExp, plusExpTotal), playerID)  
 | 
        addExpTotal += addExp  
 | 
        delItemList.append(curItem)  
 | 
          
 | 
    if not delItemList:  
 | 
        GameWorld.DebugLog("    Ã»ÓвÄÁÏ¿ÉÇ¿»¯£¡", playerID)  
 | 
        return  
 | 
      
 | 
    updPlusExpTotal = curPlusExpTotal + addExpTotal  
 | 
    infoDict = {"updPlusExpTotal":updPlusExpTotal}  
 | 
      
 | 
    if costGoldTotal:  
 | 
        if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, costGoldTotal,   
 | 
                                      ChConfig.Def_Cost_DogzEquipPlus, infoDict):  
 | 
            return  
 | 
          
 | 
    for delItem in delItemList:  
 | 
        ItemCommon.DelItem(curPlayer, delItem, curItem.GetCount(), False, ChConfig.ItemDel_DogzEquipPlus, infoDict)  
 | 
          
 | 
    updPlusLV = curPlusLV  
 | 
    doCount, maxDoCount = 0, maxPlusLV * 2  
 | 
    while updPlusExpTotal >= lvUPTotalExp and updPlusLV < maxPlusLV and doCount < maxDoCount:  
 | 
        doCount += 1  
 | 
        nextLV = updPlusLV + 1  
 | 
        nextLVIpyData = IpyGameDataPY.GetIpyGameDataNotLog("DogzEquipPlus", equipPlace, nextLV)  
 | 
        if not nextLVIpyData:  
 | 
            GameWorld.DebugLog("    Ã»ÓÐÏÂÒ»¼¶Êý¾Ý£¬²»ÄÜÉý¼¶£¡nextLV=%s" % (nextLV), playerID)  
 | 
            break  
 | 
        updPlusLV = nextLV  
 | 
        lvUPTotalExp = nextLVIpyData.GetPlusLVUPTotalExp()  
 | 
        GameWorld.DebugLog("    Éý¼¶: equipPlace=%s,maxPlusLV=%s,updPlusLV=%s,updPlusExpTotal=%s,lvUPTotalExp=%s"   
 | 
                           % (equipPlace, maxPlusLV, updPlusLV, updPlusExpTotal, lvUPTotalExp), playerID)  
 | 
          
 | 
    isRefreshAtrr = False  
 | 
    # Î´Ç¿»¯¹ý  
 | 
    if not curPlusExpTotal:  
 | 
        curEquip.AddUserAttr(ShareDefine.Def_IudetDogzEquipPlus, updPlusLV)  
 | 
        curEquip.AddUserAttr(ShareDefine.Def_IudetDogzEquipPlus, updPlusExpTotal)  
 | 
        isRefreshAtrr = (updPlusLV > 0)  
 | 
    else:  
 | 
        if curPlusLV != updPlusLV:  
 | 
            isRefreshAtrr = True  
 | 
            curEquip.UpdataUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0, updPlusLV)  
 | 
        curEquip.UpdataUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 1, updPlusExpTotal)  
 | 
          
 | 
    GameWorld.DebugLog("    curPlus(LV=%s,EXP=%s),addExpTotal=%s,updPlus(LV=%s,EXP=%s)"   
 | 
                       % (curPlusLV, curPlusExpTotal, addExpTotal, updPlusLV, updPlusExpTotal), playerID)  
 | 
      
 | 
    if isRefreshAtrr:  
 | 
        RefreshDogzAttr(curPlayer)  
 | 
          
 | 
    return  
 | 
  
 | 
def GetDogzEquipPlusLVExpInfo(equipColor, equipPlace, totalExp):  
 | 
    ## »ñÈ¡µ±Ç°ÉñÊÞ×°±¸×î¸ßÇ¿»¯µÈ¼¶µÄÇ¿»¯ÊìÁ·¶È  
 | 
    retLV, retExp = 0, 0  
 | 
    colorPlusMaxLVDict = IpyGameDataPY.GetFuncEvalCfg("DogzAssist", 4) # {ÑÕÉ«:µÈ¼¶ÉÏÏÞ, ...}  
 | 
    if equipColor not in colorPlusMaxLVDict:  
 | 
        return retLV, retExp  
 | 
    maxPlusLV = colorPlusMaxLVDict[equipColor]  
 | 
    for lv in xrange(maxPlusLV + 1):  
 | 
        ipyData = IpyGameDataPY.GetIpyGameDataNotLog("DogzEquipPlus", equipPlace, lv)  
 | 
        if lv and not ipyData:  
 | 
            break  
 | 
          
 | 
        lvUPTotalExp = ipyData.GetPlusLVUPTotalExp()  
 | 
        if not lvUPTotalExp:  
 | 
            break  
 | 
          
 | 
        if totalExp < lvUPTotalExp:  
 | 
            return lv, totalExp  
 | 
        retLV, retExp = lv, lvUPTotalExp  
 | 
          
 | 
    return retLV, retExp  
 | 
  
 | 
def RefreshDogzAttr(curPlayer):  
 | 
    ## Ë¢ÐÂÉñÊÞÊôÐÔ  
 | 
      
 | 
    allAttrList = [{} for _ in range(4)]  
 | 
      
 | 
    dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)  
 | 
    equipPackCount = dogzEquipPack.GetCount()  
 | 
    ipyDataMgr = IpyGameDataPY.IPY_Data()  
 | 
    for dogzIndex in xrange(ipyDataMgr.GetDogzCount()):  
 | 
        if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, dogzIndex):  
 | 
            continue  
 | 
          
 | 
        ipyData = ipyDataMgr.GetDogzByIndex(dogzIndex)  
 | 
        dogzID = ipyData.GetDogzID()  
 | 
        #GameWorld.DebugLog("ÉñÊÞÊôÐÔ: dogzID=%s" % dogzID)  
 | 
          
 | 
        # 1. »ù´¡ÊôÐÔ  
 | 
        attrTypeList = ipyData.GetBaseAttrTypes()  
 | 
        attrValueList = ipyData.GetBaseAttrValues()  
 | 
        if attrTypeList and len(attrTypeList) == len(attrValueList):  
 | 
            for attrIndex, baseAttrID in enumerate(attrTypeList):  
 | 
                baseAttrValue = attrValueList[attrIndex]  
 | 
                PlayerControl.CalcAttrDict_Type(baseAttrID, baseAttrValue, allAttrList)  
 | 
                #GameWorld.DebugLog("    »ù´¡ÊôÐÔ: baseAttrID=%s,baseAttrValue=%s, %s" % (baseAttrID, baseAttrValue, allAttrList))  
 | 
                  
 | 
        # 2. ×°±¸ÊôÐÔ  
 | 
        startIndex = (dogzID - 1) * DogzEquipCount  
 | 
        for equipIndex in range(startIndex, startIndex + DogzEquipCount):  
 | 
            if equipIndex < 0 or equipIndex >= equipPackCount:  
 | 
                break  
 | 
            curEquip = dogzEquipPack.GetAt(equipIndex)              
 | 
            if curEquip.IsEmpty():  
 | 
                continue  
 | 
              
 | 
            #itemID = curEquip.GetItemTypeID()  
 | 
            # ×°±¸»ù´¡ÊôÐÔ  
 | 
            for effIndex in xrange(curEquip.GetEffectCount()):  
 | 
                curEffect = curEquip.GetEffectByIndex(effIndex)  
 | 
                if not curEffect or not curEffect.GetEffectID():  
 | 
                    break  
 | 
                effID = curEffect.GetEffectID()  
 | 
                if not effID or effID == ChConfig.Def_Effect_DogzEquipPlusExp:  
 | 
                    continue  
 | 
                effValue = curEffect.GetEffectValue(0)  
 | 
                PlayerControl.CalcAttrDict_Type(effID, effValue, allAttrList)  
 | 
                #GameWorld.DebugLog("    ×°±¸»ù´¡: itemID=%s,effID=%s,effValue=%s, %s" % (itemID, effID, effValue, allAttrList))  
 | 
                  
 | 
            # Ç¿»¯ÊôÐÔ  
 | 
            curPlusLV = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)  
 | 
            plusIpyData = IpyGameDataPY.GetIpyGameData("DogzEquipPlus", curEquip.GetEquipPlace(), curPlusLV)  
 | 
            if plusIpyData:  
 | 
                plusAttrTypeList = plusIpyData.GetPlusAttrTypes()  
 | 
                plusAttrValueList = plusIpyData.GetPlusAttrValues()  
 | 
                if plusAttrTypeList and len(plusAttrTypeList) == len(plusAttrValueList):  
 | 
                    for plusIndex, plusAttrID in enumerate(plusAttrTypeList):  
 | 
                        plusAttrValue = plusAttrValueList[plusIndex]  
 | 
                        PlayerControl.CalcAttrDict_Type(plusAttrID, plusAttrValue, allAttrList)  
 | 
                        #GameWorld.DebugLog("    ×°±¸Ç¿»¯: itemID=%s,plusAttrID=%s, plusAttrValue=%s, %s" % (itemID, plusAttrID, plusAttrValue, allAttrList))  
 | 
                          
 | 
            # ´«ÆæÊôÐÔ  
 | 
            ChEquip.CalcAttr_LegendAttr(curPlayer, curEquip, allAttrList)  
 | 
            #GameWorld.DebugLog("    ×°±¸´«Ææ: itemID=%s,%s" % (itemID, allAttrList))  
 | 
              
 | 
    # ±£´æ¼ÆËãÖµ  
 | 
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Dogz, allAttrList)  
 | 
    return  
 | 
  
 | 
def Sync_DogzInfo(curPlayer):  
 | 
    ## Í¬²½ÉñÊÞÐÅÏ¢  
 | 
    dogzInfoPack = ChPyNetSendPack.tagMCDogzInfo()  
 | 
    dogzInfoPack.BuyHelpbattleCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DogzBuyHelpbattleCount)  
 | 
    NetPackCommon.SendFakePack(curPlayer, dogzInfoPack)  
 | 
    return  
 | 
  
 | 
def Sync_DogzHelpbattleState(curPlayer, dogzID, batteState):  
 | 
    ## Í¬²½ÉñÊÞÖúս״̬  
 | 
    helpbattleState = ChPyNetSendPack.tagMCDogzHelpbattleState()  
 | 
    helpbattleState.DogzID = dogzID  
 | 
    helpbattleState.BatteState = 1 if batteState else 0  
 | 
    NetPackCommon.SendFakePack(curPlayer, helpbattleState)  
 | 
    return  
 | 
  
 |