From 022fb2067481c3afaafe88ae77530241e6ee7715 Mon Sep 17 00:00:00 2001 From: flswld Date: Fri, 15 Sep 2023 22:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9F=E5=A4=A7=E9=80=83=E6=9D=80=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/game.go | 16 +++- gs/game/game_command_gm.go | 12 +++ gs/game/game_command_manager.go | 2 + gs/game/game_pubg.go | 11 ++- gs/game/game_tick_manager.go | 128 +++++++++++++------------------- gs/game/game_world_manager.go | 1 - gs/game/player_common.go | 12 +++ gs/game/player_fight_sync.go | 11 ++- 8 files changed, 107 insertions(+), 86 deletions(-) diff --git a/gs/game/game.go b/gs/game/game.go index 751ba651..d1b48d8f 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -85,14 +85,11 @@ func NewGameCore(db *dao.Dao, messageQueue *mq.MessageQueue, gsId uint32, gsAppi sign = BigWorldAiSign } r.ai = r.CreateRobot(uid, name, sign) - r.isStop = false WORLD_MANAGER.InitAiWorld(r.ai) COMMAND_MANAGER.SetSystem(r.ai) - if !r.IsMainGs() { - COMMAND_MANAGER.gmCmd.GMUnlockAllPoint(r.ai.PlayerId, 3) - } USER_MANAGER.SetRemoteUserOnlineState(BigWorldAiUid, true, mainGsAppid) r.run() + r.isStop = false return r } @@ -137,6 +134,17 @@ func (g *Game) CreateRobot(uid uint32, name string, sign string) *model.Player { g.PostEnterSceneReq(robot, &proto.PostEnterSceneReq{ EnterSceneToken: world.GetEnterSceneToken(), }) + if uid == BigWorldAiUid { + g.EntityForceSyncReq(robot, &proto.EntityForceSyncReq{ + MotionInfo: &proto.MotionInfo{ + Pos: &proto.Vector{X: 500.0, Y: 900.0, Z: -500.0}, + Rot: new(proto.Vector), + }, + EntityId: world.GetPlayerWorldAvatarEntityId(robot, 10000007), + }) + } else { + COMMAND_MANAGER.gmCmd.GMUnlockAllPoint(uid, 3) + } return robot } diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go index a064b4be..dd82c1bd 100644 --- a/gs/game/game_command_gm.go +++ b/gs/game/game_command_gm.go @@ -417,3 +417,15 @@ func (g *GMCmd) SendMsgToPlayer(cmdName string, userId uint32, msgJson string) { } GAME.SendMsg(cmdId, userId, 0, msg) } + +func (g *GMCmd) StartPubg(v bool) { + if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { + world.StartPubg() + } +} + +func (g *GMCmd) StopPubg(v bool) { + if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { + world.StopPubg() + } +} diff --git a/gs/game/game_command_manager.go b/gs/game/game_command_manager.go index 510069cc..3a18fb4a 100644 --- a/gs/game/game_command_manager.go +++ b/gs/game/game_command_manager.go @@ -136,9 +136,11 @@ func (c *CommandManager) PlayerInputCommand(player *model.Player, targetUid uint func (c *CommandManager) CallGMCmd(funcName string, paramList []string) bool { fn := c.gmCmdRefValue.MethodByName(funcName) if !fn.IsValid() { + logger.Error("gm func not valid, func: %v", funcName) return false } if fn.Type().NumIn() != len(paramList) { + logger.Error("gm func param num not match, func: %v, need: %v, give: %v", funcName, fn.Type().NumIn(), len(paramList)) return false } in := make([]reflect.Value, fn.Type().NumIn()) diff --git a/gs/game/game_pubg.go b/gs/game/game_pubg.go index 5f600430..3f214be8 100644 --- a/gs/game/game_pubg.go +++ b/gs/game/game_pubg.go @@ -35,7 +35,7 @@ type Pubg struct { areaPointList []*proto.MapMarkPoint // 客户端区域地图坐标列表 } -func (w *World) NewPubg() { +func (w *World) StartPubg() { w.pubg = &Pubg{ world: w, blueAreaCenterPos: &model.Vector{X: 0.0, Y: 0.0, Z: 0.0}, @@ -48,6 +48,13 @@ func (w *World) NewPubg() { areaReduceZSpeed: 0.0, areaPointList: make([]*proto.MapMarkPoint, 0), } + w.pubg.RefreshArea() + w.chatMsgList = make([]*proto.ChatInfo, 0) +} + +func (w *World) StopPubg() { + w.pubg = nil + TICK_MANAGER.CreateUserTimer(w.GetOwner().PlayerId, UserTimerActionPubgEnd, 30) } func (p *Pubg) GetAreaPointList() []*proto.MapMarkPoint { @@ -74,7 +81,7 @@ func (p *Pubg) IsInBlueArea(pos *model.Vector) bool { func (p *Pubg) RefreshArea() { info := "" if p.phase == PUBG_PHASE_START { - info = fmt.Sprintf("安全区已出现,当前%v位存活玩家。", len(p.GetAlivePlayerList())) + info = fmt.Sprintf("安全区已生成,当前%v位存活玩家。", len(p.GetAlivePlayerList())) p.blueAreaCenterPos = &model.Vector{X: 500.0, Y: 0.0, Z: -500.0} p.blueAreaRadius = 2000.0 p.safeAreaCenterPos = &model.Vector{X: 0.0, Y: 0.0, Z: 0.0} diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index f5a34690..a8bf4857 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -174,7 +174,6 @@ func (t *TickManager) userTimerHandle(userId uint32, action int, data []any) { } GAME.ReLoginPlayer(worldPlayer.PlayerId, true) } - world.pubg = nil } } @@ -252,15 +251,11 @@ func (t *TickManager) onDayChange(now int64) { func (t *TickManager) onHourChange(now int64) { logger.Info("on hour change, time: %v", now) - for _, world := range WORLD_MANAGER.GetAllWorld() { - if WORLD_MANAGER.IsBigWorld(world) { - if world.GetPubg() != nil { - continue - } - world.NewPubg() - pubg := world.GetPubg() - pubg.RefreshArea() + if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { + if world.GetPubg() != nil { + return } + world.StartPubg() } } @@ -283,25 +278,19 @@ func (t *TickManager) onTick10Second(now int64) { func (t *TickManager) onTick5Second(now int64) { for _, world := range WORLD_MANAGER.GetAllWorld() { - if WORLD_MANAGER.IsAiWorld(world) { - if WORLD_MANAGER.IsBigWorld(world) && world.GetPubg() != nil { - continue - } - - for applyUid := range world.owner.CoopApplyMap { - GAME.PlayerDealEnterWorld(world.owner, applyUid, true) - } - } if world.GetOwner().SceneLoadState == model.SceneEnterDone { - if WORLD_MANAGER.IsBigWorld(world) { - continue - } - // 多人世界其他玩家的坐标位置广播 GAME.WorldPlayerLocationNotify(world) GAME.ScenePlayerLocationNotify(world) } } + aiWorld := WORLD_MANAGER.GetAiWorld() + if WORLD_MANAGER.IsBigWorld(aiWorld) && aiWorld.GetPubg() != nil { + return + } + for applyUid := range aiWorld.GetOwner().CoopApplyMap { + GAME.PlayerDealEnterWorld(aiWorld.GetOwner(), applyUid, true) + } } func (t *TickManager) onTickSecond(now int64) { @@ -310,48 +299,38 @@ func (t *TickManager) onTickSecond(now int64) { // 世界里所有玩家的网络延迟广播 GAME.WorldPlayerRTTNotify(world) } - - if WORLD_MANAGER.IsBigWorld(world) { - pubg := world.GetPubg() - if pubg == nil { - continue - } - pubg.UpdateArea() - scene := world.GetSceneById(world.GetOwner().SceneId) - for _, scenePlayer := range scene.GetAllPlayer() { - if scenePlayer.PlayerId == world.GetOwner().PlayerId { - continue - } - avatarEntityId := world.GetPlayerWorldAvatarEntityId(scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer)) - entity := scene.GetEntity(avatarEntityId) - if entity.GetFightProp()[constant.FIGHT_PROP_CUR_HP] <= 0.0 { - continue - } - if !pubg.IsInBlueArea(scenePlayer.Pos) { - scene := world.GetSceneById(scenePlayer.SceneId) - GAME.handleEvtBeingHit(scenePlayer, scene, &proto.EvtBeingHitInfo{ - AttackResult: &proto.AttackResult{ - AttackerId: 0, - DefenseId: world.GetPlayerWorldAvatarEntityId(scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer)), - Damage: 10, - }, - }) - } - } - alivePlayerList := pubg.GetAlivePlayerList() - if len(alivePlayerList) <= 1 { - if len(alivePlayerList) == 1 { - info := fmt.Sprintf("『%v』大吉大利,今晚吃鸡。", alivePlayerList[0].NickName) - GAME.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}}) - } - TICK_MANAGER.CreateUserTimer(world.GetOwner().PlayerId, UserTimerActionPubgEnd, 30) - } - } } // // GCG游戏Tick // for _, game := range GCG_MANAGER.gameMap { // game.onTick() // } + if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { + pubg := world.GetPubg() + if pubg == nil { + return + } + pubg.UpdateArea() + scene := world.GetSceneById(world.GetOwner().SceneId) + for _, scenePlayer := range scene.GetAllPlayer() { + if !pubg.IsInBlueArea(scenePlayer.Pos) { + GAME.handleEvtBeingHit(scenePlayer, scene, &proto.EvtBeingHitInfo{ + AttackResult: &proto.AttackResult{ + AttackerId: 0, + DefenseId: world.GetPlayerWorldAvatarEntityId(scenePlayer, world.GetPlayerActiveAvatarId(scenePlayer)), + Damage: 10, + }, + }) + } + } + alivePlayerList := pubg.GetAlivePlayerList() + if len(alivePlayerList) <= 1 { + if len(alivePlayerList) == 1 { + info := fmt.Sprintf("『%v』大吉大利,今晚吃鸡。", alivePlayerList[0].NickName) + GAME.PlayerChatReq(world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}}) + } + world.StopPubg() + } + } } func (t *TickManager) onTick200MilliSecond(now int64) { @@ -374,22 +353,21 @@ func (t *TickManager) onTick100MilliSecond(now int64) { GAME.RestoreCountStaminaHandler(player) } } - - if WORLD_MANAGER.IsBigWorld(world) { - bulletPhysicsEngine := world.GetBulletPhysicsEngine() - hitList := bulletPhysicsEngine.Update(now) - for _, rigidBody := range hitList { - scene := world.GetSceneById(rigidBody.sceneId) - defAvatarEntity := scene.GetEntity(rigidBody.hitAvatarEntityId) - defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid()) - GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{ - AttackResult: &proto.AttackResult{ - AttackerId: rigidBody.avatarEntityId, - DefenseId: rigidBody.hitAvatarEntityId, - Damage: 100, - }, - }) - } + } + if world := WORLD_MANAGER.GetAiWorld(); WORLD_MANAGER.IsBigWorld(world) { + bulletPhysicsEngine := world.GetBulletPhysicsEngine() + hitList := bulletPhysicsEngine.Update(now) + for _, rigidBody := range hitList { + scene := world.GetSceneById(rigidBody.sceneId) + defAvatarEntity := scene.GetEntity(rigidBody.hitAvatarEntityId) + defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid()) + GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{ + AttackResult: &proto.AttackResult{ + AttackerId: rigidBody.avatarEntityId, + DefenseId: rigidBody.hitAvatarEntityId, + Damage: 100, + }, + }) } } } diff --git a/gs/game/game_world_manager.go b/gs/game/game_world_manager.go index 977d3092..512bfbe0 100644 --- a/gs/game/game_world_manager.go +++ b/gs/game/game_world_manager.go @@ -101,7 +101,6 @@ func (w *WorldManager) GetAiWorld() *World { func (w *WorldManager) InitAiWorld(owner *model.Player) { w.aiWorld = w.GetWorldById(owner.WorldId) w.aiWorld.ChangeToMultiplayer() - if w.IsBigWorld(w.aiWorld) { w.aiWorld.NewPhysicsEngine(w.sceneBlockAoiMap) } diff --git a/gs/game/player_common.go b/gs/game/player_common.go index e1dd5f31..d15cdc85 100644 --- a/gs/game/player_common.go +++ b/gs/game/player_common.go @@ -152,6 +152,12 @@ func (g *Game) WorldPlayerLocationNotify(world *World) { }, }, } + + if WORLD_MANAGER.IsBigWorld(world) { + playerWorldLocationInfo.PlayerLoc.Pos = new(proto.Vector) + playerWorldLocationInfo.PlayerLoc.Rot = new(proto.Vector) + } + worldPlayerLocationNotify.PlayerWorldLocList = append(worldPlayerLocationNotify.PlayerWorldLocList, playerWorldLocationInfo) } g.SendToWorldA(world, cmd.WorldPlayerLocationNotify, 0, worldPlayerLocationNotify) @@ -179,6 +185,12 @@ func (g *Game) ScenePlayerLocationNotify(world *World) { Z: float32(scenePlayer.Rot.Z), }, } + + if WORLD_MANAGER.IsBigWorld(world) { + playerLocationInfo.Pos = new(proto.Vector) + playerLocationInfo.Rot = new(proto.Vector) + } + scenePlayerLocationNotify.PlayerLocList = append(scenePlayerLocationNotify.PlayerLocList, playerLocationInfo) // 载具位置 for _, entityId := range scenePlayer.VehicleInfo.CreateEntityIdMap { diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index a7810e9b..d32680e3 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -161,11 +161,14 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr fightProp := defEntity.GetFightProp() currHp := fightProp[constant.FIGHT_PROP_CUR_HP] + if currHp == 0.0 { + return + } currHp -= attackResult.Damage deltaHp := -attackResult.Damage - if currHp < 0 { + if currHp < 0.0 { deltaHp -= currHp - currHp = 0 + currHp = 0.0 } fightProp[constant.FIGHT_PROP_CUR_HP] = currHp g.EntityFightPropUpdateNotifyBroadcast(scene, defEntity) @@ -177,7 +180,7 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr EntityId: defEntity.GetId(), PropType: constant.FIGHT_PROP_CUR_HP, }) - if currHp == 0 { + if currHp == 0.0 { defAvatarEntity := defEntity.GetAvatarEntity() g.KillPlayerAvatar(player, defAvatarEntity.GetAvatarId(), proto.PlayerDieType_PLAYER_DIE_GM) @@ -199,7 +202,7 @@ func (g *Game) handleEvtBeingHit(player *model.Player, scene *Scene, hitInfo *pr } } case constant.ENTITY_TYPE_MONSTER: - if currHp == 0 { + if currHp == 0.0 { g.KillEntity(player, scene, defEntity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM) } case constant.ENTITY_TYPE_GADGET: