feat(element): 优化元素计算器并发安全与缓存机制
- 使用 sync.Map 替代 map+锁,提升并发读写性能 - 预加载所有元素组合,避免运行时重复创建 - 攻击系数计算结果加入缓存,提高查询效率 - 完善缓存键命名与错误处理机制 - 调整元素组合字符串展示格式,增强可读性 fix(item): 修复购买物品时价格为0仍扣除金币的问题 - 在购买逻辑中增加对物品价格是否为0的判断 - 防止免费物品被误扣金币
This commit is contained in:
@@ -49,6 +49,9 @@ var (
|
||||
PlayerEffectMAP map[int]NewSeIdx
|
||||
ItemsMAP map[int]Item
|
||||
TaskMap map[int]Task
|
||||
ShopMap map[int]ShopItem
|
||||
SkillTypeMap map[int]SkillType
|
||||
RelationsMap map[int]Relation
|
||||
)
|
||||
|
||||
func initfile() {
|
||||
@@ -75,7 +78,12 @@ func initfile() {
|
||||
return m.ID
|
||||
|
||||
})
|
||||
Shop1 := getXml[ShopRoot](path + "地图配置野怪.xml")
|
||||
|
||||
ShopMap = utils.ToMap(Shop1.Items, func(m ShopItem) int {
|
||||
return gconv.Int(m.ProductID)
|
||||
|
||||
})
|
||||
Skill := getXml[MovesTbl](path + "227.xml")
|
||||
|
||||
SkillMap = make(map[int]Move, len(Skill.Moves))
|
||||
|
||||
16
common/data/xmlres/shop.go
Normal file
16
common/data/xmlres/shop.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package xmlres
|
||||
|
||||
// Root 对应 XML 根节点 <root>
|
||||
type ShopRoot struct {
|
||||
Items []ShopItem `xml:"item"` // 所有 <item> 子节点映射为 Items 切片
|
||||
}
|
||||
|
||||
// Item 对应 XML 中的 <item> 节点
|
||||
type ShopItem struct {
|
||||
ItemID string `xml:"itemID,attr"` // 物品ID(属性)
|
||||
Name string `xml:"name,attr"` // 物品名称(属性)
|
||||
ProductID string `xml:"productID,attr"` // 商品ID(属性,可能为空)
|
||||
Price int `xml:"price,attr"` // 金豆价格(属性,整数)
|
||||
Vip float64 `xml:"vip,attr"` // VIP折扣(属性,小数)
|
||||
MoneyType string `xml:"moneyType,attr"` // 货币类型(属性,部分item可能缺失)
|
||||
}
|
||||
32
common/data/xmlres/skilltype.go
Normal file
32
common/data/xmlres/skilltype.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package xmlres
|
||||
|
||||
// Root 对应XML根节点
|
||||
type SkillTypeRoot struct {
|
||||
Items []SkillType `xml:"item"` // 所有技能类型映射为切片
|
||||
}
|
||||
|
||||
// SkillType 对应单个<item>节点
|
||||
type SkillType struct {
|
||||
ID int `xml:"id,attr"` // 技能类型ID
|
||||
CN string `xml:"cn,attr"` // 中文名称
|
||||
EN string `xml:"en,attr"` // 英文名称
|
||||
IsDou int `xml:"is_dou,attr"` // 是否双属性(1=是,0=否/未设置)
|
||||
Att string `xml:"att,attr"` // 双属性对应基础ID(格式:"id1 id2")
|
||||
}
|
||||
|
||||
// Root 对应XML根节点 <Root>
|
||||
type RelationsRoot struct {
|
||||
Relations []Relation `xml:"Relation"` // 所有克制关系映射为切片
|
||||
}
|
||||
|
||||
// Relation 对应 <Relation> 节点(攻击方属性)
|
||||
type Relation struct {
|
||||
Type string `xml:"type,attr"` // 攻击方属性英文(如grass)
|
||||
Opponents []Opponent `xml:"Opponent"` // 该属性对应的所有被克制方
|
||||
}
|
||||
|
||||
// Opponent 对应 <Opponent> 节点(被克制方属性及倍数)
|
||||
type Opponent struct {
|
||||
Type string `xml:"type,attr"` // 被攻击方属性英文
|
||||
Multiple float64 `xml:"multiple,attr"` // 克制倍数(0=无效,0.5=抗性,2=克制)
|
||||
}
|
||||
Reference in New Issue
Block a user