diff --git a/gs/game/game.go b/gs/game/game.go index 28ece2cf..798536af 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -258,6 +258,7 @@ const ( EndlessLoopCheckTypeTriggerQuest EndlessLoopCheckTypeUseItem EndlessLoopCheckTypeCallLuaFunc + EndlessLoopCheckTypeCheckFinishedCond ) func (g *Game) EndlessLoopCheck(checkType int) { @@ -299,6 +300,10 @@ func (g *Game) EndlessLoopCheck(checkType int) { if checkCount > 1000 { EndlessLoopHandleFunc() } + case EndlessLoopCheckTypeCheckFinishedCond: + if checkCount > 1000 { + EndlessLoopHandleFunc() + } default: } } diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index 23f6bafd..3eafd5d4 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -306,9 +306,7 @@ func (t *TickManager) onTickSecond(now int64) { } // 场景时间增加 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) - } + world.ChangeGameTime(world.GetGameTime() + 1) } } } diff --git a/gs/game/game_world_manager.go b/gs/game/game_world_manager.go index dcbcaf89..b11f6fe4 100644 --- a/gs/game/game_world_manager.go +++ b/gs/game/game_world_manager.go @@ -856,6 +856,14 @@ func (w *World) RemoveWaitPlayer(uid uint32) { delete(w.waitEnterPlayerMap, uid) } +func (w *World) GetGameTime() uint32 { + return w.GetOwner().GetDbWorld().GameTime +} + +func (w *World) ChangeGameTime(time uint32) { + w.GetOwner().GetDbWorld().GameTime = time % 1440 +} + func (w *World) CreateScene(sceneId uint32) *Scene { scene := &Scene{ id: sceneId, @@ -863,7 +871,6 @@ func (w *World) CreateScene(sceneId uint32) *Scene { playerMap: make(map[uint32]*model.Player), entityMap: make(map[uint32]*Entity), groupMap: make(map[uint32]*Group), - gameTime: 0, createTime: time.Now().UnixMilli(), meeoIndex: 0, } diff --git a/gs/game/game_world_scene.go b/gs/game/game_world_scene.go index 18f2f330..26bd7b89 100644 --- a/gs/game/game_world_scene.go +++ b/gs/game/game_world_scene.go @@ -19,7 +19,6 @@ type Scene struct { playerMap map[uint32]*model.Player entityMap map[uint32]*Entity // 场景中全部的实体 groupMap map[uint32]*Group // 场景中按group->suite分类的实体 - gameTime uint32 // 游戏内提瓦特大陆的时间 createTime int64 // 场景创建时间 meeoIndex uint32 // 客户端风元素染色同步协议的计数器 monsterWudi bool // 是否开启场景内怪物无敌 @@ -49,10 +48,6 @@ func (s *Scene) GetAllGroup() map[uint32]*Group { return s.groupMap } -func (s *Scene) GetGameTime() uint32 { - return s.gameTime -} - func (s *Scene) GetMeeoIndex() uint32 { return s.meeoIndex } @@ -69,10 +64,6 @@ func (s *Scene) SetMonsterWudi(monsterWudi bool) { s.monsterWudi = monsterWudi } -func (s *Scene) ChangeGameTime(time uint32) { - s.gameTime = time % 1440 -} - func (s *Scene) GetSceneCreateTime() int64 { return s.createTime } diff --git a/gs/game/player_common.go b/gs/game/player_common.go index b27f5c8e..76a4a607 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -236,14 +236,12 @@ func (g *Game) PlayerTimeNotify(world *World) { } func (g *Game) PlayerGameTimeNotify(world *World) { - for _, scene := range world.sceneMap { - for _, scenePlayer := range scene.GetAllPlayer() { - playerGameTimeNotify := &proto.PlayerGameTimeNotify{ - GameTime: scene.GetGameTime(), - Uid: scenePlayer.PlayerId, - } - g.SendMsg(cmd.PlayerGameTimeNotify, scenePlayer.PlayerId, 0, playerGameTimeNotify) + for _, player := range world.GetAllPlayer() { + playerGameTimeNotify := &proto.PlayerGameTimeNotify{ + GameTime: world.GetGameTime(), + Uid: player.PlayerId, } + g.SendMsg(cmd.PlayerGameTimeNotify, player.PlayerId, 0, playerGameTimeNotify) } } diff --git a/gs/game/player_quest.go b/gs/game/player_quest.go index 9880653a..e6b96030 100644 --- a/gs/game/player_quest.go +++ b/gs/game/player_quest.go @@ -231,6 +231,7 @@ func (g *Game) StartQuest(player *model.Player, questId uint32, notifyClient boo g.ExecQuest(player, questId, QuestExecTypeStart) g.QuestStartTriggerCheck(player, questId) + g.CheckQuestFinishedCond(player, questId) if notifyClient { ntf := &proto.QuestListUpdateNotify{ @@ -401,7 +402,7 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId) continue } - g.ChangeGameTime(scene, uint32(hour*60)) + g.ChangeGameTime(world, uint32(hour*60)) case constant.QUEST_EXEC_TYPE_ROLLBACK_QUEST: // 回滚任务 if len(questExec.Param) != 1 { @@ -421,6 +422,36 @@ func (g *Game) ExecQuest(player *model.Player, questId uint32, questExecType int } } +// CheckQuestFinishedCond 检测任务已完成的条件 +func (g *Game) CheckQuestFinishedCond(player *model.Player, questId uint32) { + g.EndlessLoopCheck(EndlessLoopCheckTypeCheckFinishedCond) + questDataConfig := gdconf.GetQuestDataById(int32(questId)) + if questDataConfig == nil { + return + } + // TODO 检测已经完成的失败条件 + // 检测已经完成的完成条件 + for _, cond := range questDataConfig.FinishCondList { + switch cond.Type { + case constant.QUEST_FINISH_COND_TYPE_UNLOCK_TRANS_POINT: + sceneId := uint32(cond.Param[0]) + pointId := uint32(cond.Param[1]) + + dbWorld := player.GetDbWorld() + dbScene := dbWorld.GetSceneById(sceneId) + if dbScene == nil { + logger.Error("get dbScene is nil, sceneId: %v, uid: %v", sceneId, player.PlayerId) + continue + } + unlock := dbScene.CheckPointUnlock(pointId) + if !unlock { + continue + } + g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_TRANS_POINT, "", int32(sceneId), int32(pointId)) + } + } +} + // TriggerQuest 触发任务 func (g *Game) TriggerQuest(player *model.Player, cond int32, complexParam string, param ...int32) { g.EndlessLoopCheck(EndlessLoopCheckTypeTriggerQuest) diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 2ca1ef11..1ae11201 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -234,7 +234,7 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) { g.SendMsg(cmd.SceneTimeNotify, player.PlayerId, player.ClientSeq, sceneTimeNotify) playerGameTimeNotify := &proto.PlayerGameTimeNotify{ - GameTime: scene.GetGameTime(), + GameTime: world.GetGameTime(), Uid: player.PlayerId, } g.SendMsg(cmd.PlayerGameTimeNotify, player.PlayerId, player.ClientSeq, playerGameTimeNotify) diff --git a/gs/game/player_stamina.go b/gs/game/player_stamina.go index 1382235b..560f14f9 100644 --- a/gs/game/player_stamina.go +++ b/gs/game/player_stamina.go @@ -366,25 +366,25 @@ func (g *Game) HandleDrown(player *model.Player, stamina uint32) { if player.StaminaInfo.State != proto.MotionState_MOTION_SWIM_MOVE && player.StaminaInfo.State != proto.MotionState_MOTION_SWIM_DASH { return } - logger.Debug("player drown, curStamina: %v, state: %v", stamina, player.StaminaInfo.State) // 设置角色为死亡 world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { logger.Error("world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId) return } - for _, worldAvatar := range world.GetPlayerWorldAvatarList(player) { - dbAvatar := player.GetDbAvatar() - avatar := dbAvatar.GetAvatarById(worldAvatar.GetAvatarId()) - if avatar == nil { - logger.Error("get avatar is nil, avatarId: %v", worldAvatar.GetAvatarId()) - continue - } - if avatar.LifeState != constant.LIFE_STATE_ALIVE { - continue - } - g.KillPlayerAvatar(player, worldAvatar.GetAvatarId(), proto.PlayerDieType_PLAYER_DIE_DRAWN) + // 获取现行的角色 + activeAvatarId := player.GetDbTeam().GetActiveAvatarId() + activeAvatar := player.GetDbAvatar().GetAvatarById(activeAvatarId) + if activeAvatar == nil { + logger.Error("active avatar is nil, avatarId: %v", activeAvatarId) + return } + if activeAvatar.LifeState != constant.LIFE_STATE_ALIVE { + return + } + g.KillPlayerAvatar(player, activeAvatarId, proto.PlayerDieType_PLAYER_DIE_DRAWN) + + logger.Debug("player drown, curStamina: %v, state: %v", stamina, player.StaminaInfo.State) } // SetVehicleStamina 设置载具耐力 diff --git a/gs/game/player_world.go b/gs/game/player_world.go index 2f81dbdb..ce70f5c3 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -276,19 +276,14 @@ func (g *Game) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) { logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId) return } - scene := world.GetSceneById(player.GetSceneId()) - if scene == nil { - logger.Error("scene is nil, sceneId: %v, uid: %v", player.GetSceneId(), player.PlayerId) - return - } logger.Debug("change game time, gameTime: %v, uid: %v", gameTime, player.PlayerId) - g.ChangeGameTime(scene, gameTime) + g.ChangeGameTime(world, gameTime) // 天气气象随机 g.WeatherClimateRandom(player, player.WeatherInfo.WeatherAreaId) rsp := &proto.ChangeGameTimeRsp{ - CurGameTime: scene.GetGameTime(), + CurGameTime: world.GetGameTime(), } g.SendMsg(cmd.ChangeGameTimeRsp, player.PlayerId, player.ClientSeq, rsp) } @@ -564,15 +559,15 @@ func (g *Game) UnlockPlayerSceneArea(player *model.Player, sceneId uint32, areaI g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_UNLOCK_AREA, "", int32(sceneId), int32(areaId)) } -// ChangeGameTime 修改游戏场景时间 -func (g *Game) ChangeGameTime(scene *Scene, gameTime uint32) { - scene.ChangeGameTime(gameTime) - for _, scenePlayer := range scene.GetAllPlayer() { +// ChangeGameTime 修改游戏时间 +func (g *Game) ChangeGameTime(world *World, gameTime uint32) { + world.ChangeGameTime(gameTime) + for _, player := range world.GetAllPlayer() { playerGameTimeNotify := &proto.PlayerGameTimeNotify{ - GameTime: scene.GetGameTime(), - Uid: scenePlayer.PlayerId, + GameTime: world.GetGameTime(), + Uid: player.PlayerId, } - g.SendMsg(cmd.PlayerGameTimeNotify, scenePlayer.PlayerId, scenePlayer.ClientSeq, playerGameTimeNotify) + g.SendMsg(cmd.PlayerGameTimeNotify, player.PlayerId, player.ClientSeq, playerGameTimeNotify) } } diff --git a/gs/model/db_world.go b/gs/model/db_world.go index dd10188b..db51524a 100644 --- a/gs/model/db_world.go +++ b/gs/model/db_world.go @@ -7,6 +7,7 @@ import ( type DbWorld struct { SceneMap map[uint32]*DbScene MapMarkList []*MapMark + GameTime uint32 // 游戏内提瓦特大陆的时间 } type DbScene struct { @@ -26,6 +27,7 @@ type MapMark struct { func (p *Player) GetDbWorld() *DbWorld { if p.DbWorld == nil { p.DbWorld = new(DbWorld) + p.DbWorld.GameTime = 8 * 60 // 初始时间 } if p.DbWorld.SceneMap == nil { p.DbWorld.SceneMap = make(map[uint32]*DbScene)