feat(player): 重构玩家金币系统,使用BaseSysUserService管理金币 将玩家金币逻辑从PlayerInfo中移除,改为通过BaseSysUserService进行统一管理。 新增了金币的获取与设置方法,支持以分为单位的精确计算。 调整了登录时用户服务的初始化逻辑,确保User字段正确赋值。 fix(pet): 修复宠物性格道具使用逻辑错误 更新了多个性格相关道具的处理方式,包括新增的性格转换道具范围。 修正了性格随机与指定逻辑,避免越界问题并增强可维护性。 feat(fight): 战斗初始化时恢复宠物状态 在战斗初始化阶段调用宠物治愈方法,确保战斗开始前宠物处于健康状态。 feat(admin): 调整管理员会话获取接口参数类型 修改GetPerson方法传入参数为uint32类型,提高数据一致性与安全性。 refactor(model): 移除PlayerInfo中的GoldBean字段 金币字段不再存储于PlayerInfo结构体中,转而由BaseSysUser模块统一管理。 ```
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/data/xmlres"
|
|
"blazing/common/socket/errorcode"
|
|
|
|
"blazing/logic/service/item"
|
|
"blazing/logic/service/player"
|
|
"blazing/modules/blazing/model"
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
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 && tt.Price != 0 && c.UseCoins(data.Count*uint32(tt.Price)) {
|
|
|
|
r := c.ItemAdd(model.ItemInfo{ItemId: data.ItemId, ItemCnt: data.Count})
|
|
if len(r) != 0 {
|
|
return &item.BuyOutboundInfo{
|
|
ItemId: data.ItemId,
|
|
Level: 1,
|
|
Count: data.Count,
|
|
Coins: c.Info.Coins,
|
|
}, 0
|
|
}
|
|
//购买失败,返还豆子
|
|
c.Info.Coins += data.Count * uint32(tt.Price)
|
|
}
|
|
|
|
return &item.BuyOutboundInfo{
|
|
|
|
Coins: c.Info.Coins,
|
|
}, 0
|
|
}
|
|
func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
|
var rrr []model.ItemInfo
|
|
for _, v := range data.ItemIds {
|
|
_, ok := xmlres.ItemsMAP[int(v)]
|
|
|
|
if ok {
|
|
rrr = append(rrr, model.ItemInfo{ItemId: uint32(v), ItemCnt: 1})
|
|
|
|
}
|
|
}
|
|
r := c.ItemAdd(rrr...)
|
|
if len(r) != 0 {
|
|
return &item.BuyMultiOutboundInfo{
|
|
|
|
Coins: c.Info.Coins,
|
|
}, 0
|
|
}
|
|
return &item.BuyMultiOutboundInfo{
|
|
|
|
Coins: c.Info.Coins,
|
|
}, 0
|
|
}
|
|
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
|
r := xmlres.GoldProductMap[int(data.ProductID)]
|
|
|
|
if !c.UseGold(uint32(data.Count) * uint32(gconv.Uint32(r.Price))) {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
r1 := c.ItemAdd(model.ItemInfo{ItemId: uint32(gconv.Uint32(r.ItemID)), ItemCnt: uint32(data.Count)})
|
|
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.User.GetGold(uint(c.Info.UserID)),
|
|
PayGold: uint32(isbuycot) * uint32(gconv.Uint32(r.Price)),
|
|
Reserved: 0,
|
|
}
|
|
|
|
return
|
|
|
|
}
|