From 6c0826138f3684b8052ea9770a52fcda8ceb2617 Mon Sep 17 00:00:00 2001 From: flswld Date: Sat, 9 Sep 2023 01:51:30 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8E=9FFPS]=E7=89=A9=E7=90=86=E5=BC=95?= =?UTF-8?q?=E6=93=8E/=E7=94=98=E9=9B=A8=E5=AF=B9=E7=8B=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/game_physics_engine.go | 188 +++++++++++++++++++++++++++++++++ gs/game/game_tick_manager.go | 5 + gs/game/game_world_manager.go | 8 +- gs/game/player_fight_sync.go | 102 ++++++++++++++---- gs/game/player_scene.go | 8 +- pkg/alg/shape.go | 14 ++- pkg/alg/vector.go | 14 +++ 7 files changed, 308 insertions(+), 31 deletions(-) create mode 100644 gs/game/game_physics_engine.go diff --git a/gs/game/game_physics_engine.go b/gs/game/game_physics_engine.go new file mode 100644 index 00000000..fe015655 --- /dev/null +++ b/gs/game/game_physics_engine.go @@ -0,0 +1,188 @@ +package game + +import ( + "math" + + "hk4e/common/constant" + "hk4e/pkg/alg" + "hk4e/pkg/logger" +) + +const ( + AVATAR_RADIUS = 0.4 + AVATAR_HEIGHT = 2.0 +) + +// RigidBody 刚体 +type RigidBody struct { + entityId uint32 // 子弹实体id + avatarEntityId uint32 // 子弹发射者角色实体id + sceneId uint32 // 子弹所在场景id + position *alg.Vector3 // 坐标 + velocity *alg.Vector3 // 速度 + drag float32 // 阻力参数 + mass float32 // 质量 +} + +// PhysicsEngine 物理引擎 +type PhysicsEngine struct { + rigidBodyMap map[uint32]*RigidBody // 刚体集合 + acc float32 // 重力加速度 + lastUpdateTime int64 // 上一次更新时间 + sceneBlockAoiMap map[uint32]*alg.AoiManager // 全局各场景地图的aoi管理器 + world *World // 世界对象 +} + +func (w *World) NewPhysicsEngine(sceneBlockAoiMap map[uint32]*alg.AoiManager) { + w.bulletPhysicsEngine = &PhysicsEngine{ + rigidBodyMap: make(map[uint32]*RigidBody), + acc: -5.0, + sceneBlockAoiMap: sceneBlockAoiMap, + world: w, + } +} + +func (p *PhysicsEngine) Update(now int64) []*Entity { + hitEntityList := make([]*Entity, 0) + dt := float32(now-p.lastUpdateTime) / 1000.0 + for _, rigidBody := range p.rigidBodyMap { + aoiManager, exist := p.sceneBlockAoiMap[rigidBody.sceneId] + if !exist { + p.DestroyRigidBody(rigidBody.entityId) + continue + } + if !aoiManager.IsValidAoiPos(rigidBody.position.X, rigidBody.position.Y, rigidBody.position.Z) { + p.DestroyRigidBody(rigidBody.entityId) + continue + } + // 阻力作用于速度 + dvx := rigidBody.drag * rigidBody.velocity.X * dt + if math.Abs(float64(dvx)) >= math.Abs(float64(rigidBody.velocity.X)) { + rigidBody.velocity.X = 0.0 + } else { + rigidBody.velocity.X -= dvx + } + dvy := rigidBody.drag * rigidBody.velocity.Y * dt + if math.Abs(float64(dvy)) >= math.Abs(float64(rigidBody.velocity.Y)) { + rigidBody.velocity.Y = 0.0 + } else { + rigidBody.velocity.Y -= dvy + } + dvz := rigidBody.drag * rigidBody.velocity.Z * dt + if math.Abs(float64(dvz)) >= math.Abs(float64(rigidBody.velocity.Z)) { + rigidBody.velocity.Z = 0.0 + } else { + rigidBody.velocity.Z -= dvz + } + // 重力作用于速度 + rigidBody.velocity.Y += p.acc * dt + // 速度作用于位移 + oldPos := &alg.Vector3{X: rigidBody.position.X, Y: rigidBody.position.Y, Z: rigidBody.position.Z} + rigidBody.position.X += rigidBody.velocity.X * dt + rigidBody.position.Y += rigidBody.velocity.Y * dt + rigidBody.position.Z += rigidBody.velocity.Z * dt + newPos := &alg.Vector3{X: rigidBody.position.X, Y: rigidBody.position.Y, Z: rigidBody.position.Z} + // 碰撞检测 + entity := p.Collision(rigidBody.sceneId, rigidBody.avatarEntityId, oldPos, newPos) + if entity != nil { + hitEntityList = append(hitEntityList, entity) + p.DestroyRigidBody(rigidBody.entityId) + } + logger.Debug("[PhysicsEngineUpdate] e: %v, s: %v, p: %v, v: %v", rigidBody.entityId, rigidBody.sceneId, rigidBody.position, rigidBody.velocity) + } + p.lastUpdateTime = now + return hitEntityList +} + +func (p *PhysicsEngine) Collision(sceneId uint32, avatarEntityId uint32, oldPos *alg.Vector3, newPos *alg.Vector3) *Entity { + scene := p.world.GetSceneById(sceneId) + for _, entity := range scene.GetAllEntity() { + if entity.GetEntityType() != constant.ENTITY_TYPE_AVATAR { + continue + } + avatarEntity := entity.GetAvatarEntity() + player := USER_MANAGER.GetOnlineUser(avatarEntity.GetUid()) + if avatarEntity.GetAvatarId() != p.world.GetPlayerActiveAvatarId(player) { + continue + } + if entity.GetId() == avatarEntityId { + continue + } + avatarPos := entity.GetPos() + // x轴 + lineMinX := float32(0) + lineMaxX := float32(0) + if oldPos.X < newPos.X { + lineMinX = oldPos.X + lineMaxX = newPos.X + } else { + lineMinX = newPos.X + lineMaxX = oldPos.X + } + shapeMinX := float32(avatarPos.X) - AVATAR_RADIUS + shapeMaxX := float32(avatarPos.X) + AVATAR_RADIUS + if lineMaxX < shapeMinX || lineMinX > shapeMaxX { + continue + } + // z轴 + lineMinZ := float32(0) + lineMaxZ := float32(0) + if oldPos.Z < newPos.Z { + lineMinZ = oldPos.Z + lineMaxZ = newPos.Z + } else { + lineMinZ = newPos.Z + lineMaxZ = oldPos.Z + } + shapeMinZ := float32(avatarPos.Z) - AVATAR_RADIUS + shapeMaxZ := float32(avatarPos.Z) + AVATAR_RADIUS + if lineMaxZ < shapeMinZ || lineMinZ > shapeMaxZ { + continue + } + // y轴 + lineMinY := float32(0) + lineMaxY := float32(0) + if oldPos.Y < newPos.Y { + lineMinY = oldPos.Y + lineMaxY = newPos.Y + } else { + lineMinY = newPos.Y + lineMaxY = oldPos.Y + } + shapeMinY := float32(avatarPos.Y) - AVATAR_HEIGHT/2.0 + shapeMaxY := float32(avatarPos.Y) + AVATAR_HEIGHT/2.0 + if lineMaxY < shapeMinY || lineMinY > shapeMaxY { + continue + } + return entity + } + return nil +} + +func (p *PhysicsEngine) IsRigidBody(entityId uint32) bool { + _, exist := p.rigidBodyMap[entityId] + return exist +} + +func (p *PhysicsEngine) CreateRigidBody(entityId, avatarEntityId, sceneId uint32, px, py, pz float32, vx, vy, vz float32) { + rigidBody := &RigidBody{ + entityId: entityId, + avatarEntityId: avatarEntityId, + sceneId: sceneId, + position: &alg.Vector3{X: px, Y: py, Z: pz}, + velocity: &alg.Vector3{X: vx, Y: vy, Z: vz}, + drag: 0.01, + mass: 1.0, + } + logger.Debug("[CreateRigidBody] e: %v, s: %v, p: %v, v: %v", rigidBody.entityId, rigidBody.sceneId, rigidBody.position, rigidBody.velocity) + p.rigidBodyMap[entityId] = rigidBody +} + +func (p *PhysicsEngine) DestroyRigidBody(entityId uint32) { + if !p.IsRigidBody(entityId) { + return + } + rigidBody := p.rigidBodyMap[entityId] + logger.Debug("[DestroyRigidBody] e: %v, s: %v, p: %v, v: %v", rigidBody.entityId, rigidBody.sceneId, rigidBody.position, rigidBody.velocity) + delete(p.rigidBodyMap, entityId) +} diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index 69558662..a906853a 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -263,6 +263,11 @@ func (t *TickManager) onTick100MilliSecond(now int64) { GAME.RestoreCountStaminaHandler(player) } } + bulletPhysicsEngine := world.GetBulletPhysicsEngine() + hitEntityList := bulletPhysicsEngine.Update(now) + for _, entity := range hitEntityList { + GAME.ServerEvtBeingHitInfo(world.owner, entity.GetId(), entity.GetId(), 100.0) + } } } diff --git a/gs/game/game_world_manager.go b/gs/game/game_world_manager.go index 10abe737..4a487ebe 100644 --- a/gs/game/game_world_manager.go +++ b/gs/game/game_world_manager.go @@ -66,6 +66,7 @@ func (w *WorldManager) CreateWorld(owner *model.Player) *World { peerList: make([]*model.Player, 0), bigWorldAoi: nil, } + world.NewPhysicsEngine(w.sceneBlockAoiMap) world.mpLevelEntityId = world.GetNextWorldEntityId(constant.ENTITY_TYPE_MP_LEVEL) w.worldMap[worldId] = world if w.IsBigWorld(world) { @@ -177,7 +178,7 @@ func (w *WorldManager) LoadSceneBlockAoiMap() { } // 将每个block作为aoi格子 并在格子中放入block拥有的所有group aoiManager := alg.NewAoiManager() - aoiManager.SetAoiRange(minX, maxX, -1.0, 1.0, minZ, maxZ) + aoiManager.SetAoiRange(minX, maxX, -1000, 1000, minZ, maxZ) aoiManager.Init3DRectAoiManager(numX, 1, numZ, true) for _, block := range sceneLuaConfig.BlockMap { for _, group := range block.GroupMap { @@ -221,6 +222,11 @@ type World struct { multiplayerTeam *MultiplayerTeam // 多人队伍 peerList []*model.Player // 玩家编号列表 bigWorldAoi *alg.AoiManager // 大世界的aoi管理器 + bulletPhysicsEngine *PhysicsEngine // 蓄力箭子弹物理引擎 +} + +func (w *World) GetBulletPhysicsEngine() *PhysicsEngine { + return w.bulletPhysicsEngine } func (w *World) GetId() uint32 { diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index 1b3de893..311227da 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -1,6 +1,7 @@ package game import ( + "math" "strings" "time" @@ -100,7 +101,7 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa logger.Error("parse EvtBeingHitInfo error: %v", err) break } - // logger.Debug("EvtBeingHitInfo: %v, ForwardType: %v", evtBeingHitInfo, entry.ForwardType) + logger.Debug("EvtBeingHitInfo: %+v, ForwardType: %v", evtBeingHitInfo, entry.ForwardType) attackResult := evtBeingHitInfo.AttackResult if attackResult == nil { logger.Error("attackResult is nil") @@ -142,7 +143,7 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa logger.Error("parse EntityMoveInfo error: %v", err) break } - // logger.Debug("EntityMoveInfo: %v, ForwardType: %v", entityMoveInfo, entry.ForwardType) + // logger.Debug("EntityMoveInfo: %+v, ForwardType: %v", entityMoveInfo, entry.ForwardType) motionInfo := entityMoveInfo.MotionInfo if motionInfo.Pos == nil || motionInfo.Rot == nil { break @@ -215,7 +216,7 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa logger.Error("parse EvtAnimatorParameterInfo error: %v", err) break } - // logger.Debug("EvtAnimatorParameterInfo: %v, ForwardType: %v", evtAnimatorParameterInfo, entry.ForwardType) + // logger.Debug("EvtAnimatorParameterInfo: %+v, ForwardType: %v", evtAnimatorParameterInfo, entry.ForwardType) case proto.CombatTypeArgument_COMBAT_ANIMATOR_STATE_CHANGED: evtAnimatorStateChangedInfo := new(proto.EvtAnimatorStateChangedInfo) err := pb.Unmarshal(entry.CombatData, evtAnimatorStateChangedInfo) @@ -223,7 +224,7 @@ func (g *Game) CombatInvocationsNotify(player *model.Player, payloadMsg pb.Messa logger.Error("parse EvtAnimatorStateChangedInfo error: %v", err) break } - // logger.Debug("EvtAnimatorStateChangedInfo: %v, ForwardType: %v", evtAnimatorStateChangedInfo, entry.ForwardType) + // logger.Debug("EvtAnimatorStateChangedInfo: %+v, ForwardType: %v", evtAnimatorStateChangedInfo, entry.ForwardType) } player.CombatInvokeHandler.AddEntry(entry.ForwardType, entry) } @@ -443,7 +444,7 @@ func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Mess logger.Error("parse AbilityMetaModifierChange error: %v", err) continue } - // logger.Debug("EntityId: %v, ModifierChange: %v", entry.EntityId, modifierChange) + // logger.Debug("EntityId: %v, ModifierChange: %+v", entry.EntityId, modifierChange) // 处理耐力消耗 g.HandleAbilityStamina(player, entry) g.handleGadgetEntityAbilityLow(player, entry.EntityId, entry.ArgumentType, modifierChange) @@ -454,7 +455,7 @@ func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Mess logger.Error("parse AbilityMixinCostStamina error: %v", err) continue } - // logger.Debug("EntityId: %v, MixinCostStamina: %v", entry.EntityId, costStamina) + // logger.Debug("EntityId: %v, MixinCostStamina: %+v", entry.EntityId, costStamina) // 处理耐力消耗 g.HandleAbilityStamina(player, entry) case proto.AbilityInvokeArgument_ABILITY_META_MODIFIER_DURABILITY_CHANGE: @@ -464,7 +465,7 @@ func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Mess logger.Error("parse AbilityMetaModifierDurabilityChange error: %v", err) continue } - // logger.Debug("EntityId: %v, DurabilityChange: %v", entry.EntityId, modifierDurabilityChange) + // logger.Debug("EntityId: %v, DurabilityChange: %+v", entry.EntityId, modifierDurabilityChange) } } } @@ -476,7 +477,7 @@ func (g *Game) ClientAbilityInitFinishNotify(player *model.Player, payloadMsg pb } invokeHandler := model.NewInvokeHandler[proto.AbilityInvokeEntry]() for _, entry := range req.Invokes { - // logger.Debug("ClientAbilityInitFinishNotify: %v", entry) + // logger.Debug("ClientAbilityInitFinishNotify: %+v", entry) invokeHandler.AddEntry(entry.ForwardType, entry) } DoForward[proto.AbilityInvokeEntry](player, invokeHandler, @@ -491,7 +492,7 @@ func (g *Game) ClientAbilityChangeNotify(player *model.Player, payloadMsg pb.Mes } invokeHandler := model.NewInvokeHandler[proto.AbilityInvokeEntry]() for _, entry := range req.Invokes { - // logger.Debug("ClientAbilityChangeNotify: %v", entry) + // logger.Debug("ClientAbilityChangeNotify: %+v", entry) invokeHandler.AddEntry(entry.ForwardType, entry) } DoForward[proto.AbilityInvokeEntry](player, invokeHandler, @@ -554,7 +555,7 @@ func (g *Game) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.Message) if player.SceneLoadState != model.SceneEnterDone { return } - logger.Debug("EvtDoSkillSuccNotify: %v", req) + // logger.Debug("EvtDoSkillSuccNotify: %+v", req) // 处理技能开始的耐力消耗 g.SkillStartStamina(player, req.CasterId, req.SkillId) g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_SKILL, "", int32(req.SkillId)) @@ -565,7 +566,7 @@ func (g *Game) EvtAvatarEnterFocusNotify(player *model.Player, payloadMsg pb.Mes if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAvatarEnterFocusNotify: %v", req) + // logger.Debug("EvtAvatarEnterFocusNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -579,7 +580,7 @@ func (g *Game) EvtAvatarUpdateFocusNotify(player *model.Player, payloadMsg pb.Me if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAvatarUpdateFocusNotify: %v", req) + // logger.Debug("EvtAvatarUpdateFocusNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -593,7 +594,7 @@ func (g *Game) EvtAvatarExitFocusNotify(player *model.Player, payloadMsg pb.Mess if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAvatarExitFocusNotify: %v", req) + // logger.Debug("EvtAvatarExitFocusNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -607,7 +608,7 @@ func (g *Game) EvtEntityRenderersChangedNotify(player *model.Player, payloadMsg if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtEntityRenderersChangedNotify: %v", req) + // logger.Debug("EvtEntityRenderersChangedNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -621,7 +622,7 @@ func (g *Game) EvtBulletDeactiveNotify(player *model.Player, payloadMsg pb.Messa if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtBulletDeactiveNotify: %v", req) + // logger.Debug("EvtBulletDeactiveNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -635,11 +636,17 @@ func (g *Game) EvtBulletHitNotify(player *model.Player, payloadMsg pb.Message) { if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtBulletHitNotify: %v", req) + // logger.Debug("EvtBulletHitNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } + bulletPhysicsEngine := world.GetBulletPhysicsEngine() + if bulletPhysicsEngine.IsRigidBody(req.EntityId) { + logger.Debug("[FPS] EvtBulletHitNotify: %+v", req) + bulletPhysicsEngine.DestroyRigidBody(req.EntityId) + _ = req.HitPoint + } scene := world.GetSceneById(player.SceneId) g.SendToSceneA(scene, cmd.EvtBulletHitNotify, player.ClientSeq, req) } @@ -649,7 +656,7 @@ func (g *Game) EvtBulletMoveNotify(player *model.Player, payloadMsg pb.Message) if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtBulletMoveNotify: %v", req) + // logger.Debug("EvtBulletMoveNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -663,11 +670,39 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtCreateGadgetNotify: %v", req) + // logger.Debug("EvtCreateGadgetNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return } + // 甘雨冰属性蓄力箭 + if req.ConfigId == 41037009 && world.GetMultiplayer() { + logger.Debug("[FPS] EvtCreateGadgetNotify: %+v", req) + pitchAngleRaw := float64(req.InitEulerAngles.X) + pitchAngle := 0.0 + if pitchAngleRaw < 90.0 { + pitchAngle = -pitchAngleRaw + } else if pitchAngleRaw > 270.0 { + pitchAngle = 360.0 - pitchAngleRaw + } else { + logger.Error("invalid raw pitch angle: %v, uid: %v", pitchAngleRaw, player.PlayerId) + return + } + vy := math.Sin(pitchAngle/360.0*2*math.Pi) * 50.0 + vxz := math.Cos(pitchAngle/360.0*2*math.Pi) * 50.0 + yawAngle := float64(req.InitEulerAngles.Y) + vx := math.Sin(yawAngle/360.0*2*math.Pi) * vxz + vz := math.Cos(yawAngle/360.0*2*math.Pi) * vxz + bulletPhysicsEngine := world.GetBulletPhysicsEngine() + activeAvatarId := world.GetPlayerActiveAvatarId(player) + bulletPhysicsEngine.CreateRigidBody( + req.EntityId, + world.GetPlayerWorldAvatarEntityId(player, activeAvatarId), + player.SceneId, + req.InitPos.X, req.InitPos.Y, req.InitPos.Z, + float32(vx), float32(vy), float32(vz), + ) + } scene := world.GetSceneById(player.SceneId) if req.InitPos == nil { return @@ -689,7 +724,7 @@ func (g *Game) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb.Messag if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtDestroyGadgetNotify: %v", req) + // logger.Debug("EvtDestroyGadgetNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -704,7 +739,7 @@ func (g *Game) EvtAiSyncSkillCdNotify(player *model.Player, payloadMsg pb.Messag if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAiSyncSkillCdNotify: %v", req) + // logger.Debug("EvtAiSyncSkillCdNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -718,7 +753,7 @@ func (g *Game) EvtAiSyncCombatThreatInfoNotify(player *model.Player, payloadMsg if player.SceneLoadState != model.SceneEnterDone { return } - // logger.Debug("EvtAiSyncCombatThreatInfoNotify: %v", req) + // logger.Debug("EvtAiSyncCombatThreatInfoNotify: %+v", req) world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { return @@ -757,6 +792,31 @@ func (g *Game) EntityAiSyncNotify(player *model.Player, payloadMsg pb.Message) { g.SendMsg(cmd.EntityAiSyncNotify, player.PlayerId, player.ClientSeq, entityAiSyncNotify) } +func (g *Game) ServerEvtBeingHitInfo(player *model.Player, atkEntityId uint32, defEntityId uint32, dmg float32) { + evtBeingHitInfo := &proto.EvtBeingHitInfo{ + AttackResult: &proto.AttackResult{ + AttackerId: atkEntityId, + DefenseId: defEntityId, + Damage: dmg, + ElementType: constant.ELEMENT_TYPE_FIRE, + }, + } + combatData, err := pb.Marshal(evtBeingHitInfo) + if err != nil { + logger.Error("marshal EvtBeingHitInfo error: %v", err) + return + } + GAME.CombatInvocationsNotify(player, &proto.CombatInvocationsNotify{ + InvokeList: []*proto.CombatInvokeEntry{{ + CombatData: combatData, + ForwardType: proto.ForwardType_FORWARD_ONLY_SERVER, + ArgumentType: proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT, + }}, + }) + GAME.UnionCmdNotify(player, &proto.UnionCmdNotify{}) + +} + // TODO 一些很low的解决方案 我本来是不想写的 有多low?要多low有多low! func (g *Game) handleGadgetEntityBeHitLow(player *model.Player, entity *Entity, hitElementType uint32) { diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 87b5d8d5..447befea 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -437,7 +437,7 @@ func (g *Game) AddSceneEntityNotifyToPlayer(player *model.Player, visionType pro AppearType: visionType, EntityList: entityList, } - logger.Debug("[SceneEntityAppearNotify UC], type: %v, len: %v, uid: %v", ntf.AppearType, len(ntf.EntityList), player.PlayerId) + // logger.Debug("[SceneEntityAppearNotify UC], type: %v, len: %v, uid: %v", ntf.AppearType, len(ntf.EntityList), player.PlayerId) g.SendMsg(cmd.SceneEntityAppearNotify, player.PlayerId, player.ClientSeq, ntf) } @@ -449,7 +449,7 @@ func (g *Game) AddSceneEntityNotifyBroadcast(scene *Scene, visionType proto.Visi } world := scene.GetWorld() owner := world.GetOwner() - logger.Debug("[SceneEntityAppearNotify BC], type: %v, len: %v, uid: %v, aec: %v", ntf.AppearType, len(ntf.EntityList), owner.PlayerId, aec) + // logger.Debug("[SceneEntityAppearNotify BC], type: %v, len: %v, uid: %v, aec: %v", ntf.AppearType, len(ntf.EntityList), owner.PlayerId, aec) if aec { g.SendToSceneAEC(scene, cmd.SceneEntityAppearNotify, owner.ClientSeq, ntf, aecUid) } else { @@ -463,7 +463,7 @@ func (g *Game) RemoveSceneEntityNotifyToPlayer(player *model.Player, visionType EntityList: entityIdList, DisappearType: visionType, } - logger.Debug("[SceneEntityDisappearNotify UC], type: %v, len: %v, uid: %v", ntf.DisappearType, len(ntf.EntityList), player.PlayerId) + // logger.Debug("[SceneEntityDisappearNotify UC], type: %v, len: %v, uid: %v", ntf.DisappearType, len(ntf.EntityList), player.PlayerId) g.SendMsg(cmd.SceneEntityDisappearNotify, player.PlayerId, player.ClientSeq, ntf) } @@ -475,7 +475,7 @@ func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.V } world := scene.GetWorld() owner := world.GetOwner() - logger.Debug("[SceneEntityDisappearNotify BC], type: %v, len: %v, uid: %v, aec: %v", ntf.DisappearType, len(ntf.EntityList), owner.PlayerId, aec) + // logger.Debug("[SceneEntityDisappearNotify BC], type: %v, len: %v, uid: %v, aec: %v", ntf.DisappearType, len(ntf.EntityList), owner.PlayerId, aec) if aec { g.SendToSceneAEC(scene, cmd.SceneEntityDisappearNotify, owner.ClientSeq, ntf, aecUid) } else { diff --git a/pkg/alg/shape.go b/pkg/alg/shape.go index c0942149..940e4acf 100644 --- a/pkg/alg/shape.go +++ b/pkg/alg/shape.go @@ -161,9 +161,11 @@ func regionCubicContainPos(cubic *RegionCubic, pos *Vector3) bool { // 检测一个点是否在球体内 func regionSphereContainPos(sphere *RegionSphere, pos *Vector3) bool { - distance3D := math.Sqrt(float64(sphere.pos.X-pos.X)*float64(sphere.pos.X-pos.X) + - float64(sphere.pos.Y-pos.Y)*float64(sphere.pos.Y-pos.Y) + - float64(sphere.pos.Z-pos.Z)*float64(sphere.pos.Z-pos.Z)) + distance3D := math.Sqrt( + float64(sphere.pos.X-pos.X)*float64(sphere.pos.X-pos.X) + + float64(sphere.pos.Y-pos.Y)*float64(sphere.pos.Y-pos.Y) + + float64(sphere.pos.Z-pos.Z)*float64(sphere.pos.Z-pos.Z), + ) if float32(distance3D) < sphere.radius { return true } else { @@ -173,8 +175,10 @@ func regionSphereContainPos(sphere *RegionSphere, pos *Vector3) bool { // 检测一个点是否在圆柱体内 func regionCylinderContainPos(cylinder *RegionCylinder, pos *Vector3) bool { - distance2D := math.Sqrt(float64(cylinder.pos.X-pos.X)*float64(cylinder.pos.X-pos.X) + - float64(cylinder.pos.Z-pos.Z)*float64(cylinder.pos.Z-pos.Z)) + distance2D := math.Sqrt( + float64(cylinder.pos.X-pos.X)*float64(cylinder.pos.X-pos.X) + + float64(cylinder.pos.Z-pos.Z)*float64(cylinder.pos.Z-pos.Z), + ) if float32(distance2D) >= cylinder.radius { return false } diff --git a/pkg/alg/vector.go b/pkg/alg/vector.go index 0285c743..2fe9c5b7 100644 --- a/pkg/alg/vector.go +++ b/pkg/alg/vector.go @@ -1,5 +1,9 @@ package alg +import ( + "math" +) + // Vector2 二维向量 type Vector2 struct { X float32 @@ -13,6 +17,16 @@ type Vector3 struct { Z float32 } +// Vector2Magnitude 二维向量模长 +func Vector2Magnitude(v *Vector2) float32 { + return float32(math.Sqrt(float64(v.X*v.X + v.Z*v.Z))) +} + +// Vector3Magnitude 三维向量模长 +func Vector3Magnitude(v *Vector3) float32 { + return float32(math.Sqrt(float64(v.X*v.X + v.Y*v.Y + v.Z*v.Z))) +} + // Vector2Add 二维向量加 func Vector2Add(v1 *Vector2, v2 *Vector2) *Vector2 { v3 := new(Vector2)