This commit is contained in:
flswld committed 2024-08-23 15:13:55 +08:00
1 parent f1f8d2e00c
commit 565243bfe7
7 files changed
+131 -71

No files matched your search

+13
View File
@@ -523,6 +523,7 @@ type IEntity interface {
RemoveModifier(instancedModifierId uint32)
AbilityAction(ability *Ability, action *gdconf.ActionData, entity IEntity)
AbilityMixin(ability *Ability, mixin *gdconf.MixinData, entity IEntity)
GetDynamicValueMap() map[uint32]float32
}
// Entity 场景实体数据结构
@@ -544,6 +545,7 @@ type Entity struct {
visionLevel int
abilityMap map[uint32]*Ability
modifierMap map[uint32]*Modifier
dynamicValueMap map[uint32]float32
}
func (e *Entity) IsEntity() {
@@ -836,6 +838,8 @@ func (e *Entity) AbilityAction(ability *Ability, action *gdconf.ActionData, enti
GAME.CreateDropGadget(owner, entity.GetPos(), uint32(itemDataConfig.GadgetId), uint32(action.ConfigID), 1)
}
}
default:
logger.Error("not support ability action type: %v, abilityName: %v, entityId: %v", action.Type, ability.abilityName, entity.GetId())
}
}
@@ -854,6 +858,10 @@ func (e *Entity) AbilityMixin(ability *Ability, mixin *gdconf.MixinData, entity
}
}
func (e *Entity) GetDynamicValueMap() map[uint32]float32 {
return e.dynamicValueMap
}
type AvatarEntity struct {
*Entity
uid uint32
@@ -871,6 +879,7 @@ func (a *AvatarEntity) GetAvatarId() uint32 {
func (a *AvatarEntity) InitAbility() {
a.abilityMap = make(map[uint32]*Ability)
a.modifierMap = make(map[uint32]*Modifier)
a.dynamicValueMap = make(map[uint32]float32)
}
type WeaponEntity struct {
@@ -880,6 +889,7 @@ type WeaponEntity struct {
func (w *WeaponEntity) InitAbility() {
w.abilityMap = make(map[uint32]*Ability)
w.modifierMap = make(map[uint32]*Modifier)
w.dynamicValueMap = make(map[uint32]float32)
}
type MonsterEntity struct {
@@ -894,6 +904,7 @@ func (m *MonsterEntity) GetMonsterId() uint32 {
func (m *MonsterEntity) InitAbility() {
m.abilityMap = make(map[uint32]*Ability)
m.modifierMap = make(map[uint32]*Modifier)
m.dynamicValueMap = make(map[uint32]float32)
monsterDataConfig := gdconf.GetMonsterDataById(int32(m.GetMonsterId()))
if monsterDataConfig == nil {
logger.Error("get monster data config is nil, monsterId: %v", m.GetMonsterId())
@@ -950,6 +961,7 @@ func (n *NpcEntity) GetBlockId() uint32 {
func (n *NpcEntity) InitAbility() {
n.abilityMap = make(map[uint32]*Ability)
n.modifierMap = make(map[uint32]*Modifier)
n.dynamicValueMap = make(map[uint32]float32)
}
func (n *NpcEntity) CreateNpcEntity(npcId, roomId, parentQuestId, blockId uint32) {
@@ -987,6 +999,7 @@ func (g *GadgetEntity) SetGadgetState(state uint32) {
func (g *GadgetEntity) InitAbility() {
g.abilityMap = make(map[uint32]*Ability)
g.modifierMap = make(map[uint32]*Modifier)
g.dynamicValueMap = make(map[uint32]float32)
gadgetDataConfig := gdconf.GetGadgetDataById(int32(g.GetGadgetId()))
if gadgetDataConfig == nil {
logger.Error("get gadget data config is nil, gadgetId: %v", g.GetGadgetId())
+1 -1
View File
@@ -103,7 +103,7 @@ func (g *Game) QueryPathReq(player *model.Player, payloadMsg pb.Message) {
queryPathRsp := &proto.QueryPathRsp{
QueryId: req.QueryId,
QueryStatus: proto.QueryPathRsp_STATUS_SUCC,
Corners: []*proto.Vector{req.DestinationPos[0]},
Corners: []*proto.Vector{req.SourcePos, req.DestinationPos[0]},
}
g.SendMsg(cmd.QueryPathRsp, player.PlayerId, player.ClientSeq, queryPathRsp)
}
+17 -2
View File
@@ -773,7 +773,7 @@ func (g *Game) handleAbilityInvoke(player *model.Player, entry *proto.AbilityInv
}
for _, abilityScalarValueEntry := range reInitOverrideMap.OverrideMap {
if abilityScalarValueEntry.ValueType != proto.AbilityScalarType_ABILITY_SCALAR_TYPE_FLOAT {
logger.Error("override param type not support, type: %v, uid: %v", abilityScalarValueEntry.ValueType, player.PlayerId)
logger.Error("param type not support, type: %v, uid: %v", abilityScalarValueEntry.ValueType, player.PlayerId)
return
}
key := abilityScalarValueEntry.Key.GetHash()
@@ -793,12 +793,27 @@ func (g *Game) handleAbilityInvoke(player *model.Player, entry *proto.AbilityInv
return
}
if abilityScalarValueEntry.ValueType != proto.AbilityScalarType_ABILITY_SCALAR_TYPE_FLOAT {
logger.Error("override param type not support, type: %v, uid: %v", abilityScalarValueEntry.ValueType, player.PlayerId)
logger.Error("param type not support, type: %v, uid: %v", abilityScalarValueEntry.ValueType, player.PlayerId)
return
}
key := abilityScalarValueEntry.Key.GetHash()
value := abilityScalarValueEntry.Value.(*proto.AbilityScalarValueEntry_FloatValue).FloatValue
ability.abilitySpecialOverrideMap[key] = value
case proto.AbilityInvokeArgument_ABILITY_META_GLOBAL_FLOAT_VALUE:
abilityScalarValueEntry := new(proto.AbilityScalarValueEntry)
err := pb.Unmarshal(entry.AbilityData, abilityScalarValueEntry)
if err != nil {
logger.Error("parse AbilityScalarValueEntry error: %v", err)
return
}
if abilityScalarValueEntry.ValueType != proto.AbilityScalarType_ABILITY_SCALAR_TYPE_FLOAT {
logger.Error("param type not support, type: %v, uid: %v", abilityScalarValueEntry.ValueType, player.PlayerId)
return
}
key := abilityScalarValueEntry.Key.GetHash()
value := abilityScalarValueEntry.Value.(*proto.AbilityScalarValueEntry_FloatValue).FloatValue
dynamicValueMap := entity.GetDynamicValueMap()
dynamicValueMap[key] = value
}
} else {
logger.Error("???")
+84 -53
View File
@@ -31,12 +31,17 @@ const (
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
}
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
if ctx == nil {
logger.Error("get enter scene context is nil, uid: %v", player.PlayerId)
return
}
logger.Debug("player enter scene ready, ctx: %+v, uid: %v", ctx, player.PlayerId)
if world.IsMultiplayerWorld() && world.IsPlayerFirstEnter(player) {
playerPreEnterMpNotify := &proto.PlayerPreEnterMpNotify{
@@ -47,11 +52,6 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
g.SendToWorldH(world, cmd.PlayerPreEnterMpNotify, 0, playerPreEnterMpNotify)
}
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
if ctx == nil {
logger.Error("get enter scene context is nil, uid: %v", player.PlayerId)
return
}
if ctx.OldSceneId != 0 {
oldSceneId := ctx.OldSceneId
oldPos := ctx.OldPos
@@ -149,12 +149,18 @@ func (g *Game) EnterSceneReadyReq(player *model.Player, payloadMsg pb.Message) {
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)
if world == nil {
logger.Error("get world is nil, worldId: %v, uid: %v", player.WorldId, player.PlayerId)
return
}
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
if ctx == nil {
logger.Error("get enter scene context is nil, uid: %v", player.PlayerId)
return
}
logger.Debug("player scene init finish, ctx: %+v, uid: %v", ctx, player.PlayerId)
scene := world.GetSceneById(player.GetSceneId())
if world.IsMultiplayerWorld() && world.IsPlayerFirstEnter(player) {
@@ -298,11 +304,6 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
g.UpdateWorldScenePlayerInfo(player, world)
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
if ctx == nil {
logger.Error("get enter scene context is nil, uid: %v", player.PlayerId)
return
}
if ctx.DungeonId != 0 {
// 进入的场景是地牢副本
g.GCGTavernInit(player) // GCG酒馆信息通知
@@ -337,12 +338,18 @@ func (g *Game) SceneInitFinishReq(player *model.Player, payloadMsg pb.Message) {
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
}
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
if ctx == nil {
logger.Error("get enter scene context is nil, uid: %v", player.PlayerId)
return
}
logger.Debug("player enter scene done, ctx: %+v, uid: %v", ctx, player.PlayerId)
scene := world.GetSceneById(player.GetSceneId())
var visionType = proto.VisionType_VISION_NONE
@@ -436,12 +443,17 @@ func (g *Game) EnterSceneDoneReq(player *model.Player, payloadMsg pb.Message) {
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
}
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
if ctx == nil {
logger.Error("get enter scene context is nil, uid: %v", player.PlayerId)
return
}
logger.Debug("player post enter scene, ctx: %+v, uid: %v", ctx, player.PlayerId)
if world.IsMultiplayerWorld() && world.IsPlayerFirstEnter(player) {
guestPostEnterSceneNotify := &proto.GuestPostEnterSceneNotify{
@@ -453,11 +465,6 @@ func (g *Game) PostEnterSceneReq(player *model.Player, payloadMsg pb.Message) {
world.PlayerEnter(player.PlayerId)
ctx := world.GetEnterSceneContextByToken(req.EnterSceneToken)
if ctx == nil {
logger.Error("get enter scene context is nil, uid: %v", player.PlayerId)
return
}
sceneDataConfig := gdconf.GetSceneDataById(int32(ctx.NewSceneId))
if sceneDataConfig == nil {
logger.Error("get scene data config is nil, sceneId: %v, uid: %v", ctx.NewSceneId, player.PlayerId)
@@ -555,6 +562,9 @@ type SceneBlockLoadInfoCtx struct {
// LoadSceneBlockAsync 异步加载场景区块存档
func (g *Game) LoadSceneBlockAsync(player *model.Player, oldScene *Scene, newScene *Scene, oldPos *model.Vector, newPos *model.Vector, origin string, ctx *SceneBlockLoadInfoCtx) bool {
if player.SceneBlockAsyncLoad {
return false
}
oldSceneBlockAoi := WORLD_MANAGER.GetSceneBlockAoiMap()[oldScene.GetId()]
if oldSceneBlockAoi == nil {
logger.Error("scene not exist in aoi, sceneId: %v", oldScene.GetId())
@@ -567,44 +577,51 @@ func (g *Game) LoadSceneBlockAsync(player *model.Player, oldScene *Scene, newSce
}
oldGid := oldSceneBlockAoi.GetGidByPos(float32(oldPos.X), 0.0, float32(oldPos.Z))
newGid := newSceneBlockAoi.GetGidByPos(float32(newPos.X), 0.0, float32(newPos.Z))
if oldGid == newGid {
return false
}
// 跨越了block格子
logger.Debug("player cross scene block grid, oldGid: %v, newGid: %v, uid: %v", oldGid, newGid, player.PlayerId)
if player.SceneBlockAsyncLoad {
return false
}
logger.Info("async load player scene block from db, uid: %v", player.PlayerId)
oldGridList := oldSceneBlockAoi.GetSurrGridListByGid(oldGid, 1)
newGridList := newSceneBlockAoi.GetSurrGridListByGid(newGid, 1)
delGridIdList := make([]uint32, 0)
for _, oldGrid := range oldGridList {
exist := false
for _, newGrid := range newGridList {
if oldGrid.GetGid() == newGrid.GetGid() {
exist = true
break
}
}
if exist {
continue
}
delGridIdList = append(delGridIdList, oldGrid.GetGid())
}
addGridIdList := make([]uint32, 0)
for _, newGrid := range newGridList {
exist := false
if oldScene.GetId() == newScene.GetId() {
if oldGid == newGid {
return false
}
// 跨越了block格子
logger.Debug("player cross scene block grid, oldGid: %v, newGid: %v, uid: %v", oldGid, newGid, player.PlayerId)
oldGridList := oldSceneBlockAoi.GetSurrGridListByGid(oldGid, 1)
newGridList := newSceneBlockAoi.GetSurrGridListByGid(newGid, 1)
for _, oldGrid := range oldGridList {
if newGrid.GetGid() == oldGrid.GetGid() {
exist = true
break
exist := false
for _, newGrid := range newGridList {
if oldGrid.GetGid() == newGrid.GetGid() {
exist = true
break
}
}
if exist {
continue
}
delGridIdList = append(delGridIdList, oldGrid.GetGid())
}
if exist {
continue
for _, newGrid := range newGridList {
exist := false
for _, oldGrid := range oldGridList {
if newGrid.GetGid() == oldGrid.GetGid() {
exist = true
break
}
}
if exist {
continue
}
addGridIdList = append(addGridIdList, newGrid.GetGid())
}
} else {
oldGridList := oldSceneBlockAoi.GetSurrGridListByGid(oldGid, 1)
newGridList := newSceneBlockAoi.GetSurrGridListByGid(newGid, 1)
for _, oldGrid := range oldGridList {
delGridIdList = append(delGridIdList, oldGrid.GetGid())
}
for _, newGrid := range newGridList {
addGridIdList = append(addGridIdList, newGrid.GetGid())
}
addGridIdList = append(addGridIdList, newGrid.GetGid())
}
loadSceneBlockMap := make(map[uint32]*gdconf.Block)
for _, addGridId := range addGridIdList {
@@ -620,6 +637,7 @@ func (g *Game) LoadSceneBlockAsync(player *model.Player, oldScene *Scene, newSce
if len(loadSceneBlockMap) == 0 {
return false
}
logger.Info("async load player scene block from db: %v, uid: %v", loadSceneBlockMap, player.PlayerId)
player.SceneBlockAsyncLoad = true
go func() {
loadSceneBlockList := make([]*model.SceneBlock, 0)
@@ -2135,17 +2153,30 @@ func (g *Game) PacketSceneAvatarInfo(scene *Scene, player *model.Player, avatarI
func (g *Game) PacketSceneMonsterInfo(entity IEntity) *proto.SceneMonsterInfo {
blockId := uint32(0)
titleId := uint32(0)
specialNameId := uint32(0)
if entity.GetGroupId() != 0 {
groupConfig := gdconf.GetSceneGroup(int32(entity.GetGroupId()))
if groupConfig == nil {
logger.Error("get scene group config is nil, groupId: %v", entity.GetGroupId())
return new(proto.SceneMonsterInfo)
}
blockId = uint32(groupConfig.BlockId)
monsterConfig, exist := groupConfig.MonsterMap[int32(entity.GetConfigId())]
if !exist {
logger.Error("monster config not exist, configId: %v", entity.GetConfigId())
return new(proto.SceneMonsterInfo)
}
titleId = uint32(monsterConfig.TitleId)
specialNameId = uint32(monsterConfig.SpecialNameId)
}
sceneMonsterInfo := &proto.SceneMonsterInfo{
MonsterId: entity.(*MonsterEntity).GetMonsterId(),
AuthorityPeerId: 1,
BornType: proto.MonsterBornType_MONSTER_BORN_DEFAULT,
BlockId: blockId,
TitleId: blockId,
SpecialNameId: 0,
TitleId: titleId,
SpecialNameId: specialNameId,
}
return sceneMonsterInfo
}
+3 -3
View File
@@ -927,17 +927,17 @@ func (g *Game) TeleportPlayer(
var enterType proto.EnterType
if newSceneId != oldSceneId {
player.SceneJump = true
logger.Debug("player jump scene, scene: %v, pos: %v", player.GetSceneId(), newPos)
logger.Debug("player jump scene, scene: %v, pos: %v", newSceneId, newPos)
enterType = proto.EnterType_ENTER_JUMP
if enterReason == proto.EnterReason_ENTER_REASON_DUNGEON_ENTER {
logger.Debug("player tp to dungeon scene, sceneId: %v, pos: %v", player.GetSceneId(), newPos)
logger.Debug("player tp to dungeon scene, sceneId: %v, pos: %v", newSceneId, newPos)
enterType = proto.EnterType_ENTER_DUNGEON
}
delTeamEntityNotify := g.PacketDelTeamEntityNotify(world, player)
g.SendMsg(cmd.DelTeamEntityNotify, player.PlayerId, player.ClientSeq, delTeamEntityNotify)
} else {
player.SceneJump = false
logger.Debug("player goto scene, scene: %v, pos: %v", player.GetSceneId(), newPos)
logger.Debug("player goto scene, scene: %v, pos: %v", newSceneId, newPos)
enterType = proto.EnterType_ENTER_GOTO
}