pubg游戏世界功能物件配置

This commit is contained in:
flswld committed 2023-10-11 00:06:53 +08:00
1 parent c4fa288b93
commit 090650ed9d
14 files changed
+186 -61

No files matched your search

+2
View File
@@ -75,6 +75,7 @@ type GameDataConfig struct {
WeatherDataMap map[int32]*WeatherData // 天气
WeatherTemplateMap map[string]map[int32]*WeatherTemplate // 天气模版
SceneWeatherAreaMap map[int32]map[int32]*SceneWeatherArea // 天气区域
PubgWorldGadgetDataMap map[int32]*PubgWorldGadgetData // pubg世界物件
}
func InitGameDataConfig() {
@@ -182,6 +183,7 @@ func (g *GameDataConfig) load() {
g.loadWeatherData() // 天气
g.loadWeatherTemplateData() // 天气模版
g.loadSceneWeatherArea() // 天气区域
g.loadPubgWorldGadgetData() // pubg世界物件
}
// CSV相关
@@ -0,0 +1,4 @@
Id,GadgetId,X,Y,Z
int32,int32,float32,float32,float32
ID,物件ID,X坐标,Y坐标,Z坐标
1,70520009,396.491,201.000,-353.049
1 Id GadgetId X Y Z
2 int32 int32 float32 float32 float32
3 ID 物件ID X坐标 Y坐标 Z坐标
4 1 70520009 396.491 201.000 -353.049
+29
View File
@@ -0,0 +1,29 @@
package gdconf
import (
"hk4e/pkg/logger"
)
// pubg世界物件
type PubgWorldGadgetData struct {
Id int32 `csv:"Id"`
GadgetId int32 `csv:"GadgetId"`
X float32 `csv:"X"`
Y float32 `csv:"Y"`
Z float32 `csv:"Z"`
}
func (g *GameDataConfig) loadPubgWorldGadgetData() {
g.PubgWorldGadgetDataMap = make(map[int32]*PubgWorldGadgetData)
pubgWorldGadgetDataList := make([]*PubgWorldGadgetData, 0)
readExtCsv[PubgWorldGadgetData](g.extPrefix+"PubgWorldGadgetData.csv", &pubgWorldGadgetDataList)
for _, pubgWorldGadgetData := range pubgWorldGadgetDataList {
g.PubgWorldGadgetDataMap[pubgWorldGadgetData.Id] = pubgWorldGadgetData
}
logger.Info("PubgWorldGadgetData count: %v", len(g.PubgWorldGadgetDataMap))
}
func GetPubgWorldGadgetDataMap() map[int32]*PubgWorldGadgetData {
return CONF.PubgWorldGadgetDataMap
}
+4 -4
View File
@@ -556,23 +556,23 @@ func (g *GMCmd) SendMsgToPlayer(cmdName string, userId uint32, msgJson string) {
}
func (g *GMCmd) StartPubg(v bool) {
pluginPubg := &PluginPubg{}
err := PLUGIN_MANAGER.GetPlugin(pluginPubg)
iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{})
if err != nil {
logger.Error("get plugin pubg error: %v", err)
return
}
pluginPubg := iPlugin.(*PluginPubg)
logger.Error("plugin: %v", pluginPubg)
pluginPubg.StartPubg()
}
func (g *GMCmd) StopPubg(v bool) {
pluginPubg := &PluginPubg{}
err := PLUGIN_MANAGER.GetPlugin(pluginPubg)
iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{})
if err != nil {
logger.Error("get plugin pubg error: %v", err)
return
}
pluginPubg := iPlugin.(*PluginPubg)
pluginPubg.StopPubg()
}
+11 -18
View File
@@ -30,19 +30,18 @@ type RigidBody struct {
// PhysicsEngine 物理引擎
type PhysicsEngine struct {
rigidBodyMap map[uint32]*RigidBody // 刚体集合
pathTracing bool // 子弹路径追踪调试
acc float32 // 重力加速度
drag float32 // 阻力参数
pitchAngleOffset float32 // 子弹俯仰角偏移
initSpeed float32 // 子弹初始速度
avatarYOffset float32 // 角色中心点位置高度偏移
lastUpdateTime int64 // 上一次更新时间
sceneBlockAoiMap map[uint32]*alg.AoiManager // 全局各场景地图的aoi管理器
world *World // 世界对象
rigidBodyMap map[uint32]*RigidBody // 刚体集合
pathTracing bool // 子弹路径追踪调试
acc float32 // 重力加速度
drag float32 // 阻力参数
pitchAngleOffset float32 // 子弹俯仰角偏移
initSpeed float32 // 子弹初始速度
avatarYOffset float32 // 角色中心点位置高度偏移
lastUpdateTime int64 // 上一次更新时间
world *World // 世界对象
}
func (w *World) NewPhysicsEngine(sceneBlockAoiMap map[uint32]*alg.AoiManager) {
func (w *World) NewPhysicsEngine() {
w.bulletPhysicsEngine = &PhysicsEngine{
rigidBodyMap: make(map[uint32]*RigidBody),
pathTracing: false,
@@ -52,7 +51,6 @@ func (w *World) NewPhysicsEngine(sceneBlockAoiMap map[uint32]*alg.AoiManager) {
initSpeed: INIT_SPEED,
avatarYOffset: AVATAR_Y_OFFSET,
lastUpdateTime: 0,
sceneBlockAoiMap: sceneBlockAoiMap,
world: w,
}
}
@@ -88,12 +86,7 @@ func (p *PhysicsEngine) Update(now int64) []*RigidBody {
hitList := make([]*RigidBody, 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) {
if !p.world.IsValidAiWorldPos(rigidBody.sceneId, rigidBody.position.X, rigidBody.position.Y, rigidBody.position.Z) {
p.DestroyRigidBody(rigidBody.entityId)
continue
}
+14 -7
View File
@@ -33,6 +33,7 @@ const (
PluginEventIdPlayerKillAvatar
PluginEventIdMarkMap
PluginEventIdAvatarDieAnimationEnd
PluginEventIdGadgetInteract
)
// PluginEventKillAvatar 角色被杀死
@@ -57,6 +58,13 @@ type PluginEventAvatarDieAnimationEnd struct {
Req *proto.AvatarDieAnimationEndReq // 请求
}
// PluginEventGadgetInteract gadget交互
type PluginEventGadgetInteract struct {
*PluginEvent
Player *model.Player // 玩家
Req *proto.GadgetInteractReq // 请求
}
type PluginEventFunc func(event IPluginEvent)
// IPluginEvent 插件事件接口
@@ -266,7 +274,7 @@ func (p *PluginManager) DelPlugin(iPlugin IPlugin) {
}
// GetPlugin 获取插件实例
func (p *PluginManager) GetPlugin(value IPlugin) (err error) {
func (p *PluginManager) GetPlugin(value IPlugin) (plugin IPlugin, err error) {
defer func() {
if r := recover(); r != nil {
switch x := r.(type) {
@@ -281,18 +289,17 @@ func (p *PluginManager) GetPlugin(value IPlugin) (err error) {
}()
refValue := reflect.ValueOf(value)
if refValue.Kind() != reflect.Pointer || refValue.IsNil() {
return errors.New("value is not pointer")
return nil, errors.New("value is not pointer")
}
refType := refValue.Type()
// 校验插件是否注册
plugin, exist := p.pluginMap[refType]
exist := false
plugin, exist = p.pluginMap[refType]
if !exist {
err = errors.New(fmt.Sprintf("plugin not exist, refType: %v", refType))
return
return nil, err
}
refPlugin := reflect.ValueOf(plugin)
refValue.Elem().Set(refPlugin.Elem())
return
return plugin, nil
}
// TriggerEvent 触发事件
+47 -7
View File
@@ -5,6 +5,7 @@ import (
"math"
"hk4e/common/constant"
"hk4e/gdconf"
"hk4e/gs/model"
"hk4e/pkg/logger"
"hk4e/pkg/random"
@@ -13,10 +14,10 @@ import (
)
const (
PUBG_PHASE_WAIT = iota
PUBG_PHASE_START
PUBG_PHASE_II
PUBG_PHASE_END
PUBG_PHASE_WAIT = -1
PUBG_PHASE_START = 0
PUBG_PHASE_II = 2
PUBG_PHASE_END = 16
)
const (
@@ -37,6 +38,7 @@ type PluginPubg struct {
areaReduceXSpeed float64 // 缩圈X速度
areaReduceZSpeed float64 // 缩圈Z速度
areaPointList []*proto.MapMarkPoint // 客户端区域地图坐标列表
playerAtkMap map[uint32]float32 // 玩家攻击力集合
}
func NewPluginPubg() *PluginPubg {
@@ -47,11 +49,12 @@ func NewPluginPubg() *PluginPubg {
blueAreaRadius: 0.0,
safeAreaCenterPos: &model.Vector{X: 0.0, Y: 0.0, Z: 0.0},
safeAreaRadius: 0.0,
phase: PUBG_PHASE_START,
phase: PUBG_PHASE_WAIT,
areaReduceRadiusSpeed: 0.0,
areaReduceXSpeed: 0.0,
areaReduceZSpeed: 0.0,
areaPointList: make([]*proto.MapMarkPoint, 0),
playerAtkMap: make(map[uint32]float32),
}
return p
}
@@ -62,6 +65,7 @@ func (p *PluginPubg) OnEnable() {
p.ListenEvent(PluginEventIdPlayerKillAvatar, PluginEventPriorityNormal, p.EventKillAvatar)
p.ListenEvent(PluginEventIdMarkMap, PluginEventPriorityNormal, p.EventMarkMap)
p.ListenEvent(PluginEventIdAvatarDieAnimationEnd, PluginEventPriorityNormal, p.EventAvatarDieAnimationEnd)
p.ListenEvent(PluginEventIdGadgetInteract, PluginEventPriorityNormal, p.EventGadgetInteract)
// 添加全局定时器
p.AddGlobalTick(PluginGlobalTickSecond, p.GlobalTickPubg)
p.AddGlobalTick(PluginGlobalTickHour, p.GlobalTickHourStart)
@@ -105,11 +109,36 @@ func (p *PluginPubg) EventAvatarDieAnimationEnd(iEvent IPluginEvent) {
alivePlayerNum := len(p.GetAlivePlayerList())
info := fmt.Sprintf("『%v』死亡了,剩余%v位存活玩家。", player.NickName, alivePlayerNum)
GAME.PlayerChatReq(p.world.GetOwner(), &proto.PlayerChatReq{ChatInfo: &proto.ChatInfo{Content: &proto.ChatInfo_Text{Text: info}}})
player.PubgRank += uint32(100 - alivePlayerNum)
GAME.SendMsg(cmd.AvatarDieAnimationEndRsp, player.PlayerId, player.ClientSeq, &proto.AvatarDieAnimationEndRsp{SkillId: event.Req.SkillId, DieGuid: event.Req.DieGuid})
event.Cancel()
}
func (p *PluginPubg) EventGadgetInteract(iEvent IPluginEvent) {
event := iEvent.(*PluginEventGadgetInteract)
player := event.Player
// 确保游戏开启
if !p.IsStartPubg() || p.world.id != player.WorldId {
return
}
p.playerAtkMap[player.PlayerId] += 100.0
req := event.Req
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
return
}
scene := world.GetSceneById(player.SceneId)
GAME.KillEntity(player, scene, req.GadgetEntityId, proto.PlayerDieType_PLAYER_DIE_NONE)
rsp := &proto.GadgetInteractRsp{
GadgetEntityId: req.GadgetEntityId,
GadgetId: req.GadgetId,
OpType: req.OpType,
InteractType: proto.InteractType_INTERACT_GATHER,
}
GAME.SendMsg(cmd.GadgetInteractRsp, player.PlayerId, player.ClientSeq, rsp)
event.Cancel()
}
/************************************************** 全局定时器 **************************************************/
// GlobalTickPubg pubg游戏定时器
@@ -230,6 +259,17 @@ func (p *PluginPubg) StartPubg() {
}
world := WORLD_MANAGER.GetAiWorld()
p.world = world
for _, pubgWorldGadgetDataConfig := range gdconf.GetPubgWorldGadgetDataMap() {
GAME.CreateGadget(
p.world.GetOwner(),
&model.Vector{X: float64(pubgWorldGadgetDataConfig.X), Y: float64(pubgWorldGadgetDataConfig.Y), Z: float64(pubgWorldGadgetDataConfig.Z)},
uint32(pubgWorldGadgetDataConfig.GadgetId),
nil,
)
}
for uid := range p.world.GetAllPlayer() {
p.playerAtkMap[uid] = 100.0
}
p.phase = PUBG_PHASE_START
p.RefreshArea()
world.chatMsgList = make([]*proto.ChatInfo, 0)
@@ -246,7 +286,7 @@ func (p *PluginPubg) StopPubg() {
// IsStartPubg pubg游戏是否开启
func (p *PluginPubg) IsStartPubg() bool {
return p.world != nil && p.phase != PUBG_PHASE_WAIT && p.phase != PUBG_PHASE_END
return p.world != nil && p.phase != PUBG_PHASE_WAIT
}
// GetAreaPointList 获取游戏区域标点列表
+11 -2
View File
@@ -327,11 +327,20 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
scene := world.GetSceneById(rigidBody.sceneId)
defAvatarEntity := scene.GetEntity(rigidBody.hitAvatarEntityId)
defPlayer := USER_MANAGER.GetOnlineUser(defAvatarEntity.GetAvatarEntity().GetUid())
iPlugin, err := PLUGIN_MANAGER.GetPlugin(&PluginPubg{})
if err != nil {
logger.Error("get plugin pubg error: %v", err)
return
}
pluginPubg := iPlugin.(*PluginPubg)
entity := scene.GetEntity(rigidBody.avatarEntityId)
avatarEntity := entity.GetAvatarEntity()
atk := pluginPubg.playerAtkMap[avatarEntity.GetUid()]
GAME.handleEvtBeingHit(defPlayer, scene, &proto.EvtBeingHitInfo{
AttackResult: &proto.AttackResult{
AttackerId: rigidBody.avatarEntityId,
DefenseId: rigidBody.hitAvatarEntityId,
Damage: 100,
Damage: atk,
},
})
if attackResultTemplate == nil {
@@ -344,7 +353,7 @@ func (t *TickManager) onTick100MilliSecond(now int64) {
}
evtBeingHitInfo.AttackResult.AttackerId = rigidBody.avatarEntityId
evtBeingHitInfo.AttackResult.DefenseId = rigidBody.hitAvatarEntityId
evtBeingHitInfo.AttackResult.Damage = 100
evtBeingHitInfo.AttackResult.Damage = atk
if evtBeingHitInfo.AttackResult.HitCollision == nil {
return
}
+13 -1
View File
@@ -101,7 +101,7 @@ func (w *WorldManager) GetAiWorld() *World {
func (w *WorldManager) InitAiWorld(owner *model.Player) {
w.aiWorld = w.GetWorldById(owner.WorldId)
w.aiWorld.ChangeToMultiplayer()
w.aiWorld.NewPhysicsEngine(w.sceneBlockAoiMap)
w.aiWorld.NewPhysicsEngine()
}
func (w *WorldManager) IsAiWorld(world *World) bool {
@@ -190,6 +190,18 @@ func (w *WorldManager) LoadSceneBlockAoiMap() {
}
}
func (w *World) IsValidSceneBlockPos(sceneId uint32, x, y, z float32) bool {
aoiManager, exist := WORLD_MANAGER.sceneBlockAoiMap[sceneId]
if !exist {
return false
}
return aoiManager.IsValidAoiPos(x, y, z)
}
func (w *World) IsValidAiWorldPos(sceneId uint32, x, y, z float32) bool {
return w.aiWorldAoi.IsValidAoiPos(x, y, z)
}
func (w *WorldManager) GetMultiplayerWorldNum() uint32 {
return w.multiplayerWorldNum
}
+2 -2
View File
@@ -289,7 +289,7 @@ func (g *Game) GmTalkReq(player *model.Player, payloadMsg pb.Message) {
beginIndex := strings.Index(commandText, "(")
endIndex := strings.Index(commandText, ")")
if beginIndex == 0 || beginIndex == -1 || endIndex == -1 || beginIndex >= endIndex {
g.SendMsg(cmd.GmTalkRsp, player.PlayerId, player.ClientSeq, &proto.GmTalkRsp{Retmsg: "命令解析失败", Msg: req.Msg})
g.SendMsg(cmd.GmTalkRsp, player.PlayerId, player.ClientSeq, &proto.GmTalkRsp{Retmsg: "GM函数解析失败", Msg: req.Msg})
return
}
funcName := commandText[:beginIndex]
@@ -303,7 +303,7 @@ func (g *Game) GmTalkReq(player *model.Player, payloadMsg pb.Message) {
commandMessageInput <- &CommandMessage{
GMType: DevClientGM,
Executor: player,
Text: req.Msg,
Text: strings.ToLower(req.Msg),
}
}
g.SendMsg(cmd.GmTalkRsp, player.PlayerId, player.ClientSeq, &proto.GmTalkRsp{Retmsg: "执行成功", Msg: req.Msg})
+38 -18
View File
@@ -272,11 +272,14 @@ func (g *Game) handleEntityMove(player *model.Player, world *World, scene *Scene
}
}
func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene *Scene, oldPos *model.Vector, newPos *model.Vector, entityId uint32) {
func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene *Scene, oldPos *model.Vector, newPos *model.Vector, avatarEntityId uint32) {
if WORLD_MANAGER.IsAiWorld(world) {
return
}
if !world.IsValidSceneBlockPos(scene.GetId(), float32(newPos.X), 0.0, float32(newPos.Z)) {
return
}
// 服务器处理玩家移动场景区块aoi事件频率限制
now := uint64(time.Now().UnixMilli())
if now-player.LastSceneBlockAoiMoveTime < 200 {
@@ -341,34 +344,20 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene
oldVisionEntityMap := g.GetVisionEntity(scene, oldPos)
newVisionEntityMap := g.GetVisionEntity(scene, newPos)
delEntityIdList := make([]uint32, 0)
for entityId, entity := range oldVisionEntityMap {
for entityId := range oldVisionEntityMap {
_, exist := newVisionEntityMap[entityId]
if exist {
continue
}
if WORLD_MANAGER.IsAiWorld(world) {
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
continue
}
}
// 旧有新没有的实体即为消失的
delEntityIdList = append(delEntityIdList, entityId)
}
addEntityIdList := make([]uint32, 0)
for entityId, entity := range newVisionEntityMap {
for entityId := range newVisionEntityMap {
_, exist := oldVisionEntityMap[entityId]
if exist {
continue
}
if WORLD_MANAGER.IsAiWorld(world) {
if entity.GetEntityType() == constant.ENTITY_TYPE_AVATAR {
continue
}
}
// 新有旧没有的实体即为出现的
addEntityIdList = append(addEntityIdList, entityId)
}
@@ -380,12 +369,15 @@ func (g *Game) SceneBlockAoiPlayerMove(player *model.Player, world *World, scene
g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false)
}
// 场景区域触发器检测
g.SceneRegionTriggerCheck(player, oldPos, newPos, entityId)
g.SceneRegionTriggerCheck(player, oldPos, newPos, avatarEntityId)
// 场景天气区域变更检测
g.SceneWeatherAreaCheck(player, oldPos, newPos)
}
func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *Scene, oldPos *model.Vector, newPos *model.Vector) {
if !world.IsValidAiWorldPos(scene.GetId(), float32(newPos.X), float32(newPos.Y), float32(newPos.Z)) {
return
}
aiWorldAoi := world.GetAiWorldAoi()
oldGid := aiWorldAoi.GetGidByPos(float32(oldPos.X), float32(oldPos.Y), float32(oldPos.Z))
newGid := aiWorldAoi.GetGidByPos(float32(newPos.X), float32(newPos.Y), float32(newPos.Z))
@@ -476,6 +468,34 @@ func (g *Game) AiWorldAoiPlayerMove(player *model.Player, world *World, scene *S
// 新格子添加玩家
aiWorldAoi.AddObjectToGrid(int64(player.PlayerId), activeWorldAvatar, newGid)
}
// 消失和出现的场景实体
oldVisionEntityMap := g.GetVisionEntity(scene, oldPos)
newVisionEntityMap := g.GetVisionEntity(scene, newPos)
delEntityIdList := make([]uint32, 0)
for entityId := range oldVisionEntityMap {
_, exist := newVisionEntityMap[entityId]
if exist {
continue
}
// 旧有新没有的实体即为消失的
delEntityIdList = append(delEntityIdList, entityId)
}
addEntityIdList := make([]uint32, 0)
for entityId := range newVisionEntityMap {
_, exist := oldVisionEntityMap[entityId]
if exist {
continue
}
// 新有旧没有的实体即为出现的
addEntityIdList = append(addEntityIdList, entityId)
}
// 同步客户端消失和出现的场景实体
if len(delEntityIdList) > 0 {
g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_MISS, delEntityIdList)
}
if len(addEntityIdList) > 0 {
g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false)
}
}
func (g *Game) AbilityInvocationsNotify(player *model.Player, payloadMsg pb.Message) {
+1 -1
View File
@@ -39,7 +39,7 @@ func (g *Game) GetPlayerSocialDetailReq(player *model.Player, payloadMsg pb.Mess
WorldLevel: targetPlayer.PropertiesMap[constant.PLAYER_PROP_PLAYER_WORLD_LEVEL],
NameCardId: targetPlayer.NameCard,
IsShowAvatar: false,
FinishAchievementNum: targetPlayer.PubgRank,
FinishAchievementNum: 0,
IsFriend: exist,
}
getPlayerSocialDetailRsp := &proto.GetPlayerSocialDetailRsp{
+10
View File
@@ -408,6 +408,16 @@ func (g *Game) PlayerQuitDungeonReq(player *model.Player, payloadMsg pb.Message)
// GadgetInteractReq gadget交互请求
func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.GadgetInteractReq)
// 触发事件
if PLUGIN_MANAGER.TriggerEvent(PluginEventIdGadgetInteract, &PluginEventGadgetInteract{
PluginEvent: NewPluginEvent(),
Player: player,
Req: req,
}) {
return
}
world := WORLD_MANAGER.GetWorldById(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
-1
View File
@@ -47,7 +47,6 @@ type Player struct {
SafePos *Vector // 在陆地时的坐标
Pos *Vector // 坐标
Rot *Vector // 朝向
PubgRank uint32 // 大逃杀模式积分
DbItem *DbItem // 道具
DbWeapon *DbWeapon // 武器
DbReliquary *DbReliquary // 圣遗物