2025-08-30 00:36:08 +08:00
|
|
|
package xmlres
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-30 21:59:52 +08:00
|
|
|
"blazing/common/utils"
|
2025-09-23 17:34:58 +00:00
|
|
|
"encoding/json"
|
2025-08-30 00:36:08 +08:00
|
|
|
"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"
|
2025-09-19 00:29:55 +08:00
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
2025-08-30 00:36:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var path string
|
|
|
|
|
|
|
|
|
|
func getXml[T any](path string) T {
|
|
|
|
|
|
|
|
|
|
// 解析XML到结构体
|
|
|
|
|
var xmls T
|
|
|
|
|
t1 := gfile.GetBytes(path)
|
|
|
|
|
xml.Unmarshal(t1, &xmls)
|
|
|
|
|
|
|
|
|
|
return xmls
|
|
|
|
|
}
|
2025-09-23 17:34:58 +00:00
|
|
|
func getJson[T any](path string) T {
|
|
|
|
|
|
|
|
|
|
// 解析XML到结构体
|
|
|
|
|
var xmls T
|
|
|
|
|
t1 := gfile.GetBytes(path)
|
|
|
|
|
json.Unmarshal(t1, &xmls)
|
|
|
|
|
|
|
|
|
|
return xmls
|
|
|
|
|
}
|
2025-08-30 00:36:08 +08:00
|
|
|
|
|
|
|
|
var (
|
2025-09-23 17:34:58 +00:00
|
|
|
MapConfig Maps //地图配置
|
|
|
|
|
ItemsConfig Items //物品配置
|
|
|
|
|
EffectArgsConfig EffectArg //arg参数
|
|
|
|
|
TalkConfig TalkCount //任务配置
|
2025-08-30 21:59:52 +08:00
|
|
|
//Monster MonsterRoot //野怪配置
|
|
|
|
|
MonsterMap map[int]TMapConfig
|
|
|
|
|
//Skill MovesTbl //技能配置
|
2025-09-19 06:25:09 +00:00
|
|
|
SkillMap map[int]Move
|
|
|
|
|
PetMAP map[int]PetInfo //宠物配置
|
|
|
|
|
NatureRootMap map[int]NatureItem
|
|
|
|
|
EffectMAP map[int]NewSeIdx
|
|
|
|
|
PlayerEffectMAP map[int]NewSeIdx
|
2025-09-21 14:56:37 +00:00
|
|
|
ItemsMAP map[int]Item
|
2025-10-20 23:59:49 +08:00
|
|
|
TaskMap map[int]Task
|
2025-08-30 00:36:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func initfile() {
|
|
|
|
|
path1, _ := os.Getwd()
|
2025-09-19 00:29:55 +08:00
|
|
|
path = path1 + "/public/config/"
|
2025-08-30 00:36:08 +08:00
|
|
|
MapConfig = getXml[Maps](path + "210.xml")
|
|
|
|
|
ItemsConfig = getXml[Items](path + "43.xml")
|
2025-09-23 17:34:58 +00:00
|
|
|
EffectArgsConfig = getJson[EffectArg](path + "side_effect.json")
|
2025-09-24 12:40:13 +08:00
|
|
|
EffectArgs = make(map[int]int)
|
|
|
|
|
for _, t := range EffectArgsConfig.SideEffects.SideEffect {
|
|
|
|
|
EffectArgs[t.ID] = t.SideEffectArgcount
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-21 14:56:37 +00:00
|
|
|
ItemsMAP = utils.ToMap[Item, int](ItemsConfig.Items, func(m Item) int {
|
|
|
|
|
return m.ID
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
2025-08-30 00:36:08 +08:00
|
|
|
TalkConfig = getXml[TalkCount](path + "talk.xml")
|
2025-10-20 23:59:49 +08:00
|
|
|
|
2025-08-30 21:59:52 +08:00
|
|
|
Monster := getXml[MonsterRoot](path + "地图配置野怪.xml")
|
|
|
|
|
|
|
|
|
|
MonsterMap = utils.ToMap(Monster.Maps, func(m TMapConfig) int {
|
|
|
|
|
return m.ID
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Skill := getXml[MovesTbl](path + "227.xml")
|
2025-09-04 23:57:22 +08:00
|
|
|
|
|
|
|
|
SkillMap = make(map[int]Move, len(Skill.Moves))
|
|
|
|
|
for _, v := range Skill.Moves {
|
2025-09-19 00:29:55 +08:00
|
|
|
v.SideEffectS = ParseSideEffectArgs(v.SideEffect)
|
|
|
|
|
v.SideEffectArgS = ParseSideEffectArgs(v.SideEffectArg)
|
2025-09-04 23:57:22 +08:00
|
|
|
SkillMap[v.ID] = v
|
|
|
|
|
}
|
2025-10-20 23:59:49 +08:00
|
|
|
task := getXml[Tasks](path + "task.xml")
|
|
|
|
|
TaskMap = utils.ToMap[Task, int](task.Tasks, func(m Task) int {
|
|
|
|
|
return m.ID
|
2025-08-30 21:59:52 +08:00
|
|
|
|
2025-10-20 23:59:49 +08:00
|
|
|
})
|
2025-08-31 00:27:07 +08:00
|
|
|
pet := getXml[Monsters](path + "226.xml")
|
2025-09-03 02:09:43 +08:00
|
|
|
PetMAP = utils.ToMap[PetInfo, int](pet.Monsters, func(m PetInfo) int {
|
2025-08-31 00:27:07 +08:00
|
|
|
return m.ID
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
NatureRootMap1 := getXml[NatureRoot](path + "nature.xml")
|
2025-08-30 00:36:08 +08:00
|
|
|
|
2025-08-31 00:27:07 +08:00
|
|
|
NatureRootMap = utils.ToMap[NatureItem, int](NatureRootMap1.Items, func(m NatureItem) int {
|
|
|
|
|
return m.ID
|
|
|
|
|
|
|
|
|
|
})
|
2025-09-19 00:29:55 +08:00
|
|
|
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
|
|
|
|
|
}
|
2025-09-19 06:25:09 +00:00
|
|
|
PlayerEffectMAP = make(map[int]NewSeIdx)
|
|
|
|
|
for _, v := range EffectMAP1.SeIdxList {
|
|
|
|
|
if gconv.Int(v.Stat) == 1 && gconv.Int(v.StarLevel) == 0 {
|
|
|
|
|
v.ArgsS = ParseSideEffectArgs(v.Args)
|
2025-09-19 00:29:55 +08:00
|
|
|
|
2025-09-19 06:25:09 +00:00
|
|
|
PlayerEffectMAP[gconv.Int(v.Idx)] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-19 00:29:55 +08:00
|
|
|
|
2025-08-30 00:36:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}, true)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
glog.Fatal(ctx, err)
|
|
|
|
|
} else {
|
|
|
|
|
select {}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
}
|