#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#-------------------------------------------------------------------------------  
 | 
#  
 | 
##@package Player.PlayerLuckyCloudBuy  
 | 
#  
 | 
# @todo:ÐÒÔËÔÆ¹º  
 | 
# @author hxp  
 | 
# @date 2021-10-21  
 | 
# @version 1.0  
 | 
#  
 | 
# ÏêϸÃèÊö: ÐÒÔËÔÆ¹º  
 | 
#  
 | 
#-------------------------------------------------------------------------------  
 | 
#"""Version = 2021-10-21 17:00"""  
 | 
#-------------------------------------------------------------------------------  
 | 
  
 | 
import ChConfig  
 | 
import PyGameData  
 | 
import ShareDefine  
 | 
import PlayerControl  
 | 
import IpyGameDataPY  
 | 
import CrossRealmPlayer  
 | 
import ChPyNetSendPack  
 | 
import IPY_GameWorld  
 | 
import NetPackCommon  
 | 
import ItemControler  
 | 
import ItemCommon  
 | 
import GameWorld  
 | 
  
 | 
def OnPlayerLogin(curPlayer):  
 | 
      
 | 
    if GameWorld.IsCrossServer():  
 | 
        return  
 | 
      
 | 
    if not CrossRealmPlayer.IsCrossServerOpen():  
 | 
        return  
 | 
      
 | 
    __CheckLuckyCloudBuyID(curPlayer)  
 | 
    Sync_LuckyCloudBuyPlayerInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
def OnLuckyCloudBuyChange():  
 | 
      
 | 
    if GameWorld.IsCrossServer():  
 | 
        return  
 | 
      
 | 
    if not CrossRealmPlayer.IsCrossServerOpen():  
 | 
        return  
 | 
      
 | 
    playerManager = GameWorld.GetPlayerManager()  
 | 
    for index in xrange(playerManager.GetPlayerCount()):  
 | 
        curPlayer = playerManager.GetPlayerByIndex(index)  
 | 
        if curPlayer.GetID() == 0:  
 | 
            continue  
 | 
        __CheckLuckyCloudBuyID(curPlayer)  
 | 
        Sync_LuckyCloudBuyPlayerInfo(curPlayer) # ¸Ã¹¦ÄÜÊÕµ½¾Íͬ²½£¬²»ÂÛÓÐûÓÐÖØÖã¬ÒòΪ¿ÉÄÜÓÉ¿ç·þ¹Ø±Õ±äΪ¿ªÆôʱµÄÊý¾Ýͬ²½  
 | 
          
 | 
    return  
 | 
  
 | 
def __CheckLuckyCloudBuyID(curPlayer):  
 | 
      
 | 
    roundID = PyGameData.g_luckyCloudBuyInfo.get("idTime", 0)  
 | 
    playerRoundID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_RoundID) # Íæ¼ÒÉíÉϵĻID  
 | 
    if playerRoundID == roundID:  
 | 
        GameWorld.DebugLog("ÐÒÔËÔÆ¹º½±ÀøÆÚIDÏàͬ£¬²»ÖØÖÃ! playerRoundID=%s,roundID=%s" % (playerRoundID, roundID), curPlayer.GetPlayerID())  
 | 
        return  
 | 
    GameWorld.DebugLog("ÐÒÔËÔÆ¹º½±ÀøÆÚID±ä¸ü£¬ÖØÖÃ! playerRoundID=%s,roundID=%s" % (playerRoundID, roundID), curPlayer.GetPlayerID())  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LuckyCloudBuy_RoundID, roundID)  
 | 
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LuckyCloudBuy_BuyCount, 0)  
 | 
    return True  
 | 
  
 | 
#// C1 10 ÐÒÔËÔÆ¹º¹ºÂò #tagCMLuckyCloudBuy  
 | 
#  
 | 
#struct    tagCMLuckyCloudBuy  
 | 
#{  
 | 
#    tagHead        Head;  
 | 
#    BYTE        BuyCount;    // ¹ºÂò´ÎÊý  
 | 
#};  
 | 
