#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package Player.PlayerActLunhuidian
|
#
|
# @todo:Âֻصî
|
# @author hxp
|
# @date 2024-11-11
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: Âֻصî
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2024-11-11 18:00"""
|
#-------------------------------------------------------------------------------
|
|
import PyGameData
|
import ShareDefine
|
import PlayerControl
|
import IpyGameDataPY
|
import ChPyNetSendPack
|
import FunctionNPCCommon
|
import NetPackCommon
|
import ItemControler
|
import PlayerCoin
|
import GameWorld
|
import ChConfig
|
|
# ÂÖ»ØÉ趨ÅäÖÃË÷Òý
|
RoundSetIndex = (
|
RoundSetIndex_AwardType, # 0 ½±ÀøÀàÐÍ
|
RoundSetIndex_AwardTypeValue, # 1 ½±ÀøÀàÐͶÔÓ¦Öµ
|
RoundSetIndex_RoundMax, # 2 ×î´óÂֻشÎÊý
|
) = range(3)
|
|
# Âֻؽ±ÀøÀàÐÍ
|
AwardTypeList = (
|
AwardType_PayMoney, # 1 ÏûºÄ»õ±Ò
|
AwardType_Treasure, # 2 Ѱ±¦
|
AwardType_UseItem, # 3 ÏûºÄÎïÆ·
|
) = range(1, 1 + 3)
|
|
def OnPlayerLogin(curPlayer):
|
|
for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Lunhuidian, {}).values():
|
actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
isReset = __CheckPlayerActLunhuidianAction(curPlayer, actNum)
|
# »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
|
if not isReset and actInfo.get(ShareDefine.ActKey_State):
|
Sync_ActLunhuidianActionInfo(curPlayer, actNum)
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
|
if ipyData:
|
roundSetDict = ipyData.GetRoundSetInfo()
|
for roundType in roundSetDict.keys():
|
Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
|
return
|
|
def RefreshActLunhuidianActionInfo(actNum):
|
## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
|
playerManager = GameWorld.GetPlayerManager()
|
for index in xrange(playerManager.GetPlayerCount()):
|
curPlayer = playerManager.GetPlayerByIndex(index)
|
if not GameWorld.IsNormalPlayer(curPlayer):
|
continue
|
__CheckPlayerActLunhuidianAction(curPlayer, actNum)
|
return
|
|
def __CheckPlayerActLunhuidianAction(curPlayer, actNum):
|
## ¼ì²éÍæ»î¶¯Êý¾ÝÐÅÏ¢
|
|
playerID = curPlayer.GetPlayerID()
|
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Lunhuidian, actNum)
|
actID = actInfo.get(ShareDefine.ActKey_ID, 0)
|
state = actInfo.get(ShareDefine.ActKey_State, 0)
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
|
playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianID % actNum) # Íæ¼ÒÉíÉϵĻID
|
|
# »î¶¯ID ÏàͬµÄ»°²»´¦Àí
|
if actID == playerActID:
|
GameWorld.DebugLog("Âֻصî»î¶¯ID²»±ä£¬²»´¦Àí£¡ actNum=%s,cfgID=%s,actID=%s" % (actNum, cfgID, actID), playerID)
|
return
|
GameWorld.DebugLog("Âֻصî»î¶¯ÖØÖÃ! actNum=%s,cfgID=%s,actID=%s,playerActID=%s,state=%s"
|
% (actNum, cfgID, actID, playerActID, state), playerID)
|
OnGiveUngetAward(curPlayer, actNum)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianID % actNum, actID)
|
|
if state:
|
Sync_ActLunhuidianActionInfo(curPlayer, actNum)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
|
if ipyData:
|
roundSetDict = ipyData.GetRoundSetInfo()
|
ctgIDDict = ipyData.GetRoundCTGIDInfo()
|
shopTypeDict = ipyData.GetRoundShopTypeInfo()
|
resetCTGIDList, resetShopTypeList = [], []
|
for roundType, roundSet in roundSetDict.items():
|
SaveActRoundSet(curPlayer, actNum, roundType, roundSet)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType), 0)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType), 1) # ´ÓµÚ1ÂÖ¿ªÊ¼
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType), 0)
|
Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
|
resetCTGIDList += ctgIDDict.get(roundType, [])
|
shopType = shopTypeDict.get(roundType, 0)
|
if shopType and shopType not in resetShopTypeList:
|
resetShopTypeList.append(shopType)
|
|
PlayerCoin.DoResetCTGCountByIDList(curPlayer, "ActLunhuidian", resetCTGIDList)
|
FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, resetShopTypeList)
|
|
return True
|
|
def SaveActRoundSet(curPlayer, actNum, roundType, roundSet):
|
## ±£´æ²ÎÓëµÄ»î¶¯ÂÖ»ØÉ趨£¬ÓÃÓڻ½áÊøÓʼþ²¹·¢½±Àø
|
# µ¥´ÎactNum»î¶¯×î¶àÖ§³Öͬʱ¿ªx¸öÂÖ»ØÀàÐÍ£¬Ò»°ãͬ¸öʱ¼äµÄÂֻػ×î¶àͬʱ¿ª2¸ö»ò3¸ö×î¶àÁË
|
for num in range(20):
|
if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianSet % (actNum, num)):
|
continue
|
roundMax = GetRoundSetValue(roundSet, RoundSetIndex_RoundMax)
|
setValue = roundType * 100 + roundMax
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianSet % (actNum, num), setValue)
|
GameWorld.DebugLog(" ±£´æÂֻصî²ÎÓëÖµ! actNum=%s,roundType=%s,roundMax=%s,setValue=%s"
|
% (actNum, roundType, roundMax, setValue), curPlayer.GetPlayerID())
|
break
|
return
|
|
def OnGiveUngetAward(curPlayer, actNum):
|
## ²¹·¢Î´ÁìÈ¡½±Àø
|
for num in range(20):
|
setValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianSet % (actNum, num))
|
if not setValue:
|
continue
|
__DoGiveUngetAwardByMail(curPlayer, actNum, setValue)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianSet % (actNum, num), 0)
|
return
|
|
def __DoGiveUngetAwardByMail(curPlayer, actNum, setValue):
|
playerID = curPlayer.GetPlayerID()
|
roundType = setValue / 100
|
roundMax = setValue % 100
|
curRound = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType))
|
curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType))
|
awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType))
|
awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActLunhuidianAward", roundType)
|
if not awardIpyDataList:
|
return
|
|
mailItemList = []
|
doRound = curRound
|
doValue = curValue
|
doAwardState = awardState
|
while doValue > 0 and doRound <= roundMax:
|
GameWorld.DebugLog("´¦Àí²¹·¢Âֻؽ±Àø: doRound=%s,doValue=%s,doAwardState=%s" % (doRound, doValue, doAwardState), playerID)
|
roundValueMax = 0
|
for awardIpyData in awardIpyDataList:
|
needV = awardIpyData.GetNeedValue()
|
aIndex = awardIpyData.GetAwardIndex()
|
awardItemList = awardIpyData.GetAwardItemList()
|
roundValueMax = max(roundValueMax, needV)
|
if doAwardState&pow(2, aIndex):
|
GameWorld.DebugLog(" ÒÑÁìÈ¡¸Ã½±Àø: doRound=%s,aIndex=%s,needV=%s" % (doRound, aIndex, needV), playerID)
|
continue
|
if doValue < needV:
|
GameWorld.DebugLog(" ËùÐèÖµ²»´ï±ê: doRound=%s,aIndex=%s,needV=%s > %s" % (doRound, aIndex, needV, doValue), playerID)
|
continue
|
mailItemList += awardItemList
|
GameWorld.DebugLog(" δÁìÈ¡²¹·¢½±: doRound=%s,aIndex=%s,needV=%s,%s" % (doRound, aIndex, needV, awardItemList), playerID)
|
|
doRound += 1
|
doValue -= roundValueMax
|
doAwardState = 0
|
|
if not mailItemList:
|
return
|
GameWorld.Log("´¦Àí²¹·¢Âֻؽ±ÀøÍê±Ï: actNum=%s,roundType=%s,roundMax=%s,curRound=%s,curValue=%s,awardState=%s,mailItemList=%s"
|
% (actNum, roundType, roundMax, curRound, curValue, awardState, mailItemList), playerID)
|
PlayerControl.SendMailByKey("LunhuidianUnget", [playerID], mailItemList)
|
return
|
|
def GetRoundSetValue(roundSet, setIndex): return roundSet[setIndex] if len(roundSet) > setIndex else 0
|
|
def AddLunhuidianValue(curPlayer, awardType, awardTypeValue, addValue):
|
## Ôö¼ÓÂÖ»Øµî½ø¶ÈÖµ
|
playerID = curPlayer.GetPlayerID()
|
for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Lunhuidian, {}).values():
|
if not actInfo.get(ShareDefine.ActKey_State):
|
continue
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
|
if not ipyData:
|
continue
|
roundSetDict = ipyData.GetRoundSetInfo()
|
for roundType, roundSet in roundSetDict.items():
|
if awardType != GetRoundSetValue(roundSet, RoundSetIndex_AwardType):
|
continue
|
if awardTypeValue != GetRoundSetValue(roundSet, RoundSetIndex_AwardTypeValue):
|
continue
|
|
curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType))
|
updValue = min(curValue + addValue, ChConfig.Def_UpperLimit_DWord)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType), updValue)
|
GameWorld.DebugLog("¸üÐÂÂֻصîÀÛ¼ÆÖµ: actNum=%s,cfgID=%s,roundType=%s,awardType=%s,awardTypeValue=%s,addValue=%s,curValue=%s,updValue=%s"
|
% (actNum, cfgID, roundType, awardType, awardTypeValue, addValue, curValue, updValue), playerID)
|
Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
|
|
return
|
|
def GetLunhuidianAward(curPlayer, dataEx, dataExStr):
|
## ÁìÈ¡½±Àø
|
# @param awardInfo: ÒªÁìÈ¡µÄ½±ÀøÐÅÏ¢ roundType|needValue
|
actNum = dataEx
|
awardSplitList = dataExStr.split("|")
|
if len(awardSplitList) != 2:
|
GameWorld.DebugLog("·¢ËÍÁìÈ¡¸ñʽ´íÎó: dataExStr=%s" % dataExStr)
|
return
|
roundType = GameWorld.ToIntDef(awardSplitList[0], 0)
|
needValue = GameWorld.ToIntDef(awardSplitList[1], 0)
|
|
playerID = curPlayer.GetPlayerID()
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Lunhuidian, actNum)
|
if not actInfo or not actInfo.get(ShareDefine.ActKey_State):
|
GameWorld.DebugLog("¸ÃÂֻصî·Ç»î¶¯ÖÐ: actNum=%s" % actNum)
|
return
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
|
if not ipyData:
|
return
|
roundSetDict = ipyData.GetRoundSetInfo()
|
if roundType not in roundSetDict:
|
GameWorld.DebugLog("¸ÃÂֻصîÀàÐͲ»ÔÚ±¾´Î»î¶¯ÖÐ: actNum=%s,roundType=%s not in %s" % (actNum, roundType, roundSetDict))
|
return
|
roundSet = roundSetDict[roundType]
|
roundMax = GetRoundSetValue(roundSet, RoundSetIndex_RoundMax)
|
|
awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActLunhuidianAward", roundType)
|
if not awardIpyDataList:
|
return
|
|
curRound = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType))
|
curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType))
|
awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType))
|
|
roundValueMax = 0
|
unGetIndexList = []
|
awardIndex, awardItemList = None, []
|
for awardIpyData in awardIpyDataList:
|
needV = awardIpyData.GetNeedValue()
|
roundValueMax = max(roundValueMax, needV)
|
aIndex = awardIpyData.GetAwardIndex()
|
if needValue == needV:
|
awardIndex = aIndex
|
awardItemList = awardIpyData.GetAwardItemList()
|
else:
|
if not awardState&pow(2, aIndex):
|
unGetIndexList.append(aIndex)
|
|
if awardIndex == None:
|
GameWorld.DebugLog("ÂֻصîûÓиý±Àø! actNum=%s,roundType=%s,needValue=%s" % (actNum, roundType, needValue), playerID)
|
return
|
|
if awardState&pow(2, awardIndex):
|
GameWorld.DebugLog("ÂֻصÀøÒÑÁì½±! actNum=%s,roundType=%s,needValue=%s,awardIndex=%s"
|
% (actNum, roundType, needValue, awardIndex), playerID)
|
return
|
|
if curValue < needValue:
|
GameWorld.DebugLog("Âֻصǰֵ²»×㣬ÎÞ·¨Áì½±! actNum=%s,roundType=%s,curRound=%s,curValue=%s < %s"
|
% (actNum, roundType, curRound, curValue, needValue), playerID)
|
return
|
|
updState = awardState|pow(2, awardIndex)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType), updState)
|
GameWorld.DebugLog("ÁìÈ¡ÂֻصÀø! actNum=%s,roundType=%s,needValue=%s,awardIndex=%s,awardState=%s,updState=%s,curRound=%s"
|
% (actNum, roundType, needValue, awardIndex, awardState, updState, curRound), playerID)
|
ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["Lunhuidian", False, {}])
|
|
GameWorld.DebugLog(" curRound=%s/%s,unGetIndexList=%s,curValue=%s,roundValueMax=%s"
|
% (curRound, roundMax, unGetIndexList, curValue, roundValueMax), playerID)
|
if not unGetIndexList and curRound < roundMax:
|
updRound = curRound + 1
|
updValue = max(0, curValue - roundValueMax)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType), updRound)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType), updValue)
|
PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType), 0)
|
GameWorld.DebugLog(" ±¾ÂÖ´ÎËùÓн±ÀøÒѾÁìÈ¡Íê±Ï£¬½øÈëÏÂÒ»ÂÖ! updRound=%s,updValue=%s" % (updRound, updValue), playerID)
|
|
Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType)
|
return
|
|
def Sync_ActLunhuidianPlayerInfo(curPlayer, actNum, roundType):
|
clientPack = ChPyNetSendPack.tagMCActLunhuidianPlayerInfo()
|
clientPack.ActNum = actNum
|
clientPack.RoundType = roundType
|
clientPack.CurRound = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianRound % (actNum, roundType))
|
clientPack.CurValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianValue % (actNum, roundType))
|
clientPack.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLunhuidianAward % (actNum, roundType))
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|
|
def Sync_ActLunhuidianActionInfo(curPlayer, actNum, roundType=0):
|
## ֪ͨ»î¶¯ÐÅÏ¢
|
actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Lunhuidian, actNum)
|
if not actInfo:
|
return
|
if not actInfo.get(ShareDefine.ActKey_State):
|
return
|
cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
|
ipyData = IpyGameDataPY.GetIpyGameData("ActLunhuidian", cfgID)
|
if not ipyData:
|
return
|
|
startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
|
clientPack = ChPyNetSendPack.tagMCActLunhuidianInfo()
|
clientPack.Clear()
|
clientPack.ActNum = actNum
|
clientPack.StartDate = startDateStr
|
clientPack.EndtDate = endDateStr
|
clientPack.ResetType = ipyData.GetResetType()
|
clientPack.LimitLV = ipyData.GetLVLimit()
|
|
roundSetDict = ipyData.GetRoundSetInfo()
|
ctgIDDict = ipyData.GetRoundCTGIDInfo()
|
shopTypeDict = ipyData.GetRoundShopTypeInfo()
|
for roundType, roundSet in roundSetDict.items():
|
roundInfo = ChPyNetSendPack.tagMCActLunhuidianRound()
|
roundInfo.RoundType = roundType
|
roundInfo.AwardType = GetRoundSetValue(roundSet, RoundSetIndex_AwardType)
|
roundInfo.AwardTypeValue = GetRoundSetValue(roundSet, RoundSetIndex_AwardTypeValue)
|
roundInfo.RoundMax = GetRoundSetValue(roundSet, RoundSetIndex_RoundMax)
|
roundInfo.AwardList = []
|
|
awardIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActLunhuidianAward", roundType)
|
if awardIpyDataList:
|
for awardIpyData in awardIpyDataList:
|
award = ChPyNetSendPack.tagMCActLunhuidianAward()
|
award.AwardIndex = awardIpyData.GetAwardIndex()
|
award.NeedValue = awardIpyData.GetNeedValue()
|
for itemID, itemCount, isAuctionItem in awardIpyData.GetAwardItemList():
|
item = ChPyNetSendPack.tagMCActLunhuidianItem()
|
item.ItemID = itemID
|
item.ItemCount = itemCount
|
item.IsBind = isAuctionItem
|
award.AwardItemList.append(item)
|
award.Count = len(award.AwardItemList)
|
|
roundInfo.AwardList.append(award)
|
roundInfo.AwardCount = len(roundInfo.AwardList)
|
roundInfo.CTGIDList = ctgIDDict.get(roundType, [])
|
roundInfo.CTGIDCount = len(roundInfo.CTGIDList)
|
roundInfo.ShopType = shopTypeDict.get(roundType, 0)
|
|
clientPack.RoundList.append(roundInfo)
|
clientPack.RoundCount = len(clientPack.RoundList)
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|