| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package PlayerFamilyBoss  | 
| #  | 
| # @todo:¼Ò×åboss¸±±¾  | 
| # @author hxp  | 
| # @date 2014-04-16  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¼Ò×åboss¸±±¾  | 
| #  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2014-04-16 18:00"""  | 
| #---------------------------------------------------------------------  | 
|   | 
| import PlayerFamilyAction  | 
| import GameWorld  | 
| import PlayerCompensation  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import ShareDefine  | 
| import IpyGameDataPY  | 
| import PlayerDBGSEvent  | 
| import PlayerControl  | 
| import ChConfig  | 
| import time  | 
|   | 
| def FamilyBossFBOnWeek(curFamily):  | 
|     return  | 
|   | 
| def FamilyBossFBOnDayEx(curFamily):  | 
|     __FamilyBossFBHurtOnDay(curFamily)  | 
|     return  | 
|   | 
| def OnLogin(curPlayer):  | 
|     SyncFamilyBosFBInfo(curPlayer.GetFamilyID(), None, curPlayer)  | 
|     NotifyAllFamilyBossState(curPlayer)  | 
|     return  | 
|   | 
| def OnPlayerJionFamily(curFamily, curPlayer):  | 
|     SyncFamilyBosFBInfo(curPlayer.GetFamilyID(), None, curPlayer)  | 
|     return  | 
|   | 
| def __FamilyBossFBHurtOnDay(curFamily):  | 
|     familyID = curFamily.GetID()  | 
|       | 
|     #²¹·¢ÏÉÃËÉËѪ½±Àø  | 
|     hurtValueTotal = 0  | 
|     memberHurtAwardStateDict = {}  | 
|     fActionType = ShareDefine.Def_ActionType_FamilyBossFB  | 
|     familyBossFBAction = GameWorld.GetFamilyActionManager().GetFamilyAction(familyID, fActionType)  | 
|     for index in range(familyBossFBAction.Count()):  | 
|         actionData = familyBossFBAction.At(index)  | 
|         playerID = actionData.GetValue1()  | 
|           | 
|         if playerID == 1:  | 
|             hurtValueTotal = GetFamilyBossPlayerHurtValue(actionData)  | 
|         else:  | 
|             hurtAwardStateFamily = actionData.GetValue2()  | 
|             memberHurtAwardStateDict[playerID] = hurtAwardStateFamily  | 
|               | 
|     #GameWorld.DebugLog("__FamilyBossFBHurtOnDay hurtValueTotal=%s,memberHurtAwardStateDict=%s" % (hurtValueTotal, memberHurtAwardStateDict), familyID)  | 
|     awardIpyDataList = []  | 
|     ipyDataMgr = IpyGameDataPY.IPY_Data()  | 
|     for ipyIndex in range(ipyDataMgr.GetFamilyBossHurtAwardCount()):  | 
|         ipyData = ipyDataMgr.GetFamilyBossHurtAwardByIndex(ipyIndex)  | 
|         if ipyData.GetAwardType() != 2:  | 
|             continue  | 
|         needHurtTotal = ipyData.GetNeedHurtTotal()  | 
|         if hurtValueTotal < needHurtTotal:  | 
|             #GameWorld.DebugLog("    ÏÉÃËÉËѪ²»×㣬²»²¹·¢¸Ã½±Àø! needHurtTotal=%s" % needHurtTotal, familyID)  | 
|             continue  | 
|         awardIpyDataList.append(ipyData)  | 
|           | 
|     offLineHourMax = 48  | 
|     for index in xrange(curFamily.GetCount()):  | 
|         member = curFamily.GetAt(index)  | 
|         playerID = member.GetPlayerID()  | 
|         offLineHour = GameWorld.GetPastHour(GameWorld.ChangeTimeNumToStr(member.GetExattr2())) if member.GetExattr2() > 1 else 0  | 
|         if offLineHour >= offLineHourMax:  | 
|             #GameWorld.DebugLog("    ÀëÏß¹ý¾Ã£¬²»²¹·¢. playerID=%s,offLineHour=%s" % (playerID, offLineHour), familyID)  | 
|             continue  | 
|           | 
|         hurtAwardStateFamily = memberHurtAwardStateDict.get(playerID, 0)  | 
|         for ipyData in awardIpyDataList:  | 
|             recordIndex = ipyData.GetRecordIndex()  | 
|             if hurtAwardStateFamily & pow(2, recordIndex):  | 
|                 #GameWorld.DebugLog("    ÒѾÁìÈ¡¹ý£¬²»²¹·¢. playerID=%s,recordIndex=%s,%s" % (playerID, recordIndex, hurtAwardStateFamily), familyID)  | 
|                 continue  | 
|             needHurtTotal = ipyData.GetNeedHurtTotal()  | 
|             paramList = [needHurtTotal]  | 
|             awardItemList = ipyData.GetAwardItemList()  | 
|             PlayerCompensation.SendMailByKey("FamilyBossHurtAwardFamily", [playerID], awardItemList, paramList)  | 
|             #GameWorld.DebugLog("    Óʼþ²¹·¢ÉËѪ½±Àø. playerID=%s,recordIndex=%s" % (playerID, recordIndex), familyID)  | 
|               | 
|     # ×îºóÇå³ýaction  | 
|     PlayerFamilyAction.ClearFamilyAction(familyID, fActionType)  | 
|     SyncFamilyBosFBInfo(familyID, curFamily)  | 
|     return  | 
|   | 
| def GetFamilyBossFBActionData(familyID, playerID=1):  | 
|     ## »ñÈ¡ÏÉÃËbossÉËѪaction  | 
|     # playerID  1-ÌØÊâÀàÐÍ£¬¼Ç¼ÏÉÃË×ÜÉ˺¦ÐÅÏ¢£»>1-Íæ¼ÒÏÉÃËÉËѪ½±ÀøÁì½±¼Ç¼  | 
|       | 
|     findActionData = None  | 
|     fActionType = ShareDefine.Def_ActionType_FamilyBossFB  | 
|     familyBossFBAction = GameWorld.GetFamilyActionManager().GetFamilyAction(familyID, fActionType)  | 
|     for index in range(familyBossFBAction.Count()):  | 
|         actionData = familyBossFBAction.At(index)  | 
|         if playerID == actionData.GetValue1():  | 
|             findActionData = actionData  | 
|             break  | 
|               | 
|     if not findActionData:  | 
|         findActionData = familyBossFBAction.AddAction()  | 
|         findActionData.SetFamilyId(familyID)  | 
|         findActionData.SetActionType(fActionType)  | 
|         findActionData.SetValue1(playerID)  | 
|           | 
|     return findActionData  | 
|   | 
| def GetFamilyBossPlayerHurtValue(actionData):  | 
|     return actionData.GetValue3() * ChConfig.Def_PerPointValue + actionData.GetValue2()  | 
| def SetFamilyBossPlayerHurtValue(actionData, hurtValue):  | 
|     actionData.SetValue2(hurtValue % ChConfig.Def_PerPointValue)  | 
|     actionData.SetValue3(hurtValue / ChConfig.Def_PerPointValue)  | 
|     return  | 
|   | 
| def MapServer_FamilyBoss(msgList, tick):  | 
|     msgType, msgData = msgList  | 
|       | 
|     # Í¬²½ÉËѪ  | 
|     if msgType == "FBMemberHurt":  | 
|         __addFBMemberHurtInfo(msgData)  | 
|         return  | 
|       | 
|     # ÏÉÃËÉËѪÁì½±  - ÇëÇó  | 
|     if msgType == "FamilyHurtAwardReq":  | 
|         familyID = msgData[0]  | 
|         actionData = GetFamilyBossFBActionData(familyID)  | 
|         hurtValueTotal = GetFamilyBossPlayerHurtValue(actionData) if actionData else 0  | 
|         return msgList + [hurtValueTotal]  | 
|       | 
|     # ÏÉÃËÉËѪÁì½±¼Ç¼ͬ²½ - ÓÃÓÚ¼ÓÈëÏÉÃËʱ£¬Í¬²½µ½GameServer£¬·½±ãͳһ´¦Àí²¹·¢½±Àø  | 
|     if msgType == "FamilyHurtAwardStateFamily":  | 
|         familyID, playerID, hurtAwardStateFamily = msgData  | 
|         actionData = GetFamilyBossFBActionData(familyID, playerID)  | 
|         actionData.SetValue2(hurtAwardStateFamily)  | 
|         return  | 
|       | 
|     return  | 
|   | 
| def __addFBMemberHurtInfo(msgData):  | 
|     ## Ôö¼ÓÏÉÃËbossÏÉÃË×ÜÉËѪ  | 
|     statsType, familyID, fightMemCount, addFamilyHurt = msgData  | 
|     curFamily = GameWorld.GetFamilyManager().FindFamily(familyID)  | 
|     if not curFamily:  | 
|         return  | 
|       | 
|     actionData = GetFamilyBossFBActionData(familyID)  | 
|     if not actionData:  | 
|         return  | 
|     actionData.SetValue4(fightMemCount)  | 
|       | 
|     hurtValueTotal = GetFamilyBossPlayerHurtValue(actionData) + addFamilyHurt  | 
|     SetFamilyBossPlayerHurtValue(actionData, hurtValueTotal)  | 
|       | 
|     #GameWorld.DebugLog("FamilyBossFBMemberHurt statsType=%s,familyID=%s,fightMemCount=%s,addFamilyHurt=%s,hurtValueTotal=%s"   | 
|     #                   % (statsType, familyID, fightMemCount, addFamilyHurt, hurtValueTotal))  | 
|       | 
|     if statsType:  | 
|         SyncFamilyBosFBInfo(familyID, curFamily)  | 
|     return  | 
|   | 
| def SyncFamilyBosFBInfo(familyID, curFamily=None, curPlayer=None):  | 
|     if not familyID:  | 
|         return  | 
|     if not curFamily and not curPlayer:  | 
|         return  | 
|     actionData = GetFamilyBossFBActionData(familyID)  | 
|     if not actionData:  | 
|         return  | 
|       | 
|     clientPack = ChPyNetSendPack.tagGCFamilyBosFBInfo()  | 
|     clientPack.Clear()  | 
|     clientPack.HurtTotal = actionData.GetValue2()  | 
|     clientPack.HurtTotalPoint = actionData.GetValue3()  | 
|     clientPack.FightMemCount = actionData.GetValue4()  | 
|       | 
|     if curFamily:  | 
|         for i in range(0, curFamily.GetCount()):  | 
|             notifyMember = curFamily.GetAt(i)  | 
|             curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(notifyMember.GetPlayerID())          | 
|             if curPlayer == None:  | 
|                 continue  | 
|             NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|         return  | 
|       | 
|     if curPlayer:  | 
|         NetPackCommon.SendFakePack(curPlayer, clientPack)  | 
|           | 
|     return  | 
|   | 
| #############################¶àÏÉÃËBOSS#############################  | 
|   | 
| def OnAllFamilyBossStateChange(isOpen):  | 
|     if isOpen:  | 
|         #±¾´Î¿ªÆôʱ¼ä¾àÀëÉϴλ÷ɱʱ¼ä³¬¹ý1СʱÔòÖØÖà  | 
|         lastKillTime = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_AllFamilyBossTime)  | 
|         curTime = int(time.time())  | 
|         if abs(curTime-lastKillTime)> 3600:  | 
|             PlayerDBGSEvent.SetDBGSTrig_ByKey(PlayerDBGSEvent.Def_AllFamilyBossTime, 0)  | 
|             #֪ͨ  | 
|             NotifyAllFamilyBossState()  | 
|     return  | 
|   | 
| def AllFamilyBossKilled():  | 
|     if PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_AllFamilyBossTime):  | 
|         GameWorld.Log('¶àÏÉÃËBossÒѱ»»÷ɱ£¬²»¿ÉÖØ¸´£¡£¡')  | 
|         return  | 
|     curTime = int(time.time())  | 
|     PlayerDBGSEvent.SetDBGSTrig_ByKey(PlayerDBGSEvent.Def_AllFamilyBossTime, curTime)  | 
|     GameWorld.Log('¶àÏÉÃËBoss±»»÷ɱ!!')  | 
|     NotifyAllFamilyBossState()  | 
|     return  | 
|   | 
| def NotifyAllFamilyBossState(curPlayer=None):  | 
|     lastKillTime = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_AllFamilyBossTime)  | 
|     bossInfo = ChPyNetSendPack.tagGCAllFamilyBossInfo()  | 
|     bossInfo.IsEnd = 1 if lastKillTime else 0  | 
|       | 
|     if curPlayer == None:  | 
|         playerManager = GameWorld.GetPlayerManager()  | 
|         for i in xrange(playerManager.GetActivePlayerCount()):  | 
|             curPlayer = playerManager.GetActivePlayerAt(i)  | 
|             if curPlayer == None or not curPlayer.GetInitOK():  | 
|                 continue  | 
|             if PlayerControl.GetIsTJG(curPlayer):  | 
|                 continue  | 
|             NetPackCommon.SendFakePack(curPlayer, bossInfo)  | 
|     else:  | 
|         if PlayerControl.GetIsTJG(curPlayer):  | 
|             return  | 
|         NetPackCommon.SendFakePack(curPlayer, bossInfo)  | 
|     return  | 
|   | 
| #ÊÇ·ñÔÚÏÉÃËBOSS»î¶¯ÖÐ  | 
| def IsInAllFamilyBoss(lineID=-1):  | 
|     state1 = GameWorld.GetGameWorld().GetDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % ShareDefine.DailyActionID_FamilyBoss1)  | 
|     return state1  |