小道具初步

This commit is contained in:
flswld committed 2024-08-16 18:09:48 +08:00
1 parent 6f168bb3cf
commit 2518e08e1a
7 files changed
+142 -4

No files matched your search

+2
View File
@@ -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世界物件
+53
View File
@@ -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))]
}
+2
View File
@@ -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,
}
}
+2 -1
View File
@@ -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登录相关的通知包
}
+65
View File
@@ -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
}
+12 -3
View File
@@ -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
}
+6
View File
@@ -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) }) // 角色战斗属性通知