From 0c3ef8a641c968e6a2f51abeb84f890342e4cb0c Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 15 十二月 2025 11:42:13 +0800
Subject: [PATCH] 129 【战斗】战斗系统-服务端(优化效果6011可指定检查自己还是检查目标的buff;)
---
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py | 135 +++++++++++++++++++++++++++++++++++++++-----
1 files changed, 118 insertions(+), 17 deletions(-)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py
index 318d0f4..03b3c43 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py
@@ -17,12 +17,22 @@
import DBDataMgr
import GameWorld
+import PyMongoMain
+import PlayerFamily
import IpyGameDataPY
+import IPY_GameWorld
+import DataRecordPack
import PlayerEventCounter
-import ShareDefine
-import PlayerTeam
-import PyGameData
+import PlayerViewCache
+import PlayerControl
import NetPackCommon
+import PlayerOnline
+import ShareDefine
+import PyGameData
+import ItemCommon
+import BattleObj
+import ChPlayer
+import ObjPool
import datetime
import time
@@ -63,7 +73,7 @@
#调用该函数时,C++已经设置好区服,如果改变区服需重启
def StartDB(tick):
#初始化数据库, 恢复备档(按区服记录), 加载静态表
- from PyMongoDB import PyMongoMain
+ #from PyMongoDB import PyMongoMain
PyMongoMain.StartDB()
InitGameWorld(tick)
return
@@ -75,7 +85,9 @@
serverID = GameWorld.GetGameWorld().GetServerID()
GameWorld.Log("服务器启动初始化InitGameWorld: serverID=%s" % serverID)
DBDataMgr.OnServerStart() # 优先加载公共数据
+ ItemCommon.InitPyItem()
LoadDBPlayer()
+ PlayerViewCache.LoadRobot()
PyGameData.g_initGameTime = int(time.time()) # 放到加载数据之后
#初始话开服时间、星期几
@@ -228,9 +240,30 @@
## 每秒分钟执行一次
if not PyGameData.g_initGameTime:
return
- if tick - PyGameData.g_highProcessTick < 1000:
+ curTime = int(time.time())
+ if not PyGameData.g_highProcessTime:
+ PyGameData.g_highProcessTime = curTime
+
+ if curTime < PyGameData.g_highProcessTime:
+ GameWorld.Log("时间回调了: lastProcessTime=%s" % (GameWorld.ChangeTimeNumToStr(PyGameData.g_highProcessTime)))
+ PyGameData.g_highProcessTime = curTime
+ OnFixServerTimeProcess()
+
+ passSeconds = curTime - PyGameData.g_highProcessTime
+ if passSeconds < 1:
return
- PyGameData.g_highProcessTick = tick
+ if passSeconds > 10:
+ GameWorld.Log("时间误差过大: passSeconds=%s,lastProcessTime=%s" % (passSeconds, GameWorld.ChangeTimeNumToStr(PyGameData.g_highProcessTime)))
+ OnFixServerTimeProcess()
+
+ PyGameData.g_highProcessTime = curTime
+
+ if PyGameData.g_serverClosing:
+ CheckCloseMapOK()
+ return
+
+ PyMongoMain.GetUserCtrlDB().onSecondProcess()
+
OnMinute(tick)
# 其他逻辑
@@ -239,6 +272,21 @@
return
+def OnFixServerTimeProcess():
+
+ # 补同步一次服务器时间给前端
+ playerManager = GameWorld.GetPlayerManager()
+ for i in xrange(playerManager.GetPlayerCount()):
+ curPlayer = playerManager.GetPlayerByIndex(i)
+
+ if not GameWorld.IsNormalPlayer(curPlayer):
+ continue
+
+ ChPlayer.Sync_PyServerDataTimeToClient(curPlayer)
+ ChPlayer.Sync_OpenServerDay(curPlayer)
+
+ return
+
def OnMinute(tick):
## 每整分钟执行一次
curTime = GameWorld.GetCurrentTime()
@@ -252,15 +300,40 @@
DBDataMgr.OnMinute(curTime)
DoLogic_GameWorldEvenByTime(tick)
+ #每5分钟
+ if curMinute % 5 == 0:
+ OnMinute_5(curTime, tick)
+
#其他功能逻辑
#GameWorldActionControl.Dispose_OperationActionState()
#GameWorldActionControl.Dispose_DailyActionState()
#GameWorldActionControl.Dispose_FBStateTime()
+ PlayerControl.OnMinute(curTime)
+ PlayerFamily.OnMinute()
+ PlayerOnline.OnMinute()
+ BattleObj.OnMinute()
+ ObjPool.OnMinute(curTime)
- PlayerTeam.OnCheckTeamPlayerDisconnectTimeout(tick)
__CheckIpyDataRecycle(curTime)
return
+def OnMinute_5(curTime, tick):
+ ## 每5分钟
+ DisposeGameActivePlayer(curTime, tick)
+ return
+
+def DisposeGameActivePlayer(curTime, tick):
+ curMinute = curTime.minute
+ gameWorld = GameWorld.GetGameWorld()
+ noteData = gameWorld.GetGameWorldDictByKey("OnlineCntM")
+ if noteData == curMinute:
+ # 同一分钟只处理1次
+ return
+ gameWorld.SetGameWorldDict("OnlineCntM", curMinute)
+ activePlayerCount = GameWorld.GetPlayerManager().OnlineCount()
+ DataRecordPack.DR_OnLinePlayerCount(activePlayerCount) # 总在线
+ return
+
def DoLogic_GameWorldEvenByTime(tick):
#-----------服务器当前时间
curTime = datetime.datetime.today()
@@ -367,15 +440,43 @@
# 关闭地图通知py处理
def CloseMap(tick):
+ serverID = GameWorld.GetGameWorld().GetServerID()
+ GameWorld.Log("地图服务器关闭开始保存数据! serverID=%s" % serverID)
+ PyGameData.g_serverClosing = 1
+
+ playerManager = GameWorld.GetPlayerManager()
+ for i in xrange(playerManager.GetPlayerCount()):
+ curPlayer = playerManager.GetPlayerByIndex(i)
+ if not curPlayer or curPlayer.GetID() == 0 or curPlayer.IsEmpty():
+ continue
+
+ #镜像玩家回收、真实玩家踢下线
+ if GameWorld.IsMirrorPlayer(curPlayer):
+ PlayerControl.DeleteMirror(curPlayer)
+ else:
+ curPlayer.Kick(IPY_GameWorld.disMapServerClose)
+
+ DBDataMgr.OnServerClose()
+ return
+
+def CheckCloseMapOK():
+ '''检查等待关服数据处理完毕
+ 没有玩家了,且公共数据已入库完毕
+ '''
+ if PyGameData.g_serverClosing != 1:
+ return
+ if not PyGameData.g_closeSaveDataOK:
+ return
+ if GameWorld.GetPlayerManager().OnlineCount():
+ return
+ DBDataMgr.ClearBackupFile() # 正常关服数据处理完毕可直接删除备档
+
from PyMongoDB.DBCommon import CommonDefine
from PyMongoDB.Common import CommFunc
- #初始化数据库, 恢复备档(按区服记录), 加载静态表
- try:
- pass
- finally:
- #回发地图 处理完成,必须被调用地图才能正常关闭
- data = ''
- data = CommFunc.WriteBYTE(data, CommonDefine.dgPlayerSaveGameServerData)
- NetPackCommon.SendPyPackToMapServerSelf(data, len(data))
- GameWorld.Log("python 已处理地图关闭逻辑")
- return
\ No newline at end of file
+ data = ''
+ data = CommFunc.WriteBYTE(data, CommonDefine.dgPlayerSaveGameServerData)
+ NetPackCommon.SendPyPackToMapServerSelf(data, len(data))
+ GameWorld.Log("python 已处理地图关闭逻辑")
+ PyGameData.g_serverClosing = 2
+ return
+
\ No newline at end of file
--
Gitblit v1.8.0