| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerBossReborn  | 
| #  | 
| # @todo:BOSS¸´»î  | 
| # @author xdh  | 
| # @date 2018-07-12 16:50  | 
| # @version 1.0  | 
| #  | 
| #  | 
| # ÏêϸÃèÊö: BOSS¸´»î  | 
| #  | 
| #---------------------------------------------------------------------  | 
| """Version = 2018-07-12 16:50"""  | 
| #---------------------------------------------------------------------  | 
|   | 
| import IPY_GameWorld  | 
| import GameWorld  | 
| import ChConfig  | 
| import IpyGameDataPY  | 
| import PlayerControl  | 
| import ItemControler  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import ShareDefine  | 
| import PyGameData  | 
| import ItemCommon  | 
|   | 
|   | 
| def OnLogin(curPlayer):  | 
|     isReset = __CheckPlayerBossRebornAction(curPlayer)  | 
|     if not isReset:  | 
|         actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})  | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|         if actCostRebateInfo.get(ShareDefine.ActKey_State):  | 
|             SyncBossRebornInfo(curPlayer)  | 
|             SyncBossRebornPlayerInfo(curPlayer)  | 
|     return  | 
|   | 
|   | 
| def RefreshOperationAction_BossReborn():  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for i in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(i)  | 
|         if curPlayer == None or not curPlayer.GetInitOK():  | 
|             continue  | 
|         __CheckPlayerBossRebornAction(curPlayer)  | 
|     return  | 
|   | 
|   | 
| def __CheckPlayerBossRebornAction(curPlayer):  | 
|     ## ¼ì²éÍæ¼ÒBOSS¸´»î»î¶¯Êý¾ÝÐÅÏ¢  | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})  | 
|     bossRebornID = actBossRebornInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)  | 
|       | 
|     playerBossRebornID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornID)  # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if bossRebornID == playerBossRebornID:  | 
|         #GameWorld.DebugLog("BOSS¸´»î»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())  | 
|         return  | 
|     templateID = actBossRebornInfo.get(ShareDefine.ActKey_TemplateID, 0)  | 
|     playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornTemplateID)  | 
|       | 
|     GameWorld.DebugLog("BOSS¸´»îÖØÖÃ! costRebateID=%s,playerCostRebateID=%s,state=%s,templateID=%s,playerTemplateID=%s"   | 
|                        % (bossRebornID, playerBossRebornID, state, templateID, playerTemplateID), playerID)  | 
|       | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|     __SendBossRebornMail(curPlayer, playerTemplateID)  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BossRebornID, bossRebornID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BossRebornTemplateID, templateID)  | 
|     for brid in ChConfig.BossRebornActIDList:  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionCurTimes % brid, 0)  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionGotTimes % brid, 0)  | 
|           | 
|     SyncBossRebornInfo(curPlayer)  | 
|     SyncBossRebornPlayerInfo(curPlayer)  | 
|     return True  | 
|   | 
|   | 
| def __SendBossRebornMail(curPlayer, playerTemplateID):  | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("BossReborn", {'TemplateID':playerTemplateID}, True)  | 
|     if not ipyDataList:  | 
|         return  | 
|       | 
|     totalItemDict = {}  | 
|     for ipyData in ipyDataList:  | 
|         brid = ipyData.GetID()  | 
|         singleTimes = ipyData.GetSingleTimes()  | 
|         curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % brid)  | 
|         gotTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionGotTimes % brid)  | 
|         canGotCnt = (curTimes - gotTimes) / singleTimes  | 
|         if not canGotCnt:  | 
|             continue  | 
|         itemDict = __GetAwardItem(curPlayer, ipyData, canGotCnt)  | 
|         GameWorld.AddDictValue(totalItemDict, itemDict)  | 
|       | 
|     #È¥µô¸´»îµãµÀ¾ß  | 
|     totalItemDict.pop(ChConfig.Def_ItemID_BossReborn, 0)  | 
|     if not totalItemDict:  | 
|         return  | 
|     totalItemList = [[itemID, itemCnt, 1] for itemID, itemCnt in totalItemDict.items()]  | 
|     PlayerControl.SendMailByKey('BossFHUnGetMail', [curPlayer.GetID()], totalItemList)  | 
|     return  | 
|   | 
|   | 
| def AddBossRebornActionCnt(curPlayer, actionID, addCnt=1):  | 
|     '''Ôö¼Óboss¸´»îÏà¹Ø»î¶¯Íê³É´ÎÊý'''  | 
|     #ÅжϻÊÇ·ñ¿ªÆô  | 
|     actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})  | 
|     state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)  | 
|     if not state:  | 
|         return  | 
|     playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornTemplateID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData('BossReborn', playerTemplateID, actionID)  | 
|     if not ipyData:  | 
|         return  | 
|     totalTimes = ipyData.GetTotalTimes()  | 
|     curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % actionID)  | 
|     addCnt = addCnt if totalTimes == 0 else min(totalTimes - curTimes, addCnt)  | 
|     if addCnt <= 0:  | 
|         return  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionCurTimes % actionID, curTimes + addCnt)  | 
|       | 
|     SyncBossRebornPlayerInfo(curPlayer, actionID)  | 
|     return  | 
|   | 
|   | 
| def GetBossRebornActionAward(curPlayer, actionID):  | 
|     '''ÁìÈ¡boss¸´»î»î¶¯½±Àø'''  | 
|     playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornTemplateID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData('BossReborn', playerTemplateID, actionID)  | 
|     if not ipyData:  | 
|         return  | 
|     singleTimes = ipyData.GetSingleTimes()  | 
|     curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % actionID)  | 
|     gotTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionGotTimes % actionID)  | 
|     if curTimes - gotTimes < singleTimes:  | 
|         return  | 
|       | 
|     #¸ø½±Àø  | 
|     awardDict = __GetAwardItem(curPlayer, ipyData)  | 
|     # ¼ì²é±³°ü  | 
|     needSpace = len(awardDict)  | 
|     packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)  | 
|     if needSpace > packSpace:  | 
|         PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")  | 
|         return  | 
|     #¸üдÎÊý Ã¿´ÎÁì½±Ö»ÁìÒ»´Î  | 
|     newGotTimes = gotTimes + singleTimes  | 
|       | 
|     #GameWorld.Log('  actionID=%s,curTimes=%s,gotTimes=%s,singleTimes=%s,newGotTimes=%s'%(actionID, curTimes, gotTimes,singleTimes, newGotTimes))  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionGotTimes % actionID, newGotTimes)  | 
|     for itemID, itemCnt in awardDict.items():  | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 1, [IPY_GameWorld.rptItem])  | 
|     SyncBossRebornPlayerInfo(curPlayer, actionID)  | 
|     return  | 
|   | 
|   | 
| def __GetAwardItem(curPlayer, ipyData, times=1):  | 
|     awardDict = {}  | 
|     for itemID, itemCnt, isbind in ipyData.GetReward():  | 
|         if not itemID or not itemCnt:  | 
|             continue  | 
|         awardDict[itemID] = awardDict.get(itemID, 0) + itemCnt * times  | 
|           | 
|     return awardDict  | 
|   | 
|   | 
| def SyncBossRebornPlayerInfo(curPlayer, actID=-1):  | 
|     #֪ͨµ±Ç°´ÎÊý¡¢ÒÑÁì´ÎÊý   | 
|     packData = ChPyNetSendPack.tagMCBossRebornPlayerInfo()  | 
|     packData.DataList = []  | 
|     if actID != -1:  | 
|         syneActIDList = [actID]  | 
|     else:  | 
|         syneActIDList = []  | 
|         ipyMgr = IpyGameDataPY.IPY_Data()  | 
|         for i in xrange(ipyMgr.GetBossRebornCount()):  | 
|             ipyData = ipyMgr.GetBossRebornByIndex(i)  | 
|             syneActIDList.append(ipyData.GetID())  | 
|        | 
|     for actid in syneActIDList:  | 
|         curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % actid)  | 
|         gotTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionGotTimes % actid)  | 
|         tiemInfo = ChPyNetSendPack.tagMCBossRebornData()  | 
|         tiemInfo.ActID = actid  | 
|         tiemInfo.CurTimes = curTimes  | 
|         tiemInfo.GotTimes = gotTimes  | 
|         packData.DataList.append(tiemInfo)  | 
|       | 
|     packData.Count = len(packData.DataList)  | 
|     NetPackCommon.SendFakePack(curPlayer, packData)  | 
|     return  | 
|   | 
|   | 
| def SyncBossRebornInfo(curPlayer):  | 
|     actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})  | 
|     state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)  | 
|     if not state:  | 
|         return  | 
|     templateID = actBossRebornInfo.get(ShareDefine.ActKey_TemplateID, 0)  | 
|     if not templateID:  | 
|         return  | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("BossReborn", {'TemplateID':templateID}, True)  | 
|     if not ipyDataList:  | 
|         return  | 
|     actInfo = ChPyNetSendPack.tagMCBossRebornInfo()  | 
|     actInfo.Clear()  | 
|     actInfo.StartDate = actBossRebornInfo.get(ShareDefine.ActKey_StartDate, "")  | 
|     actInfo.EndtDate = actBossRebornInfo.get(ShareDefine.ActKey_EndDate, "")  | 
|     actInfo.LimitLV = actBossRebornInfo.get(ShareDefine.ActKey_LVLimit, 0)  | 
|     actInfo.TaskInfo = []  | 
|     for ipyData in ipyDataList:  | 
|         taskInfo = ChPyNetSendPack.tagMCBossRebornTaskInfo()  | 
|         taskInfo.TaskID = ipyData.GetID()  | 
|         taskInfo.TotalTimes = ipyData.GetTotalTimes()  | 
|         taskInfo.SingleTimes = ipyData.GetSingleTimes()  | 
|         taskInfo.AwardItem = []  | 
|         for itemID, itemCnt, isBind in ipyData.GetReward():  | 
|             awardItem = ChPyNetSendPack.tagMCBossRebornAwardItem()  | 
|             awardItem.ItemID = itemID  | 
|             awardItem.ItemCount = itemCnt  | 
|             awardItem.IsBind = isBind  | 
|             taskInfo.AwardItem.append(awardItem)  | 
|         taskInfo.AwardItemCount = len(taskInfo.AwardItem)  | 
|         actInfo.TaskInfo.append(taskInfo)  | 
|     actInfo.TaskCnt = len(actInfo.TaskInfo)  | 
|     NetPackCommon.SendFakePack(curPlayer, actInfo)  | 
|     return  |