场景时间更新,自动切换气象初步
This commit is contained in:
1 parent
1bcde691bc
commit
be737e45e9
7 files changed
+107
-33
No files matched your search
@@ -53,6 +53,11 @@ func NewPluginPubg() *PluginPubg {
|
||||
areaReduceZSpeed: 0.0,
|
||||
areaPointList: make([]*proto.MapMarkPoint, 0),
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// OnEnable 插件启用生命周期
|
||||
func (p *PluginPubg) OnEnable() {
|
||||
// 监听事件
|
||||
p.ListenEvent(PluginEventIdPlayerKillAvatar, PluginEventPriorityNormal, p.EventKillAvatar)
|
||||
p.ListenEvent(PluginEventIdMarkMap, PluginEventPriorityNormal, p.EventMarkMap)
|
||||
@@ -62,7 +67,6 @@ func NewPluginPubg() *PluginPubg {
|
||||
p.AddGlobalTick(PluginGlobalTickHour, p.GlobalTickHourStart)
|
||||
// 注册命令
|
||||
p.RegCommandController(p.NewPubgCommandController())
|
||||
return p
|
||||
}
|
||||
|
||||
/************************************************** 事件监听 **************************************************/
|
||||
|
||||
@@ -243,6 +243,11 @@ func (t *TickManager) onTickHour(now int64) {
|
||||
|
||||
func (t *TickManager) onTickMinute(now int64) {
|
||||
gdconf.LuaStateLruRemove()
|
||||
for _, world := range WORLD_MANAGER.GetAllWorld() {
|
||||
if world.GetOwner().SceneLoadState == model.SceneEnterDone {
|
||||
GAME.PlayerGameTimeNotify(world)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TickManager) onTick10Second(now int64) {
|
||||
@@ -280,6 +285,13 @@ func (t *TickManager) onTickSecond(now int64) {
|
||||
// 世界里所有玩家的网络延迟广播
|
||||
GAME.WorldPlayerRTTNotify(world)
|
||||
}
|
||||
// 每个场景时间+1
|
||||
for _, scene := range world.sceneMap {
|
||||
if world.GetOwner().Pause {
|
||||
continue
|
||||
}
|
||||
scene.gameTime = scene.gameTime + 1%1440
|
||||
}
|
||||
}
|
||||
// GCG游戏Tick
|
||||
for _, game := range GCG_MANAGER.gameMap {
|
||||
|
||||
+3
-1
@@ -764,7 +764,9 @@ func EnterWeatherArea(luaState *lua.LState) int {
|
||||
return 1
|
||||
}
|
||||
weatherAreaId := luaState.ToInt(2)
|
||||
GAME.SetPlayerWeatherByWeatherAreaId(player, uint32(weatherAreaId))
|
||||
// 设置玩家天气
|
||||
climateType := GAME.GetWeatherAreaClimate(uint32(weatherAreaId))
|
||||
GAME.SetPlayerWeather(player, uint32(weatherAreaId), climateType)
|
||||
luaState.Push(lua.LNumber(0))
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -251,6 +251,30 @@ func (g *Game) PlayerTimeNotify(world *World) {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) PlayerGameTimeNotify(world *World) {
|
||||
for _, player := range world.GetAllPlayer() {
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
playerGameTimeNotify := &proto.PlayerGameTimeNotify{
|
||||
GameTime: scene.GetGameTime(),
|
||||
Uid: scenePlayer.PlayerId,
|
||||
}
|
||||
g.SendMsg(cmd.PlayerGameTimeNotify, scenePlayer.PlayerId, 0, playerGameTimeNotify)
|
||||
// 设置玩家天气
|
||||
climateType := GAME.GetWeatherAreaClimate(player.WeatherInfo.WeatherAreaId)
|
||||
// 跳过相同的天气
|
||||
if climateType == player.WeatherInfo.ClimateType {
|
||||
return
|
||||
}
|
||||
GAME.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Game) GmTalkReq(player *model.Player, payloadMsg pb.Message) {
|
||||
req := payloadMsg.(*proto.GmTalkReq)
|
||||
logger.Info("GmTalkReq: %v", req.Msg)
|
||||
|
||||
+25
-23
@@ -245,8 +245,10 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
|
||||
}
|
||||
g.SendMsg(cmd.PlayerEnterSceneInfoNotify, player.PlayerId, player.ClientSeq, playerEnterSceneInfoNotify)
|
||||
|
||||
// 设置玩家天气
|
||||
weatherAreaId := g.GetPlayerInWeatherAreaId(player, player.Pos)
|
||||
g.SetPlayerWeatherByWeatherAreaId(player, weatherAreaId)
|
||||
climateType := GAME.GetWeatherAreaClimate(weatherAreaId)
|
||||
GAME.SetPlayerWeather(player, weatherAreaId, climateType)
|
||||
}
|
||||
|
||||
g.UpdateWorldScenePlayerInfo(player, world)
|
||||
@@ -358,7 +360,12 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
|
||||
g.AddSceneEntityNotify(player, visionType, entityIdList, false, false)
|
||||
}
|
||||
|
||||
g.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, player.WeatherInfo.ClimateType)
|
||||
// 设置玩家天气
|
||||
sceneAreaWeatherNotify := &proto.SceneAreaWeatherNotify{
|
||||
WeatherAreaId: player.WeatherInfo.WeatherAreaId,
|
||||
ClimateType: player.WeatherInfo.ClimateType,
|
||||
}
|
||||
g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerId, player.ClientSeq, sceneAreaWeatherNotify)
|
||||
|
||||
enterSceneDoneRsp := &proto.EnterSceneDoneRsp{
|
||||
EnterSceneToken: req.EnterSceneToken,
|
||||
@@ -1290,16 +1297,17 @@ func (g *Game) SceneWeatherAreaCheck(player *model.Player, oldPos *model.Vector,
|
||||
return
|
||||
}
|
||||
// 设置玩家天气
|
||||
g.SetPlayerWeatherByWeatherAreaId(player, weatherAreaId)
|
||||
climateType := GAME.GetWeatherAreaClimate(weatherAreaId)
|
||||
GAME.SetPlayerWeather(player, weatherAreaId, climateType)
|
||||
}
|
||||
|
||||
// SetPlayerWeatherByWeatherAreaId 通过天气区域设置玩家天气
|
||||
func (g *Game) SetPlayerWeatherByWeatherAreaId(player *model.Player, weatherAreaId uint32) {
|
||||
// GetWeatherAreaClimate 获取天气区域气象
|
||||
func (g *Game) GetWeatherAreaClimate(weatherAreaId uint32) uint32 {
|
||||
// 获取天气数据配置表
|
||||
weatherConfig := gdconf.GetWeatherDataById(int32(weatherAreaId))
|
||||
if weatherConfig == nil {
|
||||
logger.Error("weather data config not exist, weatherId: %v", weatherAreaId)
|
||||
return
|
||||
return 0
|
||||
}
|
||||
// 如果指定了则使用指定的天气
|
||||
var weatherTemplateConfig *gdconf.WeatherTemplate
|
||||
@@ -1312,7 +1320,7 @@ func (g *Game) SetPlayerWeatherByWeatherAreaId(player *model.Player, weatherArea
|
||||
weatherTemplateMap := gdconf.GetWeatherTemplateMap()[weatherConfig.TemplateName]
|
||||
if weatherTemplateMap == nil {
|
||||
logger.Error("weather template map not exist, templateName: %v", weatherConfig.TemplateName)
|
||||
return
|
||||
return 0
|
||||
}
|
||||
weatherTemplateList := make([]int32, 0, len(weatherTemplateMap))
|
||||
for key := range weatherTemplateMap {
|
||||
@@ -1324,7 +1332,7 @@ func (g *Game) SetPlayerWeatherByWeatherAreaId(player *model.Player, weatherArea
|
||||
// 确保指定的天气模版存在
|
||||
if weatherTemplateConfig == nil {
|
||||
logger.Error("weather template config not exist, templateName: %v, weather: %v", weatherConfig.TemplateName, weather)
|
||||
return
|
||||
return 0
|
||||
}
|
||||
// 随机气象 轮盘赌选择法RWS
|
||||
var climateType uint32
|
||||
@@ -1337,6 +1345,7 @@ func (g *Game) SetPlayerWeatherByWeatherAreaId(player *model.Player, weatherArea
|
||||
constant.CLIMATE_TYPE_MIST: weatherTemplateConfig.Mist,
|
||||
constant.CLIMATE_TYPE_DESERT: weatherTemplateConfig.Desert,
|
||||
}
|
||||
logger.Debug("climate weight: %v", climateWeightMap)
|
||||
randNum := random.GetRandomInt32(0, 100-1)
|
||||
sumWeight := int32(0)
|
||||
for climate, weight := range climateWeightMap {
|
||||
@@ -1346,33 +1355,26 @@ func (g *Game) SetPlayerWeatherByWeatherAreaId(player *model.Player, weatherArea
|
||||
break
|
||||
}
|
||||
}
|
||||
// 设置玩家天气
|
||||
g.SetPlayerWeather(player, weatherAreaId, climateType)
|
||||
return climateType
|
||||
}
|
||||
|
||||
// SetPlayerWeather 设置玩家天气
|
||||
func (g *Game) SetPlayerWeather(player *model.Player, weatherAreaId uint32, climateType uint32) {
|
||||
logger.Debug("weather climateType: %v, weatherAreaId: %v", climateType, weatherAreaId)
|
||||
|
||||
// 获取天气数据配置表
|
||||
weatherConfig := gdconf.GetWeatherDataById(int32(weatherAreaId))
|
||||
if weatherConfig == nil {
|
||||
logger.Error("weather data config not exist, weatherId: %v", weatherAreaId)
|
||||
return
|
||||
}
|
||||
|
||||
// 记录数据
|
||||
player.WeatherInfo.WeatherAreaId = weatherAreaId
|
||||
player.WeatherInfo.ClimateType = climateType
|
||||
|
||||
sceneAreaWeatherNotify := &proto.SceneAreaWeatherNotify{
|
||||
WeatherAreaId: uint32(weatherConfig.WeatherAreaId),
|
||||
WeatherGadgetId: uint32(weatherConfig.GadgetID),
|
||||
ClimateType: climateType,
|
||||
TransDuration: 0,
|
||||
WeatherValueMap: nil,
|
||||
WeatherAreaId: weatherAreaId,
|
||||
ClimateType: climateType,
|
||||
}
|
||||
if player.SceneJump {
|
||||
g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerId, player.ClientSeq, sceneAreaWeatherNotify)
|
||||
} else {
|
||||
g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerId, 0, sceneAreaWeatherNotify)
|
||||
}
|
||||
g.SendMsg(cmd.SceneAreaWeatherNotify, player.PlayerId, player.ClientSeq, sceneAreaWeatherNotify)
|
||||
}
|
||||
|
||||
/************************************************** 打包封装 **************************************************/
|
||||
|
||||
+26
-8
@@ -294,15 +294,11 @@ func (g *Game) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) {
|
||||
return
|
||||
}
|
||||
scene := world.GetSceneById(player.SceneId)
|
||||
scene.ChangeGameTime(gameTime)
|
||||
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
playerGameTimeNotify := &proto.PlayerGameTimeNotify{
|
||||
GameTime: scene.GetGameTime(),
|
||||
Uid: scenePlayer.PlayerId,
|
||||
}
|
||||
g.SendMsg(cmd.PlayerGameTimeNotify, scenePlayer.PlayerId, scenePlayer.ClientSeq, playerGameTimeNotify)
|
||||
if scene == nil {
|
||||
logger.Error("scene is nil, sceneId: %v, uid: %v", player.SceneId, player.PlayerId)
|
||||
return
|
||||
}
|
||||
g.ChangeGameTime(player, scene, gameTime)
|
||||
|
||||
changeGameTimeRsp := &proto.ChangeGameTimeRsp{
|
||||
CurGameTime: scene.GetGameTime(),
|
||||
@@ -514,6 +510,28 @@ func (g *Game) ExitTransPointRegionNotify(player *model.Player, payloadMsg pb.Me
|
||||
|
||||
/************************************************** 游戏功能 **************************************************/
|
||||
|
||||
// ChangeGameTime 修改游戏场景时间
|
||||
func (g *Game) ChangeGameTime(player *model.Player, scene *Scene, gameTime uint32) {
|
||||
logger.Debug("change game time, gameTime: %v, uid: %v", gameTime, player.PlayerId)
|
||||
scene.ChangeGameTime(gameTime)
|
||||
|
||||
for _, scenePlayer := range scene.GetAllPlayer() {
|
||||
playerGameTimeNotify := &proto.PlayerGameTimeNotify{
|
||||
GameTime: scene.GetGameTime(),
|
||||
Uid: scenePlayer.PlayerId,
|
||||
}
|
||||
g.SendMsg(cmd.PlayerGameTimeNotify, scenePlayer.PlayerId, scenePlayer.ClientSeq, playerGameTimeNotify)
|
||||
}
|
||||
|
||||
// 设置玩家天气
|
||||
climateType := GAME.GetWeatherAreaClimate(player.WeatherInfo.WeatherAreaId)
|
||||
// 跳过相同的天气
|
||||
if climateType == player.WeatherInfo.ClimateType {
|
||||
return
|
||||
}
|
||||
GAME.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType)
|
||||
}
|
||||
|
||||
func (g *Game) monsterDrop(player *model.Player, entity *Entity) {
|
||||
sceneGroupConfig := gdconf.GetSceneGroup(int32(entity.GetGroupId()))
|
||||
if sceneGroupConfig == nil {
|
||||
|
||||
@@ -111,6 +111,7 @@ func runPacketCaptureApi() {
|
||||
e := gin.Default()
|
||||
e.GET("/packet/capture/ws", packetCaptureWs)
|
||||
e.GET("/packet/capture/list", packetCaptureList)
|
||||
e.GET("/packet/capture/clear", packetCaptureClear)
|
||||
port := config.GetConfig().HttpPort
|
||||
addr := ":" + strconv.Itoa(int(port))
|
||||
err := e.Run(addr)
|
||||
@@ -156,6 +157,17 @@ func packetCaptureList(ctx *gin.Context) {
|
||||
_, _ = ctx.Writer.WriteString(string(data))
|
||||
}
|
||||
|
||||
func packetCaptureClear(ctx *gin.Context) {
|
||||
if PacketCaptureSession == nil {
|
||||
_, _ = ctx.Writer.WriteString("500")
|
||||
return
|
||||
}
|
||||
PacketCaptureSession.PktLock.Lock()
|
||||
PacketCaptureSession.PktList = make([]*net.Packet, 0)
|
||||
PacketCaptureSession.PktLock.Unlock()
|
||||
_, _ = ctx.Writer.WriteString("ok")
|
||||
}
|
||||
|
||||
func runForward(messageQueue *mq.MessageQueue) {
|
||||
for {
|
||||
netMsg := <-messageQueue.GetNetMsg()
|
||||
|
||||
Reference in new issue
Block a user