refactor(effectarg): 移动EffectArgs初始化逻辑 将EffectArgs的初始化从effectarg.go中的init函数移动到file.go的initfile函数中, 确保在使用前正确加载配置并初始化映射。 refactor(login): 更新Login方法中的Person调用 修改Login方法中对Person函数的调用,传递UserID参数以获取正确的用户信息。 refactor(user): 统一使用Person方法替代PersonOther 在UserSimInfo和UserMoreInfo方法中,将原先调用的PersonOther方法统一替换为 Person方法,保持代码一致性。 refactor(effect_damage): 简化属性获取和伤害计算逻辑 移除deepcopy相关逻辑,简化Effect0的OnSkill方法中的属性获取和伤害计算流程, 直接通过输入参数进行计算。 refactor(fightc): 优化玩家输入处理和战斗逻辑 更新GetInputByPlayer方法中的玩家判断逻辑,使用UserID比较代替对象比较; 在initplayer中添加InitAttackValue调用; 修复battleLoop中打印语句的格式问题; 调整技能攻击处理流程,增加SkillUseEnd回调调用。 refactor(attr): 改进属性获取方法和伤害计算逻辑 将GetProp方法重命名为Prop,并支持传入对方输入参数; 更新CalculatePower方法签名,使用Input类型代替BattlePetEntity; 在属性获取和伤害计算中正确处理双方属性影响。 refactor(playeraction): 简化技能使用逻辑 简化UseSkill方法中获取当前宠物信息的逻辑,去除冗余的条件判断; 在找到对应技能后添加break语句,提高执行效率。 refactor(reg): 更新Person方法实现 合并Person和PersonOther方法为统一的Person方法; 在数据库查询失败时添加错误处理,避免潜在的空指针异常。 ```
157 lines
3.5 KiB
Go
157 lines
3.5 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 TalkCount //任务配置
|
|
//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
|
|
)
|
|
|
|
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[TalkCount](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
|
|
}
|
|
|
|
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 {}
|
|
}
|
|
}()
|
|
|
|
}
|