#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package Player.PlayerActBuyCountGift
|
#
|
# @todo:¹ºÂò´ÎÊýÀñ°ü»î¶¯
|
# @author hxp
|
# @date 2024-06-05
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: ¹ºÂò´ÎÊýÀñ°ü»î¶¯
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2024-06-05 12:00"""
|
#-------------------------------------------------------------------------------
|
|
import PyGameData
|
import ShareDefine
|
import PlayerControl
|
import IpyGameDataPY
|
import ChPyNetSendPack
|
import FunctionNPCCommon
|
import DataRecordPack
|
import NetPackCommon
|
import ItemControler
|
import IPY_GameWorld
|
import PlayerCoin
|
import GameWorld
|
import ChConfig
|
|
def OnDay(curPlayer, onEventType):
|
OnCheckRelateFuncAct(curPlayer)
|
if onEventType != ShareDefine.Def_OnEventType:
|
return
|
for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BuyCountGift, {}).values():
|
if not actInfo.get(ShareDefine.ActKey_State):
|
continue
|
actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
|
if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum):
|
continue
|
ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
|
if not ipyData:
|
continue
|
CTGCountDayResetList = ipyData.GetCTGCountDayResetList()
|
if not CTGCountDayResetList:
|
continue
|
|
awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftAward % actNum)
|
for buyCount in CTGCountDayResetList:
|
awardRecord = GameWorld.SetBitValue(awardRecord, buyCount, 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftAward % actNum, awardRecord)
|
Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
|
|
return
|
|
def OnPlayerLogin(curPlayer):
|
|
for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BuyCountGift, {}).values():
|
actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
isReset = __CheckPlayerBuyCountGiftAction(curPlayer, actNum)
|
# »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
|
if not isReset and actInfo.get(ShareDefine.ActKey_State) and curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum):
|
Sync_BuyCountGiftActionInfo(curPlayer, actNum)
|
Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
|
|
return
|
|
def OnCheckRelateFuncAct(curPlayer, openFuncIDList=None):
|
## ¼ì²é¹ØÁª¹¦ÄÜID¿ªÆôµÄ»î¶¯
|
for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BuyCountGift, {}).values():
|
if not actInfo.get(ShareDefine.ActKey_State):
|
continue
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
|
if not ipyData:
|
continue
|
if not hasattr(ipyData, "GetRelateFuncID"):
|
continue
|
relateFuncID = ipyData.GetRelateFuncID()
|
if not relateFuncID:
|
continue
|
if openFuncIDList and relateFuncID not in openFuncIDList:
|
continue
|
actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
__CheckPlayerBuyCountGiftAction(curPlayer, actNum)
|
|
return
|
|
def RefreshBuyCountGiftActionInfo(actNum):
|
## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
|
playerManager = GameWorld.GetPlayerManager()
|
for index in xrange(playerManager.GetPlayerCount()):
|
curPlayer = playerManager.GetPlayerByIndex(index)
|
if not GameWorld.IsNormalPlayer(curPlayer):
|
continue
|
__CheckPlayerBuyCountGiftAction(curPlayer, actNum)
|
|
return
|
|
def __CheckPlayerBuyCountGiftAction(curPlayer, actNum):
|
## ¼ì²éÍæ»î¶¯Êý¾ÝÐÅÏ¢
|
|
playerID = curPlayer.GetPlayerID()
|
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_BuyCountGift, actNum)
|
actID = actInfo.get(ShareDefine.ActKey_ID, 0)
|
state = actInfo.get(ShareDefine.ActKey_State, 0)
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
|
|
playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum) # Íæ¼ÒÉíÉϵĻID
|
|
funcActInfo = GameWorld.GetActRelateFuncInfo(curPlayer, "ActBuyCountGift", actInfo, playerActID)
|
if funcActInfo:
|
isInAct, actID = funcActInfo
|
if not isInAct:
|
return
|
|
# »î¶¯ID ÏàͬµÄ»°²»´¦Àí
|
if actID == playerActID:
|
GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°ü»î¶¯ID²»±ä£¬²»´¦Àí£¡ actNum=%s,cfgID=%s,actID=%s" % (actNum, cfgID, actID), curPlayer.GetPlayerID())
|
return
|
GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÖØÖÃ! actNum=%s,cfgID=%s,actID=%s,playerActID=%s,state=%s" % (actNum, cfgID, actID, playerActID, state), playerID)
|
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftID % actNum, actID)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftAward % actNum, 0)
|
|
if state:
|
# ÖØÖóäÖµID³äÖµ¼Ç¼
|
__ResetCTGIDCount(curPlayer, actInfo)
|
|
Sync_BuyCountGiftActionInfo(curPlayer, actNum)
|
Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
|
|
return True
|
|
def __ResetCTGIDCount(curPlayer, actInfo):
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
|
if not ipyData:
|
return
|
resetCTGIDList = ipyData.GetCTGIDList()
|
PlayerCoin.DoResetCTGCountByIDList(curPlayer, "ActBuyCountGift", resetCTGIDList)
|
|
shopType = ipyData.GetActShopType()
|
if shopType:
|
FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, [shopType])
|
return
|
|
def OnGetBuyCountGiftAward(curPlayer, buyCount, actNum):
|
playerID = curPlayer.GetPlayerID()
|
|
actNum = GameWorld.ToIntDef(actNum, 0)
|
if actNum <= 0:
|
GameWorld.DebugLog("ûÓÐÖ¸¶¨ÁìÈ¡µÄ»î¶¯±àºÅ! actNum=%s" % actNum, playerID)
|
return
|
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_BuyCountGift, actNum)
|
|
if not actInfo.get(ShareDefine.ActKey_State):
|
GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°ü·Ç»î¶¯ÖÐÎÞ·¨ÁìÈ¡½±Àø! actNum=%s" % actNum, playerID)
|
return
|
if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum):
|
return
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
|
ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
|
if not ipyData:
|
return
|
CTGIDList = ipyData.GetCTGIDList()
|
CTGCountAwardInfo = ipyData.GetCTGCountAwardInfo()
|
if buyCount not in CTGCountAwardInfo:
|
GameWorld.DebugLog("¹ºÂò´ÎÊýÀñ°üûÓиôÎÊýÀñ°ü½±Àø! actNum=%s,cfgID=%s,buyCount=%s" % (actNum, cfgID, buyCount), playerID)
|
return
|
awardItemList = CTGCountAwardInfo[buyCount]
|
|
awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftAward % actNum)
|
if awardRecord & pow(2, buyCount):
|
GameWorld.Log("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÒѾÁìÈ¡¹ý¸Ã½±Àø! actNum=%s,cfgID=%s,buyCount=%s,awardRecord=%s"
|
% (actNum, cfgID, buyCount, awardRecord), playerID)
|
return
|
|
totalBuyCount = 0
|
for ctgID in CTGIDList:
|
totalBuyCount += curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % ctgID)
|
|
if totalBuyCount < buyCount:
|
GameWorld.Log("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÀۼƹºÂò´ÎÊý²»×㣬ÎÞ·¨Ãâ·ÑÁìÈ¡! actNum=%s,cfgID=%s,CTGIDList=%s,totalBuyCount=%s < %s"
|
% (actNum, cfgID, CTGIDList, totalBuyCount, buyCount), playerID)
|
return
|
|
# ¼ì²é±³°ü
|
if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
|
return
|
|
awardRecord |= pow(2, buyCount)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BuyCountGiftAward % actNum, awardRecord)
|
Sync_BuyCountGiftPlayerInfo(curPlayer, actNum)
|
|
for itemID, itemCount, isAuctionItem in awardItemList:
|
ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], event=["ActBuyCountGift", False, {}])
|
ItemControler.NotifyGiveAwardInfo(curPlayer, awardItemList, "ActBuyCountGift")
|
|
addDataDict = {"actNum":actNum, "cfgID":cfgID, "buyCount":buyCount, "awardItemList":str(awardItemList)}
|
DataRecordPack.DR_FuncGiveItem(curPlayer, "ActBuyCountGift", addDataDict)
|
GameWorld.Log("¹ºÂò´ÎÊýÀñ°ü»î¶¯ÁìÈ¡½±Àø! actNum=%s,cfgID=%s,buyCount=%s,awardItemList=%s"
|
% (actNum, cfgID, buyCount, awardItemList), playerID)
|
return
|
|
def Sync_BuyCountGiftPlayerInfo(curPlayer, actNum):
|
## ֪ͨÍæ¼ÒÊý¾ÝÐÅÏ¢
|
clientPack = ChPyNetSendPack.tagMCActBuyCountGiftPlayerInfo()
|
clientPack.ActNum = actNum
|
clientPack.GiftAwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftAward % actNum)
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|
|
def Sync_BuyCountGiftActionInfo(curPlayer, actNum):
|
## ֪ͨ»î¶¯ÐÅÏ¢
|
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_BuyCountGift, actNum)
|
if not actInfo.get(ShareDefine.ActKey_State):
|
return
|
playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BuyCountGiftID % actNum)
|
if not playerActID:
|
return
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActBuyCountGift", cfgID)
|
if not ipyData:
|
return
|
CTGCountAwardInfo = ipyData.GetCTGCountAwardInfo()
|
|
if hasattr(ipyData, "GetRelateFuncID") and ipyData.GetRelateFuncID():
|
startDateStr, endDateStr = GameWorld.GetActRelateFuncDate(ipyData, playerActID, True)
|
else:
|
startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
|
startDateSync = actInfo.get(ShareDefine.ActKey_StartDateSync, startDateStr)
|
actInfo = ChPyNetSendPack.tagMCActBuyCountGiftInfo()
|
actInfo.ActNum = actNum
|
actInfo.StartDate = startDateSync
|
actInfo.EndtDate = endDateStr
|
actInfo.LimitLV = ipyData.GetLVLimit()
|
actInfo.IsDayReset = ipyData.GetIsDayReset()
|
actInfo.ResetType = ipyData.GetResetType()
|
actInfo.ShopType = ipyData.GetActShopType()
|
actInfo.CTGIDList = ipyData.GetCTGIDList()
|
actInfo.CTGIDCount = len(actInfo.CTGIDList)
|
|
actInfo.BuyCountGiftList = []
|
for buyCount, awardItemList in CTGCountAwardInfo.items():
|
giftbag = ChPyNetSendPack.tagMCActBuyCountGift()
|
giftbag.NeedBuyCount = buyCount
|
giftbag.AwardItemList = []
|
for itemID, itemCount, isAuctionItem in awardItemList:
|
giftItem = ChPyNetSendPack.tagMCActBuyCountGiftItem()
|
giftItem.ItemID = itemID
|
giftItem.ItemCount = itemCount
|
giftItem.IsBind = isAuctionItem
|
giftbag.AwardItemList.append(giftItem)
|
giftbag.Count = len(giftbag.AwardItemList)
|
actInfo.BuyCountGiftList.append(giftbag)
|
actInfo.GiftCount = len(actInfo.BuyCountGiftList)
|
|
NetPackCommon.SendFakePack(curPlayer, actInfo)
|
return
|