From fd937a7095cdebc38f8490873005114ba06bc8d7 Mon Sep 17 00:00:00 2001 From: UnKownOwO <80520429@qq.com> Date: Fri, 5 Apr 2024 22:42:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E9=97=B4=E9=94=81?= =?UTF-8?q?=E5=AE=9A=E3=80=81=E5=A4=A9=E6=B0=94=E9=94=81=E5=AE=9A=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/game_command_controller.go | 15 ++++-------- gs/game/game_command_gm.go | 4 ++-- gs/game/game_tick_manager.go | 18 ++++++++------ gs/game/lua_func.go | 4 ++-- gs/game/player_base.go | 9 +++++-- gs/game/player_common.go | 3 --- gs/game/player_login.go | 4 ++-- gs/game/player_scene.go | 38 +++++++++++++++++++----------- gs/game/player_world.go | 2 +- 9 files changed, 54 insertions(+), 43 deletions(-) diff --git a/gs/game/game_command_controller.go b/gs/game/game_command_controller.go index 45bd3dcf..95050951 100644 --- a/gs/game/game_command_controller.go +++ b/gs/game/game_command_controller.go @@ -770,7 +770,7 @@ func (c *CommandManager) NewWeatherCommandController() *CommandController { AliasList: []string{"weather"}, Description: "{alias} 天气", UsageList: []string{ - "{alias} [天气区域ID] <气象类型> 更改天气", + "{alias} <气象类型> 更改天气", }, Perm: CommandPermNormal, Func: c.WeatherCommand, @@ -778,21 +778,16 @@ func (c *CommandManager) NewWeatherCommandController() *CommandController { } func (c *CommandManager) WeatherCommand(content *CommandContent) bool { - var weatherAreaId = content.AssignPlayer.WeatherInfo.WeatherAreaId // 天气区域id - var climateType uint32 // 气象类型 + var climateType uint32 // 气象类型 - return content.Option("uint32", func(param any) bool { - // 天气区域id - weatherAreaId = param.(uint32) - return true - }).Dynamic("uint32", func(param any) bool { + return content.Dynamic("uint32", func(param any) bool { // 气象类型 climateType = param.(uint32) return true }).Execute(func() bool { // 设置天气 - c.gmCmd.GMSetWeather(content.AssignPlayer.PlayerId, weatherAreaId, climateType) - content.SendSuccMessage(content.Executor, "已更改天气,指定UID:%v,天气区域ID:%v,气象类型:%v。", content.AssignPlayer.PlayerId, weatherAreaId, climateType) + c.gmCmd.GMSetWeather(content.AssignPlayer.PlayerId, climateType) + content.SendSuccMessage(content.Executor, "已更改天气,指定UID:%v,气象类型:%v。", content.AssignPlayer.PlayerId, climateType) return true }) } diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go index a28cf890..9c3029ef 100644 --- a/gs/game/game_command_gm.go +++ b/gs/game/game_command_gm.go @@ -405,13 +405,13 @@ func (g *GMCmd) GMUnlockAllArea(userId uint32, sceneId uint32) { } // GMSetWeather 设置天气 -func (g *GMCmd) GMSetWeather(userId uint32, weatherAreaId uint32, climateType uint32) { +func (g *GMCmd) GMSetWeather(userId uint32, climateType uint32) { player := USER_MANAGER.GetOnlineUser(userId) if player == nil { logger.Error("player is nil, uid: %v", userId) return } - GAME.SetPlayerWeather(player, weatherAreaId, climateType) + GAME.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType, true) } // GMCreateMonster 在玩家附近创建怪物 diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index 1e037085..23f6bafd 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -249,7 +249,12 @@ func (t *TickManager) onTickMinute(now int64) { gdconf.LuaStateLruRemove() for _, world := range WORLD_MANAGER.GetAllWorld() { if world.GetOwner().SceneLoadState == model.SceneEnterDone { - GAME.PlayerGameTimeNotify(world) + // 天气气象随机 + for _, scene := range world.GetAllScene() { + for _, scenePlayer := range scene.GetAllPlayer() { + GAME.WeatherClimateRandom(scenePlayer, scenePlayer.WeatherInfo.WeatherAreaId) + } + } } } } @@ -299,13 +304,12 @@ func (t *TickManager) onTickSecond(now int64) { if world.IsMultiplayerWorld() { GAME.WorldPlayerRTTNotify(world) } - } - // 每个场景时间+1 - for _, scene := range world.GetAllScene() { - if world.GetOwner().Pause { - continue + // 场景时间增加 + if !world.GetOwner().Pause && world.GetOwner().PropMap[constant.PLAYER_PROP_IS_GAME_TIME_LOCKED] != 1 { + for _, scene := range world.GetAllScene() { + scene.ChangeGameTime(scene.gameTime + 1) + } } - scene.ChangeGameTime(scene.GetGameTime() + 1) } } // GCG游戏Tick diff --git a/gs/game/lua_func.go b/gs/game/lua_func.go index 68055992..68b15d4e 100644 --- a/gs/game/lua_func.go +++ b/gs/game/lua_func.go @@ -847,7 +847,7 @@ func EnterWeatherArea(luaState *lua.LState) int { weatherAreaId := luaState.ToInt(2) // 设置玩家天气 climateType := GAME.GetWeatherAreaClimate(uint32(weatherAreaId)) - GAME.SetPlayerWeather(player, uint32(weatherAreaId), climateType) + GAME.SetPlayerWeather(player, uint32(weatherAreaId), climateType, true) luaState.Push(lua.LNumber(0)) return 1 } @@ -865,7 +865,7 @@ func SetWeatherAreaState(luaState *lua.LState) int { } weatherAreaId := luaState.ToInt(2) climateType := luaState.ToInt(3) - GAME.SetPlayerWeather(player, uint32(weatherAreaId), uint32(climateType)) + GAME.SetPlayerWeather(player, uint32(weatherAreaId), uint32(climateType), true) luaState.Push(lua.LNumber(0)) return 1 } diff --git a/gs/game/player_base.go b/gs/game/player_base.go index b697a4e4..f6fe34ca 100644 --- a/gs/game/player_base.go +++ b/gs/game/player_base.go @@ -19,8 +19,13 @@ import ( func (g *Game) PlayerSetPauseReq(player *model.Player, payloadMsg pb.Message) { req := payloadMsg.(*proto.PlayerSetPauseReq) + // 处于多人游戏中禁止暂停 + if player.IsInMp { + g.SendError(cmd.PlayerSetPauseRsp, player, &proto.PlayerSetPauseRsp{}, proto.Retcode_RET_FAIL) + } player.Pause = req.IsPaused - g.SendMsg(cmd.PlayerSetPauseRsp, player.PlayerId, player.ClientSeq, new(proto.PlayerSetPauseRsp)) + + g.SendSucc(cmd.PlayerSetPauseRsp, player, &proto.PlayerSetPauseRsp{}) } func (g *Game) SetPlayerPropReq(player *model.Player, payloadMsg pb.Message) { @@ -29,7 +34,7 @@ func (g *Game) SetPlayerPropReq(player *model.Player, payloadMsg pb.Message) { logger.Debug("player set prop, key: %v, value: %v, uid: %v", propValue.Type, propValue.Val, player.PlayerId) player.PropMap[propValue.Type] = uint32(propValue.Val) } - g.SendMsg(cmd.SetPlayerPropRsp, player.PlayerId, player.ClientSeq, new(proto.SetPlayerPropRsp)) + g.SendSucc(cmd.SetPlayerPropRsp, player, &proto.SetPlayerPropRsp{}) } func (g *Game) SetOpenStateReq(player *model.Player, payloadMsg pb.Message) { diff --git a/gs/game/player_common.go b/gs/game/player_common.go index 4a25028d..b27f5c8e 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -243,9 +243,6 @@ func (g *Game) PlayerGameTimeNotify(world *World) { Uid: scenePlayer.PlayerId, } g.SendMsg(cmd.PlayerGameTimeNotify, scenePlayer.PlayerId, 0, playerGameTimeNotify) - - // 天气气象随机 - g.WeatherClimateRandom(scenePlayer) } } } diff --git a/gs/game/player_login.go b/gs/game/player_login.go index f9e94041..5c72fe52 100644 --- a/gs/game/player_login.go +++ b/gs/game/player_login.go @@ -195,8 +195,8 @@ func (g *Game) CreatePlayer(userId uint32) *model.Player { player.PropMap[constant.PLAYER_PROP_IS_SPRING_AUTO_USE] = 1 player.PropMap[constant.PLAYER_PROP_SPRING_AUTO_USE_PERCENT] = 50 player.PropMap[constant.PLAYER_PROP_IS_FLYABLE] = 0 - player.PropMap[constant.PLAYER_PROP_IS_WEATHER_LOCKED] = 1 - player.PropMap[constant.PLAYER_PROP_IS_GAME_TIME_LOCKED] = 1 + player.PropMap[constant.PLAYER_PROP_IS_WEATHER_LOCKED] = 0 + player.PropMap[constant.PLAYER_PROP_IS_GAME_TIME_LOCKED] = 0 player.PropMap[constant.PLAYER_PROP_IS_TRANSFERABLE] = 1 player.PropMap[constant.PLAYER_PROP_MAX_STAMINA] = 10000 diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 4d7bc050..2ca1ef11 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -277,13 +277,17 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) { g.SendMsg(cmd.PlayerEnterSceneInfoNotify, player.PlayerId, player.ClientSeq, playerEnterSceneInfoNotify) } - // 设置玩家天气 - weatherAreaId := g.GetPlayerInWeatherAreaId(player, player.GetPos()) - if weatherAreaId != 0 { + // 天气未初始化 或 未锁定天气并且是场景跳跃 更新天气 + if player.WeatherInfo.WeatherAreaId == 0 || player.PropMap[constant.PLAYER_PROP_IS_WEATHER_LOCKED] == 0 { + // 初始化天气区域id + weatherAreaId := g.GetPlayerInWeatherAreaId(player, player.GetPos()) + if weatherAreaId == 0 { + logger.Error("weather area id error, weatherAreaId: %v", weatherAreaId) + return + } + // 获取天气气象 climateType := g.GetWeatherAreaClimate(weatherAreaId) - g.SetPlayerWeather(player, weatherAreaId, climateType) - } else { - logger.Error("weather area id error, weatherAreaId: %v", weatherAreaId) + g.SetPlayerWeather(player, weatherAreaId, climateType, false) } g.UpdateWorldScenePlayerInfo(player, world) @@ -1521,14 +1525,18 @@ func (g *Game) GetPlayerInWeatherAreaId(player *model.Player, newPos *model.Vect } // WeatherClimateRandom 随机天气气象 -func (g *Game) WeatherClimateRandom(player *model.Player) { - // 设置玩家天气 - climateType := g.GetWeatherAreaClimate(player.WeatherInfo.WeatherAreaId) +func (g *Game) WeatherClimateRandom(player *model.Player, weatherAreaId uint32) { + // 天气气象锁定则跳过 + if player.PropMap[constant.PLAYER_PROP_IS_WEATHER_LOCKED] == 1 { + return + } + // 获取天气气象 + climateType := g.GetWeatherAreaClimate(weatherAreaId) // 跳过相同的天气 if climateType == player.WeatherInfo.ClimateType { return } - g.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType) + g.SetPlayerWeather(player, player.WeatherInfo.WeatherAreaId, climateType, true) } // SceneWeatherAreaCheck 场景天气区域变更检测 @@ -1551,9 +1559,8 @@ func (g *Game) SceneWeatherAreaCheck(player *model.Player, oldPos *model.Vector, if player.WeatherInfo.WeatherAreaId == weatherAreaId { return } - // 设置玩家天气 - climateType := g.GetWeatherAreaClimate(weatherAreaId) - g.SetPlayerWeather(player, weatherAreaId, climateType) + // 随机天气气象 + g.WeatherClimateRandom(player, weatherAreaId) } // GetWeatherAreaClimate 获取天气气象 @@ -1616,7 +1623,7 @@ func (g *Game) GetWeatherAreaClimate(weatherAreaId uint32) uint32 { } // SetPlayerWeather 设置玩家天气 -func (g *Game) SetPlayerWeather(player *model.Player, weatherAreaId uint32, climateType uint32) { +func (g *Game) SetPlayerWeather(player *model.Player, weatherAreaId uint32, climateType uint32, sendNotify bool) { // 获取天气数据配置表 weatherData := gdconf.GetWeatherDataByWeatherAreaId(int32(weatherAreaId)) if weatherData == nil { @@ -1631,6 +1638,9 @@ func (g *Game) SetPlayerWeather(player *model.Player, weatherAreaId uint32, clim player.WeatherInfo.JsonWeatherAreaId = uint32(weatherData.JsonWeatherAreaId) player.WeatherInfo.ClimateType = climateType + if !sendNotify { + return + } sceneAreaWeatherNotify := &proto.SceneAreaWeatherNotify{ WeatherAreaId: weatherAreaId, ClimateType: climateType, diff --git a/gs/game/player_world.go b/gs/game/player_world.go index 9e853673..2f81dbdb 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -285,7 +285,7 @@ func (g *Game) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) { g.ChangeGameTime(scene, gameTime) // 天气气象随机 - g.WeatherClimateRandom(player) + g.WeatherClimateRandom(player, player.WeatherInfo.WeatherAreaId) rsp := &proto.ChangeGameTimeRsp{ CurGameTime: scene.GetGameTime(),