fix(fight): 使用模型层方法生成精灵信息 refactor(controller): 移除冗余变量与内联XML读取逻辑 refactor(pet): 重构经验更新与进化逻辑 refactor(item): 校验并扣减使用道具数量 feat(item): 新增金豆购买商品协议结构体 feat(user): 迁移角色服装变更逻辑至user控制器 feat(pet): 增加技能排序协议定义 refactor(utils): 移除未使用的工具函数引用 chore(config): 更新地图怪物配置信息 详细变更内容包括: - 在`xmlres/file.go`中初始化`GoldProductMap`并加载相关配置。 - 将`GenPetInfo`方法从玩家服务迁移至`model`包以统一管理。 - 合并部分不必要的局部变量声明,并优化XML资源加载方式。 - 拆分精灵升级与进化方法,明确调用职责。 - 在战斗和治疗等操作前增加货币校验及扣除逻辑。 - 补充金豆购买相关的客户端/服务端通信结构体。 - 调整技能选择逻辑避免潜在索引越界问题。 - 更新部分注释说明和代码结构以提升可维护性。
175 lines
4.1 KiB
Go
175 lines
4.1 KiB
Go
package xmlres
|
|
|
|
import (
|
|
"blazing/common/utils"
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"github.com/ECUST-XX/xml"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/gogf/gf/v2/os/gfile"
|
|
"github.com/gogf/gf/v2/os/gfsnotify"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var path string
|
|
|
|
func getXml[T any](path string) T {
|
|
|
|
// 解析XML到结构体
|
|
var xmls T
|
|
t1 := gfile.GetBytes(path)
|
|
xml.Unmarshal(t1, &xmls)
|
|
|
|
return xmls
|
|
}
|
|
func getJson[T any](path string) T {
|
|
|
|
// 解析XML到结构体
|
|
var xmls T
|
|
t1 := gfile.GetBytes(path)
|
|
json.Unmarshal(t1, &xmls)
|
|
|
|
return xmls
|
|
}
|
|
|
|
var (
|
|
MapConfig Maps //地图配置
|
|
ItemsConfig Items //物品配置
|
|
EffectArgsConfig EffectArg //arg参数
|
|
TalkConfig TalkRoot //任务配置
|
|
//Monster MonsterRoot //野怪配置
|
|
MonsterMap map[int]TMapConfig
|
|
//Skill MovesTbl //技能配置
|
|
SkillMap map[int]Move
|
|
PetMAP map[int]PetInfo //宠物配置
|
|
NatureRootMap map[int]NatureItem
|
|
EffectMAP map[int]NewSeIdx
|
|
PlayerEffectMAP map[int]NewSeIdx
|
|
ItemsMAP map[int]Item
|
|
TaskMap map[int]Task
|
|
ShopMap map[int]ShopItem
|
|
SkillTypeMap map[int]SkillType
|
|
RelationsMap map[int]Relation
|
|
GoldProductMap = make(map[int]GoldProductItem, 0)
|
|
)
|
|
|
|
func initfile() {
|
|
path1, _ := os.Getwd()
|
|
path = path1 + "/public/config/"
|
|
MapConfig = getXml[Maps](path + "210.xml")
|
|
ItemsConfig = getXml[Items](path + "43.xml")
|
|
EffectArgsConfig = getJson[EffectArg](path + "side_effect.json")
|
|
EffectArgs = make(map[int]int)
|
|
for _, t := range EffectArgsConfig.SideEffects.SideEffect {
|
|
EffectArgs[t.ID] = t.SideEffectArgcount
|
|
|
|
}
|
|
ItemsMAP = utils.ToMap[Item, int](ItemsConfig.Items, func(m Item) int {
|
|
return m.ID
|
|
|
|
})
|
|
|
|
TalkConfig = getXml[TalkRoot](path + "talk.xml")
|
|
|
|
MonsterMap = utils.ToMap(getXml[MonsterRoot](path+"地图配置野怪.xml").Maps, func(m TMapConfig) int {
|
|
return m.ID
|
|
|
|
})
|
|
|
|
ShopMap = utils.ToMap(getXml[ShopRoot](path+"地图配置野怪.xml").Items, func(m ShopItem) int {
|
|
return gconv.Int(m.ProductID)
|
|
|
|
})
|
|
Skill := getXml[MovesTbl](path + "227.xml")
|
|
|
|
SkillMap = make(map[int]Move, len(Skill.Moves))
|
|
for _, v := range Skill.Moves {
|
|
v.SideEffectS = ParseSideEffectArgs(v.SideEffect)
|
|
v.SideEffectArgS = ParseSideEffectArgs(v.SideEffectArg)
|
|
SkillMap[v.ID] = v
|
|
}
|
|
|
|
TaskMap = utils.ToMap[Task, int](getXml[Tasks](path+"task.xml").Tasks, func(m Task) int {
|
|
return m.ID
|
|
|
|
})
|
|
|
|
PetMAP = utils.ToMap[PetInfo, int](getXml[Monsters](path+"226.xml").Monsters, func(m PetInfo) int {
|
|
return m.ID
|
|
|
|
})
|
|
|
|
NatureRootMap = utils.ToMap[NatureItem, int](getXml[NatureRoot](path+"nature.xml").Items, func(m NatureItem) int {
|
|
return m.ID
|
|
|
|
})
|
|
EffectMAP1 := getXml[NewSe](path + "bossbuff和特性.xml")
|
|
EffectMAP = make(map[int]NewSeIdx, len(EffectMAP1.SeIdxList))
|
|
for _, v := range EffectMAP1.SeIdxList {
|
|
v.ArgsS = ParseSideEffectArgs(v.Args)
|
|
|
|
EffectMAP[gconv.Int(v.Idx)] = v
|
|
}
|
|
PlayerEffectMAP = make(map[int]NewSeIdx)
|
|
for _, v := range EffectMAP1.SeIdxList {
|
|
if gconv.Int(v.Stat) == 1 && gconv.Int(v.StarLevel) == 0 && gconv.Int(v.Idx) > 1000 {
|
|
v.ArgsS = ParseSideEffectArgs(v.Args)
|
|
|
|
PlayerEffectMAP[gconv.Int(v.Idx)] = v
|
|
}
|
|
|
|
}
|
|
|
|
GoldProductMap = utils.ToMap(getXml[GoldProductConfig](path+"30001.xml").Items,
|
|
func(m GoldProductItem) int {
|
|
return gconv.Int(m.ProductID)
|
|
|
|
},
|
|
)
|
|
|
|
}
|
|
|
|
func init() {
|
|
|
|
initfile() //先初始化一次
|
|
|
|
go func() {
|
|
|
|
if !gfile.Exists(path) {
|
|
fileHandle, _ := gfile.Create(path)
|
|
fileHandle.Close()
|
|
}
|
|
|
|
//updatersares()
|
|
ctx := gctx.New()
|
|
_, err := gfsnotify.Add(path, func(event *gfsnotify.Event) {
|
|
if event.IsCreate() {
|
|
glog.Debug(ctx, "创建文件 : ", event.Path)
|
|
}
|
|
if event.IsWrite() {
|
|
glog.Debug(ctx, "写入文件 : ", event.Path)
|
|
//initfile() //先初始化一次
|
|
}
|
|
if event.IsRemove() {
|
|
glog.Debug(ctx, "删除文件 : ", event.Path)
|
|
}
|
|
if event.IsRename() {
|
|
glog.Debug(ctx, "重命名文件 : ", event.Path)
|
|
}
|
|
if event.IsChmod() {
|
|
glog.Debug(ctx, "修改权限 : ", event.Path)
|
|
}
|
|
glog.Debug(ctx, event)
|
|
})
|
|
|
|
if err != nil {
|
|
glog.Fatal(ctx, err)
|
|
} else {
|
|
select {}
|
|
}
|
|
}()
|
|
|
|
}
|