| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerGodWeapon  | 
| #  | 
| # @todo:Éñ±ø  | 
| # @author alee  | 
| # @date 2017-07-20  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: Éñ±ø  | 
| #  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2017-07-20 16:00"""  | 
| #---------------------------------------------------------------------  | 
|   | 
| import GameWorld  | 
| import EventShell  | 
| import ChConfig  | 
| import PlayerControl  | 
| import ItemCommon  | 
| import IPY_GameWorld  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import PlayerSuccess  | 
| import ShareDefine  | 
| import SkillShell  | 
| import DataRecordPack  | 
| import GameFuncComm  | 
| import SkillCommon  | 
| import BuffSkill  | 
| import ItemControler  | 
| #import EventReport  | 
| import IpyGameDataPY  | 
| import PassiveBuffEffMng  | 
|   | 
| import random  | 
|   | 
| ## ÉñÆ÷¹¦ÄܵǼ´¦Àí  | 
| #  @param curPlayer Íæ¼Ò  | 
| #  @return None  | 
| def OnLogin(curPlayer):  | 
|     if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon):  | 
|         return  | 
|     Sync_GodWeaponLVInfo(curPlayer)  | 
|     return  | 
|   | 
|   | 
| ## ÉñÆ÷¿ªÆô  | 
| #  @return: ÊÇ·ñ¼¤»î³É¹¦  | 
| def DoGodWeaponOpen(curPlayer):  | 
|     # Ä¬Èϼ¤»î1¼¶µÄÀàÐÍ  | 
|     for i in IpyGameDataPY.GetFuncEvalCfg('GodWeaponActive'):  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponLV % i, 1)  | 
|         PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GodWeapon, 1, [i])  | 
|     Sync_GodWeaponLVInfo(curPlayer)  | 
|     return True  | 
|   | 
|   | 
| ## Ë¢ÐÂÉñ±øÊôÐÔ  | 
| def RefreshGodWeaponAttr(curPlayer):  | 
|     CalcGodWeaponAttr(curPlayer)  | 
|     # ²»Á¢¼´Ë¢Ð  | 
|     PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()  | 
|     return  | 
|   | 
| ## ¼ÆËãÊôÐÔ  | 
| #  @param curPlayer Íæ¼Ò  | 
| #  @param allAttrList ÊôÐÔÁÐ±í  | 
| #  @return None  | 
| def CalcGodWeaponAttr(curPlayer):  | 
|     if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon):  | 
|         return  | 
|       | 
|     ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|     maxType = ipyDataMgr.GetGodWeaponByIndex(ipyDataMgr.GetGodWeaponCount()-1).GetType()  | 
|   | 
|     allAttrList = [{} for i in range(4)]  | 
|     for gwType in xrange(1, maxType + 1):  | 
|         attrLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % gwType)  | 
|         godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', gwType, attrLV)  | 
|         if not godWeaponData:  | 
|             continue  | 
|         attrTypeList, attrValueList =  godWeaponData.GetAttrType(), godWeaponData.GetAttrNum()  | 
|         for i, attrID in enumerate(attrTypeList):  | 
|             PlayerControl.CalcAttrDict_Type(attrID, attrValueList[i], allAttrList)  | 
|           | 
|     # ±£´æ¼ÆËãÖµ  | 
|     PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_GodWeapon, allAttrList)     | 
|     return  | 
|   | 
| #---------------------------------------------------------------------------------------------------  | 
| #===============================================================================  | 
| # // A5 55 Éñ±øÉý¼¶ #tagCMGodWeaponPlus  | 
| #   | 
| # struct    tagCMGodWeaponPlus  | 
| # {  | 
| #    tagHead        Head;  | 
| #    DWORD        WeaponType;    // Éñ±øÀàÐÍ  | 
| #    DWORD        ItemID;        //ÏûºÄµÄÎïÆ·ID  | 
| # };  | 
| #===============================================================================  | 
| def OnPlusGodWeapon(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     weaponType = clientData.WeaponType  | 
|     useItemID = clientData.ItemID  | 
|       | 
|     if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_GodWeapon):  | 
|         #µÈ¼¶²»×ã  | 
|         return  | 
|       | 
|     #1.ÅжϱíÖÐÓÐû´ËÀàÐÍ£¬2.ÊÇ·ñÂú¼¶£¬3.ÅжÏÊÇ·ñÓÐÎïÆ·  | 
|     attrLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % weaponType)  | 
|     beforeAttrLV = attrLV   # ÓÃÓÚÌáʾ  | 
|     godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', weaponType, attrLV)  | 
|     if not godWeaponData:  | 
|         GameWorld.DebugLog('Éñ±øÉý¼¶ÕÒ²»µ½Êý¾Ý %s-%s'%(weaponType, attrLV))  | 
|         return  | 
|       | 
|     totalExp = godWeaponData.GetExp()  | 
|     if totalExp == 0:  | 
|         #Âú¼¶  | 
|         return  | 
|       | 
|     #ÑéÖ¤ÊÇ·ñÖ¸¶¨µÄÎïÆ·ID  | 
|     if useItemID not in IpyGameDataPY.GetFuncEvalCfg("GodWeapon%s"%weaponType):  | 
|         return  | 
|       | 
|     curItem = ItemCommon.FindItemInPackByItemID(curPlayer, useItemID, IPY_GameWorld.rptItem)  | 
|     if not curItem:  | 
|         GameWorld.DebugLog('###Éñ±ø¼Ù°ü£¬Ã»ÓÐÎïÆ·ID=%s'%useItemID)  | 
|         return  | 
|   | 
|     effect = ItemCommon.GetItemEffectByEffectID(curItem, ChConfig.Def_Item_Eff_GodWeaponExp)  | 
|     if not effect:  | 
|         GameWorld.DebugLog('###Éñ±ø¼Ù°ü£¬ÎïÆ·ID=%sûÓоÑéÖµ'%useItemID)  | 
|         return  | 
|     addExp = effect.GetEffectValue(0)  | 
|     if not addExp:  | 
|         GameWorld.DebugLog('###Éñ±ø¼Ù°ü£¬ÎïÆ·ID=%sûÓоÑéÖµ'%useItemID)  | 
|         return  | 
|       | 
|     delCnt = 1  | 
|     ItemCommon.DelItem(curPlayer, curItem, delCnt, False, ChConfig.ItemDel_GodWeapon)  | 
|       | 
|     curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % weaponType)  | 
|     curExp = curExp + addExp  | 
|       | 
|     isLVUP = False  | 
|       | 
|     # °²È«ÎªÖ÷²»ÓÃwhile  | 
|     for i in xrange(100):  | 
|         if curExp < totalExp:  | 
|             break  | 
|         godWeaponData = IpyGameDataPY.GetIpyGameData('GodWeapon', weaponType, attrLV+1)  | 
|         if not godWeaponData:  | 
|             GameWorld.DebugLog('Éñ±øÉý¼¶ÕÒ²»µ½Êý¾Ý %s-%s'%(weaponType, attrLV))  | 
|             break  | 
|           | 
|         curExp = curExp - totalExp  | 
|         attrLV += 1  | 
|         isLVUP = True  | 
|         GodWeaponLVUP(curPlayer, godWeaponData, attrLV)  | 
|           | 
|         totalExp = godWeaponData.GetExp()  | 
|         if totalExp == 0:  | 
|             curExp = 0  | 
|             #Âú¼¶  | 
|             break  | 
|           | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponLV % weaponType, attrLV)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GodWeaponExp % weaponType, curExp)  | 
|       | 
|     if isLVUP:  | 
|         RefreshGodWeaponAttr(curPlayer)  | 
|         #xÉñÆ÷´ïµ½X¼¶³É¾Í  | 
|         PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GodWeapon, attrLV, [weaponType])  | 
|         if beforeAttrLV == 0:  | 
|             # ½â·â֪ͨ  | 
|             sysMark = IpyGameDataPY.GetFuncEvalCfg('GodWeaponSys', 1, {}).get(weaponType, 'GetGodWeapon')  | 
|             PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), weaponType])  | 
|               | 
|         #{1:[100,200,300,400],2:[100,200,300,400],3:[100,200,300,400]}  | 
|         notifyDict = IpyGameDataPY.GetFuncEvalCfg('GodLv', 1, {})  | 
|         if weaponType in notifyDict:  | 
|             for notifyLV in notifyDict[weaponType]:  | 
|                 if beforeAttrLV < notifyLV and attrLV >= notifyLV:  | 
|                     PlayerControl.WorldNotify(0, 'GodWeaponLv', [curPlayer.GetName(), weaponType, notifyLV])  | 
|           | 
|     Sync_GodWeaponLVInfo(curPlayer, weaponType)  | 
|     #ÈÎÎñ  | 
|     EventShell.EventRespons_PlusGodWeapon(curPlayer)  | 
|     return  | 
|   | 
| #Éñ±øÉý¼¶´¥·¢ÆäËû¹¦ÄÜ£º¼¼ÄÜ  | 
| def GodWeaponLVUP(curPlayer, godWeaponData, attrLV):  | 
|     skillID = godWeaponData.GetSkillID()  | 
|       | 
|     if skillID:  | 
|         if __GiveGodWeaponSkill(curPlayer, skillID):  | 
|             sysMark = godWeaponData.GetSysMark()  | 
|             if sysMark:  | 
|                 PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), attrLV, skillID])  | 
|   | 
|   | 
|   | 
| ## Í¬²½ÉñÆ÷µÈ¼¶  | 
| #  @param curPlayer  | 
| #  @param godWeaponId ÉñÆ÷ID  | 
| #  @return None  | 
| def Sync_GodWeaponLVInfo(curPlayer, godWeaponID=0):  | 
|     sendPack = ChPyNetSendPack.tagMCGodWeaponLVList()  | 
|     sendPack.Clear()  | 
|           | 
|     sendPack.WeaponInfoList = []  | 
|   | 
|     if godWeaponID <= 0:  | 
| #        weaponStateStr = bin(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponState))[::-1][:-2]  | 
| #        for i in range(0, len(weaponStateStr)):  | 
| #            if weaponStateStr[i] == '0':  | 
| #                #ÕÒ³ö¼¤»îµÄÉñ±ø  | 
| #                continue  | 
|         ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|         maxType = ipyDataMgr.GetGodWeaponByIndex(ipyDataMgr.GetGodWeaponCount()-1).GetType()  | 
|         for i in xrange(1, maxType + 1):  | 
|             weaponInfo = ChPyNetSendPack.tagMCGodWeaponLVInfo()  | 
|             weaponInfo.Clear()  | 
|             weaponInfo.WeaponType = i  | 
|             weaponInfo.WeaponLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % i)  | 
|             weaponInfo.WeaponExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % i)  | 
|             sendPack.WeaponInfoList.append(weaponInfo)  | 
|     else:  | 
|         weaponInfo = ChPyNetSendPack.tagMCGodWeaponLVInfo()  | 
|         weaponInfo.Clear()  | 
|         weaponInfo.WeaponType = godWeaponID  | 
|         weaponInfo.WeaponLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponLV % godWeaponID)  | 
|         weaponInfo.WeaponExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GodWeaponExp % godWeaponID)  | 
|         sendPack.WeaponInfoList.append(weaponInfo)  | 
|       | 
|     sendPack.WeaponNum = len(sendPack.WeaponInfoList)  | 
|     NetPackCommon.SendFakePack(curPlayer, sendPack)    | 
|     return  | 
|   | 
|   | 
|   | 
| def __GiveGodWeaponSkill(curPlayer, skillResId):  | 
|     # ÉñÆ÷ѧϰ¼¼ÄÜ  | 
|     skillManager = curPlayer.GetSkillManager()  | 
|     if skillManager.FindSkillBySkillTypeID(skillResId):  | 
|         GameWorld.DebugLog("godSkill() have learned skill(%s)" % skillResId)  | 
|         return  | 
|       | 
|     skillData = GameWorld.GetGameData().FindSkillByType(skillResId, 1)  | 
|     if skillData == None:  | 
|         GameWorld.DebugLog("godSkill() hasn't find skill(%s)" % skillResId)  | 
|         return  | 
|     if not SkillShell.CheckLearnSkillCondition(curPlayer, skillData):  | 
|         GameWorld.DebugLog("godSkill() learn skill(%s) condition isn't enough" % skillResId)  | 
|         return  | 
|       | 
|     skillManager.LVUpSkillBySkillTypeID(skillResId)  | 
|     #PlayerControl.NotifyCode(curPlayer, "Skill_andyshao_31379", [skillResId])  | 
|     GameWorld.DebugLog("godSkill() skill(%s) success!" % skillResId)  | 
|     DataRecordPack.DR_LearnORUPSkill(curPlayer, skillResId, 0)  | 
|       | 
|     #if SkillCommon.isPassiveSkill(skillData):  | 
|     #    buffType = SkillCommon.GetBuffType(skillData)  | 
|     #    BuffSkill.DoAddBuff(curPlayer, buffType, skillData, GameWorld.GetGameWorld().GetTick(), [], curPlayer)  | 
|     PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPlayer, skillResId)  | 
|     PlayerControl.PlayerControl(curPlayer).RefreshSkillFightPowerEx(skillResId, 0)  | 
|     return True  | 
|   |