def OnLuckyCloudBuy(index, clientData, tick):  
 | 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  
 | 
    accID = curPlayer.GetAccID()  
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
    buyCount = clientData.BuyCount  
 | 
      
 | 
    if GameWorld.IsCrossServer():  
 | 
        return  
 | 
      
 | 
    if not CrossRealmPlayer.IsCrossServerOpen():  
 | 
        PlayerControl.NotifyCode(curPlayer, "CrossMatching18")  
 | 
        return  
 | 
      
 | 
    unLimitHour, unLimitMinute = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 3)  
 | 
    crossServerDateTime = GameWorld.ChangeStrToDatetime(GameWorld.GetCrossServerTimeStr())  
 | 
    unLimitDateTime = GameWorld.ChangeStrToDatetime("%d-%d-%d %d:%d:00" \  
 | 
                                % (crossServerDateTime.year, crossServerDateTime.month, crossServerDateTime.day, unLimitHour, unLimitMinute))  
 | 
      
 | 
    if crossServerDateTime >= unLimitDateTime:  
 | 
        GameWorld.DebugLog("µ±Ç°¿ç·þ·þÎñÆ÷ʱ¼ä²»ÏÞÖÆÐÒÔËÔÆ¹º¹ºÂò´ÎÊýÁË! crossServerDateTime=%s,unLimitHour=%s,unLimitMinute=%s"   
 | 
                           % (crossServerDateTime, unLimitHour, unLimitMinute))  
 | 
    else:  
 | 
        hadBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_BuyCount)  
 | 
        vipLV = curPlayer.GetVIPLv()  
 | 
        gmLVLimitBuyCountList = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 2)  
 | 
        maxBuyCount = gmLVLimitBuyCountList[vipLV] if len(gmLVLimitBuyCountList) > vipLV else gmLVLimitBuyCountList[-1]  
 | 
        if hadBuyCount + buyCount > maxBuyCount:  
 | 
            GameWorld.DebugLog("ÐÒÔËÔÆ¹º¹ºÂò´ÎÊýÏÞÖÆ! hadBuyCount=%s,buyCount=%s,vipLV=%s,maxBuyCount=%s,crossServerDateTime=%s"   
 | 
                               % (hadBuyCount, buyCount, vipLV, maxBuyCount, crossServerDateTime))  
 | 
            return  
 | 
          
 | 
    buyCountCostMoneyDict = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 1, {})  
 | 
    if str(buyCount) not in buyCountCostMoneyDict:  
 | 
        return  
 | 
    costMoneyType, costMoneyValue = buyCountCostMoneyDict[str(buyCount)]  
 | 
    if not PlayerControl.HaveMoney(curPlayer, costMoneyType, costMoneyValue):  
 | 
        return  
 | 
      
 | 
    needSpace = min(buyCount, 10)  
 | 
    emptySpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)  
 | 
    if needSpace > emptySpace:  
 | 
        PlayerControl.NotifyCode(curPlayer, "GeRen_lhs_202580")  
 | 
        return  
 | 
      
 | 
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_LuckyCloudBuy, tick):  
 | 
        PlayerControl.NotifyCode(curPlayer, "RequestLater")  
 | 
        return  
 | 
      
 | 
    GameWorld.Log("ÐÒÔËÔÆ¹º¹ºÂò: buyCount=%s" % (buyCount), playerID)  
 | 
      
 | 
    dataMsg = {"accID":accID,  
 | 
               "playerID":playerID,  
 | 
               "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),  
 | 
               "buyCount":buyCount,  
 | 
               "roundID":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_RoundID),  
 | 
               }  
 | 
    GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_LuckyCloudBuy, dataMsg)  
 | 
    return  
 | 
  
 | 
def GameServer_LuckyCloudBuy(curPlayer, msgData):  
 | 
    msgType = msgData[0]  
 | 
    if msgType == "LuckyCloudBuyNum":  
 | 
        CrossServerMsg_LuckyCloudBuyNum(curPlayer, msgData)  
 | 
          
 | 
    return  
 | 
  
 | 
def CrossServerMsg_LuckyCloudBuyNum(curPlayer, msgData):  
 | 
          
 | 
    playerID = curPlayer.GetPlayerID()  
 | 
    _, roundID, buyCount, awardItemList = msgData  
 | 
      
 | 
    # ÏûºÄÇ®¼°½±Àø±ØÐëÖ´ÐУ¬Ôö¼Ó´ÎÊýÐèͬһ¸öÂÖ´ÎID  
 | 
    playerRoundID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_RoundID)  
 | 
    hadBuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_BuyCount)  
 | 
    GameWorld.Log("µØÍ¼Íæ¼ÒÊÕµ½ÐÒÔËÔÆ¹º¹ºÂò½áËãÐÅÏ¢! playerRoundID=%s,hadBuyCount=%s, roundID=%s,buyCount=%s"   
 | 
                  % (playerRoundID, hadBuyCount, roundID, buyCount), playerID)  
 | 
      
 | 
    buyCountCostMoneyDict = IpyGameDataPY.GetFuncEvalCfg("LuckyCloudBuyCost", 1, {})  
 | 
    if str(buyCount) not in buyCountCostMoneyDict:  
 | 
        return  
 | 
    costMoneyType, costMoneyValue = buyCountCostMoneyDict[str(buyCount)]  
 | 
      
 | 
    if not PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, "LuckyCloudBuy"):  
 | 
        return  
 | 
      
 | 
    if roundID == playerRoundID:  
 | 
        updBuyCount = hadBuyCount + buyCount  
 | 
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LuckyCloudBuy_BuyCount, updBuyCount)  
 | 
        GameWorld.Log("    ¸üÐÂÐÒÔËÔÆ¹º¹ºÂò´ÎÊý: updBuyCount=%s" % (updBuyCount), playerID)  
 | 
          
 | 
    GameWorld.Log("    ½áËãÐÒÔËÔÆ¹º¹ºÂò½±Àø: awardItemList=%s" % str(awardItemList), playerID)  
 | 
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["LuckyCloudBuy", False, {}])  
 | 
      
 | 
    Sync_LuckyCloudBuyPlayerInfo(curPlayer)  
 | 
    return  
 | 
  
 | 
def Sync_LuckyCloudBuyPlayerInfo(curPlayer):  
 | 
    clientPack = ChPyNetSendPack.tagMCLuckyCloudBuyPlayerInfo()  
 | 
    clientPack.BuyCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LuckyCloudBuy_BuyCount)  
 | 
    NetPackCommon.SendFakePack(curPlayer, clientPack)  
 | 
    return  
 | 
  
 |