feat(element): 优化元素计算器并发安全与缓存机制
- 使用 sync.Map 替代 map+锁,提升并发读写性能 - 预加载所有元素组合,避免运行时重复创建 - 攻击系数计算结果加入缓存,提高查询效率 - 完善缓存键命名与错误处理机制 - 调整元素组合字符串展示格式,增强可读性 fix(item): 修复购买物品时价格为0仍扣除金币的问题 - 在购买逻辑中增加对物品价格是否为0的判断 - 防止免费物品被误扣金币
This commit is contained in:
@@ -33,6 +33,7 @@ func (h Controller) PlayerGoldCount(data *item.GoldOnlineRemainInboundInfo, c *p
|
||||
return &item.GoldOnlineRemainOutboundInfo{
|
||||
|
||||
GoldNumber: uint32(c.Info.GoldBean) * 100,
|
||||
Coin: c.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
func (h Controller) PlayerExp(data *item.ExpTotalRemainInboundInfo, c *player.Player) (result *item.ExpTotalRemainOutboundInfo, err errorcode.ErrorCode) {
|
||||
@@ -45,7 +46,7 @@ func (h Controller) PlayerExp(data *item.ExpTotalRemainInboundInfo, c *player.Pl
|
||||
|
||||
func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result *item.BuyOutboundInfo, err errorcode.ErrorCode) {
|
||||
tt, ok := xmlres.ItemsMAP[int(data.ItemId)]
|
||||
if ok {
|
||||
if ok && tt.Price != 0 {
|
||||
if (data.Count * uint32(tt.Price)) <= c.Info.Coins {
|
||||
c.Info.Coins -= data.Count * uint32(tt.Price)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user