#!/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 NetPackCommon
|
import ItemControler
|
import GameWorld
|
import ChConfig
|
|
# ÂÖ»ØÉ趨ÅäÖÃË÷Òý
|
RoundSetIndex = (
|
RoundSetIndex_AwardType, # 0 ½±ÀøÀàÐÍ
|
RoundSetIndex_AwardTypeValue, # 1 ½±ÀøÀàÐͶÔÓ¦Öµ
|
RoundSetIndex_RoundMax, # 2 ×î´óÂֻشÎÊý
|
) = range(3)
|
|
# Âֻؽ±ÀøÀàÐÍ
|
AwardType_PayMoney = 1
|
AwardType_Treasure = 2
|
|
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)
|
|
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()
|
for roundType in roundSetDict.keys():
|
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)
|
return True
|
|
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)
|
|
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()
|
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)
|
|
clientPack.RoundList.append(roundInfo)
|
clientPack.RoundCount = len(clientPack.RoundList)
|
NetPackCommon.SendFakePack(curPlayer, clientPack)
|
return
|