This commit is contained in:
flswld
2023-04-11 00:41:08 +08:00
parent 4bf41183ae
commit e50747e441
12 changed files with 167 additions and 108 deletions

View File

@@ -304,10 +304,6 @@ func UpdateFrame(rgb bool) {
}
world := WORLD_MANAGER.GetAiWorld()
scene := world.GetSceneById(3)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", 3)
return
}
for _, v := range SCREEN_ENTITY_ID_LIST {
scene.DestroyEntity(v)
}

View File

@@ -392,7 +392,7 @@ func (g *Game) SendToWorldH(world *World, cmdId uint16, seq uint32, msg pb.Messa
// SendToSceneA 给场景内所有玩家发消息
func (g *Game) SendToSceneA(scene *Scene, cmdId uint16, seq uint32, msg pb.Message) {
world := scene.GetWorld()
if WORLD_MANAGER.IsBigWorld(world) {
if WORLD_MANAGER.IsBigWorld(world) && SELF != nil {
bigWorldAoi := world.GetBigWorldAoi()
otherWorldAvatarMap := bigWorldAoi.GetObjectListByPos(float32(SELF.Pos.X), float32(SELF.Pos.Y), float32(SELF.Pos.Z))
for uid := range otherWorldAvatarMap {
@@ -408,7 +408,7 @@ func (g *Game) SendToSceneA(scene *Scene, cmdId uint16, seq uint32, msg pb.Messa
// SendToSceneAEC 给场景内除某玩家(一般是自己)以外的所有玩家发消息
func (g *Game) SendToSceneAEC(scene *Scene, cmdId uint16, seq uint32, msg pb.Message, aecUid uint32) {
world := scene.GetWorld()
if WORLD_MANAGER.IsBigWorld(world) {
if WORLD_MANAGER.IsBigWorld(world) && SELF != nil {
bigWorldAoi := world.GetBigWorldAoi()
otherWorldAvatarMap := bigWorldAoi.GetObjectListByPos(float32(SELF.Pos.X), float32(SELF.Pos.Y), float32(SELF.Pos.Z))
for uid := range otherWorldAvatarMap {

View File

@@ -360,10 +360,6 @@ func (w *World) AddPlayer(player *model.Player, sceneId uint32) {
}
}
scene := w.GetSceneById(sceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", sceneId)
return
}
scene.AddPlayer(player)
w.InitPlayerTeamEntityId(player)
if WORLD_MANAGER.IsBigWorld(w) {
@@ -496,10 +492,6 @@ func (w *World) GetWorldAvatarByEntityId(avatarEntityId uint32) *WorldAvatar {
// InitPlayerWorldAvatar 初始化某玩家在世界队伍中的所有角色
func (w *World) InitPlayerWorldAvatar(player *model.Player) {
scene := w.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
return
}
for _, worldAvatar := range w.GetWorldAvatarList() {
if worldAvatar.uid != player.PlayerID {
continue

View File

@@ -241,12 +241,12 @@ func (g *Game) AvatarWearFlycloakReq(player *model.Player, payloadMsg pb.Message
req := payloadMsg.(*proto.AvatarWearFlycloakReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
g.SendError(cmd.AvatarWearFlycloakRsp, player, &proto.AvatarWearFlycloakRsp{})
return
}
scene := world.GetSceneById(player.SceneId)
// 确保角色存在
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)
@@ -290,12 +290,12 @@ func (g *Game) AvatarChangeCostumeReq(player *model.Player, payloadMsg pb.Messag
req := payloadMsg.(*proto.AvatarChangeCostumeReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
g.SendError(cmd.AvatarChangeCostumeRsp, player, &proto.AvatarChangeCostumeRsp{})
return
}
scene := world.GetSceneById(player.SceneId)
// 确保角色存在
avatar, ok := player.GameObjectGuidMap[req.AvatarGuid].(*model.Avatar)

View File

@@ -34,6 +34,10 @@ func (g *Game) PullRecentChatReq(player *model.Player, payloadMsg pb.Message) {
}
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
if world.GetMultiplayer() {
chatList := world.GetChatList()
count := len(chatList)
@@ -247,6 +251,10 @@ func (g *Game) PlayerChatReq(player *model.Player, payloadMsg pb.Message) {
}
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
world.AddChat(sendChatInfo)
playerChatNotify := &proto.PlayerChatNotify{

View File

@@ -218,7 +218,7 @@ func (g *Game) WearUserAvatarWeapon(userId uint32, avatarId uint32, weaponId uin
}
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("world is nil, worldId: %v", player.WorldId)
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
// 角色已装备的武器

View File

@@ -355,45 +355,37 @@ func (g *Game) BigWorldAoiPlayerMove(player *model.Player, world *World, scene *
delEntityIdList := make([]uint32, 0)
for _, otherWorldAvatarAny := range oldOtherWorldAvatarMap {
otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar)
if otherWorldAvatar.GetUid() == player.PlayerID {
continue
}
delEntityIdList = append(delEntityIdList, otherWorldAvatar.GetAvatarEntityId())
}
g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_MISS, delEntityIdList)
if len(delEntityIdList) > 0 {
g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_MISS, delEntityIdList)
}
// 通知老格子里的其它玩家 自己消失
for otherPlayerId := range oldOtherWorldAvatarMap {
if uint32(otherPlayerId) == player.PlayerID {
continue
}
otherPlayer := USER_MANAGER.GetOnlineUser(uint32(otherPlayerId))
g.RemoveSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MISS, []uint32{activeWorldAvatar.GetAvatarEntityId()})
}
}
// 处理出现的格子
for _, addGridId := range addGridIdList {
// 新格子添加玩家
bigWorldAoi.AddObjectToGrid(int64(player.PlayerID), activeWorldAvatar, addGridId)
// 通知自己 新格子里的其他玩家出现
newOtherWorldAvatarMap := bigWorldAoi.GetObjectListByGid(addGridId)
addEntityIdList := make([]uint32, 0)
for _, otherWorldAvatarAny := range newOtherWorldAvatarMap {
otherWorldAvatar := otherWorldAvatarAny.(*WorldAvatar)
if otherWorldAvatar.GetUid() == player.PlayerID {
continue
}
addEntityIdList = append(addEntityIdList, otherWorldAvatar.GetAvatarEntityId())
}
g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false)
if len(addEntityIdList) > 0 {
g.AddSceneEntityNotify(player, proto.VisionType_VISION_MEET, addEntityIdList, false, false)
}
// 通知新格子里的其他玩家 自己出现
for otherPlayerId := range newOtherWorldAvatarMap {
if uint32(otherPlayerId) == player.PlayerID {
continue
}
otherPlayer := USER_MANAGER.GetOnlineUser(uint32(otherPlayerId))
sceneEntityInfoAvatar := g.PacketSceneEntityInfoAvatar(scene, player, world.GetPlayerActiveAvatarId(player))
g.AddSceneEntityNotifyToPlayer(otherPlayer, proto.VisionType_VISION_MEET, []*proto.SceneEntityInfo{sceneEntityInfoAvatar})
}
// 新格子添加玩家
bigWorldAoi.AddObjectToGrid(int64(player.PlayerID), activeWorldAvatar, addGridId)
}
}
}
@@ -598,7 +590,6 @@ func (g *Game) EvtCreateGadgetNotify(player *model.Player, payloadMsg pb.Message
// logger.Debug("EvtCreateGadgetNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("world is nil, WorldId: %v", player.WorldId)
return
}
scene := world.GetSceneById(player.SceneId)
@@ -625,7 +616,6 @@ func (g *Game) EvtDestroyGadgetNotify(player *model.Player, payloadMsg pb.Messag
// logger.Debug("EvtDestroyGadgetNotify: %v", req)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("world is nil, worldId: %v", player.WorldId)
return
}
scene := world.GetSceneById(player.SceneId)
@@ -694,6 +684,11 @@ func (g *Game) EntityAiSyncNotify(player *model.Player, payloadMsg pb.Message) {
// TODO 一些很low的解决方案 我本来是不想写的 有多low要多low有多low
func (g *Game) handleGadgetEntityBeHitLow(player *model.Player, entity *Entity, hitElementType uint32) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
return
}
scene := world.GetSceneById(player.SceneId)
if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET {
return
}
@@ -734,6 +729,8 @@ func (g *Game) handleGadgetEntityBeHitLow(player *model.Player, entity *Entity,
return
}
g.ChangeGadgetState(player, entity.GetId(), constant.GADGET_STATE_GEAR_START)
} else if strings.Contains(gadgetDataConfig.ServerLuaScript, "SubfieldDrop_WoodenObject_Broken") {
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)
}
}
@@ -744,6 +741,9 @@ func (g *Game) handleGadgetEntityAbilityLow(player *model.Player, entityId uint3
}
scene := world.GetSceneById(player.SceneId)
entity := scene.GetEntity(entityId)
if entity == nil {
return
}
switch argument {
case proto.AbilityInvokeArgument_ABILITY_META_MODIFIER_CHANGE:
// 物件破碎
@@ -751,7 +751,6 @@ func (g *Game) handleGadgetEntityAbilityLow(player *model.Player, entityId uint3
if modifierChange.Action != proto.ModifierAction_REMOVED {
return
}
logger.Debug("物件破碎, entityId: %v, modifierChange: %v, uid: %v", entityId, modifierChange, player.PlayerID)
if entity.GetEntityType() != constant.ENTITY_TYPE_GADGET {
return
}
@@ -764,6 +763,7 @@ func (g *Game) handleGadgetEntityAbilityLow(player *model.Player, entityId uint3
}
if strings.Contains(gadgetDataConfig.Name, "碎石堆") ||
strings.Contains(gadgetDataConfig.ServerLuaScript, "SubfieldDrop_WoodenObject_Broken") {
logger.Debug("物件破碎, entityId: %v, modifierChange: %v, uid: %v", entityId, modifierChange, player.PlayerID)
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)
} else if strings.Contains(gadgetDataConfig.ServerLuaScript, "SubfieldDrop_Ore") {
g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_GM)

View File

@@ -29,20 +29,18 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.EnterSceneReadyReq)
logger.Debug("player enter scene ready, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
if world.GetMultiplayer() && world.IsPlayerFirstEnter(player) {
guestBeginEnterSceneNotify := &proto.GuestBeginEnterSceneNotify{
SceneId: player.SceneId,
Uid: player.PlayerID,
}
g.SendToWorldAEC(world, cmd.GuestBeginEnterSceneNotify, 0, guestBeginEnterSceneNotify, player.PlayerID)
playerPreEnterMpNotify := &proto.PlayerPreEnterMpNotify{
State: proto.PlayerPreEnterMpNotify_START,
Uid: player.PlayerID,
Nickname: player.NickName,
}
g.SendToWorldAEC(world, cmd.PlayerPreEnterMpNotify, 0, playerPreEnterMpNotify, player.PlayerID)
g.SendToWorldH(world, cmd.PlayerPreEnterMpNotify, 0, playerPreEnterMpNotify)
}
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
@@ -59,7 +57,10 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
g.RemoveSceneEntityNotifyToPlayer(player, proto.VisionType_VISION_MISS, delEntityIdList)
// 卸载旧位置附近的group
for _, groupConfig := range g.GetNeighborGroup(ctx.OldSceneId, ctx.OldPos) {
g.RemoveSceneGroup(player, oldScene, groupConfig)
if !world.GetMultiplayer() {
// 处理多人世界不同玩家不同位置的group卸载情况
g.RemoveSceneGroup(player, oldScene, groupConfig)
}
}
}
@@ -81,11 +82,19 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.SceneInitFinishReq)
logger.Debug("player scene init finish, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
scene := world.GetSceneById(player.SceneId)
if world.GetMultiplayer() && world.IsPlayerFirstEnter(player) {
guestBeginEnterSceneNotify := &proto.GuestBeginEnterSceneNotify{
SceneId: player.SceneId,
Uid: player.PlayerID,
}
g.SendToWorldAEC(world, cmd.GuestBeginEnterSceneNotify, 0, guestBeginEnterSceneNotify, player.PlayerID)
}
serverTimeNotify := &proto.ServerTimeNotify{
ServerTime: uint64(time.Now().UnixMilli()),
@@ -241,6 +250,10 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.EnterSceneDoneReq)
logger.Debug("player enter scene done, uid: %v", player.PlayerID)
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)
var visionType = proto.VisionType_VISION_NONE
@@ -252,6 +265,12 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
activeAvatarId := world.GetPlayerActiveAvatarId(player)
activeWorldAvatar := world.GetPlayerWorldAvatar(player, activeAvatarId)
if WORLD_MANAGER.IsBigWorld(world) && !world.IsPlayerFirstEnter(player) {
bigWorldAoi := world.GetBigWorldAoi()
bigWorldAoi.AddObjectToGridByPos(int64(player.PlayerID), activeWorldAvatar, float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
}
g.AddSceneEntityNotify(player, visionType, []uint32{activeWorldAvatar.GetAvatarEntityId()}, true, false)
// 加载附近的group
@@ -296,7 +315,6 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
g.SendMsg(cmd.EnterSceneDoneRsp, player.PlayerID, player.ClientSeq, enterSceneDoneRsp)
player.SceneLoadState = model.SceneEnterDone
world.PlayerEnter(player.PlayerID)
for _, otherPlayerId := range world.GetAllWaitPlayer() {
// 房主第一次进入多人世界场景完成 开始通知等待列表中的玩家进入场景
@@ -314,6 +332,10 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.PostEnterSceneReq)
logger.Debug("player post enter scene, uid: %v", player.PlayerID)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
if world.GetMultiplayer() && world.IsPlayerFirstEnter(player) {
guestPostEnterSceneNotify := &proto.GuestPostEnterSceneNotify{
@@ -323,6 +345,8 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
g.SendToWorldAEC(world, cmd.GuestPostEnterSceneNotify, 0, guestPostEnterSceneNotify, player.PlayerID)
}
world.PlayerEnter(player.PlayerID)
postEnterSceneRsp := &proto.PostEnterSceneRsp{
EnterSceneToken: req.EnterSceneToken,
}
@@ -400,11 +424,10 @@ func (g *Game) RemoveSceneEntityNotifyBroadcast(scene *Scene, visionType proto.V
// AddSceneEntityNotify 添加的场景实体同步 封装接口
func (g *Game) AddSceneEntityNotify(player *model.Player, visionType proto.VisionType, entityIdList []uint32, broadcast bool, aec bool) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
return
}
scene := world.GetSceneById(player.SceneId)
// 如果总数量太多则分包发送
times := int(math.Ceil(float64(len(entityIdList)) / float64(ENTITY_MAX_BATCH_SEND_NUM)))
for i := 0; i < times; i++ {
@@ -560,7 +583,9 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
return
}
dbWorld := player.GetDbWorld()
world := scene.GetWorld()
owner := world.GetOwner()
dbWorld := owner.GetDbWorld()
dbScene := dbWorld.GetSceneById(scene.GetId())
dbSceneGroup := dbScene.GetSceneGroupById(entity.GetGroupId())
dbSceneGroup.AddKill(entity.GetConfigId())
@@ -576,7 +601,6 @@ func (g *Game) KillEntity(player *model.Player, scene *Scene, entityId uint32, d
func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state uint32) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v", player.WorldId)
return
}
scene := world.GetSceneById(player.SceneId)
@@ -605,7 +629,8 @@ func (g *Game) ChangeGadgetState(player *model.Player, entityId uint32, state ui
return
}
dbWorld := player.GetDbWorld()
owner := world.GetOwner()
dbWorld := owner.GetDbWorld()
dbScene := dbWorld.GetSceneById(scene.GetId())
dbSceneGroup := dbScene.GetSceneGroupById(groupId)
dbSceneGroup.ChangeGadgetState(entity.GetConfigId(), uint8(gadgetEntity.GetGadgetState()))
@@ -652,10 +677,15 @@ func (g *Game) GetNeighborGroup(sceneId uint32, pos *model.Vector) map[uint32]*g
// AddSceneGroup 加载场景组
func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gdconf.Group) {
group := scene.GetGroupById(uint32(groupConfig.Id))
if group != nil {
logger.Error("group already exist, groupId: %v, uid: %v", groupConfig.Id, player.PlayerID)
return
}
initSuiteId := groupConfig.GroupInitConfig.Suite
_, exist := groupConfig.SuiteMap[initSuiteId]
if !exist {
logger.Error("invalid init suite id: %v, uid: %v", initSuiteId, player.PlayerID)
logger.Error("invalid suiteId: %v, uid: %v", initSuiteId, player.PlayerID)
return
}
g.AddSceneGroupSuiteCore(player, scene, uint32(groupConfig.Id), uint8(initSuiteId))
@@ -665,7 +695,9 @@ func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gd
ntf.GroupMap[uint32(groupConfig.Id)] = uint32(initSuiteId)
g.SendMsg(cmd.GroupSuiteNotify, player.PlayerID, player.ClientSeq, ntf)
dbWorld := player.GetDbWorld()
world := scene.GetWorld()
owner := world.GetOwner()
dbWorld := owner.GetDbWorld()
dbScene := dbWorld.GetSceneById(scene.GetId())
dbSceneGroup := dbScene.GetSceneGroupById(uint32(groupConfig.Id))
for _, variable := range groupConfig.VariableMap {
@@ -676,13 +708,22 @@ func (g *Game) AddSceneGroup(player *model.Player, scene *Scene, groupConfig *gd
dbSceneGroup.SetVariable(variable.Name, variable.Value)
}
group := scene.GetGroupById(uint32(groupConfig.Id))
group = scene.GetGroupById(uint32(groupConfig.Id))
if group == nil {
logger.Error("group not exist, groupId: %v, uid: %v", groupConfig.Id, player.PlayerID)
return
}
// 场景组加载触发器检测
g.GroupLoadTriggerCheck(player, group)
// 物件创建触发器检测
suiteConfig, exist := groupConfig.SuiteMap[initSuiteId]
if !exist {
logger.Error("invalid suiteId: %v, uid: %v", initSuiteId, player.PlayerID)
return
}
for _, gadgetConfigId := range suiteConfig.GadgetConfigIdList {
GAME.GadgetCreateTriggerCheck(player, group, uint32(gadgetConfigId))
}
}
// RemoveSceneGroup 卸载场景组
@@ -713,6 +754,11 @@ func (g *Game) AddSceneGroupSuiteCore(player *model.Player, scene *Scene, groupI
logger.Error("invalid suiteId: %v", suiteId)
return
}
world := scene.GetWorld()
owner := world.GetOwner()
dbWorld := owner.GetDbWorld()
dbScene := dbWorld.GetSceneById(scene.GetId())
dbSceneGroup := dbScene.GetSceneGroupById(groupId)
entityMap := make(map[uint32]*Entity)
for _, monsterConfigId := range suiteConfig.MonsterConfigIdList {
monsterConfig, exist := groupConfig.MonsterMap[monsterConfigId]
@@ -720,6 +766,10 @@ func (g *Game) AddSceneGroupSuiteCore(player *model.Player, scene *Scene, groupI
logger.Error("monster config not exist, monsterConfigId: %v", monsterConfigId)
continue
}
isKill := dbSceneGroup.CheckIsKill(uint32(monsterConfig.ConfigId))
if isKill {
continue
}
entityId := g.CreateConfigEntity(player, scene, uint32(groupConfig.Id), monsterConfig)
if entityId == 0 {
continue
@@ -733,6 +783,10 @@ func (g *Game) AddSceneGroupSuiteCore(player *model.Player, scene *Scene, groupI
logger.Error("gadget config not exist, gadgetConfigId: %v", gadgetConfigId)
continue
}
isKill := dbSceneGroup.CheckIsKill(uint32(gadgetConfig.ConfigId))
if isKill {
continue
}
entityId := g.CreateConfigEntity(player, scene, uint32(groupConfig.Id), gadgetConfig)
if entityId == 0 {
continue
@@ -749,25 +803,18 @@ func (g *Game) AddSceneGroupSuiteCore(player *model.Player, scene *Scene, groupI
entityMap[entityId] = entity
}
scene.AddGroupSuite(groupId, suiteId, entityMap)
group := scene.GetGroupById(groupId)
for _, gadgetConfigId := range suiteConfig.GadgetConfigIdList {
// 物件创建触发器检测
GAME.GadgetCreateTriggerCheck(player, group, uint32(gadgetConfigId))
}
}
// CreateConfigEntity 创建配置表里的实体
func (g *Game) CreateConfigEntity(player *model.Player, scene *Scene, groupId uint32, entityConfig any) uint32 {
dbWorld := player.GetDbWorld()
world := scene.GetWorld()
owner := world.GetOwner()
dbWorld := owner.GetDbWorld()
dbScene := dbWorld.GetSceneById(scene.GetId())
dbSceneGroup := dbScene.GetSceneGroupById(groupId)
switch entityConfig.(type) {
case *gdconf.Monster:
monster := entityConfig.(*gdconf.Monster)
isKill := dbSceneGroup.CheckIsKill(uint32(monster.ConfigId))
if isKill {
return 0
}
return scene.CreateEntityMonster(
&model.Vector{X: float64(monster.Pos.X), Y: float64(monster.Pos.Y), Z: float64(monster.Pos.Z)},
&model.Vector{X: float64(monster.Rot.X), Y: float64(monster.Rot.Y), Z: float64(monster.Rot.Z)},
@@ -782,10 +829,6 @@ func (g *Game) CreateConfigEntity(player *model.Player, scene *Scene, groupId ui
)
case *gdconf.Gadget:
gadget := entityConfig.(*gdconf.Gadget)
isKill := dbSceneGroup.CheckIsKill(uint32(gadget.ConfigId))
if isKill {
return 0
}
// 70500000并不是实际的物件id 根据节点类型对应采集物配置表
if gadget.PointType != 0 && gadget.GadgetId == 70500000 {
gatherDataConfig := gdconf.GetGatherDataByPointType(gadget.PointType)
@@ -821,9 +864,8 @@ func (g *Game) CreateConfigEntity(player *model.Player, scene *Scene, groupId ui
groupId,
)
}
default:
return 0
}
return 0
}
// TODO 临时写死
@@ -895,7 +937,6 @@ func (g *Game) AddSceneGroupMonster(player *model.Player, groupId uint32, config
}
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v", player.WorldId)
return
}
scene := world.GetSceneById(player.SceneId)
@@ -934,7 +975,6 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui
}
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v", player.WorldId)
return
}
scene := world.GetSceneById(player.SceneId)
@@ -966,7 +1006,7 @@ var SceneTransactionSeq uint32 = 0
func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player, enterType proto.EnterType) *proto.PlayerEnterSceneNotify {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v", player.WorldId)
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return new(proto.PlayerEnterSceneNotify)
}
scene := world.GetSceneById(player.SceneId)
@@ -1034,6 +1074,10 @@ func (g *Game) PacketPlayerEnterSceneNotifyCore(
dungeonPointId uint32,
) *proto.PlayerEnterSceneNotify {
world := WORLD_MANAGER.GetWorldByID(targetPlayer.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return new(proto.PlayerEnterSceneNotify)
}
scene := world.GetSceneById(targetPlayer.SceneId)
enterSceneToken := world.AddEnterSceneContext(&EnterSceneContext{
OldSceneId: prevSceneId,

View File

@@ -437,6 +437,10 @@ func (g *Game) GetOnlinePlayerInfoReq(player *model.Player, payloadMsg pb.Messag
func (g *Game) PacketOnlinePlayerInfo(player *model.Player) *proto.OnlinePlayerInfo {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return new(proto.OnlinePlayerInfo)
}
worldPlayerNum := uint32(1)
// TODO 远程玩家的世界内人数
if world != nil {

View File

@@ -16,11 +16,11 @@ func (g *Game) ChangeAvatarReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.ChangeAvatarReq)
targetAvatarGuid := req.Guid
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
scene := world.GetSceneById(player.SceneId)
targetAvatar, ok := player.GameObjectGuidMap[targetAvatarGuid].(*model.Avatar)
if !ok {
logger.Error("target avatar error, avatarGuid: %v", targetAvatarGuid)
@@ -75,6 +75,7 @@ func (g *Game) SetUpAvatarTeamReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.SetUpAvatarTeamReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
if world.GetMultiplayer() {
@@ -152,6 +153,10 @@ func (g *Game) ChooseCurAvatarTeamReq(player *model.Player, payloadMsg pb.Messag
req := payloadMsg.(*proto.ChooseCurAvatarTeamReq)
teamId := req.TeamId
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
if world.GetMultiplayer() {
g.SendError(cmd.ChooseCurAvatarTeamRsp, player, &proto.ChooseCurAvatarTeamRsp{})
return
@@ -182,6 +187,10 @@ func (g *Game) ChangeMpTeamAvatarReq(player *model.Player, payloadMsg pb.Message
req := payloadMsg.(*proto.ChangeMpTeamAvatarReq)
avatarGuidList := req.AvatarGuidList
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
if WORLD_MANAGER.IsBigWorld(world) || !world.GetMultiplayer() || len(avatarGuidList) == 0 || len(avatarGuidList) > 4 {
g.SendError(cmd.ChangeMpTeamAvatarRsp, player, &proto.ChangeMpTeamAvatarRsp{})
return
@@ -235,10 +244,6 @@ func (g *Game) PacketSceneTeamUpdateNotify(world *World, player *model.Player) *
continue
}
worldPlayerScene := world.GetSceneById(worldPlayer.SceneId)
if worldPlayerScene == nil {
logger.Error("scene is nil, sceneId: %v", worldPlayer.SceneId)
return new(proto.SceneTeamUpdateNotify)
}
worldPlayerDbAvatar := worldPlayer.GetDbAvatar()
worldPlayerAvatar := worldPlayerDbAvatar.AvatarMap[worldAvatar.GetAvatarId()]
equipIdList := make([]uint32, 0)

View File

@@ -14,11 +14,11 @@ import (
// VehicleDestroyMotion 载具销毁动作
func (g *Game) VehicleDestroyMotion(player *model.Player, entity *Entity, state proto.MotionState) {
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
scene := world.GetSceneById(player.SceneId)
// 状态等于 MOTION_STATE_DESTROY_VEHICLE 代表请求销毁
if state == proto.MotionState_MOTION_DESTROY_VEHICLE {
@@ -32,12 +32,12 @@ func (g *Game) CreateVehicleReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.CreateVehicleReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
return
}
scene := world.GetSceneById(player.SceneId)
// 创建载具冷却时间
createVehicleCd := int64(5000) // TODO 冷却时间读取配置表
@@ -200,12 +200,12 @@ func (g *Game) VehicleInteractReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.VehicleInteractReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
g.SendError(cmd.VehicleInteractRsp, player, &proto.VehicleInteractRsp{})
return
}
scene := world.GetSceneById(player.SceneId)
// 获取载具实体
entity := scene.GetEntity(req.EntityId)

View File

@@ -191,11 +191,11 @@ func (g *Game) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Message) {
req := payloadMsg.(*proto.ChangeGameTimeReq)
gameTime := req.GameTime
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
scene := world.GetSceneById(player.SceneId)
if scene == nil {
logger.Error("scene is nil, sceneId: %v", player.SceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
scene := world.GetSceneById(player.SceneId)
scene.ChangeGameTime(gameTime)
for _, scenePlayer := range scene.GetAllPlayer() {
@@ -277,6 +277,7 @@ func (g *Game) PlayerQuitDungeonReq(player *model.Player, payloadMsg pb.Message)
req := payloadMsg.(*proto.PlayerQuitDungeonReq)
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
ctx := world.GetLastEnterSceneContextBySceneIdAndUid(3, player.PlayerID)
@@ -379,6 +380,10 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) {
func (g *Game) monsterDrop(player *model.Player, entity *Entity) {
sceneGroupConfig := gdconf.GetSceneGroup(int32(entity.GetGroupId()))
if sceneGroupConfig == nil {
logger.Error("get scene group config is nil, groupId: %v, uid: %v", entity.GetGroupId(), player.PlayerID)
return
}
monsterConfig := sceneGroupConfig.MonsterMap[int32(entity.GetConfigId())]
monsterDropDataConfig := gdconf.GetMonsterDropDataByDropTagAndLevel(monsterConfig.DropTag, monsterConfig.Level)
if monsterDropDataConfig == nil {
@@ -403,6 +408,10 @@ func (g *Game) monsterDrop(player *model.Player, entity *Entity) {
func (g *Game) chestDrop(player *model.Player, entity *Entity) {
sceneGroupConfig := gdconf.GetSceneGroup(int32(entity.GetGroupId()))
if sceneGroupConfig == nil {
logger.Error("get scene group config is nil, groupId: %v, uid: %v", entity.GetGroupId(), player.PlayerID)
return
}
gadgetConfig := sceneGroupConfig.GadgetMap[int32(entity.GetConfigId())]
chestDropDataConfig := gdconf.GetChestDropDataByDropTagAndLevel(gadgetConfig.DropTag, gadgetConfig.Level)
if chestDropDataConfig == nil {
@@ -492,13 +501,12 @@ func (g *Game) doRandDropOnce(dropDataConfig *gdconf.DropData) map[int32]int32 {
return dropMap
}
// TeleportPlayer 传送玩家至地图上的某个位置
// TeleportPlayer 传送玩家通用接口
func (g *Game) TeleportPlayer(
player *model.Player, enterReason proto.EnterReason,
sceneId uint32, pos, rot *model.Vector,
dungeonId, dungeonPointId uint32,
) {
// 传送玩家
newSceneId := sceneId
oldSceneId := player.SceneId
oldPos := &model.Vector{X: player.Pos.X, Y: player.Pos.Y, Z: player.Pos.Z}
@@ -508,13 +516,19 @@ func (g *Game) TeleportPlayer(
}
player.SceneJump = jumpScene
world := WORLD_MANAGER.GetWorldByID(player.WorldId)
oldScene := world.GetSceneById(oldSceneId)
if oldScene == nil {
logger.Error("old scene is nil, sceneId: %v", oldSceneId)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerID)
return
}
oldScene := world.GetSceneById(oldSceneId)
activeAvatarId := world.GetPlayerActiveAvatarId(player)
g.RemoveSceneEntityNotifyBroadcast(oldScene, proto.VisionType_VISION_REMOVE, []uint32{world.GetPlayerWorldAvatarEntityId(player, activeAvatarId)}, false, 0)
if WORLD_MANAGER.IsBigWorld(world) {
bigWorldAoi := world.GetBigWorldAoi()
bigWorldAoi.RemoveObjectFromGridByPos(int64(player.PlayerID), float32(player.Pos.X), float32(player.Pos.Y), float32(player.Pos.Z))
}
if jumpScene {
delTeamEntityNotify := g.PacketDelTeamEntityNotify(oldScene, player)
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerID, player.ClientSeq, delTeamEntityNotify)
@@ -522,10 +536,6 @@ func (g *Game) TeleportPlayer(
oldScene.RemovePlayer(player)
player.SceneId = newSceneId
newScene := world.GetSceneById(newSceneId)
if newScene == nil {
logger.Error("new scene is nil, sceneId: %v", newSceneId)
return
}
newScene.AddPlayer(player)
}
player.SceneLoadState = model.SceneNone