From 258695308e7e8e8c909d0733d5d2b95dd37e59c5 Mon Sep 17 00:00:00 2001 From: flswld Date: Thu, 13 Jun 2024 13:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E4=BB=B6=E4=BA=A4=E4=BA=92bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gate/net/proto_endecode.go | 31 +++++++++++++++++++++++-------- gs/game/game_world_scene.go | 12 ++++++++++-- gs/game/player_scene.go | 28 +++++++++++++++++++--------- gs/game/player_world.go | 6 ++++-- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/gate/net/proto_endecode.go b/gate/net/proto_endecode.go index e5d4c27d..2a7c66dd 100644 --- a/gate/net/proto_endecode.go +++ b/gate/net/proto_endecode.go @@ -1,6 +1,8 @@ package net import ( + "bytes" + "encoding/json" "reflect" "strings" @@ -11,6 +13,7 @@ import ( "hk4e/protocol/cmd" "hk4e/protocol/proto" + "google.golang.org/protobuf/encoding/protojson" pb "google.golang.org/protobuf/proto" ) @@ -104,14 +107,18 @@ func ProtoDecode(kcpMsg *KcpMsg, msg.PayloadMessage = protoMessage.message protoMsgList = append(protoMsgList, msg) } - // for _, msg := range protoMsgList { - // cmdName := "???" - // if msg.PayloadMessage != nil { - // cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName()) - // } - // logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v", - // msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage) - // } + for _, msg := range protoMsgList { + cmdName := "???" + if msg.PayloadMessage != nil { + cmdName = string(msg.PayloadMessage.ProtoReflect().Descriptor().FullName()) + } + logger.Debug("[RECV UNION CMD] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v", + msg.CmdId, cmdName, msg.SessionId, msg.HeadMessage) + data, _ := protojson.Marshal(msg.PayloadMessage) + var buf bytes.Buffer + _ = json.Indent(&buf, data, "", "\t") + logger.Debug("%v", buf.String()) + } } else { protoMsg.PayloadMessage = protoMessageList[0].message protoMsgList = append(protoMsgList, protoMsg) @@ -121,6 +128,10 @@ func ProtoDecode(kcpMsg *KcpMsg, } logger.Debug("[RECV] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v", protoMsg.CmdId, cmdName, protoMsg.SessionId, protoMsg.HeadMessage) + data, _ := protojson.Marshal(protoMsg.PayloadMessage) + var buf bytes.Buffer + _ = json.Indent(&buf, data, "", "\t") + logger.Debug("%v", buf.String()) } return protoMsgList } @@ -200,6 +211,10 @@ func ProtoEncode(protoMsg *ProtoMsg, } logger.Debug("[SEND] cmdId: %v, cmdName: %v, sessionId: %v, headMsg: %v", protoMsg.CmdId, cmdName, protoMsg.SessionId, protoMsg.HeadMessage) + data, _ := protojson.Marshal(protoMsg.PayloadMessage) + var buf bytes.Buffer + _ = json.Indent(&buf, data, "", "\t") + logger.Debug("%v", buf.String()) kcpMsg = new(KcpMsg) kcpMsg.SessionId = protoMsg.SessionId kcpMsg.CmdId = protoMsg.CmdId diff --git a/gs/game/game_world_scene.go b/gs/game/game_world_scene.go index 418edc16..fe86a284 100644 --- a/gs/game/game_world_scene.go +++ b/gs/game/game_world_scene.go @@ -831,7 +831,9 @@ func (e *Entity) AbilityAction(ability *Ability, action *gdconf.ActionData, enti continue } count := math.Ceil(float64(totalEnergy) / float64(sameEnergy)) - GAME.CreateDropGadget(owner, entity.GetPos(), uint32(itemDataConfig.GadgetId), uint32(action.ConfigID), uint32(count)) + for i := 0; i < int(count); i++ { + GAME.CreateDropGadget(owner, entity.GetPos(), uint32(itemDataConfig.GadgetId), uint32(action.ConfigID), 1) + } } } } @@ -1034,14 +1036,20 @@ func (g *GadgetTrifleItemEntity) CreateGadgetTrifleItemEntity(itemId, count uint type GadgetGatherEntity struct { *GadgetEntity itemId uint32 + count uint32 } func (g *GadgetGatherEntity) GetItemId() uint32 { return g.itemId } -func (g *GadgetGatherEntity) CreateGadgetGatherEntity(itemId uint32) { +func (g *GadgetGatherEntity) GetCount() uint32 { + return g.count +} + +func (g *GadgetGatherEntity) CreateGadgetGatherEntity(itemId, count uint32) { g.itemId = itemId + g.count = count } type GadgetWorktopEntity struct { diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index bb1612e3..ee83c8fa 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -1333,9 +1333,9 @@ func (g *Game) CreateConfigEntity(scene *Scene, groupId uint32, entityConfig any gadgetGatherEntity := scene.CreateEntityGadgetGather( &model.Vector{X: float64(gadget.Pos.X), Y: float64(gadget.Pos.Y), Z: float64(gadget.Pos.Z)}, &model.Vector{X: float64(gadget.Rot.X), Y: float64(gadget.Rot.Y), Z: float64(gadget.Rot.Z)}, - uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), uint32(gatherDataConfig.GadgetId), uint32(constant.GADGET_STATE_DEFAULT), + uint32(gadget.ConfigId), groupId, int(gadget.VisionLevel), uint32(gatherDataConfig.GadgetId), constant.GADGET_STATE_DEFAULT, ) - gadgetGatherEntity.CreateGadgetGatherEntity(uint32(gatherDataConfig.ItemId)) + gadgetGatherEntity.CreateGadgetGatherEntity(uint32(gatherDataConfig.ItemId), 1) scene.CreateEntity(gadgetGatherEntity) return gadgetGatherEntity.GetId() case constant.GADGET_TYPE_WORKTOP: @@ -1484,8 +1484,9 @@ func (g *Game) CreateGadget(player *model.Player, pos *model.Vector, gadgetId ui // CreateDropGadget 创建掉落物的物件实体 func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetId, itemId, count uint32) uint32 { - if gadgetId == 0 { - logger.Error("create gadget id is zero, pos: %+v, itemId: %v, count: %v, uid: %v", pos, itemId, count, player.PlayerId) + gadgetDataConfig := gdconf.GetGadgetDataById(int32(gadgetId)) + if gadgetDataConfig == nil { + logger.Error("get gadget data config is nil, gadgetId: %v", gadgetId) return 0 } world := WORLD_MANAGER.GetWorldById(player.WorldId) @@ -1500,11 +1501,20 @@ func (g *Game) CreateDropGadget(player *model.Player, pos *model.Vector, gadgetI } rot := new(model.Vector) rot.Y = random.GetRandomFloat64(0.0, 360.0) - gadgetTrifleItemEntity := scene.CreateEntityGadgetTrifleItem(pos, rot, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT) - gadgetTrifleItemEntity.CreateGadgetTrifleItemEntity(itemId, count) - scene.CreateEntity(gadgetTrifleItemEntity) - g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{gadgetTrifleItemEntity.GetId()}, true, false) - return gadgetTrifleItemEntity.GetId() + entityId := uint32(0) + if gadgetDataConfig.Type == constant.GADGET_TYPE_GATHER_OBJECT { + gadgetGatherEntity := scene.CreateEntityGadgetGather(pos, rot, 0, 0, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT) + gadgetGatherEntity.CreateGadgetGatherEntity(itemId, count) + scene.CreateEntity(gadgetGatherEntity) + entityId = gadgetGatherEntity.GetId() + } else { + gadgetTrifleItemEntity := scene.CreateEntityGadgetTrifleItem(pos, rot, constant.VISION_LEVEL_NORMAL, gadgetId, constant.GADGET_STATE_DEFAULT) + gadgetTrifleItemEntity.CreateGadgetTrifleItemEntity(itemId, count) + scene.CreateEntity(gadgetTrifleItemEntity) + entityId = gadgetTrifleItemEntity.GetId() + } + g.AddSceneEntityNotify(player, proto.VisionType_VISION_BORN, []uint32{entityId}, true, false) + return entityId } // GetPosIsInWeatherArea 获取坐标是否在指定的天气区域 diff --git a/gs/game/player_world.go b/gs/game/player_world.go index 9d00c153..18a3042b 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -426,13 +426,15 @@ func (g *Game) GadgetInteractReq(player *model.Player, payloadMsg pb.Message) { // 掉落物捡起 interactType = proto.InteractType_INTERACT_PICK_ITEM gadgetTrifleItemEntity := entity.(*GadgetTrifleItemEntity) - g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetTrifleItemEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP) + itemList := []*ChangeItem{{ItemId: gadgetTrifleItemEntity.GetItemId(), ChangeCount: gadgetTrifleItemEntity.GetCount()}} + g.AddPlayerItem(player.PlayerId, itemList, proto.ActionReasonType_ACTION_REASON_SUBFIELD_DROP) g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) case constant.GADGET_TYPE_GATHER_OBJECT: // 采集物摘取 interactType = proto.InteractType_INTERACT_GATHER gadgetGatherEntity := entity.(*GadgetGatherEntity) - g.AddPlayerItem(player.PlayerId, []*ChangeItem{{ItemId: gadgetGatherEntity.GetItemId(), ChangeCount: 1}}, proto.ActionReasonType_ACTION_REASON_GATHER) + itemList := []*ChangeItem{{ItemId: gadgetGatherEntity.GetItemId(), ChangeCount: gadgetGatherEntity.GetCount()}} + g.AddPlayerItem(player.PlayerId, itemList, proto.ActionReasonType_ACTION_REASON_GATHER) g.KillEntity(player, scene, entity.GetId(), proto.PlayerDieType_PLAYER_DIE_NONE) case constant.GADGET_TYPE_CHEST: // 宝箱开启