提交 | 用户 | age
2f0b52 1 #!/usr/bin/python
H 2 # -*- coding: GBK -*-
3 #-------------------------------------------------------------------------------
4 #
5 ##@package Player.PlayerActLoginNew
6 #
7 # @todo:登录活动-新
8 # @author hxp
9 # @date 2024-06-03
10 # @version 1.0
11 #
12 # 详细描述: 登录活动-新
13 #
14 #-------------------------------------------------------------------------------
15 #"""Version = 2024-06-03 18:00"""
16 #-------------------------------------------------------------------------------
17
18 import PyGameData
789490 19 import PlayerCoin
2f0b52 20 import ShareDefine
H 21 import PlayerControl
22 import IpyGameDataPY
789490 23 import PlayerZhanling
2f0b52 24 import ChPyNetSendPack
H 25 import ItemControler
26 import IPY_GameWorld
27 import NetPackCommon
28 import GameWorld
29 import ChConfig
789490 30 import time
2f0b52 31
H 32 def OnPlayerLogin(curPlayer):
33     
34     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_ActLoginNew, {}).values():
35         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
36         isReset = __CheckPlayerActLoginAction(curPlayer, actNum)
37         # 活动中同步活动信息
789490 38         if not isReset and actInfo.get(ShareDefine.ActKey_State) and curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLoginNewID % actNum):
2f0b52 39             Sync_ActLoginActionInfo(curPlayer, actNum)
H 40             Sync_ActLoginPlayerInfo(curPlayer, actNum)
41             
789490 42     return
H 43
44 def OnDay(curPlayer):
45     OnCheckRelateFuncAct(curPlayer)
46     return
47
48 def OnCheckRelateFuncAct(curPlayer, openFuncIDList=None):
49     ## 检查关联功能ID开启的活动
50     for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_ActLoginNew, {}).values():
51         if not actInfo.get(ShareDefine.ActKey_State):
52             continue
53         cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
54         ipyData = IpyGameDataPY.GetIpyGameData("ActLoginNew", cfgID)
55         if not ipyData:
56             continue
57         if not hasattr(ipyData, "GetRelateFuncID"):
58             continue
59         relateFuncID = ipyData.GetRelateFuncID()
60         if not relateFuncID:
61             continue
62         if openFuncIDList and relateFuncID not in openFuncIDList:
63             continue
64         actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
65         __CheckPlayerActLoginAction(curPlayer, actNum)
66         
2f0b52 67     return
H 68
69 def RefreshActLoginActionInfo(actNum):
70     ## 收到GameServer同步的活动信息,刷新活动信息
71     playerManager = GameWorld.GetPlayerManager()
72     for index in xrange(playerManager.GetPlayerCount()):
73         curPlayer = playerManager.GetPlayerByIndex(index)
8f7a29 74         if not GameWorld.IsNormalPlayer(curPlayer):
2f0b52 75             continue
H 76         __CheckPlayerActLoginAction(curPlayer, actNum)
77     return
78
79 def __CheckPlayerActLoginAction(curPlayer, actNum):
80     ## 检查玩活动数据信息
81     
82     playerID = curPlayer.GetPlayerID()
83     
84     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_ActLoginNew, actNum)
85     actID = actInfo.get(ShareDefine.ActKey_ID, 0)
86     state = actInfo.get(ShareDefine.ActKey_State, 0)
87     
88     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLoginNewID % actNum) # 玩家身上的活动ID
89     
789490 90     funcActInfo = GameWorld.GetActRelateFuncInfo(curPlayer, "ActLoginNew", actInfo, playerActID)
H 91     if funcActInfo:
92         isInAct, actID = funcActInfo
93         if not isInAct:
94             return
95         
2f0b52 96     # 活动ID 相同的话不处理
H 97     if actID == playerActID:
98         GameWorld.DebugLog("新登录活动ID不变,不处理! actNum=%s,actID=%s" % (actNum, actID), curPlayer.GetPlayerID())
99         return
100     GameWorld.DebugLog("新登录活动重置! actNum=%s,actID=%s,playerActID=%s,state=%s" % (actNum, actID, playerActID, state), playerID)
101     
102     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLoginNewID % actNum, actID)
103     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLoginNewAward % actNum, 0)
789490 104     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActLoginNewAwardEx % actNum, 0)
2f0b52 105     
H 106     if state:
789490 107         cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
H 108         ipyData = IpyGameDataPY.GetIpyGameData("ActLoginNew", cfgID)
109         if ipyData:
110             if ipyData.GetAwardExCTGID():
111                 PlayerCoin.DoResetCTGCountByIDList(curPlayer, "ActLoginNew", [ipyData.GetAwardExCTGID()])
112             if ipyData.GetActZhanlingType():
113                 PlayerZhanling.ResetZhanling(curPlayer, ipyData.GetActZhanlingType())
2f0b52 114         Sync_ActLoginActionInfo(curPlayer, actNum)
H 115         Sync_ActLoginPlayerInfo(curPlayer, actNum)
116     return True
117
118 def OnGetActLoginAward(curPlayer, dayNum, actNum):
119     ## 领取活动奖励
120     
789490 121     isAwardEx = dayNum / 1000
H 122     dayNum = dayNum % 1000
2f0b52 123     actNum = GameWorld.ToIntDef(actNum)
H 124     
125     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_ActLoginNew, actNum)
126     if not actInfo:
127         GameWorld.DebugLog("没有该登录活动! actNum=%s" % actNum)
128         return
129     
130     if not actInfo.get(ShareDefine.ActKey_State):
131         GameWorld.DebugLog("非登录活动中! actNum=%s" % actNum)
132         return
133     
789490 134     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLoginNewID % actNum)
H 135     if not playerActID:
136         return
137     
138     curDayNum = GameWorld.GetDiff_Day(int(time.time()), playerActID) + 1
2f0b52 139     if curDayNum < dayNum:
H 140         GameWorld.DebugLog("未到可领取的登录天,无法领取!  actNum=%s,curDayNum=%s < %s" % (actNum, curDayNum, dayNum))
141         return
142     
143     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
144     ipyData = IpyGameDataPY.GetIpyGameData("ActLoginNew", cfgID)
145     if not ipyData:
146         return
147     templateID = ipyData.GetTemplateID()
148     
149     dayIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActLoginNewAward", templateID)
150     if not dayIpyDataList:
151         return
152     
153     findIpyData = None
154     for dayIpyData in dayIpyDataList:
155         if dayIpyData.GetDayNum() == dayNum:
156             findIpyData = dayIpyData
157             break
158         
159     if not findIpyData:
160         GameWorld.DebugLog("找不到对应登录天奖励! actNum=%s,cfgID=%s,templateID=%s,dayNum=%s" % (actNum, cfgID, templateID, dayNum))
161         return
789490 162     
H 163     if isAwardEx:
164         awardExCTGID = ipyData.GetAwardExCTGID()
165         if not awardExCTGID:
166             GameWorld.DebugLog("该登录活动没有扩展奖励! actNum=%s,cfgID=%s" % (actNum, cfgID))
167             return
168         if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGGoodsBuyCount % awardExCTGID):
169             GameWorld.DebugLog("该登录活动扩展奖励礼包未购买,无法领取! actNum=%s,cfgID=%s,awardExCTGID=%s" % (actNum, cfgID, awardExCTGID))
170             return
171         stateKey = ChConfig.Def_PDict_ActLoginNewAwardEx
172         awardItemList = findIpyData.GetLoginAwardItemListEx()
173     else:
174         stateKey = ChConfig.Def_PDict_ActLoginNewAward
175         awardItemList = findIpyData.GetLoginAwardItemList()
2f0b52 176         
789490 177     if not awardItemList:
H 178         return
179     
180     awardRecord = curPlayer.NomalDictGetProperty(stateKey % actNum)
2f0b52 181     if awardRecord & pow(2, dayNum):
H 182         GameWorld.DebugLog("登录活动该天已领奖! actNum=%s,dayNum=%s,awardRecord=%s" % (actNum, dayNum, awardRecord))
183         return
184     
185     # 判断非当天需补签
186     costMoneyType, costMoneyValue = 0, 0
187     if curDayNum != dayNum and ipyData.GetRepSignCostMoneyInfo():
188         costMoneyType, costMoneyValue = ipyData.GetRepSignCostMoneyInfo()
189         if costMoneyType and costMoneyValue and not PlayerControl.HaveMoney(curPlayer, costMoneyType, costMoneyValue):
190             return
191         
192     if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
193         return
194     
195     if costMoneyType and costMoneyValue:
789490 196         PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, "ActLoginNew", {"actNum":actNum, "dayNum":dayNum, "isAwardEx":isAwardEx})
2f0b52 197         
H 198     updAwardRecord = awardRecord | pow(2, dayNum)
789490 199     PlayerControl.NomalDictSetProperty(curPlayer, stateKey % actNum, updAwardRecord)
2f0b52 200     Sync_ActLoginPlayerInfo(curPlayer, actNum)
H 201     
789490 202     GameWorld.DebugLog("领取登录活动奖励! actNum=%s,dayNum=%s,isAwardEx=%s,awardItemList=%s,curDayNum=%s" % (actNum, dayNum, isAwardEx, awardItemList, curDayNum))
2f0b52 203     
H 204     for itemID, itemCount, isAuctionItem in awardItemList:
205         ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], event=["ActLoginNew", False, {}])
61f8b7 206     ItemControler.NotifyGiveAwardInfo(curPlayer, awardItemList, "ActLoginNew")
2f0b52 207     return
H 208
209 def Sync_ActLoginPlayerInfo(curPlayer, actNum):
210     ## 通知活动玩家信息
211     clientPack = ChPyNetSendPack.tagMCActLoginPlayerInfoNew()
a3fbff 212     clientPack.ActNum = actNum
2f0b52 213     clientPack.LoginAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLoginNewAward % actNum)
789490 214     clientPack.LoginAwardEx = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLoginNewAwardEx % actNum)
2f0b52 215     NetPackCommon.SendFakePack(curPlayer, clientPack)
H 216     return
217
218 def Sync_ActLoginActionInfo(curPlayer, actNum):
219     ## 通知活动信息
220     actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_ActLoginNew, actNum)
221     if not actInfo:
222         return
223     if not actInfo.get(ShareDefine.ActKey_State):
789490 224         return
H 225     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActLoginNewID % actNum)
226     if not playerActID:
2f0b52 227         return
H 228     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
229     ipyData = IpyGameDataPY.GetIpyGameData("ActLoginNew", cfgID)
230     if not ipyData:
231         return
dda28d 232     moneyType, moneyValue = ipyData.GetRepSignCostMoneyInfo()
2f0b52 233     templateID = ipyData.GetTemplateID()
H 234     dayIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActLoginNewAward", templateID)
235     if not dayIpyDataList:
236         return
237     
789490 238     if hasattr(ipyData, "GetRelateFuncID") and ipyData.GetRelateFuncID():
H 239         startDateStr, endDateStr = GameWorld.GetActRelateFuncDate(ipyData, playerActID, True)
240     else:
241         startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
2f0b52 242     actPack = ChPyNetSendPack.tagMCActLoginNew()
H 243     actPack.Clear()
244     actPack.ActNum = actNum
245     actPack.StartDate = startDateStr
246     actPack.EndtDate = endDateStr
247     actPack.LimitLV = ipyData.GetLVLimit()
dda28d 248     actPack.RepSignMoneyType = moneyType
H 249     actPack.RepSignMoneyValue = moneyValue
789490 250     actPack.AwardExCTGID = ipyData.GetAwardExCTGID()
2f0b52 251     
H 252     actPack.AwardDayList = []
253     for dayIpyData in dayIpyDataList:
254         dayInfo = ChPyNetSendPack.tagMCActLoginNewDay()
255         dayInfo.DayNum = dayIpyData.GetDayNum()
256         dayInfo.AwardItemList = []
257         for itemID, itemCount, isAuctionItem in dayIpyData.GetLoginAwardItemList():
258             itemInfo = ChPyNetSendPack.tagMCActLoginNewItem()
259             itemInfo.ItemID = itemID
260             itemInfo.ItemCount = itemCount
261             itemInfo.IsBind = isAuctionItem
262             dayInfo.AwardItemList.append(itemInfo)
263         dayInfo.Count = len(dayInfo.AwardItemList)
264         
789490 265         dayInfo.AwardItemListEx = []
H 266         for itemID, itemCount, isAuctionItem in dayIpyData.GetLoginAwardItemListEx():
267             itemInfo = ChPyNetSendPack.tagMCActLoginNewItem()
268             itemInfo.ItemID = itemID
269             itemInfo.ItemCount = itemCount
270             itemInfo.IsBind = isAuctionItem
271             dayInfo.AwardItemListEx.append(itemInfo)
272         dayInfo.CountEx = len(dayInfo.AwardItemListEx)
273         
2f0b52 274         actPack.AwardDayList.append(dayInfo)
H 275     actPack.DayCount = len(actPack.AwardDayList)
276     NetPackCommon.SendFakePack(curPlayer, actPack)
277     return
278