| #!/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  | 
| import PassiveBuffEffMng  | 
| import SkillCommon  | 
| import SkillShell  | 
| import PlayerSuccess  | 
| import DataRecordPack  | 
| import PlayerWeekParty  | 
| import ItemControler  | 
|   | 
| import time  | 
|   | 
| '''  | 
| ÉñÊÞ±àºÅ: 1~20£¬ÉÏÏߺ󲻿ÉÐÞ¸Ä  | 
| ÉñÊÞ×°±¸Î»: 101~105 ÎïÆ·±íÖеÄ×°±¸Î»ÅäÖà  | 
| ÉñÊÞ×°±¸ÀàÐÍ£º119~123£¬²ß»®Ëµ´òËÀ²»»áÔÙ¼ÓÀàÐÍÁË£¬¹Ì¶¨5¸öÉñÊÞ×°±¸ÀàÐÍ  | 
|   | 
| ÉñÊÞÎïÆ·±³°ü£¨ÀàÐÍ32,ÔÝ¿ª·Å100¸ñ£©£¬´æ·ÅÉñÊÞ×°±¸(ÀàÐÍ119~123)£¬¼°Ç¿»¯²ÄÁÏ£¨ÀàÐÍ70£©£¬  | 
| ÉñÊÞ×°±¸±³°ü£¨ÀàÐÍ33,ÔÝ¿ª·Å100¸ñ£©£¬ËùÓÐÉñÊÞ¹²Óã¬Ã¿Ö»ÉñÊÞ5¸ñ£¬(¸ñ×ÓË÷Òý/5)+1=¶ÔÓ¦ÉñÊÞ±àºÅ£¬(¸ñ×ÓË÷Òý%5)+100+1=¶ÔÓ¦ÉñÊÞ×°±¸Î»  | 
| '''  | 
|   | 
| DogzEquipCount = 5 # ÉñÊÞ×°±¸Î»ÊýÁ¿£¬¹Ì¶¨5¸ö£¬²ß»®Ëµ´òËÀÒ²²»¸Ä  | 
|   | 
| g_helpBattleNotifyTimeDict = {} # ÖúÕ½¹ã²¥Ê±¼ä¼Ç¼ {ÉñÊÞID:¹ã²¥time, ...}  | 
|   | 
| 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)  | 
|       | 
|     # ÉèÖóɹ¦ºó²ÅÄÜË¢¼¼ÄÜ  | 
|     PassiveBuffEffMng.PlayerDogzSkill(curPlayer)  | 
|     if not isFight:  | 
|         DataRecordPack.Cache_FightPowerChangeInfo(curPlayer, ChConfig.PowerDownType_Dogz, {'dogzID':dogzID})  | 
|     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        EquipIndexCount;  | 
| #    BYTE        EquipIndexList[EquipIndexCount];    //ÉñÊÞ×°±¸ËùÔÚÉñÊÞ±³°üË÷ÒýÁÐ±í  | 
| #};  | 
| def OnDogzEquipItem(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     dogzID = clientData.DogzID  | 
|     equipIndexList = clientData.EquipIndexList  | 
|       | 
|     ipyData = IpyGameDataPY.GetIpyGameData("Dogz", dogzID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     GameWorld.DebugLog("ÉñÊÞ´©´÷×°±¸: dogzID=%s,equipIndexList=%s" % (dogzID, equipIndexList), playerID)  | 
|     if not equipIndexList:  | 
|         return  | 
|       | 
|     succIndexList = []  | 
|     for equipIndex in equipIndexList:  | 
|         dogzItemPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzItem)  | 
|         curEquip = dogzItemPack.GetAt(equipIndex)  | 
|         if not ItemCommon.CheckItemCanUse(curEquip):  | 
|             GameWorld.DebugLog("ÎïÆ·Îª¿Õ»ò²»¿ÉÓÃ: equipIndex=%s" % equipIndex, playerID)  | 
|             continue  | 
|         if not ItemCommon.GetIsDogzEquip(curEquip):  | 
|             GameWorld.DebugLog("·ÇÉñÊÞ×°±¸: equipIndex=%s" % equipIndex, playerID)  | 
|             continue  | 
|           | 
|         equipPlace = curEquip.GetEquipPlace()  | 
|         equipPlaceIndex = GetDogzEquipPlaceIndex(equipPlace)  | 
|         equipPlaceColorList = ipyData.GetEquipPlaceColorList()  | 
|         if equipPlaceIndex < 0 or equipPlaceIndex >= len(equipPlaceColorList):  | 
|             GameWorld.ErrLog("ÉñÊÞ×°±¸Î»Òì³£: equipIndex=%s,equipPlace=%s,equipPlaceIndex=%s"   | 
|                              % (equipIndex, equipPlace, equipPlaceIndex), playerID)  | 
|             continue  | 
|           | 
|         dogzEquipPack = curPlayer.GetItemManager().GetPack(ShareDefine.rptDogzEquip)  | 
|         equipPackIndex = GetDogzEquipPackIndex(dogzID, equipPlaceIndex)  | 
|         if equipPackIndex < 0 or equipPackIndex >= dogzEquipPack.GetCount():  | 
|             GameWorld.ErrLog("ÉñÊÞ×°±¸±³°üË÷ÒýÒì³£: dogzID=%s,equipIndex=%s,equipPlace=%s,equipPackIndex=%s"   | 
|                              % (dogzID, equipIndex, equipPlace, equipPackIndex), playerID)  | 
|             continue  | 
|           | 
|         equipColor = curEquip.GetItemColor()  | 
|         limitColor = equipPlaceColorList[equipPlaceIndex]  | 
|         if equipColor < limitColor:  | 
|             GameWorld.Log("ÉñÊÞ×°±¸Î»´©´÷ÑÕÉ«ÏÞÖÆ£ºdogzID=%s,equipIndex=%s,equipPlaceIndex=%s,limitColor=%s > equipColor=%s"   | 
|                           % (dogzID, equipIndex, equipPlaceIndex, limitColor, equipColor), playerID)  | 
|             continue  | 
|           | 
|         destEquip = dogzEquipPack.GetAt(equipPackIndex)  | 
|         desItemID, desUserData = [0, ''] if destEquip.IsEmpty() else [destEquip.GetItemTypeID(), destEquip.GetUserData()]  | 
|         srcItemID, srcUserData = curEquip.GetItemTypeID(), curEquip.GetUserData()  | 
|         if ItemCommon.DoLogicSwitchItem(curPlayer, curEquip, destEquip, ShareDefine.rptDogzEquip):  | 
|             succIndexList.append(equipIndex)  | 
|             dataDict = {'dotype':'EquipDogzItem', 'desItemID':desItemID, 'desUserData':desUserData,'srcItemID':srcItemID,'srcUserData':srcUserData}  | 
|             DataRecordPack.Cache_FightPowerChangeInfo(curPlayer, ChConfig.PowerDownType_EquipChange, dataDict)  | 
|       | 
|     GameWorld.DebugLog("    ´©´÷³É¹¦Ë÷ÒýÁбí: %s" % succIndexList, playerID)  | 
|     if not succIndexList:  | 
|         return  | 
|       | 
|     # Öúս״̬»»×°ÐèҪˢÊôÐÔ  | 
|     if GetDogzIsHelpFight(curPlayer, dogzID):  | 
|         RefreshDogzAttr(curPlayer, True)  | 
|         PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  | 
|     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, True)  | 
|         PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  | 
|           | 
|     return  | 
|   | 
|   | 
| #// A5 C2 ÉñÊÞ±ä¸üÖúս״̬ #tagCMDogzBattleStateChange  | 
| #  | 
| #struct    tagCMDogzBattleStateChange  | 
| #  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        DogzID;    // ÉñÊÞID  | 
| #    BYTE        BatteState;    //Öúս״̬£¬0-Õٻأ¬1-ÖúÕ½  | 
| #};  | 
| def OnDogzBattleStateChange(index, clientData, tick):  | 
|     global g_helpBattleNotifyTimeDict  | 
|       | 
|     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  | 
|         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_DogzBattle, 1, [dogzID])  | 
|         PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_Dogz, dogzID, False)  | 
|           | 
|     isFight = True if batteState else False  | 
|     GameWorld.DebugLog("ÉñÊÞÖúս״̬±ä¸ü£¡dogzID=%s,isFight=%s" % (dogzID, isFight), playerID)  | 
|     SetDogzIsHelpFight(curPlayer, dogzID, isFight)  | 
|     RefreshDogzAttr(curPlayer, True)  | 
|     PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  | 
|       | 
|     if isFight and ipyData.GetHelpBattleNotify():  | 
|         curTime = int(time.time())  | 
|         playerName = curPlayer.GetPlayerName()  | 
|         notifyKey, notifyParamList, notifyCD = ipyData.GetHelpBattleNotify()  | 
|         lastNotifyTime = g_helpBattleNotifyTimeDict.get(dogzID, 0)  | 
|         if curTime - lastNotifyTime >= notifyCD * 60:   | 
|             PlayerControl.WorldNotify(0, notifyKey, [playerName] + notifyParamList)  | 
|             g_helpBattleNotifyTimeDict[dogzID] = curTime  | 
|     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]  | 
|       | 
|     itemData = GameWorld.GetGameData().GetItemByTypeID(needItemID)  | 
|     if not itemData:  | 
|         return  | 
|       | 
|     packType = ChConfig.GetItemPackType(itemData)  | 
|     costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, needItemID, packType=packType)  | 
|     if bindCnt + unBindCnt < needCount:  | 
|         GameWorld.DebugLog("¹ºÂòÉñÊÞÖúսλËùÐèµÀ¾ß²»×ã !needItemID=%s,needCount=%s,packType=%s" % (needItemID, needCount, packType), playerID)  | 
|         return  | 
|     ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, needCount, "DogzBuyHelpFight", packType=packType)  | 
|       | 
|     updBuyCount = helpbattleBuyCount + 1  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DogzBuyHelpbattleCount, updBuyCount)  | 
|     GameWorld.DebugLog("¹ºÂòÉñÊÞÖúսλ! updBuyCount=%s" % updBuyCount, playerID)  | 
|       | 
|     Sync_DogzInfo(curPlayer)  | 
|     PlayerControl.WorldNotify(0, "DogzNumberUp", [curPlayer.GetPlayerName(), needItemID, curHelpFightCount + 1])  | 
|     return  | 
|   | 
|   | 
| #// A5 C4 ÉñÊÞ×°±¸Ç¿»¯ #tagCMDogzEquipPlus  | 
| #  | 
| #struct    tagCMDogzEquipPlus  | 
| #  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        EquipIndex;    //ÉñÊÞ×°±¸±³°üÖÐË÷Òý  | 
| #    BYTE        IndexCount;        //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷ÒýµÄÊýÁ¿  | 
| #    BYTE        IndexList[IndexCount];    //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷ÒýÁÐ±í  | 
| #    BYTE        IndexUseCountList[IndexCount];    //²ÄÁÏËùÔÚÉñÊÞÎïÆ·±³°üË÷Òý¶ÔӦʹÓøöÊýÁÐ±í  | 
| #    BYTE        IsDouble;        //ÊÇ·ñË«±¶Ç¿»¯  | 
| #};  | 
| def OnDogzEquipPlus(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     equipIndex = clientData.EquipIndex  | 
|     indexList = clientData.IndexList  | 
|     indexUseCountList = clientData.IndexUseCountList  | 
|     isDouble = clientData.IsDouble  | 
|     GameWorld.DebugLog("ÉñÊÞ×°±¸Ç¿»¯: equipIndex=%s,indexList=%s,indexUseCountList=%s,isDouble=%s"   | 
|                        % (equipIndex, indexList, indexUseCountList, isDouble), playerID)  | 
|       | 
|     if len(indexList) != len(indexUseCountList):  | 
|         GameWorld.DebugLog("    Ö¸¶¨ÏûºÄµÄ¸öÊýÊý¾Ý³¤¶È´íÎó£¡")  | 
|         return  | 
|       | 
|     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 listIndex, i in enumerate(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  | 
|           | 
|         delCount = max(1, min(curItem.GetCount(), indexUseCountList[listIndex]))  | 
|         baseExp = effect.GetEffectValue(0)  | 
|         doubleCostGold = effect.GetEffectValue(1)  | 
|           | 
|         addExp = baseExp * delCount  | 
|         plusInfoCount = curItem.GetUserAttrCount(ShareDefine.Def_IudetDogzEquipPlus)  | 
|         if not plusInfoCount:  | 
|             if isDouble and doubleCostGold:  | 
|                 addExp = (baseExp * 2 * delCount)  | 
|                 costGoldTotal += doubleCostGold * delCount  | 
|             GameWorld.DebugLog("    Ç¿»¯: addExp=%s,delCount=%s,baseExp=%s,isDouble=%s,doubleCostGold=%s,costGoldTotal=%s"   | 
|                                % (addExp, delCount, 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,delCount=%s,baseExp=%s,plusExpTotal=%s" % (addExp, delCount, baseExp, plusExpTotal), playerID)  | 
|         addExpTotal += addExp  | 
|         delItemList.append([curItem, delCount])  | 
|           | 
|     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, delCount in delItemList:  | 
|         ItemCommon.DelItem(curPlayer, delItem, delCount, 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, True)  | 
|         PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  | 
|           | 
|     curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitDogzEquipPlus, 1)  | 
|     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, isUpdateSucc=False):  | 
|     ## Ë¢ÐÂÉñÊÞÊôÐÔ  | 
|     totalPlusLv = 0 #³öÕ½ÉñÊÞ×°±¸×ÜÇ¿»¯µÈ¼¶  | 
|     fightPowerEx = 0  | 
|     allAttrList = [{} for _ in range(4)]  | 
|     allAttrListEquip = [{} for _ in range(4)]  | 
|     allAttrListEquipPlus = [{} for _ in range(4)]  | 
|     equipScoreTotal = 0 #Ϊ½â¾ö×°±¸ÆÀ·Ö¡¢Õ½Á¦²»Ò»ÖµÄÇé¿ö£¬×°±¸Õ½Á¦¸ÄΪÓÉÆÀ·Ö×÷Ϊ²ÎÊý¼ÆËãÕ½Á¦  | 
|       | 
|     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  | 
|               | 
|             equipScoreTotal += ItemCommon.GetEquipGearScore(curEquip)  | 
|               | 
|             #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, allAttrListEquip)  | 
|                 #GameWorld.DebugLog("    ×°±¸»ù´¡: itemID=%s,effID=%s,effValue=%s, %s" % (itemID, effID, effValue, allAttrListEquip))  | 
|                   | 
|             # Ç¿»¯ÊôÐÔ  | 
|             curPlusLV = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)  | 
|             totalPlusLv += curPlusLV  | 
|             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, allAttrListEquipPlus)  | 
|                         #GameWorld.DebugLog("    ×°±¸Ç¿»¯: itemID=%s,plusAttrID=%s, plusAttrValue=%s, %s" % (itemID, plusAttrID, plusAttrValue, allAttrListEquipPlus))  | 
|                           | 
|             # ´«ÆæÊôÐÔ  | 
|             ChEquip.CalcAttr_LegendAttr(curPlayer, curEquip, allAttrListEquip)  | 
|             #GameWorld.DebugLog("    ×°±¸´«Ææ: itemID=%s,%s" % (itemID, allAttrListEquip))  | 
|               | 
|         # ¸½¼ÓÕ½Á¦  | 
|         fightPowerEx += ipyData.GetFightPowerEx()  | 
|           | 
|     # ±£´æ¼ÆËãÖµ  | 
|     PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_Dogz, allAttrList)  | 
|     PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_DogzEquip, allAttrListEquip)  | 
|     PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_DogzEquipPlus, allAttrListEquipPlus)  | 
|       | 
|     #¼ÆËã×°±¸»ù´¡ÊôÐÔ¸½¼ÓÕ½Á¦ (Ŀǰ×é³É: ÆÀ·ÖÕ½Á¦ + ...)  | 
|     equipFightPowerEx = eval(IpyGameDataPY.GetFuncCompileCfg("FightpowerFormula", 2))  | 
|     #GameWorld.DebugLog("ÉñÊÞ×°±¸ÆÀ·ÖÕ½Á¦: equipScoreTotal=%s,equipFightPowerEx=%s" % (equipScoreTotal, equipFightPowerEx))  | 
|     fightPowerEx += equipFightPowerEx  | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_MFPEx % ShareDefine.Def_MFPType_Dogz, fightPowerEx)  | 
|       | 
|     # ¼¼ÄÜÊôÐÔ£¬´ÓDef_CalcAttrFunc_Dogz»ñÈ¡  | 
|     skillAttrList = CalcDogzBattleSkillAttr(curPlayer)  | 
|     PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_DogzBattleSkill, skillAttrList)  | 
|     #³É¾Í  | 
|     if isUpdateSucc:  | 
|         PlayerSuccess.ResetSuccessByType(curPlayer, ShareDefine.SuccType_DogzEquipPlus)  | 
|         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_DogzEquipPlus, totalPlusLv)  | 
|     return  | 
|   | 
| def GetFightDogzTotalPlusLv(curPlayer):  | 
|     #³öÕ½µÄÉñÊÞ×°±¸×ÜÇ¿»¯µÈ¼¶  | 
|     totalPlusLv = 0  | 
|     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()  | 
|         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  | 
|             curPlusLV = curEquip.GetUserAttrByIndex(ShareDefine.Def_IudetDogzEquipPlus, 0)  | 
|             totalPlusLv += curPlusLV  | 
|     return totalPlusLv  | 
|   | 
| # ÖúÕ½ÉñÊÞ¼¼ÄÜÊôÐÔ£¬±ØÐëÔÚ SetDogzIsHelpFightºóµ÷Óà  | 
| def CalcDogzBattleSkillAttr(curPlayer):  | 
|     skillAttrList = [{} for _ in range(4)]  | 
|     skillManager = curPlayer.GetSkillManager()  | 
|   | 
|     for i in range(0 , skillManager.GetSkillCount()):  | 
|         curSkill = skillManager.GetSkillByIndex(i)  | 
|         if not curSkill:  | 
|             continue  | 
|           | 
|         if curSkill.GetFuncType() != ChConfig.Def_SkillFuncType_Dogz:  | 
|             continue  | 
|           | 
|         if not SkillCommon.isPassiveAttr(curSkill):  | 
|             continue  | 
|           | 
|           | 
|         for effectIndex in xrange(curSkill.GetEffectCount()):  | 
|             curEffect = curSkill.GetEffect(effectIndex)  | 
|             SkillShell.CalcBuffEffAttr(curPlayer, curEffect, skillAttrList)  | 
|               | 
|     # Def_SkillType_AttrSkillNoLearn ·ÇѧϰÊôÐÔ¼¼ÄÜ µþ¼ÓÊôÐÔ¼ÆËã  | 
|     ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|     for i in xrange(ipyDataMgr.GetDogzCount()):  | 
|         ipyData = ipyDataMgr.GetDogzByIndex(i)  | 
|         if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_DogzFightState, i):  | 
|             #δÖúÕ½  | 
|             continue  | 
|           | 
|         for skillID in ipyData.GetHelpBattleSkills():  | 
|   | 
|             skillData = GameWorld.GetGameData().GetSkillBySkillID(skillID)  | 
|             if not skillData:  | 
|                 continue  | 
|             # Í¬¼¼ÄÜÀàÐÍID¿É¶à¸öµþ¼ÓµÄÊôÐÔʱֱ½ÓÈ¡±í  | 
|             if skillData.GetSkillType() != ChConfig.Def_SkillType_AttrSkillNoLearn:  | 
|                 continue  | 
|               | 
|             for effectIndex in xrange(skillData.GetEffectCount()):  | 
|                 curEffect = skillData.GetEffect(effectIndex)  | 
|                 SkillShell.CalcBuffEffAttr(curPlayer, curEffect, skillAttrList)  | 
|       | 
|     #GameWorld.DebugLog("ÉñÊÞ¼¼ÄÜÊôÐÔ: skillFPEx=%s, %s" % ( skillFPEx, skillAttrList))  | 
|     return skillAttrList  | 
|   | 
|   | 
| 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  | 
|   |