提交 | 用户 | age
164b1a 1 #!/usr/bin/python
H 2 # -*- coding: GBK -*-
3 #-------------------------------------------------------------------------------
4 #
5 ##@package Player.PlayerCrossBattlefield
6 #
0c2782 7 # @todo:跨服战场/古神战场
164b1a 8 # @author hxp
H 9 # @date 2022-01-06
10 # @version 1.0
11 #
0c2782 12 # 详细描述: 跨服战场/古神战场
164b1a 13 #
H 14 #-------------------------------------------------------------------------------
15 #"""Version = 2022-01-06 20:30"""
16 #-------------------------------------------------------------------------------
17 import GameWorld
18 import ShareDefine
19 import PlayerControl
20 import IpyGameDataPY
21 import datetime
22 import CrossRealmPlayer
23 import ChConfig
24 import ItemCommon
25 import IPY_GameWorld
26 import ChPyNetSendPack
27 import NetPackCommon
28 import ItemControler
29 import PlayerActivity
0c2782 30 import PlayerSuccess
6eb8ce 31 import PlayerGubao
164b1a 32
H 33
34 def DoPlayerLogin(curPlayer):
35     if GameWorld.IsCrossServer():
36         return
37     SyncCrossBattlefieldPlayerInfo(curPlayer)
38     return
39
40 def DoPlayerOnDay(curPlayer):
41     if GameWorld.IsCrossServer():
42         return
43     
44     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_HighScoreToday, 0)
45     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_BuyOpenCountToday, 0)
46     
47     SyncCrossBattlefieldPlayerInfo(curPlayer)
48     return
49
50 def DoPlayerOnWeek(curPlayer):
51     if GameWorld.IsCrossServer():
52         return
53     
54     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_EnterCountWeek, 0)
55     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek, 0)
56     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_HighScoreTotalWeek, 0)
8a103d 57     SyncCrossBattlefieldPlayerInfo(curPlayer)
164b1a 58     return
H 59
60 #// C1 09 跨服战场购买开启场次 #tagCMCrossBattlefieldBuyOpen
61 #
62 #struct    tagCMCrossBattlefieldBuyOpen
63 #{
64 #    tagHead        Head;
65 #    BYTE    Hour;        //战场开启时
66 #    BYTE    Minute;        //战场开启分
67 #    BYTE    Faction;        //阵营 1-红;2-蓝
25d85f 68 #    BYTE    ServerOnly;    //是否仅本服玩家可加入,0-否,1-是
164b1a 69 #};
H 70 def OnCrossBattlefieldBuyOpen(index, clientData, tick):
71     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
72     playerID = curPlayer.GetPlayerID()
73     hour = clientData.Hour
74     minute = clientData.Minute
75     faction = clientData.Faction
25d85f 76     serverOnly = clientData.ServerOnly
164b1a 77     
H 78     if GameWorld.IsCrossServer():
79         GameWorld.DebugLog("跨服服务器无法发起匹配!", playerID)
80         return
81     
82     if not CrossRealmPlayer.IsCrossServerOpen():
83         PlayerControl.NotifyCode(curPlayer, "CrossMatching18")
84         return
85     
86     if faction not in [ChConfig.CampType_Justice, ChConfig.CampType_Evil]:
87         GameWorld.DebugLog("没有该战场阵营选择! faction=%s" % faction, playerID)
88         return
89     
90     callOpenHMList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldOpen", 2)
91     if [hour, minute] not in callOpenHMList:
92         GameWorld.Log("非可召集的战场场次! hour=%s,minute=%s,callOpenHMList=%s" % (hour, minute, callOpenHMList), playerID)
93         return
94     
95     closeBuyMinute = IpyGameDataPY.GetFuncCfg("CrossBattlefieldOpen", 4) # 开启前X分钟后关闭购买
96     crossServerTimeStr = GameWorld.GetCrossServerTimeStr()
97     crossServerDateTime = GameWorld.ChangeStrToDatetime(crossServerTimeStr)
98     
99     startTimeStr = "%s-%s-%s %s:%s:00" % (crossServerDateTime.year, crossServerDateTime.month, crossServerDateTime.day, hour, minute)
100     startDateTime = GameWorld.ChangeStrToDatetime(startTimeStr)
101     endBuyDateTime = startDateTime + datetime.timedelta(minutes= -closeBuyMinute)
102     if crossServerDateTime >= endBuyDateTime:
103         GameWorld.Log("该时间点战场已关闭召集,不能再召集! hour=%s,minute=%s,crossServerDateTime(%s) >= endBuyDateTime(%s)" 
104                       % (hour, minute, crossServerDateTime, endBuyDateTime), playerID)
105         return
106     
f9bd7e 107     canBuyStartHour = 5
H 108     curServerTime = GameWorld.GetCurrentTime()
109     if crossServerDateTime.hour < canBuyStartHour or curServerTime.hour < canBuyStartHour:
110         PlayerControl.NotifyCode(curPlayer, "CrossBattlefieldBuyLimit")
111         GameWorld.Log("跨服服务器及本服服务器需超过%s点后可购买! crossServerHour=%s,curServerHour=%s" 
112                       % (canBuyStartHour, crossServerDateTime.hour, curServerTime.hour), playerID)
113         return
114     
164b1a 115     moneyBuyMaxCount, moneyType, moneyCount = 0, 0, 0
H 116     todayBuyOpenCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountToday)
117     buyOpenMoneyInfo = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldBuyOpen", 1)
118     if len(buyOpenMoneyInfo) == 3:
119         moneyBuyMaxCount, moneyType, moneyCount = buyOpenMoneyInfo
120         
121     # 购买消耗货币
122     if todayBuyOpenCount < moneyBuyMaxCount:
123         if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyCount):
124             GameWorld.DebugLog("跨服战场召集开启货币不足! moneyType=%s,moneyCount=%s" % (moneyType, moneyCount), playerID)
125             return
126     else:
127         costItemID = IpyGameDataPY.GetFuncCfg("CrossBattlefieldBuyOpen", 2)
128         costItem = ItemCommon.FindItemInPackByItemID(curPlayer, costItemID, IPY_GameWorld.rptItem)
129         if not ItemCommon.CheckItemCanUse(costItem):
130             GameWorld.DebugLog("跨服战场召集开启道具不足! costItemID=%s" % costItemID, playerID)
131             return
132         
133     if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_Battlefield, tick):
134         PlayerControl.NotifyCode(curPlayer, "RequestLater")
135         return
136     
137     dataMsg = {"openHour":hour, "openMinute":minute, "faction":faction, "todayBuyOpenCount":todayBuyOpenCount,
25d85f 138                "serverOnly":serverOnly,
164b1a 139                "accID":curPlayer.GetAccID(),
H 140                "playerID":playerID,
141                "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),
142                "playerJob":curPlayer.GetJob(),
143                "playerLV":curPlayer.GetLV(),
144                "realmLV":curPlayer.GetOfficialRank(),
145                "fightPower":PlayerControl.GetFightPower(curPlayer),
146                "buyOpenCountWeek":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek)
147                }
148     GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_BattlefieldBuyOpen, dataMsg)
149     return
150
151 def GameServer_CrossBattlefield_DoResult(curPlayer, msgData):
152     msgType, dataMsg = msgData[:2]
153     #ret = msgData[2] if len(msgData) > 2 else None
154     
155     ## 战场购买开启场次 
156     if msgType == "BattlefieldBuy":
157         __DoBattlefieldBuy(curPlayer, dataMsg)
158                 
159     elif msgType == "BattlefieldOver":
160         __DoBattlefieldOver(curPlayer, dataMsg)
161         
162     return
163
164 def __DoBattlefieldBuy(curPlayer, dataMsg):
165     
166     playerID = curPlayer.GetPlayerID()
167     openHour, openMinute, faction, todayBuyOpenCount, buyTime = dataMsg
168     updTodayBuyOpenCount, updWeekBuyOpenCount = 0, 0
169     
170     isToday = GameWorld.CheckTimeIsSameServerDayEx(buyTime)
171     if isToday:
172         todayBuyOpenCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountToday)
173         updTodayBuyOpenCount = todayBuyOpenCount + 1
174         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_BuyOpenCountToday, updTodayBuyOpenCount)
175         
176     isSameWeek = GameWorld.CheckTimeIsSameWeek(buyTime)
177     if isSameWeek:
178         weekBuyOpenCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek)
179         updWeekBuyOpenCount = weekBuyOpenCount + 1
180         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek, updWeekBuyOpenCount)
8a103d 181     SyncCrossBattlefieldPlayerInfo(curPlayer)
H 182     
164b1a 183     GameWorld.Log("购买召集跨服战场结果: openHour=%s,openMinute=%s,faction=%s,updTodayBuyOpenCount=%s,updWeekBuyOpenCount=%s,buyTime=%s,isToday=%s,isSameWeek=%s" 
H 184                   % (openHour, openMinute, faction, updTodayBuyOpenCount, updWeekBuyOpenCount, GameWorld.ChangeTimeNumToStr(buyTime), isToday, isSameWeek), playerID)
185     
186     moneyBuyMaxCount, moneyType, moneyCount = 0, 0, 0
187     buyOpenMoneyInfo = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldBuyOpen", 1)
188     if len(buyOpenMoneyInfo) == 3:
189         moneyBuyMaxCount, moneyType, moneyCount = buyOpenMoneyInfo
190         
191     infoDict = {ChConfig.Def_Cost_Reason_SonKey:"BattlefieldBuyOpen", "buyTime":buyTime, "isToday":isToday, "isSameWeek":isSameWeek, 
192                 "updTodayBuyOpenCount":updTodayBuyOpenCount, "updWeekBuyOpenCount":updWeekBuyOpenCount}
193     # 购买消耗货币
194     if todayBuyOpenCount < moneyBuyMaxCount:
195         if not PlayerControl.PayMoney(curPlayer, moneyType, moneyCount, ChConfig.Def_Cost_CrossBattlefield, infoDict):
196             return
197     else:
198         costItemID = IpyGameDataPY.GetFuncCfg("CrossBattlefieldBuyOpen", 2)
199         costItem = ItemCommon.FindItemInPackByItemID(curPlayer, costItemID, IPY_GameWorld.rptItem)
200         if not ItemCommon.CheckItemCanUse(costItem):
201             costItem = ItemCommon.FindItemInPackByItemID(curPlayer, costItemID, IPY_GameWorld.rptWarehouse)
202         if not ItemCommon.CheckItemCanUse(costItem):
203             return
204         ItemCommon.DelItem(curPlayer, costItem, 1, True, "CrossBattlefield", infoDict)
205         
206     # 固定礼包
207     buyAwardItemList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldBuyOpen", 3)
208     ItemControler.GivePlayerItemOrMail(curPlayer, buyAwardItemList)
0c2782 209     
H 210     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_CallOpen, 1)
164b1a 211     return
H 212
213 def __DoBattlefieldOver(curPlayer, dataMsg):
214     
215     playerID = curPlayer.GetPlayerID()
0c2782 216     overTime, \
H 217         isWinner, faction, rank, score, highScoreToday, highScoreWeekTotal, enterCountWeek, \
218         isCallOpen, isCalled, killCnt, ckillCntInfo, killBossCnt, killScoreKing, killGuardCnt, auraScore, superItemAwardCnt, \
219         factionBuffCollCnt, personBuffCollCnt, crystalCollCnt, wallCollCnt = dataMsg
220         
164b1a 221     isToday = GameWorld.CheckTimeIsSameServerDayEx(overTime)
H 222     isSameWeek = GameWorld.CheckTimeIsSameWeek(overTime)
0c2782 223     GameWorld.Log("跨服战场结算玩家结果: highScoreToday=%s,highScoreWeekTotal=%s,enterCountWeek=%s,overTime=%s,isToday=%s,isSameWeek=%s" 
H 224                   % (highScoreToday, highScoreWeekTotal, enterCountWeek, GameWorld.ChangeTimeNumToStr(overTime), isToday, isSameWeek), playerID)
225     GameWorld.Log("    isWinner=%s,faction=%s,rank=%s,score=%s,isCallOpen=%s,isCalled=%s" % (isWinner, faction, rank, score, isCallOpen, isCalled), playerID)
226     GameWorld.Log("    killCnt=%s,ckillCntInfo=%s,killBossCnt=%s,killScoreKing=%s,killGuardCnt=%s,auraScore=%s,superItemAwardCnt=%s" 
227                   % (killCnt, ckillCntInfo, killBossCnt, killScoreKing, killGuardCnt, auraScore, superItemAwardCnt), playerID)
228     GameWorld.Log("    factionBuffCollCnt=%s,personBuffCollCnt=%s,crystalCollCnt=%s,wallCollCnt=%s" 
229                   % (factionBuffCollCnt, personBuffCollCnt, crystalCollCnt, wallCollCnt), playerID)
164b1a 230     
H 231     if isToday:
232         addCnt = 1
0c2782 233         # 召集进入由于是免费进入,不需要增加日常次数,直接增加日常活跃
H 234         if isCallOpen or isCalled:
164b1a 235             activityNum = PlayerActivity.GetActivityNum(PlayerActivity.RelatedType_1, ShareDefine.DailyActionID_CrossBattlefield)
H 236             PlayerActivity.AddActivityFinishCnt(curPlayer, activityNum, None, addCnt)
0c2782 237         # 非召集兑入进入的需要增加日常次数
H 238         else:
239             PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_CrossBattlefield, addCnt)
164b1a 240             
H 241         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_HighScoreToday, highScoreToday)
6eb8ce 242         PlayerGubao.AddGubaoItemEffValue(curPlayer, PlayerGubao.GubaoEffType_CrossBattlefield, 1)
164b1a 243         
H 244     if isSameWeek:
245         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_EnterCountWeek, enterCountWeek)
246         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_HighScoreTotalWeek, highScoreWeekTotal)
8a103d 247     SyncCrossBattlefieldPlayerInfo(curPlayer)
H 248     
0c2782 249     # 成就
H 250     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Join, 1)
251     if isCalled:
252         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Called, 1)
253     if isWinner:
254         if faction == ShareDefine.CampType_Justice:
255             PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_WinJ, 1)
256         elif faction == ShareDefine.CampType_Evil:
257             PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_WinE, 1)
258     if killCnt > 0:
259         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillCnt, killCnt)
260     for ckillCnt, addCnt in ckillCntInfo.items():
261         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_CKillCnt, addCnt, [ckillCnt])
262     if killBossCnt > 0:
263         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillBoss, killBossCnt)
264     if killScoreKing > 0:
265         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillScoreKing, killScoreKing)
266     if killGuardCnt > 0:
267         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillGuard, killGuardCnt)
268     if score > 0:
269         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Score, score)
270         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_ScoreMore, 1, [score])
271     if auraScore > 0:
272         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_AuraScore, auraScore)
273     if superItemAwardCnt > 0:
274         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_SuperItem, superItemAwardCnt)
275     if factionBuffCollCnt > 0:    
276         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_FactionBuff, factionBuffCollCnt)
277     if personBuffCollCnt > 0:    
278         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_PersonBuff, personBuffCollCnt)
279     if crystalCollCnt > 0:
280         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Crystal, crystalCollCnt)
281     if wallCollCnt > 0:
282         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Wall, wallCollCnt)
164b1a 283     return
H 284
285 def SyncCrossBattlefieldPlayerInfo(curPlayer):
286     clientPack = ChPyNetSendPack.tagMCCrossBattlefieldPlayerInfo()
287     clientPack.BuyOpenCountToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountToday)
288     clientPack.HighScoreToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_HighScoreToday)
8a103d 289     clientPack.EnterCountWeek = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_EnterCountWeek)
H 290     clientPack.BuyOpenCountWeek = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek)
291     clientPack.HighScoreTotalWeek = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_HighScoreTotalWeek)
ad9ca5 292     clientPack.ZoneID = CrossRealmPlayer.GetCrossPlayerZoneID(curPlayer, ChConfig.Def_FBMapID_CrossBattlefield)
164b1a 293     NetPackCommon.SendFakePack(curPlayer, clientPack)
H 294     return
295