#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package Player.PlayerActSingleRecharge
|
#
|
# @todo:µ¥±ÊÀÛ³ä»î¶¯
|
# @author hxp
|
# @date 2021-04-07
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: µ¥±ÊÀÛ³ä»î¶¯
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2021-04-07 17:30"""
|
#-------------------------------------------------------------------------------
|
|
import PyGameData
|
import ShareDefine
|
import PlayerControl
|
import IpyGameDataPY
|
import ItemControler
|
import ChPyNetSendPack
|
import IPY_GameWorld
|
import NetPackCommon
|
import GameWorld
|
import ChConfig
|
import CommFunc
|
|
def GetTemplateID(cfgID, dayIndex):
|
if not cfgID or dayIndex == None:
|
return 0
|
ipyData = IpyGameDataPY.GetIpyGameData("ActSingleRecharge", cfgID)
|
if not ipyData:
|
return 0
|
templateIDList = ipyData.GetTemplateIDList()
|
templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex]
|
return templateID
|
|
def OnPlayerLogin(curPlayer):
|
|
for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SingleRecharge, {}).values():
|
actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
isReset = __CheckPlayerSingleRechargeAction(curPlayer, actNum)
|
if not isReset:
|
# »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
|
if actInfo.get(ShareDefine.ActKey_State):
|
Sync_SingleRechargeActionInfo(curPlayer, actNum)
|
Sync_SingleRechargePlayerInfo(curPlayer, actNum)
|
|
return
|
|
def RefreshSingleRechargeActionInfo(actNum):
|
## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
|
playerManager = GameWorld.GetPlayerManager()
|
for index in xrange(playerManager.GetPlayerCount()):
|
curPlayer = playerManager.GetPlayerByIndex(index)
|
if not GameWorld.IsNormalPlayer(curPlayer):
|
continue
|
__CheckPlayerSingleRechargeAction(curPlayer, actNum)
|
return
|
|
def __CheckPlayerSingleRechargeAction(curPlayer, actNum):
|
## ¼ì²éÍæ¼Ò»î¶¯Êý¾ÝÐÅÏ¢
|
|
playerID = curPlayer.GetPlayerID()
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_SingleRecharge, actNum)
|
actID = actInfo.get(ShareDefine.ActKey_ID, 0)
|
state = actInfo.get(ShareDefine.ActKey_State, 0)
|
|
playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleRechargeID % actNum) # Íæ¼ÒÉíÉϵĻID
|
playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleRechargeTemplateID % actNum)
|
|
templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))
|
|
# »î¶¯ID ÏàͬµÄ»°²»´¦Àí
|
if actID == playerActID:
|
GameWorld.DebugLog("µ¥±ÊÀÛ³ä»î¶¯ID²»±ä£¬²»´¦Àí£¡actNum=%s,actID=%s" % (actNum, actID), playerID)
|
if state and templateID and templateID != playerTemplateID:
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleRechargeTemplateID % actNum, templateID)
|
Sync_SingleRechargeActionInfo(curPlayer, actNum)
|
Sync_SingleRechargePlayerInfo(curPlayer, actNum)
|
GameWorld.DebugLog(" »î¶¯ÖиüÐÂÄ£°åID: templateID=%s" % templateID, playerID)
|
|
return
|
|
actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)
|
playerWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleRechargeWorldLV % actNum)
|
|
GameWorld.DebugLog("µ¥±ÊÀÛ³äÖØÖÃ! actNum=%s,actID=%s,playerActID=%s,state=%s,templateID=%s,playerTemplateID=%s"
|
% (actNum, actID, playerActID, state, templateID, playerTemplateID), playerID)
|
|
# δÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å
|
__SendSingleRechargeMail(curPlayer, playerTemplateID, playerWorldLV, actNum)
|
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleRechargeID % actNum, actID)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleRechargeTemplateID % actNum, templateID)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleRechargeWorldLV % actNum, actWorldLV)
|
if actID and templateID:
|
ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActSingleRechargeAward", templateID)
|
if ipyDataList:
|
for ipyData in ipyDataList:
|
awardIndex = ipyData.GetAwardIndex()
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleRechargeValue % (actNum, awardIndex), 0)
|
|
Sync_SingleRechargeActionInfo(curPlayer, actNum)
|
Sync_SingleRechargePlayerInfo(curPlayer, actNum)
|
return True
|
|
def GetAwardCountInfo(curPlayer, actNum, awardIndex):
|
valueInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleRechargeValue % (actNum, awardIndex))
|
getCount = valueInfo / 1000
|
canGetCount = valueInfo % 1000
|
return getCount, canGetCount
|
def SetAwardCountInfo(curPlayer, actNum, awardIndex, getCount, canGetCount):
|
valueInfo = getCount * 1000 + canGetCount
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleRechargeValue % (actNum, awardIndex), valueInfo)
|
return valueInfo
|
|
def __SendSingleRechargeMail(curPlayer, playerTemplateID, playerWorldLV, actNum):
|
# δÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å
|
|
if not playerTemplateID:
|
return
|
|
ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActSingleRechargeAward", playerTemplateID)
|
if not ipyDataList:
|
return
|
|
playerID = curPlayer.GetPlayerID()
|
batchPlayerIDList, batchAddItemList, batchParamList = [], [], []
|
|
for ipyData in ipyDataList:
|
awardIndex = ipyData.GetAwardIndex()
|
getCount, canGetCount = GetAwardCountInfo(curPlayer, actNum, awardIndex)
|
if getCount >= canGetCount:
|
#GameWorld.DebugLog("µ¥±ÊÀÛ³äÒѾȫ²¿Áì½±£¡awardIndex=%s" % awardIndex)
|
continue
|
SetAwardCountInfo(curPlayer, actNum, awardIndex, canGetCount, canGetCount)
|
|
unGetCount = canGetCount - getCount
|
singleValue = ipyData.GetSingleRechargeValue()
|
awardItemList = GameWorld.GetDictValueByRangeKey(ipyData.GetAwardItem(), playerWorldLV, [])
|
for _ in range(unGetCount):
|
batchPlayerIDList.append([playerID])
|
batchAddItemList.append(awardItemList)
|
batchParamList.append([singleValue])
|
|
if batchPlayerIDList:
|
PlayerControl.SendMailBatch("SingleRechargeMail%s" % actNum, batchPlayerIDList, batchAddItemList, batchParamList)
|
|
return
|
|
def UpdSingleRechargeValue(curPlayer, curRechargeValue, coinType):
|
if curRechargeValue <= 0:
|
return
|
|
for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_SingleRecharge, {}).values():
|
actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
if not actInfo.get(ShareDefine.ActKey_State):
|
GameWorld.DebugLog("µ¥±ÊÀÛ³ä»î¶¯µ±Ç°Î´¿ªÆô! actNum=%s" % actNum)
|
continue
|
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
|
if not cfgID:
|
continue
|
|
ipyData = IpyGameDataPY.GetIpyGameData("ActSingleRecharge", cfgID)
|
if not ipyData:
|
continue
|
|
ctgTypeEffValue = ipyData.GetCTGTypeEffValue()
|
if not ctgTypeEffValue & pow(2, coinType):
|
GameWorld.DebugLog("µ¥±ÊÀÛ³ä³äÖµ»î¶¯£¬³äÖµÀàÐͶԸûÎÞЧ! actNum=%s,coinType=%s,ctgTypeEffValue=%s"
|
% (actNum, coinType, ctgTypeEffValue), curPlayer.GetPlayerID())
|
continue
|
|
templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))
|
if not templateID:
|
GameWorld.ErrLog("µ¥±ÊÀÛ³ä³äÖµ»î¶¯Êý¾ÝÒì³£!cfgID=%s,templateID=%s" % (cfgID, templateID), curPlayer.GetPlayerID())
|
continue
|
|
awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActSingleRechargeAward", templateID)
|
if not awardIpyDataList:
|
continue
|
|
awardIndexList = []
|
awardRuleType = ipyData.GetAwardRuleType()
|
GameWorld.DebugLog("µ¥±ÊÀÛ³ä³äÖµ»î¶¯£¬actNum=%s,awardRuleType=%s,curRechargeValue=%s" % (actNum, awardRuleType, curRechargeValue))
|
# ÏòϼæÈÝËùÓеµ´Î
|
if awardRuleType == 0:
|
pass
|
# Æ¥Åä×î¸ßµµ´Î
|
elif awardRuleType == 1:
|
pass
|
# ¾«È·Æ¥Åä¶ÔÓ¦µµ´Î
|
elif awardRuleType == 2:
|
for awardIpyData in awardIpyDataList:
|
awardIndex = awardIpyData.GetAwardIndex()
|
singleValue = CommFunc.RMBToCoin(awardIpyData.GetSingleRechargeValue())
|
if curRechargeValue != singleValue:
|
#GameWorld.DebugLog(" ²»µÈÓÚµµ´Î¶î¶È£¬²»´¦Àí£¡awardRuleType=%s,awardIndex=%s,singleValue=%s"
|
# % (awardRuleType, awardIndex, singleValue))
|
continue
|
awardCountMax = awardIpyData.GetAwardCountMax()
|
getCount, canGetCount = GetAwardCountInfo(curPlayer, actNum, awardIndex)
|
if canGetCount >= awardCountMax:
|
GameWorld.DebugLog(" ÒÑ´ï×î´ó¿ÉÁì½±´ÎÊý£¬²»´¦Àí£¡awardRuleType=%s,awardIndex=%s,awardCountMax=%s" % (awardRuleType, awardIndex, awardCountMax))
|
break
|
|
awardIndexList.append(awardIndex)
|
canGetCount += 1
|
SetAwardCountInfo(curPlayer, actNum, awardIndex, getCount, canGetCount)
|
GameWorld.DebugLog(" ÉèÖþ«È·µµ´Î¿ÉÁìÈ¡£¡awardRuleType=%s,awardIndex=%s,singleValue=%s,canGetCount=%s"
|
% (awardRuleType, awardIndex, singleValue, canGetCount))
|
break
|
|
else:
|
continue
|
|
if not awardIndexList:
|
continue
|
|
Sync_SingleRechargePlayerInfo(curPlayer, actNum, awardIndexList)
|
|
# ÏßÏ»£¬¼ì²é·¢·Å½±Àø
|
if ipyData.GetIsOfflineAct():
|
playerWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleRechargeWorldLV % actNum)
|
__SendSingleRechargeMail(curPlayer, templateID, playerWorldLV, actNum)
|
|
return
|
|
def OnGetSingleRechargeAward(curPlayer, awardIndex, actNum):
|
'''ÁìÈ¡½±Àø
|
@param awardIndex: ½±ÀøË÷Òý
|
@param actNum: »î¶¯±àºÅ£¬Èç11 »ò 12 ´ú±í²»Í¬µÄ»î¶¯
|
'''
|
actNum = GameWorld.ToIntDef(actNum, 0)
|
if actNum <= 0:
|
GameWorld.DebugLog("ûÓÐÖ¸¶¨ÁìÈ¡µÄ»î¶¯±àºÅ! actNum=%s" % actNum)
|
return
|
|
playerID = curPlayer.GetPlayerID()
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_SingleRecharge, actNum)
|
|
state = actInfo.get(ShareDefine.ActKey_State, 0)
|
templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))
|
if not state or not templateID:
|
GameWorld.DebugLog("¸Ãµ¥±ÊÀÛ³ä»î¶¯·Ç»î¶¯ÖУ¬ÎÞ·¨Áì½±£¡actNum=%s,state=%s,templateID=%s" % (actNum, state, templateID), playerID)
|
return
|
|
ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActSingleRechargeAward", templateID)
|
if not ipyDataList:
|
return
|
|
awardIpyData = None
|
for ipyData in ipyDataList:
|
if ipyData.GetAwardIndex() == awardIndex:
|
awardIpyData = ipyData
|
break
|
|
if not awardIpyData:
|
GameWorld.DebugLog("ÕÒ²»µ½¸Ãµ¥±ÊÀÛ³ä»î¶¯µµÎ»Ë÷Òý½±Àø!actNum=%s,templateID=%s,awardIndex=%s" % (actNum, templateID, awardIndex), playerID)
|
return
|
|
getCount, canGetCount = GetAwardCountInfo(curPlayer, actNum, awardIndex)
|
if getCount >= canGetCount:
|
GameWorld.DebugLog("¸Ãµ¥±ÊÀÛ³ä»î¶¯½±ÀøÒÑ´ï×î´ó¿ÉÁì½±´ÎÊý! actNum=%s,awardIndex=%s,getCount(%s) >= canGetCount(%s)" % (actNum, awardIndex, getCount, canGetCount), playerID)
|
return
|
|
singleValue = awardIpyData.GetSingleRechargeValue()
|
|
actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleRechargeWorldLV % actNum)
|
awardItemList = GameWorld.GetDictValueByRangeKey(ipyData.GetAwardItem(), actWorldLV, [])
|
|
if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
|
return
|
|
getCount += 1
|
SetAwardCountInfo(curPlayer, actNum, awardIndex, getCount, canGetCount)
|
Sync_SingleRechargePlayerInfo(curPlayer, actNum, [awardIndex])
|
|
GameWorld.DebugLog(" ÁìÈ¡³É¹¦! actNum=%s,templateID=%s,awardIndex=%s,singleValue=%s,getCount=%s,canGetCount=%s"
|
% (actNum, templateID, awardIndex, singleValue, getCount, canGetCount))
|
|
notifyKey = awardIpyData.GetNotifyKey()
|
if notifyKey:
|
PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), str(awardIpyData.GetSingleRechargeValue())])
|
|
for itemID, itemCount, isAuctionItem in awardItemList:
|
ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], event=["SingleRechargeAward", False, {}])
|
|
return
|
|
def Sync_SingleRechargePlayerInfo(curPlayer, actNum, awardIndexList=None):
|
## Í¨ÖªÍæ¼ÒÊý¾ÝÐÅÏ¢
|
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_SingleRecharge, actNum)
|
if not actInfo.get(ShareDefine.ActKey_State):
|
return
|
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
if not cfgID:
|
return
|
|
ipyData = IpyGameDataPY.GetIpyGameData("ActSingleRecharge", cfgID)
|
if not ipyData:
|
return
|
|
if ipyData.GetIsOfflineAct():
|
#ÏßÏ»²»Ï·¢
|
return
|
|
if awardIndexList == None:
|
awardIndexList = []
|
templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))
|
if not templateID:
|
return
|
ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActSingleRechargeAward", templateID)
|
if not ipyDataList:
|
return
|
for awardIpyData in ipyDataList:
|
awardIndexList.append(awardIpyData.GetAwardIndex())
|
|
if not awardIndexList:
|
return
|
|
playerActInfo = ChPyNetSendPack.tagMCActSingleRechargePlayerInfo()
|
playerActInfo.ActNum = actNum
|
playerActInfo.AwardRecordList = []
|
for awardIndex in awardIndexList:
|
getCount, canGetCount = GetAwardCountInfo(curPlayer, actNum, awardIndex)
|
awardRecord = ChPyNetSendPack.tagMCActSingleRechargePlayerAward()
|
awardRecord.Clear()
|
awardRecord.AwardIndex = awardIndex
|
awardRecord.CanGetCount = canGetCount
|
awardRecord.GetCount = getCount
|
playerActInfo.AwardRecordList.append(awardRecord)
|
playerActInfo.RecordCount = len(playerActInfo.AwardRecordList)
|
NetPackCommon.SendFakePack(curPlayer, playerActInfo)
|
return
|
|
def Sync_SingleRechargeActionInfo(curPlayer, actNum):
|
## ֪ͨ»î¶¯ÐÅÏ¢
|
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_SingleRecharge, actNum)
|
if not actInfo.get(ShareDefine.ActKey_State):
|
return
|
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
if not cfgID:
|
return
|
|
ipyData = IpyGameDataPY.GetIpyGameData("ActSingleRecharge", cfgID)
|
if not ipyData:
|
return
|
|
if ipyData.GetIsOfflineAct():
|
#ÏßÏ»²»Ï·¢
|
return
|
|
templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))
|
if not templateID:
|
return
|
|
actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleRechargeWorldLV % actNum)
|
startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
|
|
clientPack = ChPyNetSendPack.tagMCActSingleRechargeInfo()
|
clientPack.ActNum = actNum
|
clientPack.StartDate = startDateStr
|
clientPack.EndtDate = endDateStr
|
clientPack.IsDayReset = ipyData.GetIsDayReset()
|
clientPack.LimitLV = ipyData.GetLVLimit()
|
clientPack.AwardRuleType = ipyData.GetAwardRuleType()
|
clientPack.AwardInfo = []
|
|
ipyDataList = IpyGameDataPY.GetIpyGameDataList("ActSingleRechargeAward", templateID)
|
if ipyDataList:
|
for awardIpyData in ipyDataList:
|
awardInfo = ChPyNetSendPack.tagMCActSingleRechargeAward()
|
awardInfo.AwardIndex = awardIpyData.GetAwardIndex()
|
awardInfo.AwardCountMax = awardIpyData.GetAwardCountMax()
|
awardInfo.SingleRechargeValue = CommFunc.RMBToCoin(awardIpyData.GetSingleRechargeValue())
|
awardInfo.AwardItem = []
|
awardItemList = GameWorld.GetDictValueByRangeKey(awardIpyData.GetAwardItem(), actWorldLV, [])
|
for itemID, itemCount, isBind in awardItemList:
|
awardItem = ChPyNetSendPack.tagMCActSingleRechargeAwardItem()
|
awardItem.ItemID = itemID
|
awardItem.ItemCount = itemCount
|
awardItem.IsBind = isBind
|
awardInfo.AwardItem.append(awardItem)
|
awardInfo.AwardItemCount = len(awardInfo.AwardItem)
|
|
clientPack.AwardInfo.append(awardInfo)
|
|
clientPack.AwardCount = len(clientPack.AwardInfo)
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|
|