From 08b75533880044f80f7b634fc3100b3e69ca1f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Thu, 4 Dec 2025 02:11:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(xmlres):=20=E4=BC=98=E5=8C=96=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=A0=E8=BD=BD=E4=B8=8E=E5=AD=97=E6=AE=B5=E6=8C=87?= =?UTF-8?q?=E9=92=88=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将部分全局配置变量调整为局部加载,减少内存占用 - 修改 Item 结构体中 Nature 和 NatureSet 字段为指针类型,支持空值判断 - 更新使用点逻辑以适配指针字段,避免解析错误 - 移除未使用的配置引用及旧控制器文件 --- common/data/xmlres/file.go | 17 ++++++++--------- common/data/xmlres/item.go | 10 +++++----- logic/controller/item_use.go | 8 ++++---- .../controller/admin/{pet.go => monster_get.go} | 0 4 files changed, 17 insertions(+), 18 deletions(-) rename modules/blazing/controller/admin/{pet.go => monster_get.go} (100%) diff --git a/common/data/xmlres/file.go b/common/data/xmlres/file.go index b54432b4..846818aa 100644 --- a/common/data/xmlres/file.go +++ b/common/data/xmlres/file.go @@ -36,11 +36,11 @@ func getJson[T any](path string) T { } var ( - MapConfig Maps //地图配置 - ItemsConfig Items //物品配置 - EffectArgsConfig EffectArg //arg参数 - TalkConfig TalkRoot //任务配置 - //Monster MonsterRoot //野怪配置 + MapConfig Maps //地图配置 + // ItemsConfig Items //物品配置 + // EffectArgsConfig EffectArg //arg参数 + TalkConfig TalkRoot //任务配置 + // //Monster MonsterRoot //野怪配置 MonsterMap map[int]TMapConfig //Skill MovesTbl //技能配置 SkillMap map[int]Move @@ -60,14 +60,13 @@ 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 { + for _, t := range getJson[EffectArg](path + "side_effect.json").SideEffects.SideEffect { EffectArgs[t.ID] = t.SideEffectArgcount } - ItemsMAP = utils.ToMap[Item, int](ItemsConfig.Items, func(m Item) int { + ItemsMAP = utils.ToMap[Item, int](getXml[Items](path+"43.xml").Items, func(m Item) int { return m.ID }) diff --git a/common/data/xmlres/item.go b/common/data/xmlres/item.go index 0ca2507a..a607954b 100644 --- a/common/data/xmlres/item.go +++ b/common/data/xmlres/item.go @@ -46,11 +46,11 @@ type Item struct { DualEvTimes int `xml:"DualEvTimes,attr,omitempty"` // 双倍学习力次数(学习力双倍仪) YuanshenDegrade int `xml:"YuanshenDegrade,attr,omitempty"` // 融合精灵还原标识(融合精灵还原药剂) EvRemove int `xml:"EvRemove,attr,omitempty"` // 学习力遗忘类型(各类学习力遗忘剂) - bShowPetBag int `xml:"bShowPetBag,attr,omitempty"` // 宠物背包显示标识(副融合精灵保留药剂等) - Nature int `xml:"Nature,attr,omitempty"` - NatureSet string `xml:"NatureSet,attr,omitempty"` - Pet *Pet `xml:"pet,omitempty"` // 精灵属性子节点 - TeamPK *TeamPK `xml:"teamPK,omitempty"` // 要塞保卫战子节点 + //bShowPetBag int `xml:"bShowPetBag,attr,omitempty"` // 宠物背包显示标识(副融合精灵保留药剂等) + Nature *string `xml:"Nature,attr"` // 指向int的指针,无值时为nil + NatureSet *string `xml:"NatureSet,attr"` // 指向string的指针,无值时为nil + Pet *Pet `xml:"pet,omitempty"` // 精灵属性子节点 + TeamPK *TeamPK `xml:"teamPK,omitempty"` // 要塞保卫战子节点 } // Pet 精灵属性子节点,对应标签 diff --git a/logic/controller/item_use.go b/logic/controller/item_use.go index b1febb31..ff82d47d 100644 --- a/logic/controller/item_use.go +++ b/logic/controller/item_use.go @@ -54,12 +54,12 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play case itemID >= 240042 && itemID <= 240056: - if xmlres.ItemsMAP[int(itemID)].Nature != 0 { - onpet.Nature = uint32(xmlres.ItemsMAP[int(itemID)].Nature) + if xmlres.ItemsMAP[int(itemID)].Nature != nil { + onpet.Nature = gconv.Uint32(*xmlres.ItemsMAP[int(itemID)].Nature) } - if xmlres.ItemsMAP[int(itemID)].NatureSet != "" { + if xmlres.ItemsMAP[int(itemID)].NatureSet != nil { - rr := strings.Split(xmlres.ItemsMAP[int(itemID)].NatureSet, " ") + rr := strings.Split(*xmlres.ItemsMAP[int(itemID)].NatureSet, " ") onpet.Nature = gconv.Uint32(rr[grand.Intn(len(rr))-1]) } default: diff --git a/modules/blazing/controller/admin/pet.go b/modules/blazing/controller/admin/monster_get.go similarity index 100% rename from modules/blazing/controller/admin/pet.go rename to modules/blazing/controller/admin/monster_get.go