feat(player): 重构玩家金币系统,使用BaseSysUserService管理金币

将玩家金币逻辑从PlayerInfo中移除,改为通过BaseSysUserService进行统一管理。
新增了金币的获取与设置方法,支持以分为单位的精确计算。
调整了登录时用户服务的初始化逻辑,确保User字段正确赋值。

fix(pet): 修复宠物性格道具使用逻辑错误

更新了多个性格相关道具的处理方式,包括新增的性格转换道具范围。
修正了性格随机与指定逻辑,避免越界问题并增强可维护性。

feat(fight): 战斗初始化时恢复宠物状态

在战斗初始化阶段调用宠物治愈方法,确保战斗开始前宠物处于健康状态。

feat(admin): 调整管理员会话获取接口参数类型

修改GetPerson方法传入参数为uint32类型,提高数据一致性与安全性。

refactor(model): 移除PlayerInfo中的GoldBean字段

金币字段不再存储于PlayerInfo结构体中,转而由BaseSysUser模块统一管理。
```
This commit is contained in:
2025-12-06 23:59:00 +08:00
parent 91690658b5
commit 35c89215f7
12 changed files with 55 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"blazing/common/rpc"
"blazing/common/socket/errorcode"
"blazing/logic/service/user"
"blazing/modules/base/service"
"golang.org/x/sync/singleflight"
@@ -23,7 +24,7 @@ func fetchData() (any, error) {
func (h *Controller) COMMEND_ONLINE(data *user.SidInfo, c gnet.Conn) (result *rpc.CommendSvrInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = rpc.NewInInfo()
if data.Head.UserID < 100000 {
if service.NewBaseSysUserService().GetPerson(data.Head.UserID).Debug == 1 {
result.IsVip = 1
}
v, _, _ := sg.Do("GetServerInfoList", fetchData)

View File

@@ -10,7 +10,7 @@ func (h Controller) PlayerGoldCount(data *item.GoldOnlineRemainInboundInfo, c *p
return &item.GoldOnlineRemainOutboundInfo{
GoldNumber: uint32(c.Info.GoldBean) * 100,
GoldNumber: c.User.GetGold(uint(c.Info.UserID)),
Coin: c.Info.Coins,
}, 0
}

View File

@@ -62,13 +62,14 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Playe
return nil, errorcode.ErrorCodes.ErrSystemError
}
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))
}
isbuycot := len(r1)
usegold := uint32(uint32(len(r1))) * uint32(gconv.Uint32(r.Price)*100)
c.User.SetGold(c.Info.UserID, c.User.GetGold(uint(c.Info.UserID))-usegold)
result = &item.S2C_GoldBuyProductInfo{
Gold: c.Info.GoldBean,
PayGold: uint32(data.Count) * uint32(gconv.Uint32(r.Price)),
Gold: c.User.GetGold(uint(c.Info.UserID)),
PayGold: uint32(isbuycot) * uint32(gconv.Uint32(r.Price)),
Reserved: 0,
}

View File

@@ -50,18 +50,17 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
//性格随机
case itemID == 300025:
onpet.Nature = uint32(grand.Intn(25))
case itemID >= 240042 && itemID <= 240056:
onpet.Nature = (onpet.Nature + uint32(grand.Intn(25))) % 25
if xmlres.ItemsMAP[int(itemID)].Nature != nil {
onpet.Nature = gconv.Uint32(*xmlres.ItemsMAP[int(itemID)].Nature)
}
if xmlres.ItemsMAP[int(itemID)].NatureSet != nil {
//性格转换
case itemID >= 300081 && itemID <= 300086:
onpet.Nature = gconv.Uint32(*xmlres.ItemsMAP[int(itemID)].Nature)
rr := strings.Split(*xmlres.ItemsMAP[int(itemID)].NatureSet, " ")
onpet.Nature = gconv.Uint32(rr[grand.Intn(len(rr))-1])
}
//性格转换
case (itemID >= 300602 && itemID <= 300605) || itemID == 300119 || itemID == 300120:
rr := strings.Split(*xmlres.ItemsMAP[int(itemID)].NatureSet, " ")
onpet.Nature = gconv.Uint32(rr[grand.Intn(len(rr))-1])
default:
// 无效ID处理
return nil, errorcode.ErrorCodes.ErrSystemError

View File

@@ -12,6 +12,7 @@ import (
"blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/base/service"
blservice "blazing/modules/blazing/service"
"context"
"time"
@@ -57,6 +58,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
return
}
t.Service = blservice.NewUserService(data.Head.UserID)
t.User = service.NewBaseSysUserService()
t.Info = t.Service.Info.Person(data.Head.UserID)
if t.Info == nil {
defer c.Close()

View File

@@ -77,15 +77,17 @@ func (h *Controller) PET_ROWEI(
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
_, _, ok := c.FindPet(data.CatchTime)
r := xmlres.PetMAP[int(data.ID)].FreeForbidden
//如果背包没找到,再放入背包
if !ok && t.CatchTime != 0 && xmlres.PetMAP[int(data.ID)].FreeForbidden == 0 {
if !ok && t.CatchTime != 0 && r == 0 {
t.Free = 1
} else {
err = errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
}
})
return nil, 0
return nil, err
}