From 2518e08e1ab9a15d98508cc659fac7d179be9334 Mon Sep 17 00:00:00 2001 From: flswld Date: Fri, 16 Aug 2024 18:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E9=81=93=E5=85=B7=E5=88=9D=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdconf/game_data_config.go | 2 + gdconf/widget_json_config.go | 53 +++++++++++++++++++++++ gs/game/game_route_manager.go | 2 + gs/game/player_login.go | 3 +- gs/game/player_world.go | 65 ++++++++++++++++++++++++++++ gs/model/db_world.go | 15 +++++-- protocol/cmd/cmd_id_proto_obj_map.go | 6 +++ 7 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 gdconf/widget_json_config.go diff --git a/gdconf/game_data_config.go b/gdconf/game_data_config.go index 48bb3d57..88f78725 100644 --- a/gdconf/game_data_config.go +++ b/gdconf/game_data_config.go @@ -88,6 +88,7 @@ type GameDataConfig struct { WeaponCurveDataMap map[int32]*WeaponCurveData // 武器曲线 ReliquaryLevelDataMap map[int32]map[int32]*ReliquaryLevelData // 圣遗物等级 MonsterCurveDataMap map[int32]*MonsterCurveData // 怪物曲线 + WidgetJsonConfigMap map[string]*ConfigWidget // 小道具JSON配置 } func InitGameDataConfig() { @@ -204,6 +205,7 @@ func (g *GameDataConfig) load(loadSceneLua bool) { g.loadWeaponCurveData() // 武器曲线 g.loadReliquaryLevelData() // 圣遗物等级 g.loadMonsterCurveData() // 怪物曲线 + g.loadWidgetJsonConfig() // 小道具JSON配置 if g.loadExt { g.loadGachaDropGroupData() // 卡池掉落组 临时的 g.loadPubgWorldGadgetData() // pubg世界物件 diff --git a/gdconf/widget_json_config.go b/gdconf/widget_json_config.go new file mode 100644 index 00000000..4d7e5315 --- /dev/null +++ b/gdconf/widget_json_config.go @@ -0,0 +1,53 @@ +package gdconf + +import ( + "fmt" + "hk4e/pkg/logger" + "os" + "strconv" + + "github.com/hjson/hjson-go/v4" +) + +const ( + WidgetTagTypeActionPanel = "ActionPanel" + WidgetTagTypeFlyAttach = "FlyAttach" +) + +type WidgetJsonConfig struct { + WidgetConfigMap map[string]*ConfigWidget `json:"widgetConfigMap"` +} + +type ConfigWidget struct { + Type string `json:"$type"` + Tags []string `json:"tags"` + IsConsumeMaterial bool `json:"isConsumeMaterial"` + CdGroup int32 `json:"cdGroup"` +} + +func (g *GameDataConfig) loadWidgetJsonConfig() { + g.WidgetJsonConfigMap = make(map[string]*ConfigWidget) + filePath := g.jsonPrefix + "widget_new/ConfigWidgetNew.json" + fileData, err := os.ReadFile(filePath) + if err != nil { + info := fmt.Sprintf("open file error: %v", err) + panic(info) + } + if fileData[0] == 0xEF && fileData[1] == 0xBB && fileData[2] == 0xBF { + fileData = fileData[3:] + } + widgetJsonConfig := new(WidgetJsonConfig) + err = hjson.Unmarshal(fileData, &widgetJsonConfig) + if err != nil { + logger.Error("parse file error: %v, path: %v", err, filePath) + return + } + for k, v := range widgetJsonConfig.WidgetConfigMap { + g.WidgetJsonConfigMap[k] = v + } + logger.Info("WidgetJsonConfig Count: %v", len(g.WidgetJsonConfigMap)) +} + +func GetWidgetJsonConfigByMaterialId(materialId int32) *ConfigWidget { + return CONF.WidgetJsonConfigMap[strconv.Itoa(int(materialId))] +} diff --git a/gs/game/game_route_manager.go b/gs/game/game_route_manager.go index 8f2a2aba..e7dba8b8 100644 --- a/gs/game/game_route_manager.go +++ b/gs/game/game_route_manager.go @@ -144,6 +144,8 @@ func (r *RouteManager) initRoute() { cmd.ReadMailNotify: GAME.ReadMailNotify, cmd.ChangeMailStarNotify: GAME.ChangeMailStarNotify, cmd.SelectWorktopOptionReq: GAME.SelectWorktopOptionReq, + cmd.GetWidgetSlotReq: GAME.GetWidgetSlotReq, + cmd.SetWidgetSlotReq: GAME.SetWidgetSlotReq, } } diff --git a/gs/game/player_login.go b/gs/game/player_login.go index cfa094f0..567c73f2 100644 --- a/gs/game/player_login.go +++ b/gs/game/player_login.go @@ -288,6 +288,7 @@ func (g *Game) LoginNotify(userId uint32, clientSeq uint32, player *model.Player g.SendMsg(cmd.OpenStateUpdateNotify, userId, clientSeq, g.PacketOpenStateUpdateNotify(player)) g.SendMsg(cmd.QuestListNotify, userId, clientSeq, g.PacketQuestListNotify(player)) g.SendMsg(cmd.FinishedParentQuestNotify, userId, clientSeq, g.PacketFinishedParentQuestNotify(player)) - g.SendMsg(cmd.AllMarkPointNotify, player.PlayerId, player.ClientSeq, &proto.AllMarkPointNotify{MarkList: g.PacketMapMarkPointList(player)}) + g.SendMsg(cmd.AllMarkPointNotify, userId, clientSeq, &proto.AllMarkPointNotify{MarkList: g.PacketMapMarkPointList(player)}) + g.SendMsg(cmd.AllWidgetDataNotify, userId, clientSeq, &proto.AllWidgetDataNotify{SlotList: g.PacketWidgetSlotDataList(player)}) g.GCGLogin(player) // 发送GCG登录相关的通知包 } diff --git a/gs/game/player_world.go b/gs/game/player_world.go index 214c52bf..1b046ce6 100644 --- a/gs/game/player_world.go +++ b/gs/game/player_world.go @@ -529,6 +529,58 @@ func (g *Game) SelectWorktopOptionReq(player *model.Player, payloadMsg pb.Messag }) } +func (g *Game) GetWidgetSlotReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.GetWidgetSlotReq) + _ = req + + g.SendMsg(cmd.GetWidgetSlotRsp, player.PlayerId, player.ClientSeq, &proto.GetWidgetSlotRsp{ + SlotList: g.PacketWidgetSlotDataList(player), + }) +} + +func (g *Game) SetWidgetSlotReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.SetWidgetSlotReq) + + widgetJsonConfig := gdconf.GetWidgetJsonConfigByMaterialId(int32(req.MaterialId)) + if widgetJsonConfig == nil { + g.SendError(cmd.SetWidgetSlotRsp, player, new(proto.SetWidgetSlotRsp), proto.Retcode_RET_NOT_FOUND_CONFIG) + return + } + tagList := make([]uint8, 0) + for _, tag := range widgetJsonConfig.Tags { + switch tag { + case gdconf.WidgetTagTypeActionPanel: + tagList = append(tagList, uint8(proto.WidgetSlotTag_WIDGET_SLOT_QUICK_USE)) + case gdconf.WidgetTagTypeFlyAttach: + tagList = append(tagList, uint8(proto.WidgetSlotTag_WIDGET_SLOT_ATTACH_AVATAR)) + } + } + dbWorld := player.GetDbWorld() + switch req.Op { + case proto.WidgetSlotOp_WIDGET_SLOT_OP_ATTACH: + for _, tag := range tagList { + widget, exist := dbWorld.WidgetSlotMap[tag] + if !exist { + widget = &model.Widget{ + Tag: tag, + } + dbWorld.WidgetSlotMap[tag] = widget + } + widget.MaterialId = req.MaterialId + } + case proto.WidgetSlotOp_WIDGET_SLOT_OP_DETACH: + for _, tag := range tagList { + delete(dbWorld.WidgetSlotMap, tag) + } + } + + g.SendMsg(cmd.SetWidgetSlotRsp, player.PlayerId, player.ClientSeq, &proto.SetWidgetSlotRsp{ + TagList: req.TagList, + MaterialId: req.MaterialId, + Op: req.Op, + }) +} + /************************************************** 游戏功能 **************************************************/ // UnlockPlayerScenePoint 解锁场景锚点 @@ -840,3 +892,16 @@ func (g *Game) PacketMapMarkPointList(player *model.Player) []*proto.MapMarkPoin } return pbMarkList } + +func (g *Game) PacketWidgetSlotDataList(player *model.Player) []*proto.WidgetSlotData { + widgetSlotDataList := make([]*proto.WidgetSlotData, 0) + dbWorld := player.GetDbWorld() + for _, widget := range dbWorld.WidgetSlotMap { + widgetSlotDataList = append(widgetSlotDataList, &proto.WidgetSlotData{ + Tag: proto.WidgetSlotTag(widget.Tag), + MaterialId: widget.MaterialId, + IsActive: true, + }) + } + return widgetSlotDataList +} diff --git a/gs/model/db_world.go b/gs/model/db_world.go index db51524a..45f22313 100644 --- a/gs/model/db_world.go +++ b/gs/model/db_world.go @@ -5,9 +5,10 @@ import ( ) type DbWorld struct { - SceneMap map[uint32]*DbScene - MapMarkList []*MapMark - GameTime uint32 // 游戏内提瓦特大陆的时间 + SceneMap map[uint32]*DbScene + MapMarkList []*MapMark + GameTime uint32 // 游戏内提瓦特大陆的时间 + WidgetSlotMap map[uint8]*Widget } type DbScene struct { @@ -24,6 +25,11 @@ type MapMark struct { Name string } +type Widget struct { + Tag uint8 + MaterialId uint32 +} + func (p *Player) GetDbWorld() *DbWorld { if p.DbWorld == nil { p.DbWorld = new(DbWorld) @@ -35,6 +41,9 @@ func (p *Player) GetDbWorld() *DbWorld { if p.DbWorld.MapMarkList == nil { p.DbWorld.MapMarkList = make([]*MapMark, 0) } + if p.DbWorld.WidgetSlotMap == nil { + p.DbWorld.WidgetSlotMap = make(map[uint8]*Widget) + } return p.DbWorld } diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index 00bf91d9..cdda9e2a 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -168,6 +168,12 @@ func (c *CmdProtoMap) registerMessage() { c.regMsg(SelectWorktopOptionReq, func() any { return new(proto.SelectWorktopOptionReq) }) // 操作台选项选择请求 c.regMsg(SelectWorktopOptionRsp, func() any { return new(proto.SelectWorktopOptionRsp) }) // 操作台选项选择响应 c.regMsg(WorktopOptionNotify, func() any { return new(proto.WorktopOptionNotify) }) // 操作台选项通知 + c.regMsg(GetWidgetSlotReq, func() any { return new(proto.GetWidgetSlotReq) }) // 获取小道具槽位请求 + c.regMsg(GetWidgetSlotRsp, func() any { return new(proto.GetWidgetSlotRsp) }) // 获取小道具槽位响应 + c.regMsg(SetWidgetSlotReq, func() any { return new(proto.SetWidgetSlotReq) }) // 设置小道具槽位请求 + c.regMsg(SetWidgetSlotRsp, func() any { return new(proto.SetWidgetSlotRsp) }) // 设置小道具槽位响应 + c.regMsg(WidgetSlotChangeNotify, func() any { return new(proto.WidgetSlotChangeNotify) }) // 小道具槽位更新通知 + c.regMsg(AllWidgetDataNotify, func() any { return new(proto.AllWidgetDataNotify) }) // 小道具槽位数据通知 // 战斗与同步 c.regMsg(AvatarFightPropNotify, func() any { return new(proto.AvatarFightPropNotify) }) // 角色战斗属性通知