2025-08-30 00:36:08 +08:00
|
|
|
package xmlres
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-30 21:59:52 +08:00
|
|
|
"blazing/common/utils"
|
2025-11-25 16:36:55 +08:00
|
|
|
|
2026-01-01 19:57:39 +08:00
|
|
|
_ "blazing/common/data/xmlres/packed"
|
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"
|
2026-01-01 19:57:39 +08:00
|
|
|
"github.com/gogf/gf/v2/os/gres"
|
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
|
2026-01-01 19:57:39 +08:00
|
|
|
|
|
|
|
|
t1 := gres.GetContent(path)
|
2025-08-30 00:36:08 +08:00
|
|
|
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
|
2026-01-01 19:57:39 +08:00
|
|
|
t1 := gres.GetContent(path)
|
2025-09-23 17:34:58 +00:00
|
|
|
json.Unmarshal(t1, &xmls)
|
|
|
|
|
|
|
|
|
|
return xmls
|
|
|
|
|
}
|
2025-08-30 00:36:08 +08:00
|
|
|
|
|
|
|
|
var (
|
2025-12-04 02:11:51 +08:00
|
|
|
MapConfig Maps //地图配置
|
|
|
|
|
// ItemsConfig Items //物品配置
|
|
|
|
|
// EffectArgsConfig EffectArg //arg参数
|
2025-12-08 21:11:12 +08:00
|
|
|
//TalkConfig TalkRoot //任务配置
|
2025-12-04 02:11:51 +08:00
|
|
|
// //Monster MonsterRoot //野怪配置
|
2025-08-30 21:59:52 +08:00
|
|
|
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-11-02 23:52:06 +08:00
|
|
|
ShopMap map[int]ShopItem
|
|
|
|
|
SkillTypeMap map[int]SkillType
|
|
|
|
|
RelationsMap map[int]Relation
|
2025-11-25 12:29:50 +08:00
|
|
|
GoldProductMap = make(map[int]GoldProductItem, 0)
|
2025-12-16 02:50:10 +08:00
|
|
|
EVOLVMAP map[int]Evolve
|
2025-08-30 00:36:08 +08:00
|
|
|
)
|
|
|
|
|
|
2025-11-25 16:36:55 +08:00
|
|
|
func Initfile() {
|
2026-01-01 19:57:39 +08:00
|
|
|
//gres.Dump()
|
2025-08-30 00:36:08 +08:00
|
|
|
path1, _ := os.Getwd()
|
2025-09-19 00:29:55 +08:00
|
|
|
path = path1 + "/public/config/"
|
2026-01-01 19:57:39 +08:00
|
|
|
path = "config/"
|
2025-08-30 00:36:08 +08:00
|
|
|
MapConfig = getXml[Maps](path + "210.xml")
|
2025-12-04 02:11:51 +08:00
|
|
|
|
2025-09-24 12:40:13 +08:00
|
|
|
EffectArgs = make(map[int]int)
|
2025-12-04 02:11:51 +08:00
|
|
|
for _, t := range getJson[EffectArg](path + "side_effect.json").SideEffects.SideEffect {
|
2025-09-24 12:40:13 +08:00
|
|
|
EffectArgs[t.ID] = t.SideEffectArgcount
|
|
|
|
|
|
|
|
|
|
}
|
2025-12-04 02:11:51 +08:00
|
|
|
ItemsMAP = utils.ToMap[Item, int](getXml[Items](path+"43.xml").Items, func(m Item) int {
|
2025-09-21 14:56:37 +00:00
|
|
|
return m.ID
|
|
|
|
|
|
|
|
|
|
})
|
2025-12-16 02:50:10 +08:00
|
|
|
EVOLVMAP = utils.ToMap[Evolve, int](getXml[CondEvolves](path+"进化仓.xml").Evolves, func(m Evolve) int {
|
|
|
|
|
return m.ID
|
2025-09-21 14:56:37 +00:00
|
|
|
|
2025-12-16 02:50:10 +08:00
|
|
|
})
|
2025-12-08 21:11:12 +08:00
|
|
|
//TalkConfig = getXml[TalkRoot](path + "talk.xml")
|
2025-10-20 23:59:49 +08:00
|
|
|
|
2025-11-25 12:29:50 +08:00
|
|
|
MonsterMap = utils.ToMap(getXml[MonsterRoot](path+"地图配置野怪.xml").Maps, func(m TMapConfig) int {
|
2025-08-30 21:59:52 +08:00
|
|
|
return m.ID
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
2025-11-25 12:29:50 +08:00
|
|
|
ShopMap = utils.ToMap(getXml[ShopRoot](path+"地图配置野怪.xml").Items, func(m ShopItem) int {
|
2025-11-02 23:52:06 +08:00
|
|
|
return gconv.Int(m.ProductID)
|
|
|
|
|
|
|
|
|
|
})
|
2025-08-30 21:59:52 +08:00
|
|
|
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-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
TaskMap = utils.ToMap[Task, int](getXml[Tasks](path+"task.xml").Tasks, func(m Task) int {
|
2025-10-20 23:59:49 +08:00
|
|
|
return m.ID
|
2025-08-30 21:59:52 +08:00
|
|
|
|
2025-10-20 23:59:49 +08:00
|
|
|
})
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
|
|
|
PetMAP = utils.ToMap[PetInfo, int](getXml[Monsters](path+"226.xml").Monsters, func(m PetInfo) int {
|
2025-08-31 00:27:07 +08:00
|
|
|
return m.ID
|
|
|
|
|
|
|
|
|
|
})
|
2025-08-30 00:36:08 +08:00
|
|
|
|
2025-11-25 12:29:50 +08:00
|
|
|
NatureRootMap = utils.ToMap[NatureItem, int](getXml[NatureRoot](path+"nature.xml").Items, func(m NatureItem) int {
|
2025-08-31 00:27:07 +08:00
|
|
|
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 {
|
2025-12-30 00:45:23 +08:00
|
|
|
if gconv.Int(v.Stat) == 1 && gconv.Int(v.Idx) > 1000 {
|
2025-09-19 06:25:09 +00:00
|
|
|
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-11-25 12:29:50 +08:00
|
|
|
GoldProductMap = utils.ToMap(getXml[GoldProductConfig](path+"30001.xml").Items,
|
|
|
|
|
func(m GoldProductItem) int {
|
|
|
|
|
return gconv.Int(m.ProductID)
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-30 00:36:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
|
|
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)
|
2025-11-22 22:57:32 +08:00
|
|
|
//initfile() //先初始化一次
|
2025-08-30 00:36:08 +08:00
|
|
|
}
|
|
|
|
|
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)
|
2025-11-17 12:59:46 +08:00
|
|
|
})
|
2025-08-30 00:36:08 +08:00
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
glog.Fatal(ctx, err)
|
|
|
|
|
} else {
|
|
|
|
|
select {}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
}
|