| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerFairyCeremony  | 
| #  | 
| # @todo:ÏɽçÊ¢µä  | 
| # @author xdh  | 
| # @date 2018-07-23 16:50  | 
| # @version 1.0  | 
| #  | 
| #  | 
| # ÏêϸÃèÊö: ÏɽçÊ¢µä  | 
| #  | 
| #---------------------------------------------------------------------  | 
| """Version = 2018-07-23 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  | 
| import PlayerBillboard  | 
|   | 
| (  | 
| Def_FC_Recharge, #³äÖµ´óÀñ  | 
| Def_FC_Fireworks, #ÑÌ»¨  | 
| Def_FC_Party, #È«ÃñÀ´àË  | 
| Def_FC_RechargeRank, #¾ø°æ½µÁÙ  | 
| ) = range(1, 5)  | 
|   | 
|   | 
| def OnLogin(curPlayer):  | 
|     isReset = __CheckPlayerFairyCeremonyAction(curPlayer)  | 
|     if not isReset:  | 
|         actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FairyCeremony, {})  | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|         if actCostRebateInfo.get(ShareDefine.ActKey_State):  | 
|             SyncFCRechargeInfo(curPlayer)  | 
|             SyncFCPartyInfo(curPlayer)  | 
|     return  | 
|   | 
| def RefreshOperationAction_FairyCeremony():  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for i in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(i)  | 
|         if curPlayer == None or not curPlayer.GetInitOK():  | 
|             continue  | 
|         __CheckPlayerFairyCeremonyAction(curPlayer)  | 
|     return  | 
|   | 
|   | 
| def __CheckPlayerFairyCeremonyAction(curPlayer):  | 
|     ## ¼ì²éÍæ¼ÒÏɽçÊ¢µä»î¶¯Êý¾ÝÐÅÏ¢  | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actFairyCeremonyInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FairyCeremony, {})  | 
|     FairyCeremonyID = actFairyCeremonyInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actFairyCeremonyInfo.get(ShareDefine.ActKey_State, 0)  | 
|       | 
|     playerFairyCeremonyID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyCeremonyID) # Íæ¼ÒÉíÉϵĻID  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if FairyCeremonyID == playerFairyCeremonyID:  | 
|         #GameWorld.DebugLog("ÏɽçÊ¢µä»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())  | 
|         return  | 
|     actWorldLV = actFairyCeremonyInfo.get(ShareDefine.ActKey_WorldLV, 0)  | 
|     playerFCWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCActionWorldLV)  | 
|     GameWorld.DebugLog("ÏɽçÊ¢µäÖØÖÃ! FairyCeremonyID=%s,playerCostRebateID=%s,state=%s,ActWorldLV=%s,playerFCWorldLV=%s"   | 
|                        % (FairyCeremonyID, playerFairyCeremonyID, state, actWorldLV, playerFCWorldLV), playerID)  | 
|       | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|     __SendFairyCeremonyMail(curPlayer, playerFCWorldLV)  | 
|       | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyCeremonyID, FairyCeremonyID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCActionWorldLV, actWorldLV)  | 
|     #ÖØÖóäÖµ´óÀñ¼Ç¼  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCRechargeState, 0)  | 
|     SyncFCRechargeInfo(curPlayer)  | 
|     #ÖØÖÃÈ«ÃñÀ´àË  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCPartyCurPoint, 0)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCPartyAwardRecord, 0)  | 
|     for actid in ChConfig.PeoplePartyActIDList:  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCPartyCurCnt % actid, 0)  | 
|     SyncFCPartyInfo(curPlayer)  | 
|     #ÖØÖÃÏû·Ñ  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCCostGold, 0)  | 
|     return True  | 
|   | 
| def __SendFairyCeremonyMail(curPlayer, playerFCWorldLV):  | 
|     # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å  | 
|     #³äÖµ´óÀñ  | 
|     playerID = curPlayer.GetID()  | 
|     playerName = curPlayer.GetName()  | 
|     if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCRechargeState) == 1:  | 
|         worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Recharge)  | 
|         awardInfoDict = IpyGameDataPY.GetFuncEvalCfg('CeremonyRecharge', 1, {})  | 
|         if str(worldLvNum) not in awardInfoDict:  | 
|             GameWorld.ErrLog('    Óʼþ·¢·Å³äÖµ´óÀñ½±Àø CeremonyRecharge Î´ÅäÖý±Àø worldLvNum=%s' % worldLvNum)  | 
|         else:  | 
|             awardList = awardInfoDict[str(worldLvNum)]  | 
|             PlayerControl.SendMailByKey('CeremonyPayPack', [playerID], awardList, [playerName])  | 
|     #È«ÃñÀ´àË  | 
|     worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Party)  | 
|     curPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyCurPoint)  | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyAwardRecord)  | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('AllPeoplePartyAward', {'WorldLvNum':worldLvNum}, True)  | 
|     if not ipyDataList:  | 
|         GameWorld.ErrLog('    Óʼþ·¢·ÅÈ«ÃñÀ´à˽±Àø AllPeoplePartyAward Î´ÅäÖÃÊÀ½çµÈ¼¶µµ WorldLvNum=%s' % worldLvNum)  | 
|         return  | 
|       | 
|     partyAwardList = []  | 
|     for ipyData in ipyDataList:  | 
|         index = ipyData.GetIndex()  | 
|         if awardRecord & pow(2, index):  | 
|             continue  | 
|         needPoint = ipyData.GetNeedPoint()  | 
|         if curPoint < needPoint:  | 
|             continue  | 
|         awardInfoDict = ipyData.GetAward()  | 
|         job = curPlayer.GetJob()  | 
|         if str(job) not in awardInfoDict:  | 
|             GameWorld.ErrLog('    Óʼþ·¢·ÅÈ«ÃñÀ´à˽±Àø AllPeoplePartyAward Î´ÅäÖÃÖ°Òµ½±Àø job=%s' % job)  | 
|             continue  | 
|         awardList = awardInfoDict[str(job)]  | 
|         partyAwardList += awardList  | 
|     if partyAwardList:  | 
|         PlayerControl.SendMailByKey('CeremonyHaiPoint', [playerID], partyAwardList, [playerName])  | 
|     return  | 
|   | 
| def __IsAtFCAction():  | 
|     ##ÊÇ·ñÔÚÏɽçÊ¢µä»î¶¯ÖÐ  | 
|     actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_FairyCeremony, {})  | 
|     state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)  | 
|     return state == 1  | 
|   | 
| def __GetFCWorldLVIndex(curPlayer, fcType):  | 
|     #»ñÈ¡»î¶¯ÊÀ½çµÈ¼¶µµ  | 
|     playerFCWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCActionWorldLV)  | 
|     fcWorldlvDict = IpyGameDataPY.GetFuncEvalCfg('CeremonyWorldLv', 1, {})  | 
|     if str(fcType) not in fcWorldlvDict:  | 
|         return 0  | 
|     worldLVIndex = 0  | 
|     worldlvList = fcWorldlvDict[str(fcType)]  | 
|     for index, lvinfo in enumerate(worldlvList):  | 
|         minlv, maxlv = lvinfo  | 
|         if minlv <= playerFCWorldLV <= maxlv:  | 
|             worldLVIndex = index  | 
|             break  | 
|     return worldLVIndex  | 
|   | 
| #################³äÖµ´óÀñ##############################  | 
| def OnFCRecharge(curPlayer):  | 
|     if not __IsAtFCAction():  | 
|         return  | 
|     curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCRechargeState)  | 
|     if curState != 0:  | 
|         return  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCRechargeState, 1)  | 
|     SyncFCRechargeInfo(curPlayer)  | 
|     return  | 
|   | 
| def GetFCRechargeAward(curPlayer):  | 
|     ## ÁìÈ¡³äÖµ´óÀñ½±Àø  | 
|     curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCRechargeState)  | 
|     if curState != 1:  | 
|         return  | 
|     worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Recharge)  | 
|     awardInfoDict = IpyGameDataPY.GetFuncEvalCfg('CeremonyRecharge', 1, {})  | 
|     if str(worldLvNum) not in awardInfoDict:  | 
|         GameWorld.ErrLog('    ÁìÈ¡³äÖµ´óÀñ½±Àø CeremonyRecharge Î´ÅäÖý±Àø worldLvNum=%s' % worldLvNum)  | 
|         return  | 
|     awardList = awardInfoDict[str(worldLvNum)]  | 
|     # ¼ì²é±³°ü  | 
|     needSpace = len(awardList)  | 
|     packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)  | 
|     if needSpace > packSpace:  | 
|         PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")  | 
|         return  | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCRechargeState, 2)  | 
|     for itemID, itemCnt, isBind in awardList:  | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, isBind, [IPY_GameWorld.rptItem])  | 
|       | 
|     SyncFCRechargeInfo(curPlayer)  | 
|     return  | 
|   | 
|   | 
| def SyncFCRechargeInfo(curPlayer):  | 
|     ## Í¨Öª³äÖµ´óÀñ»î¶¯×´Ì¬  | 
|     packData = ChPyNetSendPack.tagMCXJSDRecharge()  | 
|     packData.State = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCRechargeState)  | 
|     NetPackCommon.SendFakePack(curPlayer, packData)  | 
|     return  | 
|   | 
| #################È«ÃñÀ´àË##############################  | 
| def AddFCPartyActionCnt(curPlayer, actionID, addCnt=1):  | 
|     ##Ôö¼ÓÈ«ÃñÀ´àËÍê³É´ÎÊý  | 
|     if not __IsAtFCAction():  | 
|         return  | 
|     ipyData = IpyGameDataPY.GetIpyGameData('AllPeopleParty', actionID)  | 
|     if not ipyData:  | 
|         return  | 
|     maxCnt = ipyData.GetTotalTimes()  | 
|     curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyCurCnt % actionID)  | 
|     if curCnt >= maxCnt:  | 
|         return  | 
|     newCnt = min(maxCnt, curCnt + addCnt)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCPartyCurCnt % actionID, newCnt)  | 
|     singlePoint = ipyData.GetAddPoint()  | 
|     addPoint = (newCnt - curCnt) * singlePoint  | 
|     curPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyCurPoint)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCPartyCurPoint, curPoint + addPoint)  | 
|     SyncFCPartyInfo(curPlayer, [actionID])  | 
|     return  | 
|   | 
| def GetFCPartyAward(curPlayer, index):  | 
|     ## È«ÃñÀ´àËÁì½±  | 
|     worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Party)  | 
|       | 
|     ipyData = IpyGameDataPY.GetIpyGameData('AllPeoplePartyAward', worldLvNum, index)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     curPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyCurPoint)  | 
|     if curPoint < ipyData.GetNeedPoint():  | 
|         GameWorld.DebugLog('    È«ÃñÀ´àËÁì½±, µãÊý²»×ã%s,  worldLvNum=%s, index=%s' % (ipyData.GetNeedPoint(), worldLvNum, index), curPlayer.GetID())  | 
|         return  | 
|     awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyAwardRecord)  | 
|     awardMark = pow(2, index)  | 
|     if awardRecord & awardMark:  | 
|         GameWorld.DebugLog('    È«ÃñÀ´àËÁì½±, ÒÑÁì½±,  worldLvNum=%s, index=%s' % (worldLvNum, index), curPlayer.GetID())  | 
|         return  | 
|     awardInfoDict = ipyData.GetAward()  | 
|     job = curPlayer.GetJob()  | 
|     if str(job) not in awardInfoDict:  | 
|         return  | 
|     awardList = awardInfoDict[str(job)]  | 
|     # ¼ì²é±³°ü  | 
|     needSpace = len(awardList)  | 
|     packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)  | 
|     if needSpace > packSpace:  | 
|         PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")  | 
|         return  | 
|     #¸üмǼ  | 
|     awardRecord |= awardMark  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCPartyAwardRecord, awardRecord)  | 
|     for itemID, itemCnt, isBind in awardList:  | 
|         ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, isBind, [IPY_GameWorld.rptItem])  | 
|     #֪ͨ  | 
|     SyncFCPartyInfo(curPlayer, isGetAward=True)  | 
|     return  | 
|   | 
|   | 
| def SyncFCPartyInfo(curPlayer, actIDList=[], isGetAward=False):  | 
|     ##֪ͨȫÃñÀ´àËÐÅÏ¢  | 
|     packData = ChPyNetSendPack.tagMCAllPeoplePartyInfo()  | 
|     packData.Clear()  | 
|     packData.CurPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyCurPoint)  | 
|     packData.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyAwardRecord)  | 
|     if not isGetAward:  | 
|         packData.BuyCountList = []  | 
|         for actID in ChConfig.PeoplePartyActIDList:  | 
|             if actIDList and actID not in actIDList:  | 
|                 continue  | 
|             finishInfo = ChPyNetSendPack.tagMCAllPeoplePartyCount()  | 
|             finishInfo.ActID = actID  | 
|             finishInfo.CurTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCPartyCurCnt % actID)  | 
|             packData.BuyCountList.append(finishInfo)  | 
|         packData.Count = len(packData.BuyCountList)  | 
|       | 
|     NetPackCommon.SendFakePack(curPlayer, packData)  | 
|     return  | 
|   | 
| #################¾ø°æ½µÁÙ##############################  | 
| def AddFCCostGold(curPlayer, costType, costGold):  | 
|     if costGold <= 0:  | 
|         return  | 
|     if costType in ChConfig.CostRebate_DisableType:  | 
|         #GameWorld.DebugLog("²»¼ÆÈë¾ø°æ½µÁÙÏû·ÑµÄÏû·ÑÀàÐÍ!costType=%s" % costType, curPlayer.GetPlayerID())  | 
|         return  | 
|     if not __IsAtFCAction():  | 
|         return  | 
|     curCostGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FCCostGold)  | 
|     updCostGold = curCostGold + costGold  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FCCostGold, updCostGold)  | 
|       | 
|     if updCostGold < IpyGameDataPY.GetFuncCfg('CeremonyRankLimit'):  | 
|         return  | 
|       | 
|     #¸üÐÂÅÅÐаñ  | 
|     PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_FCCostGold, updCostGold)  | 
|       | 
|     GameWorld.DebugLog("Íæ¼Ò¾ø°æ½µÁÙÏû·Ñ»î¶¯: curCostGold=%s,costGold=%s,updCostGold=%s"   | 
|                        % (curCostGold, costGold, updCostGold), curPlayer.GetPlayerID())  | 
|     return  | 
|   | 
| #################ÑÌ»¨¿ñ»¶##############################  | 
| def IsCanBuyFireworks(curPlayer, itemIndex):  | 
|     ##µ±Ç°ÊÇ·ñ¿ÉÒÔÂòÑÌ»¨  | 
|     if not __IsAtFCAction():  | 
|         GameWorld.Log('    ÑÌ»¨¿ñ»¶ÂòÑÌ»¨ »î¶¯Î´¿ªÆô, ÎÞ·¨¹ºÂò')  | 
|         return False  | 
|     fireworksDict = IpyGameDataPY.GetFuncEvalCfg('CeremonyFireParty', 1, {})  | 
|     worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Fireworks)  | 
|     canBuyID = fireworksDict.get(str(worldLvNum), 0)  | 
|     if canBuyID != itemIndex:  | 
|         GameWorld.Log('    ÑÌ»¨¿ñ»¶ÂòÑÌ»¨ µ±Ç°¿ÉÒÔÂòÑÌ»¨Îª %s, ÎÞ·¨¹ºÂò %s,worldLvNum=%s'%(canBuyID, itemIndex,worldLvNum), curPlayer.GetID())  | 
|         return False  | 
|     return True |