| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #  | 
| #  | 
| ##@package Operate_PlayerBuyZhenQi  | 
| # @todo:ÆíÔ¸  | 
| # @author sgj  | 
| # @date 2017-10-31 11:30  | 
| # @version 1.0  | 
| #  | 
|   | 
| #------------------------------------------------------------------------------   | 
| #"""Version = 2017-10-31 11:30"""  | 
| #------------------------------------------------------------------------------   | 
| # µ¼Èë  | 
| import GameWorld  | 
| import ChConfig  | 
| import PlayerControl  | 
| import NetPackCommon  | 
| import ChPyNetSendPack  | 
| import IPY_GameWorld  | 
| import IpyGameDataPY  | 
| import PlayerVip  | 
| import time  | 
| import ShareDefine  | 
| import GameFuncComm  | 
| import ItemCommon  | 
| import PlayerSuccess  | 
| import PlayerActivity  | 
| import PlayerBossReborn  | 
| import PlayerFairyCeremony  | 
| import PlayerNewFairyCeremony  | 
| import PlayerActLogin  | 
| import PlayerWeekParty  | 
| import EventShell  | 
| #------------------------------------------------------------------------------   | 
|   | 
| #»ñÈ¡½ð±ÒÆíÔ¸½±Àø  | 
| def GetMoneyPrayAward():  | 
|     return IpyGameDataPY.GetFuncCfg("MoneyPray", 2)  | 
| #»ñÈ¡½ð±ÒÆíÔ¸ÏûºÄ  | 
| def GetMoneyPrayCost():  | 
|     return IpyGameDataPY.GetFuncCfg("MoneyPray", 1)  | 
| #»ñÈ¡¾ÑéÆíÔ¸½±Àø  | 
| def GetExpPrayAward():  | 
|     return IpyGameDataPY.GetFuncCfg("ExpPray", 2)  | 
| #»ñÈ¡¾ÑéÆðÑÛÏûºÄ  | 
| def GetExpPrayCost():  | 
|     return IpyGameDataPY.GetFuncCfg("ExpPray", 1)  | 
|   | 
|   | 
| #ÆíÔ¸ÀàÐÍÁÐ±í  | 
| TotalPrayList = [ChConfig.VIPPrivilege_MoneyPray,ChConfig.VIPPrivilege_ExpPray]  | 
|   | 
|   | 
| #struct    tagCMBuySomething  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        Type;  //14ÍÇ®£¬15¾Ñé  | 
| #};  | 
| ## A5 30 Íæ¼ÒÆíÔ¸  | 
| #  @param index: Íæ¼ÒË÷Òý  | 
| #  @param clientData: ¿Í»§¶Ë·â°üÊý¾Ý  | 
| #  @param tick: Ê±¼ä´Á  | 
| #  @return: None  | 
| def OnPlayerBuySomething(index, clientData, tick):  | 
|       | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|       | 
|     buyType = clientData.Type  #¹ºÂòµÄÀàÐÍ  | 
|     #ÆíÔ¸ÀàÐÍ´íÎ󣬲»´¦Àí  | 
|     if buyType not in TotalPrayList:  | 
|         GameWorld.DebugLog("ÆíÔ¸ÀàÐÍ´íÎó---buyType:%s"%buyType )  | 
|         return  | 
|     if buyType == ChConfig.VIPPrivilege_MoneyPray:  | 
|         if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_RefineMoney):  | 
|             GameWorld.DebugLog("½ð±ÒÆíÔ¸¹¦ÄÜ먦Æô")  | 
|             return  | 
|     elif buyType == ChConfig.VIPPrivilege_ExpPray:  | 
|         if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_RefineExp):  | 
|             GameWorld.DebugLog("¾ÑéÆíÔ¸¹¦ÄÜ먦Æô")  | 
|             return  | 
|       | 
|     totalCnt = PlayerVip.GetPrivilegeValue(curPlayer, buyType)  | 
|     curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HasPrayCnt%buyType)  | 
|     cnt = curCnt+1 #²ÎÊýÓà  | 
|     #½ð±ÒÆíÔ¸  | 
|     if buyType == ChConfig.VIPPrivilege_MoneyPray:  | 
|         historyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HistoryPrayCnt%buyType)  | 
|         #ÅжÏÃâ·ÑÆíÔ¸CDʱ¼ä  | 
|         needTime = __GetFreeCD(curPlayer)  | 
|         if needTime:  | 
|             itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|             needItemID = IpyGameDataPY.GetFuncCfg('FreeExpPrayItem', 2)  | 
|             hasEnough, itemList = ItemCommon.GetItem_FromPack_ByID(needItemID, itemPack, 1)  | 
|             if not hasEnough and totalCnt <= curCnt:  | 
|                 GameWorld.DebugLog("½ð±ÒÆíÔ¸´ÎÊýÒѾÓÃÍ꣬µ±Ç°´ÎÊý:%s,ÿÈÕ×î´ó´ÎÊý:%s" % (curCnt, totalCnt))  | 
|                 return  | 
|             isCostItem = False #ÊÇ·ñʹÓÃÁËÎïÆ·  | 
|             if hasEnough:  | 
|                 #ÓÅÏÈÓÃÎïÆ·  | 
|                 isCostItem = True  | 
|                 ItemCommon.ReduceItem(curPlayer, itemPack, itemList, 1, False)  | 
|             else:  | 
|               | 
|                 infoDict = {ChConfig.Def_Cost_Reason_SonKey:buyType}  | 
|                 needGold = eval(GetMoneyPrayCost())  | 
|                 if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, needGold, ChConfig.Def_Cost_Pray, infoDict):  | 
|                     GameWorld.DebugLog("ÏÉÓñ²»×ã!costGold=%s" % needGold)  | 
|                     return  | 
|             if not isCostItem: #ÓÃÎïÆ·²»Ôö¼Ó´ÎÊý  | 
|                 PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HasPrayCnt%buyType, curCnt + 1)  | 
|         else:  | 
|             curTime = int(time.time())  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FreePrayTime, curTime)  | 
|           | 
|         preCnt, fixMoney =IpyGameDataPY.GetFuncEvalCfg('MoneyPray', 4)  | 
|         GameWorld.DebugLog('11111fixMoney=%s,historyCnt=%s,preCnt=%s'%(fixMoney,historyCnt,preCnt))  | 
|         if fixMoney and historyCnt< preCnt:  | 
|             addMoney = fixMoney  | 
|             #¸üÐÂÀúÊ·´ÎÊý£¨ÌØÊâÊÕÒæ´ÎÊý´ïµ½ºó²»ÔÙ¸üУ©  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HistoryPrayCnt%buyType, historyCnt+1)  | 
|         else:  | 
|             addMoney = GetMoneyPrayAward()  | 
|         addDataDict = {ChConfig.Def_Give_Reason_SonKey:"MoneyPray"}  | 
|         PlayerControl.GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, addMoney,   | 
|                             ChConfig.Def_GiveMoney_Pray, addDataDict, False)  | 
|         PlayerControl.NotifyCode(curPlayer, 'MoneyPray_HowMuch', [addMoney])  | 
|         PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_MoneyPray, 1)  | 
|           | 
|     #¾ÑéÆíÔ¸      | 
|     elif buyType == ChConfig.VIPPrivilege_ExpPray:  | 
|         itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|         needItemID = IpyGameDataPY.GetFuncCfg('FreeExpPrayItem')  | 
|         hasEnough, itemList = ItemCommon.GetItem_FromPack_ByID(needItemID, itemPack, 1)  | 
|         if not hasEnough and totalCnt <= curCnt:  | 
|             GameWorld.DebugLog("¾ÑéÆíÔ¸´ÎÊýÒѾÓÃÍ꣬µ±Ç°´ÎÊý:%s,ÿÈÕ×î´ó´ÎÊý:%s" % (curCnt, totalCnt))  | 
|             return  | 
|         playerLV = curPlayer.GetLV()  | 
|         lvMsg = PlayerControl.GetPlayerLVIpyData(playerLV)  | 
|         if not lvMsg:  | 
|             GameWorld.DebugLog("Íæ¼ÒµÈ¼¶ÐÅÏ¢´íÎó")  | 
|             return  | 
|         isCostItem = False #ÊÇ·ñʹÓÃÁËÎïÆ·  | 
|         if hasEnough:  | 
|             #ÓÅÏÈÓÃÎïÆ·  | 
|             isCostItem = True  | 
|             ItemCommon.ReduceItem(curPlayer, itemPack, itemList, 1, False)  | 
|         else:  | 
|             infoDict = {ChConfig.Def_Cost_Reason_SonKey:buyType}  | 
|             needGold = eval(GetExpPrayCost())  | 
|             GameWorld.DebugLog("ÐèÒªÏÉÓñ--needGold--%s"%needGold )  | 
|             if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, needGold, ChConfig.Def_Cost_Pray, infoDict):  | 
|                 GameWorld.DebugLog("ÏÉÓñ²»×ã!costGold=%s" % needGold)  | 
|                 return     | 
|       | 
|         reExp = lvMsg.GetReExp()  | 
|         exp = PlayerControl.GetLVUPTotalExpNeed(lvMsg)  | 
|         addExp = eval(GetExpPrayAward())  | 
|         PlayerControl.PlayerControl(curPlayer).AddExp(addExp)  | 
|         PlayerControl.NotifyCode(curPlayer, 'ExpPray_HowMuch', [addExp])  | 
|         if not isCostItem: #ÓÃÎïÆ·²»Ôö¼Ó´ÎÊý  | 
|             PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HasPrayCnt%buyType, curCnt + 1)  | 
|         PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_ExpPray, 1)  | 
|     else:  | 
|         return  | 
|     EventShell.EventRespons_Pray(curPlayer, buyType)  | 
|     #³É¾Í  | 
|     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Pray, 1, [buyType])  | 
|     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_FeastRedPack_Pray, 1)  | 
|       | 
|     # Ã¿Èջ  | 
|     PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_Pray)  | 
|     PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_Pray, 1)  | 
|     PlayerNewFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_Pray, 1)  | 
|     PlayerActLogin.AddLoginAwardActionCnt(curPlayer, ChConfig.Def_LoginAct_Pray, 1)  | 
|     PlayerWeekParty.AddWeekPartyActionCnt(curPlayer, ChConfig.Def_WPAct_Pray, 1)  | 
|     Sync_NotifyDataChange(curPlayer, [buyType])  | 
|     return  | 
|   | 
| #»ñÈ¡Ãâ·Ñ½ð±ÒÆíÔ¸CD  | 
| def __GetFreeCD(curPlayer):  | 
|     lastTime = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FreePrayTime)  | 
|     curTime = int(time.time())  | 
|     passTime = curTime - lastTime  | 
|     cdTime = IpyGameDataPY.GetFuncCfg("MoneyPray", 3)  | 
|     needTime = max(0,cdTime - passTime)  | 
|     return needTime  | 
|       | 
| ## OnDay²Ù×÷£¬Í¨Öª¿Í»§¶Ë£¬¹ºÂò´ÎÊý±äÁË  | 
| #  @param curPlayer: Íæ¼ÒʵÀý  | 
| #  @return None  | 
| def PlayerOnDay(curPlayer):  | 
|     needSyncList = []  | 
|     for prayType in TotalPrayList:  | 
|         hasPrayCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HasPrayCnt%prayType)  | 
|         if not hasPrayCnt:  | 
|             continue  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_HasPrayCnt%prayType, 0)  | 
|         needSyncList.append(prayType)  | 
|     Sync_NotifyDataChange(curPlayer, needSyncList)  | 
|     return  | 
|           | 
|   | 
| ## Í¨Öª¿Í»§¶Ë£¬¹ºÂò´ÎÊý±äÁË  | 
| #  @param curPlayer: Íæ¼ÒʵÀý  | 
| #  @return None  | 
| def Sync_NotifyDataChange(curPlayer, prayType = []):  | 
|     if prayType == []:  | 
|         prayList = TotalPrayList  | 
|     else:  | 
|         prayList = prayType  | 
|     pack = ChPyNetSendPack.tagMCBuySomething()  | 
|     for buyType in prayList:  | 
|         subPack = ChPyNetSendPack.tagMCSingleBuySomethingInfo()  | 
|         subPack.Type = buyType  | 
|         subPack.BuyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HasPrayCnt%buyType)  | 
|         subPack.HistoryBuyCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_HistoryPrayCnt%buyType)  | 
|           | 
|         if buyType == ChConfig.VIPPrivilege_MoneyPray:  | 
|             subPack.LastFreeTime = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FreePrayTime)  | 
|         pack.Infos.append(subPack)  | 
|         GameWorld.DebugLog("֪ͨÆíÔ¸´ÎÊý--buyType:%s--BuyCnt:%s--LastFreeTime%s" % (subPack.Type,subPack.BuyCnt,subPack.LastFreeTime))  | 
|     pack.Cnt = len(pack.Infos)  | 
|     NetPackCommon.SendFakePack(curPlayer, pack)  | 
|       | 
|   | 
| ## Íæ¼ÒµÇ¼ʱ֪ͨ  | 
| #  @param curPlayer: Íæ¼ÒʵÀý  | 
| #  @return None  | 
| def DoPlayerLogin(curPlayer):  | 
|     Sync_NotifyDataChange(curPlayer)  | 
|     return  | 
|      |