From 00d32292ad48b821190262b38e98fa1317e6d1ca Mon Sep 17 00:00:00 2001 From: flswld Date: Mon, 23 Oct 2023 13:07:26 +0800 Subject: [PATCH] *** --- gate/net/kcp_conn_manager.go | 2 +- gs/game/game_physics_engine.go | 4 +- gs/game/game_plugin_pubg.go | 83 ++++++++++++++++++++++++++++++++-- gs/game/game_tick_manager.go | 47 +------------------ gs/game/player_fight_sync.go | 54 +++++++++++++++++++--- gs/game/player_multiplayer.go | 8 +++- gs/game/player_social.go | 9 ++-- 7 files changed, 140 insertions(+), 67 deletions(-) diff --git a/gate/net/kcp_conn_manager.go b/gate/net/kcp_conn_manager.go index 01bfa220..cdc8795b 100644 --- a/gate/net/kcp_conn_manager.go +++ b/gate/net/kcp_conn_manager.go @@ -26,7 +26,7 @@ import ( const ( ConnEstFreqLimit = 100 // 每秒连接建立频率限制 - RecvPacketFreqLimit = 100 // 客户端上行每秒发包频率限制 + RecvPacketFreqLimit = 1000 // 客户端上行每秒发包频率限制 SendPacketFreqLimit = 1000 // 服务器下行每秒发包频率限制 PacketMaxLen = 343 * 1024 // 最大应用层包长度 ConnRecvTimeout = 30 // 收包超时时间 秒 diff --git a/gs/game/game_physics_engine.go b/gs/game/game_physics_engine.go index f9420c64..ff15a077 100644 --- a/gs/game/game_physics_engine.go +++ b/gs/game/game_physics_engine.go @@ -24,7 +24,6 @@ type RigidBody struct { avatarEntityId uint32 // 子弹发射者角色实体id hitAvatarEntityId uint32 // 子弹命中的角色实体id sceneId uint32 // 子弹所在场景id - venti bool // 子弹是否为满蓄力箭 position *alg.Vector3 // 坐标 velocity *alg.Vector3 // 速度 } @@ -204,7 +203,7 @@ func (p *PhysicsEngine) IsRigidBody(entityId uint32) bool { return exist } -func (p *PhysicsEngine) CreateRigidBody(entityId, avatarEntityId, sceneId uint32, venti bool, x, y, z float32, pitchAngle, yawAngle float32) { +func (p *PhysicsEngine) CreateRigidBody(entityId, avatarEntityId, sceneId uint32, x, y, z float32, pitchAngle, yawAngle float32) { pitchAngle += p.pitchAngleOffset vy := math.Sin(float64(pitchAngle)/360.0*2*math.Pi) * float64(p.initSpeed) vxz := math.Cos(float64(pitchAngle)/360.0*2*math.Pi) * float64(p.initSpeed) @@ -214,7 +213,6 @@ func (p *PhysicsEngine) CreateRigidBody(entityId, avatarEntityId, sceneId uint32 entityId: entityId, avatarEntityId: avatarEntityId, sceneId: sceneId, - venti: venti, position: &alg.Vector3{X: x, Y: y, Z: z}, velocity: &alg.Vector3{X: float32(vx), Y: float32(vy), Z: float32(vz)}, } diff --git a/gs/game/game_plugin_pubg.go b/gs/game/game_plugin_pubg.go index 054247ff..cbf10816 100644 --- a/gs/game/game_plugin_pubg.go +++ b/gs/game/game_plugin_pubg.go @@ -13,6 +13,8 @@ import ( "hk4e/pkg/random" "hk4e/protocol/cmd" "hk4e/protocol/proto" + + pb "google.golang.org/protobuf/proto" ) const ( @@ -24,13 +26,17 @@ const ( const ( PUBG_PHASE_INV_TIME = 180.0 - PUBG_FIRST_AREA_REDUCE_TIME = 600.0 + PUBG_FIRST_AREA_REDUCE_TIME = 300.0 ) const ( - PUBG_ATK = 100.0 - PUBG_HP = 1000.0 - PUBG_HP_LOST = 10.0 + PUBG_ATK = 100.0 + PUBG_HP = 1000.0 + PUBG_HP_LOST = 10.0 + PUBG_BOW_ATTACK_ATK_RATIO = 2.0 + PUBG_NORMAL_ATTACK_DISTANCE = 3.0 + PUBG_NORMAL_ATTACK_INTERVAL_TIME = 500 + PUBG_NORMAL_ATTACK_ATK_RATIO = 5.0 ) // PluginPubg pubg游戏插件 @@ -48,6 +54,7 @@ type PluginPubg struct { areaReduceZSpeed float64 // 缩圈Z速度 areaPointList []*proto.MapMarkPoint // 客户端区域地图坐标列表 entityIdWorldGadgetIdMap map[uint32]int32 // 实体id世界物件id映射集合 + playerHitTimeMap map[uint32]int64 // 玩家攻击命中时间集合 } func NewPluginPubg() *PluginPubg { @@ -65,6 +72,7 @@ func NewPluginPubg() *PluginPubg { areaReduceZSpeed: 0.0, areaPointList: make([]*proto.MapMarkPoint, 0), entityIdWorldGadgetIdMap: make(map[uint32]int32), + playerHitTimeMap: make(map[uint32]int64), } return p } @@ -365,6 +373,7 @@ func (p *PluginPubg) StartPubg() { AvatarGuid: avatar.Guid, FightPropMap: avatar.FightPropMap, }) + p.playerHitTimeMap[player.PlayerId] = 0 } } @@ -386,6 +395,7 @@ func (p *PluginPubg) StopPubg() { p.areaReduceZSpeed = 0.0 p.areaPointList = make([]*proto.MapMarkPoint, 0) p.entityIdWorldGadgetIdMap = make(map[uint32]int32) + p.playerHitTimeMap = make(map[uint32]int64) p.CreateUserTimer(world.GetOwner().PlayerId, 60, p.UserTimerPubgEnd) } @@ -514,3 +524,68 @@ func (p *PluginPubg) GetAlivePlayerList() []*model.Player { } return alivePlayerList } + +func (p *PluginPubg) PubgHit(scene *Scene, defAvatarEntityId uint32, atkAvatarEntityId uint32, isBow bool) { + defAvatarEntity := scene.GetEntity(defAvatarEntityId) + if defAvatarEntity == nil { + return + } + defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid()) + if defPlayer == nil { + return + } + atkAvatarEntity := scene.GetEntity(atkAvatarEntityId) + if atkAvatarEntity == nil { + return + } + atkPlayer := USER_MANAGER.GetOnlineUser(atkAvatarEntity.GetAvatarEntity().GetUid()) + if atkPlayer == nil { + return + } + now := time.Now().UnixMilli() + lastHitTime := p.playerHitTimeMap[atkPlayer.PlayerId] + if now-lastHitTime < PUBG_NORMAL_ATTACK_INTERVAL_TIME { + return + } + p.playerHitTimeMap[atkPlayer.PlayerId] = now + atk := atkAvatarEntity.GetFightProp()[constant.FIGHT_PROP_CUR_ATTACK] + dmg := float32(0.0) + if isBow { + dmg = atk / PUBG_BOW_ATTACK_ATK_RATIO + } else { + dmg = atk / PUBG_NORMAL_ATTACK_ATK_RATIO + } + GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{ + AttackResult: &proto.AttackResult{ + AttackerId: atkAvatarEntity.GetId(), + DefenseId: defAvatarEntity.GetId(), + Damage: dmg, + }, + }) + if attackResultTemplate == nil { + return + } + evtBeingHitInfo := &proto.EvtBeingHitInfo{ + PeerId: 0, + AttackResult: attackResultTemplate, + FrameNum: 0, + } + evtBeingHitInfo.AttackResult.AttackerId = atkAvatarEntity.GetId() + evtBeingHitInfo.AttackResult.DefenseId = defAvatarEntity.GetId() + evtBeingHitInfo.AttackResult.Damage = dmg + if evtBeingHitInfo.AttackResult.HitCollision == nil { + return + } + evtBeingHitInfo.AttackResult.HitCollision.HitPoint = &proto.Vector{X: float32(defPlayer.Pos.X), Y: float32(defPlayer.Pos.Y), Z: float32(defPlayer.Pos.Z)} + combatData, err := pb.Marshal(evtBeingHitInfo) + if err != nil { + return + } + GAME.SendToSceneA(scene, cmd.CombatInvocationsNotify, 0, &proto.CombatInvocationsNotify{ + InvokeList: []*proto.CombatInvokeEntry{{ + CombatData: combatData, + ForwardType: proto.ForwardType_FORWARD_TO_ALL, + ArgumentType: proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT, + }}, + }, 0) +} diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index 7d7ff648..067d4665 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -9,8 +9,6 @@ import ( "hk4e/pkg/logger" "hk4e/protocol/cmd" "hk4e/protocol/proto" - - pb "google.golang.org/protobuf/proto" ) // 游戏服务器定时帧管理器 @@ -342,50 +340,7 @@ func (t *TickManager) onTick100MilliSecond(now int64) { 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()) - atkAvatarEntity := scene.GetEntity(rigidBody.avatarEntityId) - atk := atkAvatarEntity.GetFightProp()[constant.FIGHT_PROP_CUR_ATTACK] - dmg := float32(0.0) - if rigidBody.venti { - dmg = atk - } else { - dmg = atk / 3.0 - } - GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{ - AttackResult: &proto.AttackResult{ - AttackerId: atkAvatarEntity.GetId(), - DefenseId: defAvatarEntity.GetId(), - Damage: dmg, - }, - }) - if attackResultTemplate == nil { - return - } - evtBeingHitInfo := &proto.EvtBeingHitInfo{ - PeerId: 0, - AttackResult: attackResultTemplate, - FrameNum: 0, - } - evtBeingHitInfo.AttackResult.AttackerId = atkAvatarEntity.GetId() - evtBeingHitInfo.AttackResult.DefenseId = defAvatarEntity.GetId() - evtBeingHitInfo.AttackResult.Damage = dmg - if evtBeingHitInfo.AttackResult.HitCollision == nil { - return - } - evtBeingHitInfo.AttackResult.HitCollision.HitPoint = &proto.Vector{X: float32(defPlayer.Pos.X), Y: float32(defPlayer.Pos.Y), Z: float32(defPlayer.Pos.Z)} - combatData, err := pb.Marshal(evtBeingHitInfo) - if err != nil { - return - } - GAME.SendToSceneA(scene, cmd.CombatInvocationsNotify, 0, &proto.CombatInvocationsNotify{ - InvokeList: []*proto.CombatInvokeEntry{{ - CombatData: combatData, - ForwardType: proto.ForwardType_FORWARD_TO_ALL, - ArgumentType: proto.CombatTypeArgument_COMBAT_EVT_BEING_HIT, - }}, - }, 0) - + pluginPubg.PubgHit(scene, rigidBody.hitAvatarEntityId, rigidBody.avatarEntityId, true) } } diff --git a/gs/game/player_fight_sync.go b/gs/game/player_fight_sync.go index 2bbd7085..30d0b59f 100644 --- a/gs/game/player_fight_sync.go +++ b/gs/game/player_fight_sync.go @@ -695,6 +695,51 @@ func (g *Game) EvtDoSkillSuccNotify(player *model.Player, payloadMsg pb.Message) // 处理技能开始的耐力消耗 g.SkillStartStamina(player, ntf.CasterId, ntf.SkillId) g.TriggerQuest(player, constant.QUEST_FINISH_COND_TYPE_SKILL, "", int32(ntf.SkillId)) + world := WORLD_MANAGER.GetWorldById(player.WorldId) + if world == nil { + return + } + if !WORLD_MANAGER.IsAiWorld(world) { + return + } + iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{}) + if err != nil { + logger.Error("get plugin pubg error: %v", err) + return + } + pluginPubg := iPlugin.(*PluginPubg) + if !pluginPubg.IsStartPubg() { + return + } + worldAvatar := world.GetWorldAvatarByEntityId(ntf.CasterId) + if worldAvatar == nil { + return + } + avatarDataConfig := gdconf.GetAvatarDataById(int32(worldAvatar.GetAvatarId())) + if avatarDataConfig == nil { + return + } + logger.Debug("avatar normal attack, avatarId: %v, weaponType: %v, uid: %v", avatarDataConfig.AvatarId, avatarDataConfig.WeaponType, player.PlayerId) + switch avatarDataConfig.WeaponType { + case constant.WEAPON_TYPE_SWORD_ONE_HAND, constant.WEAPON_TYPE_CLAYMORE, constant.WEAPON_TYPE_POLE, constant.WEAPON_TYPE_CATALYST, constant.WEAPON_TYPE_BOW: + scene := world.GetSceneById(player.SceneId) + avatarEntity := scene.GetEntity(worldAvatar.GetAvatarEntityId()) + for _, entity := range scene.GetAllEntity() { + if entity.GetId() == avatarEntity.GetId() || entity.GetEntityType() != constant.ENTITY_TYPE_AVATAR { + continue + } + distance3D := math.Sqrt( + (avatarEntity.GetPos().X-entity.GetPos().X)*(avatarEntity.GetPos().X-entity.GetPos().X) + + (avatarEntity.GetPos().Y-entity.GetPos().Y)*(avatarEntity.GetPos().Y-entity.GetPos().Y) + + (avatarEntity.GetPos().Z-entity.GetPos().Z)*(avatarEntity.GetPos().Z-entity.GetPos().Z), + ) + if distance3D > PUBG_NORMAL_ATTACK_DISTANCE { + continue + } + pluginPubg.PubgHit(scene, entity.GetId(), avatarEntity.GetId(), false) + } + default: + } } func (g *Game) EvtAvatarEnterFocusNotify(player *model.Player, payloadMsg pb.Message) { @@ -838,12 +883,8 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message return } // 蓄力箭 - venti := false - if gadgetDataConfig.PrefabPath == "ART/Others/Bullet/Bullet_ArrowAiming" { - venti = false - } else if gadgetDataConfig.PrefabPath == "ART/Others/Bullet/Bullet_Venti_ArrowAiming" { - venti = true - } else { + if gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_ArrowAiming" && + gadgetDataConfig.PrefabPath != "ART/Others/Bullet/Bullet_Venti_ArrowAiming" { return } pitchAngleRaw := ntf.InitEulerAngles.X @@ -863,7 +904,6 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message ntf.EntityId, world.GetPlayerWorldAvatarEntityId(player, activeAvatarId), player.SceneId, - venti, ntf.InitPos.X, ntf.InitPos.Y, ntf.InitPos.Z, pitchAngle, yawAngle, ) diff --git a/gs/game/player_multiplayer.go b/gs/game/player_multiplayer.go index 089fe069..760b9c6e 100644 --- a/gs/game/player_multiplayer.go +++ b/gs/game/player_multiplayer.go @@ -598,15 +598,19 @@ func (g *Game) ServerPlayerMpReq(playerMpInfo *mq.PlayerMpInfo, gsAppId string) return } hostWorld := WORLD_MANAGER.GetWorldById(hostPlayer.WorldId) + if hostWorld == nil { + applyFailNotify(proto.PlayerApplyEnterMpResultNotify_PLAYER_CANNOT_ENTER_MP) + return + } if hostWorld.GetMultiplayer() && hostWorld.GetOwner().PlayerId != hostPlayer.PlayerId { // 向同一世界内的非房主玩家申请时直接拒绝 - applyFailNotify(proto.PlayerApplyEnterMpResultNotify_PLAYER_NOT_IN_PLAYER_WORLD) + applyFailNotify(proto.PlayerApplyEnterMpResultNotify_PLAYER_CANNOT_ENTER_MP) return } mpSetting := hostPlayer.PropertiesMap[constant.PLAYER_PROP_PLAYER_MP_SETTING_TYPE] if mpSetting == 0 { // 房主玩家没开权限 - applyFailNotify(proto.PlayerApplyEnterMpResultNotify_SCENE_CANNOT_ENTER) + applyFailNotify(proto.PlayerApplyEnterMpResultNotify_PLAYER_CANNOT_ENTER_MP) return } else if mpSetting == 1 { g.PlayerDealEnterWorld(hostPlayer, playerMpInfo.ApplyUserId, true) diff --git a/gs/game/player_social.go b/gs/game/player_social.go index 9fe35ef6..733cc64b 100644 --- a/gs/game/player_social.go +++ b/gs/game/player_social.go @@ -3,7 +3,6 @@ package game import ( "fmt" "regexp" - "strconv" "time" "unicode/utf8" @@ -382,11 +381,13 @@ func (g *Game) GetOnlinePlayerListReq(player *model.Player, payloadMsg pb.Messag aiUidList = append(aiUidList, g.GetAi().PlayerId) for _, aiUid := range aiUidList { aiGsId := aiUid - AiBaseUid - startMinute := aiGsId % 6 * 10 - sign := fmt.Sprintf("开启时间:每小时%v分。", strconv.Itoa(int(startMinute))) + roomNumber := aiGsId - 1 + startMinute := roomNumber % 6 * 10 + name := fmt.Sprintf("房间:%v", roomNumber) + sign := fmt.Sprintf("开启时间:%02d:%02d。", time.Now().Hour(), startMinute) rsp.PlayerInfoList = append(rsp.PlayerInfoList, &proto.OnlinePlayerInfo{ Uid: aiUid, - Nickname: AiName, + Nickname: name, PlayerLevel: 1, AvatarId: 10000007, MpSettingType: proto.MpSettingType_MP_SETTING_ENTER_AFTER_APPLY,