提交 | 用户 | 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():
b66c09 79         GameWorld.DebugLog("跨服服务器无法发起!", playerID)
164b1a 80         return
H 81     
82     if not CrossRealmPlayer.IsCrossServerOpen():
83         PlayerControl.NotifyCode(curPlayer, "CrossMatching18")
84         return
85     
b66c09 86     sysOpenHMList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldOpen", 1)
H 87     if [hour, minute] in sysOpenHMList:
88         if PlayerControl.GetCrossMapID(curPlayer) != ChConfig.Def_FBMapID_CrossBattlefield:
89             GameWorld.DebugLog("系统场次召集只能在跨服战场地图时可召集! CrossMapID=%s" % PlayerControl.GetCrossMapID(curPlayer), playerID)
90             return
91     else:
92         if faction not in [ChConfig.CampType_Justice, ChConfig.CampType_Evil]:
93             GameWorld.DebugLog("没有该战场阵营选择! faction=%s" % faction, playerID)
94             return
95         
96         callOpenHMList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldOpen", 2)
97         if [hour, minute] not in callOpenHMList:
98             GameWorld.Log("非可召集的战场场次! hour=%s,minute=%s,callOpenHMList=%s" % (hour, minute, callOpenHMList), playerID)
99             return
100         
101         closeBuyMinute = IpyGameDataPY.GetFuncCfg("CrossBattlefieldOpen", 4) # 开启前X分钟后关闭购买
102         crossServerTimeStr = GameWorld.GetCrossServerTimeStr()
103         crossServerDateTime = GameWorld.ChangeStrToDatetime(crossServerTimeStr)
104         
105         startTimeStr = "%s-%s-%s %s:%s:00" % (crossServerDateTime.year, crossServerDateTime.month, crossServerDateTime.day, hour, minute)
106         startDateTime = GameWorld.ChangeStrToDatetime(startTimeStr)
107         endBuyDateTime = startDateTime + datetime.timedelta(minutes= -closeBuyMinute)
108         if crossServerDateTime >= endBuyDateTime:
109             GameWorld.Log("该时间点战场已关闭召集,不能再召集! hour=%s,minute=%s,crossServerDateTime(%s) >= endBuyDateTime(%s)" 
110                           % (hour, minute, crossServerDateTime, endBuyDateTime), playerID)
111             return
112         
113         canBuyStartHour = 5
114         curServerTime = GameWorld.GetCurrentTime()
115         if crossServerDateTime.hour < canBuyStartHour or curServerTime.hour < canBuyStartHour:
116             PlayerControl.NotifyCode(curPlayer, "CrossBattlefieldBuyLimit")
117             GameWorld.Log("跨服服务器及本服服务器需超过%s点后可购买! crossServerHour=%s,curServerHour=%s" 
118                           % (canBuyStartHour, crossServerDateTime.hour, curServerTime.hour), playerID)
119             return
120         
164b1a 121     moneyBuyMaxCount, moneyType, moneyCount = 0, 0, 0
H 122     todayBuyOpenCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountToday)
123     buyOpenMoneyInfo = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldBuyOpen", 1)
124     if len(buyOpenMoneyInfo) == 3:
125         moneyBuyMaxCount, moneyType, moneyCount = buyOpenMoneyInfo
126         
127     # 购买消耗货币
128     if todayBuyOpenCount < moneyBuyMaxCount:
129         if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyCount):
130             GameWorld.DebugLog("跨服战场召集开启货币不足! moneyType=%s,moneyCount=%s" % (moneyType, moneyCount), playerID)
131             return
132     else:
133         costItemID = IpyGameDataPY.GetFuncCfg("CrossBattlefieldBuyOpen", 2)
134         costItem = ItemCommon.FindItemInPackByItemID(curPlayer, costItemID, IPY_GameWorld.rptItem)
135         if not ItemCommon.CheckItemCanUse(costItem):
136             GameWorld.DebugLog("跨服战场召集开启道具不足! costItemID=%s" % costItemID, playerID)
137             return
138         
139     if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_Battlefield, tick):
140         PlayerControl.NotifyCode(curPlayer, "RequestLater")
141         return
142     
143     dataMsg = {"openHour":hour, "openMinute":minute, "faction":faction, "todayBuyOpenCount":todayBuyOpenCount,
25d85f 144                "serverOnly":serverOnly,
164b1a 145                "accID":curPlayer.GetAccID(),
H 146                "playerID":playerID,
147                "playerName":CrossRealmPlayer.GetCrossPlayerName(curPlayer),
148                "playerJob":curPlayer.GetJob(),
015249 149                "face":curPlayer.GetFace(),
H 150                "facePic":curPlayer.GetFacePic(),
164b1a 151                "playerLV":curPlayer.GetLV(),
H 152                "realmLV":curPlayer.GetOfficialRank(),
153                "fightPower":PlayerControl.GetFightPower(curPlayer),
154                "buyOpenCountWeek":curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek)
155                }
156     GameWorld.SendMsgToCrossServer(ShareDefine.ClientServerMsg_BattlefieldBuyOpen, dataMsg)
157     return
158
159 def GameServer_CrossBattlefield_DoResult(curPlayer, msgData):
160     msgType, dataMsg = msgData[:2]
161     #ret = msgData[2] if len(msgData) > 2 else None
162     
163     ## 战场购买开启场次 
164     if msgType == "BattlefieldBuy":
165         __DoBattlefieldBuy(curPlayer, dataMsg)
166                 
167     elif msgType == "BattlefieldOver":
168         __DoBattlefieldOver(curPlayer, dataMsg)
169         
170     return
171
172 def __DoBattlefieldBuy(curPlayer, dataMsg):
173     
174     playerID = curPlayer.GetPlayerID()
175     openHour, openMinute, faction, todayBuyOpenCount, buyTime = dataMsg
176     updTodayBuyOpenCount, updWeekBuyOpenCount = 0, 0
177     
178     isToday = GameWorld.CheckTimeIsSameServerDayEx(buyTime)
179     if isToday:
180         todayBuyOpenCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountToday)
181         updTodayBuyOpenCount = todayBuyOpenCount + 1
182         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_BuyOpenCountToday, updTodayBuyOpenCount)
183         
184     isSameWeek = GameWorld.CheckTimeIsSameWeek(buyTime)
185     if isSameWeek:
186         weekBuyOpenCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek)
187         updWeekBuyOpenCount = weekBuyOpenCount + 1
188         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek, updWeekBuyOpenCount)
8a103d 189     SyncCrossBattlefieldPlayerInfo(curPlayer)
H 190     
164b1a 191     GameWorld.Log("购买召集跨服战场结果: openHour=%s,openMinute=%s,faction=%s,updTodayBuyOpenCount=%s,updWeekBuyOpenCount=%s,buyTime=%s,isToday=%s,isSameWeek=%s" 
H 192                   % (openHour, openMinute, faction, updTodayBuyOpenCount, updWeekBuyOpenCount, GameWorld.ChangeTimeNumToStr(buyTime), isToday, isSameWeek), playerID)
193     
194     moneyBuyMaxCount, moneyType, moneyCount = 0, 0, 0
195     buyOpenMoneyInfo = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldBuyOpen", 1)
196     if len(buyOpenMoneyInfo) == 3:
197         moneyBuyMaxCount, moneyType, moneyCount = buyOpenMoneyInfo
198         
199     infoDict = {ChConfig.Def_Cost_Reason_SonKey:"BattlefieldBuyOpen", "buyTime":buyTime, "isToday":isToday, "isSameWeek":isSameWeek, 
200                 "updTodayBuyOpenCount":updTodayBuyOpenCount, "updWeekBuyOpenCount":updWeekBuyOpenCount}
201     # 购买消耗货币
202     if todayBuyOpenCount < moneyBuyMaxCount:
203         if not PlayerControl.PayMoney(curPlayer, moneyType, moneyCount, ChConfig.Def_Cost_CrossBattlefield, infoDict):
204             return
205     else:
206         costItemID = IpyGameDataPY.GetFuncCfg("CrossBattlefieldBuyOpen", 2)
207         costItem = ItemCommon.FindItemInPackByItemID(curPlayer, costItemID, IPY_GameWorld.rptItem)
208         if not ItemCommon.CheckItemCanUse(costItem):
209             costItem = ItemCommon.FindItemInPackByItemID(curPlayer, costItemID, IPY_GameWorld.rptWarehouse)
210         if not ItemCommon.CheckItemCanUse(costItem):
211             return
212         ItemCommon.DelItem(curPlayer, costItem, 1, True, "CrossBattlefield", infoDict)
213         
214     # 固定礼包
215     buyAwardItemList = IpyGameDataPY.GetFuncEvalCfg("CrossBattlefieldBuyOpen", 3)
216     ItemControler.GivePlayerItemOrMail(curPlayer, buyAwardItemList)
0c2782 217     
H 218     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_CallOpen, 1)
164b1a 219     return
H 220
221 def __DoBattlefieldOver(curPlayer, dataMsg):
222     
223     playerID = curPlayer.GetPlayerID()
0c2782 224     overTime, \
7ed0e7 225         isWinner, faction, rank, score, highScoreToday, highScoreWeekTotal, enterCountWeek, teamID, \
0c2782 226         isCallOpen, isCalled, killCnt, ckillCntInfo, killBossCnt, killScoreKing, killGuardCnt, auraScore, superItemAwardCnt, \
H 227         factionBuffCollCnt, personBuffCollCnt, crystalCollCnt, wallCollCnt = dataMsg
228         
164b1a 229     isToday = GameWorld.CheckTimeIsSameServerDayEx(overTime)
H 230     isSameWeek = GameWorld.CheckTimeIsSameWeek(overTime)
0c2782 231     GameWorld.Log("跨服战场结算玩家结果: highScoreToday=%s,highScoreWeekTotal=%s,enterCountWeek=%s,overTime=%s,isToday=%s,isSameWeek=%s" 
H 232                   % (highScoreToday, highScoreWeekTotal, enterCountWeek, GameWorld.ChangeTimeNumToStr(overTime), isToday, isSameWeek), playerID)
7ed0e7 233     GameWorld.Log("    isWinner=%s,faction=%s,rank=%s,score=%s,teamID=%s,isCallOpen=%s,isCalled=%s" % (isWinner, faction, rank, score, teamID, isCallOpen, isCalled), playerID)
0c2782 234     GameWorld.Log("    killCnt=%s,ckillCntInfo=%s,killBossCnt=%s,killScoreKing=%s,killGuardCnt=%s,auraScore=%s,superItemAwardCnt=%s" 
H 235                   % (killCnt, ckillCntInfo, killBossCnt, killScoreKing, killGuardCnt, auraScore, superItemAwardCnt), playerID)
236     GameWorld.Log("    factionBuffCollCnt=%s,personBuffCollCnt=%s,crystalCollCnt=%s,wallCollCnt=%s" 
237                   % (factionBuffCollCnt, personBuffCollCnt, crystalCollCnt, wallCollCnt), playerID)
164b1a 238     
H 239     if isToday:
240         addCnt = 1
0c2782 241         # 召集进入由于是免费进入,不需要增加日常次数,直接增加日常活跃
H 242         if isCallOpen or isCalled:
164b1a 243             activityNum = PlayerActivity.GetActivityNum(PlayerActivity.RelatedType_1, ShareDefine.DailyActionID_CrossBattlefield)
H 244             PlayerActivity.AddActivityFinishCnt(curPlayer, activityNum, None, addCnt)
0c2782 245         # 非召集兑入进入的需要增加日常次数
H 246         else:
247             PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_CrossBattlefield, addCnt)
164b1a 248             
H 249         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_HighScoreToday, highScoreToday)
6eb8ce 250         PlayerGubao.AddGubaoItemEffValue(curPlayer, PlayerGubao.GubaoEffType_CrossBattlefield, 1)
164b1a 251         
H 252     if isSameWeek:
253         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_EnterCountWeek, enterCountWeek)
254         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_Battlefield_HighScoreTotalWeek, highScoreWeekTotal)
8a103d 255     SyncCrossBattlefieldPlayerInfo(curPlayer)
H 256     
0c2782 257     # 成就
H 258     PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Join, 1)
7ed0e7 259     if isCalled or teamID:
0c2782 260         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Called, 1)
H 261     if isWinner:
262         if faction == ShareDefine.CampType_Justice:
263             PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_WinJ, 1)
264         elif faction == ShareDefine.CampType_Evil:
265             PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_WinE, 1)
266     if killCnt > 0:
267         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillCnt, killCnt)
268     for ckillCnt, addCnt in ckillCntInfo.items():
269         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_CKillCnt, addCnt, [ckillCnt])
270     if killBossCnt > 0:
271         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillBoss, killBossCnt)
272     if killScoreKing > 0:
273         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillScoreKing, killScoreKing)
274     if killGuardCnt > 0:
275         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_KillGuard, killGuardCnt)
276     if score > 0:
277         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Score, score)
278         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_ScoreMore, 1, [score])
279     if auraScore > 0:
280         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_AuraScore, auraScore)
281     if superItemAwardCnt > 0:
282         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_SuperItem, superItemAwardCnt)
283     if factionBuffCollCnt > 0:    
284         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_FactionBuff, factionBuffCollCnt)
285     if personBuffCollCnt > 0:    
286         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_PersonBuff, personBuffCollCnt)
287     if crystalCollCnt > 0:
288         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Crystal, crystalCollCnt)
289     if wallCollCnt > 0:
290         PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_Battlefield_Wall, wallCollCnt)
164b1a 291     return
H 292
293 def SyncCrossBattlefieldPlayerInfo(curPlayer):
294     clientPack = ChPyNetSendPack.tagMCCrossBattlefieldPlayerInfo()
295     clientPack.BuyOpenCountToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountToday)
296     clientPack.HighScoreToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_HighScoreToday)
8a103d 297     clientPack.EnterCountWeek = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_EnterCountWeek)
H 298     clientPack.BuyOpenCountWeek = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_BuyOpenCountWeek)
299     clientPack.HighScoreTotalWeek = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Battlefield_HighScoreTotalWeek)
ad9ca5 300     clientPack.ZoneID = CrossRealmPlayer.GetCrossPlayerZoneID(curPlayer, ChConfig.Def_FBMapID_CrossBattlefield)
164b1a 301     NetPackCommon.SendFakePack(curPlayer, clientPack)
H 302     return
303