feat(xml): 更新任务配置结构以支持新能量节点解析 将原先的 TalkCount 和 TalkEntry 结构替换为 TalkRoot 和 Energy, 以适配新的 XML 配置格式。同时更新了相关引用代码以确保类型一致性。 refactor(item): 优化物品添加方法支持可变参数传入 调整 ItemAdd 方法签名,从接收数组改为接收可变参数, 提升调用灵活性,并同步修改控制器中对物品添加逻辑的处理方式。 feat(login): 修复每日重置逻辑并引入 gtime 时间管理 修正登录时每日任务重置区间错误(400~100 改为 400~500), 并改用 gtime.Now().Time 提供更准确的时间戳记录与比较, 同时增强挖矿次数等
163 lines
3.7 KiB
Go
163 lines
3.7 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
|
|
)
|
|
|
|
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")
|
|
|
|
Monster := getXml[MonsterRoot](path + "地图配置野怪.xml")
|
|
|
|
MonsterMap = utils.ToMap(Monster.Maps, func(m TMapConfig) int {
|
|
return m.ID
|
|
|
|
})
|
|
|
|
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
|
|
}
|
|
task := getXml[Tasks](path + "task.xml")
|
|
TaskMap = utils.ToMap[Task, int](task.Tasks, func(m Task) int {
|
|
return m.ID
|
|
|
|
})
|
|
pet := getXml[Monsters](path + "226.xml")
|
|
PetMAP = utils.ToMap[PetInfo, int](pet.Monsters, func(m PetInfo) int {
|
|
return m.ID
|
|
|
|
})
|
|
NatureRootMap1 := getXml[NatureRoot](path + "nature.xml")
|
|
|
|
NatureRootMap = utils.ToMap[NatureItem, int](NatureRootMap1.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 {
|
|
v.ArgsS = ParseSideEffectArgs(v.Args)
|
|
|
|
PlayerEffectMAP[gconv.Int(v.Idx)] = v
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 {}
|
|
}
|
|
}()
|
|
|
|
}
|