feat(item): 优化购买金币商品逻辑并完善宠物属性计算

- 购买金币商品时增加失败回滚机制,确保扣除金币与实际获得物品一致
- 使用 `CalculatePetPane` 替代 `Update` 方法以正确刷新宠物面板数据
- 精简地图热度统计逻辑,移除并发安全库依赖,改用普通 map 配合原子操作
- 移除 Space 结构体中冗余的 SuperValue 字段,直接通过 map 统计地图人数
- 更新地图配置文件中的怪物分布信息,调整部分怪物等级和数量配置
```
This commit is contained in:
2025-11-25 21:10:52 +08:00
parent 6455455992
commit f682abe537
8 changed files with 36 additions and 52 deletions

View File

@@ -0,0 +1 @@
package controller

View File

@@ -61,9 +61,11 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Playe
if !c.UseGold(uint32(data.Count) * uint32(gconv.Uint32(r.Price))) {
return nil, errorcode.ErrorCodes.ErrSystemError
}
c.ItemAdd(model.ItemInfo{ItemId: uint32(gconv.Uint32(r.ItemID)), ItemCnt: uint32(data.Count)})
c.Info.GoldBean -= gconv.Uint32(r.Price)
r1 := c.ItemAdd(model.ItemInfo{ItemId: uint32(gconv.Uint32(r.ItemID)), ItemCnt: uint32(data.Count)})
if len(r1) == int(data.Count) {
//失败返还
c.Info.GoldBean += uint32(uint32(data.Count)-uint32(len(r1))) * uint32(gconv.Uint32(r.Price))
}
result = &item.S2C_GoldBuyProductInfo{
Gold: c.Info.GoldBean,
PayGold: uint32(data.Count) * uint32(gconv.Uint32(r.Price)),

View File

@@ -58,7 +58,7 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
}
c.Service.Item.SubItem(data.ItemID, 1)
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
onpet.Update()
onpet.CalculatePetPane()
copier.Copy(&result, onpet)
return result, 0
@@ -74,6 +74,7 @@ func (h Controller) RESET_NATURE(data *item.C2S_PET_RESET_NATURE, c *player.Play
}
onpet.Nature = data.Nature
onpet.CalculatePetPane()
c.Service.Item.SubItem(data.ItemId, 1)
return result, 0
}

View File

@@ -1,9 +1,6 @@
package space
import (
"sync/atomic"
csmap "github.com/mhmtszr/concurrent-swiss-map"
"golang.org/x/sync/singleflight"
)
@@ -14,32 +11,18 @@ type MapHotInfo struct {
Count int32 `struc:"uint32" json:"count"` // 地图里的人数
}
var maphot = csmap.New[uint32, *int32](
// set the number of map shards. the default value is 32.
csmap.WithShardCount[uint32, *int32](32),
// // if don't set custom hasher, use the built-in maphash.
// csmap.WithCustomHasher[string, int](func(key string) uint64 {
// hash := fnv.New64a()
// hash.Write([]byte(key))
// return hash.Sum64()
// }),
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
// csmap.WithSize[string, int](1000),
)
var maphot = make(map[uint32]*int32, 0)
func GetMapHot() []MapHotInfo {
ret := make([]MapHotInfo, 0)
maphot.Range(func(key uint32, value *int32) (stop bool) {
for k, v := range maphot {
ret = append(ret, MapHotInfo{
MapID: key,
Count: atomic.LoadInt32(value),
MapID: k,
Count: *v,
})
return true
})
}
return ret
// result1, _, _ := requestGroup.Do("map_hot", func() (interface{}, error) {

View File

@@ -46,10 +46,8 @@ func (s *Space) LeaveMap(c common.PlayerI) {
s.User.Delete(c.GetInfo().UserID)
s.UserInfo.Delete(c.GetInfo().UserID)
if s.SuperValue != nil {
atomic.AddInt32(s.SuperValue, -1)
}
atomic.AddInt32(maphot[s.Super], -1)
}
@@ -62,9 +60,7 @@ func (s *Space) EnterMap(c common.PlayerI) {
s.UserInfo.Store(c.GetInfo().UserID, *out)
s.Broadcast(c, 2001, out)
if s.SuperValue != nil {
atomic.AddInt32(s.SuperValue, 1)
}
atomic.AddInt32(maphot[s.Super], 1)
}
func (s *Space) GetInfo() []maps.OutInfo {

View File

@@ -16,7 +16,7 @@ type Space struct {
UserInfo *csmap.CsMap[uint32, maps.OutInfo]
CanRefresh bool //是否能够刷怪
Super uint32
SuperValue *int32
//SuperValue *int32
//ID uint32 // 地图ID
Name string //地图名称
Owner ARENA
@@ -73,20 +73,20 @@ func GetSpace(id uint32) *Space {
for _, v := range xmlres.MapConfig.Maps {
if v.ID == int(id) { //找到这个地图
t := NewSpace()
t.Super = uint32(v.Super)
ok := maphot.Has(t.Super)
if !ok {
var tt int32 = 0
maphot.Store(uint32(v.Super), &tt)
t.SuperValue = &tt //创建一个
} else {
t.SuperValue, _ = maphot.Load(uint32(v.Super))
// t.Super = uint32(v.Super)
// if t.Super == 0 {
// t.Super = uint32(v.ID)
// }
t.Super = uint32(v.ID)
_, ok := maphot[t.Super]
if !ok {
var t1 int32
maphot[t.Super] = &t1
}
t.Name = v.Name
break
}
}

1
public/config/210.xml Symbolic link
View File

@@ -0,0 +1 @@
E:/newcode/flash/out/resource/xml/210.xml

View File

@@ -7827,15 +7827,15 @@ eg:
<Map ID="737" Name="深海禁地" InitX="300" InitY="100">
<Monsters>
<Monster ID="2186" Lv="13 16"/>
<Monster ID="2186" Lv="13 16"/>
<Monster ID="2186" Lv="13 16"/>
<Monster ID="2186" Lv="20 23"/>
<Monster ID="2186 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" Lv="13 16"/>
<Monster ID="108" Lv="20 23"/>
<Monster ID="108" Lv="20 23"/>
<Monster ID="108" Lv="20 23"/>
<Monster ID="108" Lv="20 20"/>
<Monster ID="108" Lv="20 20"/>
<Monster ID="108" Lv="20 20"/>
<Monster ID="108" Lv="20 20"/>
<Monster ID="108" Lv="20 20"/>
<Monster ID="2186" Lv="20 20"/>
<Monster ID="2186" Lv="20 20"/>
<Monster ID="2186" Lv="20 20"/>
<Monster ID="2186" Lv="20 20"/>
</Monsters>
<Bosses>
<Boss AppearTime="13 13" AppearStartMin="0" AppearEndMin="7" BossVisible="0" Name="巨齿鲨">